[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 11/60] tests/atomic_add-bench: add -m option to use m
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 11/60] tests/atomic_add-bench: add -m option to use mutexes |
Date: |
Thu, 28 Jun 2018 22:04:21 +0200 |
From: "Emilio G. Cota" <address@hidden>
This allows us to use atomic-add-bench as a microbenchmark
for evaluating qemu_mutex_lock's performance.
Signed-off-by: Emilio G. Cota <address@hidden>
[cherry picked from https://github.com/cota/qemu/commit/f04f34df]
Signed-off-by: Peter Xu <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
tests/atomic_add-bench.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/tests/atomic_add-bench.c b/tests/atomic_add-bench.c
index caa1e8e..f96d448 100644
--- a/tests/atomic_add-bench.c
+++ b/tests/atomic_add-bench.c
@@ -8,6 +8,7 @@ struct thread_info {
} QEMU_ALIGNED(64);
struct count {
+ QemuMutex lock;
unsigned long val;
} QEMU_ALIGNED(64);
@@ -18,11 +19,13 @@ static unsigned int n_ready_threads;
static struct count *counts;
static unsigned int duration = 1;
static unsigned int range = 1024;
+static bool use_mutex;
static bool test_start;
static bool test_stop;
static const char commands_string[] =
" -n = number of threads\n"
+ " -m = use mutexes instead of atomic increments\n"
" -d = duration in seconds\n"
" -r = range (will be rounded up to pow2)";
@@ -59,7 +62,13 @@ static void *thread_func(void *arg)
info->r = xorshift64star(info->r);
index = info->r & (range - 1);
- atomic_inc(&counts[index].val);
+ if (use_mutex) {
+ qemu_mutex_lock(&counts[index].lock);
+ counts[index].val += 1;
+ qemu_mutex_unlock(&counts[index].lock);
+ } else {
+ atomic_inc(&counts[index].val);
+ }
}
return NULL;
}
@@ -91,6 +100,9 @@ static void create_threads(void)
th_info = g_new(struct thread_info, n_threads);
counts = qemu_memalign(64, sizeof(*counts) * range);
memset(counts, 0, sizeof(*counts) * range);
+ for (i = 0; i < range; i++) {
+ qemu_mutex_init(&counts[i].lock);
+ }
for (i = 0; i < n_threads; i++) {
struct thread_info *info = &th_info[i];
@@ -131,7 +143,7 @@ static void parse_args(int argc, char *argv[])
int c;
for (;;) {
- c = getopt(argc, argv, "hd:n:r:");
+ c = getopt(argc, argv, "hd:n:mr:");
if (c < 0) {
break;
}
@@ -145,6 +157,9 @@ static void parse_args(int argc, char *argv[])
case 'n':
n_threads = atoi(optarg);
break;
+ case 'm':
+ use_mutex = true;
+ break;
case 'r':
range = pow2ceil(atoi(optarg));
break;
--
1.8.3.1
- [Qemu-devel] [PULL 02/60] move public invalidate APIs out of translate-all.{c, h}, clean up, (continued)
- [Qemu-devel] [PULL 02/60] move public invalidate APIs out of translate-all.{c, h}, clean up, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 06/60] target/i386: Fix BLSR and BLSI, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 07/60] whpx: commit missing file, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 04/60] main-loop: document IOCanReadHandler, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 05/60] hw/char/serial: Only retry if qemu_chr_fe_write returns 0, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 08/60] memory-device: turn alignment assert into check, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 09/60] exec: check that alignment is a power of two, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 13/60] QemuMutex: support --enable-debug-mutex, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 12/60] qemu-thread: introduce qemu-thread-common.h, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 10/60] kvm: Delete the slot if and only if the KVM_MEM_READONLY flag is changed, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 11/60] tests/atomic_add-bench: add -m option to use mutexes,
Paolo Bonzini <=
- [Qemu-devel] [PULL 17/60] pc-dimm: remove leftover "struct pc_dimms_capacity", Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 15/60] Replace '-enable-kvm' with '-accel kvm' in docs and help texts, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 18/60] pc: rename pc_dimm_(plug|unplug|...)* into pc_memory_(plug|unplug|...)*, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 21/60] pc: factor out pc specific dimm checks into pc_memory_pre_plug(), Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 14/60] configure: enable debug-mutex if debug enabled, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 19/60] pc-dimm: rename pc_dimm_memory_* to pc_dimm_*, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 22/60] nvdimm: no need to overwrite get_vmstate_memory_region(), Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 23/60] hostmem: drop error variable from host_memory_backend_get_memory(), Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 25/60] nvdimm: convert "unarmed" into a static property, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 16/60] qemu-options: Add missing newline to -accel help text, Paolo Bonzini, 2018/06/28