perf evsel: Don't pass evsel with sample

As struct perf_sample now directly contains its own resolved evsel pointer,
passing the evsel separately is redundant and clutters the interface.

Remove the redundant evsel parameter from evsel-specific handlers and
structures, ensuring the tool always directly accesses the evsel bound to the
sample. This simplifies the API signatures and eliminates the risk of passing
an inconsistent evsel.

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrew Jones <ajones@ventanamicro.com>
Cc: Anup Patel <anup@brainfault.org>
Cc: Athira Rajeev <atrajeev@linux.ibm.com>
Cc: Blake Jones <blakejones@google.com>
Cc: Chen Ni <nichen@iscas.ac.cn>
Cc: Chun-Tse Shao <ctshao@google.com>
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
Cc: Derek Foreman <derek.foreman@collabora.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Dr. David Alan Gilbert <linux@treblig.org>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Hrishikesh Suresh <hrishikesh123s@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Krzysztof Łopatowski <krzysztof.m.lopatowski@gmail.com>
Cc: Leo Yan <leo.yan@arm.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <pjw@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quan Zhou <zhouquan@iscas.ac.cn>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Swapnil Sapkal <swapnil.sapkal@amd.com>
Cc: Thomas Falcon <thomas.falcon@intel.com>
Cc: Tianyou Li <tianyou.li@intel.com>
Cc: Yujie Liu <yujie.liu@intel.com>
Cc: tanze <tanze@kylinos.cn>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Ian Rogers 2026-05-20 12:05:27 -07:00 committed by Arnaldo Carvalho de Melo
parent ec319c4d35
commit 2856524e4e

View File

@ -3003,52 +3003,62 @@ int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads)
return ret;
}
static int perf_evsel__parse_id_sample(const struct evsel *evsel,
const union perf_event *event,
static int perf_evsel__parse_id_sample(const union perf_event *event,
struct perf_sample *sample)
{
const struct evsel *evsel = sample->evsel;
u64 type = evsel->core.attr.sample_type;
const __u64 *array = event->sample.array;
bool swapped = evsel->needs_swap;
union u64_swap u;
array += ((event->header.size -
sizeof(event->header)) / sizeof(u64)) - 1;
int i = ((event->header.size - sizeof(event->header)) / sizeof(u64)) - 1;
if (type & PERF_SAMPLE_IDENTIFIER) {
sample->id = *array;
array--;
if (i < 0)
return -EFAULT;
sample->id = array[i--];
}
if (type & PERF_SAMPLE_CPU) {
u.val64 = *array;
if (i < 0)
return -EFAULT;
u.val64 = array[i--];
if (swapped) {
/* undo swap of u64, then swap on individual u32s */
u.val64 = bswap_64(u.val64);
u.val32[0] = bswap_32(u.val32[0]);
}
sample->cpu = u.val32[0];
array--;
}
if (type & PERF_SAMPLE_STREAM_ID) {
sample->stream_id = *array;
array--;
if (i < 0)
return -EFAULT;
sample->stream_id = array[i--];
}
if (type & PERF_SAMPLE_ID) {
sample->id = *array;
array--;
if (i < 0)
return -EFAULT;
sample->id = array[i--];
}
if (type & PERF_SAMPLE_TIME) {
sample->time = *array;
array--;
if (i < 0)
return -EFAULT;
sample->time = array[i--];
}
if (type & PERF_SAMPLE_TID) {
u.val64 = *array;
if (i < 0)
return -EFAULT;
u.val64 = array[i--];
if (swapped) {
/* undo swap of u64, then swap on individual u32s */
u.val64 = bswap_64(u.val64);
@ -3058,7 +3068,6 @@ static int perf_evsel__parse_id_sample(const struct evsel *evsel,
sample->pid = u.val32[0];
sample->tid = u.val32[1];
array--;
}
return 0;
@ -3244,15 +3253,18 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
data->deferred_cookie = event->callchain_deferred.cookie;
if (evsel->core.attr.sample_id_all)
perf_evsel__parse_id_sample(evsel, event, data);
if (evsel->core.attr.sample_id_all) {
if (perf_evsel__parse_id_sample(event, data))
goto out_efault;
}
return 0;
}
if (event->header.type != PERF_RECORD_SAMPLE) {
if (evsel->core.attr.sample_id_all)
perf_evsel__parse_id_sample(evsel, event, data);
if (evsel->core.attr.sample_id_all) {
if (perf_evsel__parse_id_sample(event, data))
goto out_efault;
}
return 0;
}
@ -3614,12 +3626,13 @@ int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event,
if (event->header.type != PERF_RECORD_SAMPLE) {
struct perf_sample data = {
.evsel = evsel,
.time = -1ULL,
};
if (!evsel->core.attr.sample_id_all)
return -1;
if (perf_evsel__parse_id_sample(evsel, event, &data))
if (perf_evsel__parse_id_sample(event, &data))
return -1;
*timestamp = data.time;