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: 9633757 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 7BBAD601E9 for ; Mon, 20 Mar 2017 10:59:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CDAD27F85 for ; Mon, 20 Mar 2017 10:59:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FB5B27FA6; Mon, 20 Mar 2017 10:59:44 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BE3A727F85 for ; Mon, 20 Mar 2017 10:59:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=el4LFfnEZuxC+bjCanuG+j4PqFJD/95Lxmj1JiXMe0M=; b=czlKGL7EQgxarhVuUsuLlvCl9Z VSFQviXIB4pRllJxwGG+wp6/YDeM+PRzSuO8OMo3ZujLgbtoCqCp1iG8q4t+Nf/5x5HAEazxOIt5b Aw4jv4kAmRDbZBn24T+WwJ6mqEd3aIOmPj+iWdbGd8f5CFsr92FQIXZ0Y7iV3GCYt2UCF8J4D6vlw Rx5bQNXcTLxS6Y9x8OGfvvqs7mc3JN51e6Dzph+FYGkHOlqFdzTvPj3BsvzQ4fwn5Kyq4/rJR4TRM +MvtxkMANMjzKmBYr7XUcwZvp7T4JR2RRgsYN8A6eWqvlIs0OUS3aqvKCsO4LWbKROboFzkEVNlWY wnqdwLKA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cpv2M-0007Nz-QV; Mon, 20 Mar 2017 10:59:42 +0000 Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cpv1Y-00067b-WE for linux-arm-kernel@lists.infradead.org; Mon, 20 Mar 2017 10:58:57 +0000 Received: by mail-wr0-x234.google.com with SMTP id g10so89499336wrg.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=SFk47xHiTIs7Z9R414OfEY539NyE0hqTWDcMS4Zsnok8QU4YYUaxFyDthX8OFSJOag K2UWTjS1PrxxgyGjQ1kmVG6j3qfcsSsyedcOzM3SiDOuBsfNJMhy3KRHzVE3QIoJua8Z 6meMV21E5SoCxpjoIGtoep/1L6pDRcQ4VfGWWsjcTpHEe3ZTqSwmLIe5DX2GsNGmE6qy IXTNPUY3hl696yRQviMuUUO89/6RG/+kHVUzQ4kMQPnqMzbIPP+CFR7wDdtOi3W90dej vMzcFvBliJb8/cFLXhE229Xm4jPMAndEyC+TekBrE7k2kDGBq3IL1LXtHiew+wGRXmuR n5sQ== X-Gm-Message-State: AFeK/H2OAR7ZyDQL1LOdGdntjQLfKsNppjj4uK9MIMwUmin8NnV/HetmjMV8Ce2Nte/XF7NI 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170320_035853_557437_F6FB8BA1 X-CRM114-Status: GOOD ( 15.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Andre Przywara , Christoffer Dall , kvm@vger.kernel.org, Eric Auger MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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. */