Speedup verify random fills by 10-15x
authorJens Axboe <jaxboe@fusionio.com>
Mon, 21 Jun 2010 18:39:38 +0000 (20:39 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Mon, 21 Jun 2010 18:39:38 +0000 (20:39 +0200)
Move the pseudo-random helper into lib/rand.c and use that
from the verify populate as well.

Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
io_u.c
lib/rand.c
lib/rand.h
verify.c

diff --git a/io_u.c b/io_u.c
index f451d1a756141e3a29eaad8f3f2fb74d113ae82e..69edd70e5eafbb97ce3f5f915ee50450fcc90ac6 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -1240,20 +1240,8 @@ void io_u_queued(struct thread_data *td, struct io_u *io_u)
 void io_u_fill_buffer(struct thread_data *td, struct io_u *io_u,
                      unsigned int max_bs)
 {
-       long *ptr = io_u->buf;
-
-       if (!td->o.zero_buffers) {
-               unsigned long r = __rand(&__fio_rand_state);
-
-               if (sizeof(int) != sizeof(*ptr))
-                       r *= (unsigned long) __rand(&__fio_rand_state);
-
-               while ((void *) ptr - io_u->buf < max_bs) {
-                       *ptr = r;
-                       ptr++;
-                       r *= GOLDEN_RATIO_PRIME;
-                       r >>= 3;
-               }
-       } else
-               memset(ptr, 0, max_bs);
+       if (!td->o.zero_buffers)
+               fill_random_buf(io_u->buf, max_bs);
+       else
+               memset(io_u->buf, 0, max_bs);
 }
index cecc4c21ea90a28775f6e187a24c52429ab4f2f5..839a6a9476c82cedad1de30067ab06c776d750bd 100644 (file)
@@ -34,6 +34,7 @@
 */
 
 #include "rand.h"
+#include "../hash.h"
 
 struct frand_state __fio_rand_state;
 
@@ -57,3 +58,19 @@ void init_rand(struct frand_state *state)
        __rand(state);
        __rand(state);
 }
+
+void fill_random_buf(void *buf, unsigned int len)
+{
+       unsigned long r = __rand(&__fio_rand_state);
+       long *ptr = buf;
+
+       if (sizeof(int) != sizeof(*ptr))
+               r *= (unsigned long) __rand(&__fio_rand_state);
+
+       while ((void *) ptr - buf < len) {
+               *ptr = r;
+               ptr++;
+               r *= GOLDEN_RATIO_PRIME;
+               r >>= 3;
+       }
+}
index 363e7b6d9651d5970c9b7b8592f61a9bc0a0962b..573116cbc2f7ec097bda77d97a3a0d669d30558f 100644 (file)
@@ -19,5 +19,6 @@ static inline unsigned int __rand(struct frand_state *state)
 }
 
 extern void init_rand(struct frand_state *);
+extern void fill_random_buf(void *buf, unsigned int len);
 
 #endif
index 6b54b70ff672ffd3c75f7e0b3b72d35592c1e91c..265bd5563210bcb1db2cadd69c127e8f4c79869f 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -10,6 +10,7 @@
 #include "fio.h"
 #include "verify.h"
 #include "smalloc.h"
+#include "lib/rand.h"
 
 #include "crc/md5.h"
 #include "crc/crc64.h"
 #include "crc/sha512.h"
 #include "crc/sha1.h"
 
-static void fill_random_bytes(struct thread_data *td, void *p, unsigned int len)
-{
-       unsigned int todo;
-       int r;
-
-       while (len) {
-               r = os_random_long(&td->verify_state);
-
-               /*
-                * lrand48_r seems to be broken and only fill the bottom
-                * 32-bits, even on 64-bit archs with 64-bit longs
-                */
-               todo = sizeof(r);
-               if (todo > len)
-                       todo = len;
-
-               memcpy(p, &r, todo);
-
-               len -= todo;
-               p += todo;
-       }
-}
-
 static void fill_pattern(struct thread_data *td, void *p, unsigned int len)
 {
        switch (td->o.verify_pattern_bytes) {
        case 0:
                dprint(FD_VERIFY, "fill random bytes len=%u\n", len);
-               fill_random_bytes(td, p, len);
+               fill_random_buf(p, len);
                break;
        case 1:
                dprint(FD_VERIFY, "fill verify pattern b=0 len=%u\n", len);