From patchwork Tue Jan 10 11:38:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Punit Agrawal X-Patchwork-Id: 9507001 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 5FF80601E9 for ; Tue, 10 Jan 2017 11:41:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53BD727BFF for ; Tue, 10 Jan 2017 11:41:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48A1F283F1; Tue, 10 Jan 2017 11:41:10 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E641327BFF for ; Tue, 10 Jan 2017 11:41:09 +0000 (UTC) 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 1cQunb-0007Go-IL; Tue, 10 Jan 2017 11:41:07 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cQumz-0005pf-7Q for linux-arm-kernel@lists.infradead.org; Tue, 10 Jan 2017 11:40:35 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D22AF15BF; Tue, 10 Jan 2017 03:40:13 -0800 (PST) Received: from localhost (e105922-lin.cambridge.arm.com [10.1.195.25]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A477D3F3D6; Tue, 10 Jan 2017 03:40:13 -0800 (PST) From: Punit Agrawal To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 7/9] kvm: host_pmu: Add support for tracking guest TLB operations Date: Tue, 10 Jan 2017 11:38:54 +0000 Message-Id: <20170110113856.7183-8-punit.agrawal@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170110113856.7183-1-punit.agrawal@arm.com> References: <20170110113856.7183-1-punit.agrawal@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170110_034029_430502_07BD5C52 X-CRM114-Status: UNSURE ( 9.05 ) X-CRM114-Notice: Please train this message. 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: kvm@vger.kernel.org, Marc Zyngier , Punit Agrawal , Will Deacon , linux-kernel@vger.kernel.org, Steven Rostedt , Peter Zijlstra , Christoffer Dall 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 Add the callbacks required by host PMU to support monitoring guest TLB operations. Signed-off-by: Punit Agrawal Cc: Christoffer Dall Cc: Marc Zyngier --- virt/kvm/arm/host_pmu.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/virt/kvm/arm/host_pmu.c b/virt/kvm/arm/host_pmu.c index fc610ccc169a..22c3aef17ec4 100644 --- a/virt/kvm/arm/host_pmu.c +++ b/virt/kvm/arm/host_pmu.c @@ -13,6 +13,7 @@ #include enum host_pmu_events { + tlb_invalidate, KVM_HOST_MAX_EVENTS, }; @@ -40,10 +41,59 @@ struct event_data { struct list_head event_list; }; +static u64 get_tlb_invalidate_count(struct kvm *kvm) +{ + struct kvm_vcpu *vcpu; + u64 val = 0; + int i; + + kvm_for_each_vcpu(i, vcpu, kvm) + val += vcpu->stat.tlb_invalidate; + + return val; +} + +static void configure_tlb_invalidate(struct kvm *kvm, bool enable) +{ + struct kvm_vcpu *vcpu; + int i; + + kvm_arm_halt_guest(kvm); + kvm_for_each_vcpu(i, vcpu, kvm) { + unsigned long hcr = vcpu_get_hcr(vcpu); + + if (enable) + hcr |= HCR_TTLB; + else + hcr &= ~HCR_TTLB; + + vcpu_set_hcr(vcpu, hcr); + } + kvm_arm_resume_guest(kvm); +} + static struct kvm_event_cb event_callbacks[] = { + { + .event = tlb_invalidate, + .get_event_count = get_tlb_invalidate_count, + .configure_event = configure_tlb_invalidate, + } }; +static ssize_t events_sysfs_show(struct device *dev, + struct device_attribute *attr, char *page) +{ + struct perf_pmu_events_attr *pmu_attr; + + pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr); + + return sprintf(page, "event=0x%03llx,vm=?\n", pmu_attr->id); +} +PMU_EVENT_ATTR(tlb_invalidate, event_attr_tlb_invalidate, tlb_invalidate, + events_sysfs_show); + static struct attribute *event_attrs[] = { + &event_attr_tlb_invalidate.attr.attr, NULL, };