From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751625AbdAaRSq (ORCPT ); Tue, 31 Jan 2017 12:18:46 -0500 Received: from foss.arm.com ([217.140.101.70]:42854 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751272AbdAaRSY (ORCPT ); Tue, 31 Jan 2017 12:18:24 -0500 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 , Peter Zijlstra , Will Deacon , Mark Rutland 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> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(); +} -- 2.11.0