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) ]
Unified · Split
| @@ -5,6 +5,7 @@ · 4 unmodified lines | ||
| 5 | 5 | #include "util/env.h" |
| 6 | 6 | #include "util/pmu.h" |
| 7 | 7 | #include "linux/string.h" |
| 8 | +#include "evsel.h" | |
| 8 | 9 | |
| 9 | 10 | void arch_evsel__set_sample_weight(struct evsel *evsel) |
| 10 | 11 | { |
| @@ -32,7 +33,7 @@ void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr) · 21 unmodified lines | ||
| 32 | 33 | } |
| 33 | 34 | |
| 34 | 35 | /* 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) | |
| 36 | 37 | { |
| 37 | 38 | const char *pmu_name = evsel->pmu_name ? evsel->pmu_name : "cpu"; |
| 38 | 39 | |
| @@ -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 | |
| @@ -4,6 +4,7 @@ · 3 unmodified lines | ||
| 4 | 4 | #include "util/pmu.h" |
| 5 | 5 | #include "util/topdown.h" |
| 6 | 6 | #include "topdown.h" |
| 7 | +#include "evsel.h" | |
| 7 | 8 | |
| 8 | 9 | /* Check whether there is a PMU which supports the perf metrics. */ |
| 9 | 10 | bool topdown_sys_has_perf_metrics(void) |
| @@ -55,33 +56,19 @@ void arch_topdown_group_warn(void) · 45 unmodified lines | ||
| 55 | 56 | |
| 56 | 57 | #define TOPDOWN_SLOTS 0x0400 |
| 57 | 58 | |
| 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 | − | |
| 72 | 59 | /* |
| 73 | 60 | * Check whether a topdown group supports sample-read. |
| 74 | 61 | * |
| 75 | − * Only Topdown metic supports sample-read. The slots | |
| 62 | + * Only Topdown metric supports sample-read. The slots | |
| 76 | 63 | * event must be the leader of the topdown group. |
| 77 | 64 | */ |
| 78 | 65 | |
| 79 | 66 | bool arch_topdown_sample_read(struct evsel *leader) |
| 80 | 67 | { |
| 81 | − if (!pmu_have_event("cpu", "slots")) | |
| 68 | + if (!evsel__sys_has_perf_metrics(leader)) | |
| 82 | 69 | return false; |
| 83 | 70 | |
| 84 | − if (is_topdown_slots_event(leader)) | |
| 71 | + if (leader->core.attr.config == TOPDOWN_SLOTS) | |
| 85 | 72 | return true; |
| 86 | 73 | |
| 87 | 74 | return false; |