[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 42/74] test-rcu-list: abstract the list implementatio
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 42/74] test-rcu-list: abstract the list implementation |
Date: |
Tue, 21 Aug 2018 19:02:14 +0200 |
From: "Emilio G. Cota" <address@hidden>
So that we can test other implementations.
Signed-off-by: Emilio G. Cota <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
tests/test-rcu-list.c | 42 ++++++++++++++++++++++++++++++------------
1 file changed, 30 insertions(+), 12 deletions(-)
diff --git a/tests/test-rcu-list.c b/tests/test-rcu-list.c
index dc58091..9bd1136 100644
--- a/tests/test-rcu-list.c
+++ b/tests/test-rcu-list.c
@@ -82,9 +82,16 @@ static void wait_all_threads(void)
n_threads = 0;
}
+#ifndef TEST_LIST_TYPE
+#define TEST_LIST_TYPE 1
+#endif
struct list_element {
+#if TEST_LIST_TYPE == 1
QLIST_ENTRY(list_element) entry;
+#else
+#error Invalid TEST_LIST_TYPE
+#endif
struct rcu_head rcu;
};
@@ -96,8 +103,19 @@ static void reclaim_list_el(struct rcu_head *prcu)
atomic_set(&n_reclaims, n_reclaims + 1);
}
+#if TEST_LIST_TYPE == 1
static QLIST_HEAD(q_list_head, list_element) Q_list_head;
+#define TEST_NAME "qlist"
+#define TEST_LIST_REMOVE_RCU QLIST_REMOVE_RCU
+#define TEST_LIST_INSERT_AFTER_RCU QLIST_INSERT_AFTER_RCU
+#define TEST_LIST_INSERT_HEAD_RCU QLIST_INSERT_HEAD_RCU
+#define TEST_LIST_FOREACH_RCU QLIST_FOREACH_RCU
+#define TEST_LIST_FOREACH_SAFE_RCU QLIST_FOREACH_SAFE_RCU
+#else
+#error Invalid TEST_LIST_TYPE
+#endif
+
static void *rcu_q_reader(void *arg)
{
long long n_reads_local = 0;
@@ -113,7 +131,7 @@ static void *rcu_q_reader(void *arg)
while (atomic_read(&goflag) == GOFLAG_RUN) {
rcu_read_lock();
- QLIST_FOREACH_RCU(el, &Q_list_head, entry) {
+ TEST_LIST_FOREACH_RCU(el, &Q_list_head, entry) {
n_reads_local++;
if (atomic_read(&goflag) == GOFLAG_STOP) {
break;
@@ -150,10 +168,10 @@ static void *rcu_q_updater(void *arg)
target_el = select_random_el(RCU_Q_LEN);
j = 0;
/* FOREACH_RCU could work here but let's use both macros */
- QLIST_FOREACH_SAFE_RCU(prev_el, &Q_list_head, entry, el) {
+ TEST_LIST_FOREACH_SAFE_RCU(prev_el, &Q_list_head, entry, el) {
j++;
if (target_el == j) {
- QLIST_REMOVE_RCU(prev_el, entry);
+ TEST_LIST_REMOVE_RCU(prev_el, entry);
/* may be more than one updater in the future */
call_rcu1(&prev_el->rcu, reclaim_list_el);
n_removed_local++;
@@ -165,12 +183,12 @@ static void *rcu_q_updater(void *arg)
}
target_el = select_random_el(RCU_Q_LEN);
j = 0;
- QLIST_FOREACH_RCU(el, &Q_list_head, entry) {
+ TEST_LIST_FOREACH_RCU(el, &Q_list_head, entry) {
j++;
if (target_el == j) {
- prev_el = g_new(struct list_element, 1);
+ struct list_element *new_el = g_new(struct list_element, 1);
n_nodes += n_nodes_local;
- QLIST_INSERT_BEFORE_RCU(el, prev_el, entry);
+ TEST_LIST_INSERT_AFTER_RCU(el, new_el, entry);
break;
}
}
@@ -195,7 +213,7 @@ static void rcu_qtest_init(void)
srand(time(0));
for (i = 0; i < RCU_Q_LEN; i++) {
new_el = g_new(struct list_element, 1);
- QLIST_INSERT_HEAD_RCU(&Q_list_head, new_el, entry);
+ TEST_LIST_INSERT_HEAD_RCU(&Q_list_head, new_el, entry);
}
qemu_mutex_lock(&counts_mutex);
n_nodes += RCU_Q_LEN;
@@ -230,8 +248,8 @@ static void rcu_qtest(const char *test, int duration, int
nreaders)
create_thread(rcu_q_updater);
rcu_qtest_run(duration, nreaders);
- QLIST_FOREACH_SAFE_RCU(prev_el, &Q_list_head, entry, el) {
- QLIST_REMOVE_RCU(prev_el, entry);
+ TEST_LIST_FOREACH_SAFE_RCU(prev_el, &Q_list_head, entry, el) {
+ TEST_LIST_REMOVE_RCU(prev_el, entry);
call_rcu1(&prev_el->rcu, reclaim_list_el);
n_removed_local++;
}
@@ -292,9 +310,9 @@ int main(int argc, char *argv[])
} else {
gtest_seconds = 20;
}
- g_test_add_func("/rcu/qlist/single-threaded", gtest_rcuq_one);
- g_test_add_func("/rcu/qlist/short-few", gtest_rcuq_few);
- g_test_add_func("/rcu/qlist/long-many", gtest_rcuq_many);
+ g_test_add_func("/rcu/"TEST_NAME"/single-threaded",
gtest_rcuq_one);
+ g_test_add_func("/rcu/"TEST_NAME"/short-few", gtest_rcuq_few);
+ g_test_add_func("/rcu/"TEST_NAME"/long-many", gtest_rcuq_many);
g_test_in_charge = 1;
return g_test_run();
}
--
1.8.3.1
- [Qemu-devel] [PULL 51/74] seqlock: add QemuLockable support, (continued)
- [Qemu-devel] [PULL 51/74] seqlock: add QemuLockable support, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 41/74] test-rcu-list: access counters with atomics, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 39/74] rcu_queue: add RCU QTAILQ, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 46/74] qom: convert the CPU list to RCU, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 23/74] tests/atomic_add-bench: add -p to enable sync profiler, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 52/74] cpus: protect TimerState writes with a spinlock, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 38/74] rcu_queue: add RCU QSIMPLEQ, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 45/74] spapr: do not use CPU_FOREACH_REVERSE, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 30/74] i386: Fix arch_query_cpu_model_expansion() leak, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 40/74] test-rcu-list: access goflag with atomics, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 42/74] test-rcu-list: abstract the list implementation,
Paolo Bonzini <=
- [Qemu-devel] [PULL 55/74] vhost-scsi: unify vhost-scsi get_features implementations, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 53/74] cpus: allow cpu_get_ticks out of BQL, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 50/74] cpus: protect all icount computation with seqlock, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 26/74] hmp-commands-info: add sync-profile, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 56/74] vhost-scsi: expose 't10_pi' property for VIRTIO_SCSI_F_T10_PI, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 54/74] vhost-user-scsi: move host_features into VHostSCSICommon, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 29/74] fw_cfg: import & use linux/qemu_fw_cfg.h, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 35/74] target-i386: fix segment limit check in ljmp, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 69/74] target/i386: update MPX flags when CPL changes, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 61/74] pc-dimm: assign and verify the "addr" property during pre_plug, Paolo Bonzini, 2018/08/21