Skip to content

Commit 151e7d7

Browse files
ZhengjunXingacmel
authored andcommitted
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 acb6515 ("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) ] Fixes: acb6515 ("perf record: Support sample-read topdown metric group") Reviewed-by: Kan Liang <[email protected]> Signed-off-by: Zhengjun Xing <[email protected]> Acked-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 2762c48 commit 151e7d7

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

tools/perf/arch/x86/util/evsel.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
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)
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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)
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;

0 commit comments

Comments
 (0)