X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=backend.c;h=902414ef8cfe23669a7c3e8ca43b0b879affd984;hp=39d13a330581e91974c4f04b36f187b149ff180b;hb=bcd5abfa9f230bbe4365dad1289fdea1f5509f74;hpb=8b28bd41375930664a0ff9ff9b101a88ac416ac5 diff --git a/backend.c b/backend.c index 39d13a33..902414ef 100644 --- a/backend.c +++ b/backend.c @@ -34,7 +34,9 @@ #include #include #include +#ifndef FIO_NO_HAVE_SHM_H #include +#endif #include #include "fio.h" @@ -62,11 +64,13 @@ struct io_log *agg_io_log[DDIR_RWDIR_CNT]; int groupid = 0; unsigned int thread_number = 0; +unsigned int stat_number = 0; unsigned int nr_process = 0; unsigned int nr_thread = 0; int shm_id = 0; int temp_stall_ts; unsigned long done_secs = 0; +volatile int disk_util_exit = 0; #define PAGE_ALIGN(buf) \ (char *) (((uintptr_t) (buf) + page_mask) & ~page_mask) @@ -107,6 +111,14 @@ static void set_sig_handlers(void) act.sa_flags = SA_RESTART; sigaction(SIGTERM, &act, NULL); +/* Windows uses SIGBREAK as a quit signal from other applications */ +#ifdef WIN32 + memset(&act, 0, sizeof(act)); + act.sa_handler = sig_int; + act.sa_flags = SA_RESTART; + sigaction(SIGBREAK, &act, NULL); +#endif + memset(&act, 0, sizeof(act)); act.sa_handler = sig_show_status; act.sa_flags = SA_RESTART; @@ -410,6 +422,7 @@ static void do_verify(struct thread_data *td) io_u = NULL; while (!td->terminate) { + enum fio_ddir ddir; int ret2, full; update_tv_cache(td); @@ -425,18 +438,50 @@ static void do_verify(struct thread_data *td) if (flow_threshold_exceeded(td)) continue; - io_u = __get_io_u(td); - if (!io_u) - break; + if (!td->o.experimental_verify) { + io_u = __get_io_u(td); + if (!io_u) + break; - if (get_next_verify(td, io_u)) { - put_io_u(td, io_u); - break; - } + if (get_next_verify(td, io_u)) { + put_io_u(td, io_u); + break; + } - if (td_io_prep(td, io_u)) { - put_io_u(td, io_u); - break; + if (td_io_prep(td, io_u)) { + put_io_u(td, io_u); + break; + } + } else { + while ((io_u = get_io_u(td)) != NULL) { + /* + * We are only interested in the places where + * we wrote or trimmed IOs. Turn those into + * reads for verification purposes. + */ + if (io_u->ddir == DDIR_READ) { + /* + * Pretend we issued it for rwmix + * accounting + */ + td->io_issues[DDIR_READ]++; + put_io_u(td, io_u); + continue; + } else if (io_u->ddir == DDIR_TRIM) { + io_u->ddir = DDIR_READ; + io_u->flags |= IO_U_F_TRIMMED; + break; + } else if (io_u->ddir == DDIR_WRITE) { + io_u->ddir = DDIR_READ; + break; + } else { + put_io_u(td, io_u); + continue; + } + } + + if (!io_u) + break; } if (td->o.verify_async) @@ -444,6 +489,8 @@ static void do_verify(struct thread_data *td) else io_u->end_io = verify_io_u; + ddir = io_u->ddir; + ret = td_io_queue(td, io_u); switch (ret) { case FIO_Q_COMPLETED: @@ -495,7 +542,7 @@ sync_done: break; } - if (break_on_this_error(td, io_u->ddir, &ret)) + if (break_on_this_error(td, ddir, &ret)) break; /* @@ -582,7 +629,7 @@ static void do_io(struct thread_data *td) int ret2, full; enum fio_ddir ddir; - if (td->terminate) + if (td->terminate || td->done) break; update_tv_cache(td); @@ -717,7 +764,7 @@ sync_done: if (ret < 0) break; - if (!ddir_rw_sum(bytes_done)) + if (!ddir_rw_sum(bytes_done) && !(td->io_ops->flags & FIO_NOIO)) continue; if (!in_ramp_time(td) && should_check_rate(td, bytes_done)) { @@ -791,6 +838,10 @@ static void cleanup_io_u(struct thread_data *td) io_u = flist_entry(entry, struct io_u, list); flist_del(&io_u->list); + + if (td->io_ops->io_u_free) + td->io_ops->io_u_free(td, io_u); + fio_memfree(io_u, sizeof(*io_u)); } @@ -802,6 +853,7 @@ static int init_io_u(struct thread_data *td) struct io_u *io_u; unsigned int max_bs, min_write; int cl_align, i, max_units; + int data_xfer = 1; char *p; max_units = td->o.iodepth; @@ -811,6 +863,9 @@ 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))) + data_xfer = 0; + if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) { unsigned long bs; @@ -823,7 +878,7 @@ static int init_io_u(struct thread_data *td) return 1; } - if (allocate_io_mem(td)) + if (data_xfer && allocate_io_mem(td)) return 1; if (td->o.odirect || td->o.mem_align || @@ -851,7 +906,7 @@ static int init_io_u(struct thread_data *td) INIT_FLIST_HEAD(&io_u->list); dprint(FD_MEM, "io_u alloc %p, index %u\n", io_u, i); - if (!(td->io_ops->flags & FIO_NOIO)) { + if (data_xfer) { io_u->buf = p; dprint(FD_MEM, "io_u %p, mem %p\n", io_u, io_u->buf); @@ -869,6 +924,16 @@ static int init_io_u(struct thread_data *td) io_u->index = i; io_u->flags = IO_U_F_FREE; flist_add(&io_u->list, &td->io_u_freelist); + + if (td->io_ops->io_u_init) { + int ret = td->io_ops->io_u_init(td, io_u); + + if (ret) { + log_err("fio: failed to init engine data: %d\n", ret); + return 1; + } + } + p += max_bs; } @@ -981,6 +1046,8 @@ static void *thread_main(void *data) } else td->pid = gettid(); + fio_local_clock_init(td->o.use_thread); + dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid); INIT_FLIST_HEAD(&td->io_u_freelist); @@ -990,6 +1057,7 @@ static void *thread_main(void *data) INIT_FLIST_HEAD(&td->io_hist_list); INIT_FLIST_HEAD(&td->verify_list); INIT_FLIST_HEAD(&td->trim_list); + INIT_FLIST_HEAD(&td->next_rand_list); pthread_mutex_init(&td->io_u_lock, NULL); td->io_hist_tree = RB_ROOT; @@ -1039,6 +1107,49 @@ static void *thread_main(void *data) goto err; } +#ifdef CONFIG_LIBNUMA + /* numa node setup */ + if (td->o.numa_cpumask_set || td->o.numa_memmask_set) { + int ret; + + if (numa_available() < 0) { + td_verror(td, errno, "Does not support NUMA API\n"); + goto err; + } + + if (td->o.numa_cpumask_set) { + ret = numa_run_on_node_mask(td->o.numa_cpunodesmask); + if (ret == -1) { + td_verror(td, errno, \ + "numa_run_on_node_mask failed\n"); + goto err; + } + } + + if (td->o.numa_memmask_set) { + + switch (td->o.numa_mem_mode) { + case MPOL_INTERLEAVE: + numa_set_interleave_mask(td->o.numa_memnodesmask); + break; + case MPOL_BIND: + numa_set_membind(td->o.numa_memnodesmask); + break; + case MPOL_LOCAL: + numa_set_localalloc(); + break; + case MPOL_PREFERRED: + numa_set_preferred(td->o.numa_mem_prefer_node); + break; + case MPOL_DEFAULT: + default: + break; + } + + } + } +#endif + /* * May alter parameters that init_io_u() will use, so we need to * do this first. @@ -1214,8 +1325,8 @@ err: verify_async_exit(td); close_and_free_files(td); - close_ioengine(td); cleanup_io_u(td); + close_ioengine(td); cgroup_shutdown(td, &cgroup_mnt); if (td->o.cpumask_set) { @@ -1326,7 +1437,7 @@ static void reap_threads(unsigned int *nr_running, unsigned int *t_rate, if (WIFSIGNALED(status)) { int sig = WTERMSIG(status); - if (sig != SIGTERM) + if (sig != SIGTERM && sig != SIGUSR2) log_err("fio: pid=%d, got signal=%d\n", (int) td->pid, sig); td->sig = sig; @@ -1606,6 +1717,13 @@ void wait_for_disk_thread_exit(void) fio_mutex_down(disk_thread_mutex); } +static void free_disk_util(void) +{ + disk_util_start_exit(); + wait_for_disk_thread_exit(); + disk_util_prune_entries(); +} + static void *disk_thread_main(void *data) { int ret = 0;