Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf tools: Add missing_features for aux_start_paused, aux_pause, aux_resume

Display "feature is not supported" error message if aux_start_paused,
aux_pause or aux_resume result in a perf_event_open() error.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20241216070244.14450-5-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
bf66b5fd 8a0f49a7

+87 -12
+86 -12
tools/perf/util/evsel.c
··· 2145 2145 return err; 2146 2146 } 2147 2147 2148 - static bool has_attr_feature(struct perf_event_attr *attr, unsigned long flags) 2148 + static bool __has_attr_feature(struct perf_event_attr *attr, 2149 + struct perf_cpu cpu, unsigned long flags) 2149 2150 { 2150 - int fd = syscall(SYS_perf_event_open, attr, /*pid=*/0, /*cpu=*/-1, 2151 + int fd = syscall(SYS_perf_event_open, attr, /*pid=*/0, cpu.cpu, 2151 2152 /*group_fd=*/-1, flags); 2152 2153 close(fd); 2153 2154 2154 2155 if (fd < 0) { 2155 2156 attr->exclude_kernel = 1; 2156 2157 2157 - fd = syscall(SYS_perf_event_open, attr, /*pid=*/0, /*cpu=*/-1, 2158 + fd = syscall(SYS_perf_event_open, attr, /*pid=*/0, cpu.cpu, 2158 2159 /*group_fd=*/-1, flags); 2159 2160 close(fd); 2160 2161 } ··· 2163 2162 if (fd < 0) { 2164 2163 attr->exclude_hv = 1; 2165 2164 2166 - fd = syscall(SYS_perf_event_open, attr, /*pid=*/0, /*cpu=*/-1, 2165 + fd = syscall(SYS_perf_event_open, attr, /*pid=*/0, cpu.cpu, 2167 2166 /*group_fd=*/-1, flags); 2168 2167 close(fd); 2169 2168 } ··· 2171 2170 if (fd < 0) { 2172 2171 attr->exclude_guest = 1; 2173 2172 2174 - fd = syscall(SYS_perf_event_open, attr, /*pid=*/0, /*cpu=*/-1, 2173 + fd = syscall(SYS_perf_event_open, attr, /*pid=*/0, cpu.cpu, 2175 2174 /*group_fd=*/-1, flags); 2176 2175 close(fd); 2177 2176 } ··· 2181 2180 attr->exclude_hv = 0; 2182 2181 2183 2182 return fd >= 0; 2183 + } 2184 + 2185 + static bool has_attr_feature(struct perf_event_attr *attr, unsigned long flags) 2186 + { 2187 + struct perf_cpu cpu = {.cpu = -1}; 2188 + 2189 + return __has_attr_feature(attr, cpu, flags); 2184 2190 } 2185 2191 2186 2192 static void evsel__detect_missing_pmu_features(struct evsel *evsel) ··· 2278 2270 errno = old_errno; 2279 2271 } 2280 2272 2281 - static bool evsel__detect_missing_features(struct evsel *evsel) 2273 + static bool evsel__probe_aux_action(struct evsel *evsel, struct perf_cpu cpu) 2274 + { 2275 + struct perf_event_attr attr = evsel->core.attr; 2276 + int old_errno = errno; 2277 + 2278 + attr.disabled = 1; 2279 + attr.aux_start_paused = 1; 2280 + 2281 + if (__has_attr_feature(&attr, cpu, /*flags=*/0)) { 2282 + errno = old_errno; 2283 + return true; 2284 + } 2285 + 2286 + /* 2287 + * EOPNOTSUPP means the kernel supports the feature but the PMU does 2288 + * not, so keep that distinction if possible. 2289 + */ 2290 + if (errno != EOPNOTSUPP) 2291 + errno = old_errno; 2292 + 2293 + return false; 2294 + } 2295 + 2296 + static void evsel__detect_missing_aux_action_feature(struct evsel *evsel, struct perf_cpu cpu) 2297 + { 2298 + static bool detection_done; 2299 + struct evsel *leader; 2300 + 2301 + /* 2302 + * Don't bother probing aux_action if it is not being used or has been 2303 + * probed before. 2304 + */ 2305 + if (!evsel->core.attr.aux_action || detection_done) 2306 + return; 2307 + 2308 + detection_done = true; 2309 + 2310 + /* 2311 + * The leader is an AUX area event. If it has failed, assume the feature 2312 + * is not supported. 2313 + */ 2314 + leader = evsel__leader(evsel); 2315 + if (evsel == leader) { 2316 + perf_missing_features.aux_action = true; 2317 + return; 2318 + } 2319 + 2320 + /* 2321 + * AUX area event with aux_action must have been opened successfully 2322 + * already, so feature is supported. 2323 + */ 2324 + if (leader->core.attr.aux_action) 2325 + return; 2326 + 2327 + if (!evsel__probe_aux_action(leader, cpu)) 2328 + perf_missing_features.aux_action = true; 2329 + } 2330 + 2331 + static bool evsel__detect_missing_features(struct evsel *evsel, struct perf_cpu cpu) 2282 2332 { 2283 2333 static bool detection_done = false; 2284 2334 struct perf_event_attr attr = { ··· 2345 2279 .disabled = 1, 2346 2280 }; 2347 2281 int old_errno; 2282 + 2283 + evsel__detect_missing_aux_action_feature(evsel, cpu); 2348 2284 2349 2285 evsel__detect_missing_pmu_features(evsel); 2350 2286 ··· 2562 2494 int idx, thread, nthreads; 2563 2495 int pid = -1, err, old_errno; 2564 2496 enum rlimit_action set_rlimit = NO_CHANGE; 2497 + struct perf_cpu cpu; 2565 2498 2566 2499 if (evsel__is_retire_lat(evsel)) 2567 2500 return tpebs_start(evsel->evlist); ··· 2600 2531 } 2601 2532 2602 2533 for (idx = start_cpu_map_idx; idx < end_cpu_map_idx; idx++) { 2534 + cpu = perf_cpu_map__cpu(cpus, idx); 2603 2535 2604 2536 for (thread = 0; thread < nthreads; thread++) { 2605 2537 int fd, group_fd; ··· 2621 2551 2622 2552 /* Debug message used by test scripts */ 2623 2553 pr_debug2_peo("sys_perf_event_open: pid %d cpu %d group_fd %d flags %#lx", 2624 - pid, perf_cpu_map__cpu(cpus, idx).cpu, group_fd, evsel->open_flags); 2554 + pid, cpu.cpu, group_fd, evsel->open_flags); 2625 2555 2626 - fd = sys_perf_event_open(&evsel->core.attr, pid, 2627 - perf_cpu_map__cpu(cpus, idx).cpu, 2556 + fd = sys_perf_event_open(&evsel->core.attr, pid, cpu.cpu, 2628 2557 group_fd, evsel->open_flags); 2629 2558 2630 2559 FD(evsel, idx, thread) = fd; ··· 2639 2570 bpf_counter__install_pe(evsel, idx, fd); 2640 2571 2641 2572 if (unlikely(test_attr__enabled())) { 2642 - test_attr__open(&evsel->core.attr, pid, 2643 - perf_cpu_map__cpu(cpus, idx), 2573 + test_attr__open(&evsel->core.attr, pid, cpu, 2644 2574 fd, group_fd, evsel->open_flags); 2645 2575 } 2646 2576 ··· 2694 2626 if (err == -EMFILE && rlimit__increase_nofile(&set_rlimit)) 2695 2627 goto retry_open; 2696 2628 2697 - if (err == -EINVAL && evsel__detect_missing_features(evsel)) 2629 + if (err == -EINVAL && evsel__detect_missing_features(evsel, cpu)) 2698 2630 goto fallback_missing_features; 2699 2631 2700 2632 if (evsel__precise_ip_fallback(evsel)) ··· 3653 3585 return scnprintf(msg, size, 3654 3586 "%s: PMU Hardware doesn't support 'aux_output' feature", 3655 3587 evsel__name(evsel)); 3588 + if (evsel->core.attr.aux_action) 3589 + return scnprintf(msg, size, 3590 + "%s: PMU Hardware doesn't support 'aux_action' feature", 3591 + evsel__name(evsel)); 3656 3592 if (evsel->core.attr.sample_period != 0) 3657 3593 return scnprintf(msg, size, 3658 3594 "%s: PMU Hardware doesn't support sampling/overflow-interrupts. Try 'perf stat'", ··· 3687 3615 return scnprintf(msg, size, "clockid feature not supported."); 3688 3616 if (perf_missing_features.clockid_wrong) 3689 3617 return scnprintf(msg, size, "wrong clockid (%d).", clockid); 3618 + if (perf_missing_features.aux_action) 3619 + return scnprintf(msg, size, "The 'aux_action' feature is not supported, update the kernel."); 3690 3620 if (perf_missing_features.aux_output) 3691 3621 return scnprintf(msg, size, "The 'aux_output' feature is not supported, update the kernel."); 3692 3622 if (!target__has_cpu(target))
+1
tools/perf/util/evsel.h
··· 207 207 bool weight_struct; 208 208 bool read_lost; 209 209 bool branch_counters; 210 + bool aux_action; 210 211 bool inherit_sample_read; 211 212 }; 212 213