History

perf record: Support sample-read topdown metric group for hybrid platforms

With the hardware TopDown metrics feature, the 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 are 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, uses the 2nd event of the group as the "leader" for the purposes of sampling. Only the platform with the TopDown metric feature supports sample-read the topdown group. In commit acb65150a47c ("perf record: Support sample-read topdown metric group"), it adds arch_topdown_sample_read() to indicate whether the TopDown group supports sample-read, it should only work on the non-hybrid systems, this patch extends the support for hybrid platforms. Before: # ./perf record -e "{cpu_core/slots/,cpu_core/cycles/,cpu_core/topdown-retiring/}:S" -a sleep 1 Error: The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (cpu_core/topdown-retiring/). /bin/dmesg | grep -i perf may provide additional information. After: # ./perf record -e "{cpu_core/slots/,cpu_core/cycles/,cpu_core/topdown-retiring/}:S" -a sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.238 MB perf.data (369 samples) ]

Zhengjun Xing committed 4 years ago

Commit 151e7d71 parent 2762c483 files · +13 −18Browse files

Unified · Split

3 files
  1. tools/perf/arch/x86/util/evsel.c +2 −1
  2. tools/perf/arch/x86/util/evsel.h +7 −0
  3. tools/perf/arch/x86/util/topdown.c +4 −17
tools/perf/arch/x86/util/evsel.c+2−1
@@ -5,6 +5,7 @@ · 4 unmodified lines
55 #include "util/env.h"
66 #include "util/pmu.h"
77 #include "linux/string.h"
8+#include "evsel.h"
89
910 void arch_evsel__set_sample_weight(struct evsel *evsel)
1011 {
@@ -32,7 +33,7 @@ void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr) · 21 unmodified lines
3233 }
3334
3435 /* Check whether the evsel's PMU supports the perf metrics */
35−static bool evsel__sys_has_perf_metrics(const struct evsel *evsel)
36+bool evsel__sys_has_perf_metrics(const struct evsel *evsel)
3637 {
3738 const char *pmu_name = evsel->pmu_name ? evsel->pmu_name : "cpu";
3839
tools/perf/arch/x86/util/evsel.h+7−0
@@ -0,0 +1,7 @@
1+/* SPDX-License-Identifier: GPL-2.0 */
2+#ifndef _EVSEL_H
3+#define _EVSEL_H 1
4+
5+bool evsel__sys_has_perf_metrics(const struct evsel *evsel);
6+
7+#endif
tools/perf/arch/x86/util/topdown.c+4−17
@@ -4,6 +4,7 @@ · 3 unmodified lines
44 #include "util/pmu.h"
55 #include "util/topdown.h"
66 #include "topdown.h"
7+#include "evsel.h"
78
89 /* Check whether there is a PMU which supports the perf metrics. */
910 bool topdown_sys_has_perf_metrics(void)
@@ -55,33 +56,19 @@ void arch_topdown_group_warn(void) · 45 unmodified lines
5556
5657 #define TOPDOWN_SLOTS 0x0400
5758
58−static bool is_topdown_slots_event(struct evsel *counter)
59−{
60− if (!counter->pmu_name)
61− return false;
62−
63− if (strcmp(counter->pmu_name, "cpu"))
64− return false;
65−
66− if (counter->core.attr.config == TOPDOWN_SLOTS)
67− return true;
68−
69− return false;
70−}
71−
7259 /*
7360 * Check whether a topdown group supports sample-read.
7461 *
75− * Only Topdown metic supports sample-read. The slots
62+ * Only Topdown metric supports sample-read. The slots
7663 * event must be the leader of the topdown group.
7764 */
7865
7966 bool arch_topdown_sample_read(struct evsel *leader)
8067 {
81− if (!pmu_have_event("cpu", "slots"))
68+ if (!evsel__sys_has_perf_metrics(leader))
8269 return false;
8370
84− if (is_topdown_slots_event(leader))
71+ if (leader->core.attr.config == TOPDOWN_SLOTS)
8572 return true;
8673
8774 return false;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t