diff options
| author | Mark Rutland <mark.rutland@arm.com> | 2017-10-06 14:38:22 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-10-09 14:48:46 -0400 |
| commit | 66ec11919a0f96e936bb731fdbc2851316077d26 (patch) | |
| tree | 65a506ebb5db351c348c4bcfca98077d655d3118 | |
| parent | e9516c0813aeb89ebd19ec0ed39fbfcd78b6ef3a (diff) | |
perf pmu: Unbreak perf record for arm/arm64 with events with explicit PMU
Currently, perf record is broken on arm/arm64 systems when the PMU is
specified explicitly as part of the event, e.g.
$ ./perf record -e armv8_cortex_a53/cpu_cycles/u true
In such cases, perf record fails to open events unless
perf_event_paranoid is set to -1, even if the PMU in question supports
mode exclusion. Further, even when perf_event_paranoid is toggled, no
samples are recorded.
This is an unintended side effect of commit:
e3ba76deef23064f ("perf tools: Force uncore events to system wide monitoring)
... which assumes that if a PMU has an associated cpu_map, it is an
uncore PMU, and forces events for such PMUs to be system-wide.
This is not true for arm/arm64 systems, which can have heterogeneous
CPUs. To account for this, multiple CPU PMUs are exposed, each with a
"cpus" field under sysfs, which the perf tool parses into a cpu_map. ARM
PMUs do not have a "cpumask" file, and only have a "cpus" file. For the
gory details as to why, see commit:
7e3fcffe95544010 ("perf pmu: Support alternative sysfs cpumask")
Given all of this, we can instead identify uncore PMUs by explicitly
checking for a "cpumask" file, and restore arm/arm64 PMU support back to
a working state. This patch does so, adding a new perf_pmu::is_uncore
field, and splitting the existing cpumask parsing so that it can be
reused.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Tested-by Will Deacon <will.deacon@arm.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: 4.12+ <stable@vger.kernel.org>
Fixes: e3ba76deef23064f ("perf tools: Force uncore events to system wide monitoring)
Link: http://lkml.kernel.org/r/1507315102-5942-1-git-send-email-mark.rutland@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
| -rw-r--r-- | tools/perf/util/parse-events.c | 9 | ||||
| -rw-r--r-- | tools/perf/util/pmu.c | 56 | ||||
| -rw-r--r-- | tools/perf/util/pmu.h | 1 |
3 files changed, 47 insertions, 19 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index f6257fb4f08c..39b15968eab1 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
| @@ -309,10 +309,11 @@ static char *get_config_name(struct list_head *head_terms) | |||
| 309 | static struct perf_evsel * | 309 | static struct perf_evsel * |
| 310 | __add_event(struct list_head *list, int *idx, | 310 | __add_event(struct list_head *list, int *idx, |
| 311 | struct perf_event_attr *attr, | 311 | struct perf_event_attr *attr, |
| 312 | char *name, struct cpu_map *cpus, | 312 | char *name, struct perf_pmu *pmu, |
| 313 | struct list_head *config_terms, bool auto_merge_stats) | 313 | struct list_head *config_terms, bool auto_merge_stats) |
| 314 | { | 314 | { |
| 315 | struct perf_evsel *evsel; | 315 | struct perf_evsel *evsel; |
| 316 | struct cpu_map *cpus = pmu ? pmu->cpus : NULL; | ||
| 316 | 317 | ||
| 317 | event_attr_init(attr); | 318 | event_attr_init(attr); |
| 318 | 319 | ||
| @@ -323,7 +324,7 @@ __add_event(struct list_head *list, int *idx, | |||
| 323 | (*idx)++; | 324 | (*idx)++; |
| 324 | evsel->cpus = cpu_map__get(cpus); | 325 | evsel->cpus = cpu_map__get(cpus); |
| 325 | evsel->own_cpus = cpu_map__get(cpus); | 326 | evsel->own_cpus = cpu_map__get(cpus); |
| 326 | evsel->system_wide = !!cpus; | 327 | evsel->system_wide = pmu ? pmu->is_uncore : false; |
| 327 | evsel->auto_merge_stats = auto_merge_stats; | 328 | evsel->auto_merge_stats = auto_merge_stats; |
| 328 | 329 | ||
| 329 | if (name) | 330 | if (name) |
| @@ -1233,7 +1234,7 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state, | |||
| 1233 | 1234 | ||
| 1234 | if (!head_config) { | 1235 | if (!head_config) { |
| 1235 | attr.type = pmu->type; | 1236 | attr.type = pmu->type; |
| 1236 | evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu->cpus, NULL, auto_merge_stats); | 1237 | evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu, NULL, auto_merge_stats); |
| 1237 | return evsel ? 0 : -ENOMEM; | 1238 | return evsel ? 0 : -ENOMEM; |
| 1238 | } | 1239 | } |
| 1239 | 1240 | ||
| @@ -1254,7 +1255,7 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state, | |||
| 1254 | return -EINVAL; | 1255 | return -EINVAL; |
| 1255 | 1256 | ||
| 1256 | evsel = __add_event(list, &parse_state->idx, &attr, | 1257 | evsel = __add_event(list, &parse_state->idx, &attr, |
| 1257 | get_config_name(head_config), pmu->cpus, | 1258 | get_config_name(head_config), pmu, |
| 1258 | &config_terms, auto_merge_stats); | 1259 | &config_terms, auto_merge_stats); |
| 1259 | if (evsel) { | 1260 | if (evsel) { |
| 1260 | evsel->unit = info.unit; | 1261 | evsel->unit = info.unit; |
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index ac16a9db1fb5..1c4d7b4e4fb5 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c | |||
| @@ -470,17 +470,36 @@ static void pmu_read_sysfs(void) | |||
| 470 | closedir(dir); | 470 | closedir(dir); |
| 471 | } | 471 | } |
| 472 | 472 | ||
| 473 | static struct cpu_map *__pmu_cpumask(const char *path) | ||
| 474 | { | ||
| 475 | FILE *file; | ||
| 476 | struct cpu_map *cpus; | ||
| 477 | |||
| 478 | file = fopen(path, "r"); | ||
| 479 | if (!file) | ||
| 480 | return NULL; | ||
| 481 | |||
| 482 | cpus = cpu_map__read(file); | ||
| 483 | fclose(file); | ||
| 484 | return cpus; | ||
| 485 | } | ||
| 486 | |||
| 487 | /* | ||
| 488 | * Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64) | ||
| 489 | * may have a "cpus" file. | ||
| 490 | */ | ||
| 491 | #define CPUS_TEMPLATE_UNCORE "%s/bus/event_source/devices/%s/cpumask" | ||
| 492 | #define CPUS_TEMPLATE_CPU "%s/bus/event_source/devices/%s/cpus" | ||
| 493 | |||
| 473 | static struct cpu_map *pmu_cpumask(const char *name) | 494 | static struct cpu_map *pmu_cpumask(const char *name) |
| 474 | { | 495 | { |
| 475 | struct stat st; | ||
| 476 | char path[PATH_MAX]; | 496 | char path[PATH_MAX]; |
| 477 | FILE *file; | ||
| 478 | struct cpu_map *cpus; | 497 | struct cpu_map *cpus; |
| 479 | const char *sysfs = sysfs__mountpoint(); | 498 | const char *sysfs = sysfs__mountpoint(); |
| 480 | const char *templates[] = { | 499 | const char *templates[] = { |
| 481 | "%s/bus/event_source/devices/%s/cpumask", | 500 | CPUS_TEMPLATE_UNCORE, |
| 482 | "%s/bus/event_source/devices/%s/cpus", | 501 | CPUS_TEMPLATE_CPU, |
| 483 | NULL | 502 | NULL |
| 484 | }; | 503 | }; |
| 485 | const char **template; | 504 | const char **template; |
| 486 | 505 | ||
| @@ -489,20 +508,25 @@ static struct cpu_map *pmu_cpumask(const char *name) | |||
| 489 | 508 | ||
| 490 | for (template = templates; *template; template++) { | 509 | for (template = templates; *template; template++) { |
| 491 | snprintf(path, PATH_MAX, *template, sysfs, name); | 510 | snprintf(path, PATH_MAX, *template, sysfs, name); |
| 492 | if (stat(path, &st) == 0) | 511 | cpus = __pmu_cpumask(path); |
| 493 | break; | 512 | if (cpus) |
| 513 | return cpus; | ||
| 494 | } | 514 | } |
| 495 | 515 | ||
| 496 | if (!*template) | 516 | return NULL; |
| 497 | return NULL; | 517 | } |
| 498 | 518 | ||
| 499 | file = fopen(path, "r"); | 519 | static bool pmu_is_uncore(const char *name) |
| 500 | if (!file) | 520 | { |
| 501 | return NULL; | 521 | char path[PATH_MAX]; |
| 522 | struct cpu_map *cpus; | ||
| 523 | const char *sysfs = sysfs__mountpoint(); | ||
| 502 | 524 | ||
| 503 | cpus = cpu_map__read(file); | 525 | snprintf(path, PATH_MAX, CPUS_TEMPLATE_UNCORE, sysfs, name); |
| 504 | fclose(file); | 526 | cpus = __pmu_cpumask(path); |
| 505 | return cpus; | 527 | cpu_map__put(cpus); |
| 528 | |||
| 529 | return !!cpus; | ||
| 506 | } | 530 | } |
| 507 | 531 | ||
| 508 | /* | 532 | /* |
| @@ -617,6 +641,8 @@ static struct perf_pmu *pmu_lookup(const char *name) | |||
| 617 | 641 | ||
| 618 | pmu->cpus = pmu_cpumask(name); | 642 | pmu->cpus = pmu_cpumask(name); |
| 619 | 643 | ||
| 644 | pmu->is_uncore = pmu_is_uncore(name); | ||
| 645 | |||
| 620 | INIT_LIST_HEAD(&pmu->format); | 646 | INIT_LIST_HEAD(&pmu->format); |
| 621 | INIT_LIST_HEAD(&pmu->aliases); | 647 | INIT_LIST_HEAD(&pmu->aliases); |
| 622 | list_splice(&format, &pmu->format); | 648 | list_splice(&format, &pmu->format); |
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 389e9729331f..fe0de0502ce2 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h | |||
| @@ -22,6 +22,7 @@ struct perf_pmu { | |||
| 22 | char *name; | 22 | char *name; |
| 23 | __u32 type; | 23 | __u32 type; |
| 24 | bool selectable; | 24 | bool selectable; |
| 25 | bool is_uncore; | ||
| 25 | struct perf_event_attr *default_config; | 26 | struct perf_event_attr *default_config; |
| 26 | struct cpu_map *cpus; | 27 | struct cpu_map *cpus; |
| 27 | struct list_head format; /* HEAD struct perf_pmu_format -> list */ | 28 | struct list_head format; /* HEAD struct perf_pmu_format -> list */ |
