linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Sukadev Bhattiprolu <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: maddy@linux.vnet.ibm.com, peterz@infradead.org, mingo@kernel.org,
	hpa@zytor.com, acme@redhat.com, linux-kernel@vger.kernel.org,
	sukadev@linux.vnet.ibm.com, jolsa@redhat.com, tglx@linutronix.de
Subject: [tip:perf/urgent] perf pmu: Use pmu_events table to create aliases
Date: Tue, 4 Oct 2016 01:12:33 -0700	[thread overview]
Message-ID: <tip-933f82ff72d7d1641663462f61f3056ee1fe3f8b@git.kernel.org> (raw)
In-Reply-To: <1473978296-20712-4-git-send-email-sukadev@linux.vnet.ibm.com>

Commit-ID:  933f82ff72d7d1641663462f61f3056ee1fe3f8b
Gitweb:     http://git.kernel.org/tip/933f82ff72d7d1641663462f61f3056ee1fe3f8b
Author:     Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
AuthorDate: Thu, 15 Sep 2016 15:24:40 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 3 Oct 2016 19:58:00 -0300

perf pmu: Use pmu_events table to create aliases

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: Ingo Molnar <mingo@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lkml.kernel.org/r/1473978296-20712-4-git-send-email-sukadev@linux.vnet.ibm.com
[ Make pmu_add_cpu_aliases() return void, since it was returning just '0' and
  furthermore, even that was being discarded via an explicit (void) cast ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/header.h |  1 +
 tools/perf/util/pmu.c    | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index d306ca1..d30109b 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -151,4 +151,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 2babcdf..10668b7 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;
@@ -473,6 +475,61 @@ 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 void 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;
+
+	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);
+}
+
 struct perf_event_attr * __weak
 perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused)
 {
@@ -497,6 +554,9 @@ static struct perf_pmu *pmu_lookup(const char *name)
 	if (pmu_aliases(name, &aliases))
 		return NULL;
 
+	if (!strcmp(name, "cpu"))
+		pmu_add_cpu_aliases(&aliases);
+
 	if (pmu_type(name, &type))
 		return NULL;
 

  parent reply	other threads:[~2016-10-04  8:13 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-15 22:24 [PATCH v21 00/20] perf, tools: Add support for PMU events in JSON format Sukadev Bhattiprolu
2016-09-15 22:24 ` [PATCH v21 01/19] perf, tools: Add jsmn `jasmine' JSON parser Sukadev Bhattiprolu
2016-10-04  8:11   ` [tip:perf/urgent] perf " tip-bot for Andi Kleen
2016-09-15 22:24 ` [PATCH v21 02/19] perf, tools, jevents: Program to convert JSON file to C style file Sukadev Bhattiprolu
2016-09-15 22:24 ` [PATCH v21 03/19] perf, tools: Use pmu_events table to create aliases Sukadev Bhattiprolu
2016-09-27 13:16   ` Arnaldo Carvalho de Melo
2016-10-04  8:12   ` tip-bot for Sukadev Bhattiprolu [this message]
2016-09-15 22:24 ` [PATCH v21 04/19] perf, tools: Support CPU ID matching for Powerpc Sukadev Bhattiprolu
2016-10-04  8:13   ` [tip:perf/urgent] perf powerpc: " tip-bot for Sukadev Bhattiprolu
2016-09-15 22:24 ` [PATCH v21 05/19] perf, tools: Support CPU id matching for x86 v2 Sukadev Bhattiprolu
2016-10-04  8:13   ` [tip:perf/urgent] perf " tip-bot for Andi Kleen
2016-09-15 22:24 ` [PATCH v21 06/19] perf, tools: Support alias descriptions Sukadev Bhattiprolu
2016-09-27 17:41   ` Arnaldo Carvalho de Melo
2016-09-27 18:11     ` Sukadev Bhattiprolu
2016-09-28 13:57       ` Arnaldo Carvalho de Melo
2016-09-28 18:29         ` Sukadev Bhattiprolu
2016-09-28 19:08           ` Arnaldo Carvalho de Melo
2016-10-03 20:52           ` Arnaldo Carvalho de Melo
2016-10-04  8:14   ` [tip:perf/urgent] perf pmu: " tip-bot for Andi Kleen
2016-09-15 22:24 ` [PATCH v21 07/19] perf, tools: Query terminal width and use in perf list Sukadev Bhattiprolu
2016-10-04  8:14   ` [tip:perf/urgent] perf " tip-bot for Andi Kleen
2016-09-15 22:24 ` [PATCH v21 08/19] perf, tools: Add a --no-desc flag to " Sukadev Bhattiprolu
2016-10-04  8:15   ` [tip:perf/urgent] perf list: Add a --no-desc flag tip-bot for Andi Kleen
2016-09-15 22:24 ` [PATCH v21 09/19] perf, tools: Add override support for event list CPUID Sukadev Bhattiprolu
2016-10-04  8:15   ` [tip:perf/urgent] perf pmu: " tip-bot for Andi Kleen
2016-09-15 22:24 ` [PATCH v21 10/19] perf, tools, jevents: Add support for long descriptions Sukadev Bhattiprolu
2016-10-04  8:16   ` [tip:perf/urgent] perf " tip-bot for Sukadev Bhattiprolu
2016-09-15 22:24 ` [PATCH v21 11/19] perf, tools: Add alias " Sukadev Bhattiprolu
2016-10-04  0:20   ` Arnaldo Carvalho de Melo
2016-09-15 22:24 ` [PATCH v21 12/19] perf, tools: Support long descriptions with perf list Sukadev Bhattiprolu
2016-10-04  0:26   ` Arnaldo Carvalho de Melo
2016-10-04  8:16   ` [tip:perf/urgent] perf list: Support long jevents descriptions tip-bot for Sukadev Bhattiprolu
2016-09-15 22:24 ` [PATCH v21 13/19] perf, tools: Add support for event list topics Sukadev Bhattiprolu
2016-10-04  8:16   ` [tip:perf/urgent] perf list jevents: " tip-bot for Andi Kleen
2016-09-15 22:24 ` [PATCH v21 14/19] perf, tools, jevents: Handle header line in mapfile Sukadev Bhattiprolu
2016-10-04  0:36   ` Arnaldo Carvalho de Melo
2016-10-04  8:13   ` [tip:perf/urgent] perf " tip-bot for Andi Kleen
2016-09-15 22:24 ` [PATCH v21 15/19] perf, tools: Add README for info on parsing JSON/map files Sukadev Bhattiprolu
2016-10-04  0:38   ` Arnaldo Carvalho de Melo
2016-10-04  8:17   ` [tip:perf/urgent] perf " tip-bot for Sukadev Bhattiprolu
2016-09-15 22:24 ` [PATCH v21 16/19] perf, tools: Make alias matching case-insensitive Sukadev Bhattiprolu
2016-10-04  0:47   ` Arnaldo Carvalho de Melo
2016-10-04  0:54     ` Arnaldo Carvalho de Melo
2016-10-04  8:19       ` Jiri Olsa
2016-10-04  8:19     ` Jiri Olsa
2016-10-04  8:18   ` [tip:perf/urgent] perf " tip-bot for Andi Kleen
2016-09-15 22:24 ` [PATCH v21 17/19] perf, tools, pmu-events: Fix fixed counters on Intel Sukadev Bhattiprolu
2016-10-04  8:18   ` [tip:perf/urgent] perf " tip-bot for Andi Kleen
2016-09-15 22:24 ` [PATCH v21 18/19] perf, tools, pmu-events: Add Skylake frontend MSR support Sukadev Bhattiprolu
2016-10-04  8:19   ` [tip:perf/urgent] perf " tip-bot for Andi Kleen
2016-09-15 22:24 ` [PATCH v21 19/19] perf, tools: Allow period= in perf stat CPU event descriptions Sukadev Bhattiprolu
2016-10-04  8:17   ` [tip:perf/urgent] perf " tip-bot for Sukadev Bhattiprolu
2016-09-19 16:58 ` [PATCH v21 00/20] perf, tools: Add support for PMU events in JSON format Sukadev Bhattiprolu
2016-09-19 21:20 ` Arnaldo Carvalho de Melo
2016-09-19 23:31   ` Arnaldo Carvalho de Melo
2016-09-19 23:37     ` Arnaldo Carvalho de Melo
2016-09-20  0:02       ` Arnaldo Carvalho de Melo
2016-09-20  0:28         ` Arnaldo Carvalho de Melo
2016-09-22 14:56           ` Arnaldo Carvalho de Melo
2016-09-22 15:00           ` Jiri Olsa
2016-09-22 16:27             ` Jiri Olsa
2016-09-26  8:35               ` Jiri Olsa
2016-09-26 15:03                 ` Arnaldo Carvalho de Melo
2016-09-26 16:59                   ` Andi Kleen
2016-09-27 14:18                     ` Jiri Olsa
2016-09-29 22:19                       ` Arnaldo Carvalho de Melo
2016-09-30  9:10                         ` Jiri Olsa
2016-10-04  8:10                       ` [tip:perf/urgent] tools build: Add support for host programs format tip-bot for Jiri Olsa
2016-10-04  8:11                       ` [tip:perf/urgent] tools build: Make fixdep a hostprog tip-bot for Jiri Olsa
2016-10-04  8:12                       ` [tip:perf/urgent] perf jevents: Program to convert JSON file tip-bot for Andi Kleen

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=tip-933f82ff72d7d1641663462f61f3056ee1fe3f8b@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=maddy@linux.vnet.ibm.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sukadev@linux.vnet.ibm.com \
    --cc=tglx@linutronix.de \
    /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).