[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 10/43] tcg: introduce tcg_current_cpu
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 10/43] tcg: introduce tcg_current_cpu |
Date: |
Wed, 9 Sep 2015 15:49:40 +0200 |
This is already useful on Windows in order to remove tls.h, because
accesses to current_cpu are done from a different thread on that
platform. It will be used on POSIX platforms as soon TCG stops using
signals to interrupt the execution of translated code.
Reviewed-by: Richard Henderson <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
cpu-exec.c | 14 +++++---------
cpus.c | 5 +++--
include/exec/exec-all.h | 1 +
3 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index 713540f..5153f1b 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -342,6 +342,7 @@ static void cpu_handle_debug_exception(CPUState *cpu)
/* main execution loop */
volatile sig_atomic_t exit_request;
+CPUState *tcg_current_cpu;
int cpu_exec(CPUState *cpu)
{
@@ -368,15 +369,7 @@ int cpu_exec(CPUState *cpu)
}
current_cpu = cpu;
-
- /* As long as current_cpu is null, up to the assignment just above,
- * requests by other threads to exit the execution loop are expected to
- * be issued using the exit_request global. We must make sure that our
- * evaluation of the global value is performed past the current_cpu
- * value transition point, which requires a memory barrier as well as
- * an instruction scheduling constraint on modern architectures. */
- smp_mb();
-
+ atomic_mb_set(&tcg_current_cpu, cpu);
rcu_read_lock();
if (unlikely(exit_request)) {
@@ -579,5 +572,8 @@ int cpu_exec(CPUState *cpu)
/* fail safe : never use current_cpu outside cpu_exec() */
current_cpu = NULL;
+
+ /* Does not need atomic_mb_set because a spurious wakeup is okay. */
+ atomic_set(&tcg_current_cpu, NULL);
return ret;
}
diff --git a/cpus.c b/cpus.c
index e831aa3..6cebb7a 100644
--- a/cpus.c
+++ b/cpus.c
@@ -663,8 +663,9 @@ static void cpu_handle_guest_debug(CPUState *cpu)
static void cpu_signal(int sig)
{
- if (current_cpu) {
- cpu_exit(current_cpu);
+ CPUState *cpu = atomic_mb_read(&tcg_current_cpu);
+ if (cpu) {
+ cpu_exit(cpu);
}
exit_request = 1;
}
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 83b9251..d5dd48f 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -387,6 +387,7 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1,
target_ulong addr);
extern int singlestep;
/* cpu-exec.c */
+extern CPUState *tcg_current_cpu;
extern volatile sig_atomic_t exit_request;
#if !defined(CONFIG_USER_ONLY)
--
2.4.3
- [Qemu-devel] [PULL 00/43] First batch of misc changes for 2.5 (2015-09-09), Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 02/43] seqlock: add missing 'inline' to seqlock_read_retry, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 01/43] qemu-thread: handle spurious futex_wait wakeups, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 03/43] seqlock: read sequence number atomically, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 04/43] cpus.c: qemu_mutex_lock_iothread fix race condition at cpu thread init, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 05/43] iohandler: Use aio API, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 08/43] i8257: rewrite DMA_schedule to avoid hooking into the CPU loop, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 06/43] block/iscsi: validate block size returned from target, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 10/43] tcg: introduce tcg_current_cpu,
Paolo Bonzini <=
- [Qemu-devel] [PULL 07/43] Added generic panic handler qemu_system_guest_panicked(), Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 09/43] i8257: remove cpu_request_exit irq, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 14/43] tcg: synchronize exit_request and tcg_current_cpu accesses, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 15/43] use qemu_cpu_kick instead of cpu_exit or qemu_cpu_kick_thread, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 11/43] remove qemu/tls.h, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 13/43] tcg: synchronize cpu->exit_request and cpu->tcg_exit_req accesses, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 16/43] tcg: signal-free qemu_cpu_kick, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 12/43] tcg: assign cpu->current_tb in a simpler place, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 18/43] Makefile.target: include top level build dir in vpath, Paolo Bonzini, 2015/09/09
- [Qemu-devel] [PULL 17/43] Move RAMBlock and ram_list to ram_addr.h, Paolo Bonzini, 2015/09/09