[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 11/79] test-rcu-list: access n_reclaims and n_nodes_r
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 11/79] test-rcu-list: access n_reclaims and n_nodes_removed with atomic64 |
Date: |
Sun, 30 Sep 2018 10:12:09 +0200 |
From: "Emilio G. Cota" <address@hidden>
To avoid undefined behaviour.
Note that these "atomics" are atomic in the "access once" sense.
The variables are updated by a single thread at a time, so no
"full" atomics are necessary.
Signed-off-by: Emilio G. Cota <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
tests/test-rcu-list.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/tests/test-rcu-list.c b/tests/test-rcu-list.c
index 192bfbf..2e6f70b 100644
--- a/tests/test-rcu-list.c
+++ b/tests/test-rcu-list.c
@@ -33,8 +33,8 @@
static QemuMutex counts_mutex;
static long long n_reads = 0LL;
static long long n_updates = 0LL;
-static long long n_reclaims = 0LL;
-static long long n_nodes_removed = 0LL;
+static int64_t n_reclaims;
+static int64_t n_nodes_removed;
static long long n_nodes = 0LL;
static int g_test_in_charge = 0;
@@ -104,7 +104,7 @@ static void reclaim_list_el(struct rcu_head *prcu)
struct list_element *el = container_of(prcu, struct list_element, rcu);
g_free(el);
/* Accessed only from call_rcu thread. */
- n_reclaims++;
+ atomic_set_i64(&n_reclaims, n_reclaims + 1);
}
#if TEST_LIST_TYPE == 1
@@ -232,7 +232,7 @@ static void *rcu_q_updater(void *arg)
qemu_mutex_lock(&counts_mutex);
n_nodes += n_nodes_local;
n_updates += n_updates_local;
- n_nodes_removed += n_removed_local;
+ atomic_set_i64(&n_nodes_removed, n_nodes_removed + n_removed_local);
qemu_mutex_unlock(&counts_mutex);
return NULL;
}
@@ -286,19 +286,21 @@ static void rcu_qtest(const char *test, int duration, int
nreaders)
n_removed_local++;
}
qemu_mutex_lock(&counts_mutex);
- n_nodes_removed += n_removed_local;
+ atomic_set_i64(&n_nodes_removed, n_nodes_removed + n_removed_local);
qemu_mutex_unlock(&counts_mutex);
synchronize_rcu();
- while (n_nodes_removed > n_reclaims) {
+ while (atomic_read_i64(&n_nodes_removed) > atomic_read_i64(&n_reclaims)) {
g_usleep(100);
synchronize_rcu();
}
if (g_test_in_charge) {
- g_assert_cmpint(n_nodes_removed, ==, n_reclaims);
+ g_assert_cmpint(atomic_read_i64(&n_nodes_removed), ==,
+ atomic_read_i64(&n_reclaims));
} else {
printf("%s: %d readers; 1 updater; nodes read: " \
- "%lld, nodes removed: %lld; nodes reclaimed: %lld\n",
- test, nthreadsrunning - 1, n_reads, n_nodes_removed,
n_reclaims);
+ "%lld, nodes removed: %"PRIi64"; nodes reclaimed: %"PRIi64"\n",
+ test, nthreadsrunning - 1, n_reads,
+ atomic_read_i64(&n_nodes_removed),
atomic_read_i64(&n_reclaims));
exit(0);
}
}
--
1.8.3.1
- [Qemu-devel] [PULL 01/79] virtio: Return true from virtio_queue_empty if broken, (continued)
- [Qemu-devel] [PULL 01/79] virtio: Return true from virtio_queue_empty if broken, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 09/79] tests: add atomic64-bench, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 16/79] hostmem-memfd: add checks before adding hostmem-memfd & properties, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 13/79] cpus: access .qemu_icount with atomic64, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 12/79] cpus: take seqlock across qemu_icount updates, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 14/79] cpus: access .qemu_icount_bias with atomic64, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 17/79] kvm: x86: Fix kvm_arch_fixup_msi_route for remap-less case, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 22/79] serial: fix DLL writes, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 10/79] qsp: use atomic64 accessors, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 15/79] dump: fix Windows dump memory run mapping, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 11/79] test-rcu-list: access n_reclaims and n_nodes_removed with atomic64,
Paolo Bonzini <=
- [Qemu-devel] [PULL 18/79] configure: preserve various environment variables in config.status, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 19/79] hw/char/sh_serial: Add timeout handling to unbreak serial input, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 21/79] util: use fcntl() for qemu_write_pidfile() locking, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 20/79] util: add qemu_write_pidfile(), Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 23/79] Delete PID file on exit, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 24/79] change get_image_size return type to int64_t, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 25/79] target/i386: move cpu_cc_srcT to DisasContext, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 28/79] target/i386: move cpu_T1 to DisasContext, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 34/79] target/i386: move cpu_tmp3_i32 to DisasContext, Paolo Bonzini, 2018/09/30
- [Qemu-devel] [PULL 26/79] target/i386: move cpu_A0 to DisasContext, Paolo Bonzini, 2018/09/30