From patchwork Tue Jan 31 17:16:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Punit Agrawal X-Patchwork-Id: 9547849 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 C30716016C for ; Tue, 31 Jan 2017 17:20:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B50EA28406 for ; Tue, 31 Jan 2017 17:20:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA23C2840B; Tue, 31 Jan 2017 17:20:38 +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 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 2F54128406 for ; Tue, 31 Jan 2017 17:20:38 +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 1cYc6a-0006Kt-R9; Tue, 31 Jan 2017 17:20:32 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cYc45-0002is-RR for linux-arm-kernel@lists.infradead.org; Tue, 31 Jan 2017 17:18:01 +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 A98E7164F; Tue, 31 Jan 2017 09:17:41 -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 7B4FD3F24D; Tue, 31 Jan 2017 09:17:41 -0800 (PST) From: Punit Agrawal To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 6/9] KVM: arm/arm64: Add support for tracking guest TLB operations Date: Tue, 31 Jan 2017 17:16:27 +0000 Message-Id: <20170131171630.26898-7-punit.agrawal@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170131171630.26898-1-punit.agrawal@arm.com> References: <20170131171630.26898-1-punit.agrawal@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170131_091758_039858_2A5CDB2F X-CRM114-Status: GOOD ( 11.88 ) 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: Mark Rutland , kvm@vger.kernel.org, Marc Zyngier , Punit Agrawal , Will Deacon , linux-kernel@vger.kernel.org, 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 The host pmu supports monitoring of VM operations. Register a host pmu and provide the necessary callbacks to enable monitoring TLB operations. Signed-off-by: Punit Agrawal Cc: Christoffer Dall Cc: Marc Zyngier --- virt/kvm/arm/host_pmu_events.c | 82 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 virt/kvm/arm/host_pmu_events.c diff --git a/virt/kvm/arm/host_pmu_events.c b/virt/kvm/arm/host_pmu_events.c new file mode 100644 index 000000000000..a5f097a6fb21 --- /dev/null +++ b/virt/kvm/arm/host_pmu_events.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2017 ARM Ltd. + * Author: Punit Agrawal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include +#include +#include +#include +#include + +#include + +enum host_pmu_events { + tlb_invalidate, + MAX_EVENTS, +}; + +static u64 get_tlb_invalidate_count(struct kvm_vcpu *vcpu) +{ + return vcpu->stat.tlb_invalidate; +} + +static void configure_tlb_invalidate(struct kvm_vcpu *vcpu, bool enable) +{ + unsigned long hcr; + + hcr = vcpu_get_hcr(vcpu); + + if (enable) + hcr |= HCR_TTLB; + else + hcr &= ~HCR_TTLB; + + vcpu_set_hcr(vcpu, hcr); +} + +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\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, +}; + +static struct kvm_event_cb event_callbacks[] = { + { + .get_event_count = get_tlb_invalidate_count, + .configure_event = configure_tlb_invalidate, + }, +}; + +int arm_host_pmu_init(void) +{ + return kvm_host_pmu_register(MAX_EVENTS, event_callbacks, event_attrs); +} + +void arm_host_pmu_teardown(void) +{ + kvm_host_pmu_unregister(); +}