1 // SPDX-License-Identifier: GPL-2.0
3 #include "util/evsel.h"
4 #include "util/evlist.h"
7 #include "util/topdown.h"
11 /* Check whether there is a PMU which supports the perf metrics. */
12 bool topdown_sys_has_perf_metrics(void)
14 static bool has_perf_metrics
;
19 return has_perf_metrics
;
22 * The perf metrics feature is a core PMU feature.
23 * The PERF_TYPE_RAW type is the type of a core PMU.
24 * The slots event is only available when the core PMU
25 * supports the perf metrics feature.
27 pmu
= perf_pmus__find_by_type(PERF_TYPE_RAW
);
28 if (pmu
&& perf_pmu__have_event(pmu
, "slots"))
29 has_perf_metrics
= true;
32 return has_perf_metrics
;
35 #define TOPDOWN_SLOTS 0x0400
36 bool arch_is_topdown_slots(const struct evsel
*evsel
)
38 if (evsel
->core
.attr
.config
== TOPDOWN_SLOTS
)
44 bool arch_is_topdown_metrics(const struct evsel
*evsel
)
46 int config
= evsel
->core
.attr
.config
;
47 const char *name_from_config
;
50 /* All topdown events have an event code of 0. */
51 if ((config
& 0xFF) != 0)
54 pmu
= evsel__find_pmu(evsel
);
55 if (!pmu
|| !pmu
->is_core
)
58 name_from_config
= perf_pmu__name_from_config(pmu
, config
);
59 return name_from_config
&& strcasestr(name_from_config
, "topdown");
63 * Check whether a topdown group supports sample-read.
65 * Only Topdown metric supports sample-read. The slots
66 * event must be the leader of the topdown group.
68 bool arch_topdown_sample_read(struct evsel
*leader
)
72 if (!evsel__sys_has_perf_metrics(leader
))
75 if (!arch_is_topdown_slots(leader
))
79 * If slots event as leader event but no topdown metric events
80 * in group, slots event should still sample as leader.
82 evlist__for_each_entry(leader
->evlist
, evsel
) {
83 if (evsel
->core
.leader
!= leader
->core
.leader
)
85 if (evsel
!= leader
&& arch_is_topdown_metrics(evsel
))