tests/qht-bench: Adjust rate/threshold computation
v2 cover tests/qht-bench: Adjust rate/threshold computation
Supercedes: <[email protected]>
Thanks for Emilio's review of v1. I've split "seed" from "rate" as suggested, left the comparisons alone, and expanded the comment in do_threshold.
r~
Richard Henderson (2):
tests/qht-bench: Adjust testing rate by -1
tests/qht-bench: Adjust threshold computation
tests/qht-bench.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 tests/qht-bench: Adjust testing rate by -1
Since the seed must be non-zero, subtracting 1 means puts the rate in 0..UINT64_MAX-1, which allows the 0 and UINT64_MAX thresholds to corrspond to 0% (never) and 100% (always).
--- tests/qht-bench.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
tests/qht-bench.c +15 -7
@@ -25,7 +25,13 @@ struct thread_stats {struct thread_info {void (*func)(struct thread_info *);struct thread_stats stats; -uint64_t r; +/* +* Seed is in the range [1..UINT64_MAX], because the RNG requires +* a non-zero seed. To use, subtract 1 and compare against the +* threshold with </>=. This lets threshold = 0 never match (0% hit), +* and threshold = UINT64_MAX always match (100% hit). +*/ +uint64_t seed;bool write_op;/* writes alternate between insertions and removals */ bool resize_down; } QEMU_ALIGNED(64); /* avoid false sharing among threads */
@@ -131,8 +137,9 @@ static uint64_t xorshift64star(uint64_t x)static void do_rz (struct thread_info *info) {struct thread_stats *stats = &info->stats; +uint64_t r = info->seed -1 ; -if (info->r < resize_threshold) { +if (r < resize_threshold) {size_t size = info->resize_down ? resize_min : resize_max;bool resized;
@@ -151,13 +158,14 @@ static void do_rz(struct thread_info *info)static void do_rw (struct thread_info *info) {struct thread_stats *stats = &info->stats; +uint64_t r = info->seed -1 ;uint32_t hash;long *p; -if (info->r >= update_threshold) { +if (r >= update_threshold) {bool read; - p = &keys[info->r & (lookup_range -1 )]; + p = &keys[r & (lookup_range -1 )]; hash =hfunc (*p); read =qht_lookup (&ht, p, hash);if (read) {
@@ -166,7 +174,7 @@ static void do_rw(struct thread_info *info) stats->not_rd++; } }else { - p = &keys[info->r & (update_range -1 )]; + p = &keys[r & (update_range -1 )]; hash =hfunc (*p);if (info->write_op) {bool written = false;
@@ -208,7 +216,7 @@ static void *thread_func(void *p)rcu_read_lock ();while (!atomic_read (&test_stop)) { - info->r =xorshift64star (info->r); + info->seed =xorshift64star (info->seed); info->func (info); }rcu_read_unlock ();
@@ -221,7 +229,7 @@ static void *thread_func(void *p)static void prepare_thread_info (struct thread_info *info,int i) {/* seed for the RNG; each thread should have a different one */ - info->r = (i +1 ) ^time (NULL ); + info->seed = (i +1 ) ^time (NULL );/* the first update will be a write */ info->write_op = true;/* the first resize will be down */
Signature · 1 line
2.25.1
Re: [PATCH v2 1/2] tests/qht-bench: Adjust testing rate by -1
Quoted 77 lines · Richard Henderson
Since the seed must be non-zero, subtracting 1 means puts the rate in 0..UINT64_MAX-1, which allows the 0 and
UINT64_MAXthresholds to corrspond to 0% (never) and 100% (always).Suggested-by Emilio G. Cota <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- tests/qht-bench.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)tests/qht-bench.c +14
-6@@ -25,7 +25,13 @@ struct thread_stats {struct thread_info {void (*func)(struct thread_info *);struct thread_stats stats; -uint64_t r; +/* +* Seed is in the range [1..UINT64_MAX], because the RNG requires +* a non-zero seed. To use, subtract 1 and compare against the +* threshold with </>=. This lets threshold = 0 never match (0% hit), +* and threshold = UINT64_MAX always match (100% hit). +*/ +uint64_t seed;bool write_op;/* writes alternate between insertions and removals */ bool resize_down; } QEMU_ALIGNED(64); /* avoid false sharing among threads */@@ -131,8 +137,9 @@ static uint64_t xorshift64star(uint64_t x)static void do_rz (struct thread_info *info) {struct thread_stats *stats = &info->stats; +uint64_t r = info->seed -1 ; -if (info->r < resize_threshold) { +if (r < resize_threshold) {size_t size = info->resize_down ? resize_min : resize_max;bool resized;@@ -151,13 +158,14 @@ static void do_rz(struct thread_info *info)static void do_rw (struct thread_info *info) {struct thread_stats *stats = &info->stats; +uint64_t r = info->seed -1 ;uint32_t hash;long *p; -if (info->r >= update_threshold) { +if (r >= update_threshold) {bool read; - p = &keys[info->r & (lookup_range -1 )]; + p = &keys[r & (lookup_range -1 )]; hash =hfunc (*p); read =qht_lookup (&ht, p, hash);if (read) {@@ -166,7 +174,7 @@ static void do_rw(struct thread_info *info) stats->not_rd++; } }else { - p = &keys[info->r & (update_range -1 )]; + p = &keys[r & (update_range -1 )]; hash =hfunc (*p);if (info->write_op) {bool written = false;@@ -208,7 +216,7 @@ static void *thread_func(void *p)rcu_read_lock ();while (!atomic_read (&test_stop)) { - info->r =xorshift64star (info->r); + info->seed =xorshift64star (info->seed); info->func (info); }rcu_read_unlock ();
tests/qht-bench.c static void *thread_func(void *p) · line 235
Quoted 8 lines
tests/qht-bench.c +1
-1@@ -221,7 +229,7 @@ static void *thread_func(void *p)static void prepare_thread_info (struct thread_info *info,int i) {/* seed for the RNG; each thread should have a different one */ - info->r = (i +1 ) ^time (NULL ); + info->seed = (i +1 ) ^time (NULL );/* the first update will be a write */ info->write_op = true;/* the first resize will be down */
PATCH v2 2/2 tests/qht-bench: Adjust threshold computation
In reply to Richard HendersonIn 06c4cc3660b3, we split the multiplication in two parts to avoid a clang warning. But because double still rounds to 53 bits, this does not provide additional precision beyond multiplication by nextafter(0x1p64, 0), the largest representable value smaller than 2**64.
However, since we have eliminated 1.0, mutiplying by 2**64 produces a better distribution of input values to the output values.
--- tests/qht-bench.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
tests/qht-bench.c +16 -2
@@ -289,11 +289,25 @@ static void pr_params(void)static void do_threshold (double rate,uint64_t *threshold) { +/* +* For 0 <= rate <= 1, scale to fit in a uint64_t. +* +* Scale by 2**64, with a special case for 1.0. +* The remainder of the possible values are scattered between 0 +* and 0xfffffffffffff800 (nextafter(0x1p64, 0)). +* +* Note that we cannot simply scale by UINT64_MAX, because that +* value is not representable as an IEEE double value. +* +* If we scale by the next largest value, nextafter(0x1p64, 0), +* then the remainder of the possible values are scattered between +* 0 and 0xfffffffffffff000. Which leaves us with a gap between +* the final two inputs that is twice as large as any other. +*/ if (rate ==1.0 ) { *threshold =UINT64_MAX ; }else { - *threshold = (rate *0xffff000000000000ull ) - + (rate *0x0000ffffffffffffull ); + *threshold = rate *0x1p64 ; } }
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] tests/qht-bench: Adjust threshold computation
Quoted 37 lines · Richard Henderson
In
06c4cc3660b3, we split the multiplication in two parts to avoid a clang warning. But because double still rounds to 53 bits, this does not provide additional precision beyond multiplication bynextafter(0x1p64, 0), the largest representable value smaller than 2**64.However, since we have eliminated 1.0, mutiplying by 2**64 produces a better distribution of input values to the output values.
Signed-off-by Richard Henderson <[email protected]>--- tests/qht-bench.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)tests/qht-bench.c +14
-0@@ -289,11 +289,25 @@ static void pr_params(void)static void do_threshold (double rate,uint64_t *threshold) { +/* +* For 0 <= rate <= 1, scale to fit in a uint64_t. +* +* Scale by 2**64, with a special case for 1.0. +* The remainder of the possible values are scattered between 0 +* and 0xfffffffffffff800 (nextafter(0x1p64, 0)). +* +* Note that we cannot simply scale by UINT64_MAX, because that +* value is not representable as an IEEE double value. +* +* If we scale by the next largest value, nextafter(0x1p64, 0), +* then the remainder of the possible values are scattered between +* 0 and 0xfffffffffffff000. Which leaves us with a gap between +* the final two inputs that is twice as large as any other.
tests/qht-bench.c static void pr_params(void) · line 313
Quoted 10 lines
tests/qht-bench.c +2
-2+*/ if (rate ==1.0 ) { *threshold =UINT64_MAX ; }else { - *threshold = (rate *0xffff000000000000ull ) - + (rate *0x0000ffffffffffffull ); + *threshold = rate *0x1p64 ; } }
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the docker-mingw@fedora build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#! /bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-mingw@fedora J=14 NETWORK=1
=== TEST SCRIPT END ===
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=cfb70a057f99414cb380e1aac7ea404b', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-w3ye4819/src/docker-src.2020-06-26-16.16.29.10114:/var/tmp/qemu:z,ro', 'qemu:fedora', '/var/tmp/qemu/run', 'test-mingw']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=cfb70a057f99414cb380e1aac7ea404b
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-w3ye4819/src'
make: *** [docker-run-test-mingw@fedora] Error 2
real 4m59.023s
user 0m8.221s
The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 5 lines · Richard Henderson
Supercedes: <[email protected]>
Thanks for Emilio's review of v1. I've split "seed" from "rate" as suggested, left the comparisons alone, and expanded the comment in
do_threshold.
for the series. Thanks a lot!
E.
Quoted 5 lines · Richard Henderson
Supercedes: <[email protected]>
Thanks for Emilio's review of v1. I've split "seed" from "rate" as suggested, left the comparisons alone, and expanded the comment in
do_threshold.
Queued to testing/next, thanks.
Quoted 11 lines
r~
Richard Henderson (2):
tests/qht-bench: Adjust testing rate by -1
tests/qht-bench: Adjust threshold computationtests/qht-bench.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-)
Signature · 1 line
Alex Bennée