summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2012-11-07 14:04:11 +0100
committerJens Axboe <axboe@kernel.dk>2012-11-07 14:04:11 +0100
commitb2b0b7534d857e4ca22429a9f573791b8e03264c (patch)
tree71cfdaed3e528706014d053d028d8135ae75dcfe /lib
parent078189c148e6e0e42894033cf5e19bd6028ca288 (diff)
downloadfio-b2b0b7534d857e4ca22429a9f573791b8e03264c.tar.gz
fio-b2b0b7534d857e4ca22429a9f573791b8e03264c.tar.bz2
zipf/pareto: ensure that 0 isn't always the hottest block
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'lib')
-rw-r--r--lib/zipf.c24
-rw-r--r--lib/zipf.h1
2 files changed, 14 insertions, 11 deletions
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);