From: Jens Axboe Date: Tue, 17 May 2016 01:18:09 +0000 (-0600) Subject: zipf/pareto/gauss: hash cleanup X-Git-Tag: fio-2.10~23 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=8c5e96a4ee7004b2982b5d5247ecea1cb96bccb7 zipf/pareto/gauss: hash cleanup Signed-off-by: Jens Axboe --- diff --git a/lib/gauss.c b/lib/gauss.c index 48e2fbfe..f974490f 100644 --- a/lib/gauss.c +++ b/lib/gauss.c @@ -39,7 +39,7 @@ unsigned long long gauss_next(struct gauss_state *gs) } if (!gs->disable_hash) - return __hash_u64(sum) % gs->nranges; + sum = __hash_u64(sum); return sum % gs->nranges; } diff --git a/lib/zipf.c b/lib/zipf.c index 8b581faf..681df700 100644 --- a/lib/zipf.c +++ b/lib/zipf.c @@ -69,10 +69,12 @@ unsigned long long zipf_next(struct zipf_state *zs) else val = 1 + (unsigned long long)(n * pow(eta*rand_uni - eta + 1.0, alpha)); + val--; + if (!zs->disable_hash) - return (__hash_u64(val - 1) + zs->rand_off) % zs->nranges; + val = __hash_u64(val); - return (val - 1 + zs->rand_off) % zs->nranges; + return (val + zs->rand_off) % zs->nranges; } void pareto_init(struct zipf_state *zs, unsigned long nranges, double h, @@ -85,12 +87,14 @@ void pareto_init(struct zipf_state *zs, unsigned long nranges, double h, unsigned long long pareto_next(struct zipf_state *zs) { double rand = (double) __rand(&zs->rand) / (double) FRAND32_MAX; - unsigned long long n = zs->nranges - 1; + unsigned long long n; + + n = (zs->nranges - 1) * pow(rand, zs->pareto_pow); if (!zs->disable_hash) - return (__hash_u64(n * pow(rand, zs->pareto_pow)) + zs->rand_off) % zs->nranges; + n = __hash_u64(n); - return (unsigned long long) (n * pow(rand, zs->pareto_pow) + zs->rand_off) % zs->nranges; + return (n + zs->rand_off) % zs->nranges; } void zipf_disable_hash(struct zipf_state *zs)