From 6760605e1c3ffceec3eedebbe5c48ee439ab5c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Fri, 2 Mar 2018 09:43:09 -0500 Subject: [PATCH] tcg: enable thread-per-vCPU There are a couple of changes that occur at the same time here: - introduce a single vCPU qemu_tcg_cpu_thread_fn One of these is spawned per vCPU with its own Thread and Condition variables. qemu_tcg_rr_cpu_thread_fn is the new name for the old single threaded function. - the TLS current_cpu variable is now live for the lifetime of MTTCG vCPU threads. This is for future work where async jobs need to know the vCPU context they are operating in. The user to switch on multi-thread behaviour and spawn a thread per-vCPU. For a simple test kvm-unit-test like: ./arm/run ./arm/locking-test.flat -smp 4 -accel tcg,thread=multi Will now use 4 vCPU threads and have an expected FAIL (instead of the unexpected PASS) as the default mode of the test has no protection when incrementing a shared variable. We enable the parallel_cpus flag to ensure we generate correct barrier and atomic code if supported by the front and backends. This doesn't automatically enable MTTCG until default_mttcg_enabled() is updated to check the configuration is supported. Backports relevant parts of commit 372579427a5040a26dfee78464b50e2bdf27ef26 --- qemu/cpu-exec.c | 4 ---- qemu/translate-all.c | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/qemu/cpu-exec.c b/qemu/cpu-exec.c index 3a35e843..d88d377e 100644 --- a/qemu/cpu-exec.c +++ b/qemu/cpu-exec.c @@ -539,9 +539,5 @@ int cpu_exec(struct uc_struct *uc, CPUState *cpu) // TODO: optimize this for better performance tb_flush(cpu); - /* fail safe : never use current_cpu outside cpu_exec() */ - atomic_set(&uc->current_cpu, NULL); - /* Does not need atomic_mb_set because a spurious wakeup is okay. */ - atomic_set(&uc->tcg_current_rr_cpu, NULL); return ret; } diff --git a/qemu/translate-all.c b/qemu/translate-all.c index bef5a154..d92d9afe 100644 --- a/qemu/translate-all.c +++ b/qemu/translate-all.c @@ -78,7 +78,7 @@ * mmap_lock. */ #ifdef CONFIG_SOFTMMU -#define assert_memory_lock() do { /* nothing */ } while (0) +#define assert_memory_lock() tcg_debug_assert(have_tb_lock) #else #define assert_memory_lock() tcg_debug_assert(have_mmap_lock()) #endif