rand: add 64-bit tausworthe variant with a 2^258 cycle
[fio.git] / backend.c
index 65a3e184a6d77d7d5439f23c9a4c17813a405326..2aa88403da00600c5a1b8713572aa5840eb7dba3 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -55,6 +55,7 @@
 #include "err.h"
 #include "lib/tp.h"
 #include "workqueue.h"
+#include "lib/mountcheck.h"
 
 static pthread_t helper_thread;
 static pthread_mutex_t helper_lock;
@@ -363,6 +364,20 @@ static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
        return 0;
 }
 
+/*
+ * We need to update the runtime consistently in ms, but keep a running
+ * tally of the current elapsed time in microseconds for sub millisecond
+ * updates.
+ */
+static inline void update_runtime(struct thread_data *td,
+                                 unsigned long long *elapsed_us,
+                                 const enum fio_ddir ddir)
+{
+       td->ts.runtime[ddir] -= (elapsed_us[ddir] + 999) / 1000;
+       elapsed_us[ddir] += utime_since_now(&td->start);
+       td->ts.runtime[ddir] += (elapsed_us[ddir] + 999) / 1000;
+}
+
 static int break_on_this_error(struct thread_data *td, enum fio_ddir ddir,
                               int *retptr)
 {
@@ -428,7 +443,7 @@ static int wait_for_completions(struct thread_data *td, struct timeval *time)
         * if the queue is full, we MUST reap at least 1 event
         */
        min_evts = min(td->o.iodepth_batch_complete, td->cur_depth);
-       if (full && !min_evts)
+    if ((full && !min_evts) || !td->o.iodepth_batch_complete)
                min_evts = 1;
 
        if (time && (__should_check_rate(td, DDIR_READ) ||
@@ -1306,7 +1321,7 @@ static void io_workqueue_fn(struct thread_data *td, struct io_u *io_u)
  */
 static void *thread_main(void *data)
 {
-       unsigned long long elapsed;
+       unsigned long long elapsed_us[DDIR_RWDIR_CNT] = { 0, };
        struct thread_data *td = data;
        struct thread_options *o = &td->o;
        pthread_condattr_t attr;
@@ -1544,18 +1559,12 @@ static void *thread_main(void *data)
                check_update_rusage(td);
 
                fio_mutex_down(stat_mutex);
-               if (td_read(td) && td->io_bytes[DDIR_READ]) {
-                       elapsed = mtime_since_now(&td->start);
-                       td->ts.runtime[DDIR_READ] += elapsed;
-               }
-               if (td_write(td) && td->io_bytes[DDIR_WRITE]) {
-                       elapsed = mtime_since_now(&td->start);
-                       td->ts.runtime[DDIR_WRITE] += elapsed;
-               }
-               if (td_trim(td) && td->io_bytes[DDIR_TRIM]) {
-                       elapsed = mtime_since_now(&td->start);
-                       td->ts.runtime[DDIR_TRIM] += elapsed;
-               }
+               if (td_read(td) && td->io_bytes[DDIR_READ])
+                       update_runtime(td, elapsed_us, DDIR_READ);
+               if (td_write(td) && td->io_bytes[DDIR_WRITE])
+                       update_runtime(td, elapsed_us, DDIR_WRITE);
+               if (td_trim(td) && td->io_bytes[DDIR_TRIM])
+                       update_runtime(td, elapsed_us, DDIR_TRIM);
                fio_gettime(&td->start, NULL);
                fio_mutex_up(stat_mutex);
 
@@ -1579,7 +1588,7 @@ static void *thread_main(void *data)
                check_update_rusage(td);
 
                fio_mutex_down(stat_mutex);
-               td->ts.runtime[DDIR_READ] += mtime_since_now(&td->start);
+               update_runtime(td, elapsed_us, DDIR_READ);
                fio_gettime(&td->start, NULL);
                fio_mutex_up(stat_mutex);
 
@@ -1869,11 +1878,12 @@ static int fio_verify_load_state(struct thread_data *td)
 
        if (is_backend) {
                void *data;
+               int ver;
 
                ret = fio_server_get_verify_state(td->o.name,
-                                       td->thread_number - 1, &data);
+                                       td->thread_number - 1, &data, &ver);
                if (!ret)
-                       verify_convert_assign_state(td, data);
+                       verify_convert_assign_state(td, data, ver);
        } else
                ret = verify_load_state(td, "local");
 
@@ -1887,6 +1897,27 @@ static void do_usleep(unsigned int usecs)
        usleep(usecs);
 }
 
+static int check_mount_writes(struct thread_data *td)
+{
+       struct fio_file *f;
+       unsigned int i;
+
+       if (!td_write(td) || td->o.allow_mounted_write)
+               return 0;
+
+       for_each_file(td, f, i) {
+               if (f->filetype != FIO_TYPE_BD)
+                       continue;
+               if (device_is_mounted(f->file_name))
+                       goto mounted;
+       }
+
+       return 0;
+mounted:
+       log_err("fio: %s appears mounted, and 'allow_mounted_write' isn't set. Aborting.", f->file_name);
+       return 1;
+}
+
 /*
  * Main function for kicking off and reaping jobs, as needed.
  */
@@ -1905,6 +1936,8 @@ static void run_threads(void)
 
        nr_thread = nr_process = 0;
        for_each_td(td, i) {
+               if (check_mount_writes(td))
+                       return;
                if (td->o.use_thread)
                        nr_thread++;
                else
@@ -2253,7 +2286,7 @@ int fio_backend(void)
                        for (i = 0; i < DDIR_RWDIR_CNT; i++) {
                                struct io_log *log = agg_io_log[i];
 
-                               flush_log(log);
+                               flush_log(log, 0);
                                free_log(log);
                        }
                }