lib/rand: improve __fill_random_buf()
authorJens Axboe <axboe@kernel.dk>
Fri, 1 Jul 2022 16:44:25 +0000 (10:44 -0600)
committerJens Axboe <axboe@kernel.dk>
Fri, 1 Jul 2022 16:54:50 +0000 (10:54 -0600)
This won't be equivalent to what we have, but I _think_ the randomness
is good enough for this purpose.

While in there, fixup the coding style to conform to fio standards,
and simplify the setup and loop.

This improves performance by about 30% for me, tested on both aarch64
and x86-64.

Link: https://github.com/axboe/fio/pull/1417
Signed-off-by: Jens Axboe <axboe@kernel.dk>
lib/rand.c

index e84cf65a8776036b5c78ff6871c660930f37ef1d..efcf93b4c55f9d072fb380088a03d23f98be5147 100644 (file)
@@ -97,18 +97,17 @@ void init_rand_seed(struct frand_state *state, uint64_t seed, bool use64)
 
 void __fill_random_buf(void *buf, unsigned int len, uint64_t seed)
 {
-    int64_t *b = buf;
-    int64_t *e = b  + len / sizeof *b;
-    unsigned int rest = len % sizeof *b;
-
-    for (int64_t *p = b; p != e; ++p) {
-        *p = seed;
-        seed *= GOLDEN_RATIO_PRIME;
-        seed >>= 3;
-    }
-
-    if (rest)
-        __builtin_memcpy(e, &seed, rest);
+       uint64_t *b = buf;
+       uint64_t *e = b  + len / sizeof(*b);
+       unsigned int rest = len % sizeof(*b);
+
+       while (b != e) {
+               *b++ = seed;
+               seed *= GOLDEN_RATIO_64;
+       }
+
+       if (fio_unlikely(rest))
+               __builtin_memcpy(e, &seed, rest);
 }
 
 uint64_t fill_random_buf(struct frand_state *fs, void *buf,