From: Jens Axboe Date: Wed, 7 Nov 2012 13:04:11 +0000 (+0100) Subject: zipf/pareto: ensure that 0 isn't always the hottest block X-Git-Tag: fio-2.0.11~25 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=b2b0b7534d857e4ca22429a9f573791b8e03264c zipf/pareto: ensure that 0 isn't always the hottest block Signed-off-by: Jens Axboe --- diff --git a/lib/zipf.c b/lib/zipf.c index 527ae294..8cd25864 100644 --- a/lib/zipf.c +++ b/lib/zipf.c @@ -88,20 +88,26 @@ punt: zs->nranges = f.nranges; } +static void shared_rand_init(struct zipf_state *zs, unsigned long nranges) +{ + memset(zs, 0, sizeof(*zs)); + zs->nranges = nranges; + + init_rand(&zs->rand); + zs->rand_off = __rand(&zs->rand); +} + void zipf_init(struct zipf_state *zs, unsigned long nranges, double theta) { unsigned int i; - memset(zs, 0, sizeof(*zs)); + shared_rand_init(zs, nranges); - zs->nranges = nranges; zs->theta = theta; for (i = 1; i <= 2; i++) zs->zeta2 += pow(1.0 / (double) i, zs->theta); - init_rand(&zs->rand); - zipf_load_gen_zeta(zs); } @@ -125,17 +131,13 @@ unsigned long long zipf_next(struct zipf_state *zs) else val = 1 + (unsigned long long)(n * pow(eta*rand_uni - eta + 1.0, alpha)); - return __hash_long(val - 1) % zs->nranges; + return (__hash_long(val - 1) + zs->rand_off) % zs->nranges; } void pareto_init(struct zipf_state *zs, unsigned long nranges, double h) { - memset(zs, 0, sizeof(*zs)); - - zs->nranges = nranges; + shared_rand_init(zs, nranges); zs->pareto_pow = log(h) / log(1.0 - h); - - init_rand(&zs->rand); } unsigned long long pareto_next(struct zipf_state *zs) @@ -143,5 +145,5 @@ unsigned long long pareto_next(struct zipf_state *zs) double rand = (double) __rand(&zs->rand) / (double) FRAND_MAX; unsigned long long n = zs->nranges - 1; - return __hash_long(n * pow(rand, zs->pareto_pow)) % zs->nranges; + return (__hash_long(n * pow(rand, zs->pareto_pow)) + zs->rand_off) % zs->nranges; } diff --git a/lib/zipf.h b/lib/zipf.h index c66b0640..a23afe5e 100644 --- a/lib/zipf.h +++ b/lib/zipf.h @@ -11,6 +11,7 @@ struct zipf_state { double zetan; double pareto_pow; struct frand_state rand; + unsigned long rand_off; }; void zipf_init(struct zipf_state *zs, unsigned long nranges, double theta);