Make the 32/64-bit helper just return a random number up to a certain
value, and let the generic helper handle the range part.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fio_ro_check(td, io_u);
if (o->hipri &&
fio_ro_check(td, io_u);
if (o->hipri &&
- (rand32_between(&sd->rand_state, 1, 100) <= o->hipri_percentage))
+ (rand_between(&sd->rand_state, 1, 100) <= o->hipri_percentage))
flags |= RWF_HIPRI;
iov->iov_base = io_u->xfer_buf;
flags |= RWF_HIPRI;
iov->iov_base = io_u->xfer_buf;
/*
* Generate a value, v, between 1 and 100, both inclusive
*/
/*
* Generate a value, v, between 1 and 100, both inclusive
*/
- v = rand32_between(&td->zone_state, 1, 100);
+ v = rand_between(&td->zone_state, 1, 100);
/*
* Find our generated table. 'send' is the end block of this zone,
/*
* Find our generated table. 'send' is the end block of this zone,
/*
* Generate a value, v, between 1 and 100, both inclusive
*/
/*
* Generate a value, v, between 1 and 100, both inclusive
*/
- v = rand32_between(&td->zone_state, 1, 100);
+ v = rand_between(&td->zone_state, 1, 100);
zsi = &td->zone_state_index[ddir][v - 1];
stotal = zsi->size_perc_prev;
zsi = &td->zone_state_index[ddir][v - 1];
stotal = zsi->size_perc_prev;
if (td->o.perc_rand[ddir] == 100)
return true;
if (td->o.perc_rand[ddir] == 100)
return true;
- v = rand32_between(&td->seq_rand_state[ddir], 1, 100);
+ v = rand_between(&td->seq_rand_state[ddir], 1, 100);
return v <= td->o.perc_rand[ddir];
}
return v <= td->o.perc_rand[ddir];
}
- v = rand32_between(&td->rwmix_state, 1, 100);
+ v = rand_between(&td->rwmix_state, 1, 100);
if (v <= td->o.rwmix[DDIR_READ])
return DDIR_READ;
if (v <= td->o.rwmix[DDIR_READ])
return DDIR_READ;
- v = rand32_between(&td->dedupe_state, 1, 100);
+ v = rand_between(&td->dedupe_state, 1, 100);
if (v <= td->o.dedupe_percentage)
return &td->buf_state_prev;
if (v <= td->o.dedupe_percentage)
return &td->buf_state_prev;
/*
* Generate a random value between 'start' and 'end', both inclusive
*/
/*
* Generate a random value between 'start' and 'end', both inclusive
*/
-static inline int rand32_between(struct frand_state *state, int start, int end)
+static inline uint32_t rand32_upto(struct frand_state *state, uint32_t end)
{
uint32_t r;
assert(!state->use64);
r = __rand32(&state->state32);
{
uint32_t r;
assert(!state->use64);
r = __rand32(&state->state32);
- return start + (int) ((double)end * (r / (FRAND32_MAX + 1.0)));
+ return (int) ((double)end * (r / (FRAND32_MAX + 1.0)));
-static inline uint64_t rand64_between(struct frand_state *state, uint64_t start,
- uint64_t end)
+static inline uint64_t rand64_upto(struct frand_state *state, uint64_t end)
+ assert(state->use64);
+
r = __rand64(&state->state64);
r = __rand64(&state->state64);
- return start + (uint64_t) ((double)end * (r / (FRAND64_MAX + 1.0)));
+ return (uint64_t) ((double)end * (r / (FRAND64_MAX + 1.0)));
}
static inline uint64_t rand_between(struct frand_state *state, uint64_t start,
uint64_t end)
{
if (state->use64)
}
static inline uint64_t rand_between(struct frand_state *state, uint64_t start,
uint64_t end)
{
if (state->use64)
- return rand32_between(state, start, end);
+ return start + rand64_upto(state, end - start);
- return rand64_between(state, start, end);
+ return start + rand32_upto(state, end - start);
}
extern void init_rand(struct frand_state *, bool);
}
extern void init_rand(struct frand_state *, bool);
init_rand(&s, false);
for (i = 0; i < nvalues; i++) {
init_rand(&s, false);
for (i = 0; i < nvalues; i++) {
- int v = rand32_between(&s, start, end);
+ int v = rand_between(&s, start, end);