linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
To: mingo@redhat.com, ak@linux.intel.com,
	Michael Ellerman <mpe@ellerman.id.au>,
	Jiri Olsa <jolsa@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: namhyung@kernel.org, maddy@linux.vnet.ibm.com,
	linuxppc-dev@lists.ozlabs.org, <linux-kernel@vger.kernel.org>
Subject: [PATCH v17 03/19] perf, tools: Use pmu_events table to create aliases
Date: Mon, 28 Sep 2015 17:50:41 -0700	[thread overview]
Message-ID: <1443487857-26281-4-git-send-email-sukadev@linux.vnet.ibm.com> (raw)
In-Reply-To: <1443487857-26281-1-git-send-email-sukadev@linux.vnet.ibm.com>

At run time (when 'perf' is starting up), locate the specific table
of PMU events that corresponds to the current CPU. Using that table,
create aliases for the each of the PMU events in the CPU. The use
these aliases to parse the user specified perf event.

In short this would allow the user to specify events using their
aliases rather than raw event codes.

Based on input and some earlier patches from Andi Kleen, Jiri Olsa.

Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
---

Changelog[v4]
	- Split off unrelated code into separate patches.
Changelog[v3]
	- [Jiri Olsa] Fix memory leak in cpuid
Changelog[v2]
	- [Andi Kleen] Replace pmu_events_map->vfm with a generic "cpuid".
---
 tools/perf/util/header.h |  1 +
 tools/perf/util/pmu.c    | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 05f27cb..d02b2f9 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -133,4 +133,5 @@ int write_padded(int fd, const void *bf, size_t count, size_t count_aligned);
  */
 int get_cpuid(char *buffer, size_t sz);
 
+char *get_cpuid_str(void);
 #endif /* __PERF_HEADER_H */
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 89c91a1..b8f7627 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -12,6 +12,8 @@
 #include "pmu.h"
 #include "parse-events.h"
 #include "cpumap.h"
+#include "header.h"
+#include "pmu-events/pmu-events.h"
 
 struct perf_pmu_format {
 	char *name;
@@ -449,6 +451,62 @@ static struct cpu_map *pmu_cpumask(const char *name)
 	return cpus;
 }
 
+/*
+ * Return the CPU id as a raw string.
+ *
+ * Each architecture should provide a more precise id string that
+ * can be use to match the architecture's "mapfile".
+ */
+char * __weak get_cpuid_str(void)
+{
+	return NULL;
+}
+
+/*
+ * From the pmu_events_map, find the table of PMU events that corresponds
+ * to the current running CPU. Then, add all PMU events from that table
+ * as aliases.
+ */
+static int pmu_add_cpu_aliases(struct list_head *head)
+{
+	int i;
+	struct pmu_events_map *map;
+	struct pmu_event *pe;
+	char *cpuid;
+
+	cpuid = get_cpuid_str();
+	if (!cpuid)
+		return 0;
+
+	i = 0;
+	while (1) {
+		map = &pmu_events_map[i++];
+		if (!map->table)
+			goto out;
+
+		if (!strcmp(map->cpuid, cpuid))
+			break;
+	}
+
+	/*
+	 * Found a matching PMU events table. Create aliases
+	 */
+	i = 0;
+	while (1) {
+		pe = &map->table[i++];
+		if (!pe->name)
+			break;
+
+		/* need type casts to override 'const' */
+		__perf_pmu__new_alias(head, NULL, (char *)pe->name,
+				(char *)pe->desc, (char *)pe->event);
+	}
+
+out:
+	free(cpuid);
+	return 0;
+}
+
 struct perf_event_attr * __weak
 perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused)
 {
@@ -473,6 +531,9 @@ static struct perf_pmu *pmu_lookup(const char *name)
 	if (pmu_aliases(name, &aliases))
 		return NULL;
 
+	if (!strcmp(name, "cpu"))
+		(void)pmu_add_cpu_aliases(&aliases);
+
 	if (pmu_type(name, &type))
 		return NULL;
 
-- 
2.5.3

  parent reply	other threads:[~2015-09-29  0:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29  0:50 [PATCH v17 00/19] perf, tools: Add support for PMU events in JSON format Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 01/19] perf, tools: Add jsmn `jasmine' JSON parser Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 02/19] perf, tools, jevents: Program to convert JSON file to C style file Sukadev Bhattiprolu
2015-09-29  0:50 ` Sukadev Bhattiprolu [this message]
2015-09-29  0:50 ` [PATCH v17 04/19] perf, tools: Support CPU ID matching for Powerpc Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 05/19] perf, tools: Support CPU id matching for x86 v2 Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 06/19] perf, tools: Support alias descriptions Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 07/19] perf, tools: Query terminal width and use in perf list Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 08/19] perf, tools: Add a --no-desc flag to " Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 09/19] perf, tools: Add override support for event list CPUID Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 10/19] perf, tools, jevents: Add support for long descriptions Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 11/19] perf, tools: Add alias " Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 12/19] perf, tools: Support long descriptions with perf list Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 13/19] perf, tools, jevents: Add support for event topics Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 14/19] perf, tools: Add support for event list topics Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 15/19] perf, tools: Handle header line in mapfile Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 16/19] perf, tools: Add README for info on parsing JSON/map files Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 17/19] perf, tools: Make alias matching case-insensitive Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 18/19] perf, tools, pmu-events: Fix fixed counters on Intel Sukadev Bhattiprolu
2015-09-29  0:50 ` [PATCH v17 19/19] perf, tools, pmu-events: Add Skylake frontend MSR support Sukadev Bhattiprolu

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=1443487857-26281-4-git-send-email-sukadev@linux.vnet.ibm.com \
    --to=sukadev@linux.vnet.ibm.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.vnet.ibm.com \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=namhyung@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).