1 // SPDX-License-Identifier: GPL-2.0
4 #include "util/evlist.h"
5 #include "util/parse-events.h"
6 #include "util/event.h"
7 #include "util/pmu-hybrid.h"
10 static int ___evlist__add_default_attrs(struct evlist *evlist,
11 struct perf_event_attr *attrs,
14 struct perf_cpu_map *cpus;
15 struct evsel *evsel, *n;
20 for (i = 0; i < nr_attrs; i++)
21 event_attr_init(attrs + i);
23 if (!perf_pmu__has_hybrid())
24 return evlist__add_attrs(evlist, attrs, nr_attrs);
26 for (i = 0; i < nr_attrs; i++) {
27 if (attrs[i].type == PERF_TYPE_SOFTWARE) {
28 evsel = evsel__new(attrs + i);
30 goto out_delete_partial_list;
31 list_add_tail(&evsel->core.node, &head);
35 perf_pmu__for_each_hybrid_pmu(pmu) {
36 evsel = evsel__new(attrs + i);
38 goto out_delete_partial_list;
39 evsel->core.attr.config |= (__u64)pmu->type << PERF_PMU_TYPE_SHIFT;
40 cpus = perf_cpu_map__get(pmu->cpus);
41 evsel->core.cpus = cpus;
42 evsel->core.own_cpus = perf_cpu_map__get(cpus);
43 evsel->pmu_name = strdup(pmu->name);
44 list_add_tail(&evsel->core.node, &head);
48 evlist__splice_list_tail(evlist, &head);
52 out_delete_partial_list:
53 __evlist__for_each_entry_safe(&head, n, evsel)
58 int arch_evlist__add_default_attrs(struct evlist *evlist,
59 struct perf_event_attr *attrs,
65 return ___evlist__add_default_attrs(evlist, attrs, nr_attrs);
68 int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs)
70 if (topdown_sys_has_perf_metrics() &&
71 (!lhs->pmu_name || !strncmp(lhs->pmu_name, "cpu", 3))) {
72 /* Ensure the topdown slots comes first. */
73 if (strcasestr(lhs->name, "slots"))
75 if (strcasestr(rhs->name, "slots"))
77 /* Followed by topdown events. */
78 if (strcasestr(lhs->name, "topdown") && !strcasestr(rhs->name, "topdown"))
80 if (!strcasestr(lhs->name, "topdown") && strcasestr(rhs->name, "topdown"))
84 /* Default ordering by insertion index. */
85 return lhs->core.idx - rhs->core.idx;