mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Punit Agrawal <punit.agrawal@arm.com>
To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org
Cc: Punit Agrawal <punit.agrawal@arm.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	Christoffer Dall <christoffer.dall@linaro.org>,
	Marc Zyngier <marc.zyngier@arm.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Will Deacon <will.deacon@arm.com>,
	Mark Rutland <mark.rutland@arm.com>
Subject: [PATCH v4 6/9] KVM: arm/arm64: Add support for tracking guest TLB operations
Date: Tue, 31 Jan 2017 17:16:27 +0000	[thread overview]
Message-ID: <20170131171630.26898-7-punit.agrawal@arm.com> (raw)
In-Reply-To: <20170131171630.26898-1-punit.agrawal@arm.com>

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 <punit.agrawal@arm.com>
Cc: Christoffer Dall <christoffer.dall@linaro.org>
Cc: Marc Zyngier <marc.zyngier@arm.com>
---
 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 <punit.agrawal@arm.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+#include <kvm/host_pmu.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/kvm_host.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>
+
+#include <asm/kvm_emulate.h>
+
+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

  parent reply	other threads:[~2017-01-31 17:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-31 17:16 [PATCH v4 0/9] Add support for monitoring " Punit Agrawal
2017-01-31 17:16 ` [PATCH v4 1/9] arm64/kvm: hyp: tlb: use __tlbi() helper Punit Agrawal
2017-01-31 17:16 ` [PATCH v4 2/9] KVM: Add event to trace tlb invalidations Punit Agrawal
2017-01-31 17:16 ` [PATCH v4 3/9] arm: KVM: Handle trappable TLB instructions Punit Agrawal
2017-01-31 17:16 ` [PATCH v4 4/9] arm64: " Punit Agrawal
2017-01-31 17:16 ` [PATCH v4 5/9] kvm: Add host pmu to support VM introspection Punit Agrawal
2017-01-31 17:16 ` Punit Agrawal [this message]
2017-01-31 17:16 ` [PATCH v4 7/9] arm64: KVM: Enable support for the host pmu Punit Agrawal
2017-01-31 17:16 ` [PATCH v4 8/9] arm: KVM: Enable support for " Punit Agrawal
2017-01-31 17:16 ` [PATCH v4 9/9] arm/arm64: KVM: Initialise the " Punit Agrawal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170131171630.26898-7-punit.agrawal@arm.com \
    --to=punit.agrawal@arm.com \
    --cc=christoffer.dall@linaro.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=peterz@infradead.org \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome