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 4/7] powerpc/powernv: detect supported nest units and its events
Date: Tue, 23 Feb 2016 09:16:35 +0530	[thread overview]
Message-ID: <1456199198-11056-5-git-send-email-maddy@linux.vnet.ibm.com> (raw)
In-Reply-To: <1456199198-11056-1-git-send-email-maddy@linux.vnet.ibm.com>

Parse device tree to detect nest units. Traverse through
each nest unit folder to find supported events and
corresponding unit/scale files (if any).

The nest unit event file from Device Tree will contain the offset in the
reserved memory region to get the counter data for a given event.
Kernel code uses this offset as event configuration value.

Device tree parser code also looks for scale/unit in the file name and
passes on the file as an event attr for perf tool to use in the post
processing.

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/platforms/powernv/opal-nest.c | 190 ++++++++++++++++++++++++++++-
 1 file changed, 189 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/powernv/opal-nest.c b/arch/powerpc/platforms/powernv/opal-nest.c
index 2ca879fdf159..548a8c0236e4 100644
--- a/arch/powerpc/platforms/powernv/opal-nest.c
+++ b/arch/powerpc/platforms/powernv/opal-nest.c
@@ -31,13 +31,194 @@
 #include <asm/nest-pmu.h>
 
 extern struct perchip_nest_info nest_perchip_info[NEST_MAX_CHIPS];
+extern struct nest_pmu *per_nest_pmu_arr[NEST_MAX_PMUS];
+
+static int nest_event_info(char *name, struct nest_ima_events *nest_events)
+{
+	char *buf;
+
+	/* memory for content */
+	buf = kzalloc(NEST_MAX_PMU_NAME_LEN, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	nest_events->ev_name = name;
+	nest_events->ev_value = buf;
+	return 0;
+}
+
+static int nest_event_info_str(struct property *pp, char *name,
+					struct nest_ima_events *nest_events)
+{
+	if (nest_event_info(name, nest_events))
+		return -ENOMEM;
+
+	if (!pp->value || (strnlen(pp->value, pp->length) == pp->length) ||
+	   (pp->length > NEST_MAX_PMU_NAME_LEN))
+		return -EINVAL;
+
+	strncpy(nest_events->ev_value, (const char *)pp->value, pp->length);
+	return 0;
+}
+
+static int nest_event_info_val(char *name, u32 val,
+					struct nest_ima_events *nest_events)
+{
+	if (nest_event_info(name, nest_events))
+		return -ENOMEM;
+
+	sprintf(nest_events->ev_value, "event=0x%x", val);
+	return 0;
+}
+
+static int nest_events_node_parser(struct device_node *dev,
+					struct nest_ima_events *nest_events)
+{
+	struct property *name, *pp, *id;
+	char *buf, *start, *ev_name;
+	u32 val;
+	int idx = 0, ret;
+
+	if (!dev)
+		return -EINVAL;
+
+	/*
+	* Loop through each property
+	*/
+	name = of_find_property(dev, "name", NULL);
+	if (!name) {
+		printk(KERN_INFO "No property by name\n");
+		return -1;
+	}
+
+	if (!name->value ||
+	  (strnlen(name->value, name->length) == name->length) ||
+	  (name->length > NEST_MAX_PMU_NAME_LEN))
+		return -EINVAL;
+
+	ev_name = kzalloc(NEST_MAX_PMU_NAME_LEN, GFP_KERNEL);
+	if (!ev_name)
+		return -ENOMEM;
+
+	/* Now that we got the event name, look for id */
+	id = of_find_property(dev, "id", NULL);
+	if (!id) {
+		strncpy(ev_name, name->value, (int)strlen(name->value));
+		printk(KERN_INFO "No property by id = %s\n", ev_name);
+	} else {
+		if (!id->value ||
+		  (strnlen(id->value, id->length) == id->length) ||
+		  (id->length > NEST_MAX_PMU_NAME_LEN))
+			return -EINVAL;
+
+		of_property_read_u32(dev, id->name, &val);
+		sprintf(ev_name, "%s_%x", (char *)name->value, val);
+	}
+
+	for_each_property_of_node(dev, pp) {
+		start = pp->name;
+
+		/* Skip these, we don't need it */
+		if (!strcmp(pp->name, "phandle") ||
+		   !strcmp(pp->name, "linux,phandle") ||
+		   !strcmp(pp->name, "name"))
+			continue;
+
+		if (strncmp(pp->name, "reg", 3) == 0) {
+			of_property_read_u32(dev, pp->name, &val);
+			ret = nest_event_info_val(ev_name, val, &nest_events[idx]);
+			idx++;
+		} else if (strncmp(pp->name, "unit", 4) == 0) {
+			buf = kzalloc(NEST_MAX_PMU_NAME_LEN, GFP_KERNEL);
+			if (!buf)
+				return -ENOMEM;
+			sprintf(buf,"%s.unit", ev_name);
+			ret = nest_event_info_str(pp, buf, &nest_events[idx]);
+			idx++;
+		} else if (strncmp(pp->name, "scale", 5) == 0) {
+			buf = kzalloc(NEST_MAX_PMU_NAME_LEN, GFP_KERNEL);
+			if (!buf)
+				return -ENOMEM;
+			sprintf(buf,"%s.scale", ev_name);
+			ret = nest_event_info_str(pp, buf, &nest_events[idx]);
+			idx++;
+		}
+
+		if (ret)
+			return ret;
+	}
+
+	return idx;
+}
+
+static int nest_pmu_create(struct device_node *parent, int pmu_index)
+{
+	struct device_node *ev_node;
+	struct nest_ima_events *nest_events;
+	struct nest_pmu *pmu_ptr;
+	struct property *pp;
+	char *buf;
+	int idx = 0, ret;
+
+	if (!parent)
+		return -EINVAL;
+
+	/* memory for nest pmus */
+	pmu_ptr = kzalloc(sizeof(struct nest_pmu), GFP_KERNEL);
+	if (!pmu_ptr)
+		return -ENOMEM;
+
+	/* Needed for hotplug/migration */
+	per_nest_pmu_arr[pmu_index] = pmu_ptr;
+
+	/* memory for nest pmu events */
+	nest_events = kzalloc((sizeof(struct nest_ima_events) *
+					NEST_MAX_EVENTS_SUPPORTED), GFP_KERNEL);
+	if (!nest_events)
+		return -ENOMEM;
+
+	pp = of_find_property(parent, "name", NULL);
+	if (!pp) {
+		printk(KERN_INFO "No property by name\n");
+		return -1;
+	}
+
+	if (!pp->value ||
+	  (strnlen(pp->value, pp->length) == pp->length) ||
+	  (pp->length > NEST_MAX_PMU_NAME_LEN))
+		return -EINVAL;
+
+	buf = kzalloc(NEST_MAX_PMU_NAME_LEN, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	/* Save the name to register it later */
+	sprintf(buf, "nest_%s", (char *)pp->value);
+	pmu_ptr->pmu.name = (char *)buf;
+
+	/* Loop through event nodes */
+	for_each_child_of_node(parent, ev_node) {
+		ret = nest_events_node_parser(ev_node, &nest_events[idx]);
+		if (ret < 0)
+			return -1;
+
+		/*
+		 * nest_event_node_parser will return number of
+		 * event entried created for this. This could include
+		 * event scale and unit files also.
+		 */
+		idx += ret;
+	}
+
+	return 0;
+}
 
 static int opal_nest_counters_probe(struct platform_device *pdev)
 {
 	struct device_node *child, *parent;
 	struct perchip_nest_info *pcni;
 	u32 idx, range[4], pages;
-	int rc=0, i=0;
+	int rc=0, i=0, pmu_count=0;
 
 	if (!pdev || !pdev->dev.of_node)
 		return -ENODEV;
@@ -75,6 +256,13 @@ static int opal_nest_counters_probe(struct platform_device *pdev)
 		} while( i < (pcni->size/PAGE_SIZE));
 	}
 
+	parent = of_get_next_child(pdev->dev.of_node, NULL);
+	for_each_child_of_node(parent, child) {
+		rc = nest_pmu_create(child, pmu_count++);
+		if (rc)
+			return rc;
+	}
+
 	return rc;
 }
 
-- 
1.9.1

  parent reply	other threads:[~2016-02-23  3:57 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 ` Madhavan Srinivasan [this message]
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 ` [PATCH v8 6/7] powerpc/perf: generic nest pmu event functions Madhavan Srinivasan
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-5-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

all inboxes | Powered by JetHome®