1 // SPDX-License-Identifier: GPL-2.0 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include "util/evsel.h" 5 #include "util/env.h" 6 #include "util/pmu.h" 7 #include "linux/string.h" 8 9 void arch_evsel__set_sample_weight(struct evsel *evsel) 10 { 11 evsel__set_sample_bit(evsel, WEIGHT_STRUCT); 12 } 13 14 void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr) 15 { 16 struct perf_env env = { .total_mem = 0, } ; 17 18 if (!perf_env__cpuid(&env)) 19 return; 20 21 /* 22 * On AMD, precise cycles event sampling internally uses IBS pmu. 23 * But IBS does not have filtering capabilities and perf by default 24 * sets exclude_guest = 1. This makes IBS pmu event init fail and 25 * thus perf ends up doing non-precise sampling. Avoid it by clearing 26 * exclude_guest. 27 */ 28 if (env.cpuid && strstarts(env.cpuid, "AuthenticAMD")) 29 attr->exclude_guest = 0; 30 31 free(env.cpuid); 32 } 33 34 /* Check whether the evsel's PMU supports the perf metrics */ 35 static bool evsel__sys_has_perf_metrics(const struct evsel *evsel) 36 { 37 const char *pmu_name = evsel->pmu_name ? evsel->pmu_name : "cpu"; 38 39 /* 40 * The PERF_TYPE_RAW type is the core PMU type, e.g., "cpu" PMU 41 * on a non-hybrid machine, "cpu_core" PMU on a hybrid machine. 42 * The slots event is only available for the core PMU, which 43 * supports the perf metrics feature. 44 * Checking both the PERF_TYPE_RAW type and the slots event 45 * should be good enough to detect the perf metrics feature. 46 */ 47 if ((evsel->core.attr.type == PERF_TYPE_RAW) && 48 pmu_have_event(pmu_name, "slots")) 49 return true; 50 51 return false; 52 } 53 54 bool arch_evsel__must_be_in_group(const struct evsel *evsel) 55 { 56 if (!evsel__sys_has_perf_metrics(evsel)) 57 return false; 58 59 return evsel->name && 60 (!strcasecmp(evsel->name, "slots") || 61 strcasestr(evsel->name, "topdown")); 62 } 63