Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf record: Support sample-read topdown metric group

With the hardware TopDown metrics feature, sample-read feature should be
supported for a topdown group, e.g., sample a non-topdown event and read
a topdown metric group. But the current perf record code errors out.

For a topdown metric group, the slots event must be the leader of the
group, but the leader slots event doesn't support sampling.

To support sample-read the topdown metric group, use the 2nd event of
the group as the "leader" for the purposes of sampling.

Only the platform with Topdown metic feature supports sample-read the
topdown group. Add arch_topdown_sample_read() to indicate whether the
topdown group supports sample-read.

Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200911144808.27603-3-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Kan Liang and committed by
Arnaldo Carvalho de Melo
acb65150 687986bb

+44 -1
+35
tools/perf/arch/x86/util/topdown.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <stdio.h> 3 3 #include "api/fs/fs.h" 4 + #include "util/pmu.h" 4 5 #include "util/topdown.h" 5 6 6 7 /* ··· 26 25 fprintf(stderr, 27 26 "nmi_watchdog enabled with topdown. May give wrong results.\n" 28 27 "Disable with echo 0 > /proc/sys/kernel/nmi_watchdog\n"); 28 + } 29 + 30 + #define TOPDOWN_SLOTS 0x0400 31 + 32 + static bool is_topdown_slots_event(struct evsel *counter) 33 + { 34 + if (!counter->pmu_name) 35 + return false; 36 + 37 + if (strcmp(counter->pmu_name, "cpu")) 38 + return false; 39 + 40 + if (counter->core.attr.config == TOPDOWN_SLOTS) 41 + return true; 42 + 43 + return false; 44 + } 45 + 46 + /* 47 + * Check whether a topdown group supports sample-read. 48 + * 49 + * Only Topdown metic supports sample-read. The slots 50 + * event must be the leader of the topdown group. 51 + */ 52 + 53 + bool arch_topdown_sample_read(struct evsel *leader) 54 + { 55 + if (!pmu_have_event("cpu", "slots")) 56 + return false; 57 + 58 + if (is_topdown_slots_event(leader)) 59 + return true; 60 + 61 + return false; 29 62 }
+2 -1
tools/perf/util/record.c
··· 14 14 #include "util/perf_api_probe.h" 15 15 #include "record.h" 16 16 #include "../perf-sys.h" 17 + #include "topdown.h" 17 18 18 19 /* 19 20 * evsel__config_leader_sampling() uses special rules for leader sampling. ··· 25 24 { 26 25 struct evsel *leader = evsel->leader; 27 26 28 - if (evsel__is_aux_event(leader)) { 27 + if (evsel__is_aux_event(leader) || arch_topdown_sample_read(leader)) { 29 28 evlist__for_each_entry(evlist, evsel) { 30 29 if (evsel->leader == leader && evsel != evsel->leader) 31 30 return evsel;
+5
tools/perf/util/topdown.c
··· 51 51 __weak void arch_topdown_group_warn(void) 52 52 { 53 53 } 54 + 55 + __weak bool arch_topdown_sample_read(struct evsel *leader __maybe_unused) 56 + { 57 + return false; 58 + }
+2
tools/perf/util/topdown.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 #ifndef TOPDOWN_H 3 3 #define TOPDOWN_H 1 4 + #include "evsel.h" 4 5 5 6 bool arch_topdown_check_group(bool *warn); 6 7 void arch_topdown_group_warn(void); 8 + bool arch_topdown_sample_read(struct evsel *leader); 7 9 8 10 int topdown_filter_events(const char **attr, char **str, bool use_group); 9 11