mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Anton Blanchard <anton@samba.org>, Daniel Axtens <dja@axtens.net>,
	Stephane Eranian <eranian@google.com>,
	Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Subject: [PATCH v8 6/7] powerpc/perf: generic nest pmu event functions
Date: Tue, 23 Feb 2016 09:16:37 +0530	[thread overview]
Message-ID: <1456199198-11056-7-git-send-email-maddy@linux.vnet.ibm.com> (raw)
In-Reply-To: <1456199198-11056-1-git-send-email-maddy@linux.vnet.ibm.com>

Add set of generic nest pmu related event functions to be used by
each nest pmu. Add code to setup format attribute and to register
nest pmus.

Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Anton Blanchard <anton@samba.org>
Cc: Daniel Axtens <dja@axtens.net>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
---
 arch/powerpc/perf/nest-pmu.c | 114 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 114 insertions(+)

diff --git a/arch/powerpc/perf/nest-pmu.c b/arch/powerpc/perf/nest-pmu.c
index b9b44147c9b8..772e4d2d7a04 100644
--- a/arch/powerpc/perf/nest-pmu.c
+++ b/arch/powerpc/perf/nest-pmu.c
@@ -13,6 +13,111 @@
 struct perchip_nest_info nest_perchip_info[NEST_MAX_CHIPS];
 struct nest_pmu *per_nest_pmu_arr[NEST_MAX_PMUS];
 
+PMU_FORMAT_ATTR(event, "config:0-20");
+static struct attribute *nest_format_attrs[] = {
+	&format_attr_event.attr,
+	NULL,
+};
+
+static struct attribute_group nest_format_group = {
+	.name = "format",
+	.attrs = nest_format_attrs,
+};
+
+static int nest_event_init(struct perf_event *event)
+{
+	int chip_id;
+	u32 config = event->attr.config;
+	struct perchip_nest_info *pcni;
+
+	if (event->attr.type != event->pmu->type)
+		return -ENOENT;
+
+	/* Sampling not supported yet */
+	if (event->hw.sample_period)
+		return -EINVAL;
+
+	/* unsupported modes and filters */
+	if (event->attr.exclude_user   ||
+	  event->attr.exclude_kernel ||
+	  event->attr.exclude_hv     ||
+	  event->attr.exclude_idle   ||
+	  event->attr.exclude_host   ||
+	  event->attr.exclude_guest)
+		return -EINVAL;
+
+	if (event->cpu < 0)
+		return -EINVAL;
+
+	chip_id = topology_physical_package_id(event->cpu);
+	pcni = &nest_perchip_info[chip_id];
+	event->hw.event_base = pcni->vbase[config/PAGE_SIZE] +
+							(config & ~PAGE_MASK );
+
+	return 0;
+}
+
+static void nest_read_counter(struct perf_event *event)
+{
+	u64 *addr, data;
+
+	addr = (u64 *)event->hw.event_base;
+	data = __be64_to_cpu(*addr);
+	local64_set(&event->hw.prev_count, data);
+}
+
+static void nest_perf_event_update(struct perf_event *event)
+{
+	u64 counter_prev, counter_new, final_count, *addr;
+
+	addr = (u64 *)event->hw.event_base;
+	counter_prev = local64_read(&event->hw.prev_count);
+	counter_new = __be64_to_cpu(*addr);
+	final_count = counter_new - counter_prev;
+
+	local64_set(&event->hw.prev_count, counter_new);
+	local64_add(final_count, &event->count);
+}
+
+static void nest_event_start(struct perf_event *event, int flags)
+{
+	nest_read_counter(event);
+}
+
+static void nest_event_stop(struct perf_event *event, int flags)
+{
+	if (flags & PERF_EF_UPDATE)
+		nest_perf_event_update(event);
+}
+
+static int nest_event_add(struct perf_event *event, int flags)
+{
+       if (flags & PERF_EF_START)
+               nest_event_start(event, flags);
+
+       return 0;
+}
+
+/*
+ * Populate pmu ops in the structure
+ */
+static int update_pmu_ops(struct nest_pmu *pmu)
+{
+	if (!pmu)
+		return -EINVAL;
+
+	pmu->pmu.task_ctx_nr = perf_invalid_context;
+	pmu->pmu.event_init = nest_event_init;
+	pmu->pmu.add = nest_event_add;
+	pmu->pmu.del = nest_event_stop;
+	pmu->pmu.start = nest_event_start;
+	pmu->pmu.stop = nest_event_stop;
+	pmu->pmu.read = nest_perf_event_update;
+	pmu->attr_groups[1] = &nest_format_group;
+	pmu->pmu.attr_groups = pmu->attr_groups;
+
+	return 0;
+}
 /*
  * Populate event name and string in attribute
  */
@@ -62,8 +167,17 @@ static int update_events_in_group(
 int init_nest_pmu(struct nest_ima_events *nest_events,
 					int idx, struct nest_pmu *pmu_ptr)
 {
+	int ret = -ENODEV;
 
 	update_events_in_group(nest_events, idx, pmu_ptr);
+	update_pmu_ops(pmu_ptr);
+
+	ret = perf_pmu_register(&pmu_ptr->pmu, pmu_ptr->pmu.name, -1);
+	if (ret)
+		return ret;
+
+	pr_info("%s performance monitor hardware support registered\n",
+							pmu_ptr->pmu.name);
 	return 0;
 }
 
-- 
1.9.1

  parent reply	other threads:[~2016-02-23  3:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-23  3:46 [PATCH v8 0/7] powerpc/powernv: Nest Instrumentation support Madhavan Srinivasan
2016-02-23  3:46 ` [PATCH v8 1/7] powerpc/powernv: Data structure and macros definition Madhavan Srinivasan
2016-02-23  3:46 ` [PATCH v8 2/7] powerpc/powernv: Add OPAL support for Nest PMU Madhavan Srinivasan
2016-02-23  3:46 ` [PATCH v8 3/7] powerpc/powernv: autoload nest unit driver module Madhavan Srinivasan
2016-02-23  3:46 ` [PATCH v8 4/7] powerpc/powernv: detect supported nest units and its events Madhavan Srinivasan
2016-02-23  3:46 ` [PATCH v8 5/7] powerpc/perf: Add event attribute and group to nest pmu Madhavan Srinivasan
2016-02-23  3:46 ` Madhavan Srinivasan [this message]
2016-02-23  3:46 ` [PATCH v8 7/7] powerpc/perf: nest pmu cpumask and cpu hotplug support Madhavan Srinivasan
2016-02-29 20:13   ` kbuild test robot

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=1456199198-11056-7-git-send-email-maddy@linux.vnet.ibm.com \
    --to=maddy@linux.vnet.ibm.com \
    --cc=anton@samba.org \
    --cc=benh@kernel.crashing.org \
    --cc=dja@axtens.net \
    --cc=eranian@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=sukadev@linux.vnet.ibm.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