X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=lib%2Fzipf.c;h=681df70069ac27419b4545dcbac0ee2de81fdbee;hp=9b6ce6334836baa1f0f3c0c238da24f319ad4c3b;hb=8c5e96a4ee7004b2982b5d5247ecea1cb96bccb7;hpb=a5a4fdfd44ec1b55ebab7800a931c148540a7324 diff --git a/lib/zipf.c b/lib/zipf.c index 9b6ce633..681df700 100644 --- a/lib/zipf.c +++ b/lib/zipf.c @@ -11,7 +11,7 @@ #include "../minmax.h" #include "../hash.h" -#define ZIPF_MAX_GEN 10000000 +#define ZIPF_MAX_GEN 10000000UL static void zipf_update(struct zipf_state *zs) { @@ -23,7 +23,7 @@ static void zipf_update(struct zipf_state *zs) * 10M max, that should be doable in 1-2s on even slow machines. * Precision will take a slight hit, but nothing major. */ - to_gen = min(zs->nranges, ZIPF_MAX_GEN); + to_gen = min(zs->nranges, (uint64_t) ZIPF_MAX_GEN); for (i = 0; i < to_gen; i++) zs->zetan += pow(1.0 / (double) (i + 1), zs->theta); @@ -35,7 +35,7 @@ static void shared_rand_init(struct zipf_state *zs, unsigned long nranges, memset(zs, 0, sizeof(*zs)); zs->nranges = nranges; - init_rand_seed(&zs->rand, seed); + init_rand_seed(&zs->rand, seed, 0); zs->rand_off = __rand(&zs->rand); } @@ -59,7 +59,7 @@ unsigned long long zipf_next(struct zipf_state *zs) alpha = 1.0 / (1.0 - zs->theta); eta = (1.0 - pow(2.0 / n, 1.0 - zs->theta)) / (1.0 - zs->zeta2 / zs->zetan); - rand_uni = (double) __rand(&zs->rand) / (double) FRAND_MAX; + rand_uni = (double) __rand(&zs->rand) / (double) FRAND32_MAX; rand_z = rand_uni * zs->zetan; if (rand_z < 1.0) @@ -69,7 +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)); - return (__hash_u64(val - 1) + zs->rand_off) % zs->nranges; + val--; + + if (!zs->disable_hash) + val = __hash_u64(val); + + return (val + zs->rand_off) % zs->nranges; } void pareto_init(struct zipf_state *zs, unsigned long nranges, double h, @@ -81,8 +86,18 @@ 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) FRAND_MAX; - unsigned long long n = zs->nranges - 1; + double rand = (double) __rand(&zs->rand) / (double) FRAND32_MAX; + unsigned long long n; + + n = (zs->nranges - 1) * pow(rand, zs->pareto_pow); + + if (!zs->disable_hash) + n = __hash_u64(n); - return (__hash_u64(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) +{ + zs->disable_hash = true; }