xref: /openbmc/linux/tools/perf/arch/x86/util/topdown.c (revision 60eb644b)
1 // SPDX-License-Identifier: GPL-2.0
2 #include "api/fs/fs.h"
3 #include "util/evsel.h"
4 #include "util/pmu.h"
5 #include "util/topdown.h"
6 #include "topdown.h"
7 #include "evsel.h"
8 
9 /* Check whether there is a PMU which supports the perf metrics. */
10 bool topdown_sys_has_perf_metrics(void)
11 {
12 	static bool has_perf_metrics;
13 	static bool cached;
14 	struct perf_pmu *pmu;
15 
16 	if (cached)
17 		return has_perf_metrics;
18 
19 	/*
20 	 * The perf metrics feature is a core PMU feature.
21 	 * The PERF_TYPE_RAW type is the type of a core PMU.
22 	 * The slots event is only available when the core PMU
23 	 * supports the perf metrics feature.
24 	 */
25 	pmu = perf_pmu__find_by_type(PERF_TYPE_RAW);
26 	if (pmu && pmu_have_event(pmu->name, "slots"))
27 		has_perf_metrics = true;
28 
29 	cached = true;
30 	return has_perf_metrics;
31 }
32 
33 #define TOPDOWN_SLOTS		0x0400
34 
35 /*
36  * Check whether a topdown group supports sample-read.
37  *
38  * Only Topdown metric supports sample-read. The slots
39  * event must be the leader of the topdown group.
40  */
41 bool arch_topdown_sample_read(struct evsel *leader)
42 {
43 	if (!evsel__sys_has_perf_metrics(leader))
44 		return false;
45 
46 	if (leader->core.attr.config == TOPDOWN_SLOTS)
47 		return true;
48 
49 	return false;
50 }
51