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