From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [PATCH qom-next 09/59] cpus: Pass CPUState to qemu_cpu_is_self() Date: Wed, 23 May 2012 05:07:32 +0200 Message-ID: <1337742502-28565-10-git-send-email-afaerber@suse.de> References: <1337742502-28565-1-git-send-email-afaerber@suse.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , Avi Kivity (supporter:Overall), Marcelo Tosatti (supporter:Overall), kvm@vger.kernel.org (open list:Overall) To: qemu-devel@nongnu.org Return-path: Received: from cantor2.suse.de ([195.135.220.15]:35553 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964927Ab2EWDJB (ORCPT ); Tue, 22 May 2012 23:09:01 -0400 In-Reply-To: <1337742502-28565-1-git-send-email-afaerber@suse.de> Sender: kvm-owner@vger.kernel.org List-ID: Change return type to bool, move to include/qemu/cpu.h and add documentation. Signed-off-by: Andreas F=C3=A4rber --- cpus.c | 10 ++++------ exec.c | 3 ++- hw/apic.c | 2 +- include/qemu/cpu.h | 10 ++++++++++ kvm-all.c | 4 +++- qemu-common.h | 1 - target-i386/kvm.c | 6 ++++-- 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/cpus.c b/cpus.c index 7d8e2ad..8712259 100644 --- a/cpus.c +++ b/cpus.c @@ -640,9 +640,10 @@ void qemu_init_cpu_loop(void) =20 void run_on_cpu(CPUArchState *env, void (*func)(void *data), void *dat= a) { + CPUState *cpu =3D ENV_GET_CPU(env); struct qemu_work_item wi; =20 - if (qemu_cpu_is_self(env)) { + if (qemu_cpu_is_self(cpu)) { func(data); return; } @@ -857,7 +858,7 @@ static void qemu_cpu_kick_thread(CPUArchState *env) exit(1); } #else /* _WIN32 */ - if (!qemu_cpu_is_self(env)) { + if (!qemu_cpu_is_self(cpu)) { SuspendThread(cpu->hThread); cpu_signal(0); ResumeThread(cpu->hThread); @@ -892,11 +893,8 @@ void qemu_cpu_kick_self(void) #endif } =20 -int qemu_cpu_is_self(void *_env) +bool qemu_cpu_is_self(CPUState *cpu) { - CPUArchState *env =3D _env; - CPUState *cpu =3D ENV_GET_CPU(env); - return qemu_thread_is_self(cpu->thread); } =20 diff --git a/exec.c b/exec.c index a0494c7..79e553c 100644 --- a/exec.c +++ b/exec.c @@ -1734,6 +1734,7 @@ static void cpu_unlink_tb(CPUArchState *env) /* mask must never be zero, except for A20 change call */ static void tcg_handle_interrupt(CPUArchState *env, int mask) { + CPUState *cpu =3D ENV_GET_CPU(env); int old_mask; =20 old_mask =3D env->interrupt_request; @@ -1743,7 +1744,7 @@ static void tcg_handle_interrupt(CPUArchState *en= v, int mask) * If called from iothread context, wake the target cpu in * case its halted. */ - if (!qemu_cpu_is_self(env)) { + if (!qemu_cpu_is_self(cpu)) { qemu_cpu_kick(env); return; } diff --git a/hw/apic.c b/hw/apic.c index 1207c33..b14635d 100644 --- a/hw/apic.c +++ b/hw/apic.c @@ -114,7 +114,7 @@ static void apic_sync_vapic(APICCommonState *s, int= sync_type) length =3D offsetof(VAPICState, enabled) - offsetof(VAPICState= , isr); =20 if (sync_type & SYNC_TO_VAPIC) { - assert(qemu_cpu_is_self(&s->cpu->env)); + assert(qemu_cpu_is_self(CPU(s->cpu))); =20 vapic_state.tpr =3D s->tpr; vapic_state.enabled =3D 1; diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h index ad706a6..7be983d 100644 --- a/include/qemu/cpu.h +++ b/include/qemu/cpu.h @@ -78,5 +78,15 @@ struct CPUState { */ void cpu_reset(CPUState *cpu); =20 +/** + * 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); + =20 #endif diff --git a/kvm-all.c b/kvm-all.c index 9b73ccf..f25cf6d 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -831,9 +831,11 @@ static MemoryListener kvm_memory_listener =3D { =20 static void kvm_handle_interrupt(CPUArchState *env, int mask) { + CPUState *cpu =3D ENV_GET_CPU(env); + env->interrupt_request |=3D mask; =20 - if (!qemu_cpu_is_self(env)) { + if (!qemu_cpu_is_self(cpu)) { qemu_cpu_kick(env); } } diff --git a/qemu-common.h b/qemu-common.h index cccfb42..653e0e5 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -285,7 +285,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version= _id); /* Unblock cpu */ void qemu_cpu_kick(void *env); void qemu_cpu_kick_self(void); -int qemu_cpu_is_self(void *env); bool all_cpu_threads_idle(void); =20 /* work queue */ diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 97a2cb1..e9e2241 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1527,9 +1527,10 @@ static int kvm_get_debugregs(CPUX86State *env) =20 int kvm_arch_put_registers(CPUX86State *env, int level) { + CPUState *cpu =3D ENV_GET_CPU(env); int ret; =20 - assert(cpu_is_stopped(env) || qemu_cpu_is_self(env)); + assert(cpu_is_stopped(env) || qemu_cpu_is_self(cpu)); =20 ret =3D kvm_getput_regs(env, 1); if (ret < 0) { @@ -1584,9 +1585,10 @@ int kvm_arch_put_registers(CPUX86State *env, int= level) =20 int kvm_arch_get_registers(CPUX86State *env) { + CPUState *cpu =3D ENV_GET_CPU(env); int ret; =20 - assert(cpu_is_stopped(env) || qemu_cpu_is_self(env)); + assert(cpu_is_stopped(env) || qemu_cpu_is_self(cpu)); =20 ret =3D kvm_getput_regs(env, 0); if (ret < 0) { --=20 1.7.7 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SX1wf-0000KD-6K for qemu-devel@nongnu.org; Tue, 22 May 2012 23:09:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SX1wc-0005aY-Ji for qemu-devel@nongnu.org; Tue, 22 May 2012 23:09:04 -0400 Received: from cantor2.suse.de ([195.135.220.15]:35559 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SX1wc-0005ZY-9T for qemu-devel@nongnu.org; Tue, 22 May 2012 23:09:02 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 23 May 2012 05:07:32 +0200 Message-Id: <1337742502-28565-10-git-send-email-afaerber@suse.de> In-Reply-To: <1337742502-28565-1-git-send-email-afaerber@suse.de> References: <1337742502-28565-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH qom-next 09/59] cpus: Pass CPUState to qemu_cpu_is_self() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Marcelo Tosatti , =?UTF-8?q?Andreas=20F=C3=A4rber?= , "open list:Overall" , Avi Kivity Change return type to bool, move to include/qemu/cpu.h and add documentation. Signed-off-by: Andreas F=C3=A4rber --- cpus.c | 10 ++++------ exec.c | 3 ++- hw/apic.c | 2 +- include/qemu/cpu.h | 10 ++++++++++ kvm-all.c | 4 +++- qemu-common.h | 1 - target-i386/kvm.c | 6 ++++-- 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/cpus.c b/cpus.c index 7d8e2ad..8712259 100644 --- a/cpus.c +++ b/cpus.c @@ -640,9 +640,10 @@ void qemu_init_cpu_loop(void) =20 void run_on_cpu(CPUArchState *env, void (*func)(void *data), void *data) { + CPUState *cpu =3D ENV_GET_CPU(env); struct qemu_work_item wi; =20 - if (qemu_cpu_is_self(env)) { + if (qemu_cpu_is_self(cpu)) { func(data); return; } @@ -857,7 +858,7 @@ static void qemu_cpu_kick_thread(CPUArchState *env) exit(1); } #else /* _WIN32 */ - if (!qemu_cpu_is_self(env)) { + if (!qemu_cpu_is_self(cpu)) { SuspendThread(cpu->hThread); cpu_signal(0); ResumeThread(cpu->hThread); @@ -892,11 +893,8 @@ void qemu_cpu_kick_self(void) #endif } =20 -int qemu_cpu_is_self(void *_env) +bool qemu_cpu_is_self(CPUState *cpu) { - CPUArchState *env =3D _env; - CPUState *cpu =3D ENV_GET_CPU(env); - return qemu_thread_is_self(cpu->thread); } =20 diff --git a/exec.c b/exec.c index a0494c7..79e553c 100644 --- a/exec.c +++ b/exec.c @@ -1734,6 +1734,7 @@ static void cpu_unlink_tb(CPUArchState *env) /* mask must never be zero, except for A20 change call */ static void tcg_handle_interrupt(CPUArchState *env, int mask) { + CPUState *cpu =3D ENV_GET_CPU(env); int old_mask; =20 old_mask =3D env->interrupt_request; @@ -1743,7 +1744,7 @@ static void tcg_handle_interrupt(CPUArchState *env,= int mask) * If called from iothread context, wake the target cpu in * case its halted. */ - if (!qemu_cpu_is_self(env)) { + if (!qemu_cpu_is_self(cpu)) { qemu_cpu_kick(env); return; } diff --git a/hw/apic.c b/hw/apic.c index 1207c33..b14635d 100644 --- a/hw/apic.c +++ b/hw/apic.c @@ -114,7 +114,7 @@ static void apic_sync_vapic(APICCommonState *s, int s= ync_type) length =3D offsetof(VAPICState, enabled) - offsetof(VAPICState, = isr); =20 if (sync_type & SYNC_TO_VAPIC) { - assert(qemu_cpu_is_self(&s->cpu->env)); + assert(qemu_cpu_is_self(CPU(s->cpu))); =20 vapic_state.tpr =3D s->tpr; vapic_state.enabled =3D 1; diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h index ad706a6..7be983d 100644 --- a/include/qemu/cpu.h +++ b/include/qemu/cpu.h @@ -78,5 +78,15 @@ struct CPUState { */ void cpu_reset(CPUState *cpu); =20 +/** + * 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); + =20 #endif diff --git a/kvm-all.c b/kvm-all.c index 9b73ccf..f25cf6d 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -831,9 +831,11 @@ static MemoryListener kvm_memory_listener =3D { =20 static void kvm_handle_interrupt(CPUArchState *env, int mask) { + CPUState *cpu =3D ENV_GET_CPU(env); + env->interrupt_request |=3D mask; =20 - if (!qemu_cpu_is_self(env)) { + if (!qemu_cpu_is_self(cpu)) { qemu_cpu_kick(env); } } diff --git a/qemu-common.h b/qemu-common.h index cccfb42..653e0e5 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -285,7 +285,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_i= d); /* Unblock cpu */ void qemu_cpu_kick(void *env); void qemu_cpu_kick_self(void); -int qemu_cpu_is_self(void *env); bool all_cpu_threads_idle(void); =20 /* work queue */ diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 97a2cb1..e9e2241 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1527,9 +1527,10 @@ static int kvm_get_debugregs(CPUX86State *env) =20 int kvm_arch_put_registers(CPUX86State *env, int level) { + CPUState *cpu =3D ENV_GET_CPU(env); int ret; =20 - assert(cpu_is_stopped(env) || qemu_cpu_is_self(env)); + assert(cpu_is_stopped(env) || qemu_cpu_is_self(cpu)); =20 ret =3D kvm_getput_regs(env, 1); if (ret < 0) { @@ -1584,9 +1585,10 @@ int kvm_arch_put_registers(CPUX86State *env, int l= evel) =20 int kvm_arch_get_registers(CPUX86State *env) { + CPUState *cpu =3D ENV_GET_CPU(env); int ret; =20 - assert(cpu_is_stopped(env) || qemu_cpu_is_self(env)); + assert(cpu_is_stopped(env) || qemu_cpu_is_self(cpu)); =20 ret =3D kvm_getput_regs(env, 0); if (ret < 0) { --=20 1.7.7