From patchwork Wed Jul 25 13:24:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 10237 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 2B57923E02 for ; Wed, 25 Jul 2012 13:24:41 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id EED0AA18C87 for ; Wed, 25 Jul 2012 13:24:40 +0000 (UTC) Received: by mail-gh0-f180.google.com with SMTP id z12so687253ghb.11 for ; Wed, 25 Jul 2012 06:24:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=M8KEGbXseU5InnEwGOeMM/yHjM0lDcR+exYXs5i5YwA=; b=CF2x9OBHy9ppM9IrrZtq5gN8/QOaN0Ey6IPerpIdecdIvbAe4xfFu89Z644y5QYdA+ Pag28LWbPg/7mJamAPLwUd9DAOlO9TDrD1W///jZxf2t/6BLTL/nGCymwy2I3U/ryOUe SwYgFmHMV4xJ8ina7e9ogxPDZ1LtCPZPpTdnFMYUK+aHORvxrgGaxa/Zu5lwH1oz3i1n GurvbBpmQ8J+uCvxoES5MUtekkfcVXhN5i36qyjW+Q1Bi8EXWGdn2HIa4u6AITIYIgM1 5UTewJRwXWPwbpJDkXspRuxS0+YNbGnCwNCHA7DThskjoaQlqPZo4iXeyaA92MxgRBLE 1qog== Received: by 10.42.155.200 with SMTP id v8mr24328486icw.12.1343222680434; Wed, 25 Jul 2012 06:24:40 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.153.7 with SMTP id i7csp90867ibw; Wed, 25 Jul 2012 06:24:36 -0700 (PDT) Received: by 10.216.241.202 with SMTP id g52mr10751497wer.212.1343222676182; Wed, 25 Jul 2012 06:24:36 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id n17si24446773wee.46.2012.07.25.06.24.35 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Jul 2012 06:24:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1Su1Zo-0006aj-7H; Wed, 25 Jul 2012 14:24:32 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Avi Kivity , Marcelo Tosatti , Jan Kiszka , Alexander Graf Subject: [PATCH 1/6] kvm: Decouple 'interrupt injection is async' from 'kernel irqchip' Date: Wed, 25 Jul 2012 14:24:27 +0100 Message-Id: <1343222672-25312-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1343222672-25312-1-git-send-email-peter.maydell@linaro.org> References: <1343222672-25312-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQntQ+aprx9O7EFEW5vXirQAVLcGKbiM3zi0WSIjdhYe3CGxJgozoqSucIo4UAGe7dGlL0iD On x86 interrupt injection is asynchronous (and therefore VCPU idle management is done in the kernel) if and only if there is an in-kernel irqchip. On other architectures this isn't necessarily true (they may always do asynchronous injection), so define a new kvm_async_interrupt_injection() function instead of misusing kvm_irqchip_in_kernel(). Signed-off-by: Peter Maydell Acked-by: Jan Kiszka --- cpus.c | 3 ++- kvm-all.c | 7 ++++++- kvm-stub.c | 1 + kvm.h | 11 +++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cpus.c b/cpus.c index 756e624..584b298 100644 --- a/cpus.c +++ b/cpus.c @@ -69,7 +69,8 @@ static bool cpu_thread_is_idle(CPUArchState *env) if (env->stopped || !runstate_is_running()) { return true; } - if (!env->halted || qemu_cpu_has_work(env) || kvm_irqchip_in_kernel()) { + if (!env->halted || qemu_cpu_has_work(env) || + kvm_async_interrupt_injection()) { return false; } return true; diff --git a/kvm-all.c b/kvm-all.c index 2148b20..3354c6f 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -100,6 +100,7 @@ struct KVMState KVMState *kvm_state; bool kvm_kernel_irqchip; +bool kvm_async_interrupt_injection; static const KVMCapabilityInfo kvm_required_capabilites[] = { KVM_CAP_INFO(USER_MEMORY), @@ -857,7 +858,7 @@ int kvm_irqchip_set_irq(KVMState *s, int irq, int level) struct kvm_irq_level event; int ret; - assert(kvm_irqchip_in_kernel()); + assert(kvm_async_interrupt_injection()); event.level = level; event.irq = irq; @@ -1201,6 +1202,10 @@ static int kvm_irqchip_create(KVMState *s) s->irqchip_inject_ioctl = KVM_IRQ_LINE_STATUS; } kvm_kernel_irqchip = true; + /* If we have an in-kernel IRQ chip then we must have asynchronous + * interrupt injection (though the reverse is not necessarily true) + */ + kvm_async_interrupt_injection = true; kvm_init_irq_routing(s); diff --git a/kvm-stub.c b/kvm-stub.c index d23b11c..b4023d1 100644 --- a/kvm-stub.c +++ b/kvm-stub.c @@ -19,6 +19,7 @@ KVMState *kvm_state; bool kvm_kernel_irqchip; +bool kvm_async_interrupt_injection; int kvm_init_vcpu(CPUArchState *env) { diff --git a/kvm.h b/kvm.h index 2617dd5..00abe36 100644 --- a/kvm.h +++ b/kvm.h @@ -24,13 +24,24 @@ extern int kvm_allowed; extern bool kvm_kernel_irqchip; +extern bool kvm_async_interrupt_injection; #if defined CONFIG_KVM || !defined NEED_CPU_H #define kvm_enabled() (kvm_allowed) #define kvm_irqchip_in_kernel() (kvm_kernel_irqchip) +/** + * kvm_async_interrupt_injection: + * + * Returns: true if we can inject interrupts into a KVM CPU + * asynchronously (ie by ioctl from any thread at any time) + * rather than having to do interrupt delivery synchronously + * (where the vcpu must be stopped at a suitable point first). + */ +#define kvm_async_interrupt_injection() (kvm_async_interrupt_injection) #else #define kvm_enabled() (0) #define kvm_irqchip_in_kernel() (false) +#define kvm_async_interrupt_injection() (false) #endif struct kvm_run;