test-qht: perform lookups under rcu_read_lock

qht_lookup is meant to be called from an RCU read-critical
section. Make sure we're in such a section in test-qht
when performing lookups, despite the fact that no races
in qht can be triggered by test-qht since it is single-threaded.

Note that rcu_register_thread is already called by the
rcu_after_fork hook, and therefore duplicating it here would
be a bug.

Signed-off-by: Emilio G. Cota <cota@braap.org>
Message-Id: <1475706880-10667-4-git-send-email-cota@braap.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Emilio G. Cota 2016-10-05 18:34:40 -04:00 committed by Paolo Bonzini
parent 76b553b308
commit 9c7d64eb2a

View File

@ -6,6 +6,7 @@
*/ */
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "qemu/qht.h" #include "qemu/qht.h"
#include "qemu/rcu.h"
#define N 5000 #define N 5000
@ -51,6 +52,7 @@ static void check(int a, int b, bool expected)
struct qht_stats stats; struct qht_stats stats;
int i; int i;
rcu_read_lock();
for (i = a; i < b; i++) { for (i = a; i < b; i++) {
void *p; void *p;
uint32_t hash; uint32_t hash;
@ -61,6 +63,8 @@ static void check(int a, int b, bool expected)
p = qht_lookup(&ht, is_equal, &val, hash); p = qht_lookup(&ht, is_equal, &val, hash);
g_assert_true(!!p == expected); g_assert_true(!!p == expected);
} }
rcu_read_unlock();
qht_statistics_init(&ht, &stats); qht_statistics_init(&ht, &stats);
if (stats.used_head_buckets) { if (stats.used_head_buckets) {
g_assert_cmpfloat(qdist_avg(&stats.chain), >=, 1.0); g_assert_cmpfloat(qdist_avg(&stats.chain), >=, 1.0);