From 9b87f09b1d3cac320c2da5758c1e74d4b4c0fadd Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 15 Aug 2016 09:42:37 -0600 Subject: [PATCH] fio: inherit IO engine flags to 'td' Signed-off-by: Jens Axboe --- backend.c | 12 ++++++------ diskutil.c | 2 +- filesetup.c | 10 +++++----- fio.c | 2 ++ fio.h | 19 +++++++++++++++++++ init.c | 21 +++++++++++---------- io_u.c | 6 +++--- ioengines.c | 8 ++++---- memory.c | 4 ++-- rate-submit.c | 3 --- verify.c | 2 +- 11 files changed, 54 insertions(+), 35 deletions(-) diff --git a/backend.c b/backend.c index c051c13c..b43486dc 100644 --- a/backend.c +++ b/backend.c @@ -1024,7 +1024,7 @@ reap: if (ret < 0) break; if (!ddir_rw_sum(td->bytes_done) && - !(td->io_ops->flags & FIO_NOIO)) + !td_ioengine_flagged(td, FIO_NOIO)) continue; if (!in_ramp_time(td) && should_check_rate(td)) { @@ -1175,7 +1175,7 @@ static int init_io_u(struct thread_data *td) td->orig_buffer_size = (unsigned long long) max_bs * (unsigned long long) max_units; - if ((td->io_ops->flags & FIO_NOIO) || !(td_read(td) || td_write(td))) + if (td_ioengine_flagged(td, FIO_NOIO) || !(td_read(td) || td_write(td))) data_xfer = 0; err = 0; @@ -1195,7 +1195,7 @@ static int init_io_u(struct thread_data *td) * lucky and the allocator gives us an aligned address. */ if (td->o.odirect || td->o.mem_align || td->o.oatomic || - (td->io_ops->flags & FIO_RAWIO)) + td_ioengine_flagged(td, FIO_RAWIO)) td->orig_buffer_size += page_mask + td->o.mem_align; if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) { @@ -1214,7 +1214,7 @@ static int init_io_u(struct thread_data *td) return 1; if (td->o.odirect || td->o.mem_align || td->o.oatomic || - (td->io_ops->flags & FIO_RAWIO)) + td_ioengine_flagged(td, FIO_RAWIO)) p = PAGE_ALIGN(td->orig_buffer) + td->o.mem_align; else p = td->orig_buffer; @@ -1288,7 +1288,7 @@ static int switch_ioscheduler(struct thread_data *td) FILE *f; int ret; - if (td->io_ops->flags & FIO_DISKLESSIO) + if (td_ioengine_flagged(td, FIO_DISKLESSIO)) return 0; sprintf(tmp, "%s/queue/scheduler", td->sysfs_root); @@ -1748,7 +1748,7 @@ static void *thread_main(void *data) if (!o->do_verify || o->verify == VERIFY_NONE || - (td->io_ops->flags & FIO_UNIDIR)) + td_ioengine_flagged(td, FIO_UNIDIR)) continue; clear_io_state(td, 0); diff --git a/diskutil.c b/diskutil.c index a1077d40..0f7a6420 100644 --- a/diskutil.c +++ b/diskutil.c @@ -491,7 +491,7 @@ void init_disk_util(struct thread_data *td) unsigned int i; if (!td->o.do_disk_util || - (td->io_ops->flags & (FIO_DISKLESSIO | FIO_NODISKUTIL))) + td_ioengine_flagged(td, FIO_DISKLESSIO | FIO_NODISKUTIL)) return; for_each_file(td, f, i) diff --git a/filesetup.c b/filesetup.c index 42a9f415..5db44c29 100644 --- a/filesetup.c +++ b/filesetup.c @@ -52,7 +52,7 @@ static int extend_file(struct thread_data *td, struct fio_file *f) */ if (td_read(td) || (td_write(td) && td->o.overwrite && !td->o.file_append) || - (td_write(td) && td->io_ops->flags & FIO_NOEXTEND)) + (td_write(td) && td_ioengine_flagged(td, FIO_NOEXTEND))) new_layout = 1; if (td_write(td) && !td->o.overwrite && !td->o.file_append) unlink_file = 1; @@ -217,7 +217,7 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f) unsigned int bs; char *b; - if (td->io_ops->flags & FIO_PIPEIO) + if (td_ioengine_flagged(td, FIO_PIPEIO)) return 0; if (!fio_file_open(f)) { @@ -827,7 +827,7 @@ int setup_files(struct thread_data *td) * device/file sizes are zero and no size given, punt */ if ((!total_size || total_size == -1ULL) && !o->size && - !(td->io_ops->flags & FIO_NOIO) && !o->fill_device && + !td_ioengine_flagged(td, FIO_NOIO) && !o->fill_device && !(o->nr_files && (o->file_size_low || o->file_size_high))) { log_err("%s: you need to specify size=\n", o->name); td_verror(td, EINVAL, "total_file_size"); @@ -903,7 +903,7 @@ int setup_files(struct thread_data *td) if (f->filetype == FIO_TYPE_FILE && (f->io_size + f->file_offset) > f->real_file_size && - !(td->io_ops->flags & FIO_DISKLESSIO)) { + !td_ioengine_flagged(td, FIO_DISKLESSIO)) { if (!o->create_on_open) { need_extend++; extend_size += (f->io_size + f->file_offset); @@ -1374,7 +1374,7 @@ int add_file(struct thread_data *td, const char *fname, int numjob, int inc) /* * init function, io engine may not be loaded yet */ - if (td->io_ops && (td->io_ops->flags & FIO_DISKLESSIO)) + if (td->io_ops && td_ioengine_flagged(td, FIO_DISKLESSIO)) f->real_file_size = -1ULL; f->file_name = smalloc_strdup(file_name); diff --git a/fio.c b/fio.c index 69014ddb..7b3a50b6 100644 --- a/fio.c +++ b/fio.c @@ -32,6 +32,8 @@ int main(int argc, char *argv[], char *envp[]) { int ret = 1; + compiletime_assert(TD_NR <= TD_ENG_FLAG_SHIFT, "TD_ENG_FLAG_SHIFT"); + if (initialize_fio(envp)) return 1; diff --git a/fio.h b/fio.h index 33b43193..e96a4dd1 100644 --- a/fio.h +++ b/fio.h @@ -556,8 +556,27 @@ enum { TD_EXITED, TD_REAPED, TD_LAST, + TD_NR, }; +#define TD_ENG_FLAG_SHIFT 16 +#define TD_ENG_FLAG_MASK ((1U << 16) - 1) + +static inline enum fio_ioengine_flags td_ioengine_flags(struct thread_data *td) +{ + return (td->flags >> TD_ENG_FLAG_SHIFT) & TD_ENG_FLAG_MASK; +} + +static inline void td_set_ioengine_flags(struct thread_data *td) +{ + td->flags |= (td->io_ops->flags << TD_ENG_FLAG_SHIFT); +} + +static inline bool td_ioengine_flagged(struct thread_data *td, unsigned int val) +{ + return ((td->flags >> TD_ENG_FLAG_SHIFT) & val) != 0; +} + extern void td_set_runstate(struct thread_data *, int); extern int td_bump_runstate(struct thread_data *, int); extern void td_restore_runstate(struct thread_data *, int); diff --git a/init.c b/init.c index fb07daad..a1a00879 100644 --- a/init.c +++ b/init.c @@ -677,7 +677,7 @@ static int fixup_options(struct thread_data *td) "verify limited\n"); ret = warnings_fatal; } - if (o->bs_unaligned && (o->odirect || td->io_ops->flags & FIO_RAWIO)) + if (o->bs_unaligned && (o->odirect || td_ioengine_flagged(td, FIO_RAWIO))) log_err("fio: bs_unaligned may not work with raw io\n"); /* @@ -764,7 +764,7 @@ static int fixup_options(struct thread_data *td) if (o->pre_read) { o->invalidate_cache = 0; - if (td->io_ops->flags & FIO_PIPEIO) { + if (td_ioengine_flagged(td, FIO_PIPEIO)) { log_info("fio: cannot pre-read files with an IO engine" " that isn't seekable. Pre-read disabled.\n"); ret = warnings_fatal; @@ -772,7 +772,7 @@ static int fixup_options(struct thread_data *td) } if (!o->unit_base) { - if (td->io_ops->flags & FIO_BIT_BASED) + if (td_ioengine_flagged(td, FIO_BIT_BASED)) o->unit_base = 1; else o->unit_base = 8; @@ -795,7 +795,7 @@ static int fixup_options(struct thread_data *td) * Windows doesn't support O_DIRECT or O_SYNC with the _open interface, * so fail if we're passed those flags */ - if ((td->io_ops->flags & FIO_SYNCIO) && (td->o.odirect || td->o.sync_io)) { + if (td_ioengine_flagged(td, FIO_SYNCIO) && (td->o.odirect || td->o.sync_io)) { log_err("fio: Windows does not support direct or non-buffered io with" " the synchronous ioengines. Use the 'windowsaio' ioengine" " with 'direct=1' and 'iodepth=1' instead.\n"); @@ -844,7 +844,7 @@ static int fixup_options(struct thread_data *td) if (fio_option_is_set(&td->o, rand_seed)) td->o.rand_repeatable = 0; - if ((td->io_ops->flags & FIO_NOEXTEND) && td->o.file_append) { + if (td_ioengine_flagged(td, FIO_NOEXTEND) && td->o.file_append) { log_err("fio: can't append/extent with IO engine %s\n", td->io_ops->name); ret = 1; } @@ -1069,6 +1069,10 @@ int ioengine_load(struct thread_data *td) *(struct thread_data **)td->eo = td; } + if (td->o.odirect) + td->io_ops->flags |= FIO_RAWIO; + + td_set_ioengine_flags(td); return 0; } @@ -1340,9 +1344,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num, if (ioengine_load(td)) goto err; - if (o->odirect) - td->io_ops->flags |= FIO_RAWIO; - file_alloced = 0; if (!o->filename && !td->files_index && !o->read_iolog_file) { file_alloced = 1; @@ -1373,7 +1374,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num, if (td->eo) *(struct thread_data **)td->eo = NULL; - if (td->io_ops->flags & FIO_DISKLESSIO) { + if (td_ioengine_flagged(td, FIO_DISKLESSIO)) { struct fio_file *f; for_each_file(td, f, i) @@ -1537,7 +1538,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num, if (is_backend && !recursed) fio_server_send_add_job(td); - if (!(td->io_ops->flags & FIO_NOIO)) { + if (!td_ioengine_flagged(td, FIO_NOIO)) { char *c1, *c2, *c3, *c4; char *c5 = NULL, *c6 = NULL; diff --git a/io_u.c b/io_u.c index 34acc569..22701274 100644 --- a/io_u.c +++ b/io_u.c @@ -768,7 +768,7 @@ static void set_rw_ddir(struct thread_data *td, struct io_u *io_u) io_u->ddir = io_u->acct_ddir = ddir; - if (io_u->ddir == DDIR_WRITE && (td->io_ops->flags & FIO_BARRIER) && + if (io_u->ddir == DDIR_WRITE && td_ioengine_flagged(td, FIO_BARRIER) && td->o.barrier_blocks && !(td->io_issues[DDIR_WRITE] % td->o.barrier_blocks) && td->io_issues[DDIR_WRITE]) @@ -843,7 +843,7 @@ static int fill_io_u(struct thread_data *td, struct io_u *io_u) { unsigned int is_random; - if (td->io_ops->flags & FIO_NOIO) + if (td_ioengine_flagged(td, FIO_NOIO)) goto out; set_rw_ddir(td, io_u); @@ -1622,7 +1622,7 @@ struct io_u *get_io_u(struct thread_data *td) assert(fio_file_open(f)); if (ddir_rw(io_u->ddir)) { - if (!io_u->buflen && !(td->io_ops->flags & FIO_NOIO)) { + if (!io_u->buflen && !td_ioengine_flagged(td, FIO_NOIO)) { dprint(FD_IO, "get_io_u: zero buflen on %p\n", io_u); goto err_put; } diff --git a/ioengines.c b/ioengines.c index 1c7a93b4..ae55f951 100644 --- a/ioengines.c +++ b/ioengines.c @@ -272,7 +272,7 @@ int td_io_queue(struct thread_data *td, struct io_u *io_u) io_u->error = 0; io_u->resid = 0; - if (td->io_ops->flags & FIO_SYNCIO) { + if (td_ioengine_flagged(td, FIO_SYNCIO)) { if (fio_fill_issue_time(td)) fio_gettime(&io_u->issue_time, NULL); @@ -346,7 +346,7 @@ int td_io_queue(struct thread_data *td, struct io_u *io_u) } } - if ((td->io_ops->flags & FIO_SYNCIO) == 0) { + if (!td_ioengine_flagged(td, FIO_SYNCIO)) { if (fio_fill_issue_time(td)) fio_gettime(&io_u->issue_time, NULL); @@ -375,7 +375,7 @@ int td_io_init(struct thread_data *td) td->error = ret; } - if (!ret && (td->io_ops->flags & FIO_NOIO)) + if (!ret && td_ioengine_flagged(td, FIO_NOIO)) td->flags |= TD_F_NOIO; return ret; @@ -441,7 +441,7 @@ int td_io_open_file(struct thread_data *td, struct fio_file *f) } } - if (td->io_ops->flags & FIO_DISKLESSIO) + if (td_ioengine_flagged(td, FIO_DISKLESSIO)) goto done; if (td->o.invalidate_cache && file_invalidate_cache(td, f)) diff --git a/memory.c b/memory.c index af4d5ef8..91241175 100644 --- a/memory.c +++ b/memory.c @@ -215,13 +215,13 @@ int allocate_io_mem(struct thread_data *td) size_t total_mem; int ret = 0; - if (td->io_ops->flags & FIO_NOIO) + if (td_ioengine_flagged(td, FIO_NOIO)) return 0; total_mem = td->orig_buffer_size; if (td->o.odirect || td->o.mem_align || td->o.oatomic || - (td->io_ops->flags & FIO_MEMALIGN)) { + td_ioengine_flagged(td, FIO_MEMALIGN)) { total_mem += page_mask; if (td->o.mem_align && td->o.mem_align > page_size) total_mem += td->o.mem_align - page_size; diff --git a/rate-submit.c b/rate-submit.c index 48b7a58c..2efbdcba 100644 --- a/rate-submit.c +++ b/rate-submit.c @@ -110,9 +110,6 @@ static int io_workqueue_init_worker_fn(struct submit_worker *sw) if (ioengine_load(td)) goto err; - if (td->o.odirect) - td->io_ops->flags |= FIO_RAWIO; - td->pid = gettid(); INIT_FLIST_HEAD(&td->io_log_list); diff --git a/verify.c b/verify.c index 40cfbabf..3d9e2687 100644 --- a/verify.c +++ b/verify.c @@ -802,7 +802,7 @@ int verify_io_u(struct thread_data *td, struct io_u **io_u_ptr) * If the IO engine is faking IO (like null), then just pretend * we verified everything. */ - if (td->io_ops->flags & FIO_FAKEIO) + if (td_ioengine_flagged(td, FIO_FAKEIO)) return 0; if (io_u->flags & IO_U_F_TRIMMED) { -- 2.25.1