From patchwork Sun Apr 23 17:08:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9695169 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 5DB17601E9 for ; Sun, 23 Apr 2017 17:34:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BB65209D8 for ; Sun, 23 Apr 2017 17:34:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FA56262F2; Sun, 23 Apr 2017 17:34: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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable 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 BE56B209D8 for ; Sun, 23 Apr 2017 17:34:11 +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=nPvGx55VkXB1ySkd04rG5c4K74ek7gAYcncc6Ra04Es=; b=fT0x4Ttx8ClT67uBd9S96CuiZ9 CTde6lhHD2JQmzKjQ/mnlbMenSfwjCne/zEl9lIOcNvhqdI/RI0ayjVub2WT3lbWVaNQasZb/lOla kbWytiY4UElmaN9IJ/5A8pQSv+WoYidCUylj/ch5xRcgEQ/4CbS46ehMu/mQVYH8CwQLr5wBUmyP5 ESQOCYXYIbcTkdwp8KEz8vY10nYK+HJywS+J32jCOmN9Ek/LqjzwhB0cPSaSSwI7IB7EZz65G4/ri XlS//JXoXIx2GwStWV6zLLxQKR4CEoxh210p5r/7ACBVpg0zxr76BEYo1oNR3KaiBPEFkvcWBtQW/ EocMuaUQ==; 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 1d2LOk-0006Nq-S8; Sun, 23 Apr 2017 17:34:10 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d2LM3-0002ZO-2x for linux-arm-kernel@bombadil.infradead.org; Sun, 23 Apr 2017 17:31:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=1WyWhA5Unxu4BpeRjrI9YlwMQE8fc0fr0tC11p1qsGM=; b=JN6rXRhCmEz9qcB8EnT2TPych 320jjO2KtG7J1/++6KK1ZPmskZjr0sUN9tVv0JR3BxxFXHvawAHDg5npb6ml2wh1HNfzKXxLgOzUr v9xjigVTfhVyLgaIho33BjEM8gjcA5lFUvOoLAJF4X1RoYZU/Wg4IjbKWLsptlB+BON/VSRJjRF05 gasWsdtM2TJmhrIK0EnC1q1AKB3W0VojGyUnovCAD/dQ1g/DERXevnwbkIPYXnkHgrbJ3VJCSVd3o QZpu3gkGZ5KYo65X9W2bfs0Cz71K+BQTnjBvgMFJEOvb18tb0GXwq1FHy/CbQ/mFvW53dKfDx7tOb ZB2IyOn6g==; Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d2L3c-0005Ld-JO for linux-arm-kernel@lists.infradead.org; Sun, 23 Apr 2017 17:12:21 +0000 Received: by mail-wm0-x22b.google.com with SMTP id r190so50448914wme.1 for ; Sun, 23 Apr 2017 10:12:00 -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=1WyWhA5Unxu4BpeRjrI9YlwMQE8fc0fr0tC11p1qsGM=; b=F6DvzglRAhbGNXVQY4bZ3aF9x69FuNbhPU+tkW6N8VbMHQLLqD9noe5M7xzA1iI7ov JMnuu0J+Q/01WXpbD64Bn5qgxNEx2zzcD4unfUiMXjm7Iux9YX/GmPy2v9TqRPsmdc26 3ZQKHMkcFQydv7tQDvZwrE/Jz7lihbnZNRKjk= 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=1WyWhA5Unxu4BpeRjrI9YlwMQE8fc0fr0tC11p1qsGM=; b=eZb3zMWCDikM02yGC8oWeqR7PxP9643yBxxnMShyJzKIR7snkgPgGACYlS0hjvpwRP gKu+G5vkELHgjyUIUpqHXtArl6tVHEIIgyk8y3FjDDSEmp3FV+hrQzzEAjoejPcRnYo6 qOsMDLeczkuCleMyWnUxSoRnRNroSVFHjEhz/+rJREYKWnM6fb8G3CDcxJ+Yh1Ja3y5e SoD8oml5uwowvqtYIXgJoDKfb1mIcbQGdH9LwZ0I/0NADZmNhUuPDJcCcrL7WyFbKRNH y/1ixViTFQP/OCZ8ncouiO36YCS98fZH/k7abniD7B7f+HOy4j7SAIElGAPifZ6tNubO wyRw== X-Gm-Message-State: AN3rC/4VtxC9ag8jNFFxntnXzBJL3IXY7cS8jifEJtF/Q8glS3nSC2Fy WUr0hoxTIGdsKUtoithrJQ== X-Received: by 10.80.154.230 with SMTP id p93mr140337edb.84.1492967398726; Sun, 23 Apr 2017 10:09:58 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id 58sm2803521edz.2.2017.04.23.10.09.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Apr 2017 10:09:58 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 26/79] KVM: arm/arm64: vgic: Improve sync_hwstate performance Date: Sun, 23 Apr 2017 19:08:36 +0200 Message-Id: <20170423170929.27334-27-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170423170929.27334-1-cdall@linaro.org> References: <20170423170929.27334-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170423_131220_794680_F8E3C385 X-CRM114-Status: GOOD ( 14.18 ) 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 , Christoffer Dall , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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. Reviewed-by: Marc Zyngier Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic-v2.c | 7 +++++-- virt/kvm/arm/vgic/vgic-v3.c | 7 +++++-- virt/kvm/arm/vgic/vgic.c | 10 ++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-v2.c b/virt/kvm/arm/vgic/vgic-v2.c index b58b086..025b57d 100644 --- a/virt/kvm/arm/vgic/vgic-v2.c +++ b/virt/kvm/arm/vgic/vgic-v2.c @@ -44,12 +44,13 @@ static bool lr_signals_eoi_mi(u32 lr_val) */ void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu) { - struct vgic_v2_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v2; + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; + struct vgic_v2_cpu_if *cpuif = &vgic_cpu->vgic_v2; int lr; cpuif->vgic_hcr &= ~GICH_HCR_UIE; - for (lr = 0; lr < vcpu->arch.vgic_cpu.used_lrs; lr++) { + for (lr = 0; lr < vgic_cpu->used_lrs; lr++) { u32 val = cpuif->vgic_lr[lr]; u32 intid = val & GICH_LR_VIRTUALID; struct vgic_irq *irq; @@ -91,6 +92,8 @@ void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu) spin_unlock(&irq->irq_lock); vgic_put_irq(vcpu->kvm, irq); } + + vgic_cpu->used_lrs = 0; } /* diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c index 4f2dce6..bc7010d 100644 --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c @@ -36,13 +36,14 @@ static bool lr_signals_eoi_mi(u64 lr_val) void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu) { - struct vgic_v3_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v3; + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; + struct vgic_v3_cpu_if *cpuif = &vgic_cpu->vgic_v3; u32 model = vcpu->kvm->arch.vgic.vgic_model; int lr; cpuif->vgic_hcr &= ~ICH_HCR_UIE; - for (lr = 0; lr < vcpu->arch.vgic_cpu.used_lrs; lr++) { + for (lr = 0; lr < vgic_cpu->used_lrs; lr++) { u64 val = cpuif->vgic_lr[lr]; u32 intid; struct vgic_irq *irq; @@ -92,6 +93,8 @@ void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu) spin_unlock(&irq->irq_lock); vgic_put_irq(vcpu->kvm, irq); } + + vgic_cpu->used_lrs = 0; } /* Requires the irq to be locked already */ diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 04a405a..3d0979c 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -633,11 +633,13 @@ void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu) { struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; - vgic_fold_lr_state(vcpu); - vgic_prune_ap_list(vcpu); + /* An empty ap_list_head implies used_lrs == 0 */ + if (list_empty(&vcpu->arch.vgic_cpu.ap_list_head)) + return; - /* 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_prune_ap_list(vcpu); } /* Flush our emulation state into the GIC hardware before entering the guest. */