From c63dbedae09faa0c8f50008baeefc8d3950d8fc4 Mon Sep 17 00:00:00 2001 From: Fengguang Wu Date: Wed, 26 Sep 2018 10:21:21 +0800 Subject: [PATCH] sb_memory.c: use configurable random function The --rand-type described in man pages don't really work for sysbench memory tests. So enable this powerful feature. Tested with sysbench memory --memory-access-mode=rnd --rand-type=pareto run Signed-off-by: Fengguang Wu --- src/tests/memory/sb_memory.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tests/memory/sb_memory.c b/src/tests/memory/sb_memory.c index b9d6b98..c14d4ed 100644 --- a/src/tests/memory/sb_memory.c +++ b/src/tests/memory/sb_memory.c @@ -309,8 +309,8 @@ int event_rnd_none(sb_event_t *req, int thread_id) for (ssize_t i = 0; i < memory_block_size; i += SIZEOF_SIZE_T) { - size_t offset = (volatile size_t) (sb_rand_uniform_double() * - (memory_block_size / SIZEOF_SIZE_T)); + size_t offset = (volatile size_t) + sb_rand_default(0, (memory_block_size - 1) / SIZEOF_SIZE_T); (void) offset; /* unused */ /* nop */ } @@ -326,8 +326,8 @@ int event_rnd_read(sb_event_t *req, int thread_id) for (ssize_t i = 0; i < memory_block_size; i += SIZEOF_SIZE_T) { - size_t offset = (size_t) (sb_rand_uniform_double() * - (memory_block_size / SIZEOF_SIZE_T)); + size_t offset = (size_t) + sb_rand_default(0, (memory_block_size - 1) / SIZEOF_SIZE_T); size_t val = SIZE_T_LOAD(tls_buf + offset); (void) val; /* unused */ } @@ -343,8 +343,8 @@ int event_rnd_write(sb_event_t *req, int thread_id) for (ssize_t i = 0; i < memory_block_size; i += SIZEOF_SIZE_T) { - size_t offset = (size_t) (sb_rand_uniform_double() * - (memory_block_size / SIZEOF_SIZE_T)); + size_t offset = (size_t) + sb_rand_default(0, (memory_block_size - 1) / SIZEOF_SIZE_T); SIZE_T_STORE(tls_buf + offset, i); }