From patchwork Mon Mar 20 10:58:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9633767 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 029B8601E9 for ; Mon, 20 Mar 2017 11:00:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA51A27F17 for ; Mon, 20 Mar 2017 11:00:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF33A27F9F; Mon, 20 Mar 2017 11:00:12 +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 7B74D27F17 for ; Mon, 20 Mar 2017 11:00:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753928AbdCTK6p (ORCPT ); Mon, 20 Mar 2017 06:58:45 -0400 Received: from mail-wr0-f177.google.com ([209.85.128.177]:35021 "EHLO mail-wr0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753777AbdCTK6g (ORCPT ); Mon, 20 Mar 2017 06:58:36 -0400 Received: by mail-wr0-f177.google.com with SMTP id g10so89499339wrg.2 for ; Mon, 20 Mar 2017 03:58:35 -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=8R6xlv263IF+A/Fyr6GZx1eBNONPihRH65y99kFEt/c=; b=f4mdi/gCIz2rmqUWQ0L9rUcqhqZbfc+JDdokr7yrOq4Ij+czX+rrj6rYECoSdEQOAt 3nU/+dvu8RUbU1N9+32P8djamrqJZNEA2qB7ZlhEK0bTvshyaOj6UkHrQPbMu54eKGNX mk8/Vr2meR9d1IzLiQeb6VT/4nUqMKiOjCWgA= 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=8R6xlv263IF+A/Fyr6GZx1eBNONPihRH65y99kFEt/c=; b=UgWJO7CXIWwi6gKMnRwX2nwPpFsRCVDJ3ef2O2vVX9nAcih4Qm8IxXuZytqt7BGtWH mV3C0rIt55tpEaIJcTrMbLe6Aq4HeoIDAa9j37OdV1eU3FvcmKnoLjoq9xz48kOimif3 /fDqvH2btE047qrSLyFt/tomH10PO6Cvijx0v0HXJMPo+2+8XF0TAorJFYNbUE/dZZlM zs1OXPiYy5QqfA8YaipjZ6OEy0JvPw1KtXkEJvbfDuDOpqU63SthirUe94AThgG8HaqZ +kA0MVzUHdeyIbg/naTPNKihrwotZw5xa47NU0bpVhvyfjpo451rxP5xCb9hGrFnpk9X hluA== X-Gm-Message-State: AFeK/H2BwxhZoBoJ1R6kzbiwesOCtOFs1fNgFiaG9oOYwk93fW8PqRbyLlWgn048NIpAlzao X-Received: by 10.223.164.201 with SMTP id h9mr23355116wrb.175.1490007514300; Mon, 20 Mar 2017 03:58:34 -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.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Mar 2017 03:58:33 -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 , Christoffer Dall Subject: [PATCH 9/9] KVM: arm/arm64: vgic: Improve sync_hwstate performance Date: Mon, 20 Mar 2017 11:58:18 +0100 Message-Id: <20170320105818.20481-10-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 There is no need to call any functions to fold LRs when we don't use any LRs and we don't need to mess with overflow flags, take spinlocks, or prune the AP list if the AP list is empty. Note: list_empty is a single atomic read (uses READ_ONCE) and can therefore check if a list is empty or not without the need to take the spinlock protecting the list. Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 093873e..8ecb009 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -639,15 +639,18 @@ void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu) { struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; - if (unlikely(!vgic_initialized(vcpu->kvm))) + /* An empty ap_list_head implies used_lrs == 0 */ + if (list_empty(&vcpu->arch.vgic_cpu.ap_list_head)) return; vgic_clear_uie(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; + if (vgic_cpu->used_lrs) { + vgic_fold_lr_state(vcpu); + vgic_cpu->used_lrs = 0; + } + + vgic_prune_ap_list(vcpu); } /* Flush our emulation state into the GIC hardware before entering the guest. */