1 // SPDX-License-Identifier: GPL-2.0
4 #include "util/evsel.h"
7 #include "linux/string.h"
9 #include "util/debug.h"
11 #define IBS_FETCH_L3MISSONLY (1ULL << 59)
12 #define IBS_OP_L3MISSONLY (1ULL << 16)
14 void arch_evsel__set_sample_weight(struct evsel *evsel)
16 evsel__set_sample_bit(evsel, WEIGHT_STRUCT);
19 void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr)
21 struct perf_env env = { .total_mem = 0, } ;
23 if (!perf_env__cpuid(&env))
27 * On AMD, precise cycles event sampling internally uses IBS pmu.
28 * But IBS does not have filtering capabilities and perf by default
29 * sets exclude_guest = 1. This makes IBS pmu event init fail and
30 * thus perf ends up doing non-precise sampling. Avoid it by clearing
33 if (env.cpuid && strstarts(env.cpuid, "AuthenticAMD"))
34 attr->exclude_guest = 0;
39 /* Check whether the evsel's PMU supports the perf metrics */
40 bool evsel__sys_has_perf_metrics(const struct evsel *evsel)
42 const char *pmu_name = evsel->pmu_name ? evsel->pmu_name : "cpu";
45 * The PERF_TYPE_RAW type is the core PMU type, e.g., "cpu" PMU
46 * on a non-hybrid machine, "cpu_core" PMU on a hybrid machine.
47 * The slots event is only available for the core PMU, which
48 * supports the perf metrics feature.
49 * Checking both the PERF_TYPE_RAW type and the slots event
50 * should be good enough to detect the perf metrics feature.
52 if ((evsel->core.attr.type == PERF_TYPE_RAW) &&
53 pmu_have_event(pmu_name, "slots"))
59 bool arch_evsel__must_be_in_group(const struct evsel *evsel)
61 if (!evsel__sys_has_perf_metrics(evsel))
65 (strcasestr(evsel->name, "slots") ||
66 strcasestr(evsel->name, "topdown"));
69 int arch_evsel__hw_name(struct evsel *evsel, char *bf, size_t size)
71 u64 event = evsel->core.attr.config & PERF_HW_EVENT_MASK;
72 u64 pmu = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT;
73 const char *event_name;
75 if (event < PERF_COUNT_HW_MAX && evsel__hw_names[event])
76 event_name = evsel__hw_names[event];
78 event_name = "unknown-hardware";
80 /* The PMU type is not required for the non-hybrid platform. */
82 return scnprintf(bf, size, "%s", event_name);
84 return scnprintf(bf, size, "%s/%s/",
85 evsel->pmu_name ? evsel->pmu_name : "cpu",
89 static void ibs_l3miss_warn(void)
92 "WARNING: Hw internally resets sampling period when L3 Miss Filtering is enabled\n"
93 "and tagged operation does not cause L3 Miss. This causes sampling period skew.\n");
96 void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr)
98 struct perf_pmu *evsel_pmu, *ibs_fetch_pmu, *ibs_op_pmu;
99 static int warned_once;
100 /* 0: Uninitialized, 1: Yes, -1: No */
103 if (warned_once || is_amd == -1)
107 struct perf_env *env = evsel__env(evsel);
109 if (!perf_env__cpuid(env) || !env->cpuid ||
110 !strstarts(env->cpuid, "AuthenticAMD")) {
117 evsel_pmu = evsel__find_pmu(evsel);
121 ibs_fetch_pmu = perf_pmu__find("ibs_fetch");
122 ibs_op_pmu = perf_pmu__find("ibs_op");
124 if (ibs_fetch_pmu && ibs_fetch_pmu->type == evsel_pmu->type) {
125 if (attr->config & IBS_FETCH_L3MISSONLY) {
129 } else if (ibs_op_pmu && ibs_op_pmu->type == evsel_pmu->type) {
130 if (attr->config & IBS_OP_L3MISSONLY) {