io_u: tweak small content buffer scramble
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index 5e4209d3533252a965b7be6016d33300e3106db7..c25854273a68d279a9265ec1780cc4fc260da4d2 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -157,6 +157,66 @@ static int __get_next_rand_offset_gauss(struct thread_data *td,
        return 0;
 }
 
+static int __get_next_rand_offset_zoned_abs(struct thread_data *td,
+                                           struct fio_file *f,
+                                           enum fio_ddir ddir, uint64_t *b)
+{
+       struct zone_split_index *zsi;
+       uint64_t lastb, send, stotal;
+       static int warned;
+       unsigned int v;
+
+       lastb = last_block(td, f, ddir);
+       if (!lastb)
+               return 1;
+
+       if (!td->o.zone_split_nr[ddir]) {
+bail:
+               return __get_next_rand_offset(td, f, ddir, b, lastb);
+       }
+
+       /*
+        * Generate a value, v, between 1 and 100, both inclusive
+        */
+       v = rand32_between(&td->zone_state, 1, 100);
+
+       /*
+        * Find our generated table. 'send' is the end block of this zone,
+        * 'stotal' is our start offset.
+        */
+       zsi = &td->zone_state_index[ddir][v - 1];
+       stotal = zsi->size_prev / td->o.ba[ddir];
+       send = zsi->size / td->o.ba[ddir];
+
+       /*
+        * Should never happen
+        */
+       if (send == -1U) {
+               if (!warned) {
+                       log_err("fio: bug in zoned generation\n");
+                       warned = 1;
+               }
+               goto bail;
+       } else if (send > lastb) {
+               /*
+                * This happens if the user specifies ranges that exceed
+                * the file/device size. We can't handle that gracefully,
+                * so error and exit.
+                */
+               log_err("fio: zoned_abs sizes exceed file size\n");
+               return 1;
+       }
+
+       /*
+        * Generate index from 0..send-stotal
+        */
+       if (__get_next_rand_offset(td, f, ddir, b, send - stotal) == 1)
+               return 1;
+
+       *b += stotal;
+       return 0;
+}
+
 static int __get_next_rand_offset_zoned(struct thread_data *td,
                                        struct fio_file *f, enum fio_ddir ddir,
                                        uint64_t *b)
@@ -249,6 +309,8 @@ static int get_off_from_method(struct thread_data *td, struct fio_file *f,
                return __get_next_rand_offset_gauss(td, f, ddir, b);
        else if (td->o.random_distribution == FIO_RAND_DIST_ZONED)
                return __get_next_rand_offset_zoned(td, f, ddir, b);
+       else if (td->o.random_distribution == FIO_RAND_DIST_ZONED_ABS)
+               return __get_next_rand_offset_zoned_abs(td, f, ddir, b);
 
        log_err("fio: unknown random distribution: %d\n", td->o.random_distribution);
        return 1;
@@ -367,7 +429,7 @@ static int get_next_seq_offset(struct thread_data *td, struct fio_file *f,
         */
        if (f->last_pos[ddir] >= f->io_size + get_start_offset(td, f) &&
            o->time_based) {
-               f->last_pos[ddir] = 0;
+               f->last_pos[ddir] = f->file_offset;
                loop_cache_invalidate(td, f);
        }
 
@@ -1347,10 +1409,10 @@ static long set_io_u_file(struct thread_data *td, struct io_u *io_u)
 }
 
 static void lat_fatal(struct thread_data *td, struct io_completion_data *icd,
-                     unsigned long tusec, unsigned long max_usec)
+                     unsigned long long tnsec, unsigned long long max_nsec)
 {
        if (!td->error)
-               log_err("fio: latency of %lu usec exceeds specified max (%lu usec)\n", tusec, max_usec);
+               log_err("fio: latency of %llu nsec exceeds specified max (%llu nsec)\n", tnsec, max_nsec);
        td_verror(td, ETIMEDOUT, "max latency exceeded");
        icd->error = ETIMEDOUT;
 }
@@ -1611,8 +1673,8 @@ static bool check_get_verify(struct thread_data *td, struct io_u *io_u)
 static void small_content_scramble(struct io_u *io_u)
 {
        unsigned int i, nr_blocks = io_u->buflen / 512;
-       uint64_t boffset;
        unsigned int offset;
+       uint64_t boffset;
        char *p, *end;
 
        if (!nr_blocks)
@@ -1625,15 +1687,15 @@ static void small_content_scramble(struct io_u *io_u)
        for (i = 0; i < nr_blocks; i++) {
                /*
                 * Fill the byte offset into a "random" start offset of
-                * the buffer, given by the product of the usec time
-                * and the actual offset.
+                * the first half of the buffer.
                 */
-               offset = ((io_u->start_time.tv_nsec/1000) ^ boffset) & 511;
-               offset &= ~(sizeof(uint64_t) - 1);
-               if (offset >= 512 - sizeof(uint64_t))
-                       offset -= sizeof(uint64_t);
+               offset = (io_u->start_time.tv_nsec ^ boffset) & 255;
+               offset &= ~(sizeof(boffset) - 1);
                memcpy(p + offset, &boffset, sizeof(boffset));
 
+               /*
+                * Fill the start time into the end of the buffer
+                */
                end = p + 512 - sizeof(io_u->start_time);
                memcpy(end, &io_u->start_time, sizeof(io_u->start_time));
                p += 512;
@@ -1806,14 +1868,14 @@ static void account_io_completion(struct thread_data *td, struct io_u *io_u,
                        struct prof_io_ops *ops = &td->prof_io_ops;
 
                        if (ops->io_u_lat)
-                               icd->error = ops->io_u_lat(td, tnsec/1000);
+                               icd->error = ops->io_u_lat(td, tnsec);
                }
 
-               if (td->o.max_latency && tnsec/1000 > td->o.max_latency)
-                       lat_fatal(td, icd, tnsec/1000, td->o.max_latency);
-               if (td->o.latency_target && tnsec/1000 > td->o.latency_target) {
+               if (td->o.max_latency && tnsec > td->o.max_latency)
+                       lat_fatal(td, icd, tnsec, td->o.max_latency);
+               if (td->o.latency_target && tnsec > td->o.latency_target) {
                        if (lat_target_failed(td))
-                               lat_fatal(td, icd, tnsec/1000, td->o.latency_target);
+                               lat_fatal(td, icd, tnsec, td->o.latency_target);
                }
        }