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: 9547813 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 1A7B16016C for ; Tue, 31 Jan 2017 17:18:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AB03283E1 for ; Tue, 31 Jan 2017 17:18:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F307A28408; Tue, 31 Jan 2017 17:18:33 +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 9633A283E1 for ; Tue, 31 Jan 2017 17:18:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751486AbdAaRSc (ORCPT ); Tue, 31 Jan 2017 12:18:32 -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 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 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: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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(); +}