cpus: Pass CPUState to qemu_cpu_is_self()

Change return type to bool, move to include/qemu/cpu.h and
add documentation.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
[AF: Updated new caller qemu_in_vcpu_thread()]
This commit is contained in:
Andreas Färber 2012-05-02 22:23:49 +02:00
parent e9f9d6b165
commit 60e82579c7
7 changed files with 28 additions and 14 deletions

12
cpus.c
View File

@ -638,9 +638,10 @@ void qemu_init_cpu_loop(void)
void run_on_cpu(CPUArchState *env, void (*func)(void *data), void *data) void run_on_cpu(CPUArchState *env, void (*func)(void *data), void *data)
{ {
CPUState *cpu = ENV_GET_CPU(env);
struct qemu_work_item wi; struct qemu_work_item wi;
if (qemu_cpu_is_self(env)) { if (qemu_cpu_is_self(cpu)) {
func(data); func(data);
return; return;
} }
@ -855,7 +856,7 @@ static void qemu_cpu_kick_thread(CPUArchState *env)
exit(1); exit(1);
} }
#else /* _WIN32 */ #else /* _WIN32 */
if (!qemu_cpu_is_self(env)) { if (!qemu_cpu_is_self(cpu)) {
SuspendThread(cpu->hThread); SuspendThread(cpu->hThread);
cpu_signal(0); cpu_signal(0);
ResumeThread(cpu->hThread); ResumeThread(cpu->hThread);
@ -890,17 +891,14 @@ void qemu_cpu_kick_self(void)
#endif #endif
} }
int qemu_cpu_is_self(void *_env) bool qemu_cpu_is_self(CPUState *cpu)
{ {
CPUArchState *env = _env;
CPUState *cpu = ENV_GET_CPU(env);
return qemu_thread_is_self(cpu->thread); return qemu_thread_is_self(cpu->thread);
} }
static bool qemu_in_vcpu_thread(void) static bool qemu_in_vcpu_thread(void)
{ {
return cpu_single_env && qemu_cpu_is_self(cpu_single_env); return cpu_single_env && qemu_cpu_is_self(ENV_GET_CPU(cpu_single_env));
} }
void qemu_mutex_lock_iothread(void) void qemu_mutex_lock_iothread(void)

3
exec.c
View File

@ -1693,6 +1693,7 @@ static void cpu_unlink_tb(CPUArchState *env)
/* mask must never be zero, except for A20 change call */ /* mask must never be zero, except for A20 change call */
static void tcg_handle_interrupt(CPUArchState *env, int mask) static void tcg_handle_interrupt(CPUArchState *env, int mask)
{ {
CPUState *cpu = ENV_GET_CPU(env);
int old_mask; int old_mask;
old_mask = env->interrupt_request; old_mask = env->interrupt_request;
@ -1702,7 +1703,7 @@ static void tcg_handle_interrupt(CPUArchState *env, int mask)
* If called from iothread context, wake the target cpu in * If called from iothread context, wake the target cpu in
* case its halted. * case its halted.
*/ */
if (!qemu_cpu_is_self(env)) { if (!qemu_cpu_is_self(cpu)) {
qemu_cpu_kick(env); qemu_cpu_kick(env);
return; return;
} }

View File

@ -107,7 +107,7 @@ static void apic_sync_vapic(APICCommonState *s, int sync_type)
length = offsetof(VAPICState, enabled) - offsetof(VAPICState, isr); length = offsetof(VAPICState, enabled) - offsetof(VAPICState, isr);
if (sync_type & SYNC_TO_VAPIC) { if (sync_type & SYNC_TO_VAPIC) {
assert(qemu_cpu_is_self(&s->cpu->env)); assert(qemu_cpu_is_self(CPU(s->cpu)));
vapic_state.tpr = s->tpr; vapic_state.tpr = s->tpr;
vapic_state.enabled = 1; vapic_state.enabled = 1;
@ -363,10 +363,12 @@ static int apic_irq_pending(APICCommonState *s)
/* signal the CPU if an irq is pending */ /* signal the CPU if an irq is pending */
static void apic_update_irq(APICCommonState *s) static void apic_update_irq(APICCommonState *s)
{ {
CPUState *cpu = CPU(s->cpu);
if (!(s->spurious_vec & APIC_SV_ENABLE)) { if (!(s->spurious_vec & APIC_SV_ENABLE)) {
return; return;
} }
if (!qemu_cpu_is_self(&s->cpu->env)) { if (!qemu_cpu_is_self(cpu)) {
cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_POLL); cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_POLL);
} else if (apic_irq_pending(s) > 0) { } else if (apic_irq_pending(s) > 0) {
cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD); cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);

View File

@ -78,5 +78,15 @@ struct CPUState {
*/ */
void cpu_reset(CPUState *cpu); void cpu_reset(CPUState *cpu);
/**
* qemu_cpu_is_self:
* @cpu: The vCPU to check against.
*
* Checks whether the caller is executing on the vCPU thread.
*
* Returns: %true if called from @cpu's thread, %false otherwise.
*/
bool qemu_cpu_is_self(CPUState *cpu);
#endif #endif

View File

@ -828,9 +828,11 @@ static MemoryListener kvm_io_listener = {
static void kvm_handle_interrupt(CPUArchState *env, int mask) static void kvm_handle_interrupt(CPUArchState *env, int mask)
{ {
CPUState *cpu = ENV_GET_CPU(env);
env->interrupt_request |= mask; env->interrupt_request |= mask;
if (!qemu_cpu_is_self(env)) { if (!qemu_cpu_is_self(cpu)) {
qemu_cpu_kick(env); qemu_cpu_kick(env);
} }
} }

View File

@ -326,7 +326,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id);
/* Unblock cpu */ /* Unblock cpu */
void qemu_cpu_kick(void *env); void qemu_cpu_kick(void *env);
void qemu_cpu_kick_self(void); void qemu_cpu_kick_self(void);
int qemu_cpu_is_self(void *env);
/* work queue */ /* work queue */
struct qemu_work_item { struct qemu_work_item {

View File

@ -1552,9 +1552,10 @@ static int kvm_get_debugregs(CPUX86State *env)
int kvm_arch_put_registers(CPUX86State *env, int level) int kvm_arch_put_registers(CPUX86State *env, int level)
{ {
CPUState *cpu = ENV_GET_CPU(env);
int ret; int ret;
assert(cpu_is_stopped(env) || qemu_cpu_is_self(env)); assert(cpu_is_stopped(env) || qemu_cpu_is_self(cpu));
ret = kvm_getput_regs(env, 1); ret = kvm_getput_regs(env, 1);
if (ret < 0) { if (ret < 0) {
@ -1609,9 +1610,10 @@ int kvm_arch_put_registers(CPUX86State *env, int level)
int kvm_arch_get_registers(CPUX86State *env) int kvm_arch_get_registers(CPUX86State *env)
{ {
CPUState *cpu = ENV_GET_CPU(env);
int ret; int ret;
assert(cpu_is_stopped(env) || qemu_cpu_is_self(env)); assert(cpu_is_stopped(env) || qemu_cpu_is_self(cpu));
ret = kvm_getput_regs(env, 0); ret = kvm_getput_regs(env, 0);
if (ret < 0) { if (ret < 0) {