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: 9506997 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 5B376601E9 for ; Tue, 10 Jan 2017 11:41:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E5FF27BFF for ; Tue, 10 Jan 2017 11:41:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 426F3284BD; Tue, 10 Jan 2017 11:41:08 +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=-6.9 required=2.0 tests=BAYES_00,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 DE8CA27BFF for ; Tue, 10 Jan 2017 11:41:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762807AbdAJLku (ORCPT ); Tue, 10 Jan 2017 06:40:50 -0500 Received: from foss.arm.com ([217.140.101.70]:49512 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934508AbdAJLkT (ORCPT ); Tue, 10 Jan 2017 06:40:19 -0500 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 Cc: Punit Agrawal , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Christoffer Dall , Marc Zyngier , Steven Rostedt , Peter Zijlstra , Will Deacon 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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, };