X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=backend.c;h=fcb74dcbcfc3d39b7916c3c1f2f8fcb43127e889;hp=6461fff70c21aa37192d3c2dd40a1831543b7a05;hb=a03fb65f4e5d657ee3bb68309cfa70ae2d5bc44b;hpb=5bd5f71a3e54950fb4bee64c7ad5edc67e40b8c8 diff --git a/backend.c b/backend.c index 6461fff7..fcb74dcb 100644 --- a/backend.c +++ b/backend.c @@ -34,12 +34,12 @@ #include #include #include -#ifndef FIO_NO_HAVE_SHM_H -#include -#endif #include #include "fio.h" +#ifndef FIO_NO_HAVE_SHM_H +#include +#endif #include "hash.h" #include "smalloc.h" #include "verify.h" @@ -322,6 +322,21 @@ requeue: return 0; } +static int fio_file_fsync(struct thread_data *td, struct fio_file *f) +{ + int ret; + + if (fio_file_open(f)) + return fio_io_sync(td, f); + + if (td_io_open_file(td, f)) + return 1; + + ret = fio_io_sync(td, f); + td_io_close_file(td, f); + return ret; +} + static inline void __update_tv_cache(struct thread_data *td) { fio_gettime(&td->tv_cache, NULL); @@ -391,6 +406,15 @@ static int break_on_this_error(struct thread_data *td, enum fio_ddir ddir, return 0; } +static void check_update_rusage(struct thread_data *td) +{ + if (td->update_rusage) { + td->update_rusage = 0; + update_rusage_stat(td); + fio_mutex_up(td->rusage_sem); + } +} + /* * The main verify engine. Runs over the writes we previously submitted, * reads the blocks back in, and checks the crc/md5 of the data. @@ -418,6 +442,8 @@ static void do_verify(struct thread_data *td, uint64_t verify_bytes) break; } + check_update_rusage(td); + if (td->error) return; @@ -429,6 +455,7 @@ static void do_verify(struct thread_data *td, uint64_t verify_bytes) int ret2, full; update_tv_cache(td); + check_update_rusage(td); if (runtime_exceeded(td, &td->tv_cache)) { __update_tv_cache(td); @@ -582,6 +609,8 @@ sync_done: break; } + check_update_rusage(td); + if (!td->error) { min_events = td->cur_depth; @@ -637,6 +666,8 @@ static uint64_t do_io(struct thread_data *td) int ret2, full; enum fio_ddir ddir; + check_update_rusage(td); + if (td->terminate || td->done) break; @@ -801,6 +832,8 @@ sync_done: } } + check_update_rusage(td); + if (td->trim_entries) log_err("fio: %d trim entries leaked?\n", td->trim_entries); @@ -822,9 +855,11 @@ sync_done: td_set_runstate(td, TD_FSYNCING); for_each_file(td, f, i) { - if (!fio_file_open(f)) + if (!fio_file_fsync(td, f)) continue; - fio_io_sync(td, f); + + log_err("fio: end_fsync failed for file %s\n", + f->file_name); } } } else @@ -867,8 +902,7 @@ static int init_io_u(struct thread_data *td) char *p; max_units = td->o.iodepth; - max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]); - max_bs = max(td->o.max_bs[DDIR_TRIM], max_bs); + max_bs = td_max_bs(td); min_write = td->o.min_bs[DDIR_WRITE]; td->orig_buffer_size = (unsigned long long) max_bs * (unsigned long long) max_units; @@ -1017,7 +1051,7 @@ static int keep_running(struct thread_data *td) return 1; } - if (ddir_rw_sum(td->io_bytes) < td->o.size) { + if (td->o.size != -1ULL && ddir_rw_sum(td->io_bytes) < td->o.size) { uint64_t diff; /* @@ -1025,7 +1059,7 @@ static int keep_running(struct thread_data *td) * are done. */ diff = td->o.size - ddir_rw_sum(td->io_bytes); - if (diff < td->o.rw_min_bs) + if (diff < td_max_bs(td)) return 0; return 1; @@ -1363,6 +1397,9 @@ err: if (td->o.write_iolog_file) write_iolog_close(td); + fio_mutex_remove(td->rusage_sem); + td->rusage_sem = NULL; + td_set_runstate(td, TD_EXITED); return (void *) (uintptr_t) td->error; } @@ -1611,6 +1648,9 @@ static void run_threads(void) init_disk_util(td); + td->rusage_sem = fio_mutex_init(FIO_MUTEX_LOCKED); + td->update_rusage = 0; + /* * Set state to created. Thread will transition * to TD_INITIALIZED when it's done setting up.