t/zbd: fix wrong units in test case #37
[fio.git] / backend.c
index a4367672d68ce80c88dc828245c2467aa1f6917c..f2efddd67d365dc9c4300892275caaa88796a2e1 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -62,8 +62,9 @@ struct io_log *agg_io_log[DDIR_RWDIR_CNT];
 
 int groupid = 0;
 unsigned int thread_number = 0;
+unsigned int nr_segments = 0;
+unsigned int cur_segment = 0;
 unsigned int stat_number = 0;
-int shm_id = 0;
 int temp_stall_ts;
 unsigned long done_secs = 0;
 #ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
@@ -76,7 +77,7 @@ pthread_mutex_t overlap_check = PTHREAD_MUTEX_INITIALIZER;
 
 static void sig_int(int sig)
 {
-       if (threads) {
+       if (nr_segments) {
                if (is_backend)
                        fio_server_got_signal(sig);
                else {
@@ -438,7 +439,7 @@ static int wait_for_completions(struct thread_data *td, struct timespec *time)
        if ((full && !min_evts) || !td->o.iodepth_batch_complete_min)
                min_evts = 1;
 
-       if (time && __should_check_rate(td))
+       if (time && should_check_rate(td))
                fio_gettime(time, NULL);
 
        do {
@@ -493,7 +494,7 @@ int io_queue_event(struct thread_data *td, struct io_u *io_u, int *ret,
                        requeue_io_u(td, &io_u);
                } else {
 sync_done:
-                       if (comp_time && __should_check_rate(td))
+                       if (comp_time && should_check_rate(td))
                                fio_gettime(comp_time, NULL);
 
                        *ret = io_u_sync_complete(td, io_u);
@@ -857,14 +858,15 @@ static long long usec_for_io(struct thread_data *td, enum fio_ddir ddir)
        return 0;
 }
 
-static void handle_thinktime(struct thread_data *td, enum fio_ddir ddir)
+static void handle_thinktime(struct thread_data *td, enum fio_ddir ddir,
+                            struct timespec *time)
 {
        unsigned long long b;
        uint64_t total;
        int left;
 
-       b = ddir_rw_sum(td->io_blocks);
-       if (b % td->o.thinktime_blocks)
+       b = ddir_rw_sum(td->thinktime_blocks_counter);
+       if (b % td->o.thinktime_blocks || !b)
                return;
 
        io_u_quiesce(td);
@@ -897,6 +899,9 @@ static void handle_thinktime(struct thread_data *td, enum fio_ddir ddir)
                /* adjust for rate_process=poisson */
                td->last_usec[ddir] += total;
        }
+
+       if (time && should_check_rate(td))
+               fio_gettime(time, NULL);
 }
 
 /*
@@ -1075,6 +1080,10 @@ reap:
                }
                if (ret < 0)
                        break;
+
+               if (ddir_rw(ddir) && td->o.thinktime)
+                       handle_thinktime(td, ddir, &comp_time);
+
                if (!ddir_rw_sum(td->bytes_done) &&
                    !td_ioengine_flagged(td, FIO_NOIO))
                        continue;
@@ -1089,9 +1098,6 @@ reap:
                }
                if (!in_ramp_time(td) && td->o.latency_target)
                        lat_target_check(td);
-
-               if (ddir_rw(ddir) && td->o.thinktime)
-                       handle_thinktime(td, ddir);
        }
 
        check_update_rusage(td);
@@ -1458,16 +1464,17 @@ static bool keep_running(struct thread_data *td)
        return false;
 }
 
-static int exec_string(struct thread_options *o, const char *string, const char *mode)
+static int exec_string(struct thread_options *o, const char *string,
+                      const char *mode)
 {
-       size_t newlen = strlen(string) + strlen(o->name) + strlen(mode) + 13 + 1;
        int ret;
        char *str;
 
-       str = malloc(newlen);
-       sprintf(str, "%s > %s.%s.txt 2>&1", string, o->name, mode);
+       if (asprintf(&str, "%s > %s.%s.txt 2>&1", string, o->name, mode) < 0)
+               return -1;
 
-       log_info("%s : Saving output of %s in %s.%s.txt\n",o->name, mode, o->name, mode);
+       log_info("%s : Saving output of %s in %s.%s.txt\n", o->name, mode,
+                o->name, mode);
        ret = system(str);
        if (ret == -1)
                log_err("fio: exec of cmd <%s> failed\n", str);
@@ -1731,7 +1738,7 @@ static void *thread_main(void *data)
        if (!init_random_map(td))
                goto err;
 
-       if (o->exec_prerun && exec_string(o, o->exec_prerun, (const char *)"prerun"))
+       if (o->exec_prerun && exec_string(o, o->exec_prerun, "prerun"))
                goto err;
 
        if (o->pre_read && !pre_read_files(td))
@@ -1742,6 +1749,11 @@ static void *thread_main(void *data)
        if (rate_submit_init(td, sk_out))
                goto err;
 
+       if (td->o.thinktime_blocks_type == THINKTIME_BLOCKS_TYPE_COMPLETE)
+               td->thinktime_blocks_counter = td->io_blocks;
+       else
+               td->thinktime_blocks_counter = td->io_issues;
+
        set_epoch_time(td, o->log_unix_epoch);
        fio_getrusage(&td->ru_start);
        memcpy(&td->bw_sample_time, &td->epoch, sizeof(td->epoch));
@@ -1890,7 +1902,7 @@ static void *thread_main(void *data)
        rate_submit_exit(td);
 
        if (o->exec_postrun)
-               exec_string(o, o->exec_postrun, (const char *)"postrun");
+               exec_string(o, o->exec_postrun, "postrun");
 
        if (exitall_on_terminate || (o->exitall_error && td->error))
                fio_terminate_threads(td->groupid, td->o.exit_what);
@@ -2042,6 +2054,7 @@ reaped:
 
                done_secs += mtime_since_now(&td->epoch) / 1000;
                profile_td_exit(td);
+               flow_exit_job(td);
        }
 
        if (*nr_running == cputhreads && !pending && realthreads)