aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorSukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>2016-09-15 18:24:40 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-10-03 18:58:00 -0400
commit933f82ff72d7d1641663462f61f3056ee1fe3f8b (patch)
tree73643abccf0465e85bae985e7b2bcdb63b8454aa /tools/perf
parent80eeb67fe577aa76b2d1bb5b029bca097f0f25bc (diff)
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>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/header.h1
-rw-r--r--tools/perf/util/pmu.c60
2 files changed, 61 insertions, 0 deletions
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index d306ca118449..d30109b421ee 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);
151 */ 151 */
152int get_cpuid(char *buffer, size_t sz); 152int get_cpuid(char *buffer, size_t sz);
153 153
154char *get_cpuid_str(void);
154#endif /* __PERF_HEADER_H */ 155#endif /* __PERF_HEADER_H */
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 2babcdf62839..10668b7f5272 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -12,6 +12,8 @@
12#include "pmu.h" 12#include "pmu.h"
13#include "parse-events.h" 13#include "parse-events.h"
14#include "cpumap.h" 14#include "cpumap.h"
15#include "header.h"
16#include "pmu-events/pmu-events.h"
15 17
16struct perf_pmu_format { 18struct perf_pmu_format {
17 char *name; 19 char *name;
@@ -473,6 +475,61 @@ static struct cpu_map *pmu_cpumask(const char *name)
473 return cpus; 475 return cpus;
474} 476}
475 477
478/*
479 * Return the CPU id as a raw string.
480 *
481 * Each architecture should provide a more precise id string that
482 * can be use to match the architecture's "mapfile".
483 */
484char * __weak get_cpuid_str(void)
485{
486 return NULL;
487}
488
489/*
490 * From the pmu_events_map, find the table of PMU events that corresponds
491 * to the current running CPU. Then, add all PMU events from that table
492 * as aliases.
493 */
494static void pmu_add_cpu_aliases(struct list_head *head)
495{
496 int i;
497 struct pmu_events_map *map;
498 struct pmu_event *pe;
499 char *cpuid;
500
501 cpuid = get_cpuid_str();
502 if (!cpuid)
503 return;
504
505 i = 0;
506 while (1) {
507 map = &pmu_events_map[i++];
508 if (!map->table)
509 goto out;
510
511 if (!strcmp(map->cpuid, cpuid))
512 break;
513 }
514
515 /*
516 * Found a matching PMU events table. Create aliases
517 */
518 i = 0;
519 while (1) {
520 pe = &map->table[i++];
521 if (!pe->name)
522 break;
523
524 /* need type casts to override 'const' */
525 __perf_pmu__new_alias(head, NULL, (char *)pe->name,
526 (char *)pe->desc, (char *)pe->event);
527 }
528
529out:
530 free(cpuid);
531}
532
476struct perf_event_attr * __weak 533struct perf_event_attr * __weak
477perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused) 534perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused)
478{ 535{
@@ -497,6 +554,9 @@ static struct perf_pmu *pmu_lookup(const char *name)
497 if (pmu_aliases(name, &aliases)) 554 if (pmu_aliases(name, &aliases))
498 return NULL; 555 return NULL;
499 556
557 if (!strcmp(name, "cpu"))
558 pmu_add_cpu_aliases(&aliases);
559
500 if (pmu_type(name, &type)) 560 if (pmu_type(name, &type))
501 return NULL; 561 return NULL;
502 562