1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/zalloc.h>
11 #include "parse-events.h"
12 #include "parse-events-hybrid.h"
15 #include "pmu-hybrid.h"
18 static void config_hybrid_attr(struct perf_event_attr *attr,
19 int type, int pmu_type)
22 * attr.config layout for type PERF_TYPE_HARDWARE and
25 * PERF_TYPE_HARDWARE: 0xEEEEEEEE000000AA
26 * AA: hardware event ID
27 * EEEEEEEE: PMU type ID
28 * PERF_TYPE_HW_CACHE: 0xEEEEEEEE00DDCCBB
29 * BB: hardware cache ID
30 * CC: hardware cache op ID
31 * DD: hardware cache op result ID
32 * EEEEEEEE: PMU type ID
33 * If the PMU type ID is 0, the PERF_TYPE_RAW will be applied.
36 attr->config = attr->config | ((__u64)pmu_type << PERF_PMU_TYPE_SHIFT);
39 static int create_event_hybrid(__u32 config_type, int *idx,
40 struct list_head *list,
41 struct perf_event_attr *attr, char *name,
42 struct list_head *config_terms,
46 __u32 type = attr->type;
47 __u64 config = attr->config;
49 config_hybrid_attr(attr, config_type, pmu->type);
50 evsel = parse_events__add_event_hybrid(list, idx, attr, name,
53 evsel->pmu_name = strdup(pmu->name);
58 attr->config = config;
62 static int add_hw_hybrid(struct parse_events_state *parse_state,
63 struct list_head *list, struct perf_event_attr *attr,
64 char *name, struct list_head *config_terms)
69 perf_pmu__for_each_hybrid_pmu(pmu) {
70 ret = create_event_hybrid(PERF_TYPE_HARDWARE,
71 &parse_state->idx, list, attr, name,
80 int parse_events__add_numeric_hybrid(struct parse_events_state *parse_state,
81 struct list_head *list,
82 struct perf_event_attr *attr,
83 char *name, struct list_head *config_terms,
87 if (attr->type == PERF_TYPE_SOFTWARE)
90 if (!perf_pmu__has_hybrid())
94 if (attr->type != PERF_TYPE_RAW) {
95 return add_hw_hybrid(parse_state, list, attr, name,