io_u: cleanup frand_max usage
Signed-off-by: Jens Axboe <axboe@fb.com>
diff --git a/io_u.c b/io_u.c
index 672a1e3..d98945d 100644
--- a/io_u.c
+++ b/io_u.c
@@ -93,14 +93,12 @@
if (td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE ||
td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE64) {
- uint64_t frand_max;
- frand_max = rand_max(&td->random_state);
r = __rand(&td->random_state);
dprint(FD_RANDOM, "off rand %llu\n", (unsigned long long) r);
- *b = lastb * (r / ((uint64_t) frand_max + 1.0));
+ *b = lastb * (r / (rand_max(&td->random_state) + 1.0));
} else {
uint64_t off = 0;
@@ -163,7 +161,7 @@
uint64_t *b)
{
unsigned int i, v, send, atotal, stotal;
- uint64_t offset, frand_max, lastb;
+ uint64_t offset, lastb;
unsigned long r;
static int warned;
@@ -179,9 +177,8 @@
/*
* Generate a value, v, between 1 and 100, both inclusive
*/
- frand_max = rand_max(&td->zone_state);
r = __rand(&td->zone_state);
- v = 1 + (int) (100.0 * (r / (frand_max + 1.0)));
+ v = 1 + (int) (100.0 * (r / (rand_max(&td->zone_state) + 1.0)));
/*
* Find the slot that we should use
@@ -291,16 +288,14 @@
static bool should_do_random(struct thread_data *td, enum fio_ddir ddir)
{
- uint64_t frand_max;
unsigned int v;
unsigned long r;
if (td->o.perc_rand[ddir] == 100)
return true;
- frand_max = rand_max(&td->seq_rand_state[ddir]);
r = __rand(&td->seq_rand_state[ddir]);
- v = 1 + (int) (100.0 * (r / (frand_max + 1.0)));
+ v = 1 + (int) (100.0 * (r / (rand_max(&td->seq_rand_state[ddir]) + 1.0)));
return v <= td->o.perc_rand[ddir];
}
@@ -620,12 +615,11 @@
static inline enum fio_ddir get_rand_ddir(struct thread_data *td)
{
- uint64_t frand_max = rand_max(&td->rwmix_state);
unsigned int v;
unsigned long r;
r = __rand(&td->rwmix_state);
- v = 1 + (int) (100.0 * (r / (frand_max + 1.0)));
+ v = 1 + (int) (100.0 * (r / (rand_max(&td->rwmix_state) + 1.0)));
if (v <= td->o.rwmix[DDIR_READ])
return DDIR_READ;
@@ -1979,7 +1973,6 @@
*/
static struct frand_state *get_buf_state(struct thread_data *td)
{
- uint64_t frand_max;
unsigned int v;
unsigned long r;
@@ -1990,9 +1983,8 @@
return &td->buf_state;
}
- frand_max = rand_max(&td->dedupe_state);
r = __rand(&td->dedupe_state);
- v = 1 + (int) (100.0 * (r / (frand_max + 1.0)));
+ v = 1 + (int) (100.0 * (r / (rand_max(&td->dedupe_state) + 1.0)));
if (v <= td->o.dedupe_percentage)
return &td->buf_state_prev;