Ensure that buffer contents are random across jobs as well
authorJens Axboe <jaxboe@fusionio.com>
Wed, 31 Aug 2011 21:20:15 +0000 (15:20 -0600)
committerJens Axboe <jaxboe@fusionio.com>
Wed, 31 Aug 2011 21:20:15 +0000 (15:20 -0600)
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
fio.c
fio.h
init.c
io_u.c
lib/rand.c
lib/rand.h
verify.c

diff --git a/fio.c b/fio.c
index 9c1bed379df586ba8f3efea187aaaf319ce2d387..4514840dbb11027da8127a64e379ddb21d7acd4f 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -874,9 +874,9 @@ static int init_io_u(struct thread_data *td)
                        io_u->buf = p + max_bs * i;
                        dprint(FD_MEM, "io_u %p, mem %p\n", io_u, io_u->buf);
 
-                       if (td_write(td) && !td->o.refill_buffers)
+                       if (td_write(td))
                                io_u_fill_buffer(td, io_u, max_bs);
-                       else if (td_write(td) && td->o.verify_pattern_bytes) {
+                       if (td_write(td) && td->o.verify_pattern_bytes) {
                                /*
                                 * Fill the buffer with the pattern if we are
                                 * going to be doing writes.
@@ -1699,7 +1699,6 @@ int main(int argc, char *argv[], char *envp[])
        arch_init(envp);
 
        sinit();
-       init_rand(&__fio_rand_state);
 
        /*
         * We need locale for number printing, if it isn't set then just
diff --git a/fio.h b/fio.h
index 8401eda7132e02660e2d9812cc79e3fc934cfe92..6eb270d2a8e802b6607b43c0e992454ac8e68d56 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -460,7 +460,7 @@ struct thread_data {
 
        char *sysfs_root;
 
-       unsigned long rand_seeds[7];
+       unsigned long rand_seeds[8];
 
        union {
                os_random_state_t bsrange_state;
@@ -475,6 +475,8 @@ struct thread_data {
                struct frand_state __trim_state;
        };
 
+       struct frand_state buf_state;
+
        unsigned int verify_batch;
        unsigned int trim_batch;
 
diff --git a/init.c b/init.c
index a920c6ed87e71e8b0399708fcb12ac0d6361c88a..ed3426936a9fb84b26b4b9567b853cb592819490 100644 (file)
--- a/init.c
+++ b/init.c
@@ -515,6 +515,8 @@ void td_fill_rand_seeds(struct thread_data *td)
                td_fill_rand_seeds_os(td);
        else
                td_fill_rand_seeds_internal(td);
+
+       init_rand_seed(&td->buf_state, td->rand_seeds[7]);
 }
 
 /*
diff --git a/io_u.c b/io_u.c
index 16c98b1f454869c43e4862b91c57b1278898de28..a87c58e32791e35cfbb770c705a2c34c9b41ee17 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -1450,7 +1450,7 @@ void io_u_fill_buffer(struct thread_data *td, struct io_u *io_u,
        io_u->buf_filled_len = 0;
 
        if (!td->o.zero_buffers)
-               fill_random_buf(io_u->buf, max_bs);
+               fill_random_buf(&td->buf_state, io_u->buf, max_bs);
        else
                memset(io_u->buf, 0, max_bs);
 }
index 3b2d67ad6e9ebc4a242b24c162f94aa667a11743..7c6fed1fabbcc01f1803f00521d881a9c9662603 100644 (file)
@@ -36,8 +36,6 @@
 #include "rand.h"
 #include "../hash.h"
 
-struct frand_state __fio_rand_state;
-
 static inline int __seed(unsigned int x, unsigned int m)
 {
        return (x < m) ? x + m : x;
@@ -79,12 +77,13 @@ void __fill_random_buf(void *buf, unsigned int len, unsigned long seed)
        }
 }
 
-unsigned long fill_random_buf(void *buf, unsigned int len)
+unsigned long fill_random_buf(struct frand_state *fs, void *buf,
+                             unsigned int len)
 {
-       unsigned long r = __rand(&__fio_rand_state);
+       unsigned long r = __rand(fs);
 
        if (sizeof(int) != sizeof(long *))
-               r *= (unsigned long) __rand(&__fio_rand_state);
+               r *= (unsigned long) __rand(fs);
 
        __fill_random_buf(buf, len, r);
        return r;
index f80c111a53f9083d19ad0c972920732cb7a51bef..6b9e13c03acd77895d1fbe32e2dd88de10cbfa26 100644 (file)
@@ -7,8 +7,6 @@ struct frand_state {
        unsigned int s1, s2, s3;
 };
 
-extern struct frand_state __fio_rand_state;
-
 static inline unsigned int __rand(struct frand_state *state)
 {
 #define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b)
@@ -23,6 +21,6 @@ static inline unsigned int __rand(struct frand_state *state)
 extern void init_rand(struct frand_state *);
 extern void init_rand_seed(struct frand_state *, unsigned int seed);
 extern void __fill_random_buf(void *buf, unsigned int len, unsigned long seed);
-extern unsigned long fill_random_buf(void *buf, unsigned int len);
+extern unsigned long fill_random_buf(struct frand_state *, void *buf, unsigned int len);
 
 #endif
index fc207cf635bc731fbdbb788d4f791bb9bba4124b..c450e88cfc37bdf84835d7145ea75c7c9b337a2d 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -36,7 +36,7 @@ void fill_pattern(struct thread_data *td, void *p, unsigned int len, struct io_u
                if (use_seed)
                        __fill_random_buf(p, len, seed);
                else
-                       io_u->rand_seed = fill_random_buf(p, len);
+                       io_u->rand_seed = fill_random_buf(&td->buf_state, p, len);
                break;
        case 1:
                /*