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

perf evsel: Add accessor for tool_event

Currently tool events use a dedicated variable within the evsel. Later
changes will move this to the unused struct perf_event_attr config for
these events. Add an accessor to allow the later change to be well
typed and avoid changing all uses.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20240907050830.6752-4-irogers@google.com
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Yang Jihong <yangjihong@bytedance.com>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Clément Le Goffic <clement.legoffic@foss.st.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ze Gao <zegao2021@gmail.com>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Junhao He <hejunhao3@huawei.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Will Deacon <will@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: Benjamin Gray <bgray@linux.ibm.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: Sun Haiyong <sunhaiyong@loongson.cn>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Xu Yang <xu.yang_2@nxp.com>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Veronika Molnarova <vmolnaro@redhat.com>
Cc: Dr. David Alan Gilbert <linux@treblig.org>
Cc: linux-kernel@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
f08cc258 92532073

+21 -16
+3 -3
tools/perf/builtin-stat.c
··· 294 294 * terminates. Use the wait4 values in that case. 295 295 */ 296 296 if (err && cpu_map_idx == 0 && 297 - (counter->tool_event == PERF_TOOL_USER_TIME || 298 - counter->tool_event == PERF_TOOL_SYSTEM_TIME)) { 297 + (evsel__tool_event(counter) == PERF_TOOL_USER_TIME || 298 + evsel__tool_event(counter) == PERF_TOOL_SYSTEM_TIME)) { 299 299 u64 val, *start_time; 300 300 struct perf_counts_values *count = 301 301 perf_counts(counter->counts, cpu_map_idx, thread); 302 302 303 303 start_time = xyarray__entry(counter->start_times, cpu_map_idx, thread); 304 - if (counter->tool_event == PERF_TOOL_USER_TIME) 304 + if (evsel__tool_event(counter) == PERF_TOOL_USER_TIME) 305 305 val = ru_stats.ru_utime_usec_stat.mean; 306 306 else 307 307 val = ru_stats.ru_stime_usec_stat.mean;
+12 -12
tools/perf/util/evsel.c
··· 773 773 774 774 case PERF_TYPE_SOFTWARE: 775 775 if (evsel__is_tool(evsel)) 776 - evsel__tool_name(evsel->tool_event, bf, sizeof(bf)); 776 + evsel__tool_name(evsel__tool_event(evsel), bf, sizeof(bf)); 777 777 else 778 778 evsel__sw_name(evsel, bf, sizeof(bf)); 779 779 break; ··· 811 811 return evsel->metric_id; 812 812 813 813 if (evsel__is_tool(evsel)) 814 - return perf_tool_event__to_str(evsel->tool_event); 814 + return perf_tool_event__to_str(evsel__tool_event(evsel)); 815 815 816 816 return "unknown"; 817 817 } ··· 1503 1503 evsel->per_pkg_mask = NULL; 1504 1504 zfree(&evsel->metric_events); 1505 1505 perf_evsel__object.fini(evsel); 1506 - if (evsel->tool_event == PERF_TOOL_SYSTEM_TIME || 1507 - evsel->tool_event == PERF_TOOL_USER_TIME) 1506 + if (evsel__tool_event(evsel) == PERF_TOOL_SYSTEM_TIME || 1507 + evsel__tool_event(evsel) == PERF_TOOL_USER_TIME) 1508 1508 xyarray__delete(evsel->start_times); 1509 1509 } 1510 1510 ··· 1785 1785 1786 1786 count = perf_counts(evsel->counts, cpu_map_idx, thread); 1787 1787 1788 - switch (evsel->tool_event) { 1788 + switch (evsel__tool_event(evsel)) { 1789 1789 case PERF_TOOL_DURATION_TIME: 1790 1790 /* 1791 1791 * Pretend duration_time is only on the first CPU and thread, or ··· 1800 1800 break; 1801 1801 case PERF_TOOL_USER_TIME: 1802 1802 case PERF_TOOL_SYSTEM_TIME: { 1803 - bool system = evsel->tool_event == PERF_TOOL_SYSTEM_TIME; 1803 + bool system = evsel__tool_event(evsel) == PERF_TOOL_SYSTEM_TIME; 1804 1804 1805 1805 start_time = xyarray__entry(evsel->start_times, cpu_map_idx, thread); 1806 1806 fd = FD(evsel, cpu_map_idx, thread); ··· 2072 2072 perf_evsel__alloc_fd(&evsel->core, perf_cpu_map__nr(cpus), nthreads) < 0) 2073 2073 return -ENOMEM; 2074 2074 2075 - if ((evsel->tool_event == PERF_TOOL_SYSTEM_TIME || 2076 - evsel->tool_event == PERF_TOOL_USER_TIME) && 2075 + if ((evsel__tool_event(evsel) == PERF_TOOL_SYSTEM_TIME || 2076 + evsel__tool_event(evsel) == PERF_TOOL_USER_TIME) && 2077 2077 !evsel->start_times) { 2078 2078 evsel->start_times = xyarray__new(perf_cpu_map__nr(cpus), nthreads, sizeof(__u64)); 2079 2079 if (!evsel->start_times) ··· 2262 2262 int pid = -1, err, old_errno; 2263 2263 enum rlimit_action set_rlimit = NO_CHANGE; 2264 2264 2265 - if (evsel->tool_event == PERF_TOOL_DURATION_TIME) { 2265 + if (evsel__tool_event(evsel) == PERF_TOOL_DURATION_TIME) { 2266 2266 if (evsel->core.attr.sample_period) /* no sampling */ 2267 2267 return -EINVAL; 2268 2268 evsel->start_time = rdclock(); ··· 2304 2304 if (!evsel->cgrp && !evsel->core.system_wide) 2305 2305 pid = perf_thread_map__pid(threads, thread); 2306 2306 2307 - if (evsel->tool_event == PERF_TOOL_USER_TIME || 2308 - evsel->tool_event == PERF_TOOL_SYSTEM_TIME) { 2309 - bool system = evsel->tool_event == PERF_TOOL_SYSTEM_TIME; 2307 + if (evsel__tool_event(evsel) == PERF_TOOL_USER_TIME || 2308 + evsel__tool_event(evsel) == PERF_TOOL_SYSTEM_TIME) { 2309 + bool system = evsel__tool_event(evsel) == PERF_TOOL_SYSTEM_TIME; 2310 2310 __u64 *start_time = NULL; 2311 2311 2312 2312 if (evsel->core.attr.sample_period) {
+5
tools/perf/util/evsel.h
··· 330 330 return evsel->retire_lat; 331 331 } 332 332 333 + static inline enum perf_tool_event evsel__tool_event(const struct evsel *evsel) 334 + { 335 + return evsel->tool_event; 336 + } 337 + 333 338 const char *evsel__group_name(struct evsel *evsel); 334 339 int evsel__group_desc(struct evsel *evsel, char *buf, size_t size); 335 340
+1 -1
tools/perf/util/stat-shadow.c
··· 380 380 struct stats *stats; 381 381 double scale; 382 382 383 - switch (metric_events[i]->tool_event) { 383 + switch (evsel__tool_event(metric_events[i])) { 384 384 case PERF_TOOL_DURATION_TIME: 385 385 stats = &walltime_nsecs_stats; 386 386 scale = 1e-9;