From patchwork Thu Aug 16 15:30:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 1333601 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 364E53FC33 for ; Thu, 16 Aug 2012 15:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757567Ab2HPPaq (ORCPT ); Thu, 16 Aug 2012 11:30:46 -0400 Received: from mail-qc0-f174.google.com ([209.85.216.174]:62914 "EHLO mail-qc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751642Ab2HPPaq (ORCPT ); Thu, 16 Aug 2012 11:30:46 -0400 Received: by mail-qc0-f174.google.com with SMTP id o28so2210212qcr.19 for ; Thu, 16 Aug 2012 08:30:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:to:from:date:message-id:in-reply-to:references:user-agent :mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=ADeZyYH5eEjmOatUawieHzEUGnxy5M4M2BntYpbNjRQ=; b=U+Tk5n68uz3FFAyUh8//HBdtN11jh2ugjuqOuQC0ObpQsjaoJF9OhYYxyqTnCxY1QS PcZzwigguUNHr3FdTEFTI586m1WEJfeiR86TWXDf05IvX2beRXQdIU8BkGP7kvP+bhNK Asar9pT4ZnCOYO1tPzIWsgK7Ux/lvR4opEN/Sw3pEH51pPscsLJUBSvd0hy2utH1H+M+ Iq7jeQx0ZfuGXkIQamcJpvNyHGXl5l7RKIJa3xUhAiGKIrXESYkwj28N2FfbsmVfed0m 36Q6/lUbozAAS40BclQ2HQOP2M1TkAFkpB39MgD1r2EAUPg7rf1bobmj8V7XltNtXVv5 UoGQ== Received: by 10.224.221.143 with SMTP id ic15mr3945170qab.51.1345131045644; Thu, 16 Aug 2012 08:30:45 -0700 (PDT) Received: from [127.0.1.1] (pool-72-80-83-148.nycmny.fios.verizon.net. [72.80.83.148]) by mx.google.com with ESMTPS id dr6sm7002390qab.16.2012.08.16.08.30.44 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 16 Aug 2012 08:30:45 -0700 (PDT) Subject: [PATCH v10 14/14] KVM: ARM: Guest wait-for-interrupts (WFI) support To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org From: Christoffer Dall Date: Thu, 16 Aug 2012 11:30:43 -0400 Message-ID: <20120816153043.21484.91782.stgit@ubuntu> In-Reply-To: <20120816152637.21484.65421.stgit@ubuntu> References: <20120816152637.21484.65421.stgit@ubuntu> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQn/LQrm15xjU5Knd4h5qqC7KLwH6U8CJzJlMdBSObLTCiEpifKV7ZB6MnedgL52WASWPc+L Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Christoffer Dall When the guest executes a WFI instruction the operation is trapped to KVM, which emulates the instruction in software. There is no correlation between a guest executing a WFI instruction and actually putting the hardware into a low-power mode, since a KVM guest is essentially a process and the WFI instruction can be seen as 'sleep' call from this process. Therefore, we block the vcpu when the guest excecutes a wfi instruction and the IRQ or FIQ lines are not raised. When an interrupt comes in through KVM_IRQ_LINE (see previous patch) we signal the VCPU thread and unflag the VCPU to no longer wait for interrupts. Signed-off-by: Christoffer Dall --- arch/arm/kvm/arm.c | 10 ++++++++-- arch/arm/kvm/emulate.c | 13 ++++++++++++- arch/arm/kvm/trace.h | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 31ddf56..09a6800 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -313,9 +313,16 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, return -EINVAL; } +/** + * kvm_arch_vcpu_runnable - determine if the vcpu can be scheduled + * @v: The VCPU pointer + * + * If the guest CPU is not waiting for interrupts or an interrupt line is + * asserted, the CPU is by definition runnable. + */ int kvm_arch_vcpu_runnable(struct kvm_vcpu *v) { - return 0; + return !!v->arch.irq_lines; } int kvm_arch_vcpu_in_guest_mode(struct kvm_vcpu *v) @@ -581,7 +588,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) * Check conditions before entering the guest */ cond_resched(); - update_vttbr(vcpu->kvm); local_irq_disable(); diff --git a/arch/arm/kvm/emulate.c b/arch/arm/kvm/emulate.c index cc5fa89..6cbdb08 100644 --- a/arch/arm/kvm/emulate.c +++ b/arch/arm/kvm/emulate.c @@ -154,9 +154,20 @@ static int kvm_instr_index(u32 instr, u32 table[][2], int table_entries) return INSTR_NONE; } +/** + * kvm_handle_wfi - handle a wait-for-interrupts instruction executed by a guest + * @vcpu: the vcpu pointer + * @run: the kvm_run structure pointer + * + * Simply sets the wait_for_interrupts flag on the vcpu structure, which will + * halt execution of world-switches and schedule other host processes until + * there is an incoming IRQ or FIQ to the VM. + */ int kvm_handle_wfi(struct kvm_vcpu *vcpu, struct kvm_run *run) { - return 0; + trace_kvm_wfi(vcpu->arch.regs.pc); + kvm_vcpu_block(vcpu); + return 1; } diff --git a/arch/arm/kvm/trace.h b/arch/arm/kvm/trace.h index 325106c..28ed1a1 100644 --- a/arch/arm/kvm/trace.h +++ b/arch/arm/kvm/trace.h @@ -90,6 +90,22 @@ TRACE_EVENT(kvm_emulate_cp15_imp, __entry->CRm, __entry->Op2) ); +TRACE_EVENT(kvm_wfi, + TP_PROTO(unsigned long vcpu_pc), + TP_ARGS(vcpu_pc), + + TP_STRUCT__entry( + __field( unsigned long, vcpu_pc ) + ), + + TP_fast_assign( + __entry->vcpu_pc = vcpu_pc; + ), + + TP_printk("guest executed wfi at: 0x%08lx", __entry->vcpu_pc) +); + + #endif /* _TRACE_KVM_H */ #undef TRACE_INCLUDE_PATH