From 76c37788d45145b00004b4ef09856c8c3892006a Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 1 Jul 2022 10:44:25 -0600 Subject: [PATCH] lib/rand: improve __fill_random_buf() 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 --- lib/rand.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/rand.c b/lib/rand.c index e84cf65a..efcf93b4 100644 --- a/lib/rand.c +++ b/lib/rand.c @@ -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, -- 2.25.1