From patchwork Wed Oct 31 00:59:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 1675201 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id D62D1DFB7B for ; Wed, 31 Oct 2012 01:00:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934135Ab2JaBA1 (ORCPT ); Tue, 30 Oct 2012 21:00:27 -0400 Received: from cantor2.suse.de ([195.135.220.15]:52358 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933435Ab2JaBA1 (ORCPT ); Tue, 30 Oct 2012 21:00:27 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 4EB38A3D59; Wed, 31 Oct 2012 02:00:25 +0100 (CET) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Cc: anthony@codemonkey.ws, =?UTF-8?q?Andreas=20F=C3=A4rber?= , Avi Kivity (supporter:Overall), Marcelo Tosatti (supporter:Overall), kvm@vger.kernel.org (open list:Overall) Subject: [PATCH 07/35] cpus: Pass CPUState to qemu_cpu_is_self() Date: Wed, 31 Oct 2012 01:59:38 +0100 Message-Id: <1351645206-3041-8-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1351645206-3041-1-git-send-email-afaerber@suse.de> References: <1351645206-3041-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Change return type to bool, move to include/qemu/cpu.h and add documentation. Signed-off-by: Andreas Färber Reviewed-by: Igor Mammedov [AF: Updated new caller qemu_in_vcpu_thread()] --- cpus.c | 12 +++++------- exec.c | 3 ++- hw/apic.c | 6 ++++-- include/qemu/cpu.h | 10 ++++++++++ kvm-all.c | 4 +++- qemu-common.h | 1 - target-i386/kvm.c | 6 ++++-- 7 Dateien geändert, 28 Zeilen hinzugefügt(+), 14 Zeilen entfernt(-) diff --git a/cpus.c b/cpus.c index 191cbf5..1f3ac91 100644 --- a/cpus.c +++ b/cpus.c @@ -638,9 +638,10 @@ void qemu_init_cpu_loop(void) void run_on_cpu(CPUArchState *env, void (*func)(void *data), void *data) { + CPUState *cpu = ENV_GET_CPU(env); struct qemu_work_item wi; - if (qemu_cpu_is_self(env)) { + if (qemu_cpu_is_self(cpu)) { func(data); return; } @@ -855,7 +856,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); @@ -890,17 +891,14 @@ void qemu_cpu_kick_self(void) #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); } 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) diff --git a/exec.c b/exec.c index b0ed593..a85a9b1 100644 --- a/exec.c +++ b/exec.c @@ -1693,6 +1693,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 = ENV_GET_CPU(env); int old_mask; 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 * 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 4bc14e0..f73fc87 100644 --- a/hw/apic.c +++ b/hw/apic.c @@ -107,7 +107,7 @@ static void apic_sync_vapic(APICCommonState *s, int sync_type) length = offsetof(VAPICState, enabled) - offsetof(VAPICState, isr); 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.enabled = 1; @@ -363,10 +363,12 @@ static int apic_irq_pending(APICCommonState *s) /* signal the CPU if an irq is pending */ static void apic_update_irq(APICCommonState *s) { + CPUState *cpu = CPU(s->cpu); + if (!(s->spurious_vec & APIC_SV_ENABLE)) { return; } - if (!qemu_cpu_is_self(&s->cpu->env)) { + if (!qemu_cpu_is_self(cpu)) { cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_POLL); } else if (apic_irq_pending(s) > 0) { cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD); 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); +/** + * 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 diff --git a/kvm-all.c b/kvm-all.c index 961e1db..74d2652 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -828,9 +828,11 @@ static MemoryListener kvm_io_listener = { static void kvm_handle_interrupt(CPUArchState *env, int mask) { + CPUState *cpu = ENV_GET_CPU(env); + env->interrupt_request |= mask; - 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 b54612b..2094742 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -326,7 +326,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); /* work queue */ struct qemu_work_item { diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 3aa62b2..c13f196 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1552,9 +1552,10 @@ static int kvm_get_debugregs(CPUX86State *env) int kvm_arch_put_registers(CPUX86State *env, int level) { + CPUState *cpu = ENV_GET_CPU(env); 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); if (ret < 0) { @@ -1609,9 +1610,10 @@ int kvm_arch_put_registers(CPUX86State *env, int level) int kvm_arch_get_registers(CPUX86State *env) { + CPUState *cpu = ENV_GET_CPU(env); 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); if (ret < 0) {