From patchwork Mon Mar 20 10:58:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9633719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2BD4860327 for ; Mon, 20 Mar 2017 10:59:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EF5227F94 for ; Mon, 20 Mar 2017 10:59:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13AD42807B; Mon, 20 Mar 2017 10:59:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 042A927FA7 for ; Mon, 20 Mar 2017 10:59:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754135AbdCTK6x (ORCPT ); Mon, 20 Mar 2017 06:58:53 -0400 Received: from mail-wr0-f170.google.com ([209.85.128.170]:34962 "EHLO mail-wr0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753720AbdCTK62 (ORCPT ); Mon, 20 Mar 2017 06:58:28 -0400 Received: by mail-wr0-f170.google.com with SMTP id g10so89496967wrg.2 for ; Mon, 20 Mar 2017 03:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5sk6JScLhWReZRAIZNokFeIGmSgSIVYOte1lrHpoKMg=; b=N6TKV5Hf/f+8jzdVVxpxYAMCUMBO0PUQuybXcCcJGFPU4kQwLIapPwFsIwr3P0bE6W zQcpS3n4I3KQ9f+NCVUKffHn9wONvU+wwSnlCoeUcXfMMwTbYkFSFgETIywHmP+NdoLk tRr2zO54cgwyiskc/ACpoomnbpP4MagNmmN7I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5sk6JScLhWReZRAIZNokFeIGmSgSIVYOte1lrHpoKMg=; b=OLJ9go7PaHpq71q34dc+BXc9jeEIbfJKLegYGcATr/OsFy4yY6KsoMbVO9yeuFC1JT a4vk8FjXbsMroGu76uC65drY6z5TDy6pPI3/6zIyOf2rZVbQMQNTQKfJwtr35nVUbTW7 0mAJnsTBjfBDneMa+/eGx02gF62VPxvxy+hmcq2MyS8nxUnU1aePijn7M4Jtz4K2Spfr QmJ7y6PGhomJq3xJCvtT1W38fLBEpq4DNo5rU0H+40YW9bdlXr0bM7//gyjw1FpGWeOb CqHU+LGTZ4SCUKi0WmOW6m2tz0P52yxot20UPWqmdpqZm7DKGnkvcJduultQfTMeNREY RRcg== X-Gm-Message-State: AFeK/H0L2TJnNuduj8yAXwAWlZwApoqBxHeduU34VtIhc1ZtZGfleJfucTvu3UbDs84krIBb X-Received: by 10.223.176.143 with SMTP id i15mr26139034wra.136.1490007506534; Mon, 20 Mar 2017 03:58:26 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id q1sm10372065wra.65.2017.03.20.03.58.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Mar 2017 03:58:23 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Marc Zyngier , Andre Przywara , Eric Auger , Shih-Wei Li , Christoffer Dall Subject: [PATCH 2/9] KVM: arm/arm64: vgic: Avoid flushing vgic state when there's no pending IRQ Date: Mon, 20 Mar 2017 11:58:11 +0100 Message-Id: <20170320105818.20481-3-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170320105818.20481-1-cdall@linaro.org> References: <20170320105818.20481-1-cdall@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Shih-Wei Li We do not need to flush vgic states in each world switch unless there is pending IRQ queued to the vgic's ap list. We can thus reduce the overhead by not grabbing the spinlock and not making the extra function call to vgic_flush_lr_state. Signed-off-by: Shih-Wei Li Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 2ac0def..1436c2e 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -637,12 +637,17 @@ static void vgic_flush_lr_state(struct kvm_vcpu *vcpu) /* Sync back the hardware VGIC state into our emulation after a guest's run. */ void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu) { + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; + if (unlikely(!vgic_initialized(vcpu->kvm))) return; vgic_process_maintenance_interrupt(vcpu); vgic_fold_lr_state(vcpu); vgic_prune_ap_list(vcpu); + + /* Make sure we can fast-path in flush_hwstate */ + vgic_cpu->used_lrs = 0; } /* Flush our emulation state into the GIC hardware before entering the guest. */ @@ -651,6 +656,9 @@ void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu) if (unlikely(!vgic_initialized(vcpu->kvm))) return; + if (list_empty(&vcpu->arch.vgic_cpu.ap_list_head)) + return; + spin_lock(&vcpu->arch.vgic_cpu.ap_list_lock); vgic_flush_lr_state(vcpu); spin_unlock(&vcpu->arch.vgic_cpu.ap_list_lock);