[PATCH] Reversed order of thinktime_blocks modulo operation
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index 28864bdf72ebf8c6f5d610e5e068c0d0cab5d506..dd52626469a0358cdbacc062d02058b19f148825 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -105,7 +105,7 @@ static int check_min_rate(struct thread_data *td, struct timeval *now)
 
                rate = (td->this_io_bytes[ddir] - td->rate_bytes) / spent;
                if (rate < td->ratemin) {
-                       fprintf(f_out, "%s: min rate %d not met, got %ldKiB/sec\n", td->name, td->ratemin, rate);
+                       fprintf(f_out, "%s: min rate %u not met, got %luKiB/sec\n", td->name, td->ratemin, rate);
                        return 1;
                }
        }
@@ -242,7 +242,7 @@ static int fio_io_sync(struct thread_data *td, struct fio_file *f)
  * The main verify engine. Runs over the writes we previusly submitted,
  * reads the blocks back in, and checks the crc/md5 of the data.
  */
-void do_verify(struct thread_data *td)
+static void do_verify(struct thread_data *td)
 {
        struct io_u *io_u, *v_io_u = NULL;
        struct io_completion_data icd;
@@ -379,7 +379,6 @@ static void do_io(struct thread_data *td)
        td_set_runstate(td, TD_RUNNING);
 
        while (td->this_io_bytes[td->ddir] < td->io_size) {
-               struct timespec ts = { .tv_sec = 0, .tv_nsec = 0};
                struct timespec *timeout;
                int min_evts = 0;
                struct io_u *io_u;
@@ -407,6 +406,8 @@ static void do_io(struct thread_data *td)
                add_slat_sample(td, io_u->ddir, mtime_since(&io_u->start_time, &io_u->issue_time));
 
                if (td->cur_depth < td->iodepth) {
+                       struct timespec ts = { .tv_sec = 0, .tv_nsec = 0};
+
                        timeout = &ts;
                        min_evts = 0;
                } else {
@@ -447,8 +448,13 @@ static void do_io(struct thread_data *td)
                if (runtime_exceeded(td, &icd.time))
                        break;
 
-               if (td->thinktime)
-                       usec_sleep(td, td->thinktime);
+               if (td->thinktime) {
+                       unsigned long long b;
+
+                       b = td->io_blocks[0] + td->io_blocks[1];
+                       if (!(b % td->thinktime_blocks))
+                               usec_sleep(td, td->thinktime);
+               }
        }
 
        if (!td->error) {
@@ -507,7 +513,12 @@ static int init_io_u(struct thread_data *td)
                max_units = td->iodepth;
 
        max_bs = max(td->max_bs[DDIR_READ], td->max_bs[DDIR_WRITE]);
-       td->orig_buffer_size = max_bs * max_units + MASK;
+       td->orig_buffer_size = max_bs * max_units;
+
+       if (td->mem_type == MEM_SHMHUGE || td->mem_type == MEM_MMAPHUGE)
+               td->orig_buffer_size = (td->orig_buffer_size + td->hugepage_size - 1) & ~(td->hugepage_size - 1);
+       else
+               td->orig_buffer_size += MASK;
 
        if (allocate_io_mem(td))
                return 1;
@@ -663,10 +674,10 @@ static void *thread_main(void *data)
                system(td->exec_prerun);
 
        fio_gettime(&td->epoch, NULL);
+       getrusage(RUSAGE_SELF, &td->ru_start);
 
        runtime[0] = runtime[1] = 0;
        while (td->loops--) {
-               getrusage(RUSAGE_SELF, &td->ru_start);
                fio_gettime(&td->start, NULL);
                memcpy(&td->stat_sample_time, &td->start, sizeof(td->start));
 
@@ -685,8 +696,6 @@ static void *thread_main(void *data)
                if (td_rw(td) && td->io_bytes[td->ddir ^ 1])
                        runtime[td->ddir ^ 1] = runtime[td->ddir];
 
-               update_rusage_stat(td);
-
                if (td->error || td->terminate)
                        break;
 
@@ -704,6 +713,7 @@ static void *thread_main(void *data)
                        break;
        }
 
+       update_rusage_stat(td);
        fio_gettime(&td->end_time, NULL);
        td->runtime[0] = runtime[0] / 1000;
        td->runtime[1] = runtime[1] / 1000;