io_u: tweak small content buffer scramble
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index e1e4495202cb22fe8e589541e8704a37f4e11d36..c25854273a68d279a9265ec1780cc4fc260da4d2 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -1409,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;
 }
@@ -1673,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, usec;
        unsigned int offset;
+       uint64_t boffset;
        char *p, *end;
 
        if (!nr_blocks)
@@ -1684,21 +1684,18 @@ static void small_content_scramble(struct io_u *io_u)
        boffset = io_u->offset;
        io_u->buf_filled_len = 0;
 
-       /* close enough for this purpose */
-       usec = io_u->start_time.tv_nsec >> 10;
-
        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 = (usec ^ 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;
@@ -1871,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);
                }
        }