Fix verify random bytes filling
authorJens Axboe <jens.axboe@oracle.com>
Thu, 26 Jul 2007 09:55:10 +0000 (11:55 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 26 Jul 2007 09:55:10 +0000 (11:55 +0200)
Shawn Lewis <shawnlewis@google.com> reports:

---

verify.c: fill_random_bytes() doesn't work as intended.

drand48 on linux returns a double whose value is evenly distributed between
0.0 and 0.1. This is not the same as having an 8-byte value where each bit
has the same chance of being 0 as it does of being 1.

I'd fix this but it should probably be done in a cross-platformish way and
I'm not quite sure how to do it. Maybe just use smaller randoms? Have an
os_random_uint32?

---

I just got rid of os_random_double() and used os_random_long(),
truncating that to an unsigned integer.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
os/os-freebsd.h
os/os-linux.h
os/os-solaris.h
verify.c

index 01c5ce917b57d9501774cd80d8a84e82b6df6b35..ba2541a5f5f25159f6fa0c4ed4a25c4336daa09d 100644 (file)
@@ -52,11 +52,4 @@ static inline long os_random_long(os_random_state_t *rs)
        return val;
 }
 
        return val;
 }
 
-static inline double os_random_double(os_random_state_t *rs)
-{
-       double val;
-
-       val = (double) rand_r(rs);
-       return val;
-}
 #endif
 #endif
index f86ed322c150429df9d7a8e99f70c3dbd19d4028..1bf7e62a42ca8840fcfeef4ef7bc668476084948 100644 (file)
@@ -199,14 +199,6 @@ static inline long os_random_long(os_random_state_t *rs)
        return val;
 }
 
        return val;
 }
 
-static inline double os_random_double(os_random_state_t *rs)
-{
-       double val;
-
-       drand48_r(rs, &val);
-       return val;
-}
-
 static inline int fio_lookup_raw(dev_t dev, int *majdev, int *mindev)
 {
        struct raw_config_request rq;
 static inline int fio_lookup_raw(dev_t dev, int *majdev, int *mindev)
 {
        struct raw_config_request rq;
index 898da18e988d205004f8826c8ba08d6768ac2352..21d28e9862b0274d2fc8aaa7970bb736073750fb 100644 (file)
@@ -54,12 +54,4 @@ static inline long os_random_long(os_random_state_t *rs)
        return val;
 }
 
        return val;
 }
 
-static inline double os_random_double(os_random_state_t *rs)
-{
-       double val;
-
-       val = (double) rand_r(rs);
-       return val;
-}
-
 #endif
 #endif
index 32e7a041dec521b52574f0de1b9d37e28604f888..794244a9b495240974f26f1e4f972f38ec1cc8c2 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -12,10 +12,10 @@ static void fill_random_bytes(struct thread_data *td,
                              unsigned char *p, unsigned int len)
 {
        unsigned int todo;
                              unsigned char *p, unsigned int len)
 {
        unsigned int todo;
-       double r;
+       int r;
 
        while (len) {
 
        while (len) {
-               r = os_random_double(&td->verify_state);
+               r = os_random_long(&td->verify_state);
 
                /*
                 * lrand48_r seems to be broken and only fill the bottom
 
                /*
                 * lrand48_r seems to be broken and only fill the bottom