Split poisson rate control into read/write/trim
[fio.git] / backend.c
index c8c6de6d69c826867f2b482bfca6ebd1c211d602..86e689f838a00e752e8268ef6efda71fda156f00 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -76,9 +76,6 @@ int shm_id = 0;
 int temp_stall_ts;
 unsigned long done_secs = 0;
 
-#define PAGE_ALIGN(buf)        \
-       (char *) (((uintptr_t) (buf) + page_mask) & ~page_mask)
-
 #define JOB_START_TIMEOUT      (5 * 1000)
 
 static void sig_int(int sig)
@@ -779,8 +776,8 @@ static bool io_bytes_exceeded(struct thread_data *td, uint64_t *this_bytes)
        else
                bytes = this_bytes[DDIR_TRIM];
 
-       if (td->o.io_limit)
-               limit = td->o.io_limit;
+       if (td->o.io_size)
+               limit = td->o.io_size;
        else
                limit = td->o.size;
 
@@ -814,13 +811,13 @@ static long long usec_for_io(struct thread_data *td, enum fio_ddir ddir)
                uint64_t val;
                iops = bps / td->o.bs[ddir];
                val = (int64_t) (1000000 / iops) *
-                               -logf(__rand_0_1(&td->poisson_state));
+                               -logf(__rand_0_1(&td->poisson_state[ddir]));
                if (val) {
                        dprint(FD_RATE, "poisson rate iops=%llu\n",
                                        (unsigned long long) 1000000 / val);
                }
-               td->last_usec += val;
-               return td->last_usec;
+               td->last_usec[ddir] += val;
+               return td->last_usec[ddir];
        } else if (bps) {
                secs = bytes / bps;
                remainder = bytes % bps;
@@ -854,11 +851,11 @@ static void do_io(struct thread_data *td, uint64_t *bytes_done)
 
        total_bytes = td->o.size;
        /*
-       * Allow random overwrite workloads to write up to io_limit
+       * Allow random overwrite workloads to write up to io_size
        * before starting verification phase as 'size' doesn't apply.
        */
        if (td_write(td) && td_random(td) && td->o.norandommap)
-               total_bytes = max(total_bytes, (uint64_t) td->o.io_limit);
+               total_bytes = max(total_bytes, (uint64_t) td->o.io_size);
        /*
         * If verify_backlog is enabled, we'll run the verify in this
         * handler as well. For that case, we may need up to twice the
@@ -1198,7 +1195,7 @@ static int init_io_u(struct thread_data *td)
 
        if (td->o.odirect || td->o.mem_align || td->o.oatomic ||
            td_ioengine_flagged(td, FIO_RAWIO))
-               p = PAGE_ALIGN(td->orig_buffer) + td->o.mem_align;
+               p = PTR_ALIGN(td->orig_buffer, page_mask) + td->o.mem_align;
        else
                p = td->orig_buffer;
 
@@ -1264,6 +1261,10 @@ static int init_io_u(struct thread_data *td)
        return 0;
 }
 
+/*
+ * This function is Linux specific.
+ * FIO_HAVE_IOSCHED_SWITCH enabled currently means it's Linux.
+ */
 static int switch_ioscheduler(struct thread_data *td)
 {
 #ifdef FIO_HAVE_IOSCHED_SWITCH
@@ -1274,7 +1275,8 @@ static int switch_ioscheduler(struct thread_data *td)
        if (td_ioengine_flagged(td, FIO_DISKLESSIO))
                return 0;
 
-       sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
+       assert(td->files && td->files[0]);
+       sprintf(tmp, "%s/queue/scheduler", td->files[0]->du->sysfs_root);
 
        f = fopen(tmp, "r+");
        if (!f) {
@@ -1353,8 +1355,8 @@ static bool keep_running(struct thread_data *td)
        if (exceeds_number_ios(td))
                return false;
 
-       if (td->o.io_limit)
-               limit = td->o.io_limit;
+       if (td->o.io_size)
+               limit = td->o.io_size;
        else
                limit = td->o.size;
 
@@ -1362,14 +1364,14 @@ static bool keep_running(struct thread_data *td)
                uint64_t diff;
 
                /*
-                * If the difference is less than the minimum IO size, we
+                * If the difference is less than the maximum IO size, we
                 * are done.
                 */
                diff = limit - ddir_rw_sum(td->io_bytes);
                if (diff < td_max_bs(td))
                        return false;
 
-               if (fio_files_done(td) && !td->o.io_limit)
+               if (fio_files_done(td) && !td->o.io_size)
                        return false;
 
                return true;
@@ -1691,7 +1693,7 @@ static void *thread_main(void *data)
 
                prune_io_piece_log(td);
 
-               if (td->o.verify_only && (td_write(td) || td_rw(td)))
+               if (td->o.verify_only && td_write(td))
                        verify_bytes = do_dry_run(td);
                else {
                        uint64_t bytes_done[DDIR_RWDIR_CNT];
@@ -1834,9 +1836,6 @@ err:
        if (o->write_iolog_file)
                write_iolog_close(td);
 
-       fio_mutex_remove(td->mutex);
-       td->mutex = NULL;
-
        td_set_runstate(td, TD_EXITED);
 
        /*
@@ -2054,8 +2053,16 @@ static bool check_mount_writes(struct thread_data *td)
        if (!td_write(td) || td->o.allow_mounted_write)
                return false;
 
+       /*
+        * If FIO_HAVE_CHARDEV_SIZE is defined, it's likely that chrdevs
+        * are mkfs'd and mounted.
+        */
        for_each_file(td, f, i) {
-               if (f->filetype != FIO_TYPE_BD)
+#ifdef FIO_HAVE_CHARDEV_SIZE
+               if (f->filetype != FIO_TYPE_BLOCK && f->filetype != FIO_TYPE_CHAR)
+#else
+               if (f->filetype != FIO_TYPE_BLOCK)
+#endif
                        continue;
                if (device_is_mounted(f->file_name))
                        goto mounted;
@@ -2063,7 +2070,7 @@ static bool check_mount_writes(struct thread_data *td)
 
        return false;
 mounted:
-       log_err("fio: %s appears mounted, and 'allow_mounted_write' isn't set. Aborting.", f->file_name);
+       log_err("fio: %s appears mounted, and 'allow_mounted_write' isn't set. Aborting.\n", f->file_name);
        return true;
 }
 
@@ -2425,6 +2432,8 @@ int fio_backend(struct sk_out *sk_out)
                        fio_mutex_remove(td->rusage_sem);
                        td->rusage_sem = NULL;
                }
+               fio_mutex_remove(td->mutex);
+               td->mutex = NULL;
        }
 
        free_disk_util();