1 // SPDX-License-Identifier: GPL-2.0
4 #include "util/evsel.h"
7 #include "linux/string.h"
9 #include "util/debug.h"
12 #define IBS_FETCH_L3MISSONLY (1ULL << 59)
13 #define IBS_OP_L3MISSONLY (1ULL << 16)
15 void arch_evsel__set_sample_weight(struct evsel *evsel)
17 evsel__set_sample_bit(evsel, WEIGHT_STRUCT);
20 void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr)
22 struct perf_env env = { .total_mem = 0, } ;
24 if (!perf_env__cpuid(&env))
28 * On AMD, precise cycles event sampling internally uses IBS pmu.
29 * But IBS does not have filtering capabilities and perf by default
30 * sets exclude_guest = 1. This makes IBS pmu event init fail and
31 * thus perf ends up doing non-precise sampling. Avoid it by clearing
34 if (env.cpuid && strstarts(env.cpuid, "AuthenticAMD"))
35 attr->exclude_guest = 0;
40 /* Check whether the evsel's PMU supports the perf metrics */
41 bool evsel__sys_has_perf_metrics(const struct evsel *evsel)
43 const char *pmu_name = evsel->pmu_name ? evsel->pmu_name : "cpu";
46 * The PERF_TYPE_RAW type is the core PMU type, e.g., "cpu" PMU
47 * on a non-hybrid machine, "cpu_core" PMU on a hybrid machine.
48 * The slots event is only available for the core PMU, which
49 * supports the perf metrics feature.
50 * Checking both the PERF_TYPE_RAW type and the slots event
51 * should be good enough to detect the perf metrics feature.
53 if ((evsel->core.attr.type == PERF_TYPE_RAW) &&
54 pmu_have_event(pmu_name, "slots"))
60 bool arch_evsel__must_be_in_group(const struct evsel *evsel)
62 if (!evsel__sys_has_perf_metrics(evsel))
66 (strcasestr(evsel->name, "slots") ||
67 strcasestr(evsel->name, "topdown"));
70 int arch_evsel__hw_name(struct evsel *evsel, char *bf, size_t size)
72 u64 event = evsel->core.attr.config & PERF_HW_EVENT_MASK;
73 u64 pmu = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT;
74 const char *event_name;
76 if (event < PERF_COUNT_HW_MAX && evsel__hw_names[event])
77 event_name = evsel__hw_names[event];
79 event_name = "unknown-hardware";
81 /* The PMU type is not required for the non-hybrid platform. */
83 return scnprintf(bf, size, "%s", event_name);
85 return scnprintf(bf, size, "%s/%s/",
86 evsel->pmu_name ? evsel->pmu_name : "cpu",
90 static void ibs_l3miss_warn(void)
93 "WARNING: Hw internally resets sampling period when L3 Miss Filtering is enabled\n"
94 "and tagged operation does not cause L3 Miss. This causes sampling period skew.\n");
97 void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr)
99 struct perf_pmu *evsel_pmu, *ibs_fetch_pmu, *ibs_op_pmu;
100 static int warned_once;
102 if (warned_once || !x86__is_amd_cpu())
105 evsel_pmu = evsel__find_pmu(evsel);
109 ibs_fetch_pmu = perf_pmu__find("ibs_fetch");
110 ibs_op_pmu = perf_pmu__find("ibs_op");
112 if (ibs_fetch_pmu && ibs_fetch_pmu->type == evsel_pmu->type) {
113 if (attr->config & IBS_FETCH_L3MISSONLY) {
117 } else if (ibs_op_pmu && ibs_op_pmu->type == evsel_pmu->type) {
118 if (attr->config & IBS_OP_L3MISSONLY) {