mirror of https://gitee.com/openkylin/qemu.git
tcg: introduce tcg_current_cpu
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 <rth@twiddle.net> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
5039d6e235
commit
9373e63297
14
cpu-exec.c
14
cpu-exec.c
|
@ -342,6 +342,7 @@ static void cpu_handle_debug_exception(CPUState *cpu)
|
||||||
/* main execution loop */
|
/* main execution loop */
|
||||||
|
|
||||||
volatile sig_atomic_t exit_request;
|
volatile sig_atomic_t exit_request;
|
||||||
|
CPUState *tcg_current_cpu;
|
||||||
|
|
||||||
int cpu_exec(CPUState *cpu)
|
int cpu_exec(CPUState *cpu)
|
||||||
{
|
{
|
||||||
|
@ -368,15 +369,7 @@ int cpu_exec(CPUState *cpu)
|
||||||
}
|
}
|
||||||
|
|
||||||
current_cpu = cpu;
|
current_cpu = cpu;
|
||||||
|
atomic_mb_set(&tcg_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();
|
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
|
|
||||||
if (unlikely(exit_request)) {
|
if (unlikely(exit_request)) {
|
||||||
|
@ -579,5 +572,8 @@ int cpu_exec(CPUState *cpu)
|
||||||
|
|
||||||
/* fail safe : never use current_cpu outside cpu_exec() */
|
/* fail safe : never use current_cpu outside cpu_exec() */
|
||||||
current_cpu = NULL;
|
current_cpu = NULL;
|
||||||
|
|
||||||
|
/* Does not need atomic_mb_set because a spurious wakeup is okay. */
|
||||||
|
atomic_set(&tcg_current_cpu, NULL);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
5
cpus.c
5
cpus.c
|
@ -663,8 +663,9 @@ static void cpu_handle_guest_debug(CPUState *cpu)
|
||||||
|
|
||||||
static void cpu_signal(int sig)
|
static void cpu_signal(int sig)
|
||||||
{
|
{
|
||||||
if (current_cpu) {
|
CPUState *cpu = atomic_mb_read(&tcg_current_cpu);
|
||||||
cpu_exit(current_cpu);
|
if (cpu) {
|
||||||
|
cpu_exit(cpu);
|
||||||
}
|
}
|
||||||
exit_request = 1;
|
exit_request = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -387,6 +387,7 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr);
|
||||||
extern int singlestep;
|
extern int singlestep;
|
||||||
|
|
||||||
/* cpu-exec.c */
|
/* cpu-exec.c */
|
||||||
|
extern CPUState *tcg_current_cpu;
|
||||||
extern volatile sig_atomic_t exit_request;
|
extern volatile sig_atomic_t exit_request;
|
||||||
|
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
#if !defined(CONFIG_USER_ONLY)
|
||||||
|
|
Loading…
Reference in New Issue