* [PATCH v1 00/25] perf tool: Add evsel to perf_sample
@ 2026-02-09 17:40 Ian Rogers
2026-02-09 17:40 ` [PATCH v1 01/25] perf sample: Document struct perf_sample Ian Rogers
` (27 more replies)
0 siblings, 28 replies; 112+ messages in thread
From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev,
Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov,
Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones,
Anup Patel, Dapeng Mi, Dr. David Alan Gilbert,
Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria,
Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users,
linux-kernel
Nearly all perf code ends up passing an evsel with the perf_sample,
which is problematic if you want to rewrite the evsel such as with
off-CPU processing - all uses of the evsel need fixing up. Previously
I'd mailed this patch as an RFC with everything combined:
https://lore.kernel.org/lkml/20260126071822.447368-1-irogers@google.com/
and there was a request to break it up.
I've started the series by adding documentation to struct
perf_sample. Next I fixed missing perf_sample__init/exit largely from
the recent perf inject callchain rewriting work. The 3rd patch adds
the evsel to struct perf_sample and ensures it is correctly
initialized. The next 22 patches avoid passing the evsel along with
sample for different parts of the perf tool, along with some minor
tweaks like constification and not determining the evsel if it is
present in the sample.
Ian Rogers (25):
perf sample: Document struct perf_sample
perf sample: Make sure perf_sample__init/exit are used
perf sample: Add evsel to struct perf_sample
perf tool: Remove evsel from tool APIs that pass the sample
perf kvm: Don't pass evsel with sample
perf evsel: Refactor evsel__intval to perf_sample__intval
perf trace: Don't pass evsel with sample
perf callchain: Don't pass evsel and sample
perf lock: Only pass sample to handlers
perf lock: Constify trace_lock_handler variables
perf hist: Remove evsel parameter from inc samples functions
perf db-export: Remove evsel from struct export_sample
perf hist: Remove evsel from struct hist_entry_iter
perf report: Directly use sample->evsel to avoid computing from
sample->id
perf annotate: Don't pass evsel to add_sample
perf inject: Don't pass evsel with sample
perf kmem: Don't pass evsel with sample
perf kwork: Don't pass evsel with sample
perf sched: Don't pass evsel with sample
perf timechart: Don't pass evsel with sample
perf trace: Don't pass evsel with sample
perf evlist: Try to avoid computing evsel from sample
perf script: Don't pass evsel with sample
perf s390-sample-raw: Don't pass evsel with sample
perf evsel: Don't pass evsel with sample
tools/perf/builtin-annotate.c | 28 ++-
tools/perf/builtin-c2c.c | 6 +-
tools/perf/builtin-diff.c | 5 +-
tools/perf/builtin-inject.c | 81 ++++----
tools/perf/builtin-kmem.c | 58 +++---
tools/perf/builtin-kvm.c | 22 +--
tools/perf/builtin-kwork.c | 104 ++++------
tools/perf/builtin-lock.c | 117 +++++------
tools/perf/builtin-mem.c | 1 -
tools/perf/builtin-record.c | 3 +-
tools/perf/builtin-report.c | 38 ++--
tools/perf/builtin-sched.c | 183 ++++++++----------
tools/perf/builtin-script.c | 26 ++-
tools/perf/builtin-timechart.c | 76 +++-----
tools/perf/builtin-top.c | 19 +-
tools/perf/builtin-trace.c | 103 +++++-----
tools/perf/tests/hists_cumulate.c | 3 +-
tools/perf/tests/hists_filter.c | 2 +-
tools/perf/tests/hists_output.c | 3 +-
tools/perf/tests/mmap-basic.c | 4 +-
tools/perf/tests/openat-syscall-tp-fields.c | 2 +-
tools/perf/tests/switch-tracking.c | 9 +-
tools/perf/util/annotate.c | 19 +-
tools/perf/util/annotate.h | 6 +-
tools/perf/util/build-id.c | 3 +-
tools/perf/util/build-id.h | 7 +-
tools/perf/util/callchain.c | 8 +-
tools/perf/util/callchain.h | 5 +-
tools/perf/util/data-convert-bt.c | 2 +-
tools/perf/util/data-convert-json.c | 5 +-
tools/perf/util/db-export.c | 13 +-
tools/perf/util/db-export.h | 3 +-
tools/perf/util/evsel.c | 60 +++---
tools/perf/util/evsel.h | 12 +-
tools/perf/util/hist.c | 26 +--
tools/perf/util/hist.h | 3 +-
tools/perf/util/intel-pt.c | 12 +-
tools/perf/util/intel-tpebs.c | 3 +-
tools/perf/util/jitdump.c | 2 +-
.../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 19 +-
.../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 +-
.../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 +-
.../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 17 +-
tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +-
tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 +++----
tools/perf/util/kvm-stat.c | 19 +-
tools/perf/util/kvm-stat.h | 18 +-
tools/perf/util/kwork.h | 9 +-
tools/perf/util/machine.c | 14 +-
tools/perf/util/machine.h | 3 -
tools/perf/util/s390-sample-raw.c | 15 +-
tools/perf/util/sample.c | 8 +-
tools/perf/util/sample.h | 93 ++++++++-
.../util/scripting-engines/trace-event-perl.c | 23 +--
.../scripting-engines/trace-event-python.c | 47 ++---
tools/perf/util/session.c | 74 ++++---
tools/perf/util/synthetic-events.c | 9 +-
tools/perf/util/synthetic-events.h | 2 -
tools/perf/util/tool.c | 4 +-
tools/perf/util/tool.h | 4 +-
tools/perf/util/trace-event-scripting.c | 5 +-
tools/perf/util/trace-event.h | 3 -
62 files changed, 769 insertions(+), 823 deletions(-)
--
2.53.0.239.g8d8fc8a987-goog
^ permalink raw reply [flat|nested] 112+ messages in thread* [PATCH v1 01/25] perf sample: Document struct perf_sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-03-03 3:07 ` Namhyung Kim 2026-02-09 17:40 ` [PATCH v1 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers ` (26 subsequent siblings) 27 siblings, 1 reply; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel Add kernel-doc for struct perf_sample capturing the somewhat unusual population of fields and lifetime relationships. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/sample.h | 90 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 3cce8dd202aa..3fd2a5e01308 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -81,47 +81,131 @@ struct simd_flags { #define SIMD_OP_FLAGS_PRED_PARTIAL 0x01 /* partial predicate */ #define SIMD_OP_FLAGS_PRED_EMPTY 0x02 /* empty predicate */ +/** + * struct perf_sample + * + * A sample is generally filled in by evlist__parse_sample/evsel__parse_sample + * which fills in the variables from a "union perf_event *event" which is data + * from a perf ring buffer or perf.data file. The "event" sample is variable in + * length as determined by the perf_event_attr (in the evsel) and details within + * the sample event itself. A struct perf_sample avoids needing to care about + * the variable length nature of the original event. + * + * To avoid being excessively large parts of the struct perf_sample are pointers + * into the original sample event. In general the lifetime of a struct + * perf_sample needs to be less than the "union perf_event *event" it was + * derived from. + * + * The struct regs_dump user_regs and intr_regs are lazily allocated again for + * size reasons, due to them holding a cache of looked up registers. The + * function pair of perf_sample__init and perf_sample__exit correctly initialize + * and clean up these values. + */ struct perf_sample { + /** @ip: The sample event PERF_SAMPLE_IP value. */ u64 ip; - u32 pid, tid; + /** @pid: The sample event PERF_SAMPLE_TID pid value. */ + u32 pid; + /** @tid: The sample event PERF_SAMPLE_TID tid value. */ + u32 tid; + /** @time: The sample event PERF_SAMPLE_TIME value. */ u64 time; + /** @addr: The sample event PERF_SAMPLE_ADDR value. */ u64 addr; + /** @id: The sample event PERF_SAMPLE_ID value. */ u64 id; + /** @stream_id: The sample event PERF_SAMPLE_STREAM_ID value. */ u64 stream_id; + /** @period: The sample event PERF_SAMPLE_PERIOD value. */ u64 period; + /** @weight: Data determined by PERF_SAMPLE_WEIGHT or PERF_SAMPLE_WEIGHT_STRUCT. */ u64 weight; + /** @transaction: The sample event PERF_SAMPLE_TRANSACTION value. */ u64 transaction; + /** @insn_cnt: Filled in and used by intel-pt. */ u64 insn_cnt; + /** @cyc_cnt: Filled in and used by intel-pt. */ u64 cyc_cnt; + /** @cpu: The sample event PERF_SAMPLE_CPU value. */ u32 cpu; + /** + * @raw_size: The size in bytes of raw data from PERF_SAMPLE_RAW. For + * alignment reasons this should always be a multiple of + * sizeof(u64) + sizeof(u32). + */ u32 raw_size; + /** @data_src: The sample event PERF_SAMPLE_DATA_SRC value. */ u64 data_src; + /** @phys_addr: The sample event PERF_SAMPLE_PHYS_ADDR value. */ u64 phys_addr; + /** @data_page_size: The sample event PERF_SAMPLE_DATA_PAGE_SIZE value. */ u64 data_page_size; + /** @code_page_size: The sample event PERF_SAMPLE_CODE_PAGE_SIZE value. */ u64 code_page_size; + /** @cgroup: The sample event PERF_SAMPLE_CGROUP value. */ u64 cgroup; + /** @flags: Extra flag data from auxiliary events like intel-pt. */ u32 flags; + /** @machine_pid: The guest machine pid derived from the sample id. */ u32 machine_pid; + /** @vcpu: The guest machine vcpu derived from the sample id. */ u32 vcpu; + /** @insn_len: Instruction length from auxiliary events like intel-pt. */ u16 insn_len; + /** + * @cpumode: The cpumode from struct perf_event_header misc variable + * masked with CPUMODE_MASK. Gives user, kernel and hypervisor + * information. + */ u8 cpumode; + /** @misc: The entire struct perf_event_header misc variable. */ u16 misc; + /** @ins_lat: Instruction latency information from auxiliary events like intel-pt. */ u16 ins_lat; /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */ u16 weight3; - bool no_hw_idx; /* No hw_idx collected in branch_stack */ - bool deferred_callchain; /* Has deferred user callchains */ + /** + * @no_hw_idx: For PERF_SAMPLE_BRANCH_STACK, true when + * PERF_SAMPLE_BRANCH_HW_INDEX isn't set. + */ + bool no_hw_idx; + /** + * @deferred_callchain: When processing PERF_SAMPLE_CALLCHAIN a deferred + * user callchain marker was encountered. + */ + bool deferred_callchain; + /** + * @deferred_cookie: Identifier of the deferred callchain in the later + * PERF_RECORD_CALLCHAIN_DEFERRED event. + */ u64 deferred_cookie; + /** @insn: A copy of the sampled instruction filled in by perf_sample__fetch_insn. */ char insn[MAX_INSN]; + /** @raw_data: Byte aligned pointer into the original event for PERF_SAMPLE_RAW data. */ void *raw_data; + /** @callchain: Pointer into the original event for PERF_SAMPLE_CALLCHAIN data. */ struct ip_callchain *callchain; + /** @branch_stack: Pointer into the original event for PERF_SAMPLE_BRANCH_STACK data. */ struct branch_stack *branch_stack; + /** + * @branch_stack_cntr: Pointer into the original event for + * PERF_SAMPLE_BRANCH_COUNTERS data. + */ u64 *branch_stack_cntr; + /** @user_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_USER. */ struct regs_dump *user_regs; + /** @intr_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_INTR. */ struct regs_dump *intr_regs; + /** @user_stack: Size and pointer into the sample for PERF_SAMPLE_STACK_USER. */ struct stack_dump user_stack; + /** @read: The sample event PERF_SAMPLE_READ counter values. */ struct sample_read read; + /** + * @aux_sample: Similar to raw data but with a 64-bit size and + * alignment, PERF_SAMPLE_AUX data. + */ struct aux_sample aux_sample; + /** @simd_flags: SIMD flag information from ARM SPE auxiliary events. */ struct simd_flags simd_flags; }; -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* Re: [PATCH v1 01/25] perf sample: Document struct perf_sample 2026-02-09 17:40 ` [PATCH v1 01/25] perf sample: Document struct perf_sample Ian Rogers @ 2026-03-03 3:07 ` Namhyung Kim 2026-03-20 4:41 ` Ian Rogers 0 siblings, 1 reply; 112+ messages in thread From: Namhyung Kim @ 2026-03-03 3:07 UTC (permalink / raw) To: Ian Rogers Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel On Mon, Feb 09, 2026 at 09:40:08AM -0800, Ian Rogers wrote: > Add kernel-doc for struct perf_sample capturing the somewhat unusual > population of fields and lifetime relationships. Thanks for doing this. > > Signed-off-by: Ian Rogers <irogers@google.com> > --- > tools/perf/util/sample.h | 90 ++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 87 insertions(+), 3 deletions(-) > > diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h > index 3cce8dd202aa..3fd2a5e01308 100644 > --- a/tools/perf/util/sample.h > +++ b/tools/perf/util/sample.h > @@ -81,47 +81,131 @@ struct simd_flags { > #define SIMD_OP_FLAGS_PRED_PARTIAL 0x01 /* partial predicate */ > #define SIMD_OP_FLAGS_PRED_EMPTY 0x02 /* empty predicate */ > > +/** > + * struct perf_sample > + * > + * A sample is generally filled in by evlist__parse_sample/evsel__parse_sample > + * which fills in the variables from a "union perf_event *event" which is data > + * from a perf ring buffer or perf.data file. The "event" sample is variable in > + * length as determined by the perf_event_attr (in the evsel) and details within > + * the sample event itself. A struct perf_sample avoids needing to care about > + * the variable length nature of the original event. > + * > + * To avoid being excessively large parts of the struct perf_sample are pointers > + * into the original sample event. In general the lifetime of a struct > + * perf_sample needs to be less than the "union perf_event *event" it was > + * derived from. > + * > + * The struct regs_dump user_regs and intr_regs are lazily allocated again for > + * size reasons, due to them holding a cache of looked up registers. The > + * function pair of perf_sample__init and perf_sample__exit correctly initialize > + * and clean up these values. > + */ > struct perf_sample { > + /** @ip: The sample event PERF_SAMPLE_IP value. */ > u64 ip; > - u32 pid, tid; > + /** @pid: The sample event PERF_SAMPLE_TID pid value. */ > + u32 pid; > + /** @tid: The sample event PERF_SAMPLE_TID tid value. */ > + u32 tid; > + /** @time: The sample event PERF_SAMPLE_TIME value. */ > u64 time; > + /** @addr: The sample event PERF_SAMPLE_ADDR value. */ > u64 addr; > + /** @id: The sample event PERF_SAMPLE_ID value. */ > u64 id; > + /** @stream_id: The sample event PERF_SAMPLE_STREAM_ID value. */ > u64 stream_id; > + /** @period: The sample event PERF_SAMPLE_PERIOD value. */ > u64 period; > + /** @weight: Data determined by PERF_SAMPLE_WEIGHT or PERF_SAMPLE_WEIGHT_STRUCT. */ > u64 weight; > + /** @transaction: The sample event PERF_SAMPLE_TRANSACTION value. */ > u64 transaction; > + /** @insn_cnt: Filled in and used by intel-pt. */ > u64 insn_cnt; > + /** @cyc_cnt: Filled in and used by intel-pt. */ > u64 cyc_cnt; > + /** @cpu: The sample event PERF_SAMPLE_CPU value. */ > u32 cpu; > + /** > + * @raw_size: The size in bytes of raw data from PERF_SAMPLE_RAW. For > + * alignment reasons this should always be a multiple of > + * sizeof(u64) + sizeof(u32). > + */ > u32 raw_size; > + /** @data_src: The sample event PERF_SAMPLE_DATA_SRC value. */ > u64 data_src; > + /** @phys_addr: The sample event PERF_SAMPLE_PHYS_ADDR value. */ > u64 phys_addr; > + /** @data_page_size: The sample event PERF_SAMPLE_DATA_PAGE_SIZE value. */ > u64 data_page_size; > + /** @code_page_size: The sample event PERF_SAMPLE_CODE_PAGE_SIZE value. */ > u64 code_page_size; > + /** @cgroup: The sample event PERF_SAMPLE_CGROUP value. */ > u64 cgroup; > + /** @flags: Extra flag data from auxiliary events like intel-pt. */ > u32 flags; > + /** @machine_pid: The guest machine pid derived from the sample id. */ > u32 machine_pid; > + /** @vcpu: The guest machine vcpu derived from the sample id. */ > u32 vcpu; > + /** @insn_len: Instruction length from auxiliary events like intel-pt. */ > u16 insn_len; Does it control the insn array later? > + /** > + * @cpumode: The cpumode from struct perf_event_header misc variable > + * masked with CPUMODE_MASK. Gives user, kernel and hypervisor > + * information. > + */ > u8 cpumode; > + /** @misc: The entire struct perf_event_header misc variable. */ > u16 misc; > + /** @ins_lat: Instruction latency information from auxiliary events like intel-pt. */ > u16 ins_lat; I think this is weight2 coming from PERF_SAMPLE_WEIGHT_STRUCT. > /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */ > u16 weight3; You may also want to mention it's from WEIGHT_STRUCT. > - bool no_hw_idx; /* No hw_idx collected in branch_stack */ > - bool deferred_callchain; /* Has deferred user callchains */ > + /** > + * @no_hw_idx: For PERF_SAMPLE_BRANCH_STACK, true when > + * PERF_SAMPLE_BRANCH_HW_INDEX isn't set. > + */ > + bool no_hw_idx; > + /** > + * @deferred_callchain: When processing PERF_SAMPLE_CALLCHAIN a deferred > + * user callchain marker was encountered. > + */ > + bool deferred_callchain; If this is set, then callchain entry is allocated for deferred callchains. > + /** > + * @deferred_cookie: Identifier of the deferred callchain in the later > + * PERF_RECORD_CALLCHAIN_DEFERRED event. > + */ > u64 deferred_cookie; > + /** @insn: A copy of the sampled instruction filled in by perf_sample__fetch_insn. */ > char insn[MAX_INSN]; > + /** @raw_data: Byte aligned pointer into the original event for PERF_SAMPLE_RAW data. */ I think it's 32-bit aligned (or shifted) as it comes right after the raw_size (32-bit). As other fields in the event are 64-bit aligned this caused some troubles like in perf trace when you access the pointer directly and assume it's naturally aligned. > void *raw_data; > + /** @callchain: Pointer into the original event for PERF_SAMPLE_CALLCHAIN data. */ > struct ip_callchain *callchain; If deferred_callchain is not set, it just points to data in the mmap buffer and it should not be freed. > + /** @branch_stack: Pointer into the original event for PERF_SAMPLE_BRANCH_STACK data. */ > struct branch_stack *branch_stack; > + /** > + * @branch_stack_cntr: Pointer into the original event for > + * PERF_SAMPLE_BRANCH_COUNTERS data. > + */ > u64 *branch_stack_cntr; > + /** @user_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_USER. */ > struct regs_dump *user_regs; > + /** @intr_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_INTR. */ > struct regs_dump *intr_regs; > + /** @user_stack: Size and pointer into the sample for PERF_SAMPLE_STACK_USER. */ > struct stack_dump user_stack; > + /** @read: The sample event PERF_SAMPLE_READ counter values. */ The actual format depends on read_format in the event attribute. Thanks, Namhyung > struct sample_read read; > + /** > + * @aux_sample: Similar to raw data but with a 64-bit size and > + * alignment, PERF_SAMPLE_AUX data. > + */ > struct aux_sample aux_sample; > + /** @simd_flags: SIMD flag information from ARM SPE auxiliary events. */ > struct simd_flags simd_flags; > }; > > -- > 2.53.0.239.g8d8fc8a987-goog > ^ permalink raw reply [flat|nested] 112+ messages in thread
* Re: [PATCH v1 01/25] perf sample: Document struct perf_sample 2026-03-03 3:07 ` Namhyung Kim @ 2026-03-20 4:41 ` Ian Rogers 0 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 4:41 UTC (permalink / raw) To: Namhyung Kim Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel On Mon, Mar 2, 2026 at 7:07 PM Namhyung Kim <namhyung@kernel.org> wrote: > > On Mon, Feb 09, 2026 at 09:40:08AM -0800, Ian Rogers wrote: > > Add kernel-doc for struct perf_sample capturing the somewhat unusual > > population of fields and lifetime relationships. > > Thanks for doing this. > > > > > Signed-off-by: Ian Rogers <irogers@google.com> > > --- > > tools/perf/util/sample.h | 90 ++++++++++++++++++++++++++++++++++++++-- > > 1 file changed, 87 insertions(+), 3 deletions(-) > > > > diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h > > index 3cce8dd202aa..3fd2a5e01308 100644 > > --- a/tools/perf/util/sample.h > > +++ b/tools/perf/util/sample.h > > @@ -81,47 +81,131 @@ struct simd_flags { > > #define SIMD_OP_FLAGS_PRED_PARTIAL 0x01 /* partial predicate */ > > #define SIMD_OP_FLAGS_PRED_EMPTY 0x02 /* empty predicate */ > > > > +/** > > + * struct perf_sample > > + * > > + * A sample is generally filled in by evlist__parse_sample/evsel__parse_sample > > + * which fills in the variables from a "union perf_event *event" which is data > > + * from a perf ring buffer or perf.data file. The "event" sample is variable in > > + * length as determined by the perf_event_attr (in the evsel) and details within > > + * the sample event itself. A struct perf_sample avoids needing to care about > > + * the variable length nature of the original event. > > + * > > + * To avoid being excessively large parts of the struct perf_sample are pointers > > + * into the original sample event. In general the lifetime of a struct > > + * perf_sample needs to be less than the "union perf_event *event" it was > > + * derived from. > > + * > > + * The struct regs_dump user_regs and intr_regs are lazily allocated again for > > + * size reasons, due to them holding a cache of looked up registers. The > > + * function pair of perf_sample__init and perf_sample__exit correctly initialize > > + * and clean up these values. > > + */ > > struct perf_sample { > > + /** @ip: The sample event PERF_SAMPLE_IP value. */ > > u64 ip; > > - u32 pid, tid; > > + /** @pid: The sample event PERF_SAMPLE_TID pid value. */ > > + u32 pid; > > + /** @tid: The sample event PERF_SAMPLE_TID tid value. */ > > + u32 tid; > > + /** @time: The sample event PERF_SAMPLE_TIME value. */ > > u64 time; > > + /** @addr: The sample event PERF_SAMPLE_ADDR value. */ > > u64 addr; > > + /** @id: The sample event PERF_SAMPLE_ID value. */ > > u64 id; > > + /** @stream_id: The sample event PERF_SAMPLE_STREAM_ID value. */ > > u64 stream_id; > > + /** @period: The sample event PERF_SAMPLE_PERIOD value. */ > > u64 period; > > + /** @weight: Data determined by PERF_SAMPLE_WEIGHT or PERF_SAMPLE_WEIGHT_STRUCT. */ > > u64 weight; > > + /** @transaction: The sample event PERF_SAMPLE_TRANSACTION value. */ > > u64 transaction; > > + /** @insn_cnt: Filled in and used by intel-pt. */ > > u64 insn_cnt; > > + /** @cyc_cnt: Filled in and used by intel-pt. */ > > u64 cyc_cnt; > > + /** @cpu: The sample event PERF_SAMPLE_CPU value. */ > > u32 cpu; > > + /** > > + * @raw_size: The size in bytes of raw data from PERF_SAMPLE_RAW. For > > + * alignment reasons this should always be a multiple of > > + * sizeof(u64) + sizeof(u32). > > + */ > > u32 raw_size; > > + /** @data_src: The sample event PERF_SAMPLE_DATA_SRC value. */ > > u64 data_src; > > + /** @phys_addr: The sample event PERF_SAMPLE_PHYS_ADDR value. */ > > u64 phys_addr; > > + /** @data_page_size: The sample event PERF_SAMPLE_DATA_PAGE_SIZE value. */ > > u64 data_page_size; > > + /** @code_page_size: The sample event PERF_SAMPLE_CODE_PAGE_SIZE value. */ > > u64 code_page_size; > > + /** @cgroup: The sample event PERF_SAMPLE_CGROUP value. */ > > u64 cgroup; > > + /** @flags: Extra flag data from auxiliary events like intel-pt. */ > > u32 flags; > > + /** @machine_pid: The guest machine pid derived from the sample id. */ > > u32 machine_pid; > > + /** @vcpu: The guest machine vcpu derived from the sample id. */ > > u32 vcpu; > > + /** @insn_len: Instruction length from auxiliary events like intel-pt. */ > > u16 insn_len; > > Does it control the insn array later? > > > > + /** > > + * @cpumode: The cpumode from struct perf_event_header misc variable > > + * masked with CPUMODE_MASK. Gives user, kernel and hypervisor > > + * information. > > + */ > > u8 cpumode; > > + /** @misc: The entire struct perf_event_header misc variable. */ > > u16 misc; > > + /** @ins_lat: Instruction latency information from auxiliary events like intel-pt. */ > > u16 ins_lat; > > I think this is weight2 coming from PERF_SAMPLE_WEIGHT_STRUCT. > > > > /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */ > > u16 weight3; > > You may also want to mention it's from WEIGHT_STRUCT. > > > > - bool no_hw_idx; /* No hw_idx collected in branch_stack */ > > - bool deferred_callchain; /* Has deferred user callchains */ > > + /** > > + * @no_hw_idx: For PERF_SAMPLE_BRANCH_STACK, true when > > + * PERF_SAMPLE_BRANCH_HW_INDEX isn't set. > > + */ > > + bool no_hw_idx; > > + /** > > + * @deferred_callchain: When processing PERF_SAMPLE_CALLCHAIN a deferred > > + * user callchain marker was encountered. > > + */ > > + bool deferred_callchain; > > If this is set, then callchain entry is allocated for deferred > callchains. So when deferred_callchain is set this isn't true. The callchain points into the event: https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/evsel.c?h=perf-tools-next#n3384 > > > > + /** > > + * @deferred_cookie: Identifier of the deferred callchain in the later > > + * PERF_RECORD_CALLCHAIN_DEFERRED event. > > + */ > > u64 deferred_cookie; > > + /** @insn: A copy of the sampled instruction filled in by perf_sample__fetch_insn. */ > > char insn[MAX_INSN]; > > + /** @raw_data: Byte aligned pointer into the original event for PERF_SAMPLE_RAW data. */ > > I think it's 32-bit aligned (or shifted) as it comes right after the > raw_size (32-bit). As other fields in the event are 64-bit aligned this > caused some troubles like in perf trace when you access the pointer > directly and assume it's naturally aligned. > > > > void *raw_data; > > + /** @callchain: Pointer into the original event for PERF_SAMPLE_CALLCHAIN data. */ > > struct ip_callchain *callchain; > > If deferred_callchain is not set, it just points to data in the mmap > buffer and it should not be freed. But if deferred_callchain is set this may also be true. Sashiko is picking up on the inconsistencies. I'll weasel word it by referring to the sample__merge_deferred_callchain function. Thanks, Ian > > + /** @branch_stack: Pointer into the original event for PERF_SAMPLE_BRANCH_STACK data. */ > > struct branch_stack *branch_stack; > > + /** > > + * @branch_stack_cntr: Pointer into the original event for > > + * PERF_SAMPLE_BRANCH_COUNTERS data. > > + */ > > u64 *branch_stack_cntr; > > + /** @user_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_USER. */ > > struct regs_dump *user_regs; > > + /** @intr_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_INTR. */ > > struct regs_dump *intr_regs; > > + /** @user_stack: Size and pointer into the sample for PERF_SAMPLE_STACK_USER. */ > > struct stack_dump user_stack; > > + /** @read: The sample event PERF_SAMPLE_READ counter values. */ > > The actual format depends on read_format in the event attribute. > > Thanks, > Namhyung > > > > struct sample_read read; > > + /** > > + * @aux_sample: Similar to raw data but with a 64-bit size and > > + * alignment, PERF_SAMPLE_AUX data. > > + */ > > struct aux_sample aux_sample; > > + /** @simd_flags: SIMD flag information from ARM SPE auxiliary events. */ > > struct simd_flags simd_flags; > > }; > > > > -- > > 2.53.0.239.g8d8fc8a987-goog > > ^ permalink raw reply [flat|nested] 112+ messages in thread
* [PATCH v1 02/25] perf sample: Make sure perf_sample__init/exit are used 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 01/25] perf sample: Document struct perf_sample Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-03-03 22:38 ` Namhyung Kim 2026-02-09 17:40 ` [PATCH v1 03/25] perf sample: Add evsel to struct perf_sample Ian Rogers ` (25 subsequent siblings) 27 siblings, 1 reply; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The deferred stack trace code wasn't using perf_sample__init/exit. Add the deferred stack trace clean up to perf_sample__exit which requires proper NULL initialization in perf_sample__init. Make the perf_sample__exit robust to being called more than once by using zfree. Make the error paths in evsel__parse_sample exit the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 6 +++++- tools/perf/util/evsel.c | 28 +++++++++++++++++----------- tools/perf/util/sample.c | 8 ++++++-- tools/perf/util/session.c | 13 +++++++++---- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 5b29f4296861..3d2556213599 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1087,6 +1087,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, struct perf_sample sample_sw; struct perf_inject *inject = container_of(tool, struct perf_inject, tool); u32 pid = evsel__intval(evsel, sample, "pid"); + int ret; list_for_each_entry(ent, &inject->samples, node) { if (pid == ent->tid) @@ -1098,12 +1099,15 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, event_sw = &ent->event[0]; evsel__parse_sample(evsel, event_sw, &sample_sw); + perf_sample__init(&sample_sw, /*all=*/false); sample_sw.period = sample->period; sample_sw.time = sample->time; perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, evsel->core.attr.read_format, &sample_sw); build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); - return perf_event__repipe(tool, event_sw, &sample_sw, machine); + ret = perf_event__repipe(tool, event_sw, &sample_sw, machine); + perf_sample__exit(&sample_sw); + return ret; } #endif diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f59228c1a39e..34ae388750db 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3067,7 +3067,7 @@ static inline bool overflow(const void *endp, u16 max_size, const void *offset, #define OVERFLOW_CHECK(offset, size, max_size) \ do { \ if (overflow(endp, (max_size), (offset), (size))) \ - return -EFAULT; \ + goto out_efault; \ } while (0) #define OVERFLOW_CHECK_u64(offset) \ @@ -3199,6 +3199,8 @@ static int __set_offcpu_sample(struct perf_sample *data) data->cgroup = *array; return 0; +out_efault: + return -EFAULT; } int evsel__parse_sample(struct evsel *evsel, union perf_event *event, @@ -3217,7 +3219,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, */ union u64_swap u; - memset(data, 0, sizeof(*data)); + perf_sample__init(data, /*all=*/true); data->cpu = data->pid = data->tid = -1; data->stream_id = data->id = data->time = -1ULL; data->period = evsel->core.attr.sample_period; @@ -3231,25 +3233,26 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->callchain = (struct ip_callchain *)&event->callchain_deferred.nr; if (data->callchain->nr > max_callchain_nr) - return -EFAULT; + goto out_efault; data->deferred_cookie = event->callchain_deferred.cookie; if (evsel->core.attr.sample_id_all) perf_evsel__parse_id_sample(evsel, event, data); + return 0; } if (event->header.type != PERF_RECORD_SAMPLE) { - if (!evsel->core.attr.sample_id_all) - return 0; - return perf_evsel__parse_id_sample(evsel, event, data); + if (evsel->core.attr.sample_id_all) + perf_evsel__parse_id_sample(evsel, event, data); + return 0; } array = event->sample.array; if (perf_event__check_size(event, evsel->sample_size)) - return -EFAULT; + goto out_efault; if (type & PERF_SAMPLE_IDENTIFIER) { data->id = *array; @@ -3342,7 +3345,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, sizeof(struct sample_read_value); if (data->read.group.nr > max_group_nr) - return -EFAULT; + goto out_efault; sz = data->read.group.nr * sample_read_value_size(read_format); OVERFLOW_CHECK(array, sz, max_size); @@ -3370,7 +3373,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->callchain = (struct ip_callchain *)array++; callchain_nr = data->callchain->nr; if (callchain_nr > max_callchain_nr) - return -EFAULT; + goto out_efault; sz = callchain_nr * sizeof(u64); /* * Save the cookie for the deferred user callchain. The last 2 @@ -3428,7 +3431,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->branch_stack = (struct branch_stack *)array++; if (data->branch_stack->nr > max_branch_nr) - return -EFAULT; + goto out_efault; sz = data->branch_stack->nr * sizeof(struct branch_entry); if (evsel__has_branch_hw_idx(evsel)) { @@ -3505,7 +3508,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->user_stack.size = *array++; if (WARN_ONCE(data->user_stack.size > sz, "user stack dump failure\n")) - return -EFAULT; + goto out_efault; } } @@ -3586,6 +3589,9 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, return __set_offcpu_sample(data); return 0; +out_efault: + perf_sample__exit(data); + return -EFAULT; } int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event, diff --git a/tools/perf/util/sample.c b/tools/perf/util/sample.c index 8f82aaf1aab6..4894b990c6ce 100644 --- a/tools/perf/util/sample.c +++ b/tools/perf/util/sample.c @@ -21,13 +21,17 @@ void perf_sample__init(struct perf_sample *sample, bool all) } else { sample->user_regs = NULL; sample->intr_regs = NULL; + sample->deferred_callchain = false; + sample->callchain = NULL; } } void perf_sample__exit(struct perf_sample *sample) { - free(sample->user_regs); - free(sample->intr_regs); + zfree(&sample->user_regs); + zfree(&sample->intr_regs); + if (sample->deferred_callchain) + zfree(&sample->callchain); } struct regs_dump *perf_sample__user_regs(struct perf_sample *sample) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 4b465abfa36c..c48e840da7d4 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1367,14 +1367,18 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { struct perf_sample orig_sample; + perf_sample__init(&orig_sample, /*all=*/false); ret = evlist__parse_sample(evlist, de->event, &orig_sample); if (ret < 0) { pr_err("failed to parse original sample\n"); + perf_sample__exit(&orig_sample); break; } - if (sample->tid != orig_sample.tid) + if (sample->tid != orig_sample.tid) { + perf_sample__exit(&orig_sample); continue; + } if (event->callchain_deferred.cookie == orig_sample.deferred_cookie) sample__merge_deferred_callchain(&orig_sample, sample); @@ -1385,9 +1389,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, ret = evlist__deliver_sample(evlist, tool, de->event, &orig_sample, evsel, machine); - if (orig_sample.deferred_callchain) - free(orig_sample.callchain); - + perf_sample__exit(&orig_sample); list_del(&de->list); free(de->event); free(de); @@ -1414,9 +1416,11 @@ static int session__flush_deferred_samples(struct perf_session *session, list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { struct perf_sample sample; + perf_sample__init(&sample, /*all=*/false); ret = evlist__parse_sample(evlist, de->event, &sample); if (ret < 0) { pr_err("failed to parse original sample\n"); + perf_sample__exit(&sample); break; } @@ -1424,6 +1428,7 @@ static int session__flush_deferred_samples(struct perf_session *session, ret = evlist__deliver_sample(evlist, tool, de->event, &sample, evsel, machine); + perf_sample__exit(&sample); list_del(&de->list); free(de->event); free(de); -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* Re: [PATCH v1 02/25] perf sample: Make sure perf_sample__init/exit are used 2026-02-09 17:40 ` [PATCH v1 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers @ 2026-03-03 22:38 ` Namhyung Kim 0 siblings, 0 replies; 112+ messages in thread From: Namhyung Kim @ 2026-03-03 22:38 UTC (permalink / raw) To: Ian Rogers Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel On Mon, Feb 09, 2026 at 09:40:09AM -0800, Ian Rogers wrote: > The deferred stack trace code wasn't using perf_sample__init/exit. Add > the deferred stack trace clean up to perf_sample__exit which requires > proper NULL initialization in perf_sample__init. Make the > perf_sample__exit robust to being called more than once by using > zfree. Make the error paths in evsel__parse_sample exit the sample. > > Signed-off-by: Ian Rogers <irogers@google.com> > --- > tools/perf/builtin-inject.c | 6 +++++- > tools/perf/util/evsel.c | 28 +++++++++++++++++----------- > tools/perf/util/sample.c | 8 ++++++-- > tools/perf/util/session.c | 13 +++++++++---- > 4 files changed, 37 insertions(+), 18 deletions(-) > > diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c > index 5b29f4296861..3d2556213599 100644 > --- a/tools/perf/builtin-inject.c > +++ b/tools/perf/builtin-inject.c > @@ -1087,6 +1087,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, > struct perf_sample sample_sw; > struct perf_inject *inject = container_of(tool, struct perf_inject, tool); > u32 pid = evsel__intval(evsel, sample, "pid"); > + int ret; > > list_for_each_entry(ent, &inject->samples, node) { > if (pid == ent->tid) > @@ -1098,12 +1099,15 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, > event_sw = &ent->event[0]; > evsel__parse_sample(evsel, event_sw, &sample_sw); > > + perf_sample__init(&sample_sw, /*all=*/false); Shouldn't it be called before evsel__parse_sample()? > sample_sw.period = sample->period; > sample_sw.time = sample->time; > perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, > evsel->core.attr.read_format, &sample_sw); > build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); > - return perf_event__repipe(tool, event_sw, &sample_sw, machine); > + ret = perf_event__repipe(tool, event_sw, &sample_sw, machine); > + perf_sample__exit(&sample_sw); > + return ret; > } > #endif > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index f59228c1a39e..34ae388750db 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -3067,7 +3067,7 @@ static inline bool overflow(const void *endp, u16 max_size, const void *offset, > #define OVERFLOW_CHECK(offset, size, max_size) \ > do { \ > if (overflow(endp, (max_size), (offset), (size))) \ > - return -EFAULT; \ > + goto out_efault; \ > } while (0) > > #define OVERFLOW_CHECK_u64(offset) \ > @@ -3199,6 +3199,8 @@ static int __set_offcpu_sample(struct perf_sample *data) > data->cgroup = *array; > > return 0; > +out_efault: > + return -EFAULT; > } > > int evsel__parse_sample(struct evsel *evsel, union perf_event *event, > @@ -3217,7 +3219,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, > */ > union u64_swap u; > > - memset(data, 0, sizeof(*data)); > + perf_sample__init(data, /*all=*/true); It seems this is called before evlist__parse_sample(), do we need to do it here as well? > data->cpu = data->pid = data->tid = -1; > data->stream_id = data->id = data->time = -1ULL; > data->period = evsel->core.attr.sample_period; > @@ -3231,25 +3233,26 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, > > data->callchain = (struct ip_callchain *)&event->callchain_deferred.nr; > if (data->callchain->nr > max_callchain_nr) > - return -EFAULT; > + goto out_efault; > > data->deferred_cookie = event->callchain_deferred.cookie; > > if (evsel->core.attr.sample_id_all) > perf_evsel__parse_id_sample(evsel, event, data); > + > return 0; > } > > if (event->header.type != PERF_RECORD_SAMPLE) { > - if (!evsel->core.attr.sample_id_all) > - return 0; > - return perf_evsel__parse_id_sample(evsel, event, data); > + if (evsel->core.attr.sample_id_all) > + perf_evsel__parse_id_sample(evsel, event, data); > + return 0; > } > > array = event->sample.array; > > if (perf_event__check_size(event, evsel->sample_size)) > - return -EFAULT; > + goto out_efault; > > if (type & PERF_SAMPLE_IDENTIFIER) { > data->id = *array; > @@ -3342,7 +3345,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, > sizeof(struct sample_read_value); > > if (data->read.group.nr > max_group_nr) > - return -EFAULT; > + goto out_efault; > > sz = data->read.group.nr * sample_read_value_size(read_format); > OVERFLOW_CHECK(array, sz, max_size); > @@ -3370,7 +3373,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, > data->callchain = (struct ip_callchain *)array++; > callchain_nr = data->callchain->nr; > if (callchain_nr > max_callchain_nr) > - return -EFAULT; > + goto out_efault; > sz = callchain_nr * sizeof(u64); > /* > * Save the cookie for the deferred user callchain. The last 2 > @@ -3428,7 +3431,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, > data->branch_stack = (struct branch_stack *)array++; > > if (data->branch_stack->nr > max_branch_nr) > - return -EFAULT; > + goto out_efault; > > sz = data->branch_stack->nr * sizeof(struct branch_entry); > if (evsel__has_branch_hw_idx(evsel)) { > @@ -3505,7 +3508,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, > data->user_stack.size = *array++; > if (WARN_ONCE(data->user_stack.size > sz, > "user stack dump failure\n")) > - return -EFAULT; > + goto out_efault; > } > } > > @@ -3586,6 +3589,9 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, > return __set_offcpu_sample(data); > > return 0; > +out_efault: > + perf_sample__exit(data); > + return -EFAULT; > } > > int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event, > diff --git a/tools/perf/util/sample.c b/tools/perf/util/sample.c > index 8f82aaf1aab6..4894b990c6ce 100644 > --- a/tools/perf/util/sample.c > +++ b/tools/perf/util/sample.c > @@ -21,13 +21,17 @@ void perf_sample__init(struct perf_sample *sample, bool all) > } else { > sample->user_regs = NULL; > sample->intr_regs = NULL; > + sample->deferred_callchain = false; > + sample->callchain = NULL; > } > } > > void perf_sample__exit(struct perf_sample *sample) > { > - free(sample->user_regs); > - free(sample->intr_regs); > + zfree(&sample->user_regs); > + zfree(&sample->intr_regs); > + if (sample->deferred_callchain) > + zfree(&sample->callchain); Nit: maybe better to set deferred_callchain to false. Thanks, Namhyung > } > > struct regs_dump *perf_sample__user_regs(struct perf_sample *sample) > diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c > index 4b465abfa36c..c48e840da7d4 100644 > --- a/tools/perf/util/session.c > +++ b/tools/perf/util/session.c > @@ -1367,14 +1367,18 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, > list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { > struct perf_sample orig_sample; > > + perf_sample__init(&orig_sample, /*all=*/false); > ret = evlist__parse_sample(evlist, de->event, &orig_sample); > if (ret < 0) { > pr_err("failed to parse original sample\n"); > + perf_sample__exit(&orig_sample); > break; > } > > - if (sample->tid != orig_sample.tid) > + if (sample->tid != orig_sample.tid) { > + perf_sample__exit(&orig_sample); > continue; > + } > > if (event->callchain_deferred.cookie == orig_sample.deferred_cookie) > sample__merge_deferred_callchain(&orig_sample, sample); > @@ -1385,9 +1389,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, > ret = evlist__deliver_sample(evlist, tool, de->event, > &orig_sample, evsel, machine); > > - if (orig_sample.deferred_callchain) > - free(orig_sample.callchain); > - > + perf_sample__exit(&orig_sample); > list_del(&de->list); > free(de->event); > free(de); > @@ -1414,9 +1416,11 @@ static int session__flush_deferred_samples(struct perf_session *session, > list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { > struct perf_sample sample; > > + perf_sample__init(&sample, /*all=*/false); > ret = evlist__parse_sample(evlist, de->event, &sample); > if (ret < 0) { > pr_err("failed to parse original sample\n"); > + perf_sample__exit(&sample); > break; > } > > @@ -1424,6 +1428,7 @@ static int session__flush_deferred_samples(struct perf_session *session, > ret = evlist__deliver_sample(evlist, tool, de->event, > &sample, evsel, machine); > > + perf_sample__exit(&sample); > list_del(&de->list); > free(de->event); > free(de); > -- > 2.53.0.239.g8d8fc8a987-goog > ^ permalink raw reply [flat|nested] 112+ messages in thread
* [PATCH v1 03/25] perf sample: Add evsel to struct perf_sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 01/25] perf sample: Document struct perf_sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 04/25] perf tool: Remove evsel from tool APIs that pass the sample Ian Rogers ` (24 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel Add the evsel from evsel__parse_sample into the struct perf_sample. Sometimes we want to alter the evsel associated with a sample, such as with off-cpu bpf-output events. In general the evsel and perf_sample are passed as a pair, but this makes an altered evsel something of a chore to keep checking for and setting up. Later patches will remove passing an evsel with the perf_sample and switch to just using the perf_sample's value. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 10 ++++++--- tools/perf/builtin-script.c | 4 ++++ tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 1 + tools/perf/tests/hists_output.c | 2 +- tools/perf/util/evsel.c | 1 + tools/perf/util/sample.h | 3 +++ tools/perf/util/session.c | 35 +++++++++++++++++++------------ 8 files changed, 40 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 3d2556213599..8ae76bf5253e 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -133,7 +133,7 @@ struct perf_inject { struct perf_file_section secs[HEADER_FEAT_BITS]; struct guest_session guest_session; struct strlist *known_build_ids; - const struct evsel *mmap_evsel; + struct evsel *mmap_evsel; struct ip_callchain *raw_callchain; }; @@ -519,7 +519,7 @@ static struct dso *findnew_dso(int pid, int tid, const char *filename, * processing mmap events. If not stashed, search the evlist for the first mmap * gathering event. */ -static const struct evsel *inject__mmap_evsel(struct perf_inject *inject) +static struct evsel *inject__mmap_evsel(struct perf_inject *inject) { struct evsel *pos; @@ -1007,6 +1007,7 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e .machine = machine, .mmap_evsel = inject__mmap_evsel(inject), }; + struct evsel *saved_evsel = sample->evsel; addr_location__init(&al); thread = machine__findnew_thread(machine, sample->pid, sample->tid); @@ -1021,9 +1022,10 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e /*sample_in_dso=*/true); } + sample->evsel = inject__mmap_evsel(inject); sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, &args); - + sample->evsel = saved_evsel; thread__put(thread); repipe: perf_event__repipe(tool, event, sample, machine); @@ -1100,6 +1102,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, evsel__parse_sample(evsel, event_sw, &sample_sw); perf_sample__init(&sample_sw, /*all=*/false); + sample_sw.evsel = evsel; sample_sw.period = sample->period; sample_sw.time = sample->time; perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, @@ -1433,6 +1436,7 @@ static int synthesize_build_id(struct perf_inject *inject, struct dso *dso, pid_ { struct machine *machine = perf_session__findnew_machine(inject->session, machine_pid); struct perf_sample synth_sample = { + .evsel = inject__mmap_evsel(inject), .pid = -1, .tid = -1, .time = -1, diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 14c6f6c3c4f2..c28897186341 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2905,8 +2905,12 @@ static int print_event_with_time(const struct perf_tool *tool, thread = machine__findnew_thread(machine, pid, tid); if (evsel) { + struct evsel *saved_evsel = sample->evsel; + + sample->evsel = evsel; perf_sample__fprintf_start(script, sample, thread, evsel, event->header.type, stdout); + sample->evsel = saved_evsel; } perf_event__fprintf(event, machine, stdout); diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c index 3eb9ef8d7ec6..606aa926a8fc 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -81,7 +81,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) { struct addr_location al; struct evsel *evsel = hists_to_evsel(hists); - struct perf_sample sample = { .period = 1000, }; + struct perf_sample sample = { .evsel = evsel, .period = 1000, }; size_t i; addr_location__init(&al); diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c index 1cebd20cc91c..cc6b26e373d1 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -70,6 +70,7 @@ static int add_hist_entries(struct evlist *evlist, }; struct hists *hists = evsel__hists(evsel); + sample.evsel = evsel; /* make sure it has no filter at first */ hists->thread_filter = NULL; hists->dso_filter = NULL; diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c index ee5ec8bda60e..7818950d786e 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -51,7 +51,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) { struct addr_location al; struct evsel *evsel = hists_to_evsel(hists); - struct perf_sample sample = { .period = 100, }; + struct perf_sample sample = { .evsel = evsel, .period = 100, }; size_t i; addr_location__init(&al); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 34ae388750db..a7da54d365a9 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3220,6 +3220,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, union u64_swap u; perf_sample__init(data, /*all=*/true); + data->evsel = evsel; data->cpu = data->pid = data->tid = -1; data->stream_id = data->id = data->time = -1ULL; data->period = evsel->core.attr.sample_period; diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 3fd2a5e01308..51ea4af452ea 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -5,6 +5,7 @@ #include <linux/perf_event.h> #include <linux/types.h> +struct evsel; struct machine; struct thread; @@ -102,6 +103,8 @@ struct simd_flags { * and clean up these values. */ struct perf_sample { + /** @evsel: Backward reference to the evsel used when constructing the sample. */ + struct evsel *evsel; /** @ip: The sample event PERF_SAMPLE_IP value. */ u64 ip; /** @pid: The sample event PERF_SAMPLE_TID pid value. */ diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c48e840da7d4..3794d3a04afb 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1257,8 +1257,9 @@ static int deliver_sample_value(struct evlist *evlist, bool per_thread) { struct perf_sample_id *sid = evlist__id2sid(evlist, v->id); - struct evsel *evsel; + struct evsel *saved_evsel = sample->evsel; u64 *storage = NULL; + int ret; if (sid) { storage = perf_sample_id__get_period_storage(sid, sample->tid, per_thread); @@ -1282,8 +1283,10 @@ static int deliver_sample_value(struct evlist *evlist, if (!sample->period) return 0; - evsel = container_of(sid->evsel, struct evsel, core); - return tool->sample(tool, event, sample, evsel, machine); + sample->evsel = container_of(sid->evsel, struct evsel, core); + ret = tool->sample(tool, event, sample, sample->evsel, machine); + sample->evsel = saved_evsel; + return ret; } static int deliver_sample_group(struct evlist *evlist, @@ -1355,13 +1358,16 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, struct machine *machine) { struct deferred_event *de, *tmp; - struct evsel *evsel; int ret = 0; if (!tool->merge_deferred_callchains) { - evsel = evlist__id2evsel(evlist, sample->id); - return tool->callchain_deferred(tool, event, sample, - evsel, machine); + struct evsel *saved_evsel = sample->evsel; + + sample->evsel = evlist__id2evsel(evlist, sample->id); + ret = tool->callchain_deferred(tool, event, sample, + sample->evsel, machine); + sample->evsel = saved_evsel; + return ret; } list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { @@ -1385,9 +1391,9 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, else orig_sample.deferred_callchain = false; - evsel = evlist__id2evsel(evlist, orig_sample.id); + orig_sample.evsel = evlist__id2evsel(evlist, orig_sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &orig_sample, evsel, machine); + &orig_sample, orig_sample.evsel, machine); perf_sample__exit(&orig_sample); list_del(&de->list); @@ -1410,7 +1416,6 @@ static int session__flush_deferred_samples(struct perf_session *session, struct evlist *evlist = session->evlist; struct machine *machine = &session->machines.host; struct deferred_event *de, *tmp; - struct evsel *evsel; int ret = 0; list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { @@ -1424,9 +1429,9 @@ static int session__flush_deferred_samples(struct perf_session *session, break; } - evsel = evlist__id2evsel(evlist, sample.id); + sample.evsel = evlist__id2evsel(evlist, sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &sample, evsel, machine); + &sample, sample.evsel, machine); perf_sample__exit(&sample); list_del(&de->list); @@ -1451,8 +1456,12 @@ static int machines__deliver_event(struct machines *machines, dump_event(evlist, event, file_offset, sample, file_path); - evsel = evlist__id2evsel(evlist, sample->id); + if (!sample->evsel) + sample->evsel = evlist__id2evsel(evlist, sample->id); + else + assert(sample->evsel == evlist__id2evsel(evlist, sample->id)); + evsel = sample->evsel; machine = machines__find_for_cpumode(machines, event, sample); switch (event->header.type) { -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 04/25] perf tool: Remove evsel from tool APIs that pass the sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (2 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 03/25] perf sample: Add evsel to struct perf_sample Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 05/25] perf kvm: Don't pass evsel with sample Ian Rogers ` (23 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel Now struct perf_sample has the evsel within it there is no need to pass the evsel along with the sample. In the called functions read the sample's evsel in to a variable if there are multiple uses, or use directly if there is just one use - the goal being to leave the code with as little change as possible. Some functions only use the evsel to pass to another function which they also pass the sample, in those cases just pass the sample and get the evsel in the called function. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 3 +-- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-inject.c | 19 ++++++--------- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 5 ++-- tools/perf/builtin-kwork.c | 2 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-mem.c | 1 - tools/perf/builtin-record.c | 3 +-- tools/perf/builtin-report.c | 10 +++----- tools/perf/builtin-sched.c | 4 +-- tools/perf/builtin-script.c | 4 +-- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/build-id.c | 3 +-- tools/perf/util/build-id.h | 7 +----- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data-convert-json.c | 5 ++-- tools/perf/util/intel-tpebs.c | 3 +-- tools/perf/util/jitdump.c | 2 +- tools/perf/util/session.c | 38 ++++++++++++++--------------- tools/perf/util/tool.c | 4 +-- tools/perf/util/tool.h | 4 +-- 24 files changed, 55 insertions(+), 76 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 9c27bb30b708..a4903e4ccdb5 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -284,7 +284,6 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool); @@ -303,7 +302,7 @@ static int process_sample_event(const struct perf_tool *tool, goto out_put; if (!al.filtered && - evsel__add_sample(evsel, sample, &al, ann, machine)) { + evsel__add_sample(sample->evsel, sample, &al, ann, machine)) { pr_warning("problem incrementing symbol count, " "skipping event\n"); ret = -1; diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index d390ae4e3ec8..89456ba6fcbb 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -314,9 +314,9 @@ static void perf_c2c__evsel_hists_inc_stats(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; struct c2c_hists *c2c_hists = &c2c.hists; struct c2c_hist_entry *c2c_he; struct c2c_stats stats = { .nr_entries = 0, }; diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 59bf1f72d12e..793538ad3b4c 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -390,11 +390,11 @@ struct hist_entry_ops block_hist_ops = { static int diff__process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_diff *pdiff = container_of(tool, struct perf_diff, tool); struct addr_location al; + struct evsel *evsel = sample->evsel; struct hists *hists = evsel__hists(evsel); struct hist_entry_iter iter = { .evsel = evsel, diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 8ae76bf5253e..3c243dba6240 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -363,18 +363,17 @@ typedef int (*inject_handler)(const struct perf_tool *tool, static int perf_event__repipe_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { - struct perf_inject *inject = container_of(tool, struct perf_inject, - tool); + struct perf_inject *inject = container_of(tool, struct perf_inject, tool); + struct evsel *evsel = sample->evsel; if (evsel && evsel->handler) { inject_handler f = evsel->handler; return f(tool, event, sample, evsel, machine); } - build_id__mark_dso_hit(tool, event, sample, evsel, machine); + build_id__mark_dso_hit(tool, event, sample, machine); if (inject->itrace_synth_opts.set && sample->aux_sample.size) { event = perf_inject__cut_auxtrace_sample(inject, event, sample); @@ -388,10 +387,10 @@ static int perf_event__repipe_sample(const struct perf_tool *tool, static int perf_event__convert_sample_callchain(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); + struct evsel *evsel = sample->evsel; struct callchain_cursor *cursor = get_tls_callchain_cursor(); union perf_event *event_copy = (void *)inject->event_copy; struct callchain_cursor_node *node; @@ -988,10 +987,8 @@ static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data) args->mmap_evsel, map, /*sample_in_dso=*/false); } -int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, - struct perf_sample *sample, - struct evsel *evsel __maybe_unused, - struct machine *machine) +static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, + struct perf_sample *sample, struct machine *machine) { struct addr_location al; struct thread *thread; @@ -1023,7 +1020,7 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e } sample->evsel = inject__mmap_evsel(inject); - sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, &args); sample->evsel = saved_evsel; thread__put(thread); @@ -1107,7 +1104,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, sample_sw.time = sample->time; perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, evsel->core.attr.read_format, &sample_sw); - build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); + build_id__mark_dso_hit(tool, event_sw, &sample_sw, machine); ret = perf_event__repipe(tool, event_sw, &sample_sw, machine); perf_sample__exit(&sample_sw); return ret; diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 7929a5fa5f46..34852a4c3fc8 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -960,9 +960,9 @@ typedef int (*tracepoint_handler)(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; struct thread *thread = machine__findnew_thread(machine, sample->pid, sample->tid); diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 0c5e6b3aac74..5e8e6fde097a 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -941,9 +941,9 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, static bool handle_kvm_event(struct perf_kvm_stat *kvm, struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; struct vcpu_event_record *vcpu_record; struct event_key key = { .key = INVALID_KEY, .exit_reasons = kvm->exit_reasons }; @@ -1133,7 +1133,6 @@ static bool skip_sample(struct perf_kvm_stat *kvm, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { int err = 0; @@ -1156,7 +1155,7 @@ static int process_sample_event(const struct perf_tool *tool, return -1; } - if (!handle_kvm_event(kvm, thread, evsel, sample)) + if (!handle_kvm_event(kvm, thread, sample)) err = -1; thread__put(thread); diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 7f3068264568..1cf9fe22f234 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1955,9 +1955,9 @@ typedef int (*tracepoint_handler)(const struct perf_tool *tool, static int perf_kwork__process_tracepoint_sample(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; if (evsel->handler != NULL) { diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index e8962c985d34..dc8d1d3b4cd7 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1430,9 +1430,9 @@ typedef int (*tracepoint_handler)(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; struct thread *thread = machine__findnew_thread(machine, sample->pid, sample->tid); diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index d43500b92a7b..6101a26b3a78 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -255,7 +255,6 @@ dump_raw_samples(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine) { return dump_raw_samples(tool, event, sample, machine); diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 60d764068302..8aabe27b57a0 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1489,7 +1489,6 @@ static void set_timestamp_boundary(struct record *rec, u64 sample_time) static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct record *rec = container_of(tool, struct record, tool); @@ -1500,7 +1499,7 @@ static int process_sample_event(const struct perf_tool *tool, return 0; rec->samples++; - return build_id__mark_dso_hit(tool, event, sample, evsel, machine); + return build_id__mark_dso_hit(tool, event, sample, machine); } static int process_buildids(struct record *rec) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 3b81f4b3dc49..35791fe0bd90 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -269,10 +269,10 @@ static int process_feature_event(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct report *rep = container_of(tool, struct report, tool); + struct evsel *evsel = sample->evsel; struct addr_location al; struct hist_entry_iter iter = { .evsel = evsel, @@ -349,7 +349,6 @@ static int process_sample_event(const struct perf_tool *tool, static int process_read_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct report *rep = container_of(tool, struct report, tool); @@ -357,7 +356,7 @@ static int process_read_event(const struct perf_tool *tool, if (rep->show_threads) { int err = perf_read_values_add_value(&rep->show_threads_values, event->read.pid, event->read.tid, - evsel, + sample->evsel, event->read.value); if (err) @@ -783,11 +782,10 @@ static void report__output_resort(struct report *rep) static int count_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, - struct perf_sample *sample __maybe_unused, - struct evsel *evsel, + struct perf_sample *sample, struct machine *machine __maybe_unused) { - struct hists *hists = evsel__hists(evsel); + struct hists *hists = evsel__hists(sample->evsel); hists__inc_nr_events(hists); return 0; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 3f509cfdd58c..01ac42f0ec1f 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -1867,9 +1867,9 @@ typedef int (*tracepoint_handler)(const struct perf_tool *tool, static int perf_sched__process_tracepoint_sample(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; if (evsel->handler != NULL) { @@ -3184,10 +3184,10 @@ typedef int (*sched_handler)(const struct perf_tool *tool, static int perf_timehist__process_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); + struct evsel *evsel = sample->evsel; int err = 0; struct perf_cpu this_cpu = { .cpu = sample->cpu, diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index c28897186341..28fe3ff02cf5 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2640,10 +2640,10 @@ static bool filter_cpu(struct perf_sample *sample) static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_script *scr = container_of(tool, struct perf_script, tool); + struct evsel *evsel = sample->evsel; struct addr_location al; struct addr_location addr_al; int ret = 0; @@ -2724,10 +2724,10 @@ static int process_sample_event(const struct perf_tool *tool, static int process_deferred_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_script *scr = container_of(tool, struct perf_script, tool); + struct evsel *evsel = sample->evsel; struct perf_event_attr *attr = &evsel->core.attr; struct evsel_script *es = evsel->priv; unsigned int type = output_type(attr->type); diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index f8b49d69e9a5..f3f0e4ec0502 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -574,10 +574,10 @@ typedef int (*tracepoint_handler)(struct timechart *tchart, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct timechart *tchart = container_of(tool, struct timechart, tool); + struct evsel *evsel = sample->evsel; if (evsel->core.attr.sample_type & PERF_SAMPLE_TIME) { if (!tchart->first_time || tchart->first_time > sample->time) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 311d9da9896a..cb2d72c2a921 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3461,10 +3461,10 @@ static void trace__set_base_time(struct trace *trace, static int trace__process_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct trace *trace = container_of(tool, struct trace, tool); + struct evsel *evsel = sample->evsel; struct thread *thread; int err = 0; diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index fdb35133fde4..55b72235f891 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -55,7 +55,6 @@ static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct addr_location al; @@ -74,7 +73,7 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, addr_location__exit(&al); - sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, /*data=*/NULL); diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index 47e621cebe1b..73bad90b06f9 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h @@ -34,12 +34,7 @@ char *__dso__build_id_filename(const struct dso *dso, char *bf, size_t size, bool is_debug, bool is_kallsyms); int build_id__mark_dso_hit(const struct perf_tool *tool, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, - struct machine *machine); - -int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, - struct machine *machine); + struct perf_sample *sample, struct machine *machine); bool perf_session__read_build_ids(struct perf_session *session, bool with_hits); int perf_session__write_buildid_table(struct perf_session *session, diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c index a22e9049ff30..c4b12b33d060 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c @@ -802,10 +802,10 @@ static bool is_flush_needed(struct ctf_stream *cs) static int process_sample_event(const struct perf_tool *tool, union perf_event *_event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct convert *c = container_of(tool, struct convert, tool); + struct evsel *evsel = sample->evsel; struct evsel_priv *priv = evsel->priv; struct ctf_writer *cw = &c->writer; struct ctf_stream *cs; diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c index eefa3a94c813..f42de990a709 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -155,13 +155,12 @@ static void output_sample_callchain_entry(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine) { struct convert_json *c = container_of(tool, struct convert_json, tool); FILE *out = c->out; struct addr_location al; - u64 sample_type = __evlist__combined_sample_type(evsel->evlist); + u64 sample_type = __evlist__combined_sample_type(sample->evsel->evlist); u8 cpumode = PERF_RECORD_MISC_USER; addr_location__init(&al); @@ -241,7 +240,7 @@ static int process_sample_event(const struct perf_tool *tool, #ifdef HAVE_LIBTRACEEVENT if (sample->raw_data) { - struct tep_event *tp_format = evsel__tp_format(evsel); + struct tep_event *tp_format = evsel__tp_format(sample->evsel); struct tep_format_field **fields = tp_format ? tep_event_fields(tp_format) : NULL; if (fields) { diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 3c958d738ca6..21a672813099 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -186,7 +186,6 @@ static bool should_ignore_sample(const struct perf_sample *sample, const struct static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct tpebs_retire_lat *t; @@ -197,7 +196,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, mutex_unlock(tpebs_mtx_get()); return 0; } - t = tpebs_retire_lat__find(evsel); + t = tpebs_retire_lat__find(sample->evsel); if (!t) { mutex_unlock(tpebs_mtx_get()); return -EINVAL; diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c index e0ce8b904729..52e6ffac2b3e 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -642,7 +642,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr) ret = jit_inject_event(jd, event); if (!ret) - build_id__mark_dso_hit(tool, event, &sample, NULL, jd->machine); + build_id__mark_dso_hit(tool, event, &sample, jd->machine); out: perf_sample__exit(&sample); return ret; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 3794d3a04afb..150398b383fe 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1110,9 +1110,10 @@ char *get_page_size_name(u64 size, char *str) return str; } -static void dump_sample(struct machine *machine, struct evsel *evsel, union perf_event *event, +static void dump_sample(struct machine *machine, union perf_event *event, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; u64 sample_type; char str[PAGE_SIZE_NAME_LEN]; uint16_t e_machine = EM_NONE; @@ -1176,9 +1177,10 @@ static void dump_sample(struct machine *machine, struct evsel *evsel, union perf sample_read__printf(sample, evsel->core.attr.read_format); } -static void dump_deferred_callchain(struct evsel *evsel, union perf_event *event, - struct perf_sample *sample) +static void dump_deferred_callchain(union perf_event *event, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; + if (!dump_trace) return; @@ -1284,7 +1286,7 @@ static int deliver_sample_value(struct evlist *evlist, return 0; sample->evsel = container_of(sid->evsel, struct evsel, core); - ret = tool->sample(tool, event, sample, sample->evsel, machine); + ret = tool->sample(tool, event, sample, machine); sample->evsel = saved_evsel; return ret; } @@ -1316,8 +1318,9 @@ static int deliver_sample_group(struct evlist *evlist, static int evlist__deliver_sample(struct evlist *evlist, const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) + struct machine *machine) { + struct evsel *evsel = sample->evsel; /* We know evsel != NULL. */ u64 sample_type = evsel->core.attr.sample_type; u64 read_format = evsel->core.attr.read_format; @@ -1325,7 +1328,7 @@ static int evlist__deliver_sample(struct evlist *evlist, const struct perf_tool /* Standard sample delivery. */ if (!(sample_type & PERF_SAMPLE_READ)) - return tool->sample(tool, event, sample, evsel, machine); + return tool->sample(tool, event, sample, machine); /* For PERF_SAMPLE_READ we have either single or group mode. */ if (read_format & PERF_FORMAT_GROUP) @@ -1364,8 +1367,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, struct evsel *saved_evsel = sample->evsel; sample->evsel = evlist__id2evsel(evlist, sample->id); - ret = tool->callchain_deferred(tool, event, sample, - sample->evsel, machine); + ret = tool->callchain_deferred(tool, event, sample, machine); sample->evsel = saved_evsel; return ret; } @@ -1393,7 +1395,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, orig_sample.evsel = evlist__id2evsel(evlist, orig_sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &orig_sample, orig_sample.evsel, machine); + &orig_sample, machine); perf_sample__exit(&orig_sample); list_del(&de->list); @@ -1431,7 +1433,7 @@ static int session__flush_deferred_samples(struct perf_session *session, sample.evsel = evlist__id2evsel(evlist, sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &sample, sample.evsel, machine); + &sample, machine); perf_sample__exit(&sample); list_del(&de->list); @@ -1451,7 +1453,6 @@ static int machines__deliver_event(struct machines *machines, const struct perf_tool *tool, u64 file_offset, const char *file_path) { - struct evsel *evsel; struct machine *machine; dump_event(evlist, event, file_offset, sample, file_path); @@ -1461,21 +1462,20 @@ static int machines__deliver_event(struct machines *machines, else assert(sample->evsel == evlist__id2evsel(evlist, sample->id)); - evsel = sample->evsel; machine = machines__find_for_cpumode(machines, event, sample); switch (event->header.type) { case PERF_RECORD_SAMPLE: - if (evsel == NULL) { + if (sample->evsel == NULL) { ++evlist->stats.nr_unknown_id; return 0; } if (machine == NULL) { ++evlist->stats.nr_unprocessable_samples; - dump_sample(machine, evsel, event, sample); + dump_sample(machine, event, sample); return 0; } - dump_sample(machine, evsel, event, sample); + dump_sample(machine, event, sample); if (sample->deferred_callchain && tool->merge_deferred_callchains) { struct deferred_event *de = malloc(sizeof(*de)); size_t sz = event->header.size; @@ -1492,7 +1492,7 @@ static int machines__deliver_event(struct machines *machines, list_add_tail(&de->list, &evlist->deferred_samples); return 0; } - return evlist__deliver_sample(evlist, tool, event, sample, evsel, machine); + return evlist__deliver_sample(evlist, tool, event, sample, machine); case PERF_RECORD_MMAP: return tool->mmap(tool, event, sample, machine); case PERF_RECORD_MMAP2: @@ -1520,8 +1520,8 @@ static int machines__deliver_event(struct machines *machines, evlist->stats.total_lost_samples += event->lost_samples.lost; return tool->lost_samples(tool, event, sample, machine); case PERF_RECORD_READ: - dump_read(evsel, event); - return tool->read(tool, event, sample, evsel, machine); + dump_read(sample->evsel, event); + return tool->read(tool, event, sample, machine); case PERF_RECORD_THROTTLE: return tool->throttle(tool, event, sample, machine); case PERF_RECORD_UNTHROTTLE: @@ -1550,7 +1550,7 @@ static int machines__deliver_event(struct machines *machines, case PERF_RECORD_AUX_OUTPUT_HW_ID: return tool->aux_output_hw_id(tool, event, sample, machine); case PERF_RECORD_CALLCHAIN_DEFERRED: - dump_deferred_callchain(evsel, event, sample); + dump_deferred_callchain(event, sample); return evlist__deliver_deferred_callchain(evlist, tool, event, sample, machine); default: diff --git a/tools/perf/util/tool.c b/tools/perf/util/tool.c index 013c7839e2cf..0f285a2574c8 100644 --- a/tools/perf/util/tool.c +++ b/tools/perf/util/tool.c @@ -110,7 +110,6 @@ static int process_event_synth_event_update_stub(const struct perf_tool *tool __ int process_event_sample_stub(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct machine *machine __maybe_unused) { dump_printf(": unhandled!\n"); @@ -348,12 +347,11 @@ bool perf_tool__compressed_is_stub(const struct perf_tool *tool) static int delegate_ ## name(const struct perf_tool *tool, \ union perf_event *event, \ struct perf_sample *sample, \ - struct evsel *evsel, \ struct machine *machine) \ { \ struct delegate_tool *del_tool = container_of(tool, struct delegate_tool, tool); \ struct perf_tool *delegate = del_tool->delegate; \ - return delegate->name(delegate, event, sample, evsel, machine); \ + return delegate->name(delegate, event, sample, machine); \ } CREATE_DELEGATE_SAMPLE(read); CREATE_DELEGATE_SAMPLE(sample); diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h index 2d9a4b1ca9d0..2a4f124ffd8d 100644 --- a/tools/perf/util/tool.h +++ b/tools/perf/util/tool.h @@ -9,7 +9,6 @@ struct perf_session; union perf_event; struct evlist; -struct evsel; struct perf_sample; struct perf_tool; struct machine; @@ -17,7 +16,7 @@ struct ordered_events; typedef int (*event_sample)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); + struct machine *machine); typedef int (*event_op)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine); @@ -103,7 +102,6 @@ bool perf_tool__compressed_is_stub(const struct perf_tool *tool); int process_event_sample_stub(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); struct delegate_tool { -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 05/25] perf kvm: Don't pass evsel with sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (3 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 04/25] perf tool: Remove evsel from tool APIs that pass the sample Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval Ian Rogers ` (22 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel As the sample now contains the evsel, read the evsel from the sample rather than passing them as a pair. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-kvm.c | 19 +++-- .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 17 +++-- .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 ++--- .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 ++--- .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 18 +++-- tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +++--- tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 ++++++++----------- tools/perf/util/kvm-stat.c | 19 +++-- tools/perf/util/kvm-stat.h | 18 ++--- 9 files changed, 89 insertions(+), 126 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 5e8e6fde097a..d9b9792894a8 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -806,7 +806,6 @@ static bool update_kvm_event(struct perf_kvm_stat *kvm, } static bool is_child_event(struct perf_kvm_stat *kvm, - struct evsel *evsel, struct perf_sample *sample, struct event_key *key) { @@ -818,8 +817,8 @@ static bool is_child_event(struct perf_kvm_stat *kvm, return false; for (; child_ops->name; child_ops++) { - if (evsel__name_is(evsel, child_ops->name)) { - child_ops->get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, child_ops->name)) { + child_ops->get_key(sample, key); return true; } } @@ -917,11 +916,10 @@ static bool handle_end_event(struct perf_kvm_stat *kvm, static struct vcpu_event_record *per_vcpu_record(struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { /* Only kvm_entry records vcpu id. */ - if (!thread__priv(thread) && kvm_entry_event(evsel)) { + if (!thread__priv(thread) && kvm_entry_event(sample->evsel)) { struct vcpu_event_record *vcpu_record; struct machine *machine = maps__machine(thread__maps(thread)); uint16_t e_machine = thread__e_machine(thread, machine, /*e_flags=*/NULL); @@ -932,7 +930,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, return NULL; } - vcpu_record->vcpu_id = evsel__intval(evsel, sample, vcpu_id_str(e_machine)); + vcpu_record->vcpu_id = evsel__intval(sample->evsel, sample, vcpu_id_str(e_machine)); thread__set_priv(thread, vcpu_record); } @@ -943,12 +941,11 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, struct thread *thread, struct perf_sample *sample) { - struct evsel *evsel = sample->evsel; struct vcpu_event_record *vcpu_record; struct event_key key = { .key = INVALID_KEY, .exit_reasons = kvm->exit_reasons }; - vcpu_record = per_vcpu_record(thread, evsel, sample); + vcpu_record = per_vcpu_record(thread, sample); if (!vcpu_record) return true; @@ -957,13 +954,13 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, (kvm->trace_vcpu != vcpu_record->vcpu_id)) return true; - if (kvm->events_ops->is_begin_event(evsel, sample, &key)) + if (kvm->events_ops->is_begin_event(sample, &key)) return handle_begin_event(kvm, vcpu_record, &key, sample); - if (is_child_event(kvm, evsel, sample, &key)) + if (is_child_event(kvm, sample, &key)) return handle_child_event(kvm, vcpu_record, &key, sample); - if (kvm->events_ops->is_end_event(evsel, sample, &key)) + if (kvm->events_ops->is_end_event(sample, &key)) return handle_end_event(kvm, vcpu_record, &key, sample); return true; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c index c640dcd8af7c..1e76906f719c 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c @@ -17,10 +17,11 @@ static const char * const __kvm_events_tp[] = { NULL, }; -static void event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_get_key(struct perf_sample *sample, struct event_key *key) { + struct evsel *evsel = sample->evsel; + key->info = 0; key->key = evsel__intval(evsel, sample, kvm_exit_reason(EM_AARCH64)); key->exit_reasons = arm64_exit_reasons; @@ -36,19 +37,17 @@ static void event_get_key(struct evsel *evsel, } } -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_begin(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, kvm_entry_trace(EM_AARCH64)); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_AARCH64)); } -static bool event_end(struct evsel *evsel, - struct perf_sample *sample, +static bool event_end(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, kvm_exit_trace(EM_AARCH64))) { - event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, kvm_exit_trace(EM_AARCH64))) { + event_get_key(sample, key); return true; } return false; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c index b802e516b138..9d6265290f6d 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c @@ -53,14 +53,12 @@ static const char * const __kvm_events_tp[] = { NULL, }; -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool event_begin(struct perf_sample *sample, struct event_key *key) { - return exit_event_begin(evsel, sample, key); + return exit_event_begin(sample, key); } -static bool event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { /* @@ -71,17 +69,16 @@ static bool event_end(struct evsel *evsel, * kvm:kvm_enter means returning to vmm and then to guest * kvm:kvm_reenter means returning to guest immediately */ - return evsel__name_is(evsel, kvm_entry_trace(EM_LOONGARCH)) || - evsel__name_is(evsel, kvm_reenter_trace); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_LOONGARCH)) || + evsel__name_is(sample->evsel, kvm_reenter_trace); } -static void event_gspr_get_key(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static void event_gspr_get_key(struct perf_sample *sample, struct event_key *key) { unsigned int insn; key->key = LOONGARCH_EXCEPTION_OTHERS; - insn = evsel__intval(evsel, sample, "inst_word"); + insn = evsel__intval(sample->evsel, sample, "inst_word"); switch (insn >> 24) { case 0: diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c index 42182d70beb6..5158d7e88ee6 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c @@ -28,12 +28,11 @@ static const char * const ppc_book3s_hv_kvm_tp[] = { /* 1 extra placeholder for NULL */ static const char *__kvm_events_tp[NR_TPS + 1]; -static void hcall_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void hcall_event_get_key(struct perf_sample *sample, struct event_key *key) { key->info = 0; - key->key = evsel__intval(evsel, sample, "req"); + key->key = evsel__intval(sample->evsel, sample, "req"); } static const char *get_hcall_exit_reason(u64 exit_code) @@ -51,18 +50,16 @@ static const char *get_hcall_exit_reason(u64 exit_code) return "UNKNOWN"; } -static bool hcall_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool hcall_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, __kvm_events_tp[3]); + return evsel__name_is(sample->evsel, __kvm_events_tp[3]); } -static bool hcall_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool hcall_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, __kvm_events_tp[2])) { - hcall_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, __kvm_events_tp[2])) { + hcall_event_get_key(sample, key); return true; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c index 8d4d5d6ce720..e8db8b4f8e2e 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c @@ -20,30 +20,28 @@ static const char * const __kvm_events_tp[] = { NULL, }; -static void event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_get_key(struct perf_sample *sample, struct event_key *key) { int xlen = 64; // TODO: 32-bit support. key->info = 0; - key->key = evsel__intval(evsel, sample, kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); + key->key = evsel__intval(sample->evsel, sample, + kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); key->exit_reasons = riscv_exit_reasons; } -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_begin(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, kvm_entry_trace(EM_RISCV)); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_RISCV)); } -static bool event_end(struct evsel *evsel, - struct perf_sample *sample, +static bool event_end(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, kvm_exit_trace(EM_RISCV))) { - event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, kvm_exit_trace(EM_RISCV))) { + event_get_key(sample, key); return true; } return false; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c index 7e29169f5bb0..158372ba0205 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c @@ -18,38 +18,34 @@ define_exit_reasons_table(sie_sigp_order_codes, sigp_order_codes); define_exit_reasons_table(sie_diagnose_codes, diagnose_codes); define_exit_reasons_table(sie_icpt_prog_codes, icpt_prog_codes); -static void event_icpt_insn_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_icpt_insn_get_key(struct perf_sample *sample, struct event_key *key) { u64 insn; - insn = evsel__intval(evsel, sample, "instruction"); + insn = evsel__intval(sample->evsel, sample, "instruction"); key->key = icpt_insn_decoder(insn); key->exit_reasons = sie_icpt_insn_codes; } -static void event_sigp_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_sigp_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "order_code"); + key->key = evsel__intval(sample->evsel, sample, "order_code"); key->exit_reasons = sie_sigp_order_codes; } -static void event_diag_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_diag_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "code"); + key->key = evsel__intval(sample->evsel, sample, "code"); key->exit_reasons = sie_diagnose_codes; } -static void event_icpt_prog_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_icpt_prog_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "code"); + key->key = evsel__intval(sample->evsel, sample, "code"); key->exit_reasons = sie_icpt_prog_codes; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c index 43275d25b6cb..a7993e945d8b 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c @@ -24,45 +24,43 @@ static const struct kvm_events_ops exit_events = { * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...). */ -static void mmio_event_get_key(struct evsel *evsel, struct perf_sample *sample, +static void mmio_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "gpa"); - key->info = evsel__intval(evsel, sample, "type"); + key->key = evsel__intval(sample->evsel, sample, "gpa"); + key->info = evsel__intval(sample->evsel, sample, "type"); } #define KVM_TRACE_MMIO_READ_UNSATISFIED 0 #define KVM_TRACE_MMIO_READ 1 #define KVM_TRACE_MMIO_WRITE 2 -static bool mmio_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool mmio_event_begin(struct perf_sample *sample, struct event_key *key) { /* MMIO read begin event in kernel. */ - if (kvm_exit_event(evsel)) + if (kvm_exit_event(sample->evsel)) return true; /* MMIO write begin event in kernel. */ - if (evsel__name_is(evsel, "kvm:kvm_mmio") && - evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { - mmio_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && + evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { + mmio_event_get_key(sample, key); return true; } return false; } -static bool mmio_event_end(struct evsel *evsel, struct perf_sample *sample, - struct event_key *key) +static bool mmio_event_end(struct perf_sample *sample, struct event_key *key) { /* MMIO write end event in kernel. */ - if (kvm_entry_event(evsel)) + if (kvm_entry_event(sample->evsel)) return true; /* MMIO read end event in kernel.*/ - if (evsel__name_is(evsel, "kvm:kvm_mmio") && - evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) { - mmio_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && + evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_READ) { + mmio_event_get_key(sample, key); return true; } @@ -86,31 +84,27 @@ static const struct kvm_events_ops mmio_events = { }; /* The time of emulation pio access is from kvm_pio to kvm_entry. */ -static void ioport_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void ioport_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "port"); - key->info = evsel__intval(evsel, sample, "rw"); + key->key = evsel__intval(sample->evsel, sample, "port"); + key->info = evsel__intval(sample->evsel, sample, "rw"); } -static bool ioport_event_begin(struct evsel *evsel, - struct perf_sample *sample, +static bool ioport_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, "kvm:kvm_pio")) { - ioport_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_pio")) { + ioport_event_get_key(sample, key); return true; } return false; } -static bool ioport_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) +static bool ioport_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, @@ -130,31 +124,25 @@ static const struct kvm_events_ops ioport_events = { }; /* The time of emulation msr is from kvm_msr to kvm_entry. */ -static void msr_event_get_key(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) +static void msr_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "ecx"); - key->info = evsel__intval(evsel, sample, "write"); + key->key = evsel__intval(sample->evsel, sample, "ecx"); + key->info = evsel__intval(sample->evsel, sample, "write"); } -static bool msr_event_begin(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) +static bool msr_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, "kvm:kvm_msr")) { - msr_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_msr")) { + msr_event_get_key(sample, key); return true; } return false; } -static bool msr_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) +static bool msr_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } static void msr_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c index 27f16810498c..f17a6132958d 100644 --- a/tools/perf/util/kvm-stat.c +++ b/tools/perf/util/kvm-stat.c @@ -11,22 +11,20 @@ bool kvm_exit_event(struct evsel *evsel) return evsel__name_is(evsel, kvm_exit_trace(e_machine)); } -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +void exit_event_get_key(struct perf_sample *sample, struct event_key *key) { - uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL); + uint16_t e_machine = evsel__e_machine(sample->evsel, /*e_flags=*/NULL); key->info = 0; - key->key = evsel__intval(evsel, sample, kvm_exit_reason(e_machine)); + key->key = evsel__intval(sample->evsel, sample, kvm_exit_reason(e_machine)); } -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +bool exit_event_begin(struct perf_sample *sample, struct event_key *key) { - if (kvm_exit_event(evsel)) { - exit_event_get_key(evsel, sample, key); + if (kvm_exit_event(sample->evsel)) { + exit_event_get_key(sample, key); return true; } @@ -40,11 +38,10 @@ bool kvm_entry_event(struct evsel *evsel) return evsel__name_is(evsel, kvm_entry_trace(e_machine)); } -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +bool exit_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } static const char *get_exit_reason(struct perf_kvm_stat *kvm, diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 4a998aaece5d..cdbd921a555f 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -53,18 +53,15 @@ struct kvm_event { }; struct child_event_ops { - void (*get_key)(struct evsel *evsel, - struct perf_sample *sample, + void (*get_key)(struct perf_sample *sample, struct event_key *key); const char *name; }; struct kvm_events_ops { - bool (*is_begin_event)(struct evsel *evsel, - struct perf_sample *sample, + bool (*is_begin_event)(struct perf_sample *sample, struct event_key *key); - bool (*is_end_event)(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key); + bool (*is_end_event)(struct perf_sample *sample, struct event_key *key); const struct child_event_ops *child_ops; void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key, char *decode); @@ -116,14 +113,11 @@ struct kvm_reg_events_ops { #ifdef HAVE_LIBTRACEEVENT -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +void exit_event_get_key(struct perf_sample *sample, struct event_key *key); -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, +bool exit_event_begin(struct perf_sample *sample, struct event_key *key); -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample, +bool exit_event_end(struct perf_sample *sample, struct event_key *key); void exit_event_decode_key(struct perf_kvm_stat *kvm, struct event_key *key, -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (4 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 05/25] perf kvm: Don't pass evsel with sample Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 07/25] perf trace: Don't pass evsel with sample Ian Rogers ` (21 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The evsel argument to evsel__intval, and similar functions, is unnecessary as it can be read from the sample. Remove the evsel and rename the function to match that the data is coming from the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 33 +++---- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-kwork.c | 29 +++--- tools/perf/builtin-lock.c | 32 +++---- tools/perf/builtin-sched.c | 92 +++++++++---------- tools/perf/builtin-timechart.c | 88 +++++++++--------- tools/perf/builtin-trace.c | 12 +-- tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/tests/switch-tracking.c | 4 +- tools/perf/util/evsel.c | 22 ++--- tools/perf/util/evsel.h | 12 +-- tools/perf/util/intel-pt.c | 2 +- .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 6 +- .../util/kvm-stat-arch/kvm-stat-loongarch.c | 2 +- .../util/kvm-stat-arch/kvm-stat-powerpc.c | 2 +- .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 3 +- tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 8 +- tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 16 ++-- tools/perf/util/kvm-stat.c | 2 +- 20 files changed, 183 insertions(+), 188 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 3c243dba6240..3226ab326315 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1085,7 +1085,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, union perf_event *event_sw; struct perf_sample sample_sw; struct perf_inject *inject = container_of(tool, struct perf_inject, tool); - u32 pid = evsel__intval(evsel, sample, "pid"); + u32 pid = perf_sample__intval(sample, "pid"); int ret; list_for_each_entry(ent, &inject->samples, node) { diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 34852a4c3fc8..96b78a64c1c1 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -173,10 +173,10 @@ static int insert_caller_stat(unsigned long call_site, static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *sample) { - unsigned long ptr = evsel__intval(evsel, sample, "ptr"), - call_site = evsel__intval(evsel, sample, "call_site"); - int bytes_req = evsel__intval(evsel, sample, "bytes_req"), - bytes_alloc = evsel__intval(evsel, sample, "bytes_alloc"); + unsigned long ptr = perf_sample__intval(sample, "ptr"), + call_site = perf_sample__intval(sample, "call_site"); + int bytes_req = perf_sample__intval(sample, "bytes_req"), + bytes_alloc = perf_sample__intval(sample, "bytes_alloc"); if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) || insert_caller_stat(call_site, bytes_req, bytes_alloc)) @@ -202,7 +202,7 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s int node1, node2; node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}); - node2 = evsel__intval(evsel, sample, "node"); + node2 = perf_sample__intval(sample, "node"); /* * If the field "node" is NUMA_NO_NODE (-1), we don't take it @@ -243,9 +243,9 @@ static struct alloc_stat *search_alloc_stat(unsigned long ptr, return NULL; } -static int evsel__process_free_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_free_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - unsigned long ptr = evsel__intval(evsel, sample, "ptr"); + unsigned long ptr = perf_sample__intval(sample, "ptr"); struct alloc_stat *s_alloc, *s_caller; s_alloc = search_alloc_stat(ptr, 0, &root_alloc_stat, ptr_cmp); @@ -808,9 +808,9 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sample *sample) { u64 page; - unsigned int order = evsel__intval(evsel, sample, "order"); - unsigned int gfp_flags = evsel__intval(evsel, sample, "gfp_flags"); - unsigned int migrate_type = evsel__intval(evsel, sample, + unsigned int order = perf_sample__intval(sample, "order"); + unsigned int gfp_flags = perf_sample__intval(sample, "gfp_flags"); + unsigned int migrate_type = perf_sample__intval(sample, "migratetype"); u64 bytes = kmem_page_size << order; u64 callsite; @@ -822,9 +822,9 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp }; if (use_pfn) - page = evsel__intval(evsel, sample, "pfn"); + page = perf_sample__intval(sample, "pfn"); else - page = evsel__intval(evsel, sample, "page"); + page = perf_sample__intval(sample, "page"); nr_page_allocs++; total_page_alloc_bytes += bytes; @@ -877,10 +877,11 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp return 0; } -static int evsel__process_page_free_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_page_free_event(struct evsel *evsel __maybe_unused, + struct perf_sample *sample) { u64 page; - unsigned int order = evsel__intval(evsel, sample, "order"); + unsigned int order = perf_sample__intval(sample, "order"); u64 bytes = kmem_page_size << order; struct page_stat *pstat; struct page_stat this = { @@ -888,9 +889,9 @@ static int evsel__process_page_free_event(struct evsel *evsel, struct perf_sampl }; if (use_pfn) - page = evsel__intval(evsel, sample, "pfn"); + page = perf_sample__intval(sample, "pfn"); else - page = evsel__intval(evsel, sample, "page"); + page = perf_sample__intval(sample, "page"); nr_page_frees++; total_page_free_bytes += bytes; diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index d9b9792894a8..dd2ed21596aa 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -930,7 +930,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, return NULL; } - vcpu_record->vcpu_id = evsel__intval(sample->evsel, sample, vcpu_id_str(e_machine)); + vcpu_record->vcpu_id = perf_sample__intval(sample, vcpu_id_str(e_machine)); thread__set_priv(thread, vcpu_record); } diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 1cf9fe22f234..f47b54a68726 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1006,7 +1006,7 @@ static void irq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1014,11 +1014,11 @@ static void irq_work_init(struct perf_kwork *kwork, work->cpu = sample->cpu; if (kwork->report == KWORK_REPORT_TOP) { - work->id = evsel__intval_common(evsel, sample, "common_pid"); + work->id = perf_sample__intval_common(sample, "common_pid"); work->name = NULL; } else { - work->id = evsel__intval(evsel, sample, "irq"); - work->name = evsel__strval(evsel, sample, "name"); + work->id = perf_sample__intval(sample, "irq"); + work->name = perf_sample__strval(sample, "name"); } } @@ -1144,10 +1144,10 @@ static void softirq_work_init(struct perf_kwork *kwork, work->cpu = sample->cpu; if (kwork->report == KWORK_REPORT_TOP) { - work->id = evsel__intval_common(evsel, sample, "common_pid"); + work->id = perf_sample__intval_common(sample, "common_pid"); work->name = NULL; } else { - num = evsel__intval(evsel, sample, "vec"); + num = perf_sample__intval(sample, "vec"); work->id = num; work->name = evsel__softirq_name(evsel, num); } @@ -1234,17 +1234,16 @@ static void workqueue_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { char *modp = NULL; - unsigned long long function_addr = evsel__intval(evsel, - sample, "function"); + unsigned long long function_addr = perf_sample__intval(sample, "function"); work->class = class; work->cpu = sample->cpu; - work->id = evsel__intval(evsel, sample, "work"); + work->id = perf_sample__intval(sample, "work"); work->name = function_addr == 0 ? NULL : machine__resolve_kernel_addr(machine, &function_addr, &modp); } @@ -1302,7 +1301,7 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1310,11 +1309,11 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused, work->cpu = sample->cpu; if (src_type == KWORK_TRACE_EXIT) { - work->id = evsel__intval(evsel, sample, "prev_pid"); - work->name = strdup(evsel__strval(evsel, sample, "prev_comm")); + work->id = perf_sample__intval(sample, "prev_pid"); + work->name = strdup(perf_sample__strval(sample, "prev_comm")); } else if (src_type == KWORK_TRACE_ENTRY) { - work->id = evsel__intval(evsel, sample, "next_pid"); - work->name = strdup(evsel__strval(evsel, sample, "next_comm")); + work->id = perf_sample__intval(sample, "next_pid"); + work->name = strdup(perf_sample__strval(sample, "next_comm")); } } diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index dc8d1d3b4cd7..baf0c99df5df 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -563,15 +563,15 @@ static int get_key_by_aggr_mode(u64 *key, u64 addr, struct evsel *evsel, return get_key_by_aggr_mode_simple(key, addr, sample->tid); } -static int report_lock_acquire_event(struct evsel *evsel, +static int report_lock_acquire_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); - int flag = evsel__intval(evsel, sample, "flags"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); + int flag = perf_sample__intval(sample, "flags"); u64 key; int ret; @@ -638,15 +638,15 @@ static int report_lock_acquire_event(struct evsel *evsel, return 0; } -static int report_lock_acquired_event(struct evsel *evsel, +static int report_lock_acquired_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; u64 contended_term; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; @@ -704,14 +704,14 @@ static int report_lock_acquired_event(struct evsel *evsel, return 0; } -static int report_lock_contended_event(struct evsel *evsel, +static int report_lock_contended_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; @@ -762,14 +762,14 @@ static int report_lock_contended_event(struct evsel *evsel, return 0; } -static int report_lock_release_event(struct evsel *evsel, +static int report_lock_release_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; @@ -969,8 +969,8 @@ static int report_lock_contention_begin_event(struct evsel *evsel, struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - u64 addr = evsel__intval(evsel, sample, "lock_addr"); - unsigned int flags = evsel__intval(evsel, sample, "flags"); + u64 addr = perf_sample__intval(sample, "lock_addr"); + unsigned int flags = perf_sample__intval(sample, "flags"); u64 key; int i, ret; static bool kmap_loaded; @@ -1134,7 +1134,7 @@ static int report_lock_contention_end_event(struct evsel *evsel, struct thread_stat *ts; struct lock_seq_stat *seq; u64 contended_term; - u64 addr = evsel__intval(evsel, sample, "lock_addr"); + u64 addr = perf_sample__intval(sample, "lock_addr"); u64 key; int ret; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 01ac42f0ec1f..c2bf187104b2 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -829,8 +829,8 @@ replay_wakeup_event(struct perf_sched *sched, struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { - const char *comm = evsel__strval(evsel, sample, "comm"); - const u32 pid = evsel__intval(evsel, sample, "pid"); + const char *comm = perf_sample__strval(sample, "comm"); + const u32 pid = perf_sample__intval(sample, "pid"); struct task_desc *waker, *wakee; if (verbose > 0) { @@ -851,10 +851,10 @@ static int replay_switch_event(struct perf_sched *sched, struct perf_sample *sample, struct machine *machine __maybe_unused) { - const char *prev_comm = evsel__strval(evsel, sample, "prev_comm"), - *next_comm = evsel__strval(evsel, sample, "next_comm"); - const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), - next_pid = evsel__intval(evsel, sample, "next_pid"); + const char *prev_comm = perf_sample__strval(sample, "prev_comm"), + *next_comm = perf_sample__strval(sample, "next_comm"); + const u32 prev_pid = perf_sample__intval(sample, "prev_pid"), + next_pid = perf_sample__intval(sample, "next_pid"); struct task_desc *prev, __maybe_unused *next; u64 timestamp0, timestamp = sample->time; int cpu = sample->cpu; @@ -1134,13 +1134,13 @@ static void free_work_atoms(struct work_atoms *atoms) } static int latency_switch_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), - next_pid = evsel__intval(evsel, sample, "next_pid"); - const char prev_state = evsel__taskstate(evsel, sample, "prev_state"); + const u32 prev_pid = perf_sample__intval(sample, "prev_pid"), + next_pid = perf_sample__intval(sample, "next_pid"); + const char prev_state = perf_sample__taskstate(sample, "prev_state"); struct work_atoms *out_events, *in_events; struct thread *sched_out, *sched_in; u64 timestamp0, timestamp = sample->time; @@ -1204,12 +1204,12 @@ static int latency_switch_event(struct perf_sched *sched, } static int latency_runtime_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid = evsel__intval(evsel, sample, "pid"); - const u64 runtime = evsel__intval(evsel, sample, "runtime"); + const u32 pid = perf_sample__intval(sample, "pid"); + const u64 runtime = perf_sample__intval(sample, "runtime"); struct thread *thread = machine__findnew_thread(machine, -1, pid); struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); u64 timestamp = sample->time; @@ -1239,11 +1239,11 @@ static int latency_runtime_event(struct perf_sched *sched, } static int latency_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); struct work_atoms *atoms; struct work_atom *atom; struct thread *wakee; @@ -1300,11 +1300,11 @@ static int latency_wakeup_event(struct perf_sched *sched, } static int latency_migrate_task_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); u64 timestamp = sample->time; struct work_atoms *atoms; struct work_atom *atom; @@ -1626,11 +1626,11 @@ static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu, } } -static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, +static int map_switch_event(struct perf_sched *sched, struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); - const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"); + const u32 next_pid = perf_sample__intval(sample, "next_pid"); + const u32 prev_pid = perf_sample__intval(sample, "prev_pid"); struct thread *sched_in, *sched_out; struct thread_runtime *tr; int new_shortname; @@ -1797,8 +1797,8 @@ static int process_sched_switch_event(const struct perf_tool *tool, { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); int this_cpu = sample->cpu, err = 0; - u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), - next_pid = evsel__intval(evsel, sample, "next_pid"); + u32 prev_pid = perf_sample__intval(sample, "prev_pid"), + next_pid = perf_sample__intval(sample, "next_pid"); if (sched->curr_pid[this_cpu] != (u32)-1) { /* @@ -2068,12 +2068,11 @@ static char *timehist_get_commstr(struct thread *thread) /* prio field format: xxx or xxx->yyy */ #define MAX_PRIO_STR_LEN 8 -static char *timehist_get_priostr(struct evsel *evsel, - struct thread *thread, +static char *timehist_get_priostr(struct thread *thread, struct perf_sample *sample) { static char prio_str[16]; - int prev_prio = (int)evsel__intval(evsel, sample, "prev_prio"); + int prev_prio = (int)perf_sample__intval(sample, "prev_prio"); struct thread_runtime *tr = thread__priv(thread); if (tr->prio != prev_prio && tr->prio != -1) @@ -2161,15 +2160,14 @@ static void timehist_header(struct perf_sched *sched) } static void timehist_print_sample(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct addr_location *al, struct thread *thread, u64 t, const char state) { struct thread_runtime *tr = thread__priv(thread); - const char *next_comm = evsel__strval(evsel, sample, "next_comm"); - const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); + const char *next_comm = perf_sample__strval(sample, "next_comm"); + const u32 next_pid = perf_sample__intval(sample, "next_pid"); u32 max_cpus = sched->max_cpu.cpu + 1; char tstr[64]; char nstr[30]; @@ -2198,14 +2196,15 @@ static void timehist_print_sample(struct perf_sched *sched, } if (!thread__comm_set(thread)) { - const char *prev_comm = evsel__strval(evsel, sample, "prev_comm"); - thread__set_comm(thread, prev_comm, sample->time); + const char *prev_comm = perf_sample__strval(sample, "prev_comm"); + + thread__set_comm(thread, prev_comm, sample->time); } printf(" %-*s ", comm_width, timehist_get_commstr(thread)); if (sched->show_prio) - printf(" %-*s ", MAX_PRIO_STR_LEN, timehist_get_priostr(evsel, thread, sample)); + printf(" %-*s ", MAX_PRIO_STR_LEN, timehist_get_priostr(thread, sample)); wait_time = tr->dt_sleep + tr->dt_iowait + tr->dt_preempt; print_sched_time(wait_time, 6); @@ -2319,7 +2318,7 @@ static bool is_idle_sample(struct perf_sample *sample, { /* pid 0 == swapper == idle task */ if (evsel__name_is(evsel, "sched:sched_switch")) - return evsel__intval(evsel, sample, "prev_pid") == 0; + return perf_sample__intval(sample, "prev_pid") == 0; return sample->pid == 0; } @@ -2539,7 +2538,7 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, itr->last_thread = thread__get(thread); /* copy task callchain when entering to idle */ - if (evsel__intval(evsel, sample, "next_pid") == 0) + if (perf_sample__intval(sample, "next_pid") == 0) save_idle_callchain(sched, itr, sample); } } @@ -2572,7 +2571,7 @@ static bool timehist_skip_sample(struct perf_sched *sched, if (tr && tr->prio != -1) prio = tr->prio; else if (evsel__name_is(evsel, "sched:sched_switch")) - prio = evsel__intval(evsel, sample, "prev_prio"); + prio = perf_sample__intval(sample, "prev_prio"); if (prio != -1 && !test_bit(prio, sched->prio_bitmap)) { rc = true; @@ -2583,8 +2582,8 @@ static bool timehist_skip_sample(struct perf_sched *sched, if (sched->idle_hist) { if (!evsel__name_is(evsel, "sched:sched_switch")) rc = true; - else if (evsel__intval(evsel, sample, "prev_pid") != 0 && - evsel__intval(evsel, sample, "next_pid") != 0) + else if (perf_sample__intval(sample, "prev_pid") != 0 && + perf_sample__intval(sample, "next_pid") != 0) rc = true; } @@ -2647,7 +2646,7 @@ static int timehist_sched_wakeup_event(const struct perf_tool *tool, struct thread *thread; struct thread_runtime *tr = NULL; /* want pid of awakened task not pid in sample */ - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); thread = machine__findnew_thread(machine, 0, pid); if (thread == NULL) @@ -2686,8 +2685,8 @@ static void timehist_print_migration_event(struct perf_sched *sched, return; max_cpus = sched->max_cpu.cpu + 1; - ocpu = evsel__intval(evsel, sample, "orig_cpu"); - dcpu = evsel__intval(evsel, sample, "dest_cpu"); + ocpu = perf_sample__intval(sample, "orig_cpu"); + dcpu = perf_sample__intval(sample, "dest_cpu"); thread = machine__findnew_thread(machine, sample->pid, sample->tid); if (thread == NULL) @@ -2736,7 +2735,7 @@ static int timehist_migrate_task_event(const struct perf_tool *tool, struct thread *thread; struct thread_runtime *tr = NULL; /* want pid of migrated task not pid in sample */ - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); thread = machine__findnew_thread(machine, 0, pid); if (thread == NULL) @@ -2761,14 +2760,13 @@ static int timehist_migrate_task_event(const struct perf_tool *tool, return 0; } -static void timehist_update_task_prio(struct evsel *evsel, - struct perf_sample *sample, +static void timehist_update_task_prio(struct perf_sample *sample, struct machine *machine) { struct thread *thread; struct thread_runtime *tr = NULL; - const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); - const u32 next_prio = evsel__intval(evsel, sample, "next_prio"); + const u32 next_pid = perf_sample__intval(sample, "next_pid"); + const u32 next_prio = perf_sample__intval(sample, "next_prio"); if (next_pid == 0) thread = get_idle_thread(sample->cpu); @@ -2798,7 +2796,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, struct thread_runtime *tr = NULL; u64 tprev, t = sample->time; int rc = 0; - const char state = evsel__taskstate(evsel, sample, "prev_state"); + const char state = perf_sample__taskstate(sample, "prev_state"); addr_location__init(&al); if (machine__resolve(machine, &al, sample) < 0) { @@ -2809,7 +2807,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, } if (sched->show_prio || sched->prio_str) - timehist_update_task_prio(evsel, sample, machine); + timehist_update_task_prio(sample, machine); thread = timehist_get_thread(sched, sample, machine, evsel); if (thread == NULL) { @@ -2891,7 +2889,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, } if (!sched->summary_only) - timehist_print_sample(sched, evsel, sample, &al, thread, t, state); + timehist_print_sample(sched, sample, &al, thread, t, state); } out: diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index f3f0e4ec0502..b3f2ce52938d 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -597,12 +597,12 @@ static int process_sample_event(const struct perf_tool *tool, static int process_sample_cpu_idle(struct timechart *tchart __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u32 state = evsel__intval(evsel, sample, "state"); - u32 cpu_id = evsel__intval(evsel, sample, "cpu_id"); + u32 state = perf_sample__intval(sample, "state"); + u32 cpu_id = perf_sample__intval(sample, "cpu_id"); if (state == (u32)PWR_EVENT_EXIT) c_state_end(tchart, cpu_id, sample->time); @@ -613,12 +613,12 @@ process_sample_cpu_idle(struct timechart *tchart __maybe_unused, static int process_sample_cpu_frequency(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u32 state = evsel__intval(evsel, sample, "state"); - u32 cpu_id = evsel__intval(evsel, sample, "cpu_id"); + u32 state = perf_sample__intval(sample, "state"); + u32 cpu_id = perf_sample__intval(sample, "cpu_id"); p_state_change(tchart, cpu_id, sample->time, state); return 0; @@ -626,13 +626,13 @@ process_sample_cpu_frequency(struct timechart *tchart, static int process_sample_sched_wakeup(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { - u8 flags = evsel__intval(evsel, sample, "common_flags"); - int waker = evsel__intval(evsel, sample, "common_pid"); - int wakee = evsel__intval(evsel, sample, "pid"); + u8 flags = perf_sample__intval(sample, "common_flags"); + int waker = perf_sample__intval(sample, "common_pid"); + int wakee = perf_sample__intval(sample, "pid"); sched_wakeup(tchart, sample->cpu, sample->time, waker, wakee, flags, backtrace); return 0; @@ -640,13 +640,13 @@ process_sample_sched_wakeup(struct timechart *tchart, static int process_sample_sched_switch(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { - int prev_pid = evsel__intval(evsel, sample, "prev_pid"); - int next_pid = evsel__intval(evsel, sample, "next_pid"); - u64 prev_state = evsel__intval(evsel, sample, "prev_state"); + int prev_pid = perf_sample__intval(sample, "prev_pid"); + int next_pid = perf_sample__intval(sample, "next_pid"); + u64 prev_state = perf_sample__intval(sample, "prev_state"); sched_switch(tchart, sample->cpu, sample->time, prev_pid, next_pid, prev_state, backtrace); @@ -656,12 +656,12 @@ process_sample_sched_switch(struct timechart *tchart, #ifdef SUPPORT_OLD_POWER_EVENTS static int process_sample_power_start(struct timechart *tchart __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u64 cpu_id = evsel__intval(evsel, sample, "cpu_id"); - u64 value = evsel__intval(evsel, sample, "value"); + u64 cpu_id = perf_sample__intval(sample, "cpu_id"); + u64 value = perf_sample__intval(sample, "value"); c_state_start(cpu_id, sample->time, value); return 0; @@ -679,12 +679,12 @@ process_sample_power_end(struct timechart *tchart, static int process_sample_power_frequency(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u64 cpu_id = evsel__intval(evsel, sample, "cpu_id"); - u64 value = evsel__intval(evsel, sample, "value"); + u64 cpu_id = perf_sample__intval(sample, "cpu_id"); + u64 value = perf_sample__intval(sample, "value"); p_state_change(tchart, cpu_id, sample->time, value); return 0; @@ -849,120 +849,120 @@ static int pid_end_io_sample(struct timechart *tchart, int pid, int type, static int process_enter_read(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ, sample->time, fd); } static int process_exit_read(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_READ, sample->time, ret); } static int process_enter_write(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE, sample->time, fd); } static int process_exit_write(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_WRITE, sample->time, ret); } static int process_enter_sync(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC, sample->time, fd); } static int process_exit_sync(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_SYNC, sample->time, ret); } static int process_enter_tx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX, sample->time, fd); } static int process_exit_tx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_TX, sample->time, ret); } static int process_enter_rx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX, sample->time, fd); } static int process_exit_rx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_RX, sample->time, ret); } static int process_enter_poll(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL, sample->time, fd); } static int process_exit_poll(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_POLL, sample->time, ret); } diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index cb2d72c2a921..a092405e84aa 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3058,7 +3058,7 @@ errno_print: { return err; } -static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, +static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3067,7 +3067,7 @@ static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, size_t filename_len, entry_str_len, to_move; ssize_t remaining_space; char *pos; - const char *filename = evsel__rawptr(evsel, sample, "pathname"); + const char *filename = perf_sample__rawptr(sample, "pathname"); if (!thread) goto out; @@ -3123,7 +3123,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, union perf_event *event __maybe_unused, struct perf_sample *sample) { - u64 runtime = evsel__intval(evsel, sample, "runtime"); + u64 runtime = perf_sample__intval(sample, "runtime"); double runtime_ms = (double)runtime / NSEC_PER_MSEC; struct thread *thread = machine__findnew_thread(trace->host, sample->pid, @@ -3142,10 +3142,10 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, out_dump: fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", evsel->name, - evsel__strval(evsel, sample, "comm"), - (pid_t)evsel__intval(evsel, sample, "pid"), + perf_sample__strval(sample, "comm"), + (pid_t)perf_sample__intval(sample, "pid"), runtime, - evsel__intval(evsel, sample, "vruntime")); + perf_sample__intval(sample, "vruntime")); goto out_put; } diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c index 2a139d2781a8..97550b349418 100644 --- a/tools/perf/tests/openat-syscall-tp-fields.c +++ b/tools/perf/tests/openat-syscall-tp-fields.c @@ -118,7 +118,7 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused goto out_delete_evlist; } - tp_flags = evsel__intval(evsel, &sample, "flags"); + tp_flags = perf_sample__intval(&sample, "flags"); perf_sample__exit(&sample); if (flags != tp_flags) { pr_debug("%s: Expected flags=%#x, got %#x\n", diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index 15791fcb76b2..a7ea4b7874be 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -140,8 +140,8 @@ static int process_sample_event(struct evlist *evlist, evsel = evlist__id2evsel(evlist, sample.id); if (evsel == switch_tracking->switch_evsel) { - next_tid = evsel__intval(evsel, &sample, "next_pid"); - prev_tid = evsel__intval(evsel, &sample, "prev_pid"); + next_tid = perf_sample__intval(&sample, "next_pid"); + prev_tid = perf_sample__intval(&sample, "prev_pid"); cpu = sample.cpu; pr_debug3("sched_switch: cpu: %d prev_tid %d next_tid %d\n", cpu, prev_tid, next_tid); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index a7da54d365a9..041766d39ec3 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3679,9 +3679,9 @@ struct tep_format_field *evsel__common_field(struct evsel *evsel, const char *na return tp_format ? tep_find_common_field(tp_format, name) : NULL; } -void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name) +void *perf_sample__rawptr(struct perf_sample *sample, const char *name) { - struct tep_format_field *field = evsel__field(evsel, name); + struct tep_format_field *field = evsel__field(sample->evsel, name); int offset; if (!field) @@ -3738,21 +3738,21 @@ u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sam return 0; } -u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name) +u64 perf_sample__intval(struct perf_sample *sample, const char *name) { - struct tep_format_field *field = evsel__field(evsel, name); + struct tep_format_field *field = evsel__field(sample->evsel, name); - return field ? format_field__intval(field, sample, evsel->needs_swap) : 0; + return field ? format_field__intval(field, sample, sample->evsel->needs_swap) : 0; } -u64 evsel__intval_common(struct evsel *evsel, struct perf_sample *sample, const char *name) +u64 perf_sample__intval_common(struct perf_sample *sample, const char *name) { - struct tep_format_field *field = evsel__common_field(evsel, name); + struct tep_format_field *field = evsel__common_field(sample->evsel, name); - return field ? format_field__intval(field, sample, evsel->needs_swap) : 0; + return field ? format_field__intval(field, sample, sample->evsel->needs_swap) : 0; } -char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const char *name) +char perf_sample__taskstate(struct perf_sample *sample, const char *name) { static struct tep_format_field *prev_state_field; static const char *states; @@ -3761,7 +3761,7 @@ char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const cha unsigned int bit; char state = '?'; /* '?' denotes unknown task state */ - field = evsel__field(evsel, name); + field = evsel__field(sample->evsel, name); if (!field) return state; @@ -3780,7 +3780,7 @@ char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const cha * * We can change this if we have a good reason in the future. */ - val = evsel__intval(evsel, sample, name); + val = perf_sample__intval(sample, name); bit = val ? ffs(val) : 0; state = (!bit || bit > strlen(states)) ? 'R' : states[bit-1]; return state; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index a3d754c029a0..c9d3e6de9677 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -369,14 +369,14 @@ bool evsel__precise_ip_fallback(struct evsel *evsel); struct perf_sample; #ifdef HAVE_LIBTRACEEVENT -void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name); -u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name); -u64 evsel__intval_common(struct evsel *evsel, struct perf_sample *sample, const char *name); -char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const char *name); +void *perf_sample__rawptr(struct perf_sample *sample, const char *name); +u64 perf_sample__intval(struct perf_sample *sample, const char *name); +u64 perf_sample__intval_common(struct perf_sample *sample, const char *name); +char perf_sample__taskstate(struct perf_sample *sample, const char *name); -static inline char *evsel__strval(struct evsel *evsel, struct perf_sample *sample, const char *name) +static inline char *perf_sample__strval(struct perf_sample *sample, const char *name) { - return evsel__rawptr(evsel, sample, name); + return perf_sample__rawptr(sample, name); } #endif diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index fc9eec8b54b8..dab23a96b1d8 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -3426,7 +3426,7 @@ static int intel_pt_process_switch(struct intel_pt *pt, if (evsel != pt->switch_evsel) return 0; - tid = evsel__intval(evsel, sample, "next_pid"); + tid = perf_sample__intval(sample, "next_pid"); cpu = sample->cpu; intel_pt_log("sched_switch: cpu %d tid %d time %"PRIu64" tsc %#"PRIx64"\n", diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c index 1e76906f719c..018b0db0e6e7 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c @@ -20,10 +20,8 @@ static const char * const __kvm_events_tp[] = { static void event_get_key(struct perf_sample *sample, struct event_key *key) { - struct evsel *evsel = sample->evsel; - key->info = 0; - key->key = evsel__intval(evsel, sample, kvm_exit_reason(EM_AARCH64)); + key->key = perf_sample__intval(sample, kvm_exit_reason(EM_AARCH64)); key->exit_reasons = arm64_exit_reasons; /* @@ -32,7 +30,7 @@ static void event_get_key(struct perf_sample *sample, * properly decode event's est_ec. */ if (key->key == ARM_EXCEPTION_TRAP) { - key->key = evsel__intval(evsel, sample, kvm_trap_exit_reason); + key->key = perf_sample__intval(sample, kvm_trap_exit_reason); key->exit_reasons = arm64_trap_exit_reasons; } } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c index 9d6265290f6d..a04cd09e3361 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c @@ -78,7 +78,7 @@ static void event_gspr_get_key(struct perf_sample *sample, struct event_key *key unsigned int insn; key->key = LOONGARCH_EXCEPTION_OTHERS; - insn = evsel__intval(sample->evsel, sample, "inst_word"); + insn = perf_sample__intval(sample, "inst_word"); switch (insn >> 24) { case 0: diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c index 5158d7e88ee6..96d9c4ae0209 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c @@ -32,7 +32,7 @@ static void hcall_event_get_key(struct perf_sample *sample, struct event_key *key) { key->info = 0; - key->key = evsel__intval(sample->evsel, sample, "req"); + key->key = perf_sample__intval(sample, "req"); } static const char *get_hcall_exit_reason(u64 exit_code) diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c index e8db8b4f8e2e..967bba261a47 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c @@ -26,8 +26,7 @@ static void event_get_key(struct perf_sample *sample, int xlen = 64; // TODO: 32-bit support. key->info = 0; - key->key = evsel__intval(sample->evsel, sample, - kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); + key->key = perf_sample__intval(sample, kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); key->exit_reasons = riscv_exit_reasons; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c index 158372ba0205..4771fc69fa39 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c @@ -23,7 +23,7 @@ static void event_icpt_insn_get_key(struct perf_sample *sample, { u64 insn; - insn = evsel__intval(sample->evsel, sample, "instruction"); + insn = perf_sample__intval(sample, "instruction"); key->key = icpt_insn_decoder(insn); key->exit_reasons = sie_icpt_insn_codes; } @@ -31,21 +31,21 @@ static void event_icpt_insn_get_key(struct perf_sample *sample, static void event_sigp_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "order_code"); + key->key = perf_sample__intval(sample, "order_code"); key->exit_reasons = sie_sigp_order_codes; } static void event_diag_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "code"); + key->key = perf_sample__intval(sample, "code"); key->exit_reasons = sie_diagnose_codes; } static void event_icpt_prog_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "code"); + key->key = perf_sample__intval(sample, "code"); key->exit_reasons = sie_icpt_prog_codes; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c index a7993e945d8b..dd1f78bf621c 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c @@ -27,8 +27,8 @@ static const struct kvm_events_ops exit_events = { static void mmio_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "gpa"); - key->info = evsel__intval(sample->evsel, sample, "type"); + key->key = perf_sample__intval(sample, "gpa"); + key->info = perf_sample__intval(sample, "type"); } #define KVM_TRACE_MMIO_READ_UNSATISFIED 0 @@ -43,7 +43,7 @@ static bool mmio_event_begin(struct perf_sample *sample, struct event_key *key) /* MMIO write begin event in kernel. */ if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && - evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { + perf_sample__intval(sample, "type") == KVM_TRACE_MMIO_WRITE) { mmio_event_get_key(sample, key); return true; } @@ -59,7 +59,7 @@ static bool mmio_event_end(struct perf_sample *sample, struct event_key *key) /* MMIO read end event in kernel.*/ if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && - evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_READ) { + perf_sample__intval(sample, "type") == KVM_TRACE_MMIO_READ) { mmio_event_get_key(sample, key); return true; } @@ -87,8 +87,8 @@ static const struct kvm_events_ops mmio_events = { static void ioport_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "port"); - key->info = evsel__intval(sample->evsel, sample, "rw"); + key->key = perf_sample__intval(sample, "port"); + key->info = perf_sample__intval(sample, "rw"); } static bool ioport_event_begin(struct perf_sample *sample, @@ -126,8 +126,8 @@ static const struct kvm_events_ops ioport_events = { /* The time of emulation msr is from kvm_msr to kvm_entry. */ static void msr_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "ecx"); - key->info = evsel__intval(sample->evsel, sample, "write"); + key->key = perf_sample__intval(sample, "ecx"); + key->info = perf_sample__intval(sample, "write"); } static bool msr_event_begin(struct perf_sample *sample, struct event_key *key) diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c index f17a6132958d..755ab659a05c 100644 --- a/tools/perf/util/kvm-stat.c +++ b/tools/perf/util/kvm-stat.c @@ -17,7 +17,7 @@ void exit_event_get_key(struct perf_sample *sample, uint16_t e_machine = evsel__e_machine(sample->evsel, /*e_flags=*/NULL); key->info = 0; - key->key = evsel__intval(sample->evsel, sample, kvm_exit_reason(e_machine)); + key->key = perf_sample__intval(sample, kvm_exit_reason(e_machine)); } -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 07/25] perf trace: Don't pass evsel with sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (5 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 08/25] perf callchain: Don't pass evsel and sample Ian Rogers ` (20 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The sample now contains the evsel and so don't unnecessarily pass the evsel. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-trace.c | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index a092405e84aa..7a0913595943 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -536,12 +536,12 @@ static struct evsel *perf_evsel__raw_syscall_newtp(const char *direction, void * return NULL; } -#define perf_evsel__sc_tp_uint(evsel, name, sample) \ - ({ struct syscall_tp *fields = __evsel__syscall_tp(evsel); \ +#define perf_evsel__sc_tp_uint(name, sample) \ + ({ struct syscall_tp *fields = __evsel__syscall_tp(sample->evsel); \ fields->name.integer(&fields->name, sample); }) -#define perf_evsel__sc_tp_ptr(evsel, name, sample) \ - ({ struct syscall_tp *fields = __evsel__syscall_tp(evsel); \ +#define perf_evsel__sc_tp_ptr(name, sample) \ + ({ struct syscall_tp *fields = __evsel__syscall_tp(sample->evsel); \ fields->name.pointer(&fields->name, sample); }) size_t strarray__scnprintf_suffix(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_suffix, int val) @@ -2718,8 +2718,8 @@ static int trace__printf_interrupted_entry(struct trace *trace) return printed; } -static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, - struct perf_sample *sample, struct thread *thread) +static int trace__fprintf_sample(struct trace *trace, struct perf_sample *sample, + struct thread *thread) { int printed = 0; @@ -2727,7 +2727,7 @@ static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, double ts = (double)sample->time / NSEC_PER_MSEC; printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n", - evsel__name(evsel), ts, + evsel__name(sample->evsel), ts, thread__comm_str(thread), sample->pid, sample->tid, sample->cpu); } @@ -2782,7 +2782,7 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel, void *args; int printed = 0; struct thread *thread; - int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; + int id = perf_evsel__sc_tp_uint(id, sample), err = -1; int augmented_args_size = 0, e_machine; void *augmented_args = NULL; struct syscall *sc; @@ -2797,9 +2797,9 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel, if (ttrace == NULL) goto out_put; - trace__fprintf_sample(trace, evsel, sample, thread); + trace__fprintf_sample(trace, sample, thread); - args = perf_evsel__sc_tp_ptr(evsel, args, sample); + args = perf_evsel__sc_tp_ptr(args, sample); if (ttrace->entry_str == NULL) { ttrace->entry_str = malloc(trace__entry_str_size); @@ -2854,12 +2854,11 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel, return err; } -static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, - struct perf_sample *sample) +static int trace__fprintf_sys_enter(struct trace *trace, struct perf_sample *sample) { struct thread_trace *ttrace; struct thread *thread; - int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; + int id = perf_evsel__sc_tp_uint(id, sample), err = -1; struct syscall *sc; char msg[1024]; void *args, *augmented_args = NULL; @@ -2869,7 +2868,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); e_machine = thread__e_machine(thread, trace->host, /*e_flags=*/NULL); - sc = trace__syscall_info(trace, evsel, e_machine, id); + sc = trace__syscall_info(trace, sample->evsel, e_machine, id); if (sc == NULL) goto out_put; ttrace = thread__trace(thread, trace); @@ -2880,7 +2879,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, if (ttrace == NULL) goto out_put; - args = perf_evsel__sc_tp_ptr(evsel, args, sample); + args = perf_evsel__sc_tp_ptr(args, sample); augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_syscalls_args_size); printed += syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread); fprintf(trace->output, "%.*s", (int)printed, msg); @@ -2890,10 +2889,11 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, return err; } -static int trace__resolve_callchain(struct trace *trace, struct evsel *evsel, +static int trace__resolve_callchain(struct trace *trace, struct perf_sample *sample, struct callchain_cursor *cursor) { + struct evsel *evsel = sample->evsel; struct addr_location al; int max_stack = evsel->core.attr.sample_max_stack ? evsel->core.attr.sample_max_stack : @@ -2928,7 +2928,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, u64 duration = 0; bool duration_calculated = false; struct thread *thread; - int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1, callchain_ret = 0, printed = 0; + int id = perf_evsel__sc_tp_uint(id, sample), err = -1, callchain_ret = 0, printed = 0; int alignment = trace->args_alignment, e_machine; struct syscall *sc; struct thread_trace *ttrace; @@ -2942,9 +2942,9 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, if (ttrace == NULL) goto out_put; - trace__fprintf_sample(trace, evsel, sample, thread); + trace__fprintf_sample(trace, sample, thread); - ret = perf_evsel__sc_tp_uint(evsel, ret, sample); + ret = perf_evsel__sc_tp_uint(ret, sample); if (trace->summary) thread__update_stats(thread, ttrace, id, sample, ret, trace); @@ -2966,7 +2966,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, if (sample->callchain) { struct callchain_cursor *cursor = get_tls_callchain_cursor(); - callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret = trace__resolve_callchain(trace, sample, cursor); if (callchain_ret == 0) { if (cursor->nr < trace->min_stack) goto out; @@ -3181,9 +3181,10 @@ static void bpf_output__fprintf(struct trace *trace, ++trace->nr_events_printed; } -static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample *sample, +static size_t trace__fprintf_tp_fields(struct trace *trace, struct perf_sample *sample, struct thread *thread, void *augmented_args, int augmented_args_size) { + struct evsel *evsel = sample->evsel; char bf[2048]; size_t size = sizeof(bf); const struct tep_event *tp_format = evsel__tp_format(evsel); @@ -3266,7 +3267,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, if (sample->callchain) { struct callchain_cursor *cursor = get_tls_callchain_cursor(); - callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret = trace__resolve_callchain(trace, sample, cursor); if (callchain_ret == 0) { if (cursor->nr < trace->min_stack) goto out; @@ -3284,7 +3285,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, trace__fprintf_comm_tid(trace, thread, trace->output); if (evsel == trace->syscalls.events.bpf_output) { - int id = perf_evsel__sc_tp_uint(evsel, id, sample); + int id = perf_evsel__sc_tp_uint(id, sample); int e_machine = thread ? thread__e_machine(thread, trace->host, /*e_flags=*/NULL) : EM_HOST; @@ -3292,7 +3293,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, if (sc) { fprintf(trace->output, "%s(", sc->name); - trace__fprintf_sys_enter(trace, evsel, sample); + trace__fprintf_sys_enter(trace, sample); fputc(')', trace->output); goto newline; } @@ -3312,13 +3313,13 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, const struct tep_event *tp_format = evsel__tp_format(evsel); if (tp_format && (strncmp(tp_format->name, "sys_enter_", 10) || - trace__fprintf_sys_enter(trace, evsel, sample))) { + trace__fprintf_sys_enter(trace, sample))) { if (trace->libtraceevent_print) { event_format__fprintf(tp_format, sample->cpu, sample->raw_data, sample->raw_size, trace->output); } else { - trace__fprintf_tp_fields(trace, evsel, sample, thread, NULL, 0); + trace__fprintf_tp_fields(trace, sample, thread, NULL, 0); } } } @@ -3377,7 +3378,7 @@ static int trace__pgfault(struct trace *trace, if (sample->callchain) { struct callchain_cursor *cursor = get_tls_callchain_cursor(); - callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret = trace__resolve_callchain(trace, sample, cursor); if (callchain_ret == 0) { if (cursor->nr < trace->min_stack) goto out_put; -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 08/25] perf callchain: Don't pass evsel and sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (6 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 07/25] perf trace: Don't pass evsel with sample Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 09/25] perf lock: Only pass sample to handlers Ian Rogers ` (19 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel Change callchain resolve code to not pass an evsel with the sample, instead just read the evsel from the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-inject.c | 4 ++-- tools/perf/builtin-kmem.c | 6 ++--- tools/perf/builtin-kwork.c | 5 ++-- tools/perf/builtin-lock.c | 24 +++++++++---------- tools/perf/builtin-sched.c | 5 ++-- tools/perf/builtin-script.c | 6 ++--- tools/perf/builtin-trace.c | 2 +- tools/perf/util/build-id.c | 2 +- tools/perf/util/callchain.c | 8 +++---- tools/perf/util/callchain.h | 5 ++-- tools/perf/util/db-export.c | 8 +++---- tools/perf/util/hist.c | 2 +- tools/perf/util/machine.c | 14 +++++------ tools/perf/util/machine.h | 3 --- .../util/scripting-engines/trace-event-perl.c | 2 +- .../scripting-engines/trace-event-python.c | 2 +- 17 files changed, 46 insertions(+), 54 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 89456ba6fcbb..f9ac871264af 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -339,7 +339,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, cursor = get_tls_callchain_cursor(); ret = sample__resolve_callchain(sample, cursor, NULL, - evsel, &al, sysctl_perf_event_max_stack); + &al, sysctl_perf_event_max_stack); if (ret) goto out; diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 3226ab326315..016ad84ac4ab 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -418,7 +418,7 @@ static int perf_event__convert_sample_callchain(const struct perf_tool *tool, goto out; /* this will parse DWARF using stack and register data */ - ret = thread__resolve_callchain(thread, cursor, evsel, sample, + ret = thread__resolve_callchain(thread, cursor, sample, /*parent=*/NULL, /*root_al=*/NULL, PERF_MAX_STACK_DEPTH); thread__put(thread); @@ -1020,7 +1020,7 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e } sample->evsel = inject__mmap_evsel(inject); - sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, &args); sample->evsel = saved_evsel; thread__put(thread); diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 96b78a64c1c1..19b12209fc08 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -394,7 +394,7 @@ static int build_alloc_func_list(void) * Find first non-memory allocation function from callchain. * The allocation functions are in the 'alloc_func_list'. */ -static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample) +static u64 find_callsite(struct perf_sample *sample) { struct addr_location al; struct machine *machine = &kmem_session->machines.host; @@ -414,7 +414,7 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample) if (cursor == NULL) goto out; - sample__resolve_callchain(sample, cursor, NULL, evsel, &al, 16); + sample__resolve_callchain(sample, cursor, /*parent=*/NULL, &al, 16); callchain_cursor_commit(cursor); while (true) { @@ -839,7 +839,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) return -1; - callsite = find_callsite(evsel, sample); + callsite = find_callsite(sample); /* * This is to find the current page (with correct gfp flags and diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index f47b54a68726..bd62616af476 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -688,7 +688,6 @@ static int latency_entry_event(struct perf_kwork *kwork, static void timehist_save_callchain(struct perf_kwork *kwork, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct symbol *sym; @@ -708,7 +707,7 @@ static void timehist_save_callchain(struct perf_kwork *kwork, cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(thread, cursor, evsel, sample, + if (thread__resolve_callchain(thread, cursor, sample, NULL, NULL, kwork->max_stack + 2) != 0) { pr_debug("Failed to resolve callchain, skipping\n"); goto out_put; @@ -838,7 +837,7 @@ static int timehist_entry_event(struct perf_kwork *kwork, return ret; if (work != NULL) - timehist_save_callchain(kwork, sample, evsel, machine); + timehist_save_callchain(kwork, sample, machine); return 0; } diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index baf0c99df5df..a35e8ea4e2ef 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -551,13 +551,13 @@ static int get_key_by_aggr_mode_simple(u64 *key, u64 addr, u32 tid) return 0; } -static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample); +static u64 callchain_id(struct perf_sample *sample); -static int get_key_by_aggr_mode(u64 *key, u64 addr, struct evsel *evsel, +static int get_key_by_aggr_mode(u64 *key, u64 addr, struct perf_sample *sample) { if (aggr_mode == LOCK_AGGR_CALLER) { - *key = callchain_id(evsel, sample); + *key = callchain_id(sample); return 0; } return get_key_by_aggr_mode_simple(key, addr, sample->tid); @@ -841,7 +841,7 @@ static int get_symbol_name_offset(struct map *map, struct symbol *sym, u64 ip, else return strlcpy(buf, sym->name, size); } -static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sample, +static int lock_contention_caller(struct perf_sample *sample, char *buf, int size) { struct thread *thread; @@ -862,7 +862,7 @@ static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sampl cursor = get_tls_callchain_cursor(); /* use caller function name from the callchain */ - ret = thread__resolve_callchain(thread, cursor, evsel, sample, + ret = thread__resolve_callchain(thread, cursor, sample, NULL, NULL, max_stack_depth); if (ret != 0) { thread__put(thread); @@ -896,7 +896,7 @@ static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sampl return -1; } -static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample) +static u64 callchain_id(struct perf_sample *sample) { struct callchain_cursor *cursor; struct machine *machine = &session->machines.host; @@ -911,7 +911,7 @@ static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample) cursor = get_tls_callchain_cursor(); /* use caller function name from the callchain */ - ret = thread__resolve_callchain(thread, cursor, evsel, sample, + ret = thread__resolve_callchain(thread, cursor, sample, NULL, NULL, max_stack_depth); thread__put(thread); @@ -963,7 +963,7 @@ static u64 *get_callstack(struct perf_sample *sample, int max_stack) return callstack; } -static int report_lock_contention_begin_event(struct evsel *evsel, +static int report_lock_contention_begin_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; @@ -978,7 +978,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, struct map *kmap; struct symbol *sym; - ret = get_key_by_aggr_mode(&key, addr, evsel, sample); + ret = get_key_by_aggr_mode(&key, addr, sample); if (ret < 0) return ret; @@ -1025,7 +1025,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, break; case LOCK_AGGR_CALLER: name = buf; - if (lock_contention_caller(evsel, sample, buf, sizeof(buf)) < 0) + if (lock_contention_caller(sample, buf, sizeof(buf)) < 0) name = "Unknown"; break; case LOCK_AGGR_CGROUP: @@ -1127,7 +1127,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, return 0; } -static int report_lock_contention_end_event(struct evsel *evsel, +static int report_lock_contention_end_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; @@ -1138,7 +1138,7 @@ static int report_lock_contention_end_event(struct evsel *evsel, u64 key; int ret; - ret = get_key_by_aggr_mode(&key, addr, evsel, sample); + ret = get_key_by_aggr_mode(&key, addr, sample); if (ret < 0) return ret; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index c2bf187104b2..0580dc20720f 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -2325,7 +2325,6 @@ static bool is_idle_sample(struct perf_sample *sample, static void save_task_callchain(struct perf_sched *sched, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct callchain_cursor *cursor; @@ -2345,7 +2344,7 @@ static void save_task_callchain(struct perf_sched *sched, cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(thread, cursor, evsel, sample, + if (thread__resolve_callchain(thread, cursor, sample, NULL, NULL, sched->max_stack + 2) != 0) { if (verbose > 0) pr_err("Failed to resolve callchain. Skipping\n"); @@ -2519,7 +2518,7 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, sample->tid); } - save_task_callchain(sched, sample, evsel, machine); + save_task_callchain(sched, sample, machine); if (sched->idle_hist) { struct thread *idle; struct idle_thread_runtime *itr; diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 28fe3ff02cf5..7788a6934a8d 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1679,7 +1679,7 @@ static int perf_sample__fprintf_bts(struct perf_sample *sample, if (symbol_conf.use_callchain && sample->callchain) { cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack)) cursor = NULL; @@ -2502,7 +2502,7 @@ static void process_event(struct perf_script *script, if (symbol_conf.use_callchain && sample->callchain) { cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack)) cursor = NULL; @@ -2786,7 +2786,7 @@ static int process_deferred_sample_event(const struct perf_tool *tool, if (symbol_conf.use_callchain && sample->callchain) { cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al.thread, cursor, evsel, + if (thread__resolve_callchain(al.thread, cursor, sample, NULL, NULL, scripting_max_stack)) { pr_info("cannot resolve deferred callchains\n"); diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 7a0913595943..b6e90ee53cbe 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2904,7 +2904,7 @@ static int trace__resolve_callchain(struct trace *trace, if (machine__resolve(trace->host, &al, sample) < 0) goto out; - err = thread__resolve_callchain(al.thread, cursor, evsel, sample, NULL, NULL, max_stack); + err = thread__resolve_callchain(al.thread, cursor, sample, NULL, NULL, max_stack); out: addr_location__exit(&al); return err; diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 55b72235f891..af4d874f1381 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -73,7 +73,7 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, addr_location__exit(&al); - sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, /*data=*/NULL); diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 8ff0898799ee..4f485ed046a4 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1123,7 +1123,7 @@ int callchain_cursor_append(struct callchain_cursor *cursor, int sample__resolve_callchain(struct perf_sample *sample, struct callchain_cursor *cursor, struct symbol **parent, - struct evsel *evsel, struct addr_location *al, + struct addr_location *al, int max_stack) { if (sample->callchain == NULL && !symbol_conf.show_branchflag_count) @@ -1131,7 +1131,7 @@ int sample__resolve_callchain(struct perf_sample *sample, if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain || perf_hpp_list.parent || symbol_conf.show_branchflag_count) { - return thread__resolve_callchain(al->thread, cursor, evsel, sample, + return thread__resolve_callchain(al->thread, cursor, sample, parent, al, max_stack); } return 0; @@ -1806,7 +1806,7 @@ s64 callchain_avg_cycles(struct callchain_node *cnode) return cycles; } -int sample__for_each_callchain_node(struct thread *thread, struct evsel *evsel, +int sample__for_each_callchain_node(struct thread *thread, struct perf_sample *sample, int max_stack, bool symbols, callchain_iter_fn cb, void *data) { @@ -1817,7 +1817,7 @@ int sample__for_each_callchain_node(struct thread *thread, struct evsel *evsel, return -ENOMEM; /* Fill in the callchain. */ - ret = __thread__resolve_callchain(thread, cursor, evsel, sample, + ret = __thread__resolve_callchain(thread, cursor, sample, /*parent=*/NULL, /*root_al=*/NULL, max_stack, symbols); if (ret) diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index df54ddb8c0cb..6eb3e20349a9 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -8,7 +8,6 @@ #include "branch.h" struct addr_location; -struct evsel; struct ip_callchain; struct map; struct perf_sample; @@ -251,7 +250,7 @@ int record_opts__parse_callchain(struct record_opts *record, int sample__resolve_callchain(struct perf_sample *sample, struct callchain_cursor *cursor, struct symbol **parent, - struct evsel *evsel, struct addr_location *al, + struct addr_location *al, int max_stack); int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample); int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node, @@ -314,7 +313,7 @@ s64 callchain_avg_cycles(struct callchain_node *cnode); typedef int (*callchain_iter_fn)(struct callchain_cursor_node *node, void *data); -int sample__for_each_callchain_node(struct thread *thread, struct evsel *evsel, +int sample__for_each_callchain_node(struct thread *thread, struct perf_sample *sample, int max_stack, bool symbols, callchain_iter_fn cb, void *data); diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index ae9a9065aab7..a1f578c3a8d5 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -209,8 +209,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al, static struct call_path *call_path_from_sample(struct db_export *dbe, struct machine *machine, struct thread *thread, - struct perf_sample *sample, - struct evsel *evsel) + struct perf_sample *sample) { u64 kernel_start = machine__kernel_start(machine); struct call_path *current = &dbe->cpr->call_path; @@ -228,7 +227,7 @@ static struct call_path *call_path_from_sample(struct db_export *dbe, */ callchain_param.order = ORDER_CALLER; cursor = get_tls_callchain_cursor(); - err = thread__resolve_callchain(thread, cursor, evsel, + err = thread__resolve_callchain(thread, cursor, sample, NULL, NULL, PERF_MAX_STACK_DEPTH); if (err) { callchain_param.order = saved_order; @@ -391,8 +390,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, if (dbe->cpr) { struct call_path *cp = call_path_from_sample(dbe, machine, - thread, sample, - evsel); + thread, sample); if (cp) { db_export__call_path(dbe, cp); es.call_path_id = cp->db_id; diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 7ffaa3d9851b..84a402d248a3 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -1339,7 +1339,7 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, alm = map__get(al->map); err = sample__resolve_callchain(iter->sample, get_tls_callchain_cursor(), &iter->parent, - iter->evsel, al, max_stack_depth); + al, max_stack_depth); if (err) { map__put(alm); return err; diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index e76f8c86e62a..c2e0a99efe97 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2778,13 +2778,13 @@ static u64 get_leaf_frame_caller(struct perf_sample *sample, static int thread__resolve_callchain_sample(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, int max_stack, bool symbols) { + struct evsel *evsel = sample->evsel; struct branch_stack *branch = sample->branch_stack; struct branch_entry *entries = perf_sample__branch_entries(sample); struct ip_callchain *chain = sample->callchain; @@ -2986,10 +2986,11 @@ static int unwind_entry(struct unwind_entry *entry, void *arg) static int thread__resolve_callchain_unwind(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, int max_stack, bool symbols) { + struct evsel *evsel = sample->evsel; + /* Can we do dwarf post unwind? */ if (!((evsel->core.attr.sample_type & PERF_SAMPLE_REGS_USER) && (evsel->core.attr.sample_type & PERF_SAMPLE_STACK_USER))) @@ -3009,7 +3010,6 @@ static int thread__resolve_callchain_unwind(struct thread *thread, int __thread__resolve_callchain(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, @@ -3025,22 +3025,22 @@ int __thread__resolve_callchain(struct thread *thread, if (callchain_param.order == ORDER_CALLEE) { ret = thread__resolve_callchain_sample(thread, cursor, - evsel, sample, + sample, parent, root_al, max_stack, symbols); if (ret) return ret; ret = thread__resolve_callchain_unwind(thread, cursor, - evsel, sample, + sample, max_stack, symbols); } else { ret = thread__resolve_callchain_unwind(thread, cursor, - evsel, sample, + sample, max_stack, symbols); if (ret) return ret; ret = thread__resolve_callchain_sample(thread, cursor, - evsel, sample, + sample, parent, root_al, max_stack, symbols); } diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index 22a42c5825fa..048b24e9bd38 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -187,7 +187,6 @@ struct callchain_cursor; int __thread__resolve_callchain(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, @@ -196,7 +195,6 @@ int __thread__resolve_callchain(struct thread *thread, static inline int thread__resolve_callchain(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, @@ -204,7 +202,6 @@ static inline int thread__resolve_callchain(struct thread *thread, { return __thread__resolve_callchain(thread, cursor, - evsel, sample, parent, root_al, diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index e261a57b87d4..850a0048df82 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -272,7 +272,7 @@ static SV *perl_process_callchain(struct perf_sample *sample, cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack) != 0) { pr_err("Failed to resolve callchain. Skipping\n"); goto exit; diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 2b0df7bd9a46..0d8665c75d30 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -404,7 +404,7 @@ static PyObject *python_process_callchain(struct perf_sample *sample, goto exit; cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack) != 0) { pr_err("Failed to resolve callchain. Skipping\n"); -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 09/25] perf lock: Only pass sample to handlers 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (7 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 08/25] perf callchain: Don't pass evsel and sample Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 10/25] perf lock: Constify trace_lock_handler variables Ian Rogers ` (18 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The evsel is within the sample and so only the sample needs to be passed. Remove the parameter and fix call site. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-lock.c | 65 ++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index a35e8ea4e2ef..78fb39d06e7c 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -473,28 +473,22 @@ static struct lock_stat *pop_from_result(void) struct trace_lock_handler { /* it's used on CONFIG_LOCKDEP */ - int (*acquire_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*acquire_event)(struct perf_sample *sample); /* it's used on CONFIG_LOCKDEP && CONFIG_LOCK_STAT */ - int (*acquired_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*acquired_event)(struct perf_sample *sample); /* it's used on CONFIG_LOCKDEP && CONFIG_LOCK_STAT */ - int (*contended_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*contended_event)(struct perf_sample *sample); /* it's used on CONFIG_LOCKDEP */ - int (*release_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*release_event)(struct perf_sample *sample); /* it's used when CONFIG_LOCKDEP is off */ - int (*contention_begin_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*contention_begin_event)(struct perf_sample *sample); /* it's used when CONFIG_LOCKDEP is off */ - int (*contention_end_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*contention_end_event)(struct perf_sample *sample); }; static struct lock_seq_stat *get_seq(struct thread_stat *ts, u64 addr) @@ -563,8 +557,7 @@ static int get_key_by_aggr_mode(u64 *key, u64 addr, return get_key_by_aggr_mode_simple(key, addr, sample->tid); } -static int report_lock_acquire_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_acquire_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -638,8 +631,7 @@ static int report_lock_acquire_event(struct evsel *evsel __maybe_unused, return 0; } -static int report_lock_acquired_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_acquired_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -704,8 +696,7 @@ static int report_lock_acquired_event(struct evsel *evsel __maybe_unused, return 0; } -static int report_lock_contended_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_contended_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -762,8 +753,7 @@ static int report_lock_contended_event(struct evsel *evsel __maybe_unused, return 0; } -static int report_lock_release_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_release_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -963,8 +953,7 @@ static u64 *get_callstack(struct perf_sample *sample, int max_stack) return callstack; } -static int report_lock_contention_begin_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_contention_begin_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -1127,8 +1116,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel __maybe_unused return 0; } -static int report_lock_contention_end_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_contention_end_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -1208,45 +1196,45 @@ static struct trace_lock_handler contention_lock_ops = { static struct trace_lock_handler *trace_handler; -static int evsel__process_lock_acquire(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_acquire(struct perf_sample *sample) { if (trace_handler->acquire_event) - return trace_handler->acquire_event(evsel, sample); + return trace_handler->acquire_event(sample); return 0; } -static int evsel__process_lock_acquired(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_acquired(struct perf_sample *sample) { if (trace_handler->acquired_event) - return trace_handler->acquired_event(evsel, sample); + return trace_handler->acquired_event(sample); return 0; } -static int evsel__process_lock_contended(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_contended(struct perf_sample *sample) { if (trace_handler->contended_event) - return trace_handler->contended_event(evsel, sample); + return trace_handler->contended_event(sample); return 0; } -static int evsel__process_lock_release(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_release(struct perf_sample *sample) { if (trace_handler->release_event) - return trace_handler->release_event(evsel, sample); + return trace_handler->release_event(sample); return 0; } -static int evsel__process_contention_begin(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_contention_begin(struct perf_sample *sample) { if (trace_handler->contention_begin_event) - return trace_handler->contention_begin_event(evsel, sample); + return trace_handler->contention_begin_event(sample); return 0; } -static int evsel__process_contention_end(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_contention_end(struct perf_sample *sample) { if (trace_handler->contention_end_event) - return trace_handler->contention_end_event(evsel, sample); + return trace_handler->contention_end_event(sample); return 0; } @@ -1424,8 +1412,7 @@ static int process_event_update(const struct perf_tool *tool, return 0; } -typedef int (*tracepoint_handler)(struct evsel *evsel, - struct perf_sample *sample); +typedef int (*tracepoint_handler)(struct perf_sample *sample); static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, @@ -1445,7 +1432,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(evsel, sample); + err = f(sample); } thread__put(thread); -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 10/25] perf lock: Constify trace_lock_handler variables 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (8 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 09/25] perf lock: Only pass sample to handlers Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 11/25] perf hist: Remove evsel parameter from inc samples functions Ian Rogers ` (17 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel Structs don't change and so constify. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-lock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 78fb39d06e7c..735e6bb234ae 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1179,7 +1179,7 @@ static int report_lock_contention_end_event(struct perf_sample *sample) /* lock oriented handlers */ /* TODO: handlers for CPU oriented, thread oriented */ -static struct trace_lock_handler report_lock_ops = { +static const struct trace_lock_handler report_lock_ops = { .acquire_event = report_lock_acquire_event, .acquired_event = report_lock_acquired_event, .contended_event = report_lock_contended_event, @@ -1188,13 +1188,13 @@ static struct trace_lock_handler report_lock_ops = { .contention_end_event = report_lock_contention_end_event, }; -static struct trace_lock_handler contention_lock_ops = { +static const struct trace_lock_handler contention_lock_ops = { .contention_begin_event = report_lock_contention_begin_event, .contention_end_event = report_lock_contention_end_event, }; -static struct trace_lock_handler *trace_handler; +static const struct trace_lock_handler *trace_handler; static int evsel__process_lock_acquire(struct perf_sample *sample) { -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 11/25] perf hist: Remove evsel parameter from inc samples functions 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (9 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 10/25] perf lock: Constify trace_lock_handler variables Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 12/25] perf db-export: Remove evsel from struct export_sample Ian Rogers ` (16 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel hist_entry__inc_addr_samples and addr_map_symbol__inc_samples unnecessarily take an evsel argument. Read the evsel from the sample instead. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 7 +++---- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-report.c | 18 ++++++++---------- tools/perf/builtin-top.c | 6 +++--- tools/perf/util/annotate.c | 19 +++++++++---------- tools/perf/util/annotate.h | 6 ++---- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index a4903e4ccdb5..40c0ae0b52a4 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -177,16 +177,15 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, struct hist_entry *he = iter->he; struct branch_info *bi; struct perf_sample *sample = iter->sample; - struct evsel *evsel = iter->evsel; int err; bi = he->branch_info; - err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; - err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->to, sample); out: return err; @@ -276,7 +275,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, if (he == NULL) return -ENOMEM; - ret = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + ret = hist_entry__inc_addr_samples(he, sample, al->addr); hists__inc_nr_samples(hists, true); return ret; } diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index f9ac871264af..5684c14c2bf6 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -371,7 +371,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, if (perf_c2c__has_annotation(NULL)) { perf_c2c__evsel_hists_inc_stats(evsel, he, sample); - addr_map_symbol__inc_samples(mem_info__iaddr(mi), sample, evsel); + addr_map_symbol__inc_samples(mem_info__iaddr(mi), sample); } ret = hist_entry__append_callchain(he, sample); diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 35791fe0bd90..596b1ec9885c 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -170,7 +170,6 @@ static int hist_iter__report_callback(struct hist_entry_iter *iter, int err = 0; struct report *rep = arg; struct hist_entry *he = iter->he; - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; struct mem_info *mi; struct branch_info *bi; @@ -180,25 +179,25 @@ static int hist_iter__report_callback(struct hist_entry_iter *iter, if (sort__mode == SORT_MODE__BRANCH) { bi = he->branch_info; - err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; - err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->to, sample); } else if (rep->mem_mode) { mi = he->mem_info; - err = addr_map_symbol__inc_samples(mem_info__daddr(mi), sample, evsel); + err = addr_map_symbol__inc_samples(mem_info__daddr(mi), sample); if (err) goto out; - err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err = hist_entry__inc_addr_samples(he, sample, al->addr); } else if (symbol_conf.cumulate_callchain) { if (single) - err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err = hist_entry__inc_addr_samples(he, sample, al->addr); } else { - err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err = hist_entry__inc_addr_samples(he, sample, al->addr); } out: @@ -214,7 +213,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, struct report *rep = arg; struct branch_info *bi = he->branch_info; struct perf_sample *sample = iter->sample; - struct evsel *evsel = iter->evsel; int err; branch_type_count(&rep->brtype_stat, &bi->flags, @@ -223,11 +221,11 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, if (!ui__has_annotation() && !rep->symbol_ipc) return 0; - err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; - err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->to, sample); out: return err; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 710604c4f6f6..e863f9ef581f 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -198,7 +198,7 @@ static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip) static void perf_top__record_precise_ip(struct perf_top *top, struct hist_entry *he, struct perf_sample *sample, - struct evsel *evsel, u64 ip) + u64 ip) EXCLUSIVE_LOCKS_REQUIRED(he->hists->lock) { struct annotation *notes; @@ -215,7 +215,7 @@ static void perf_top__record_precise_ip(struct perf_top *top, if (!annotation__trylock(notes)) return; - err = hist_entry__inc_addr_samples(he, sample, evsel, ip); + err = hist_entry__inc_addr_samples(he, sample, ip); annotation__unlock(notes); @@ -734,7 +734,7 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter, struct evsel *evsel = iter->evsel; if (perf_hpp_list.sym && single) - perf_top__record_precise_ip(top, iter->he, iter->sample, evsel, al->addr); + perf_top__record_precise_ip(top, iter->he, iter->sample, al->addr); hist__account_cycles(iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY), diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 2e3522905046..15ff0443c312 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -211,9 +211,10 @@ static int __symbol__account_cycles(struct cyc_hist *ch, } static int __symbol__inc_addr_samples(struct map_symbol *ms, - struct annotated_source *src, struct evsel *evsel, u64 addr, + struct annotated_source *src, u64 addr, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; struct symbol *sym = ms->sym; long hash_key; u64 offset; @@ -316,7 +317,7 @@ struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists) } static int symbol__inc_addr_samples(struct map_symbol *ms, - struct evsel *evsel, u64 addr, + u64 addr, struct perf_sample *sample) { struct symbol *sym = ms->sym; @@ -324,8 +325,8 @@ static int symbol__inc_addr_samples(struct map_symbol *ms, if (sym == NULL) return 0; - src = symbol__hists(sym, evsel->evlist->core.nr_entries); - return src ? __symbol__inc_addr_samples(ms, src, evsel, addr, sample) : 0; + src = symbol__hists(sym, sample->evsel->evlist->core.nr_entries); + return src ? __symbol__inc_addr_samples(ms, src, addr, sample) : 0; } static int symbol__account_br_cntr(struct annotated_branch *branch, @@ -579,16 +580,14 @@ static int annotation__compute_ipc(struct annotation *notes, size_t size, return 0; } -int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample, - struct evsel *evsel) +int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample) { - return symbol__inc_addr_samples(&ams->ms, evsel, ams->al_addr, sample); + return symbol__inc_addr_samples(&ams->ms, ams->al_addr, sample); } -int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, - struct evsel *evsel, u64 ip) +int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, u64 ip) { - return symbol__inc_addr_samples(&he->ms, evsel, ip, sample); + return symbol__inc_addr_samples(&he->ms, ip, sample); } diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 696e36dbf013..1aa6df7d1618 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -422,8 +422,7 @@ static inline struct annotation *symbol__annotation(struct symbol *sym) return (void *)sym - symbol_conf.priv_size; } -int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample, - struct evsel *evsel); +int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample); struct annotated_branch *annotation__get_branch(struct annotation *notes); @@ -433,8 +432,7 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams, struct evsel *evsel, u64 br_cntr); -int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, - struct evsel *evsel, u64 addr); +int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, u64 addr); struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists); void symbol__annotate_zero_histograms(struct symbol *sym); -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 12/25] perf db-export: Remove evsel from struct export_sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (10 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 11/25] perf hist: Remove evsel parameter from inc samples functions Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 13/25] perf hist: Remove evsel from struct hist_entry_iter Ian Rogers ` (15 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel As the sample contains the evsel avoid the duplication. Remove the evsel from db_export__sample as it can also read from the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/db-export.c | 5 ++--- tools/perf/util/db-export.h | 3 +-- tools/perf/util/scripting-engines/trace-event-python.c | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index a1f578c3a8d5..fdfd825c7ef4 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -345,14 +345,13 @@ static int db_export__threads(struct db_export *dbe, struct thread *thread, } int db_export__sample(struct db_export *dbe, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al) { struct thread *thread = al->thread; struct export_sample es = { .event = event, .sample = sample, - .evsel = evsel, .al = al, }; struct thread *main_thread; @@ -365,7 +364,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, if (!machine) return -1; - err = db_export__evsel(dbe, evsel); + err = db_export__evsel(dbe, sample->evsel); if (err) return err; diff --git a/tools/perf/util/db-export.h b/tools/perf/util/db-export.h index 23983cb35706..1abbfd398e3a 100644 --- a/tools/perf/util/db-export.h +++ b/tools/perf/util/db-export.h @@ -25,7 +25,6 @@ struct call_return; struct export_sample { union perf_event *event; struct perf_sample *sample; - struct evsel *evsel; struct addr_location *al; u64 db_id; u64 comm_db_id; @@ -96,7 +95,7 @@ int db_export__symbol(struct db_export *dbe, struct symbol *sym, int db_export__branch_type(struct db_export *dbe, u32 branch_type, const char *name); int db_export__sample(struct db_export *dbe, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al); int db_export__branch_types(struct db_export *dbe); diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 0d8665c75d30..9f5c6e5e6ebe 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1312,7 +1312,7 @@ static void python_export_sample_table(struct db_export *dbe, t = tuple_new(28); tuple_set_d64(t, 0, es->db_id); - tuple_set_d64(t, 1, es->evsel->db_id); + tuple_set_d64(t, 1, es->sample->evsel->db_id); tuple_set_d64(t, 2, maps__machine(thread__maps(es->al->thread))->db_id); tuple_set_d64(t, 3, thread__db_id(es->al->thread)); tuple_set_d64(t, 4, es->comm_db_id); @@ -1353,7 +1353,7 @@ static void python_export_synth(struct db_export *dbe, struct export_sample *es) t = tuple_new(3); tuple_set_d64(t, 0, es->db_id); - tuple_set_d64(t, 1, es->evsel->core.attr.config); + tuple_set_d64(t, 1, es->sample->evsel->core.attr.config); tuple_set_bytes(t, 2, es->sample->raw_data, es->sample->raw_size); call_object(tables->synth_handler, t, "synth_data"); @@ -1368,7 +1368,7 @@ static int python_export_sample(struct db_export *dbe, python_export_sample_table(dbe, es); - if (es->evsel->core.attr.type == PERF_TYPE_SYNTH && tables->synth_handler) + if (es->sample->evsel->core.attr.type == PERF_TYPE_SYNTH && tables->synth_handler) python_export_synth(dbe, es); return 0; @@ -1517,7 +1517,7 @@ static void python_process_event(union perf_event *event, /* Reserve for future process_hw/sw/raw APIs */ default: if (tables->db_export_mode) - db_export__sample(&tables->dbe, event, sample, evsel, al, addr_al); + db_export__sample(&tables->dbe, event, sample, al, addr_al); else python_process_general_event(sample, evsel, al, addr_al); } -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 13/25] perf hist: Remove evsel from struct hist_entry_iter 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (11 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 12/25] perf db-export: Remove evsel from struct export_sample Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id Ian Rogers ` (14 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel struct hist_entry_iter has the sample within it so the evsel is unnecessary. Remove the evsel and update uses. Also remove the evsel from hist__account_cycles and derive it from the sample too. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 10 ++++------ tools/perf/builtin-diff.c | 3 +-- tools/perf/builtin-report.c | 6 ++---- tools/perf/builtin-top.c | 9 +++------ tools/perf/tests/hists_cumulate.c | 1 - tools/perf/tests/hists_filter.c | 1 - tools/perf/tests/hists_output.c | 1 - tools/perf/util/hist.c | 24 ++++++++++++------------ tools/perf/util/hist.h | 3 +-- 9 files changed, 23 insertions(+), 35 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 40c0ae0b52a4..26fe2cb93833 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -191,14 +191,12 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, return err; } -static int process_branch_callback(struct evsel *evsel, - struct perf_sample *sample, +static int process_branch_callback(struct perf_sample *sample, struct addr_location *al, struct perf_annotate *ann, struct machine *machine) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .add_entry_cb = hist_iter__branch_callback, .hide_unresolved = symbol_conf.hide_unresolved, @@ -221,8 +219,8 @@ static int process_branch_callback(struct evsel *evsel, if (a.map != NULL) dso__set_hit(map__dso(a.map)); - hist__account_cycles(sample->branch_stack, al, sample, false, - NULL, evsel); + hist__account_cycles(sample->branch_stack, al, sample, /*nonany_branch_mode=*/false, + /*total_cycles=*/NULL); ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann); out: @@ -269,7 +267,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, process_branch_stack(sample->branch_stack, al, sample); if (ann->has_br_stack && has_annotation(ann)) - return process_branch_callback(evsel, sample, al, ann, machine); + return process_branch_callback(sample, al, ann, machine); he = hists__add_entry(hists, al, NULL, NULL, NULL, NULL, sample, true); if (he == NULL) diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 793538ad3b4c..31620ac373d0 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -397,7 +397,6 @@ static int diff__process_sample_event(const struct perf_tool *tool, struct evsel *evsel = sample->evsel; struct hists *hists = evsel__hists(evsel); struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .ops = &hist_iter_normal, }; @@ -431,7 +430,7 @@ static int diff__process_sample_event(const struct perf_tool *tool, } hist__account_cycles(sample->branch_stack, &al, sample, - false, NULL, evsel); + /*nonany_branch_mode=*/false, /*total_cycles=*/NULL); break; case COMPUTE_STREAM: diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 596b1ec9885c..ae7985ec2bd8 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -270,10 +270,8 @@ static int process_sample_event(const struct perf_tool *tool, struct machine *machine) { struct report *rep = container_of(tool, struct report, tool); - struct evsel *evsel = sample->evsel; struct addr_location al; struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .hide_unresolved = symbol_conf.hide_unresolved, .add_entry_cb = hist_iter__report_callback, @@ -285,7 +283,7 @@ static int process_sample_event(const struct perf_tool *tool, return 0; } - if (evswitch__discard(&rep->evswitch, evsel)) + if (evswitch__discard(&rep->evswitch, sample->evsel)) return 0; addr_location__init(&al); @@ -329,7 +327,7 @@ static int process_sample_event(const struct perf_tool *tool, if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) { hist__account_cycles(sample->branch_stack, &al, sample, rep->nonany_branch_mode, - &rep->total_cycles, evsel); + &rep->total_cycles); } rep->total_samples++; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index e863f9ef581f..b89ca48e5d02 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -731,20 +731,18 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter, EXCLUSIVE_LOCKS_REQUIRED(iter->he->hists->lock) { struct perf_top *top = arg; - struct evsel *evsel = iter->evsel; if (perf_hpp_list.sym && single) perf_top__record_precise_ip(top, iter->he, iter->sample, al->addr); hist__account_cycles(iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY), - NULL, evsel); + /*total_cycles=*/NULL); return 0; } static void perf_event__process_sample(const struct perf_tool *tool, const union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -830,9 +828,8 @@ static void perf_event__process_sample(const struct perf_tool *tool, } if (al.sym == NULL || !al.sym->idle) { - struct hists *hists = evsel__hists(evsel); + struct hists *hists = evsel__hists(sample->evsel); struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .add_entry_cb = hist_iter__top_callback, }; @@ -1210,7 +1207,7 @@ static int deliver_event(struct ordered_events *qe, } if (event->header.type == PERF_RECORD_SAMPLE) { - perf_event__process_sample(&top->tool, event, evsel, + perf_event__process_sample(&top->tool, event, &sample, machine); } else if (event->header.type == PERF_RECORD_LOST) { perf_top__process_lost(top, event, evsel); diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c index 606aa926a8fc..267cbc24691a 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -87,7 +87,6 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) addr_location__init(&al); for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = &sample, .hide_unresolved = false, }; diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c index cc6b26e373d1..002e3a4c1ca5 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -63,7 +63,6 @@ static int add_hist_entries(struct evlist *evlist, evlist__for_each_entry(evlist, evsel) { for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = &sample, .ops = &hist_iter_normal, .hide_unresolved = false, diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c index 7818950d786e..fa683fd7b1e5 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -57,7 +57,6 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) addr_location__init(&al); for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = &sample, .ops = &hist_iter_normal, .hide_unresolved = false, diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 84a402d248a3..632c1edcab9a 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -932,8 +932,8 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al { u64 cost; struct mem_info *mi = iter->mi; - struct hists *hists = evsel__hists(iter->evsel); struct perf_sample *sample = iter->sample; + struct hists *hists = evsel__hists(sample->evsel); struct hist_entry *he; if (mi == NULL) @@ -965,7 +965,7 @@ static int iter_finish_mem_entry(struct hist_entry_iter *iter, struct addr_location *al __maybe_unused) { - struct evsel *evsel = iter->evsel; + struct evsel *evsel = iter->sample->evsel; struct hists *hists = evsel__hists(evsel); struct hist_entry *he = iter->he; int err = -EINVAL; @@ -1033,9 +1033,9 @@ static int iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) { struct branch_info *bi; - struct evsel *evsel = iter->evsel; - struct hists *hists = evsel__hists(evsel); struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; + struct hists *hists = evsel__hists(evsel); struct hist_entry *he = NULL; int i = iter->curr; int err = 0; @@ -1075,7 +1075,7 @@ static int iter_finish_branch_entry(struct hist_entry_iter *iter, struct addr_location *al __maybe_unused) { - struct evsel *evsel = iter->evsel; + struct evsel *evsel = iter->sample->evsel; struct hists *hists = evsel__hists(evsel); for (int i = 0; i < iter->total; i++) @@ -1100,8 +1100,8 @@ iter_prepare_normal_entry(struct hist_entry_iter *iter __maybe_unused, static int iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; struct hist_entry *he; he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, @@ -1118,8 +1118,8 @@ iter_finish_normal_entry(struct hist_entry_iter *iter, struct addr_location *al __maybe_unused) { struct hist_entry *he = iter->he; - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; if (he == NULL) return 0; @@ -1162,9 +1162,9 @@ static int iter_add_single_cumulative_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel = iter->evsel; - struct hists *hists = evsel__hists(evsel); struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; + struct hists *hists = evsel__hists(evsel); struct hist_entry **he_cache = iter->he_cache; struct hist_entry *he; int err = 0; @@ -1221,8 +1221,8 @@ static int iter_add_next_cumulative_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; struct hist_entry **he_cache = iter->he_cache; struct hist_entry *he; struct hist_entry he_tmp = { @@ -2823,7 +2823,7 @@ int hists__unlink(struct hists *hists) void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, struct perf_sample *sample, bool nonany_branch_mode, - u64 *total_cycles, struct evsel *evsel) + u64 *total_cycles) { struct branch_info *bi; struct branch_entry *entries = perf_sample__branch_entries(sample); @@ -2847,7 +2847,7 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, for (int i = bs->nr - 1; i >= 0; i--) { addr_map_symbol__account_cycles(&bi[i].from, nonany_branch_mode ? NULL : prev, - bi[i].flags.cycles, evsel, + bi[i].flags.cycles, sample->evsel, bi[i].branch_stack_cntr); prev = &bi[i].to; diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 1d5ea632ca4e..ee92fffc53a9 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -155,7 +155,6 @@ struct hist_entry_iter { int total; int curr; - struct evsel *evsel; struct perf_sample *sample; struct hist_entry *he; struct symbol *parent; @@ -797,7 +796,7 @@ unsigned int hists__overhead_width(struct hists *hists); void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, struct perf_sample *sample, bool nonany_branch_mode, - u64 *total_cycles, struct evsel *evsel); + u64 *total_cycles); struct option; int parse_filter_percentage(const struct option *opt, const char *arg, int unset); -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (12 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 13/25] perf hist: Remove evsel from struct hist_entry_iter Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 15/25] perf annotate: Don't pass evsel to add_sample Ian Rogers ` (13 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel In count_lost_samples_events try to avoid searching for the evsel for the sample, just use the variable within the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-report.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index ae7985ec2bd8..c088c7f94fac 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -793,9 +793,11 @@ static int count_lost_samples_event(const struct perf_tool *tool, struct machine *machine __maybe_unused) { struct report *rep = container_of(tool, struct report, tool); - struct evsel *evsel; + struct evsel *evsel = sample->evsel; + + if (!evsel) + evsel = evlist__id2evsel(rep->session->evlist, sample->id); - evsel = evlist__id2evsel(rep->session->evlist, sample->id); if (evsel) { struct hists *hists = evsel__hists(evsel); u32 count = event->lost_samples.lost; -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 15/25] perf annotate: Don't pass evsel to add_sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (13 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 16/25] perf inject: Don't pass evsel with sample Ian Rogers ` (12 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The sample contains the evsel so read it rather than pass it. Update call site. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 26fe2cb93833..44ba6ba8ffb8 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -233,11 +233,11 @@ static bool has_annotation(struct perf_annotate *ann) return ui__has_annotation() || ann->use_stdio2; } -static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, - struct addr_location *al, struct perf_annotate *ann, - struct machine *machine) +static int add_sample(struct perf_sample *sample, + struct addr_location *al, struct perf_annotate *ann, + struct machine *machine) { - struct hists *hists = evsel__hists(evsel); + struct hists *hists = evsel__hists(sample->evsel); struct hist_entry *he; int ret; @@ -299,7 +299,7 @@ static int process_sample_event(const struct perf_tool *tool, goto out_put; if (!al.filtered && - evsel__add_sample(sample->evsel, sample, &al, ann, machine)) { + add_sample(sample, &al, ann, machine)) { pr_warning("problem incrementing symbol count, " "skipping event\n"); ret = -1; -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 16/25] perf inject: Don't pass evsel with sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (14 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 15/25] perf annotate: Don't pass evsel to add_sample Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 17/25] perf kmem: " Ian Rogers ` (11 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 37 +++++++++++------------------- tools/perf/util/synthetic-events.c | 9 ++++---- tools/perf/util/synthetic-events.h | 2 -- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 016ad84ac4ab..66038d68277e 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -146,14 +146,12 @@ struct event_entry { static int tool__inject_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, const char *filename, struct dso *dso, u32 flags); static int tool__inject_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -357,7 +355,6 @@ perf_inject__cut_auxtrace_sample(struct perf_inject *inject, typedef int (*inject_handler)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); static int perf_event__repipe_sample(const struct perf_tool *tool, @@ -370,7 +367,7 @@ static int perf_event__repipe_sample(const struct perf_tool *tool, if (evsel && evsel->handler) { inject_handler f = evsel->handler; - return f(tool, event, sample, evsel, machine); + return f(tool, event, sample, machine); } build_id__mark_dso_hit(tool, event, sample, machine); @@ -584,11 +581,14 @@ static int perf_event__repipe_common_mmap(const struct perf_tool *tool, } if (dso && !dso__hit(dso)) { - struct evsel *evsel = evlist__event2evsel(inject->session->evlist, event); + struct evsel *evsel = sample->evsel; + + if (!evsel) + evlist__event2evsel(inject->session->evlist, event); if (evsel) { dso__set_hit(dso); - tool__inject_build_id(tool, sample, machine, evsel, + tool__inject_build_id(tool, sample, machine, /*misc=*/sample->cpumode, filename, dso, flags); } @@ -622,7 +622,7 @@ static int perf_event__repipe_common_mmap(const struct perf_tool *tool, dso_sought = true; } if (evsel && dso && - !tool__inject_mmap2_build_id(tool, sample, machine, evsel, + !tool__inject_mmap2_build_id(tool, sample, machine, sample->cpumode | PERF_RECORD_MISC_MMAP_BUILD_ID, pid, tid, start, len, pgoff, dso, @@ -836,7 +836,6 @@ static bool perf_inject__lookup_known_build_id(struct perf_inject *inject, static int tool__inject_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, const char *filename, struct dso *dso, u32 flags) @@ -860,7 +859,7 @@ static int tool__inject_build_id(const struct perf_tool *tool, err = perf_event__synthesize_build_id(tool, sample, machine, perf_event__repipe, - evsel, misc, dso__bid(dso), + misc, dso__bid(dso), filename); if (err) { pr_err("Can't synthesize build_id event for %s\n", filename); @@ -873,7 +872,6 @@ static int tool__inject_build_id(const struct perf_tool *tool, static int tool__inject_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -896,7 +894,6 @@ static int tool__inject_mmap2_build_id(const struct perf_tool *tool, err = perf_event__synthesize_mmap2_build_id(tool, sample, machine, perf_event__repipe, - evsel, misc, pid, tid, start, len, pgoff, dso__bid(dso), @@ -913,7 +910,6 @@ static int mark_dso_hit(const struct perf_inject *inject, const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *mmap_evsel, struct map *map, bool sample_in_dso) { struct dso *dso; @@ -943,7 +939,7 @@ static int mark_dso_hit(const struct perf_inject *inject, if (dso && !dso__hit(dso)) { dso__set_hit(dso); tool__inject_build_id(tool, sample, machine, - mmap_evsel, misc, dso__long_name(dso), dso, + misc, dso__long_name(dso), dso, map__flags(map)); } } else if (inject->build_id_style == BID_RWS__MMAP2_BUILDID_LAZY) { @@ -955,7 +951,6 @@ static int mark_dso_hit(const struct perf_inject *inject, map__set_hit(map); perf_event__synthesize_mmap2_build_id(tool, sample, machine, perf_event__repipe, - mmap_evsel, misc, sample->pid, sample->tid, map__start(map), @@ -975,7 +970,6 @@ struct mark_dso_hit_args { const struct perf_tool *tool; struct perf_sample *sample; struct machine *machine; - const struct evsel *mmap_evsel; }; static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data) @@ -984,7 +978,7 @@ static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data) struct map *map = node->ms.map; return mark_dso_hit(args->inject, args->tool, args->sample, args->machine, - args->mmap_evsel, map, /*sample_in_dso=*/false); + map, /*sample_in_dso=*/false); } static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, @@ -1002,7 +996,6 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e */ .sample = sample, .machine = machine, - .mmap_evsel = inject__mmap_evsel(inject), }; struct evsel *saved_evsel = sample->evsel; @@ -1015,7 +1008,7 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e } if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) { - mark_dso_hit(inject, tool, sample, machine, args.mmap_evsel, al.map, + mark_dso_hit(inject, tool, sample, machine, al.map, /*sample_in_dso=*/true); } @@ -1033,7 +1026,6 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e static int perf_inject__sched_process_exit(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine __maybe_unused) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); @@ -1053,13 +1045,12 @@ static int perf_inject__sched_process_exit(const struct perf_tool *tool, static int perf_inject__sched_switch(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); struct event_entry *ent; - perf_inject__sched_process_exit(tool, event, sample, evsel, machine); + perf_inject__sched_process_exit(tool, event, sample, machine); ent = malloc(event->header.size + sizeof(struct event_entry)); if (ent == NULL) { @@ -1078,13 +1069,13 @@ static int perf_inject__sched_switch(const struct perf_tool *tool, static int perf_inject__sched_stat(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct event_entry *ent; union perf_event *event_sw; struct perf_sample sample_sw; struct perf_inject *inject = container_of(tool, struct perf_inject, tool); + struct evsel *evsel = sample->evsel; u32 pid = perf_sample__intval(sample, "pid"); int ret; @@ -1451,7 +1442,7 @@ static int synthesize_build_id(struct perf_inject *inject, struct dso *dso, pid_ dso__set_hit(dso); return perf_event__synthesize_build_id(&inject->tool, &synth_sample, machine, - process_build_id, inject__mmap_evsel(inject), + process_build_id, /*misc=*/synth_sample.cpumode, dso__bid(dso), dso__long_name(dso)); } diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index ef79433ebc3a..53e411cf33cc 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2247,7 +2247,6 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, const struct build_id *bid, const char *filename) @@ -2270,12 +2269,13 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, ev.build_id.header.size = len; strcpy(ev.build_id.filename, filename); - if (evsel) { + if (sample->evsel) { void *array = &ev; int ret; array += ev.header.size; - ret = perf_event__synthesize_id_sample(array, evsel->core.attr.sample_type, sample); + ret = perf_event__synthesize_id_sample(array, sample->evsel->core.attr.sample_type, + sample); if (ret < 0) return ret; @@ -2294,7 +2294,6 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -2334,7 +2333,7 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, array = &ev; array += ev.header.size; - ret = perf_event__synthesize_id_sample(array, evsel->core.attr.sample_type, sample); + ret = perf_event__synthesize_id_sample(array, sample->evsel->core.attr.sample_type, sample); if (ret < 0) return ret; diff --git a/tools/perf/util/synthetic-events.h b/tools/perf/util/synthetic-events.h index b0edad0c3100..473a43a78993 100644 --- a/tools/perf/util/synthetic-events.h +++ b/tools/perf/util/synthetic-events.h @@ -50,7 +50,6 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, const struct build_id *bid, const char *filename); @@ -58,7 +57,6 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 17/25] perf kmem: Don't pass evsel with sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (15 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 16/25] perf inject: Don't pass evsel with sample Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 18/25] perf kwork: " Ian Rogers ` (10 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-kmem.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 19b12209fc08..ea2437971e8b 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -171,7 +171,7 @@ static int insert_caller_stat(unsigned long call_site, return 0; } -static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_alloc_event(struct perf_sample *sample) { unsigned long ptr = perf_sample__intval(sample, "ptr"), call_site = perf_sample__intval(sample, "call_site"); @@ -198,7 +198,7 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s * If the tracepoint contains the field "node" the tool stats the * cross allocation. */ - if (evsel__field(evsel, "node")) { + if (evsel__field(sample->evsel, "node")) { int node1, node2; node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}); @@ -243,7 +243,7 @@ static struct alloc_stat *search_alloc_stat(unsigned long ptr, return NULL; } -static int evsel__process_free_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) +static int evsel__process_free_event(struct perf_sample *sample) { unsigned long ptr = perf_sample__intval(sample, "ptr"); struct alloc_stat *s_alloc, *s_caller; @@ -751,8 +751,7 @@ static char *compact_gfp_string(unsigned long gfp_flags) return NULL; } -static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, - unsigned int gfp_flags) +static int parse_gfp_flags(struct perf_sample *sample, unsigned int gfp_flags) { struct tep_record record = { .cpu = sample->cpu, @@ -773,7 +772,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, } trace_seq_init(&seq); - tp_format = evsel__tp_format(evsel); + tp_format = evsel__tp_format(sample->evsel); if (tp_format) tep_print_event(tp_format->tep, &seq, &record, "%s", TEP_PRINT_INFO); @@ -805,7 +804,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, return 0; } -static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_page_alloc_event(struct perf_sample *sample) { u64 page; unsigned int order = perf_sample__intval(sample, "order"); @@ -836,7 +835,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp return 0; } - if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) + if (parse_gfp_flags(sample, gfp_flags) < 0) return -1; callsite = find_callsite(sample); @@ -877,8 +876,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp return 0; } -static int evsel__process_page_free_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int evsel__process_page_free_event(struct perf_sample *sample) { u64 page; unsigned int order = perf_sample__intval(sample, "order"); @@ -955,8 +953,7 @@ static bool perf_kmem__skip_sample(struct perf_sample *sample) return false; } -typedef int (*tracepoint_handler)(struct evsel *evsel, - struct perf_sample *sample); +typedef int (*tracepoint_handler)(struct perf_sample *sample); static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, @@ -981,7 +978,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(evsel, sample); + err = f(sample); } thread__put(thread); -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 18/25] perf kwork: Don't pass evsel with sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (16 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 17/25] perf kmem: " Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 19/25] perf sched: " Ian Rogers ` (9 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The sample contains the evsel and so it is unnecessary to pass the evsel as well. Remove the evsel from struct kwork_class. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-kwork.c | 74 +++++++++++++------------------------- tools/perf/util/kwork.h | 9 +++-- 2 files changed, 28 insertions(+), 55 deletions(-) diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index bd62616af476..eb3bc47c248d 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -448,7 +448,6 @@ static int work_push_atom(struct perf_kwork *kwork, struct kwork_class *class, enum kwork_trace_type src_type, enum kwork_trace_type dst_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct kwork_work **ret_work, @@ -458,7 +457,7 @@ static int work_push_atom(struct perf_kwork *kwork, struct kwork_work *work, key; BUG_ON(class->work_init == NULL); - class->work_init(kwork, class, &key, src_type, evsel, sample, machine); + class->work_init(kwork, class, &key, src_type, sample, machine); atom = atom_new(kwork, sample); if (atom == NULL) @@ -507,7 +506,6 @@ static struct kwork_atom *work_pop_atom(struct perf_kwork *kwork, struct kwork_class *class, enum kwork_trace_type src_type, enum kwork_trace_type dst_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct kwork_work **ret_work) @@ -516,7 +514,7 @@ static struct kwork_atom *work_pop_atom(struct perf_kwork *kwork, struct kwork_work *work, key; BUG_ON(class->work_init == NULL); - class->work_init(kwork, class, &key, src_type, evsel, sample, machine); + class->work_init(kwork, class, &key, src_type, sample, machine); work = work_findnew(&class->work_root, &key, &kwork->cmp_id); if (ret_work != NULL) @@ -599,18 +597,16 @@ static void report_update_exit_event(struct kwork_work *work, static int report_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int report_exit_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -618,7 +614,7 @@ static int report_exit_event(struct perf_kwork *kwork, struct kwork_work *work = NULL; atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (work == NULL) return -1; @@ -654,18 +650,16 @@ static void latency_update_entry_event(struct kwork_work *work, static int latency_raise_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_RAISE, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int latency_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -673,7 +667,7 @@ static int latency_entry_event(struct perf_kwork *kwork, struct kwork_work *work = NULL; atom = work_pop_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_RAISE, evsel, sample, + KWORK_TRACE_RAISE, sample, machine, &work); if (work == NULL) return -1; @@ -812,18 +806,16 @@ static void timehist_print_event(struct perf_kwork *kwork, static int timehist_raise_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_RAISE, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int timehist_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -831,7 +823,7 @@ static int timehist_entry_event(struct perf_kwork *kwork, struct kwork_work *work = NULL; ret = work_push_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_RAISE, evsel, sample, + KWORK_TRACE_RAISE, sample, machine, &work, true); if (ret) return ret; @@ -844,7 +836,6 @@ static int timehist_entry_event(struct perf_kwork *kwork, static int timehist_exit_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -861,7 +852,7 @@ static int timehist_exit_event(struct perf_kwork *kwork, } atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (work == NULL) { ret = -1; @@ -895,18 +886,16 @@ static void top_update_runtime(struct kwork_work *work, static int top_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int top_exit_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -915,7 +904,7 @@ static int top_exit_event(struct perf_kwork *kwork, struct kwork_atom *atom; atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (!work) return -1; @@ -936,7 +925,6 @@ static int top_exit_event(struct perf_kwork *kwork, static int top_sched_switch_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -944,7 +932,7 @@ static int top_sched_switch_event(struct perf_kwork *kwork, struct kwork_work *work; atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (!work) return -1; @@ -954,12 +942,11 @@ static int top_sched_switch_event(struct perf_kwork *kwork, atom_del(atom); } - return top_entry_event(kwork, class, evsel, sample, machine); + return top_entry_event(kwork, class, sample, machine); } static struct kwork_class kwork_irq; static int process_irq_handler_entry_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -967,12 +954,11 @@ static int process_irq_handler_entry_event(const struct perf_tool *tool, if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_irq, - evsel, sample, machine); + sample, machine); return 0; } static int process_irq_handler_exit_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -980,7 +966,7 @@ static int process_irq_handler_exit_event(const struct perf_tool *tool, if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_irq, - evsel, sample, machine); + sample, machine); return 0; } @@ -1005,7 +991,6 @@ static void irq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1038,7 +1023,6 @@ static struct kwork_class kwork_irq = { static struct kwork_class kwork_softirq; static int process_softirq_raise_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1046,13 +1030,12 @@ static int process_softirq_raise_event(const struct perf_tool *tool, if (kwork->tp_handler->raise_event) return kwork->tp_handler->raise_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); return 0; } static int process_softirq_entry_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1060,13 +1043,12 @@ static int process_softirq_entry_event(const struct perf_tool *tool, if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); return 0; } static int process_softirq_exit_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1074,7 +1056,7 @@ static int process_softirq_exit_event(const struct perf_tool *tool, if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); return 0; } @@ -1133,7 +1115,6 @@ static void softirq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1148,7 +1129,7 @@ static void softirq_work_init(struct perf_kwork *kwork, } else { num = perf_sample__intval(sample, "vec"); work->id = num; - work->name = evsel__softirq_name(evsel, num); + work->name = evsel__softirq_name(sample->evsel, num); } } @@ -1169,7 +1150,6 @@ static struct kwork_class kwork_softirq = { static struct kwork_class kwork_workqueue; static int process_workqueue_activate_work_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1177,13 +1157,12 @@ static int process_workqueue_activate_work_event(const struct perf_tool *tool, if (kwork->tp_handler->raise_event) return kwork->tp_handler->raise_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); return 0; } static int process_workqueue_execute_start_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1191,13 +1170,12 @@ static int process_workqueue_execute_start_event(const struct perf_tool *tool, if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); return 0; } static int process_workqueue_execute_end_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1205,7 +1183,7 @@ static int process_workqueue_execute_end_event(const struct perf_tool *tool, if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); return 0; } @@ -1233,7 +1211,6 @@ static void workqueue_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1267,7 +1244,6 @@ static struct kwork_class kwork_workqueue = { static struct kwork_class kwork_sched; static int process_sched_switch_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1275,7 +1251,7 @@ static int process_sched_switch_event(const struct perf_tool *tool, if (kwork->tp_handler->sched_switch_event) return kwork->tp_handler->sched_switch_event(kwork, &kwork_sched, - evsel, sample, machine); + sample, machine); return 0; } @@ -1300,7 +1276,6 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1946,7 +1921,6 @@ static int perf_kwork__report(struct perf_kwork *kwork) } typedef int (*tracepoint_handler)(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -1961,7 +1935,7 @@ static int perf_kwork__process_tracepoint_sample(const struct perf_tool *tool, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(tool, evsel, sample, machine); + err = f(tool, sample, machine); } return err; diff --git a/tools/perf/util/kwork.h b/tools/perf/util/kwork.h index db00269b73f2..abf637d44794 100644 --- a/tools/perf/util/kwork.h +++ b/tools/perf/util/kwork.h @@ -157,7 +157,6 @@ struct kwork_class { struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -167,19 +166,19 @@ struct kwork_class { struct trace_kwork_handler { int (*raise_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); int (*entry_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); int (*exit_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); int (*sched_switch_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); }; -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 19/25] perf sched: Don't pass evsel with sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (17 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 18/25] perf kwork: " Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 20/25] perf timechart: " Ian Rogers ` (8 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-sched.c | 92 ++++++++++++++------------------------ 1 file changed, 34 insertions(+), 58 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 0580dc20720f..0f3982d6722e 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -129,21 +129,20 @@ typedef int (*sort_fn_t)(struct work_atoms *, struct work_atoms *); struct perf_sched; struct trace_sched_handler { - int (*switch_event)(struct perf_sched *sched, struct evsel *evsel, - struct perf_sample *sample, struct machine *machine); + int (*switch_event)(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine); - int (*runtime_event)(struct perf_sched *sched, struct evsel *evsel, - struct perf_sample *sample, struct machine *machine); + int (*runtime_event)(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine); - int (*wakeup_event)(struct perf_sched *sched, struct evsel *evsel, - struct perf_sample *sample, struct machine *machine); + int (*wakeup_event)(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine); /* PERF_RECORD_FORK event, not sched_process_fork tracepoint */ int (*fork_event)(struct perf_sched *sched, union perf_event *event, struct machine *machine); int (*migrate_task_event)(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); }; @@ -826,7 +825,7 @@ static void test_calibrations(struct perf_sched *sched) static int replay_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, + struct perf_sample *sample, struct machine *machine __maybe_unused) { const char *comm = perf_sample__strval(sample, "comm"); @@ -834,7 +833,7 @@ replay_wakeup_event(struct perf_sched *sched, struct task_desc *waker, *wakee; if (verbose > 0) { - printf("sched_wakeup event %p\n", evsel); + printf("sched_wakeup event %p\n", sample->evsel); printf(" ... pid %d woke up %s/%d\n", sample->tid, comm, pid); } @@ -847,7 +846,6 @@ replay_wakeup_event(struct perf_sched *sched, } static int replay_switch_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -861,7 +859,7 @@ static int replay_switch_event(struct perf_sched *sched, s64 delta; if (verbose > 0) - printf("sched_switch event %p\n", evsel); + printf("sched_switch event %p\n", sample->evsel); if (cpu >= MAX_CPUS || cpu < 0) return 0; @@ -1134,7 +1132,6 @@ static void free_work_atoms(struct work_atoms *atoms) } static int latency_switch_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1204,7 +1201,6 @@ static int latency_switch_event(struct perf_sched *sched, } static int latency_runtime_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1239,7 +1235,6 @@ static int latency_runtime_event(struct perf_sched *sched, } static int latency_wakeup_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1300,7 +1295,6 @@ static int latency_wakeup_event(struct perf_sched *sched, } static int latency_migrate_task_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1519,20 +1513,18 @@ static void perf_sched__sort_lat(struct perf_sched *sched) } static int process_sched_wakeup_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); if (sched->tp_handler->wakeup_event) - return sched->tp_handler->wakeup_event(sched, evsel, sample, machine); + return sched->tp_handler->wakeup_event(sched, sample, machine); return 0; } static int process_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused) { @@ -1626,8 +1618,8 @@ static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu, } } -static int map_switch_event(struct perf_sched *sched, struct evsel *evsel __maybe_unused, - struct perf_sample *sample, struct machine *machine) +static int map_switch_event(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine) { const u32 next_pid = perf_sample__intval(sample, "next_pid"); const u32 prev_pid = perf_sample__intval(sample, "prev_pid"); @@ -1791,7 +1783,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel __mayb } static int process_sched_switch_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1810,21 +1801,20 @@ static int process_sched_switch_event(const struct perf_tool *tool, } if (sched->tp_handler->switch_event) - err = sched->tp_handler->switch_event(sched, evsel, sample, machine); + err = sched->tp_handler->switch_event(sched, sample, machine); sched->curr_pid[this_cpu] = next_pid; return err; } static int process_sched_runtime_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); if (sched->tp_handler->runtime_event) - return sched->tp_handler->runtime_event(sched, evsel, sample, machine); + return sched->tp_handler->runtime_event(sched, sample, machine); return 0; } @@ -1847,20 +1837,18 @@ static int perf_sched__process_fork_event(const struct perf_tool *tool, } static int process_sched_migrate_task_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); if (sched->tp_handler->migrate_task_event) - return sched->tp_handler->migrate_task_event(sched, evsel, sample, machine); + return sched->tp_handler->migrate_task_event(sched, sample, machine); return 0; } typedef int (*tracepoint_handler)(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -1874,7 +1862,7 @@ static int perf_sched__process_tracepoint_sample(const struct perf_tool *tool __ if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(tool, evsel, sample, machine); + err = f(tool, sample, machine); } return err; @@ -2313,11 +2301,10 @@ static void timehist_update_runtime_stats(struct thread_runtime *r, r->total_pre_mig_time += r->dt_pre_mig; } -static bool is_idle_sample(struct perf_sample *sample, - struct evsel *evsel) +static bool is_idle_sample(struct perf_sample *sample) { /* pid 0 == swapper == idle task */ - if (evsel__name_is(evsel, "sched:sched_switch")) + if (evsel__name_is(sample->evsel, "sched:sched_switch")) return perf_sample__intval(sample, "prev_pid") == 0; return sample->pid == 0; @@ -2499,12 +2486,11 @@ static void save_idle_callchain(struct perf_sched *sched, static struct thread *timehist_get_thread(struct perf_sched *sched, struct perf_sample *sample, - struct machine *machine, - struct evsel *evsel) + struct machine *machine) { struct thread *thread; - if (is_idle_sample(sample, evsel)) { + if (is_idle_sample(sample)) { thread = get_idle_thread(sample->cpu); if (thread == NULL) pr_err("Failed to get idle thread for cpu %d.\n", sample->cpu); @@ -2547,7 +2533,6 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, static bool timehist_skip_sample(struct perf_sched *sched, struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { bool rc = false; @@ -2569,7 +2554,7 @@ static bool timehist_skip_sample(struct perf_sched *sched, tr = thread__get_runtime(thread); if (tr && tr->prio != -1) prio = tr->prio; - else if (evsel__name_is(evsel, "sched:sched_switch")) + else if (evsel__name_is(sample->evsel, "sched:sched_switch")) prio = perf_sample__intval(sample, "prev_prio"); if (prio != -1 && !test_bit(prio, sched->prio_bitmap)) { @@ -2579,7 +2564,7 @@ static bool timehist_skip_sample(struct perf_sched *sched, } if (sched->idle_hist) { - if (!evsel__name_is(evsel, "sched:sched_switch")) + if (!evsel__name_is(sample->evsel, "sched:sched_switch")) rc = true; else if (perf_sample__intval(sample, "prev_pid") != 0 && perf_sample__intval(sample, "next_pid") != 0) @@ -2590,7 +2575,6 @@ static bool timehist_skip_sample(struct perf_sched *sched, } static void timehist_print_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct thread *awakened) @@ -2603,8 +2587,8 @@ static void timehist_print_wakeup_event(struct perf_sched *sched, return; /* show wakeup unless both awakee and awaker are filtered */ - if (timehist_skip_sample(sched, thread, evsel, sample) && - timehist_skip_sample(sched, awakened, evsel, sample)) { + if (timehist_skip_sample(sched, thread, sample) && + timehist_skip_sample(sched, awakened, sample)) { thread__put(thread); return; } @@ -2628,7 +2612,6 @@ static void timehist_print_wakeup_event(struct perf_sched *sched, static int timehist_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused) { @@ -2637,7 +2620,6 @@ static int timehist_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unu static int timehist_sched_wakeup_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2663,14 +2645,13 @@ static int timehist_sched_wakeup_event(const struct perf_tool *tool, /* show wakeups if requested */ if (sched->show_wakeups && !perf_time__skip_sample(&sched->ptime, sample->time)) - timehist_print_wakeup_event(sched, evsel, sample, machine, thread); + timehist_print_wakeup_event(sched, sample, machine, thread); thread__put(thread); return 0; } static void timehist_print_migration_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct thread *migrated) @@ -2691,8 +2672,8 @@ static void timehist_print_migration_event(struct perf_sched *sched, if (thread == NULL) return; - if (timehist_skip_sample(sched, thread, evsel, sample) && - timehist_skip_sample(sched, migrated, evsel, sample)) { + if (timehist_skip_sample(sched, thread, sample) && + timehist_skip_sample(sched, migrated, sample)) { thread__put(thread); return; } @@ -2726,7 +2707,6 @@ static void timehist_print_migration_event(struct perf_sched *sched, static int timehist_migrate_task_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2751,8 +2731,7 @@ static int timehist_migrate_task_event(const struct perf_tool *tool, /* show migrations if requested */ if (sched->show_migrations) { - timehist_print_migration_event(sched, evsel, sample, - machine, thread); + timehist_print_migration_event(sched, sample, machine, thread); } thread__put(thread); @@ -2784,7 +2763,6 @@ static void timehist_update_task_prio(struct perf_sample *sample, static int timehist_sched_change_event(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2808,13 +2786,13 @@ static int timehist_sched_change_event(const struct perf_tool *tool, if (sched->show_prio || sched->prio_str) timehist_update_task_prio(sample, machine); - thread = timehist_get_thread(sched, sample, machine, evsel); + thread = timehist_get_thread(sched, sample, machine); if (thread == NULL) { rc = -1; goto out; } - if (timehist_skip_sample(sched, thread, evsel, sample)) + if (timehist_skip_sample(sched, thread, sample)) goto out; tr = thread__get_runtime(thread); @@ -2823,7 +2801,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, goto out; } - tprev = evsel__get_time(evsel, sample->cpu); + tprev = evsel__get_time(sample->evsel, sample->cpu); /* * If start time given: @@ -2913,7 +2891,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, tr->migrated = 0; } - evsel__save_time(evsel, sample->time, sample->cpu); + evsel__save_time(sample->evsel, sample->time, sample->cpu); thread__put(thread); addr_location__exit(&al); @@ -2922,11 +2900,10 @@ static int timehist_sched_change_event(const struct perf_tool *tool, static int timehist_sched_switch_event(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { - return timehist_sched_change_event(tool, event, evsel, sample, machine); + return timehist_sched_change_event(tool, event, sample, machine); } static int process_lost(const struct perf_tool *tool __maybe_unused, @@ -3174,7 +3151,6 @@ static void timehist_print_summary(struct perf_sched *sched, typedef int (*sched_handler)(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -3196,7 +3172,7 @@ static int perf_timehist__process_sample(const struct perf_tool *tool, if (evsel->handler != NULL) { sched_handler f = evsel->handler; - err = f(tool, event, evsel, sample, machine); + err = f(tool, event, sample, machine); } return err; -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 20/25] perf timechart: Don't pass evsel with sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (18 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 19/25] perf sched: " Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 21/25] perf trace: " Ian Rogers ` (7 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-timechart.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index b3f2ce52938d..d98c0b50e93f 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -567,7 +567,6 @@ static const char *cat_backtrace(union perf_event *event, } typedef int (*tracepoint_handler)(struct timechart *tchart, - struct evsel *evsel, struct perf_sample *sample, const char *backtrace); @@ -588,7 +587,7 @@ static int process_sample_event(const struct perf_tool *tool, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - return f(tchart, evsel, sample, + return f(tchart, sample, cat_backtrace(event, sample, machine)); } @@ -597,7 +596,6 @@ static int process_sample_event(const struct perf_tool *tool, static int process_sample_cpu_idle(struct timechart *tchart __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -613,7 +611,6 @@ process_sample_cpu_idle(struct timechart *tchart __maybe_unused, static int process_sample_cpu_frequency(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -626,7 +623,6 @@ process_sample_cpu_frequency(struct timechart *tchart, static int process_sample_sched_wakeup(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { @@ -640,7 +636,6 @@ process_sample_sched_wakeup(struct timechart *tchart, static int process_sample_sched_switch(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { @@ -656,7 +651,6 @@ process_sample_sched_switch(struct timechart *tchart, #ifdef SUPPORT_OLD_POWER_EVENTS static int process_sample_power_start(struct timechart *tchart __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -669,7 +663,6 @@ process_sample_power_start(struct timechart *tchart __maybe_unused, static int process_sample_power_end(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -679,7 +672,6 @@ process_sample_power_end(struct timechart *tchart, static int process_sample_power_frequency(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -849,7 +841,6 @@ static int pid_end_io_sample(struct timechart *tchart, int pid, int type, static int process_enter_read(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long fd = perf_sample__intval(sample, "fd"); @@ -859,7 +850,6 @@ process_enter_read(struct timechart *tchart, static int process_exit_read(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long ret = perf_sample__intval(sample, "ret"); @@ -869,7 +859,6 @@ process_exit_read(struct timechart *tchart, static int process_enter_write(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long fd = perf_sample__intval(sample, "fd"); @@ -879,7 +868,6 @@ process_enter_write(struct timechart *tchart, static int process_exit_write(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long ret = perf_sample__intval(sample, "ret"); @@ -889,7 +877,6 @@ process_exit_write(struct timechart *tchart, static int process_enter_sync(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long fd = perf_sample__intval(sample, "fd"); @@ -899,7 +886,6 @@ process_enter_sync(struct timechart *tchart, static int process_exit_sync(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long ret = perf_sample__intval(sample, "ret"); @@ -909,7 +895,6 @@ process_exit_sync(struct timechart *tchart, static int process_enter_tx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long fd = perf_sample__intval(sample, "fd"); @@ -919,7 +904,6 @@ process_enter_tx(struct timechart *tchart, static int process_exit_tx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long ret = perf_sample__intval(sample, "ret"); @@ -929,7 +913,6 @@ process_exit_tx(struct timechart *tchart, static int process_enter_rx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long fd = perf_sample__intval(sample, "fd"); @@ -939,7 +922,6 @@ process_enter_rx(struct timechart *tchart, static int process_exit_rx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long ret = perf_sample__intval(sample, "ret"); @@ -949,7 +931,6 @@ process_exit_rx(struct timechart *tchart, static int process_enter_poll(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long fd = perf_sample__intval(sample, "fd"); @@ -959,7 +940,6 @@ process_enter_poll(struct timechart *tchart, static int process_exit_poll(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long ret = perf_sample__intval(sample, "ret"); -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 21/25] perf trace: Don't pass evsel with sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (19 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 20/25] perf timechart: " Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 22/25] perf evlist: Try to avoid computing evsel from sample Ian Rogers ` (6 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The sample contains the evsel and so it is unnecessary to pass the evsel as well. In trace__handle_event try to use the evsel from the sample to avoid recomputation. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-trace.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index b6e90ee53cbe..ff3c85144038 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2579,7 +2579,7 @@ static struct syscall *trace__find_syscall(struct trace *trace, int e_machine, i return sc; } -typedef int (*tracepoint_handler)(struct trace *trace, struct evsel *evsel, +typedef int (*tracepoint_handler)(struct trace *trace, union perf_event *event, struct perf_sample *sample); @@ -2774,10 +2774,11 @@ static void *syscall__augmented_args(struct syscall *sc, struct perf_sample *sam return NULL; } -static int trace__sys_enter(struct trace *trace, struct evsel *evsel, +static int trace__sys_enter(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; char *msg; void *args; int printed = 0; @@ -2920,10 +2921,11 @@ static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sam return sample__fprintf_callchain(sample, 38, print_opts, get_tls_callchain_cursor(), symbol_conf.bt_stop_list, trace->output); } -static int trace__sys_exit(struct trace *trace, struct evsel *evsel, +static int trace__sys_exit(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; long ret; u64 duration = 0; bool duration_calculated = false; @@ -3058,7 +3060,7 @@ errno_print: { return err; } -static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_unused, +static int trace__vfs_getname(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3119,7 +3121,7 @@ static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_u return 0; } -static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, +static int trace__sched_stat_runtime(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3141,7 +3143,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, out_dump: fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", - evsel->name, + sample->evsel->name, perf_sample__strval(sample, "comm"), (pid_t)perf_sample__intval(sample, "pid"), runtime, @@ -3252,10 +3254,11 @@ static size_t trace__fprintf_tp_fields(struct trace *trace, struct perf_sample * return fprintf(trace->output, "%.*s", (int)printed, bf); } -static int trace__event_handler(struct trace *trace, struct evsel *evsel, +static int trace__event_handler(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; struct thread *thread; int callchain_ret = 0; @@ -3443,7 +3446,6 @@ static int trace__pgfault(struct trace *trace, } static void trace__set_base_time(struct trace *trace, - struct evsel *evsel, struct perf_sample *sample) { /* @@ -3455,7 +3457,7 @@ static void trace__set_base_time(struct trace *trace, * appears in our event stream (vfs_getname comes to mind). */ if (trace->base_time == 0 && !trace->full_time && - (evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) + (sample->evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) trace->base_time = sample->time; } @@ -3475,11 +3477,11 @@ static int trace__process_sample(const struct perf_tool *tool, if (thread && thread__is_filtered(thread)) goto out; - trace__set_base_time(trace, evsel, sample); + trace__set_base_time(trace, sample); if (handler) { ++trace->nr_events; - handler(trace, evsel, event, sample); + handler(trace, event, sample); } out: thread__put(thread); @@ -3621,14 +3623,16 @@ static void evlist__free_syscall_tp_fields(struct evlist *evlist) static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *sample) { const u32 type = event->header.type; - struct evsel *evsel; + struct evsel *evsel = sample->evsel; if (type != PERF_RECORD_SAMPLE) { trace__process_event(trace, trace->host, event, sample); return; } - evsel = evlist__id2evsel(trace->evlist, sample->id); + if (evsel == NULL) + evsel = evlist__id2evsel(trace->evlist, sample->id); + if (evsel == NULL) { fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id); return; @@ -3637,7 +3641,7 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st if (evswitch__discard(&trace->evswitch, evsel)) return; - trace__set_base_time(trace, evsel, sample); + trace__set_base_time(trace, sample); if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT && sample->raw_data == NULL) { @@ -3646,7 +3650,7 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st sample->cpu, sample->raw_size); } else { tracepoint_handler handler = evsel->handler; - handler(trace, evsel, event, sample); + handler(trace, event, sample); } if (trace->nr_events_printed >= trace->max_events && trace->max_events != ULONG_MAX) -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 22/25] perf evlist: Try to avoid computing evsel from sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (20 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 21/25] perf trace: " Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 23/25] perf script: Don't pass evsel with sample Ian Rogers ` (5 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel If the sample has an evsel, don't recompute using the sample.id. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 5 +++-- tools/perf/builtin-top.c | 4 +++- tools/perf/tests/mmap-basic.c | 4 +++- tools/perf/tests/switch-tracking.c | 5 ++++- tools/perf/util/intel-pt.c | 10 +++++++--- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 66038d68277e..fd3934a7281e 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1695,11 +1695,12 @@ static int guest_session__fetch(struct guest_session *gs) static int evlist__append_id_sample(struct evlist *evlist, union perf_event *ev, const struct perf_sample *sample) { - struct evsel *evsel; + struct evsel *evsel = sample->evsel; void *array; int ret; - evsel = evlist__id2evsel(evlist, sample->id); + if (!evsel) + evsel = evlist__id2evsel(evlist, sample->id); array = ev; if (!evsel) { diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index b89ca48e5d02..faa422e35166 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1163,7 +1163,9 @@ static int deliver_event(struct ordered_events *qe, goto next_event; } - evsel = evlist__id2evsel(session->evlist, sample.id); + evsel = sample.evsel; + if (!evsel) + evsel = evlist__id2evsel(session->evlist, sample.id); assert(evsel != NULL); if (event->header.type == PERF_RECORD_SAMPLE) { diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 3313c236104e..a18d84d858aa 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -142,7 +142,9 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtest } err = -1; - evsel = evlist__id2evsel(evlist, sample.id); + evsel = sample.evsel; + if (!evsel) + evsel = evlist__id2evsel(evlist, sample.id); perf_sample__exit(&sample); if (evsel == NULL) { pr_debug("event with id %" PRIu64 diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index a7ea4b7874be..ed17c3be71c4 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -138,7 +138,10 @@ static int process_sample_event(struct evlist *evlist, goto out; } - evsel = evlist__id2evsel(evlist, sample.id); + evsel = sample.evsel; + if (!evsel) + evsel = evlist__id2evsel(evlist, sample.id); + if (evsel == switch_tracking->switch_evsel) { next_tid = perf_sample__intval(&sample, "next_pid"); prev_tid = perf_sample__intval(&sample, "prev_pid"); diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index dab23a96b1d8..3d759546a7c0 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -3421,7 +3421,10 @@ static int intel_pt_process_switch(struct intel_pt *pt, { pid_t tid; int cpu, ret; - struct evsel *evsel = evlist__id2evsel(pt->session->evlist, sample->id); + struct evsel *evsel = sample->evsel; + + if (!evsel) + evsel = evlist__id2evsel(pt->session->evlist, sample->id); if (evsel != pt->switch_evsel) return 0; @@ -3611,10 +3614,11 @@ static int intel_pt_process_aux_output_hw_id(struct intel_pt *pt, u64 hw_id = event->aux_output_hw_id.hw_id; struct auxtrace_queue *queue; struct intel_pt_queue *ptq; - struct evsel *evsel; + struct evsel *evsel = sample->evsel; queue = auxtrace_queues__sample_queue(&pt->queues, sample, pt->session); - evsel = evlist__id2evsel_strict(pt->session->evlist, sample->id); + if (!evsel) + evsel = evlist__id2evsel_strict(pt->session->evlist, sample->id); if (!queue || !queue->priv || !evsel || hw_id > INTEL_PT_MAX_PEBS) { pr_err("Bad AUX output hardware ID\n"); return -EINVAL; -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 23/25] perf script: Don't pass evsel with sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (21 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 22/25] perf evlist: Try to avoid computing evsel from sample Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 24/25] perf s390-sample-raw: " Ian Rogers ` (4 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The sample contains the evsel and so it is unnecessary to pass the evsel as well. Remove the evsel from the struct scripting_context so that the sample version is always accessed. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-script.c | 12 ++++-- .../util/scripting-engines/trace-event-perl.c | 21 +++++------ .../scripting-engines/trace-event-python.c | 37 ++++++++----------- tools/perf/util/trace-event-scripting.c | 5 +-- tools/perf/util/trace-event.h | 3 -- 5 files changed, 33 insertions(+), 45 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 7788a6934a8d..9f7d261b1291 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2414,12 +2414,13 @@ static bool show_event(struct perf_sample *sample, } static void process_event(struct perf_script *script, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al, struct machine *machine) { struct thread *thread = al->thread; + struct evsel *evsel = sample->evsel; struct perf_event_attr *attr = &evsel->core.attr; unsigned int type = evsel__output_type(evsel); struct evsel_script *es = evsel->priv; @@ -2710,9 +2711,9 @@ static int process_sample_event(const struct perf_tool *tool, thread__resolve(al.thread, &addr_al, sample); addr_al_ptr = &addr_al; } - scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr); + scripting_ops->process_event(event, sample, &al, addr_al_ptr); } else { - process_event(scr, sample, evsel, &al, &addr_al, machine); + process_event(scr, sample, &al, &addr_al, machine); } out_put: @@ -2888,9 +2889,12 @@ static int print_event_with_time(const struct perf_tool *tool, { struct perf_script *script = container_of(tool, struct perf_script, tool); struct perf_session *session = script->session; - struct evsel *evsel = evlist__id2evsel(session->evlist, sample->id); + struct evsel *evsel = sample->evsel; struct thread *thread = NULL; + if (!evsel) + evsel = evlist__id2evsel(session->evlist, sample->id); + if (evsel && !evsel->core.attr.sample_id_all) { sample->cpu = 0; sample->time = timestamp; diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index 850a0048df82..7a18ea4b7d50 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -257,7 +257,6 @@ static void define_event_symbols(struct tep_event *event, } static SV *perl_process_callchain(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al) { struct callchain_cursor *cursor; @@ -340,7 +339,6 @@ static SV *perl_process_callchain(struct perf_sample *sample, } static void perl_process_tracepoint(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al) { struct thread *thread = al->thread; @@ -355,6 +353,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, unsigned long long nsecs = sample->time; const char *comm = thread__comm_str(thread); DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX); + struct evsel *evsel = sample->evsel; bitmap_zero(events_defined, TRACE_EVENT_TYPE_MAX); dSP; @@ -389,7 +388,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, XPUSHs(sv_2mortal(newSVuv(ns))); XPUSHs(sv_2mortal(newSViv(pid))); XPUSHs(sv_2mortal(newSVpv(comm, 0))); - XPUSHs(sv_2mortal(perl_process_callchain(sample, evsel, al))); + XPUSHs(sv_2mortal(perl_process_callchain(sample, al))); /* common fields other than pid can be accessed via xsub fns */ @@ -426,7 +425,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, XPUSHs(sv_2mortal(newSVuv(nsecs))); XPUSHs(sv_2mortal(newSViv(pid))); XPUSHs(sv_2mortal(newSVpv(comm, 0))); - XPUSHs(sv_2mortal(perl_process_callchain(sample, evsel, al))); + XPUSHs(sv_2mortal(perl_process_callchain(sample, al))); call_pv("main::trace_unhandled", G_SCALAR); } SPAGAIN; @@ -435,9 +434,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, LEAVE; } -static void perl_process_event_generic(union perf_event *event, - struct perf_sample *sample, - struct evsel *evsel) +static void perl_process_event_generic(union perf_event *event, struct perf_sample *sample) { dSP; @@ -448,7 +445,8 @@ static void perl_process_event_generic(union perf_event *event, SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVpvn((const char *)event, event->header.size))); - XPUSHs(sv_2mortal(newSVpvn((const char *)&evsel->core.attr, sizeof(evsel->core.attr)))); + XPUSHs(sv_2mortal(newSVpvn((const char *)&sample->evsel->core.attr, + sizeof(sample->evsel->core.attr)))); XPUSHs(sv_2mortal(newSVpvn((const char *)sample, sizeof(*sample)))); XPUSHs(sv_2mortal(newSVpvn((const char *)sample->raw_data, sample->raw_size))); PUTBACK; @@ -461,13 +459,12 @@ static void perl_process_event_generic(union perf_event *event, static void perl_process_event(union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { - scripting_context__update(scripting_context, event, sample, evsel, al, addr_al); - perl_process_tracepoint(sample, evsel, al); - perl_process_event_generic(event, sample, evsel); + scripting_context__update(scripting_context, event, sample, al, addr_al); + perl_process_tracepoint(sample, al); + perl_process_event_generic(event, sample); } static void run_start_sub(void) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 9f5c6e5e6ebe..63d04b051846 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -390,7 +390,6 @@ static unsigned long get_offset(struct symbol *sym, struct addr_location *al) } static PyObject *python_process_callchain(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al) { PyObject *pylist; @@ -651,11 +650,9 @@ static PyObject *get_sample_value_as_tuple(struct sample_read_value *value, return t; } -static void set_sample_read_in_dict(PyObject *dict_sample, - struct perf_sample *sample, - struct evsel *evsel) +static void set_sample_read_in_dict(PyObject *dict_sample, struct perf_sample *sample) { - u64 read_format = evsel->core.attr.read_format; + u64 read_format = sample->evsel->core.attr.read_format; PyObject *values; unsigned int i; @@ -741,11 +738,10 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, uint16_t e_machine, static int set_regs_in_dict(PyObject *dict, struct perf_sample *sample, - struct evsel *evsel, uint16_t e_machine, uint32_t e_flags) { - struct perf_event_attr *attr = &evsel->core.attr; + struct perf_event_attr *attr = &sample->evsel->core.attr; int size = (__sw_hweight64(attr->sample_regs_intr) * MAX_REG_SIZE) + 1; char *bf = NULL; @@ -831,7 +827,6 @@ static void python_process_sample_flags(struct perf_sample *sample, PyObject *di } static PyObject *get_perf_sample_dict(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al, PyObject *callchain) @@ -839,6 +834,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, PyObject *dict, *dict_sample, *brstack, *brstacksym; uint16_t e_machine = EM_HOST; uint32_t e_flags = EF_HOST; + struct evsel *evsel = sample->evsel; dict = PyDict_New(); if (!dict) @@ -871,7 +867,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, PyLong_FromUnsignedLongLong(sample->phys_addr)); pydict_set_item_string_decref(dict_sample, "addr", PyLong_FromUnsignedLongLong(sample->addr)); - set_sample_read_in_dict(dict_sample, sample, evsel); + set_sample_read_in_dict(dict_sample, sample); pydict_set_item_string_decref(dict_sample, "weight", PyLong_FromUnsignedLongLong(sample->weight)); pydict_set_item_string_decref(dict_sample, "ins_lat", @@ -928,7 +924,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, if (al->thread) e_machine = thread__e_machine(al->thread, /*machine=*/NULL, &e_flags); - if (set_regs_in_dict(dict, sample, evsel, e_machine, e_flags)) + if (set_regs_in_dict(dict, sample, e_machine, e_flags)) Py_FatalError("Failed to setting regs in dict"); return dict; @@ -936,7 +932,6 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, #ifdef HAVE_LIBTRACEEVENT static void python_process_tracepoint(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { @@ -954,6 +949,7 @@ static void python_process_tracepoint(struct perf_sample *sample, const char *comm = thread__comm_str(al->thread); const char *default_handler_name = "trace_unhandled"; DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX); + struct evsel *evsel = sample->evsel; bitmap_zero(events_defined, TRACE_EVENT_TYPE_MAX); @@ -995,7 +991,7 @@ static void python_process_tracepoint(struct perf_sample *sample, PyTuple_SetItem(t, n++, context); /* ip unwinding */ - callchain = python_process_callchain(sample, evsel, al); + callchain = python_process_callchain(sample, al); /* Need an additional reference for the perf_sample dict */ Py_INCREF(callchain); @@ -1051,7 +1047,7 @@ static void python_process_tracepoint(struct perf_sample *sample, PyTuple_SetItem(t, n++, dict); if (get_argument_count(handler) == (int) n + 1) { - all_entries_dict = get_perf_sample_dict(sample, evsel, al, addr_al, + all_entries_dict = get_perf_sample_dict(sample, al, addr_al, callchain); PyTuple_SetItem(t, n++, all_entries_dict); } else { @@ -1070,7 +1066,6 @@ static void python_process_tracepoint(struct perf_sample *sample, } #else static void python_process_tracepoint(struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct addr_location *al __maybe_unused, struct addr_location *addr_al __maybe_unused) { @@ -1465,7 +1460,6 @@ static int python_process_call_return(struct call_return *cr, u64 *parent_db_id, } static void python_process_general_event(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { @@ -1488,8 +1482,8 @@ static void python_process_general_event(struct perf_sample *sample, Py_FatalError("couldn't create Python tuple"); /* ip unwinding */ - callchain = python_process_callchain(sample, evsel, al); - dict = get_perf_sample_dict(sample, evsel, al, addr_al, callchain); + callchain = python_process_callchain(sample, al); + dict = get_perf_sample_dict(sample, al, addr_al, callchain); PyTuple_SetItem(t, n++, dict); if (_PyTuple_Resize(&t, n) == -1) @@ -1502,24 +1496,23 @@ static void python_process_general_event(struct perf_sample *sample, static void python_process_event(union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { struct tables *tables = &tables_global; - scripting_context__update(scripting_context, event, sample, evsel, al, addr_al); + scripting_context__update(scripting_context, event, sample, al, addr_al); - switch (evsel->core.attr.type) { + switch (sample->evsel->core.attr.type) { case PERF_TYPE_TRACEPOINT: - python_process_tracepoint(sample, evsel, al, addr_al); + python_process_tracepoint(sample, al, addr_al); break; /* Reserve for future process_hw/sw/raw APIs */ default: if (tables->db_export_mode) db_export__sample(&tables->dbe, event, sample, al, addr_al); else - python_process_general_event(sample, evsel, al, addr_al); + python_process_general_event(sample, al, addr_al); } } diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c index fa850e44cb46..dc584ac316a3 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -103,12 +103,11 @@ int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec) void scripting_context__update(struct scripting_context *c, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { #ifdef HAVE_LIBTRACEEVENT - const struct tep_event *tp_format = evsel__tp_format(evsel); + const struct tep_event *tp_format = evsel__tp_format(sample->evsel); c->pevent = tp_format ? tp_format->tep : NULL; #else @@ -117,7 +116,6 @@ void scripting_context__update(struct scripting_context *c, c->event_data = sample->raw_data; c->event = event; c->sample = sample; - c->evsel = evsel; c->al = al; c->addr_al = addr_al; } @@ -134,7 +132,6 @@ static int stop_script_unsupported(void) static void process_event_unsupported(union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct addr_location *al __maybe_unused, struct addr_location *addr_al __maybe_unused) { diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 914d9b69ed62..720121c74f1d 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -94,7 +94,6 @@ struct scripting_ops { int (*stop_script) (void); void (*process_event) (union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al); void (*process_switch)(union perf_event *event, @@ -124,7 +123,6 @@ struct scripting_context { void *event_data; union perf_event *event; struct perf_sample *sample; - struct evsel *evsel; struct addr_location *al; struct addr_location *addr_al; struct perf_session *session; @@ -133,7 +131,6 @@ struct scripting_context { void scripting_context__update(struct scripting_context *scripting_context, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al); -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 24/25] perf s390-sample-raw: Don't pass evsel with sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (22 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 23/25] perf script: Don't pass evsel with sample Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 25/25] perf evsel: " Ian Rogers ` (3 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/s390-sample-raw.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c index c6ae0ae8d86a..bfa342536b9b 100644 --- a/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -284,8 +284,9 @@ static bool s390_pai_all_test(struct perf_sample *sample) return true; } -static void s390_pai_all_dump(struct evsel *evsel, struct perf_sample *sample) +static void s390_pai_all_dump(struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; size_t len = sample->raw_size, offset = 0; unsigned char *p = sample->raw_data; const char *color = PERF_COLOR_BLUE; @@ -332,14 +333,16 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, struct perf_sample *sample) { const char *pai_name; - struct evsel *evsel; + struct evsel *evsel = sample->evsel; if (event->header.type != PERF_RECORD_SAMPLE) return; - evsel = evlist__event2evsel(evlist, event); - if (!evsel) - return; + if (!evsel) { + evsel = evlist__event2evsel(evlist, event); + if (!evsel) + return; + } /* Check for raw data in sample */ if (!sample->raw_size || !sample->raw_data) @@ -372,6 +375,6 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, } else { if (!evsel->pmu) evsel->pmu = perf_pmus__find_by_type(evsel->core.attr.type); - s390_pai_all_dump(evsel, sample); + s390_pai_all_dump(sample); } } -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v1 25/25] perf evsel: Don't pass evsel with sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (23 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 24/25] perf s390-sample-raw: " Ian Rogers @ 2026-02-09 17:40 ` Ian Rogers 2026-02-23 19:15 ` [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (2 subsequent siblings) 27 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-02-09 17:40 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel Arrange for the sample to contain the evsel and so it is unnecessary to pass the evsel as well. This is done for uniformity, although parsing of the sample is arguably a special case. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/evsel.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 041766d39ec3..21602d121260 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2997,10 +2997,10 @@ 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; @@ -3239,14 +3239,14 @@ 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); + perf_evsel__parse_id_sample(event, data); return 0; } if (event->header.type != PERF_RECORD_SAMPLE) { if (evsel->core.attr.sample_id_all) - perf_evsel__parse_id_sample(evsel, event, data); + perf_evsel__parse_id_sample(event, data); return 0; } @@ -3606,12 +3606,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; -- 2.53.0.239.g8d8fc8a987-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* Re: [PATCH v1 00/25] perf tool: Add evsel to perf_sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (24 preceding siblings ...) 2026-02-09 17:40 ` [PATCH v1 25/25] perf evsel: " Ian Rogers @ 2026-02-23 19:15 ` Ian Rogers 2026-03-02 17:56 ` Ian Rogers 2026-03-04 1:02 ` Namhyung Kim 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers 27 siblings, 1 reply; 112+ messages in thread From: Ian Rogers @ 2026-02-23 19:15 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel On Mon, Feb 9, 2026 at 9:40 AM Ian Rogers <irogers@google.com> wrote: > > Nearly all perf code ends up passing an evsel with the perf_sample, > which is problematic if you want to rewrite the evsel such as with > off-CPU processing - all uses of the evsel need fixing up. Previously > I'd mailed this patch as an RFC with everything combined: > https://lore.kernel.org/lkml/20260126071822.447368-1-irogers@google.com/ > and there was a request to break it up. > > I've started the series by adding documentation to struct > perf_sample. Next I fixed missing perf_sample__init/exit largely from > the recent perf inject callchain rewriting work. The 3rd patch adds > the evsel to struct perf_sample and ensures it is correctly > initialized. The next 22 patches avoid passing the evsel along with > sample for different parts of the perf tool, along with some minor > tweaks like constification and not determining the evsel if it is > present in the sample. Ping. Thanks, Ian > Ian Rogers (25): > perf sample: Document struct perf_sample > perf sample: Make sure perf_sample__init/exit are used > perf sample: Add evsel to struct perf_sample > perf tool: Remove evsel from tool APIs that pass the sample > perf kvm: Don't pass evsel with sample > perf evsel: Refactor evsel__intval to perf_sample__intval > perf trace: Don't pass evsel with sample > perf callchain: Don't pass evsel and sample > perf lock: Only pass sample to handlers > perf lock: Constify trace_lock_handler variables > perf hist: Remove evsel parameter from inc samples functions > perf db-export: Remove evsel from struct export_sample > perf hist: Remove evsel from struct hist_entry_iter > perf report: Directly use sample->evsel to avoid computing from > sample->id > perf annotate: Don't pass evsel to add_sample > perf inject: Don't pass evsel with sample > perf kmem: Don't pass evsel with sample > perf kwork: Don't pass evsel with sample > perf sched: Don't pass evsel with sample > perf timechart: Don't pass evsel with sample > perf trace: Don't pass evsel with sample > perf evlist: Try to avoid computing evsel from sample > perf script: Don't pass evsel with sample > perf s390-sample-raw: Don't pass evsel with sample > perf evsel: Don't pass evsel with sample > > tools/perf/builtin-annotate.c | 28 ++- > tools/perf/builtin-c2c.c | 6 +- > tools/perf/builtin-diff.c | 5 +- > tools/perf/builtin-inject.c | 81 ++++---- > tools/perf/builtin-kmem.c | 58 +++--- > tools/perf/builtin-kvm.c | 22 +-- > tools/perf/builtin-kwork.c | 104 ++++------ > tools/perf/builtin-lock.c | 117 +++++------ > tools/perf/builtin-mem.c | 1 - > tools/perf/builtin-record.c | 3 +- > tools/perf/builtin-report.c | 38 ++-- > tools/perf/builtin-sched.c | 183 ++++++++---------- > tools/perf/builtin-script.c | 26 ++- > tools/perf/builtin-timechart.c | 76 +++----- > tools/perf/builtin-top.c | 19 +- > tools/perf/builtin-trace.c | 103 +++++----- > tools/perf/tests/hists_cumulate.c | 3 +- > tools/perf/tests/hists_filter.c | 2 +- > tools/perf/tests/hists_output.c | 3 +- > tools/perf/tests/mmap-basic.c | 4 +- > tools/perf/tests/openat-syscall-tp-fields.c | 2 +- > tools/perf/tests/switch-tracking.c | 9 +- > tools/perf/util/annotate.c | 19 +- > tools/perf/util/annotate.h | 6 +- > tools/perf/util/build-id.c | 3 +- > tools/perf/util/build-id.h | 7 +- > tools/perf/util/callchain.c | 8 +- > tools/perf/util/callchain.h | 5 +- > tools/perf/util/data-convert-bt.c | 2 +- > tools/perf/util/data-convert-json.c | 5 +- > tools/perf/util/db-export.c | 13 +- > tools/perf/util/db-export.h | 3 +- > tools/perf/util/evsel.c | 60 +++--- > tools/perf/util/evsel.h | 12 +- > tools/perf/util/hist.c | 26 +-- > tools/perf/util/hist.h | 3 +- > tools/perf/util/intel-pt.c | 12 +- > tools/perf/util/intel-tpebs.c | 3 +- > tools/perf/util/jitdump.c | 2 +- > .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 19 +- > .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 +- > .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 +- > .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 17 +- > tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +- > tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 +++---- > tools/perf/util/kvm-stat.c | 19 +- > tools/perf/util/kvm-stat.h | 18 +- > tools/perf/util/kwork.h | 9 +- > tools/perf/util/machine.c | 14 +- > tools/perf/util/machine.h | 3 - > tools/perf/util/s390-sample-raw.c | 15 +- > tools/perf/util/sample.c | 8 +- > tools/perf/util/sample.h | 93 ++++++++- > .../util/scripting-engines/trace-event-perl.c | 23 +-- > .../scripting-engines/trace-event-python.c | 47 ++--- > tools/perf/util/session.c | 74 ++++--- > tools/perf/util/synthetic-events.c | 9 +- > tools/perf/util/synthetic-events.h | 2 - > tools/perf/util/tool.c | 4 +- > tools/perf/util/tool.h | 4 +- > tools/perf/util/trace-event-scripting.c | 5 +- > tools/perf/util/trace-event.h | 3 - > 62 files changed, 769 insertions(+), 823 deletions(-) > > -- > 2.53.0.239.g8d8fc8a987-goog > ^ permalink raw reply [flat|nested] 112+ messages in thread
* Re: [PATCH v1 00/25] perf tool: Add evsel to perf_sample 2026-02-23 19:15 ` [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers @ 2026-03-02 17:56 ` Ian Rogers 2026-03-03 1:15 ` Namhyung Kim 0 siblings, 1 reply; 112+ messages in thread From: Ian Rogers @ 2026-03-02 17:56 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel On Mon, Feb 23, 2026 at 11:15 AM Ian Rogers <irogers@google.com> wrote: > > On Mon, Feb 9, 2026 at 9:40 AM Ian Rogers <irogers@google.com> wrote: > > > > Nearly all perf code ends up passing an evsel with the perf_sample, > > which is problematic if you want to rewrite the evsel such as with > > off-CPU processing - all uses of the evsel need fixing up. Previously > > I'd mailed this patch as an RFC with everything combined: > > https://lore.kernel.org/lkml/20260126071822.447368-1-irogers@google.com/ > > and there was a request to break it up. > > > > I've started the series by adding documentation to struct > > perf_sample. Next I fixed missing perf_sample__init/exit largely from > > the recent perf inject callchain rewriting work. The 3rd patch adds > > the evsel to struct perf_sample and ensures it is correctly > > initialized. The next 22 patches avoid passing the evsel along with > > sample for different parts of the perf tool, along with some minor > > tweaks like constification and not determining the evsel if it is > > present in the sample. > > Ping. Ping. Thanks, Ian > > Ian Rogers (25): > > perf sample: Document struct perf_sample > > perf sample: Make sure perf_sample__init/exit are used > > perf sample: Add evsel to struct perf_sample > > perf tool: Remove evsel from tool APIs that pass the sample > > perf kvm: Don't pass evsel with sample > > perf evsel: Refactor evsel__intval to perf_sample__intval > > perf trace: Don't pass evsel with sample > > perf callchain: Don't pass evsel and sample > > perf lock: Only pass sample to handlers > > perf lock: Constify trace_lock_handler variables > > perf hist: Remove evsel parameter from inc samples functions > > perf db-export: Remove evsel from struct export_sample > > perf hist: Remove evsel from struct hist_entry_iter > > perf report: Directly use sample->evsel to avoid computing from > > sample->id > > perf annotate: Don't pass evsel to add_sample > > perf inject: Don't pass evsel with sample > > perf kmem: Don't pass evsel with sample > > perf kwork: Don't pass evsel with sample > > perf sched: Don't pass evsel with sample > > perf timechart: Don't pass evsel with sample > > perf trace: Don't pass evsel with sample > > perf evlist: Try to avoid computing evsel from sample > > perf script: Don't pass evsel with sample > > perf s390-sample-raw: Don't pass evsel with sample > > perf evsel: Don't pass evsel with sample > > > > tools/perf/builtin-annotate.c | 28 ++- > > tools/perf/builtin-c2c.c | 6 +- > > tools/perf/builtin-diff.c | 5 +- > > tools/perf/builtin-inject.c | 81 ++++---- > > tools/perf/builtin-kmem.c | 58 +++--- > > tools/perf/builtin-kvm.c | 22 +-- > > tools/perf/builtin-kwork.c | 104 ++++------ > > tools/perf/builtin-lock.c | 117 +++++------ > > tools/perf/builtin-mem.c | 1 - > > tools/perf/builtin-record.c | 3 +- > > tools/perf/builtin-report.c | 38 ++-- > > tools/perf/builtin-sched.c | 183 ++++++++---------- > > tools/perf/builtin-script.c | 26 ++- > > tools/perf/builtin-timechart.c | 76 +++----- > > tools/perf/builtin-top.c | 19 +- > > tools/perf/builtin-trace.c | 103 +++++----- > > tools/perf/tests/hists_cumulate.c | 3 +- > > tools/perf/tests/hists_filter.c | 2 +- > > tools/perf/tests/hists_output.c | 3 +- > > tools/perf/tests/mmap-basic.c | 4 +- > > tools/perf/tests/openat-syscall-tp-fields.c | 2 +- > > tools/perf/tests/switch-tracking.c | 9 +- > > tools/perf/util/annotate.c | 19 +- > > tools/perf/util/annotate.h | 6 +- > > tools/perf/util/build-id.c | 3 +- > > tools/perf/util/build-id.h | 7 +- > > tools/perf/util/callchain.c | 8 +- > > tools/perf/util/callchain.h | 5 +- > > tools/perf/util/data-convert-bt.c | 2 +- > > tools/perf/util/data-convert-json.c | 5 +- > > tools/perf/util/db-export.c | 13 +- > > tools/perf/util/db-export.h | 3 +- > > tools/perf/util/evsel.c | 60 +++--- > > tools/perf/util/evsel.h | 12 +- > > tools/perf/util/hist.c | 26 +-- > > tools/perf/util/hist.h | 3 +- > > tools/perf/util/intel-pt.c | 12 +- > > tools/perf/util/intel-tpebs.c | 3 +- > > tools/perf/util/jitdump.c | 2 +- > > .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 19 +- > > .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 +- > > .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 +- > > .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 17 +- > > tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +- > > tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 +++---- > > tools/perf/util/kvm-stat.c | 19 +- > > tools/perf/util/kvm-stat.h | 18 +- > > tools/perf/util/kwork.h | 9 +- > > tools/perf/util/machine.c | 14 +- > > tools/perf/util/machine.h | 3 - > > tools/perf/util/s390-sample-raw.c | 15 +- > > tools/perf/util/sample.c | 8 +- > > tools/perf/util/sample.h | 93 ++++++++- > > .../util/scripting-engines/trace-event-perl.c | 23 +-- > > .../scripting-engines/trace-event-python.c | 47 ++--- > > tools/perf/util/session.c | 74 ++++--- > > tools/perf/util/synthetic-events.c | 9 +- > > tools/perf/util/synthetic-events.h | 2 - > > tools/perf/util/tool.c | 4 +- > > tools/perf/util/tool.h | 4 +- > > tools/perf/util/trace-event-scripting.c | 5 +- > > tools/perf/util/trace-event.h | 3 - > > 62 files changed, 769 insertions(+), 823 deletions(-) > > > > -- > > 2.53.0.239.g8d8fc8a987-goog > > ^ permalink raw reply [flat|nested] 112+ messages in thread
* Re: [PATCH v1 00/25] perf tool: Add evsel to perf_sample 2026-03-02 17:56 ` Ian Rogers @ 2026-03-03 1:15 ` Namhyung Kim 0 siblings, 0 replies; 112+ messages in thread From: Namhyung Kim @ 2026-03-03 1:15 UTC (permalink / raw) To: Ian Rogers Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel On Mon, Mar 02, 2026 at 09:56:54AM -0800, Ian Rogers wrote: > On Mon, Feb 23, 2026 at 11:15 AM Ian Rogers <irogers@google.com> wrote: > > > > On Mon, Feb 9, 2026 at 9:40 AM Ian Rogers <irogers@google.com> wrote: > > > > > > Nearly all perf code ends up passing an evsel with the perf_sample, > > > which is problematic if you want to rewrite the evsel such as with > > > off-CPU processing - all uses of the evsel need fixing up. Previously > > > I'd mailed this patch as an RFC with everything combined: > > > https://lore.kernel.org/lkml/20260126071822.447368-1-irogers@google.com/ > > > and there was a request to break it up. > > > > > > I've started the series by adding documentation to struct > > > perf_sample. Next I fixed missing perf_sample__init/exit largely from > > > the recent perf inject callchain rewriting work. The 3rd patch adds > > > the evsel to struct perf_sample and ensures it is correctly > > > initialized. The next 22 patches avoid passing the evsel along with > > > sample for different parts of the perf tool, along with some minor > > > tweaks like constification and not determining the evsel if it is > > > present in the sample. > > > > Ping. > > Ping. Sorry for the delay. I'll take a look this week. Thanks, Namhyung > > > Ian Rogers (25): > > > perf sample: Document struct perf_sample > > > perf sample: Make sure perf_sample__init/exit are used > > > perf sample: Add evsel to struct perf_sample > > > perf tool: Remove evsel from tool APIs that pass the sample > > > perf kvm: Don't pass evsel with sample > > > perf evsel: Refactor evsel__intval to perf_sample__intval > > > perf trace: Don't pass evsel with sample > > > perf callchain: Don't pass evsel and sample > > > perf lock: Only pass sample to handlers > > > perf lock: Constify trace_lock_handler variables > > > perf hist: Remove evsel parameter from inc samples functions > > > perf db-export: Remove evsel from struct export_sample > > > perf hist: Remove evsel from struct hist_entry_iter > > > perf report: Directly use sample->evsel to avoid computing from > > > sample->id > > > perf annotate: Don't pass evsel to add_sample > > > perf inject: Don't pass evsel with sample > > > perf kmem: Don't pass evsel with sample > > > perf kwork: Don't pass evsel with sample > > > perf sched: Don't pass evsel with sample > > > perf timechart: Don't pass evsel with sample > > > perf trace: Don't pass evsel with sample > > > perf evlist: Try to avoid computing evsel from sample > > > perf script: Don't pass evsel with sample > > > perf s390-sample-raw: Don't pass evsel with sample > > > perf evsel: Don't pass evsel with sample > > > > > > tools/perf/builtin-annotate.c | 28 ++- > > > tools/perf/builtin-c2c.c | 6 +- > > > tools/perf/builtin-diff.c | 5 +- > > > tools/perf/builtin-inject.c | 81 ++++---- > > > tools/perf/builtin-kmem.c | 58 +++--- > > > tools/perf/builtin-kvm.c | 22 +-- > > > tools/perf/builtin-kwork.c | 104 ++++------ > > > tools/perf/builtin-lock.c | 117 +++++------ > > > tools/perf/builtin-mem.c | 1 - > > > tools/perf/builtin-record.c | 3 +- > > > tools/perf/builtin-report.c | 38 ++-- > > > tools/perf/builtin-sched.c | 183 ++++++++---------- > > > tools/perf/builtin-script.c | 26 ++- > > > tools/perf/builtin-timechart.c | 76 +++----- > > > tools/perf/builtin-top.c | 19 +- > > > tools/perf/builtin-trace.c | 103 +++++----- > > > tools/perf/tests/hists_cumulate.c | 3 +- > > > tools/perf/tests/hists_filter.c | 2 +- > > > tools/perf/tests/hists_output.c | 3 +- > > > tools/perf/tests/mmap-basic.c | 4 +- > > > tools/perf/tests/openat-syscall-tp-fields.c | 2 +- > > > tools/perf/tests/switch-tracking.c | 9 +- > > > tools/perf/util/annotate.c | 19 +- > > > tools/perf/util/annotate.h | 6 +- > > > tools/perf/util/build-id.c | 3 +- > > > tools/perf/util/build-id.h | 7 +- > > > tools/perf/util/callchain.c | 8 +- > > > tools/perf/util/callchain.h | 5 +- > > > tools/perf/util/data-convert-bt.c | 2 +- > > > tools/perf/util/data-convert-json.c | 5 +- > > > tools/perf/util/db-export.c | 13 +- > > > tools/perf/util/db-export.h | 3 +- > > > tools/perf/util/evsel.c | 60 +++--- > > > tools/perf/util/evsel.h | 12 +- > > > tools/perf/util/hist.c | 26 +-- > > > tools/perf/util/hist.h | 3 +- > > > tools/perf/util/intel-pt.c | 12 +- > > > tools/perf/util/intel-tpebs.c | 3 +- > > > tools/perf/util/jitdump.c | 2 +- > > > .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 19 +- > > > .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 +- > > > .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 +- > > > .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 17 +- > > > tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +- > > > tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 +++---- > > > tools/perf/util/kvm-stat.c | 19 +- > > > tools/perf/util/kvm-stat.h | 18 +- > > > tools/perf/util/kwork.h | 9 +- > > > tools/perf/util/machine.c | 14 +- > > > tools/perf/util/machine.h | 3 - > > > tools/perf/util/s390-sample-raw.c | 15 +- > > > tools/perf/util/sample.c | 8 +- > > > tools/perf/util/sample.h | 93 ++++++++- > > > .../util/scripting-engines/trace-event-perl.c | 23 +-- > > > .../scripting-engines/trace-event-python.c | 47 ++--- > > > tools/perf/util/session.c | 74 ++++--- > > > tools/perf/util/synthetic-events.c | 9 +- > > > tools/perf/util/synthetic-events.h | 2 - > > > tools/perf/util/tool.c | 4 +- > > > tools/perf/util/tool.h | 4 +- > > > tools/perf/util/trace-event-scripting.c | 5 +- > > > tools/perf/util/trace-event.h | 3 - > > > 62 files changed, 769 insertions(+), 823 deletions(-) > > > > > > -- > > > 2.53.0.239.g8d8fc8a987-goog > > > ^ permalink raw reply [flat|nested] 112+ messages in thread
* Re: [PATCH v1 00/25] perf tool: Add evsel to perf_sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (25 preceding siblings ...) 2026-02-23 19:15 ` [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers @ 2026-03-04 1:02 ` Namhyung Kim 2026-03-04 16:19 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers 27 siblings, 1 reply; 112+ messages in thread From: Namhyung Kim @ 2026-03-04 1:02 UTC (permalink / raw) To: Ian Rogers Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel On Mon, Feb 09, 2026 at 09:40:07AM -0800, Ian Rogers wrote: > Nearly all perf code ends up passing an evsel with the perf_sample, > which is problematic if you want to rewrite the evsel such as with > off-CPU processing - all uses of the evsel need fixing up. Previously > I'd mailed this patch as an RFC with everything combined: > https://lore.kernel.org/lkml/20260126071822.447368-1-irogers@google.com/ > and there was a request to break it up. > > I've started the series by adding documentation to struct > perf_sample. Next I fixed missing perf_sample__init/exit largely from > the recent perf inject callchain rewriting work. The 3rd patch adds > the evsel to struct perf_sample and ensures it is correctly > initialized. The next 22 patches avoid passing the evsel along with > sample for different parts of the perf tool, along with some minor > tweaks like constification and not determining the evsel if it is > present in the sample. Do you have a patch for off-CPU on top of this change? I'd like to see what you expect before applying massive changes. Thanks, Namhyung > > Ian Rogers (25): > perf sample: Document struct perf_sample > perf sample: Make sure perf_sample__init/exit are used > perf sample: Add evsel to struct perf_sample > perf tool: Remove evsel from tool APIs that pass the sample > perf kvm: Don't pass evsel with sample > perf evsel: Refactor evsel__intval to perf_sample__intval > perf trace: Don't pass evsel with sample > perf callchain: Don't pass evsel and sample > perf lock: Only pass sample to handlers > perf lock: Constify trace_lock_handler variables > perf hist: Remove evsel parameter from inc samples functions > perf db-export: Remove evsel from struct export_sample > perf hist: Remove evsel from struct hist_entry_iter > perf report: Directly use sample->evsel to avoid computing from > sample->id > perf annotate: Don't pass evsel to add_sample > perf inject: Don't pass evsel with sample > perf kmem: Don't pass evsel with sample > perf kwork: Don't pass evsel with sample > perf sched: Don't pass evsel with sample > perf timechart: Don't pass evsel with sample > perf trace: Don't pass evsel with sample > perf evlist: Try to avoid computing evsel from sample > perf script: Don't pass evsel with sample > perf s390-sample-raw: Don't pass evsel with sample > perf evsel: Don't pass evsel with sample > > tools/perf/builtin-annotate.c | 28 ++- > tools/perf/builtin-c2c.c | 6 +- > tools/perf/builtin-diff.c | 5 +- > tools/perf/builtin-inject.c | 81 ++++---- > tools/perf/builtin-kmem.c | 58 +++--- > tools/perf/builtin-kvm.c | 22 +-- > tools/perf/builtin-kwork.c | 104 ++++------ > tools/perf/builtin-lock.c | 117 +++++------ > tools/perf/builtin-mem.c | 1 - > tools/perf/builtin-record.c | 3 +- > tools/perf/builtin-report.c | 38 ++-- > tools/perf/builtin-sched.c | 183 ++++++++---------- > tools/perf/builtin-script.c | 26 ++- > tools/perf/builtin-timechart.c | 76 +++----- > tools/perf/builtin-top.c | 19 +- > tools/perf/builtin-trace.c | 103 +++++----- > tools/perf/tests/hists_cumulate.c | 3 +- > tools/perf/tests/hists_filter.c | 2 +- > tools/perf/tests/hists_output.c | 3 +- > tools/perf/tests/mmap-basic.c | 4 +- > tools/perf/tests/openat-syscall-tp-fields.c | 2 +- > tools/perf/tests/switch-tracking.c | 9 +- > tools/perf/util/annotate.c | 19 +- > tools/perf/util/annotate.h | 6 +- > tools/perf/util/build-id.c | 3 +- > tools/perf/util/build-id.h | 7 +- > tools/perf/util/callchain.c | 8 +- > tools/perf/util/callchain.h | 5 +- > tools/perf/util/data-convert-bt.c | 2 +- > tools/perf/util/data-convert-json.c | 5 +- > tools/perf/util/db-export.c | 13 +- > tools/perf/util/db-export.h | 3 +- > tools/perf/util/evsel.c | 60 +++--- > tools/perf/util/evsel.h | 12 +- > tools/perf/util/hist.c | 26 +-- > tools/perf/util/hist.h | 3 +- > tools/perf/util/intel-pt.c | 12 +- > tools/perf/util/intel-tpebs.c | 3 +- > tools/perf/util/jitdump.c | 2 +- > .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 19 +- > .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 +- > .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 +- > .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 17 +- > tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +- > tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 +++---- > tools/perf/util/kvm-stat.c | 19 +- > tools/perf/util/kvm-stat.h | 18 +- > tools/perf/util/kwork.h | 9 +- > tools/perf/util/machine.c | 14 +- > tools/perf/util/machine.h | 3 - > tools/perf/util/s390-sample-raw.c | 15 +- > tools/perf/util/sample.c | 8 +- > tools/perf/util/sample.h | 93 ++++++++- > .../util/scripting-engines/trace-event-perl.c | 23 +-- > .../scripting-engines/trace-event-python.c | 47 ++--- > tools/perf/util/session.c | 74 ++++--- > tools/perf/util/synthetic-events.c | 9 +- > tools/perf/util/synthetic-events.h | 2 - > tools/perf/util/tool.c | 4 +- > tools/perf/util/tool.h | 4 +- > tools/perf/util/trace-event-scripting.c | 5 +- > tools/perf/util/trace-event.h | 3 - > 62 files changed, 769 insertions(+), 823 deletions(-) > > -- > 2.53.0.239.g8d8fc8a987-goog > ^ permalink raw reply [flat|nested] 112+ messages in thread
* Re: [PATCH v1 00/25] perf tool: Add evsel to perf_sample 2026-03-04 1:02 ` Namhyung Kim @ 2026-03-04 16:19 ` Ian Rogers 0 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-04 16:19 UTC (permalink / raw) To: Namhyung Kim Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa, Adrian Hunter, James Clark, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Leo Yan, Tianyou Li, Athira Rajeev, Derek Foreman, Thomas Falcon, Howard Chu, Dmitry Vyukov, Andi Kleen, tanze, Hrishikesh Suresh, Quan Zhou, Andrew Jones, Anup Patel, Dapeng Mi, Dr. David Alan Gilbert, Krzysztof Łopatowski, Chun-Tse Shao, Ravi Bangoria, Swapnil Sapkal, Chen Ni, Blake Jones, Yujie Liu, linux-perf-users, linux-kernel On Tue, Mar 3, 2026 at 5:02 PM Namhyung Kim <namhyung@kernel.org> wrote: > > On Mon, Feb 09, 2026 at 09:40:07AM -0800, Ian Rogers wrote: > > Nearly all perf code ends up passing an evsel with the perf_sample, > > which is problematic if you want to rewrite the evsel such as with > > off-CPU processing - all uses of the evsel need fixing up. Previously > > I'd mailed this patch as an RFC with everything combined: > > https://lore.kernel.org/lkml/20260126071822.447368-1-irogers@google.com/ > > and there was a request to break it up. > > > > I've started the series by adding documentation to struct > > perf_sample. Next I fixed missing perf_sample__init/exit largely from > > the recent perf inject callchain rewriting work. The 3rd patch adds > > the evsel to struct perf_sample and ensures it is correctly > > initialized. The next 22 patches avoid passing the evsel along with > > sample for different parts of the perf tool, along with some minor > > tweaks like constification and not determining the evsel if it is > > present in the sample. > > Do you have a patch for off-CPU on top of this change? I'd like to see > what you expect before applying massive changes. I'll need to rebase on top of these changes as it was on top of: https://lore.kernel.org/lkml/20260126071822.447368-1-irogers@google.com/ Wrt size, these changes are prior to adding extra comments... was: 57 files changed, 599 insertions(+), 749 deletions(-) and last year we landed a clean up of: https://lore.kernel.org/lkml/20251105001103.1296863-1-irogers@google.com/#t which was: 17 files changed, 130 insertions(+), 93 deletions(-) but that was 1 patch and this is now broken into 25. Thanks, Ian > Thanks, > Namhyung > > > > > Ian Rogers (25): > > perf sample: Document struct perf_sample > > perf sample: Make sure perf_sample__init/exit are used > > perf sample: Add evsel to struct perf_sample > > perf tool: Remove evsel from tool APIs that pass the sample > > perf kvm: Don't pass evsel with sample > > perf evsel: Refactor evsel__intval to perf_sample__intval > > perf trace: Don't pass evsel with sample > > perf callchain: Don't pass evsel and sample > > perf lock: Only pass sample to handlers > > perf lock: Constify trace_lock_handler variables > > perf hist: Remove evsel parameter from inc samples functions > > perf db-export: Remove evsel from struct export_sample > > perf hist: Remove evsel from struct hist_entry_iter > > perf report: Directly use sample->evsel to avoid computing from > > sample->id > > perf annotate: Don't pass evsel to add_sample > > perf inject: Don't pass evsel with sample > > perf kmem: Don't pass evsel with sample > > perf kwork: Don't pass evsel with sample > > perf sched: Don't pass evsel with sample > > perf timechart: Don't pass evsel with sample > > perf trace: Don't pass evsel with sample > > perf evlist: Try to avoid computing evsel from sample > > perf script: Don't pass evsel with sample > > perf s390-sample-raw: Don't pass evsel with sample > > perf evsel: Don't pass evsel with sample > > > > tools/perf/builtin-annotate.c | 28 ++- > > tools/perf/builtin-c2c.c | 6 +- > > tools/perf/builtin-diff.c | 5 +- > > tools/perf/builtin-inject.c | 81 ++++---- > > tools/perf/builtin-kmem.c | 58 +++--- > > tools/perf/builtin-kvm.c | 22 +-- > > tools/perf/builtin-kwork.c | 104 ++++------ > > tools/perf/builtin-lock.c | 117 +++++------ > > tools/perf/builtin-mem.c | 1 - > > tools/perf/builtin-record.c | 3 +- > > tools/perf/builtin-report.c | 38 ++-- > > tools/perf/builtin-sched.c | 183 ++++++++---------- > > tools/perf/builtin-script.c | 26 ++- > > tools/perf/builtin-timechart.c | 76 +++----- > > tools/perf/builtin-top.c | 19 +- > > tools/perf/builtin-trace.c | 103 +++++----- > > tools/perf/tests/hists_cumulate.c | 3 +- > > tools/perf/tests/hists_filter.c | 2 +- > > tools/perf/tests/hists_output.c | 3 +- > > tools/perf/tests/mmap-basic.c | 4 +- > > tools/perf/tests/openat-syscall-tp-fields.c | 2 +- > > tools/perf/tests/switch-tracking.c | 9 +- > > tools/perf/util/annotate.c | 19 +- > > tools/perf/util/annotate.h | 6 +- > > tools/perf/util/build-id.c | 3 +- > > tools/perf/util/build-id.h | 7 +- > > tools/perf/util/callchain.c | 8 +- > > tools/perf/util/callchain.h | 5 +- > > tools/perf/util/data-convert-bt.c | 2 +- > > tools/perf/util/data-convert-json.c | 5 +- > > tools/perf/util/db-export.c | 13 +- > > tools/perf/util/db-export.h | 3 +- > > tools/perf/util/evsel.c | 60 +++--- > > tools/perf/util/evsel.h | 12 +- > > tools/perf/util/hist.c | 26 +-- > > tools/perf/util/hist.h | 3 +- > > tools/perf/util/intel-pt.c | 12 +- > > tools/perf/util/intel-tpebs.c | 3 +- > > tools/perf/util/jitdump.c | 2 +- > > .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 19 +- > > .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 +- > > .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 +- > > .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 17 +- > > tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +- > > tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 +++---- > > tools/perf/util/kvm-stat.c | 19 +- > > tools/perf/util/kvm-stat.h | 18 +- > > tools/perf/util/kwork.h | 9 +- > > tools/perf/util/machine.c | 14 +- > > tools/perf/util/machine.h | 3 - > > tools/perf/util/s390-sample-raw.c | 15 +- > > tools/perf/util/sample.c | 8 +- > > tools/perf/util/sample.h | 93 ++++++++- > > .../util/scripting-engines/trace-event-perl.c | 23 +-- > > .../scripting-engines/trace-event-python.c | 47 ++--- > > tools/perf/util/session.c | 74 ++++--- > > tools/perf/util/synthetic-events.c | 9 +- > > tools/perf/util/synthetic-events.h | 2 - > > tools/perf/util/tool.c | 4 +- > > tools/perf/util/tool.h | 4 +- > > tools/perf/util/trace-event-scripting.c | 5 +- > > tools/perf/util/trace-event.h | 3 - > > 62 files changed, 769 insertions(+), 823 deletions(-) > > > > -- > > 2.53.0.239.g8d8fc8a987-goog > > ^ permalink raw reply [flat|nested] 112+ messages in thread
* [PATCH v2 00/25] perf tool: Add evsel to perf_sample 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (26 preceding siblings ...) 2026-03-04 1:02 ` Namhyung Kim @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 01/25] perf sample: Document struct perf_sample Ian Rogers ` (25 more replies) 27 siblings, 26 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Nearly all perf code ends up passing an evsel with the perf_sample, which is problematic if you want to rewrite the evsel such as with off-CPU processing - all uses of the evsel need fixing up. Previously I'd mailed this patch as an RFC with everything combined: https://lore.kernel.org/lkml/20260126071822.447368-1-irogers@google.com/ and there was a request to break it up. I've started the series by adding documentation to struct perf_sample. Next I fixed missing perf_sample__init/exit largely from the recent perf inject callchain rewriting work. The 3rd patch adds the evsel to struct perf_sample and ensures it is correctly initialized. The next 22 patches avoid passing the evsel along with sample for different parts of the perf tool, along with some minor tweaks like constification and not determining the evsel if it is present in the sample. v1: Add review feedback on the first 2 patches from Namhyung, fix a missed evsel assignment running event2evsel in builtin-inject. https://lore.kernel.org/lkml/20260209174032.4142096-1-irogers@google.com/ Ian Rogers (25): perf sample: Document struct perf_sample perf sample: Make sure perf_sample__init/exit are used perf sample: Add evsel to struct perf_sample perf tool: Remove evsel from tool APIs that pass the sample perf kvm: Don't pass evsel with sample perf evsel: Refactor evsel__intval to perf_sample__intval perf trace: Don't pass evsel with sample perf callchain: Don't pass evsel and sample perf lock: Only pass sample to handlers perf lock: Constify trace_lock_handler variables perf hist: Remove evsel parameter from inc samples functions perf db-export: Remove evsel from struct export_sample perf hist: Remove evsel from struct hist_entry_iter perf report: Directly use sample->evsel to avoid computing from sample->id perf annotate: Don't pass evsel to add_sample perf inject: Don't pass evsel with sample perf kmem: Don't pass evsel with sample perf kwork: Don't pass evsel with sample perf sched: Don't pass evsel with sample perf timechart: Don't pass evsel with sample perf trace: Don't pass evsel with sample perf evlist: Try to avoid computing evsel from sample perf script: Don't pass evsel with sample perf s390-sample-raw: Don't pass evsel with sample perf evsel: Don't pass evsel with sample tools/perf/builtin-annotate.c | 28 ++- tools/perf/builtin-c2c.c | 6 +- tools/perf/builtin-diff.c | 5 +- tools/perf/builtin-inject.c | 79 ++++---- tools/perf/builtin-kmem.c | 58 +++--- tools/perf/builtin-kvm.c | 22 +-- tools/perf/builtin-kwork.c | 104 ++++------ tools/perf/builtin-lock.c | 117 +++++------ tools/perf/builtin-mem.c | 1 - tools/perf/builtin-record.c | 3 +- tools/perf/builtin-report.c | 38 ++-- tools/perf/builtin-sched.c | 183 ++++++++---------- tools/perf/builtin-script.c | 26 ++- tools/perf/builtin-timechart.c | 76 +++----- tools/perf/builtin-top.c | 19 +- tools/perf/builtin-trace.c | 103 +++++----- tools/perf/tests/hists_cumulate.c | 3 +- tools/perf/tests/hists_filter.c | 2 +- tools/perf/tests/hists_output.c | 3 +- tools/perf/tests/mmap-basic.c | 4 +- tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/tests/switch-tracking.c | 9 +- tools/perf/util/annotate.c | 19 +- tools/perf/util/annotate.h | 6 +- tools/perf/util/build-id.c | 3 +- tools/perf/util/build-id.h | 7 +- tools/perf/util/callchain.c | 8 +- tools/perf/util/callchain.h | 5 +- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data-convert-json.c | 5 +- tools/perf/util/db-export.c | 13 +- tools/perf/util/db-export.h | 3 +- tools/perf/util/evlist.c | 5 +- tools/perf/util/evsel.c | 60 +++--- tools/perf/util/evsel.h | 12 +- tools/perf/util/hist.c | 26 +-- tools/perf/util/hist.h | 3 +- tools/perf/util/intel-pt.c | 12 +- tools/perf/util/intel-tpebs.c | 3 +- tools/perf/util/jitdump.c | 2 +- .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 19 +- .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 +- .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 +- .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 17 +- tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +- tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 +++---- tools/perf/util/kvm-stat.c | 19 +- tools/perf/util/kvm-stat.h | 18 +- tools/perf/util/kwork.h | 9 +- tools/perf/util/machine.c | 14 +- tools/perf/util/machine.h | 3 - tools/perf/util/s390-sample-raw.c | 15 +- tools/perf/util/sample.c | 10 +- tools/perf/util/sample.h | 113 ++++++++++- .../util/scripting-engines/trace-event-perl.c | 23 +-- .../scripting-engines/trace-event-python.c | 47 ++--- tools/perf/util/session.c | 74 ++++--- tools/perf/util/synthetic-events.c | 9 +- tools/perf/util/synthetic-events.h | 2 - tools/perf/util/tool.c | 4 +- tools/perf/util/tool.h | 4 +- tools/perf/util/trace-event-scripting.c | 5 +- tools/perf/util/trace-event.h | 3 - 63 files changed, 792 insertions(+), 825 deletions(-) -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply [flat|nested] 112+ messages in thread
* [PATCH v2 01/25] perf sample: Document struct perf_sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers ` (24 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Add kernel-doc for struct perf_sample capturing the somewhat unusual population of fields and lifetime relationships. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/sample.h | 110 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 3cce8dd202aa..88ff154b630c 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -81,47 +81,149 @@ struct simd_flags { #define SIMD_OP_FLAGS_PRED_PARTIAL 0x01 /* partial predicate */ #define SIMD_OP_FLAGS_PRED_EMPTY 0x02 /* empty predicate */ +/** + * struct perf_sample + * + * A sample is generally filled in by evlist__parse_sample/evsel__parse_sample + * which fills in the variables from a "union perf_event *event" which is data + * from a perf ring buffer or perf.data file. The "event" sample is variable in + * length as determined by the perf_event_attr (in the evsel) and details within + * the sample event itself. A struct perf_sample avoids needing to care about + * the variable length nature of the original event. + * + * To avoid being excessively large parts of the struct perf_sample are pointers + * into the original sample event. In general the lifetime of a struct + * perf_sample needs to be less than the "union perf_event *event" it was + * derived from. + * + * The struct regs_dump user_regs and intr_regs are lazily allocated again for + * size reasons, due to them holding a cache of looked up registers. The + * function pair of perf_sample__init and perf_sample__exit correctly initialize + * and clean up these values. + */ struct perf_sample { + /** @ip: The sample event PERF_SAMPLE_IP value. */ u64 ip; - u32 pid, tid; + /** @pid: The sample event PERF_SAMPLE_TID pid value. */ + u32 pid; + /** @tid: The sample event PERF_SAMPLE_TID tid value. */ + u32 tid; + /** @time: The sample event PERF_SAMPLE_TIME value. */ u64 time; + /** @addr: The sample event PERF_SAMPLE_ADDR value. */ u64 addr; + /** @id: The sample event PERF_SAMPLE_ID value. */ u64 id; + /** @stream_id: The sample event PERF_SAMPLE_STREAM_ID value. */ u64 stream_id; + /** @period: The sample event PERF_SAMPLE_PERIOD value. */ u64 period; + /** @weight: Data determined by PERF_SAMPLE_WEIGHT or PERF_SAMPLE_WEIGHT_STRUCT. */ u64 weight; + /** @transaction: The sample event PERF_SAMPLE_TRANSACTION value. */ u64 transaction; + /** @insn_cnt: Filled in and used by intel-pt. */ u64 insn_cnt; + /** @cyc_cnt: Filled in and used by intel-pt. */ u64 cyc_cnt; + /** @cpu: The sample event PERF_SAMPLE_CPU value. */ u32 cpu; + /** + * @raw_size: The size in bytes of raw data from PERF_SAMPLE_RAW. For + * alignment reasons this should always be a multiple of + * sizeof(u64) + sizeof(u32). + */ u32 raw_size; + /** @data_src: The sample event PERF_SAMPLE_DATA_SRC value. */ u64 data_src; + /** @phys_addr: The sample event PERF_SAMPLE_PHYS_ADDR value. */ u64 phys_addr; + /** @data_page_size: The sample event PERF_SAMPLE_DATA_PAGE_SIZE value. */ u64 data_page_size; + /** @code_page_size: The sample event PERF_SAMPLE_CODE_PAGE_SIZE value. */ u64 code_page_size; + /** @cgroup: The sample event PERF_SAMPLE_CGROUP value. */ u64 cgroup; + /** @flags: Extra flag data from auxiliary events like intel-pt. */ u32 flags; + /** @machine_pid: The guest machine pid derived from the sample id. */ u32 machine_pid; + /** @vcpu: The guest machine vcpu derived from the sample id. */ u32 vcpu; + /** + * @insn_len: Instruction length from auxiliary events like + * intel-pt. The instruction itself is held in insn. + */ u16 insn_len; + /** + * @cpumode: The cpumode from struct perf_event_header misc variable + * masked with CPUMODE_MASK. Gives user, kernel and hypervisor + * information. + */ u8 cpumode; + /** @misc: The entire struct perf_event_header misc variable. */ u16 misc; + /** + * @ins_lat: Instruction latency information from weight2 in + * PERF_SAMPLE_WEIGHT_STRUCT or auxiliary events like + * intel-pt. + */ u16 ins_lat; - /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */ + /** + * @weight3: From PERF_SAMPLE_WEIGHT_STRUCT. On x86 holds retire_lat, on + * powerpc holds p_stage_cyc. + */ u16 weight3; - bool no_hw_idx; /* No hw_idx collected in branch_stack */ - bool deferred_callchain; /* Has deferred user callchains */ + /** + * @no_hw_idx: For PERF_SAMPLE_BRANCH_STACK, true when + * PERF_SAMPLE_BRANCH_HW_INDEX isn't set. + */ + bool no_hw_idx; + /** + * @deferred_callchain: When processing PERF_SAMPLE_CALLCHAIN a deferred + * user callchain marker was encountered. When set + * the callchain entry is allocated. + */ + bool deferred_callchain; + /** + * @deferred_cookie: Identifier of the deferred callchain in the later + * PERF_RECORD_CALLCHAIN_DEFERRED event. + */ u64 deferred_cookie; + /** @insn: A copy of the sampled instruction filled in by perf_sample__fetch_insn. */ char insn[MAX_INSN]; + /** @raw_data: Pointer into the original event for PERF_SAMPLE_RAW data. */ void *raw_data; + /** + * @callchain: Pointer into the original event for PERF_SAMPLE_CALLCHAIN + * data. If deferred_callchain is not set, it just points to + * data in the mmap buffer and it should not be freed. + */ struct ip_callchain *callchain; + /** @branch_stack: Pointer into the original event for PERF_SAMPLE_BRANCH_STACK data. */ struct branch_stack *branch_stack; + /** + * @branch_stack_cntr: Pointer into the original event for + * PERF_SAMPLE_BRANCH_COUNTERS data. + */ u64 *branch_stack_cntr; + /** @user_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_USER. */ struct regs_dump *user_regs; + /** @intr_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_INTR. */ struct regs_dump *intr_regs; + /** @user_stack: Size and pointer into the sample for PERF_SAMPLE_STACK_USER. */ struct stack_dump user_stack; + /** + * @read: The sample event PERF_SAMPLE_READ counter values. The valid + * values depend on the attr.read_format PERF_FORMAT_ values. + */ struct sample_read read; + /** + * @aux_sample: Similar to raw data but with a 64-bit size and + * alignment, PERF_SAMPLE_AUX data. + */ struct aux_sample aux_sample; + /** @simd_flags: SIMD flag information from ARM SPE auxiliary events. */ struct simd_flags simd_flags; }; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 02/25] perf sample: Make sure perf_sample__init/exit are used 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers 2026-03-19 23:23 ` [PATCH v2 01/25] perf sample: Document struct perf_sample Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 03/25] perf sample: Add evsel to struct perf_sample Ian Rogers ` (23 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The deferred stack trace code wasn't using perf_sample__init/exit. Add the deferred stack trace clean up to perf_sample__exit which requires proper NULL initialization in perf_sample__init. Make the perf_sample__exit robust to being called more than once by using zfree. Make the error paths in evsel__parse_sample exit the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 5 ++++- tools/perf/util/evlist.c | 5 ++++- tools/perf/util/evsel.c | 28 +++++++++++++++++----------- tools/perf/util/sample.c | 10 ++++++++-- tools/perf/util/session.c | 13 +++++++++---- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 5b29f4296861..039323908ebf 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1087,6 +1087,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, struct perf_sample sample_sw; struct perf_inject *inject = container_of(tool, struct perf_inject, tool); u32 pid = evsel__intval(evsel, sample, "pid"); + int ret; list_for_each_entry(ent, &inject->samples, node) { if (pid == ent->tid) @@ -1103,7 +1104,9 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, evsel->core.attr.read_format, &sample_sw); build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); - return perf_event__repipe(tool, event_sw, &sample_sw, machine); + ret = perf_event__repipe(tool, event_sw, &sample_sw, machine); + perf_sample__exit(&sample_sw); + return ret; } #endif diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 591bdf0b3e2a..bdb196425071 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1622,8 +1622,11 @@ int evlist__parse_sample(struct evlist *evlist, union perf_event *event, struct struct evsel *evsel = evlist__event2evsel(evlist, event); int ret; - if (!evsel) + if (!evsel) { + /* Ensure the sample is okay for perf_sample__exit. */ + perf_sample__init(sample, /*all=*/false); return -EFAULT; + } ret = evsel__parse_sample(evsel, event, sample); if (ret) return ret; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f59228c1a39e..34ae388750db 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3067,7 +3067,7 @@ static inline bool overflow(const void *endp, u16 max_size, const void *offset, #define OVERFLOW_CHECK(offset, size, max_size) \ do { \ if (overflow(endp, (max_size), (offset), (size))) \ - return -EFAULT; \ + goto out_efault; \ } while (0) #define OVERFLOW_CHECK_u64(offset) \ @@ -3199,6 +3199,8 @@ static int __set_offcpu_sample(struct perf_sample *data) data->cgroup = *array; return 0; +out_efault: + return -EFAULT; } int evsel__parse_sample(struct evsel *evsel, union perf_event *event, @@ -3217,7 +3219,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, */ union u64_swap u; - memset(data, 0, sizeof(*data)); + perf_sample__init(data, /*all=*/true); data->cpu = data->pid = data->tid = -1; data->stream_id = data->id = data->time = -1ULL; data->period = evsel->core.attr.sample_period; @@ -3231,25 +3233,26 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->callchain = (struct ip_callchain *)&event->callchain_deferred.nr; if (data->callchain->nr > max_callchain_nr) - return -EFAULT; + goto out_efault; data->deferred_cookie = event->callchain_deferred.cookie; if (evsel->core.attr.sample_id_all) perf_evsel__parse_id_sample(evsel, event, data); + return 0; } if (event->header.type != PERF_RECORD_SAMPLE) { - if (!evsel->core.attr.sample_id_all) - return 0; - return perf_evsel__parse_id_sample(evsel, event, data); + if (evsel->core.attr.sample_id_all) + perf_evsel__parse_id_sample(evsel, event, data); + return 0; } array = event->sample.array; if (perf_event__check_size(event, evsel->sample_size)) - return -EFAULT; + goto out_efault; if (type & PERF_SAMPLE_IDENTIFIER) { data->id = *array; @@ -3342,7 +3345,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, sizeof(struct sample_read_value); if (data->read.group.nr > max_group_nr) - return -EFAULT; + goto out_efault; sz = data->read.group.nr * sample_read_value_size(read_format); OVERFLOW_CHECK(array, sz, max_size); @@ -3370,7 +3373,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->callchain = (struct ip_callchain *)array++; callchain_nr = data->callchain->nr; if (callchain_nr > max_callchain_nr) - return -EFAULT; + goto out_efault; sz = callchain_nr * sizeof(u64); /* * Save the cookie for the deferred user callchain. The last 2 @@ -3428,7 +3431,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->branch_stack = (struct branch_stack *)array++; if (data->branch_stack->nr > max_branch_nr) - return -EFAULT; + goto out_efault; sz = data->branch_stack->nr * sizeof(struct branch_entry); if (evsel__has_branch_hw_idx(evsel)) { @@ -3505,7 +3508,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->user_stack.size = *array++; if (WARN_ONCE(data->user_stack.size > sz, "user stack dump failure\n")) - return -EFAULT; + goto out_efault; } } @@ -3586,6 +3589,9 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, return __set_offcpu_sample(data); return 0; +out_efault: + perf_sample__exit(data); + return -EFAULT; } int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event, diff --git a/tools/perf/util/sample.c b/tools/perf/util/sample.c index 8f82aaf1aab6..b04cbad7edd3 100644 --- a/tools/perf/util/sample.c +++ b/tools/perf/util/sample.c @@ -21,13 +21,19 @@ void perf_sample__init(struct perf_sample *sample, bool all) } else { sample->user_regs = NULL; sample->intr_regs = NULL; + sample->deferred_callchain = false; + sample->callchain = NULL; } } void perf_sample__exit(struct perf_sample *sample) { - free(sample->user_regs); - free(sample->intr_regs); + zfree(&sample->user_regs); + zfree(&sample->intr_regs); + if (sample->deferred_callchain) { + zfree(&sample->callchain); + sample->deferred_callchain = false; + } } struct regs_dump *perf_sample__user_regs(struct perf_sample *sample) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 4b465abfa36c..c48e840da7d4 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1367,14 +1367,18 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { struct perf_sample orig_sample; + perf_sample__init(&orig_sample, /*all=*/false); ret = evlist__parse_sample(evlist, de->event, &orig_sample); if (ret < 0) { pr_err("failed to parse original sample\n"); + perf_sample__exit(&orig_sample); break; } - if (sample->tid != orig_sample.tid) + if (sample->tid != orig_sample.tid) { + perf_sample__exit(&orig_sample); continue; + } if (event->callchain_deferred.cookie == orig_sample.deferred_cookie) sample__merge_deferred_callchain(&orig_sample, sample); @@ -1385,9 +1389,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, ret = evlist__deliver_sample(evlist, tool, de->event, &orig_sample, evsel, machine); - if (orig_sample.deferred_callchain) - free(orig_sample.callchain); - + perf_sample__exit(&orig_sample); list_del(&de->list); free(de->event); free(de); @@ -1414,9 +1416,11 @@ static int session__flush_deferred_samples(struct perf_session *session, list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { struct perf_sample sample; + perf_sample__init(&sample, /*all=*/false); ret = evlist__parse_sample(evlist, de->event, &sample); if (ret < 0) { pr_err("failed to parse original sample\n"); + perf_sample__exit(&sample); break; } @@ -1424,6 +1428,7 @@ static int session__flush_deferred_samples(struct perf_session *session, ret = evlist__deliver_sample(evlist, tool, de->event, &sample, evsel, machine); + perf_sample__exit(&sample); list_del(&de->list); free(de->event); free(de); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 03/25] perf sample: Add evsel to struct perf_sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers 2026-03-19 23:23 ` [PATCH v2 01/25] perf sample: Document struct perf_sample Ian Rogers 2026-03-19 23:23 ` [PATCH v2 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 04/25] perf tool: Remove evsel from tool APIs that pass the sample Ian Rogers ` (22 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Add the evsel from evsel__parse_sample into the struct perf_sample. Sometimes we want to alter the evsel associated with a sample, such as with off-cpu bpf-output events. In general the evsel and perf_sample are passed as a pair, but this makes an altered evsel something of a chore to keep checking for and setting up. Later patches will remove passing an evsel with the perf_sample and switch to just using the perf_sample's value. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 9 +++++--- tools/perf/builtin-script.c | 4 ++++ tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 1 + tools/perf/tests/hists_output.c | 2 +- tools/perf/util/evsel.c | 1 + tools/perf/util/sample.h | 3 +++ tools/perf/util/session.c | 35 +++++++++++++++++++------------ 8 files changed, 39 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 039323908ebf..5a04d7cff449 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -133,7 +133,7 @@ struct perf_inject { struct perf_file_section secs[HEADER_FEAT_BITS]; struct guest_session guest_session; struct strlist *known_build_ids; - const struct evsel *mmap_evsel; + struct evsel *mmap_evsel; struct ip_callchain *raw_callchain; }; @@ -519,7 +519,7 @@ static struct dso *findnew_dso(int pid, int tid, const char *filename, * processing mmap events. If not stashed, search the evlist for the first mmap * gathering event. */ -static const struct evsel *inject__mmap_evsel(struct perf_inject *inject) +static struct evsel *inject__mmap_evsel(struct perf_inject *inject) { struct evsel *pos; @@ -1007,6 +1007,7 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e .machine = machine, .mmap_evsel = inject__mmap_evsel(inject), }; + struct evsel *saved_evsel = sample->evsel; addr_location__init(&al); thread = machine__findnew_thread(machine, sample->pid, sample->tid); @@ -1021,9 +1022,10 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e /*sample_in_dso=*/true); } + sample->evsel = inject__mmap_evsel(inject); sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, &args); - + sample->evsel = saved_evsel; thread__put(thread); repipe: perf_event__repipe(tool, event, sample, machine); @@ -1432,6 +1434,7 @@ static int synthesize_build_id(struct perf_inject *inject, struct dso *dso, pid_ { struct machine *machine = perf_session__findnew_machine(inject->session, machine_pid); struct perf_sample synth_sample = { + .evsel = inject__mmap_evsel(inject), .pid = -1, .tid = -1, .time = -1, diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index b80c406d1fc1..8c3d06a3db62 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2909,8 +2909,12 @@ static int print_event_with_time(const struct perf_tool *tool, thread = machine__findnew_thread(machine, pid, tid); if (evsel) { + struct evsel *saved_evsel = sample->evsel; + + sample->evsel = evsel; perf_sample__fprintf_start(script, sample, thread, evsel, event->header.type, stdout); + sample->evsel = saved_evsel; } perf_event__fprintf(event, machine, stdout); diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c index 3eb9ef8d7ec6..606aa926a8fc 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -81,7 +81,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) { struct addr_location al; struct evsel *evsel = hists_to_evsel(hists); - struct perf_sample sample = { .period = 1000, }; + struct perf_sample sample = { .evsel = evsel, .period = 1000, }; size_t i; addr_location__init(&al); diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c index 1cebd20cc91c..cc6b26e373d1 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -70,6 +70,7 @@ static int add_hist_entries(struct evlist *evlist, }; struct hists *hists = evsel__hists(evsel); + sample.evsel = evsel; /* make sure it has no filter at first */ hists->thread_filter = NULL; hists->dso_filter = NULL; diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c index ee5ec8bda60e..7818950d786e 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -51,7 +51,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) { struct addr_location al; struct evsel *evsel = hists_to_evsel(hists); - struct perf_sample sample = { .period = 100, }; + struct perf_sample sample = { .evsel = evsel, .period = 100, }; size_t i; addr_location__init(&al); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 34ae388750db..a7da54d365a9 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3220,6 +3220,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, union u64_swap u; perf_sample__init(data, /*all=*/true); + data->evsel = evsel; data->cpu = data->pid = data->tid = -1; data->stream_id = data->id = data->time = -1ULL; data->period = evsel->core.attr.sample_period; diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 88ff154b630c..0cae9ffee39c 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -5,6 +5,7 @@ #include <linux/perf_event.h> #include <linux/types.h> +struct evsel; struct machine; struct thread; @@ -102,6 +103,8 @@ struct simd_flags { * and clean up these values. */ struct perf_sample { + /** @evsel: Backward reference to the evsel used when constructing the sample. */ + struct evsel *evsel; /** @ip: The sample event PERF_SAMPLE_IP value. */ u64 ip; /** @pid: The sample event PERF_SAMPLE_TID pid value. */ diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c48e840da7d4..3794d3a04afb 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1257,8 +1257,9 @@ static int deliver_sample_value(struct evlist *evlist, bool per_thread) { struct perf_sample_id *sid = evlist__id2sid(evlist, v->id); - struct evsel *evsel; + struct evsel *saved_evsel = sample->evsel; u64 *storage = NULL; + int ret; if (sid) { storage = perf_sample_id__get_period_storage(sid, sample->tid, per_thread); @@ -1282,8 +1283,10 @@ static int deliver_sample_value(struct evlist *evlist, if (!sample->period) return 0; - evsel = container_of(sid->evsel, struct evsel, core); - return tool->sample(tool, event, sample, evsel, machine); + sample->evsel = container_of(sid->evsel, struct evsel, core); + ret = tool->sample(tool, event, sample, sample->evsel, machine); + sample->evsel = saved_evsel; + return ret; } static int deliver_sample_group(struct evlist *evlist, @@ -1355,13 +1358,16 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, struct machine *machine) { struct deferred_event *de, *tmp; - struct evsel *evsel; int ret = 0; if (!tool->merge_deferred_callchains) { - evsel = evlist__id2evsel(evlist, sample->id); - return tool->callchain_deferred(tool, event, sample, - evsel, machine); + struct evsel *saved_evsel = sample->evsel; + + sample->evsel = evlist__id2evsel(evlist, sample->id); + ret = tool->callchain_deferred(tool, event, sample, + sample->evsel, machine); + sample->evsel = saved_evsel; + return ret; } list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { @@ -1385,9 +1391,9 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, else orig_sample.deferred_callchain = false; - evsel = evlist__id2evsel(evlist, orig_sample.id); + orig_sample.evsel = evlist__id2evsel(evlist, orig_sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &orig_sample, evsel, machine); + &orig_sample, orig_sample.evsel, machine); perf_sample__exit(&orig_sample); list_del(&de->list); @@ -1410,7 +1416,6 @@ static int session__flush_deferred_samples(struct perf_session *session, struct evlist *evlist = session->evlist; struct machine *machine = &session->machines.host; struct deferred_event *de, *tmp; - struct evsel *evsel; int ret = 0; list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { @@ -1424,9 +1429,9 @@ static int session__flush_deferred_samples(struct perf_session *session, break; } - evsel = evlist__id2evsel(evlist, sample.id); + sample.evsel = evlist__id2evsel(evlist, sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &sample, evsel, machine); + &sample, sample.evsel, machine); perf_sample__exit(&sample); list_del(&de->list); @@ -1451,8 +1456,12 @@ static int machines__deliver_event(struct machines *machines, dump_event(evlist, event, file_offset, sample, file_path); - evsel = evlist__id2evsel(evlist, sample->id); + if (!sample->evsel) + sample->evsel = evlist__id2evsel(evlist, sample->id); + else + assert(sample->evsel == evlist__id2evsel(evlist, sample->id)); + evsel = sample->evsel; machine = machines__find_for_cpumode(machines, event, sample); switch (event->header.type) { -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 04/25] perf tool: Remove evsel from tool APIs that pass the sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (2 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 03/25] perf sample: Add evsel to struct perf_sample Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 05/25] perf kvm: Don't pass evsel with sample Ian Rogers ` (21 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Now struct perf_sample has the evsel within it there is no need to pass the evsel along with the sample. In the called functions read the sample's evsel in to a variable if there are multiple uses, or use directly if there is just one use - the goal being to leave the code with as little change as possible. Some functions only use the evsel to pass to another function which they also pass the sample, in those cases just pass the sample and get the evsel in the called function. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 3 +-- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-inject.c | 19 ++++++--------- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 5 ++-- tools/perf/builtin-kwork.c | 2 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-mem.c | 1 - tools/perf/builtin-record.c | 3 +-- tools/perf/builtin-report.c | 10 +++----- tools/perf/builtin-sched.c | 4 +-- tools/perf/builtin-script.c | 4 +-- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/build-id.c | 3 +-- tools/perf/util/build-id.h | 7 +----- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data-convert-json.c | 5 ++-- tools/perf/util/intel-tpebs.c | 3 +-- tools/perf/util/jitdump.c | 2 +- tools/perf/util/session.c | 38 ++++++++++++++--------------- tools/perf/util/tool.c | 4 +-- tools/perf/util/tool.h | 4 +-- 24 files changed, 55 insertions(+), 76 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 686ad08561d6..c97a0fe159f8 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -284,7 +284,6 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool); @@ -303,7 +302,7 @@ static int process_sample_event(const struct perf_tool *tool, goto out_put; if (!al.filtered && - evsel__add_sample(evsel, sample, &al, ann, machine)) { + evsel__add_sample(sample->evsel, sample, &al, ann, machine)) { pr_warning("problem incrementing symbol count, " "skipping event\n"); ret = -1; diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index d390ae4e3ec8..89456ba6fcbb 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -314,9 +314,9 @@ static void perf_c2c__evsel_hists_inc_stats(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; struct c2c_hists *c2c_hists = &c2c.hists; struct c2c_hist_entry *c2c_he; struct c2c_stats stats = { .nr_entries = 0, }; diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 69069926dd0b..096adc65451c 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -390,11 +390,11 @@ struct hist_entry_ops block_hist_ops = { static int diff__process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_diff *pdiff = container_of(tool, struct perf_diff, tool); struct addr_location al; + struct evsel *evsel = sample->evsel; struct hists *hists = evsel__hists(evsel); struct hist_entry_iter iter = { .evsel = evsel, diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 5a04d7cff449..89f6fc826187 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -363,18 +363,17 @@ typedef int (*inject_handler)(const struct perf_tool *tool, static int perf_event__repipe_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { - struct perf_inject *inject = container_of(tool, struct perf_inject, - tool); + struct perf_inject *inject = container_of(tool, struct perf_inject, tool); + struct evsel *evsel = sample->evsel; if (evsel && evsel->handler) { inject_handler f = evsel->handler; return f(tool, event, sample, evsel, machine); } - build_id__mark_dso_hit(tool, event, sample, evsel, machine); + build_id__mark_dso_hit(tool, event, sample, machine); if (inject->itrace_synth_opts.set && sample->aux_sample.size) { event = perf_inject__cut_auxtrace_sample(inject, event, sample); @@ -388,10 +387,10 @@ static int perf_event__repipe_sample(const struct perf_tool *tool, static int perf_event__convert_sample_callchain(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); + struct evsel *evsel = sample->evsel; struct callchain_cursor *cursor = get_tls_callchain_cursor(); union perf_event *event_copy = (void *)inject->event_copy; struct callchain_cursor_node *node; @@ -988,10 +987,8 @@ static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data) args->mmap_evsel, map, /*sample_in_dso=*/false); } -int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, - struct perf_sample *sample, - struct evsel *evsel __maybe_unused, - struct machine *machine) +static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, + struct perf_sample *sample, struct machine *machine) { struct addr_location al; struct thread *thread; @@ -1023,7 +1020,7 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e } sample->evsel = inject__mmap_evsel(inject); - sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, &args); sample->evsel = saved_evsel; thread__put(thread); @@ -1105,7 +1102,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, sample_sw.time = sample->time; perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, evsel->core.attr.read_format, &sample_sw); - build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); + build_id__mark_dso_hit(tool, event_sw, &sample_sw, machine); ret = perf_event__repipe(tool, event_sw, &sample_sw, machine); perf_sample__exit(&sample_sw); return ret; diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 7929a5fa5f46..34852a4c3fc8 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -960,9 +960,9 @@ typedef int (*tracepoint_handler)(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; struct thread *thread = machine__findnew_thread(machine, sample->pid, sample->tid); diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 0c5e6b3aac74..5e8e6fde097a 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -941,9 +941,9 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, static bool handle_kvm_event(struct perf_kvm_stat *kvm, struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; struct vcpu_event_record *vcpu_record; struct event_key key = { .key = INVALID_KEY, .exit_reasons = kvm->exit_reasons }; @@ -1133,7 +1133,6 @@ static bool skip_sample(struct perf_kvm_stat *kvm, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { int err = 0; @@ -1156,7 +1155,7 @@ static int process_sample_event(const struct perf_tool *tool, return -1; } - if (!handle_kvm_event(kvm, thread, evsel, sample)) + if (!handle_kvm_event(kvm, thread, sample)) err = -1; thread__put(thread); diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 6f94a8f45f60..e34a1f35439e 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1955,9 +1955,9 @@ typedef int (*tracepoint_handler)(const struct perf_tool *tool, static int perf_kwork__process_tracepoint_sample(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; if (evsel->handler != NULL) { diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index e8962c985d34..dc8d1d3b4cd7 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1430,9 +1430,9 @@ typedef int (*tracepoint_handler)(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; struct thread *thread = machine__findnew_thread(machine, sample->pid, sample->tid); diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index d43500b92a7b..6101a26b3a78 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -255,7 +255,6 @@ dump_raw_samples(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine) { return dump_raw_samples(tool, event, sample, machine); diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 40917a0be238..09d6af344f3e 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1488,7 +1488,6 @@ static void set_timestamp_boundary(struct record *rec, u64 sample_time) static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct record *rec = container_of(tool, struct record, tool); @@ -1499,7 +1498,7 @@ static int process_sample_event(const struct perf_tool *tool, return 0; rec->samples++; - return build_id__mark_dso_hit(tool, event, sample, evsel, machine); + return build_id__mark_dso_hit(tool, event, sample, machine); } static int process_buildids(struct record *rec) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 343c0ada5ea1..507002cbdd5b 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -269,10 +269,10 @@ static int process_feature_event(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct report *rep = container_of(tool, struct report, tool); + struct evsel *evsel = sample->evsel; struct addr_location al; struct hist_entry_iter iter = { .evsel = evsel, @@ -349,7 +349,6 @@ static int process_sample_event(const struct perf_tool *tool, static int process_read_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct report *rep = container_of(tool, struct report, tool); @@ -357,7 +356,7 @@ static int process_read_event(const struct perf_tool *tool, if (rep->show_threads) { int err = perf_read_values_add_value(&rep->show_threads_values, event->read.pid, event->read.tid, - evsel, + sample->evsel, event->read.value); if (err) @@ -783,11 +782,10 @@ static void report__output_resort(struct report *rep) static int count_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, - struct perf_sample *sample __maybe_unused, - struct evsel *evsel, + struct perf_sample *sample, struct machine *machine __maybe_unused) { - struct hists *hists = evsel__hists(evsel); + struct hists *hists = evsel__hists(sample->evsel); hists__inc_nr_events(hists); return 0; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index d083e2bb7703..296b9837278a 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -1867,9 +1867,9 @@ typedef int (*tracepoint_handler)(const struct perf_tool *tool, static int perf_sched__process_tracepoint_sample(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; if (evsel->handler != NULL) { @@ -3184,10 +3184,10 @@ typedef int (*sched_handler)(const struct perf_tool *tool, static int perf_timehist__process_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); + struct evsel *evsel = sample->evsel; int err = 0; struct perf_cpu this_cpu = { .cpu = sample->cpu, diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8c3d06a3db62..8724c4ab3e88 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2644,10 +2644,10 @@ static bool filter_cpu(struct perf_sample *sample) static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_script *scr = container_of(tool, struct perf_script, tool); + struct evsel *evsel = sample->evsel; struct addr_location al; struct addr_location addr_al; int ret = 0; @@ -2728,10 +2728,10 @@ static int process_sample_event(const struct perf_tool *tool, static int process_deferred_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_script *scr = container_of(tool, struct perf_script, tool); + struct evsel *evsel = sample->evsel; struct perf_event_attr *attr = &evsel->core.attr; struct evsel_script *es = evsel->priv; unsigned int type = output_type(attr->type); diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 28f33e39895d..8692d11ccd29 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -574,10 +574,10 @@ typedef int (*tracepoint_handler)(struct timechart *tchart, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct timechart *tchart = container_of(tool, struct timechart, tool); + struct evsel *evsel = sample->evsel; if (evsel->core.attr.sample_type & PERF_SAMPLE_TIME) { if (!tchart->first_time || tchart->first_time > sample->time) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 1c38f3d16a31..e86a3d375757 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3462,10 +3462,10 @@ static void trace__set_base_time(struct trace *trace, static int trace__process_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct trace *trace = container_of(tool, struct trace, tool); + struct evsel *evsel = sample->evsel; struct thread *thread; int err = 0; diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index fdb35133fde4..55b72235f891 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -55,7 +55,6 @@ static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct addr_location al; @@ -74,7 +73,7 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, addr_location__exit(&al); - sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, /*data=*/NULL); diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index 47e621cebe1b..73bad90b06f9 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h @@ -34,12 +34,7 @@ char *__dso__build_id_filename(const struct dso *dso, char *bf, size_t size, bool is_debug, bool is_kallsyms); int build_id__mark_dso_hit(const struct perf_tool *tool, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, - struct machine *machine); - -int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, - struct machine *machine); + struct perf_sample *sample, struct machine *machine); bool perf_session__read_build_ids(struct perf_session *session, bool with_hits); int perf_session__write_buildid_table(struct perf_session *session, diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c index ba1c8e48d495..32e2173b86e3 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c @@ -803,10 +803,10 @@ static bool is_flush_needed(struct ctf_stream *cs) static int process_sample_event(const struct perf_tool *tool, union perf_event *_event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct convert *c = container_of(tool, struct convert, tool); + struct evsel *evsel = sample->evsel; struct evsel_priv *priv = evsel->priv; struct ctf_writer *cw = &c->writer; struct ctf_stream *cs; diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c index 6a626322476a..d1f931ee565a 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -159,13 +159,12 @@ static void output_sample_callchain_entry(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine) { struct convert_json *c = container_of(tool, struct convert_json, tool); FILE *out = c->out; struct addr_location al; - u64 sample_type = __evlist__combined_sample_type(evsel->evlist); + u64 sample_type = __evlist__combined_sample_type(sample->evsel->evlist); u8 cpumode = PERF_RECORD_MISC_USER; addr_location__init(&al); @@ -245,7 +244,7 @@ static int process_sample_event(const struct perf_tool *tool, #ifdef HAVE_LIBTRACEEVENT if (sample->raw_data) { - struct tep_event *tp_format = evsel__tp_format(evsel); + struct tep_event *tp_format = evsel__tp_format(sample->evsel); struct tep_format_field **fields = tp_format ? tep_event_fields(tp_format) : NULL; if (fields) { diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 2af5455488b2..01e030862d5d 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -185,7 +185,6 @@ static bool should_ignore_sample(const struct perf_sample *sample, const struct static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct tpebs_retire_lat *t; @@ -196,7 +195,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, mutex_unlock(tpebs_mtx_get()); return 0; } - t = tpebs_retire_lat__find(evsel); + t = tpebs_retire_lat__find(sample->evsel); if (!t) { mutex_unlock(tpebs_mtx_get()); return -EINVAL; diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c index e0ce8b904729..52e6ffac2b3e 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -642,7 +642,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr) ret = jit_inject_event(jd, event); if (!ret) - build_id__mark_dso_hit(tool, event, &sample, NULL, jd->machine); + build_id__mark_dso_hit(tool, event, &sample, jd->machine); out: perf_sample__exit(&sample); return ret; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 3794d3a04afb..150398b383fe 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1110,9 +1110,10 @@ char *get_page_size_name(u64 size, char *str) return str; } -static void dump_sample(struct machine *machine, struct evsel *evsel, union perf_event *event, +static void dump_sample(struct machine *machine, union perf_event *event, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; u64 sample_type; char str[PAGE_SIZE_NAME_LEN]; uint16_t e_machine = EM_NONE; @@ -1176,9 +1177,10 @@ static void dump_sample(struct machine *machine, struct evsel *evsel, union perf sample_read__printf(sample, evsel->core.attr.read_format); } -static void dump_deferred_callchain(struct evsel *evsel, union perf_event *event, - struct perf_sample *sample) +static void dump_deferred_callchain(union perf_event *event, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; + if (!dump_trace) return; @@ -1284,7 +1286,7 @@ static int deliver_sample_value(struct evlist *evlist, return 0; sample->evsel = container_of(sid->evsel, struct evsel, core); - ret = tool->sample(tool, event, sample, sample->evsel, machine); + ret = tool->sample(tool, event, sample, machine); sample->evsel = saved_evsel; return ret; } @@ -1316,8 +1318,9 @@ static int deliver_sample_group(struct evlist *evlist, static int evlist__deliver_sample(struct evlist *evlist, const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) + struct machine *machine) { + struct evsel *evsel = sample->evsel; /* We know evsel != NULL. */ u64 sample_type = evsel->core.attr.sample_type; u64 read_format = evsel->core.attr.read_format; @@ -1325,7 +1328,7 @@ static int evlist__deliver_sample(struct evlist *evlist, const struct perf_tool /* Standard sample delivery. */ if (!(sample_type & PERF_SAMPLE_READ)) - return tool->sample(tool, event, sample, evsel, machine); + return tool->sample(tool, event, sample, machine); /* For PERF_SAMPLE_READ we have either single or group mode. */ if (read_format & PERF_FORMAT_GROUP) @@ -1364,8 +1367,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, struct evsel *saved_evsel = sample->evsel; sample->evsel = evlist__id2evsel(evlist, sample->id); - ret = tool->callchain_deferred(tool, event, sample, - sample->evsel, machine); + ret = tool->callchain_deferred(tool, event, sample, machine); sample->evsel = saved_evsel; return ret; } @@ -1393,7 +1395,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, orig_sample.evsel = evlist__id2evsel(evlist, orig_sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &orig_sample, orig_sample.evsel, machine); + &orig_sample, machine); perf_sample__exit(&orig_sample); list_del(&de->list); @@ -1431,7 +1433,7 @@ static int session__flush_deferred_samples(struct perf_session *session, sample.evsel = evlist__id2evsel(evlist, sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &sample, sample.evsel, machine); + &sample, machine); perf_sample__exit(&sample); list_del(&de->list); @@ -1451,7 +1453,6 @@ static int machines__deliver_event(struct machines *machines, const struct perf_tool *tool, u64 file_offset, const char *file_path) { - struct evsel *evsel; struct machine *machine; dump_event(evlist, event, file_offset, sample, file_path); @@ -1461,21 +1462,20 @@ static int machines__deliver_event(struct machines *machines, else assert(sample->evsel == evlist__id2evsel(evlist, sample->id)); - evsel = sample->evsel; machine = machines__find_for_cpumode(machines, event, sample); switch (event->header.type) { case PERF_RECORD_SAMPLE: - if (evsel == NULL) { + if (sample->evsel == NULL) { ++evlist->stats.nr_unknown_id; return 0; } if (machine == NULL) { ++evlist->stats.nr_unprocessable_samples; - dump_sample(machine, evsel, event, sample); + dump_sample(machine, event, sample); return 0; } - dump_sample(machine, evsel, event, sample); + dump_sample(machine, event, sample); if (sample->deferred_callchain && tool->merge_deferred_callchains) { struct deferred_event *de = malloc(sizeof(*de)); size_t sz = event->header.size; @@ -1492,7 +1492,7 @@ static int machines__deliver_event(struct machines *machines, list_add_tail(&de->list, &evlist->deferred_samples); return 0; } - return evlist__deliver_sample(evlist, tool, event, sample, evsel, machine); + return evlist__deliver_sample(evlist, tool, event, sample, machine); case PERF_RECORD_MMAP: return tool->mmap(tool, event, sample, machine); case PERF_RECORD_MMAP2: @@ -1520,8 +1520,8 @@ static int machines__deliver_event(struct machines *machines, evlist->stats.total_lost_samples += event->lost_samples.lost; return tool->lost_samples(tool, event, sample, machine); case PERF_RECORD_READ: - dump_read(evsel, event); - return tool->read(tool, event, sample, evsel, machine); + dump_read(sample->evsel, event); + return tool->read(tool, event, sample, machine); case PERF_RECORD_THROTTLE: return tool->throttle(tool, event, sample, machine); case PERF_RECORD_UNTHROTTLE: @@ -1550,7 +1550,7 @@ static int machines__deliver_event(struct machines *machines, case PERF_RECORD_AUX_OUTPUT_HW_ID: return tool->aux_output_hw_id(tool, event, sample, machine); case PERF_RECORD_CALLCHAIN_DEFERRED: - dump_deferred_callchain(evsel, event, sample); + dump_deferred_callchain(event, sample); return evlist__deliver_deferred_callchain(evlist, tool, event, sample, machine); default: diff --git a/tools/perf/util/tool.c b/tools/perf/util/tool.c index 013c7839e2cf..0f285a2574c8 100644 --- a/tools/perf/util/tool.c +++ b/tools/perf/util/tool.c @@ -110,7 +110,6 @@ static int process_event_synth_event_update_stub(const struct perf_tool *tool __ int process_event_sample_stub(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct machine *machine __maybe_unused) { dump_printf(": unhandled!\n"); @@ -348,12 +347,11 @@ bool perf_tool__compressed_is_stub(const struct perf_tool *tool) static int delegate_ ## name(const struct perf_tool *tool, \ union perf_event *event, \ struct perf_sample *sample, \ - struct evsel *evsel, \ struct machine *machine) \ { \ struct delegate_tool *del_tool = container_of(tool, struct delegate_tool, tool); \ struct perf_tool *delegate = del_tool->delegate; \ - return delegate->name(delegate, event, sample, evsel, machine); \ + return delegate->name(delegate, event, sample, machine); \ } CREATE_DELEGATE_SAMPLE(read); CREATE_DELEGATE_SAMPLE(sample); diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h index 2d9a4b1ca9d0..2a4f124ffd8d 100644 --- a/tools/perf/util/tool.h +++ b/tools/perf/util/tool.h @@ -9,7 +9,6 @@ struct perf_session; union perf_event; struct evlist; -struct evsel; struct perf_sample; struct perf_tool; struct machine; @@ -17,7 +16,7 @@ struct ordered_events; typedef int (*event_sample)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); + struct machine *machine); typedef int (*event_op)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine); @@ -103,7 +102,6 @@ bool perf_tool__compressed_is_stub(const struct perf_tool *tool); int process_event_sample_stub(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); struct delegate_tool { -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 05/25] perf kvm: Don't pass evsel with sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (3 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 04/25] perf tool: Remove evsel from tool APIs that pass the sample Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval Ian Rogers ` (20 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan As the sample now contains the evsel, read the evsel from the sample rather than passing them as a pair. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-kvm.c | 19 +++-- .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 17 +++-- .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 ++--- .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 ++--- .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 18 +++-- tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +++--- tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 ++++++++----------- tools/perf/util/kvm-stat.c | 19 +++-- tools/perf/util/kvm-stat.h | 18 ++--- 9 files changed, 89 insertions(+), 126 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 5e8e6fde097a..d9b9792894a8 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -806,7 +806,6 @@ static bool update_kvm_event(struct perf_kvm_stat *kvm, } static bool is_child_event(struct perf_kvm_stat *kvm, - struct evsel *evsel, struct perf_sample *sample, struct event_key *key) { @@ -818,8 +817,8 @@ static bool is_child_event(struct perf_kvm_stat *kvm, return false; for (; child_ops->name; child_ops++) { - if (evsel__name_is(evsel, child_ops->name)) { - child_ops->get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, child_ops->name)) { + child_ops->get_key(sample, key); return true; } } @@ -917,11 +916,10 @@ static bool handle_end_event(struct perf_kvm_stat *kvm, static struct vcpu_event_record *per_vcpu_record(struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { /* Only kvm_entry records vcpu id. */ - if (!thread__priv(thread) && kvm_entry_event(evsel)) { + if (!thread__priv(thread) && kvm_entry_event(sample->evsel)) { struct vcpu_event_record *vcpu_record; struct machine *machine = maps__machine(thread__maps(thread)); uint16_t e_machine = thread__e_machine(thread, machine, /*e_flags=*/NULL); @@ -932,7 +930,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, return NULL; } - vcpu_record->vcpu_id = evsel__intval(evsel, sample, vcpu_id_str(e_machine)); + vcpu_record->vcpu_id = evsel__intval(sample->evsel, sample, vcpu_id_str(e_machine)); thread__set_priv(thread, vcpu_record); } @@ -943,12 +941,11 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, struct thread *thread, struct perf_sample *sample) { - struct evsel *evsel = sample->evsel; struct vcpu_event_record *vcpu_record; struct event_key key = { .key = INVALID_KEY, .exit_reasons = kvm->exit_reasons }; - vcpu_record = per_vcpu_record(thread, evsel, sample); + vcpu_record = per_vcpu_record(thread, sample); if (!vcpu_record) return true; @@ -957,13 +954,13 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, (kvm->trace_vcpu != vcpu_record->vcpu_id)) return true; - if (kvm->events_ops->is_begin_event(evsel, sample, &key)) + if (kvm->events_ops->is_begin_event(sample, &key)) return handle_begin_event(kvm, vcpu_record, &key, sample); - if (is_child_event(kvm, evsel, sample, &key)) + if (is_child_event(kvm, sample, &key)) return handle_child_event(kvm, vcpu_record, &key, sample); - if (kvm->events_ops->is_end_event(evsel, sample, &key)) + if (kvm->events_ops->is_end_event(sample, &key)) return handle_end_event(kvm, vcpu_record, &key, sample); return true; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c index c640dcd8af7c..1e76906f719c 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c @@ -17,10 +17,11 @@ static const char * const __kvm_events_tp[] = { NULL, }; -static void event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_get_key(struct perf_sample *sample, struct event_key *key) { + struct evsel *evsel = sample->evsel; + key->info = 0; key->key = evsel__intval(evsel, sample, kvm_exit_reason(EM_AARCH64)); key->exit_reasons = arm64_exit_reasons; @@ -36,19 +37,17 @@ static void event_get_key(struct evsel *evsel, } } -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_begin(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, kvm_entry_trace(EM_AARCH64)); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_AARCH64)); } -static bool event_end(struct evsel *evsel, - struct perf_sample *sample, +static bool event_end(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, kvm_exit_trace(EM_AARCH64))) { - event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, kvm_exit_trace(EM_AARCH64))) { + event_get_key(sample, key); return true; } return false; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c index b802e516b138..9d6265290f6d 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c @@ -53,14 +53,12 @@ static const char * const __kvm_events_tp[] = { NULL, }; -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool event_begin(struct perf_sample *sample, struct event_key *key) { - return exit_event_begin(evsel, sample, key); + return exit_event_begin(sample, key); } -static bool event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { /* @@ -71,17 +69,16 @@ static bool event_end(struct evsel *evsel, * kvm:kvm_enter means returning to vmm and then to guest * kvm:kvm_reenter means returning to guest immediately */ - return evsel__name_is(evsel, kvm_entry_trace(EM_LOONGARCH)) || - evsel__name_is(evsel, kvm_reenter_trace); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_LOONGARCH)) || + evsel__name_is(sample->evsel, kvm_reenter_trace); } -static void event_gspr_get_key(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static void event_gspr_get_key(struct perf_sample *sample, struct event_key *key) { unsigned int insn; key->key = LOONGARCH_EXCEPTION_OTHERS; - insn = evsel__intval(evsel, sample, "inst_word"); + insn = evsel__intval(sample->evsel, sample, "inst_word"); switch (insn >> 24) { case 0: diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c index 42182d70beb6..5158d7e88ee6 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c @@ -28,12 +28,11 @@ static const char * const ppc_book3s_hv_kvm_tp[] = { /* 1 extra placeholder for NULL */ static const char *__kvm_events_tp[NR_TPS + 1]; -static void hcall_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void hcall_event_get_key(struct perf_sample *sample, struct event_key *key) { key->info = 0; - key->key = evsel__intval(evsel, sample, "req"); + key->key = evsel__intval(sample->evsel, sample, "req"); } static const char *get_hcall_exit_reason(u64 exit_code) @@ -51,18 +50,16 @@ static const char *get_hcall_exit_reason(u64 exit_code) return "UNKNOWN"; } -static bool hcall_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool hcall_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, __kvm_events_tp[3]); + return evsel__name_is(sample->evsel, __kvm_events_tp[3]); } -static bool hcall_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool hcall_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, __kvm_events_tp[2])) { - hcall_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, __kvm_events_tp[2])) { + hcall_event_get_key(sample, key); return true; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c index 8d4d5d6ce720..e8db8b4f8e2e 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c @@ -20,30 +20,28 @@ static const char * const __kvm_events_tp[] = { NULL, }; -static void event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_get_key(struct perf_sample *sample, struct event_key *key) { int xlen = 64; // TODO: 32-bit support. key->info = 0; - key->key = evsel__intval(evsel, sample, kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); + key->key = evsel__intval(sample->evsel, sample, + kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); key->exit_reasons = riscv_exit_reasons; } -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_begin(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, kvm_entry_trace(EM_RISCV)); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_RISCV)); } -static bool event_end(struct evsel *evsel, - struct perf_sample *sample, +static bool event_end(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, kvm_exit_trace(EM_RISCV))) { - event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, kvm_exit_trace(EM_RISCV))) { + event_get_key(sample, key); return true; } return false; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c index 7e29169f5bb0..158372ba0205 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c @@ -18,38 +18,34 @@ define_exit_reasons_table(sie_sigp_order_codes, sigp_order_codes); define_exit_reasons_table(sie_diagnose_codes, diagnose_codes); define_exit_reasons_table(sie_icpt_prog_codes, icpt_prog_codes); -static void event_icpt_insn_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_icpt_insn_get_key(struct perf_sample *sample, struct event_key *key) { u64 insn; - insn = evsel__intval(evsel, sample, "instruction"); + insn = evsel__intval(sample->evsel, sample, "instruction"); key->key = icpt_insn_decoder(insn); key->exit_reasons = sie_icpt_insn_codes; } -static void event_sigp_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_sigp_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "order_code"); + key->key = evsel__intval(sample->evsel, sample, "order_code"); key->exit_reasons = sie_sigp_order_codes; } -static void event_diag_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_diag_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "code"); + key->key = evsel__intval(sample->evsel, sample, "code"); key->exit_reasons = sie_diagnose_codes; } -static void event_icpt_prog_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_icpt_prog_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "code"); + key->key = evsel__intval(sample->evsel, sample, "code"); key->exit_reasons = sie_icpt_prog_codes; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c index 0f626db3a439..0ce543d82850 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c @@ -24,45 +24,43 @@ static const struct kvm_events_ops exit_events = { * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...). */ -static void mmio_event_get_key(struct evsel *evsel, struct perf_sample *sample, +static void mmio_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "gpa"); - key->info = evsel__intval(evsel, sample, "type"); + key->key = evsel__intval(sample->evsel, sample, "gpa"); + key->info = evsel__intval(sample->evsel, sample, "type"); } #define KVM_TRACE_MMIO_READ_UNSATISFIED 0 #define KVM_TRACE_MMIO_READ 1 #define KVM_TRACE_MMIO_WRITE 2 -static bool mmio_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool mmio_event_begin(struct perf_sample *sample, struct event_key *key) { /* MMIO read begin event in kernel. */ - if (kvm_exit_event(evsel)) + if (kvm_exit_event(sample->evsel)) return true; /* MMIO write begin event in kernel. */ - if (evsel__name_is(evsel, "kvm:kvm_mmio") && - evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { - mmio_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && + evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { + mmio_event_get_key(sample, key); return true; } return false; } -static bool mmio_event_end(struct evsel *evsel, struct perf_sample *sample, - struct event_key *key) +static bool mmio_event_end(struct perf_sample *sample, struct event_key *key) { /* MMIO write end event in kernel. */ - if (kvm_entry_event(evsel)) + if (kvm_entry_event(sample->evsel)) return true; /* MMIO read end event in kernel.*/ - if (evsel__name_is(evsel, "kvm:kvm_mmio") && - evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) { - mmio_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && + evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_READ) { + mmio_event_get_key(sample, key); return true; } @@ -86,31 +84,27 @@ static const struct kvm_events_ops mmio_events = { }; /* The time of emulation pio access is from kvm_pio to kvm_entry. */ -static void ioport_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void ioport_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "port"); - key->info = evsel__intval(evsel, sample, "rw"); + key->key = evsel__intval(sample->evsel, sample, "port"); + key->info = evsel__intval(sample->evsel, sample, "rw"); } -static bool ioport_event_begin(struct evsel *evsel, - struct perf_sample *sample, +static bool ioport_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, "kvm:kvm_pio")) { - ioport_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_pio")) { + ioport_event_get_key(sample, key); return true; } return false; } -static bool ioport_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) +static bool ioport_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, @@ -130,31 +124,25 @@ static const struct kvm_events_ops ioport_events = { }; /* The time of emulation msr is from kvm_msr to kvm_entry. */ -static void msr_event_get_key(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) +static void msr_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "ecx"); - key->info = evsel__intval(evsel, sample, "write"); + key->key = evsel__intval(sample->evsel, sample, "ecx"); + key->info = evsel__intval(sample->evsel, sample, "write"); } -static bool msr_event_begin(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) +static bool msr_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, "kvm:kvm_msr")) { - msr_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_msr")) { + msr_event_get_key(sample, key); return true; } return false; } -static bool msr_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) +static bool msr_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } static void msr_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c index 27f16810498c..f17a6132958d 100644 --- a/tools/perf/util/kvm-stat.c +++ b/tools/perf/util/kvm-stat.c @@ -11,22 +11,20 @@ bool kvm_exit_event(struct evsel *evsel) return evsel__name_is(evsel, kvm_exit_trace(e_machine)); } -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +void exit_event_get_key(struct perf_sample *sample, struct event_key *key) { - uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL); + uint16_t e_machine = evsel__e_machine(sample->evsel, /*e_flags=*/NULL); key->info = 0; - key->key = evsel__intval(evsel, sample, kvm_exit_reason(e_machine)); + key->key = evsel__intval(sample->evsel, sample, kvm_exit_reason(e_machine)); } -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +bool exit_event_begin(struct perf_sample *sample, struct event_key *key) { - if (kvm_exit_event(evsel)) { - exit_event_get_key(evsel, sample, key); + if (kvm_exit_event(sample->evsel)) { + exit_event_get_key(sample, key); return true; } @@ -40,11 +38,10 @@ bool kvm_entry_event(struct evsel *evsel) return evsel__name_is(evsel, kvm_entry_trace(e_machine)); } -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +bool exit_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } static const char *get_exit_reason(struct perf_kvm_stat *kvm, diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 4a998aaece5d..cdbd921a555f 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -53,18 +53,15 @@ struct kvm_event { }; struct child_event_ops { - void (*get_key)(struct evsel *evsel, - struct perf_sample *sample, + void (*get_key)(struct perf_sample *sample, struct event_key *key); const char *name; }; struct kvm_events_ops { - bool (*is_begin_event)(struct evsel *evsel, - struct perf_sample *sample, + bool (*is_begin_event)(struct perf_sample *sample, struct event_key *key); - bool (*is_end_event)(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key); + bool (*is_end_event)(struct perf_sample *sample, struct event_key *key); const struct child_event_ops *child_ops; void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key, char *decode); @@ -116,14 +113,11 @@ struct kvm_reg_events_ops { #ifdef HAVE_LIBTRACEEVENT -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +void exit_event_get_key(struct perf_sample *sample, struct event_key *key); -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, +bool exit_event_begin(struct perf_sample *sample, struct event_key *key); -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample, +bool exit_event_end(struct perf_sample *sample, struct event_key *key); void exit_event_decode_key(struct perf_kvm_stat *kvm, struct event_key *key, -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (4 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 05/25] perf kvm: Don't pass evsel with sample Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 07/25] perf trace: Don't pass evsel with sample Ian Rogers ` (19 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The evsel argument to evsel__intval, and similar functions, is unnecessary as it can be read from the sample. Remove the evsel and rename the function to match that the data is coming from the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 33 +++---- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-kwork.c | 29 +++--- tools/perf/builtin-lock.c | 32 +++---- tools/perf/builtin-sched.c | 92 +++++++++---------- tools/perf/builtin-timechart.c | 88 +++++++++--------- tools/perf/builtin-trace.c | 12 +-- tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/tests/switch-tracking.c | 4 +- tools/perf/util/evsel.c | 22 ++--- tools/perf/util/evsel.h | 12 +-- tools/perf/util/intel-pt.c | 2 +- .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 6 +- .../util/kvm-stat-arch/kvm-stat-loongarch.c | 2 +- .../util/kvm-stat-arch/kvm-stat-powerpc.c | 2 +- .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 3 +- tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 8 +- tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 16 ++-- tools/perf/util/kvm-stat.c | 2 +- 20 files changed, 183 insertions(+), 188 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 89f6fc826187..483c8cac14fd 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1085,7 +1085,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, union perf_event *event_sw; struct perf_sample sample_sw; struct perf_inject *inject = container_of(tool, struct perf_inject, tool); - u32 pid = evsel__intval(evsel, sample, "pid"); + u32 pid = perf_sample__intval(sample, "pid"); int ret; list_for_each_entry(ent, &inject->samples, node) { diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 34852a4c3fc8..96b78a64c1c1 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -173,10 +173,10 @@ static int insert_caller_stat(unsigned long call_site, static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *sample) { - unsigned long ptr = evsel__intval(evsel, sample, "ptr"), - call_site = evsel__intval(evsel, sample, "call_site"); - int bytes_req = evsel__intval(evsel, sample, "bytes_req"), - bytes_alloc = evsel__intval(evsel, sample, "bytes_alloc"); + unsigned long ptr = perf_sample__intval(sample, "ptr"), + call_site = perf_sample__intval(sample, "call_site"); + int bytes_req = perf_sample__intval(sample, "bytes_req"), + bytes_alloc = perf_sample__intval(sample, "bytes_alloc"); if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) || insert_caller_stat(call_site, bytes_req, bytes_alloc)) @@ -202,7 +202,7 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s int node1, node2; node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}); - node2 = evsel__intval(evsel, sample, "node"); + node2 = perf_sample__intval(sample, "node"); /* * If the field "node" is NUMA_NO_NODE (-1), we don't take it @@ -243,9 +243,9 @@ static struct alloc_stat *search_alloc_stat(unsigned long ptr, return NULL; } -static int evsel__process_free_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_free_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - unsigned long ptr = evsel__intval(evsel, sample, "ptr"); + unsigned long ptr = perf_sample__intval(sample, "ptr"); struct alloc_stat *s_alloc, *s_caller; s_alloc = search_alloc_stat(ptr, 0, &root_alloc_stat, ptr_cmp); @@ -808,9 +808,9 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sample *sample) { u64 page; - unsigned int order = evsel__intval(evsel, sample, "order"); - unsigned int gfp_flags = evsel__intval(evsel, sample, "gfp_flags"); - unsigned int migrate_type = evsel__intval(evsel, sample, + unsigned int order = perf_sample__intval(sample, "order"); + unsigned int gfp_flags = perf_sample__intval(sample, "gfp_flags"); + unsigned int migrate_type = perf_sample__intval(sample, "migratetype"); u64 bytes = kmem_page_size << order; u64 callsite; @@ -822,9 +822,9 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp }; if (use_pfn) - page = evsel__intval(evsel, sample, "pfn"); + page = perf_sample__intval(sample, "pfn"); else - page = evsel__intval(evsel, sample, "page"); + page = perf_sample__intval(sample, "page"); nr_page_allocs++; total_page_alloc_bytes += bytes; @@ -877,10 +877,11 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp return 0; } -static int evsel__process_page_free_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_page_free_event(struct evsel *evsel __maybe_unused, + struct perf_sample *sample) { u64 page; - unsigned int order = evsel__intval(evsel, sample, "order"); + unsigned int order = perf_sample__intval(sample, "order"); u64 bytes = kmem_page_size << order; struct page_stat *pstat; struct page_stat this = { @@ -888,9 +889,9 @@ static int evsel__process_page_free_event(struct evsel *evsel, struct perf_sampl }; if (use_pfn) - page = evsel__intval(evsel, sample, "pfn"); + page = perf_sample__intval(sample, "pfn"); else - page = evsel__intval(evsel, sample, "page"); + page = perf_sample__intval(sample, "page"); nr_page_frees++; total_page_free_bytes += bytes; diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index d9b9792894a8..dd2ed21596aa 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -930,7 +930,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, return NULL; } - vcpu_record->vcpu_id = evsel__intval(sample->evsel, sample, vcpu_id_str(e_machine)); + vcpu_record->vcpu_id = perf_sample__intval(sample, vcpu_id_str(e_machine)); thread__set_priv(thread, vcpu_record); } diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index e34a1f35439e..111ae53025d1 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1006,7 +1006,7 @@ static void irq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1014,11 +1014,11 @@ static void irq_work_init(struct perf_kwork *kwork, work->cpu = sample->cpu; if (kwork->report == KWORK_REPORT_TOP) { - work->id = evsel__intval_common(evsel, sample, "common_pid"); + work->id = perf_sample__intval_common(sample, "common_pid"); work->name = NULL; } else { - work->id = evsel__intval(evsel, sample, "irq"); - work->name = evsel__strval(evsel, sample, "name"); + work->id = perf_sample__intval(sample, "irq"); + work->name = perf_sample__strval(sample, "name"); } } @@ -1144,10 +1144,10 @@ static void softirq_work_init(struct perf_kwork *kwork, work->cpu = sample->cpu; if (kwork->report == KWORK_REPORT_TOP) { - work->id = evsel__intval_common(evsel, sample, "common_pid"); + work->id = perf_sample__intval_common(sample, "common_pid"); work->name = NULL; } else { - num = evsel__intval(evsel, sample, "vec"); + num = perf_sample__intval(sample, "vec"); work->id = num; work->name = evsel__softirq_name(evsel, num); } @@ -1234,17 +1234,16 @@ static void workqueue_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { char *modp = NULL; - unsigned long long function_addr = evsel__intval(evsel, - sample, "function"); + unsigned long long function_addr = perf_sample__intval(sample, "function"); work->class = class; work->cpu = sample->cpu; - work->id = evsel__intval(evsel, sample, "work"); + work->id = perf_sample__intval(sample, "work"); work->name = function_addr == 0 ? NULL : machine__resolve_kernel_addr(machine, &function_addr, &modp); } @@ -1302,7 +1301,7 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1310,11 +1309,11 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused, work->cpu = sample->cpu; if (src_type == KWORK_TRACE_EXIT) { - work->id = evsel__intval(evsel, sample, "prev_pid"); - work->name = strdup(evsel__strval(evsel, sample, "prev_comm")); + work->id = perf_sample__intval(sample, "prev_pid"); + work->name = strdup(perf_sample__strval(sample, "prev_comm")); } else if (src_type == KWORK_TRACE_ENTRY) { - work->id = evsel__intval(evsel, sample, "next_pid"); - work->name = strdup(evsel__strval(evsel, sample, "next_comm")); + work->id = perf_sample__intval(sample, "next_pid"); + work->name = strdup(perf_sample__strval(sample, "next_comm")); } } diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index dc8d1d3b4cd7..baf0c99df5df 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -563,15 +563,15 @@ static int get_key_by_aggr_mode(u64 *key, u64 addr, struct evsel *evsel, return get_key_by_aggr_mode_simple(key, addr, sample->tid); } -static int report_lock_acquire_event(struct evsel *evsel, +static int report_lock_acquire_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); - int flag = evsel__intval(evsel, sample, "flags"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); + int flag = perf_sample__intval(sample, "flags"); u64 key; int ret; @@ -638,15 +638,15 @@ static int report_lock_acquire_event(struct evsel *evsel, return 0; } -static int report_lock_acquired_event(struct evsel *evsel, +static int report_lock_acquired_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; u64 contended_term; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; @@ -704,14 +704,14 @@ static int report_lock_acquired_event(struct evsel *evsel, return 0; } -static int report_lock_contended_event(struct evsel *evsel, +static int report_lock_contended_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; @@ -762,14 +762,14 @@ static int report_lock_contended_event(struct evsel *evsel, return 0; } -static int report_lock_release_event(struct evsel *evsel, +static int report_lock_release_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; @@ -969,8 +969,8 @@ static int report_lock_contention_begin_event(struct evsel *evsel, struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - u64 addr = evsel__intval(evsel, sample, "lock_addr"); - unsigned int flags = evsel__intval(evsel, sample, "flags"); + u64 addr = perf_sample__intval(sample, "lock_addr"); + unsigned int flags = perf_sample__intval(sample, "flags"); u64 key; int i, ret; static bool kmap_loaded; @@ -1134,7 +1134,7 @@ static int report_lock_contention_end_event(struct evsel *evsel, struct thread_stat *ts; struct lock_seq_stat *seq; u64 contended_term; - u64 addr = evsel__intval(evsel, sample, "lock_addr"); + u64 addr = perf_sample__intval(sample, "lock_addr"); u64 key; int ret; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 296b9837278a..c7a7e0208a16 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -829,8 +829,8 @@ replay_wakeup_event(struct perf_sched *sched, struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { - const char *comm = evsel__strval(evsel, sample, "comm"); - const u32 pid = evsel__intval(evsel, sample, "pid"); + const char *comm = perf_sample__strval(sample, "comm"); + const u32 pid = perf_sample__intval(sample, "pid"); struct task_desc *waker, *wakee; if (verbose > 0) { @@ -851,10 +851,10 @@ static int replay_switch_event(struct perf_sched *sched, struct perf_sample *sample, struct machine *machine __maybe_unused) { - const char *prev_comm = evsel__strval(evsel, sample, "prev_comm"), - *next_comm = evsel__strval(evsel, sample, "next_comm"); - const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), - next_pid = evsel__intval(evsel, sample, "next_pid"); + const char *prev_comm = perf_sample__strval(sample, "prev_comm"), + *next_comm = perf_sample__strval(sample, "next_comm"); + const u32 prev_pid = perf_sample__intval(sample, "prev_pid"), + next_pid = perf_sample__intval(sample, "next_pid"); struct task_desc *prev, __maybe_unused *next; u64 timestamp0, timestamp = sample->time; int cpu = sample->cpu; @@ -1134,13 +1134,13 @@ static void free_work_atoms(struct work_atoms *atoms) } static int latency_switch_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), - next_pid = evsel__intval(evsel, sample, "next_pid"); - const char prev_state = evsel__taskstate(evsel, sample, "prev_state"); + const u32 prev_pid = perf_sample__intval(sample, "prev_pid"), + next_pid = perf_sample__intval(sample, "next_pid"); + const char prev_state = perf_sample__taskstate(sample, "prev_state"); struct work_atoms *out_events, *in_events; struct thread *sched_out, *sched_in; u64 timestamp0, timestamp = sample->time; @@ -1204,12 +1204,12 @@ static int latency_switch_event(struct perf_sched *sched, } static int latency_runtime_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid = evsel__intval(evsel, sample, "pid"); - const u64 runtime = evsel__intval(evsel, sample, "runtime"); + const u32 pid = perf_sample__intval(sample, "pid"); + const u64 runtime = perf_sample__intval(sample, "runtime"); struct thread *thread = machine__findnew_thread(machine, -1, pid); struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); u64 timestamp = sample->time; @@ -1239,11 +1239,11 @@ static int latency_runtime_event(struct perf_sched *sched, } static int latency_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); struct work_atoms *atoms; struct work_atom *atom; struct thread *wakee; @@ -1300,11 +1300,11 @@ static int latency_wakeup_event(struct perf_sched *sched, } static int latency_migrate_task_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); u64 timestamp = sample->time; struct work_atoms *atoms; struct work_atom *atom; @@ -1626,11 +1626,11 @@ static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu, } } -static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, +static int map_switch_event(struct perf_sched *sched, struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); - const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"); + const u32 next_pid = perf_sample__intval(sample, "next_pid"); + const u32 prev_pid = perf_sample__intval(sample, "prev_pid"); struct thread *sched_in, *sched_out; struct thread_runtime *tr; int new_shortname; @@ -1797,8 +1797,8 @@ static int process_sched_switch_event(const struct perf_tool *tool, { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); int this_cpu = sample->cpu, err = 0; - u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), - next_pid = evsel__intval(evsel, sample, "next_pid"); + u32 prev_pid = perf_sample__intval(sample, "prev_pid"), + next_pid = perf_sample__intval(sample, "next_pid"); if (sched->curr_pid[this_cpu] != (u32)-1) { /* @@ -2068,12 +2068,11 @@ static char *timehist_get_commstr(struct thread *thread) /* prio field format: xxx or xxx->yyy */ #define MAX_PRIO_STR_LEN 8 -static char *timehist_get_priostr(struct evsel *evsel, - struct thread *thread, +static char *timehist_get_priostr(struct thread *thread, struct perf_sample *sample) { static char prio_str[16]; - int prev_prio = (int)evsel__intval(evsel, sample, "prev_prio"); + int prev_prio = (int)perf_sample__intval(sample, "prev_prio"); struct thread_runtime *tr = thread__priv(thread); if (tr->prio != prev_prio && tr->prio != -1) @@ -2161,15 +2160,14 @@ static void timehist_header(struct perf_sched *sched) } static void timehist_print_sample(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct addr_location *al, struct thread *thread, u64 t, const char state) { struct thread_runtime *tr = thread__priv(thread); - const char *next_comm = evsel__strval(evsel, sample, "next_comm"); - const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); + const char *next_comm = perf_sample__strval(sample, "next_comm"); + const u32 next_pid = perf_sample__intval(sample, "next_pid"); u32 max_cpus = sched->max_cpu.cpu + 1; char tstr[64]; char nstr[30]; @@ -2198,14 +2196,15 @@ static void timehist_print_sample(struct perf_sched *sched, } if (!thread__comm_set(thread)) { - const char *prev_comm = evsel__strval(evsel, sample, "prev_comm"); - thread__set_comm(thread, prev_comm, sample->time); + const char *prev_comm = perf_sample__strval(sample, "prev_comm"); + + thread__set_comm(thread, prev_comm, sample->time); } printf(" %-*s ", comm_width, timehist_get_commstr(thread)); if (sched->show_prio) - printf(" %-*s ", MAX_PRIO_STR_LEN, timehist_get_priostr(evsel, thread, sample)); + printf(" %-*s ", MAX_PRIO_STR_LEN, timehist_get_priostr(thread, sample)); wait_time = tr->dt_sleep + tr->dt_iowait + tr->dt_preempt; print_sched_time(wait_time, 6); @@ -2319,7 +2318,7 @@ static bool is_idle_sample(struct perf_sample *sample, { /* pid 0 == swapper == idle task */ if (evsel__name_is(evsel, "sched:sched_switch")) - return evsel__intval(evsel, sample, "prev_pid") == 0; + return perf_sample__intval(sample, "prev_pid") == 0; return sample->pid == 0; } @@ -2539,7 +2538,7 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, itr->last_thread = thread__get(thread); /* copy task callchain when entering to idle */ - if (evsel__intval(evsel, sample, "next_pid") == 0) + if (perf_sample__intval(sample, "next_pid") == 0) save_idle_callchain(sched, itr, sample); } } @@ -2572,7 +2571,7 @@ static bool timehist_skip_sample(struct perf_sched *sched, if (tr && tr->prio != -1) prio = tr->prio; else if (evsel__name_is(evsel, "sched:sched_switch")) - prio = evsel__intval(evsel, sample, "prev_prio"); + prio = perf_sample__intval(sample, "prev_prio"); if (prio != -1 && !test_bit(prio, sched->prio_bitmap)) { rc = true; @@ -2583,8 +2582,8 @@ static bool timehist_skip_sample(struct perf_sched *sched, if (sched->idle_hist) { if (!evsel__name_is(evsel, "sched:sched_switch")) rc = true; - else if (evsel__intval(evsel, sample, "prev_pid") != 0 && - evsel__intval(evsel, sample, "next_pid") != 0) + else if (perf_sample__intval(sample, "prev_pid") != 0 && + perf_sample__intval(sample, "next_pid") != 0) rc = true; } @@ -2647,7 +2646,7 @@ static int timehist_sched_wakeup_event(const struct perf_tool *tool, struct thread *thread; struct thread_runtime *tr = NULL; /* want pid of awakened task not pid in sample */ - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); thread = machine__findnew_thread(machine, 0, pid); if (thread == NULL) @@ -2686,8 +2685,8 @@ static void timehist_print_migration_event(struct perf_sched *sched, return; max_cpus = sched->max_cpu.cpu + 1; - ocpu = evsel__intval(evsel, sample, "orig_cpu"); - dcpu = evsel__intval(evsel, sample, "dest_cpu"); + ocpu = perf_sample__intval(sample, "orig_cpu"); + dcpu = perf_sample__intval(sample, "dest_cpu"); thread = machine__findnew_thread(machine, sample->pid, sample->tid); if (thread == NULL) @@ -2736,7 +2735,7 @@ static int timehist_migrate_task_event(const struct perf_tool *tool, struct thread *thread; struct thread_runtime *tr = NULL; /* want pid of migrated task not pid in sample */ - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); thread = machine__findnew_thread(machine, 0, pid); if (thread == NULL) @@ -2761,14 +2760,13 @@ static int timehist_migrate_task_event(const struct perf_tool *tool, return 0; } -static void timehist_update_task_prio(struct evsel *evsel, - struct perf_sample *sample, +static void timehist_update_task_prio(struct perf_sample *sample, struct machine *machine) { struct thread *thread; struct thread_runtime *tr = NULL; - const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); - const u32 next_prio = evsel__intval(evsel, sample, "next_prio"); + const u32 next_pid = perf_sample__intval(sample, "next_pid"); + const u32 next_prio = perf_sample__intval(sample, "next_prio"); if (next_pid == 0) thread = get_idle_thread(sample->cpu); @@ -2798,7 +2796,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, struct thread_runtime *tr = NULL; u64 tprev, t = sample->time; int rc = 0; - const char state = evsel__taskstate(evsel, sample, "prev_state"); + const char state = perf_sample__taskstate(sample, "prev_state"); addr_location__init(&al); if (machine__resolve(machine, &al, sample) < 0) { @@ -2809,7 +2807,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, } if (sched->show_prio || sched->prio_str) - timehist_update_task_prio(evsel, sample, machine); + timehist_update_task_prio(sample, machine); thread = timehist_get_thread(sched, sample, machine, evsel); if (thread == NULL) { @@ -2891,7 +2889,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, } if (!sched->summary_only) - timehist_print_sample(sched, evsel, sample, &al, thread, t, state); + timehist_print_sample(sched, sample, &al, thread, t, state); } out: diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 8692d11ccd29..034e0ba3f9cb 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -597,12 +597,12 @@ static int process_sample_event(const struct perf_tool *tool, static int process_sample_cpu_idle(struct timechart *tchart __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u32 state = evsel__intval(evsel, sample, "state"); - u32 cpu_id = evsel__intval(evsel, sample, "cpu_id"); + u32 state = perf_sample__intval(sample, "state"); + u32 cpu_id = perf_sample__intval(sample, "cpu_id"); if (state == (u32)PWR_EVENT_EXIT) c_state_end(tchart, cpu_id, sample->time); @@ -613,12 +613,12 @@ process_sample_cpu_idle(struct timechart *tchart __maybe_unused, static int process_sample_cpu_frequency(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u32 state = evsel__intval(evsel, sample, "state"); - u32 cpu_id = evsel__intval(evsel, sample, "cpu_id"); + u32 state = perf_sample__intval(sample, "state"); + u32 cpu_id = perf_sample__intval(sample, "cpu_id"); p_state_change(tchart, cpu_id, sample->time, state); return 0; @@ -626,13 +626,13 @@ process_sample_cpu_frequency(struct timechart *tchart, static int process_sample_sched_wakeup(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { - u8 flags = evsel__intval(evsel, sample, "common_flags"); - int waker = evsel__intval(evsel, sample, "common_pid"); - int wakee = evsel__intval(evsel, sample, "pid"); + u8 flags = perf_sample__intval(sample, "common_flags"); + int waker = perf_sample__intval(sample, "common_pid"); + int wakee = perf_sample__intval(sample, "pid"); sched_wakeup(tchart, sample->cpu, sample->time, waker, wakee, flags, backtrace); return 0; @@ -640,13 +640,13 @@ process_sample_sched_wakeup(struct timechart *tchart, static int process_sample_sched_switch(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { - int prev_pid = evsel__intval(evsel, sample, "prev_pid"); - int next_pid = evsel__intval(evsel, sample, "next_pid"); - u64 prev_state = evsel__intval(evsel, sample, "prev_state"); + int prev_pid = perf_sample__intval(sample, "prev_pid"); + int next_pid = perf_sample__intval(sample, "next_pid"); + u64 prev_state = perf_sample__intval(sample, "prev_state"); sched_switch(tchart, sample->cpu, sample->time, prev_pid, next_pid, prev_state, backtrace); @@ -656,12 +656,12 @@ process_sample_sched_switch(struct timechart *tchart, #ifdef SUPPORT_OLD_POWER_EVENTS static int process_sample_power_start(struct timechart *tchart __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u64 cpu_id = evsel__intval(evsel, sample, "cpu_id"); - u64 value = evsel__intval(evsel, sample, "value"); + u64 cpu_id = perf_sample__intval(sample, "cpu_id"); + u64 value = perf_sample__intval(sample, "value"); c_state_start(cpu_id, sample->time, value); return 0; @@ -679,12 +679,12 @@ process_sample_power_end(struct timechart *tchart, static int process_sample_power_frequency(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u64 cpu_id = evsel__intval(evsel, sample, "cpu_id"); - u64 value = evsel__intval(evsel, sample, "value"); + u64 cpu_id = perf_sample__intval(sample, "cpu_id"); + u64 value = perf_sample__intval(sample, "value"); p_state_change(tchart, cpu_id, sample->time, value); return 0; @@ -849,120 +849,120 @@ static int pid_end_io_sample(struct timechart *tchart, int pid, int type, static int process_enter_read(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ, sample->time, fd); } static int process_exit_read(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_READ, sample->time, ret); } static int process_enter_write(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE, sample->time, fd); } static int process_exit_write(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_WRITE, sample->time, ret); } static int process_enter_sync(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC, sample->time, fd); } static int process_exit_sync(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_SYNC, sample->time, ret); } static int process_enter_tx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX, sample->time, fd); } static int process_exit_tx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_TX, sample->time, ret); } static int process_enter_rx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX, sample->time, fd); } static int process_exit_rx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_RX, sample->time, ret); } static int process_enter_poll(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL, sample->time, fd); } static int process_exit_poll(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_POLL, sample->time, ret); } diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index e86a3d375757..493eecf218b4 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3059,7 +3059,7 @@ errno_print: { return err; } -static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, +static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3068,7 +3068,7 @@ static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, size_t filename_len, entry_str_len, to_move; ssize_t remaining_space; char *pos; - const char *filename = evsel__rawptr(evsel, sample, "pathname"); + const char *filename = perf_sample__rawptr(sample, "pathname"); if (!thread) goto out; @@ -3124,7 +3124,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, union perf_event *event __maybe_unused, struct perf_sample *sample) { - u64 runtime = evsel__intval(evsel, sample, "runtime"); + u64 runtime = perf_sample__intval(sample, "runtime"); double runtime_ms = (double)runtime / NSEC_PER_MSEC; struct thread *thread = machine__findnew_thread(trace->host, sample->pid, @@ -3143,10 +3143,10 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, out_dump: fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", evsel->name, - evsel__strval(evsel, sample, "comm"), - (pid_t)evsel__intval(evsel, sample, "pid"), + perf_sample__strval(sample, "comm"), + (pid_t)perf_sample__intval(sample, "pid"), runtime, - evsel__intval(evsel, sample, "vruntime")); + perf_sample__intval(sample, "vruntime")); goto out_put; } diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c index 2a139d2781a8..97550b349418 100644 --- a/tools/perf/tests/openat-syscall-tp-fields.c +++ b/tools/perf/tests/openat-syscall-tp-fields.c @@ -118,7 +118,7 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused goto out_delete_evlist; } - tp_flags = evsel__intval(evsel, &sample, "flags"); + tp_flags = perf_sample__intval(&sample, "flags"); perf_sample__exit(&sample); if (flags != tp_flags) { pr_debug("%s: Expected flags=%#x, got %#x\n", diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index 15791fcb76b2..a7ea4b7874be 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -140,8 +140,8 @@ static int process_sample_event(struct evlist *evlist, evsel = evlist__id2evsel(evlist, sample.id); if (evsel == switch_tracking->switch_evsel) { - next_tid = evsel__intval(evsel, &sample, "next_pid"); - prev_tid = evsel__intval(evsel, &sample, "prev_pid"); + next_tid = perf_sample__intval(&sample, "next_pid"); + prev_tid = perf_sample__intval(&sample, "prev_pid"); cpu = sample.cpu; pr_debug3("sched_switch: cpu: %d prev_tid %d next_tid %d\n", cpu, prev_tid, next_tid); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index a7da54d365a9..041766d39ec3 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3679,9 +3679,9 @@ struct tep_format_field *evsel__common_field(struct evsel *evsel, const char *na return tp_format ? tep_find_common_field(tp_format, name) : NULL; } -void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name) +void *perf_sample__rawptr(struct perf_sample *sample, const char *name) { - struct tep_format_field *field = evsel__field(evsel, name); + struct tep_format_field *field = evsel__field(sample->evsel, name); int offset; if (!field) @@ -3738,21 +3738,21 @@ u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sam return 0; } -u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name) +u64 perf_sample__intval(struct perf_sample *sample, const char *name) { - struct tep_format_field *field = evsel__field(evsel, name); + struct tep_format_field *field = evsel__field(sample->evsel, name); - return field ? format_field__intval(field, sample, evsel->needs_swap) : 0; + return field ? format_field__intval(field, sample, sample->evsel->needs_swap) : 0; } -u64 evsel__intval_common(struct evsel *evsel, struct perf_sample *sample, const char *name) +u64 perf_sample__intval_common(struct perf_sample *sample, const char *name) { - struct tep_format_field *field = evsel__common_field(evsel, name); + struct tep_format_field *field = evsel__common_field(sample->evsel, name); - return field ? format_field__intval(field, sample, evsel->needs_swap) : 0; + return field ? format_field__intval(field, sample, sample->evsel->needs_swap) : 0; } -char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const char *name) +char perf_sample__taskstate(struct perf_sample *sample, const char *name) { static struct tep_format_field *prev_state_field; static const char *states; @@ -3761,7 +3761,7 @@ char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const cha unsigned int bit; char state = '?'; /* '?' denotes unknown task state */ - field = evsel__field(evsel, name); + field = evsel__field(sample->evsel, name); if (!field) return state; @@ -3780,7 +3780,7 @@ char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const cha * * We can change this if we have a good reason in the future. */ - val = evsel__intval(evsel, sample, name); + val = perf_sample__intval(sample, name); bit = val ? ffs(val) : 0; state = (!bit || bit > strlen(states)) ? 'R' : states[bit-1]; return state; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index a3d754c029a0..c9d3e6de9677 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -369,14 +369,14 @@ bool evsel__precise_ip_fallback(struct evsel *evsel); struct perf_sample; #ifdef HAVE_LIBTRACEEVENT -void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name); -u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name); -u64 evsel__intval_common(struct evsel *evsel, struct perf_sample *sample, const char *name); -char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const char *name); +void *perf_sample__rawptr(struct perf_sample *sample, const char *name); +u64 perf_sample__intval(struct perf_sample *sample, const char *name); +u64 perf_sample__intval_common(struct perf_sample *sample, const char *name); +char perf_sample__taskstate(struct perf_sample *sample, const char *name); -static inline char *evsel__strval(struct evsel *evsel, struct perf_sample *sample, const char *name) +static inline char *perf_sample__strval(struct perf_sample *sample, const char *name) { - return evsel__rawptr(evsel, sample, name); + return perf_sample__rawptr(sample, name); } #endif diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index fc9eec8b54b8..dab23a96b1d8 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -3426,7 +3426,7 @@ static int intel_pt_process_switch(struct intel_pt *pt, if (evsel != pt->switch_evsel) return 0; - tid = evsel__intval(evsel, sample, "next_pid"); + tid = perf_sample__intval(sample, "next_pid"); cpu = sample->cpu; intel_pt_log("sched_switch: cpu %d tid %d time %"PRIu64" tsc %#"PRIx64"\n", diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c index 1e76906f719c..018b0db0e6e7 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c @@ -20,10 +20,8 @@ static const char * const __kvm_events_tp[] = { static void event_get_key(struct perf_sample *sample, struct event_key *key) { - struct evsel *evsel = sample->evsel; - key->info = 0; - key->key = evsel__intval(evsel, sample, kvm_exit_reason(EM_AARCH64)); + key->key = perf_sample__intval(sample, kvm_exit_reason(EM_AARCH64)); key->exit_reasons = arm64_exit_reasons; /* @@ -32,7 +30,7 @@ static void event_get_key(struct perf_sample *sample, * properly decode event's est_ec. */ if (key->key == ARM_EXCEPTION_TRAP) { - key->key = evsel__intval(evsel, sample, kvm_trap_exit_reason); + key->key = perf_sample__intval(sample, kvm_trap_exit_reason); key->exit_reasons = arm64_trap_exit_reasons; } } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c index 9d6265290f6d..a04cd09e3361 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c @@ -78,7 +78,7 @@ static void event_gspr_get_key(struct perf_sample *sample, struct event_key *key unsigned int insn; key->key = LOONGARCH_EXCEPTION_OTHERS; - insn = evsel__intval(sample->evsel, sample, "inst_word"); + insn = perf_sample__intval(sample, "inst_word"); switch (insn >> 24) { case 0: diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c index 5158d7e88ee6..96d9c4ae0209 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c @@ -32,7 +32,7 @@ static void hcall_event_get_key(struct perf_sample *sample, struct event_key *key) { key->info = 0; - key->key = evsel__intval(sample->evsel, sample, "req"); + key->key = perf_sample__intval(sample, "req"); } static const char *get_hcall_exit_reason(u64 exit_code) diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c index e8db8b4f8e2e..967bba261a47 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c @@ -26,8 +26,7 @@ static void event_get_key(struct perf_sample *sample, int xlen = 64; // TODO: 32-bit support. key->info = 0; - key->key = evsel__intval(sample->evsel, sample, - kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); + key->key = perf_sample__intval(sample, kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); key->exit_reasons = riscv_exit_reasons; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c index 158372ba0205..4771fc69fa39 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c @@ -23,7 +23,7 @@ static void event_icpt_insn_get_key(struct perf_sample *sample, { u64 insn; - insn = evsel__intval(sample->evsel, sample, "instruction"); + insn = perf_sample__intval(sample, "instruction"); key->key = icpt_insn_decoder(insn); key->exit_reasons = sie_icpt_insn_codes; } @@ -31,21 +31,21 @@ static void event_icpt_insn_get_key(struct perf_sample *sample, static void event_sigp_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "order_code"); + key->key = perf_sample__intval(sample, "order_code"); key->exit_reasons = sie_sigp_order_codes; } static void event_diag_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "code"); + key->key = perf_sample__intval(sample, "code"); key->exit_reasons = sie_diagnose_codes; } static void event_icpt_prog_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "code"); + key->key = perf_sample__intval(sample, "code"); key->exit_reasons = sie_icpt_prog_codes; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c index 0ce543d82850..788d216f0852 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c @@ -27,8 +27,8 @@ static const struct kvm_events_ops exit_events = { static void mmio_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "gpa"); - key->info = evsel__intval(sample->evsel, sample, "type"); + key->key = perf_sample__intval(sample, "gpa"); + key->info = perf_sample__intval(sample, "type"); } #define KVM_TRACE_MMIO_READ_UNSATISFIED 0 @@ -43,7 +43,7 @@ static bool mmio_event_begin(struct perf_sample *sample, struct event_key *key) /* MMIO write begin event in kernel. */ if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && - evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { + perf_sample__intval(sample, "type") == KVM_TRACE_MMIO_WRITE) { mmio_event_get_key(sample, key); return true; } @@ -59,7 +59,7 @@ static bool mmio_event_end(struct perf_sample *sample, struct event_key *key) /* MMIO read end event in kernel.*/ if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && - evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_READ) { + perf_sample__intval(sample, "type") == KVM_TRACE_MMIO_READ) { mmio_event_get_key(sample, key); return true; } @@ -87,8 +87,8 @@ static const struct kvm_events_ops mmio_events = { static void ioport_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "port"); - key->info = evsel__intval(sample->evsel, sample, "rw"); + key->key = perf_sample__intval(sample, "port"); + key->info = perf_sample__intval(sample, "rw"); } static bool ioport_event_begin(struct perf_sample *sample, @@ -126,8 +126,8 @@ static const struct kvm_events_ops ioport_events = { /* The time of emulation msr is from kvm_msr to kvm_entry. */ static void msr_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "ecx"); - key->info = evsel__intval(sample->evsel, sample, "write"); + key->key = perf_sample__intval(sample, "ecx"); + key->info = perf_sample__intval(sample, "write"); } static bool msr_event_begin(struct perf_sample *sample, struct event_key *key) diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c index f17a6132958d..755ab659a05c 100644 --- a/tools/perf/util/kvm-stat.c +++ b/tools/perf/util/kvm-stat.c @@ -17,7 +17,7 @@ void exit_event_get_key(struct perf_sample *sample, uint16_t e_machine = evsel__e_machine(sample->evsel, /*e_flags=*/NULL); key->info = 0; - key->key = evsel__intval(sample->evsel, sample, kvm_exit_reason(e_machine)); + key->key = perf_sample__intval(sample, kvm_exit_reason(e_machine)); } -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 07/25] perf trace: Don't pass evsel with sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (5 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 08/25] perf callchain: Don't pass evsel and sample Ian Rogers ` (18 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample now contains the evsel and so don't unnecessarily pass the evsel. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-trace.c | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 493eecf218b4..33199ff2bbfd 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -535,12 +535,12 @@ static struct evsel *perf_evsel__raw_syscall_newtp(const char *direction, void * return NULL; } -#define perf_evsel__sc_tp_uint(evsel, name, sample) \ - ({ struct syscall_tp *fields = __evsel__syscall_tp(evsel); \ +#define perf_evsel__sc_tp_uint(name, sample) \ + ({ struct syscall_tp *fields = __evsel__syscall_tp(sample->evsel); \ fields->name.integer(&fields->name, sample); }) -#define perf_evsel__sc_tp_ptr(evsel, name, sample) \ - ({ struct syscall_tp *fields = __evsel__syscall_tp(evsel); \ +#define perf_evsel__sc_tp_ptr(name, sample) \ + ({ struct syscall_tp *fields = __evsel__syscall_tp(sample->evsel); \ fields->name.pointer(&fields->name, sample); }) size_t strarray__scnprintf_suffix(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_suffix, int val) @@ -2719,8 +2719,8 @@ static int trace__printf_interrupted_entry(struct trace *trace) return printed; } -static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, - struct perf_sample *sample, struct thread *thread) +static int trace__fprintf_sample(struct trace *trace, struct perf_sample *sample, + struct thread *thread) { int printed = 0; @@ -2728,7 +2728,7 @@ static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, double ts = (double)sample->time / NSEC_PER_MSEC; printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n", - evsel__name(evsel), ts, + evsel__name(sample->evsel), ts, thread__comm_str(thread), sample->pid, sample->tid, sample->cpu); } @@ -2783,7 +2783,7 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel, void *args; int printed = 0; struct thread *thread; - int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; + int id = perf_evsel__sc_tp_uint(id, sample), err = -1; int augmented_args_size = 0, e_machine; void *augmented_args = NULL; struct syscall *sc; @@ -2798,9 +2798,9 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel, if (ttrace == NULL) goto out_put; - trace__fprintf_sample(trace, evsel, sample, thread); + trace__fprintf_sample(trace, sample, thread); - args = perf_evsel__sc_tp_ptr(evsel, args, sample); + args = perf_evsel__sc_tp_ptr(args, sample); if (ttrace->entry_str == NULL) { ttrace->entry_str = malloc(trace__entry_str_size); @@ -2855,12 +2855,11 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel, return err; } -static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, - struct perf_sample *sample) +static int trace__fprintf_sys_enter(struct trace *trace, struct perf_sample *sample) { struct thread_trace *ttrace; struct thread *thread; - int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; + int id = perf_evsel__sc_tp_uint(id, sample), err = -1; struct syscall *sc; char msg[1024]; void *args, *augmented_args = NULL; @@ -2870,7 +2869,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); e_machine = thread__e_machine(thread, trace->host, /*e_flags=*/NULL); - sc = trace__syscall_info(trace, evsel, e_machine, id); + sc = trace__syscall_info(trace, sample->evsel, e_machine, id); if (sc == NULL) goto out_put; ttrace = thread__trace(thread, trace); @@ -2881,7 +2880,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, if (ttrace == NULL) goto out_put; - args = perf_evsel__sc_tp_ptr(evsel, args, sample); + args = perf_evsel__sc_tp_ptr(args, sample); augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_syscalls_args_size); printed += syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread); fprintf(trace->output, "%.*s", (int)printed, msg); @@ -2891,10 +2890,11 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, return err; } -static int trace__resolve_callchain(struct trace *trace, struct evsel *evsel, +static int trace__resolve_callchain(struct trace *trace, struct perf_sample *sample, struct callchain_cursor *cursor) { + struct evsel *evsel = sample->evsel; struct addr_location al; int max_stack = evsel->core.attr.sample_max_stack ? evsel->core.attr.sample_max_stack : @@ -2929,7 +2929,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, u64 duration = 0; bool duration_calculated = false; struct thread *thread; - int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1, callchain_ret = 0, printed = 0; + int id = perf_evsel__sc_tp_uint(id, sample), err = -1, callchain_ret = 0, printed = 0; int alignment = trace->args_alignment, e_machine; struct syscall *sc; struct thread_trace *ttrace; @@ -2943,9 +2943,9 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, if (ttrace == NULL) goto out_put; - trace__fprintf_sample(trace, evsel, sample, thread); + trace__fprintf_sample(trace, sample, thread); - ret = perf_evsel__sc_tp_uint(evsel, ret, sample); + ret = perf_evsel__sc_tp_uint(ret, sample); if (trace->summary) thread__update_stats(thread, ttrace, id, sample, ret, trace); @@ -2967,7 +2967,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, if (sample->callchain) { struct callchain_cursor *cursor = get_tls_callchain_cursor(); - callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret = trace__resolve_callchain(trace, sample, cursor); if (callchain_ret == 0) { if (cursor->nr < trace->min_stack) goto out; @@ -3182,9 +3182,10 @@ static void bpf_output__fprintf(struct trace *trace, ++trace->nr_events_printed; } -static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample *sample, +static size_t trace__fprintf_tp_fields(struct trace *trace, struct perf_sample *sample, struct thread *thread, void *augmented_args, int augmented_args_size) { + struct evsel *evsel = sample->evsel; char bf[2048]; size_t size = sizeof(bf); const struct tep_event *tp_format = evsel__tp_format(evsel); @@ -3267,7 +3268,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, if (sample->callchain) { struct callchain_cursor *cursor = get_tls_callchain_cursor(); - callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret = trace__resolve_callchain(trace, sample, cursor); if (callchain_ret == 0) { if (cursor->nr < trace->min_stack) goto out; @@ -3285,7 +3286,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, trace__fprintf_comm_tid(trace, thread, trace->output); if (evsel == trace->syscalls.events.bpf_output) { - int id = perf_evsel__sc_tp_uint(evsel, id, sample); + int id = perf_evsel__sc_tp_uint(id, sample); int e_machine = thread ? thread__e_machine(thread, trace->host, /*e_flags=*/NULL) : EM_HOST; @@ -3293,7 +3294,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, if (sc) { fprintf(trace->output, "%s(", sc->name); - trace__fprintf_sys_enter(trace, evsel, sample); + trace__fprintf_sys_enter(trace, sample); fputc(')', trace->output); goto newline; } @@ -3313,13 +3314,13 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, const struct tep_event *tp_format = evsel__tp_format(evsel); if (tp_format && (strncmp(tp_format->name, "sys_enter_", 10) || - trace__fprintf_sys_enter(trace, evsel, sample))) { + trace__fprintf_sys_enter(trace, sample))) { if (trace->libtraceevent_print) { event_format__fprintf(tp_format, sample->cpu, sample->raw_data, sample->raw_size, trace->output); } else { - trace__fprintf_tp_fields(trace, evsel, sample, thread, NULL, 0); + trace__fprintf_tp_fields(trace, sample, thread, NULL, 0); } } } @@ -3378,7 +3379,7 @@ static int trace__pgfault(struct trace *trace, if (sample->callchain) { struct callchain_cursor *cursor = get_tls_callchain_cursor(); - callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret = trace__resolve_callchain(trace, sample, cursor); if (callchain_ret == 0) { if (cursor->nr < trace->min_stack) goto out_put; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 08/25] perf callchain: Don't pass evsel and sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (6 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 07/25] perf trace: Don't pass evsel with sample Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 09/25] perf lock: Only pass sample to handlers Ian Rogers ` (17 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Change callchain resolve code to not pass an evsel with the sample, instead just read the evsel from the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-inject.c | 4 ++-- tools/perf/builtin-kmem.c | 6 ++--- tools/perf/builtin-kwork.c | 5 ++-- tools/perf/builtin-lock.c | 24 +++++++++---------- tools/perf/builtin-sched.c | 5 ++-- tools/perf/builtin-script.c | 6 ++--- tools/perf/builtin-trace.c | 2 +- tools/perf/util/build-id.c | 2 +- tools/perf/util/callchain.c | 8 +++---- tools/perf/util/callchain.h | 5 ++-- tools/perf/util/db-export.c | 8 +++---- tools/perf/util/hist.c | 2 +- tools/perf/util/machine.c | 14 +++++------ tools/perf/util/machine.h | 3 --- .../util/scripting-engines/trace-event-perl.c | 2 +- .../scripting-engines/trace-event-python.c | 2 +- 17 files changed, 46 insertions(+), 54 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 89456ba6fcbb..f9ac871264af 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -339,7 +339,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, cursor = get_tls_callchain_cursor(); ret = sample__resolve_callchain(sample, cursor, NULL, - evsel, &al, sysctl_perf_event_max_stack); + &al, sysctl_perf_event_max_stack); if (ret) goto out; diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 483c8cac14fd..bc6d94806080 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -418,7 +418,7 @@ static int perf_event__convert_sample_callchain(const struct perf_tool *tool, goto out; /* this will parse DWARF using stack and register data */ - ret = thread__resolve_callchain(thread, cursor, evsel, sample, + ret = thread__resolve_callchain(thread, cursor, sample, /*parent=*/NULL, /*root_al=*/NULL, PERF_MAX_STACK_DEPTH); thread__put(thread); @@ -1020,7 +1020,7 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e } sample->evsel = inject__mmap_evsel(inject); - sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, &args); sample->evsel = saved_evsel; thread__put(thread); diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 96b78a64c1c1..19b12209fc08 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -394,7 +394,7 @@ static int build_alloc_func_list(void) * Find first non-memory allocation function from callchain. * The allocation functions are in the 'alloc_func_list'. */ -static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample) +static u64 find_callsite(struct perf_sample *sample) { struct addr_location al; struct machine *machine = &kmem_session->machines.host; @@ -414,7 +414,7 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample) if (cursor == NULL) goto out; - sample__resolve_callchain(sample, cursor, NULL, evsel, &al, 16); + sample__resolve_callchain(sample, cursor, /*parent=*/NULL, &al, 16); callchain_cursor_commit(cursor); while (true) { @@ -839,7 +839,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) return -1; - callsite = find_callsite(evsel, sample); + callsite = find_callsite(sample); /* * This is to find the current page (with correct gfp flags and diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 111ae53025d1..043da61cdcef 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -688,7 +688,6 @@ static int latency_entry_event(struct perf_kwork *kwork, static void timehist_save_callchain(struct perf_kwork *kwork, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct symbol *sym; @@ -708,7 +707,7 @@ static void timehist_save_callchain(struct perf_kwork *kwork, cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(thread, cursor, evsel, sample, + if (thread__resolve_callchain(thread, cursor, sample, NULL, NULL, kwork->max_stack + 2) != 0) { pr_debug("Failed to resolve callchain, skipping\n"); goto out_put; @@ -838,7 +837,7 @@ static int timehist_entry_event(struct perf_kwork *kwork, return ret; if (work != NULL) - timehist_save_callchain(kwork, sample, evsel, machine); + timehist_save_callchain(kwork, sample, machine); return 0; } diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index baf0c99df5df..a35e8ea4e2ef 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -551,13 +551,13 @@ static int get_key_by_aggr_mode_simple(u64 *key, u64 addr, u32 tid) return 0; } -static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample); +static u64 callchain_id(struct perf_sample *sample); -static int get_key_by_aggr_mode(u64 *key, u64 addr, struct evsel *evsel, +static int get_key_by_aggr_mode(u64 *key, u64 addr, struct perf_sample *sample) { if (aggr_mode == LOCK_AGGR_CALLER) { - *key = callchain_id(evsel, sample); + *key = callchain_id(sample); return 0; } return get_key_by_aggr_mode_simple(key, addr, sample->tid); @@ -841,7 +841,7 @@ static int get_symbol_name_offset(struct map *map, struct symbol *sym, u64 ip, else return strlcpy(buf, sym->name, size); } -static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sample, +static int lock_contention_caller(struct perf_sample *sample, char *buf, int size) { struct thread *thread; @@ -862,7 +862,7 @@ static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sampl cursor = get_tls_callchain_cursor(); /* use caller function name from the callchain */ - ret = thread__resolve_callchain(thread, cursor, evsel, sample, + ret = thread__resolve_callchain(thread, cursor, sample, NULL, NULL, max_stack_depth); if (ret != 0) { thread__put(thread); @@ -896,7 +896,7 @@ static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sampl return -1; } -static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample) +static u64 callchain_id(struct perf_sample *sample) { struct callchain_cursor *cursor; struct machine *machine = &session->machines.host; @@ -911,7 +911,7 @@ static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample) cursor = get_tls_callchain_cursor(); /* use caller function name from the callchain */ - ret = thread__resolve_callchain(thread, cursor, evsel, sample, + ret = thread__resolve_callchain(thread, cursor, sample, NULL, NULL, max_stack_depth); thread__put(thread); @@ -963,7 +963,7 @@ static u64 *get_callstack(struct perf_sample *sample, int max_stack) return callstack; } -static int report_lock_contention_begin_event(struct evsel *evsel, +static int report_lock_contention_begin_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; @@ -978,7 +978,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, struct map *kmap; struct symbol *sym; - ret = get_key_by_aggr_mode(&key, addr, evsel, sample); + ret = get_key_by_aggr_mode(&key, addr, sample); if (ret < 0) return ret; @@ -1025,7 +1025,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, break; case LOCK_AGGR_CALLER: name = buf; - if (lock_contention_caller(evsel, sample, buf, sizeof(buf)) < 0) + if (lock_contention_caller(sample, buf, sizeof(buf)) < 0) name = "Unknown"; break; case LOCK_AGGR_CGROUP: @@ -1127,7 +1127,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, return 0; } -static int report_lock_contention_end_event(struct evsel *evsel, +static int report_lock_contention_end_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; @@ -1138,7 +1138,7 @@ static int report_lock_contention_end_event(struct evsel *evsel, u64 key; int ret; - ret = get_key_by_aggr_mode(&key, addr, evsel, sample); + ret = get_key_by_aggr_mode(&key, addr, sample); if (ret < 0) return ret; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index c7a7e0208a16..854e29bbd6a9 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -2325,7 +2325,6 @@ static bool is_idle_sample(struct perf_sample *sample, static void save_task_callchain(struct perf_sched *sched, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct callchain_cursor *cursor; @@ -2345,7 +2344,7 @@ static void save_task_callchain(struct perf_sched *sched, cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(thread, cursor, evsel, sample, + if (thread__resolve_callchain(thread, cursor, sample, NULL, NULL, sched->max_stack + 2) != 0) { if (verbose > 0) pr_err("Failed to resolve callchain. Skipping\n"); @@ -2519,7 +2518,7 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, sample->tid); } - save_task_callchain(sched, sample, evsel, machine); + save_task_callchain(sched, sample, machine); if (sched->idle_hist) { struct thread *idle; struct idle_thread_runtime *itr; diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8724c4ab3e88..8022801721e2 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1683,7 +1683,7 @@ static int perf_sample__fprintf_bts(struct perf_sample *sample, if (symbol_conf.use_callchain && sample->callchain) { cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack)) cursor = NULL; @@ -2506,7 +2506,7 @@ static void process_event(struct perf_script *script, if (symbol_conf.use_callchain && sample->callchain) { cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack)) cursor = NULL; @@ -2790,7 +2790,7 @@ static int process_deferred_sample_event(const struct perf_tool *tool, if (symbol_conf.use_callchain && sample->callchain) { cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al.thread, cursor, evsel, + if (thread__resolve_callchain(al.thread, cursor, sample, NULL, NULL, scripting_max_stack)) { pr_info("cannot resolve deferred callchains\n"); diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 33199ff2bbfd..385a9ac2ae96 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2905,7 +2905,7 @@ static int trace__resolve_callchain(struct trace *trace, if (machine__resolve(trace->host, &al, sample) < 0) goto out; - err = thread__resolve_callchain(al.thread, cursor, evsel, sample, NULL, NULL, max_stack); + err = thread__resolve_callchain(al.thread, cursor, sample, NULL, NULL, max_stack); out: addr_location__exit(&al); return err; diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 55b72235f891..af4d874f1381 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -73,7 +73,7 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, addr_location__exit(&al); - sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, /*data=*/NULL); diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 8ff0898799ee..4f485ed046a4 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1123,7 +1123,7 @@ int callchain_cursor_append(struct callchain_cursor *cursor, int sample__resolve_callchain(struct perf_sample *sample, struct callchain_cursor *cursor, struct symbol **parent, - struct evsel *evsel, struct addr_location *al, + struct addr_location *al, int max_stack) { if (sample->callchain == NULL && !symbol_conf.show_branchflag_count) @@ -1131,7 +1131,7 @@ int sample__resolve_callchain(struct perf_sample *sample, if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain || perf_hpp_list.parent || symbol_conf.show_branchflag_count) { - return thread__resolve_callchain(al->thread, cursor, evsel, sample, + return thread__resolve_callchain(al->thread, cursor, sample, parent, al, max_stack); } return 0; @@ -1806,7 +1806,7 @@ s64 callchain_avg_cycles(struct callchain_node *cnode) return cycles; } -int sample__for_each_callchain_node(struct thread *thread, struct evsel *evsel, +int sample__for_each_callchain_node(struct thread *thread, struct perf_sample *sample, int max_stack, bool symbols, callchain_iter_fn cb, void *data) { @@ -1817,7 +1817,7 @@ int sample__for_each_callchain_node(struct thread *thread, struct evsel *evsel, return -ENOMEM; /* Fill in the callchain. */ - ret = __thread__resolve_callchain(thread, cursor, evsel, sample, + ret = __thread__resolve_callchain(thread, cursor, sample, /*parent=*/NULL, /*root_al=*/NULL, max_stack, symbols); if (ret) diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index df54ddb8c0cb..6eb3e20349a9 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -8,7 +8,6 @@ #include "branch.h" struct addr_location; -struct evsel; struct ip_callchain; struct map; struct perf_sample; @@ -251,7 +250,7 @@ int record_opts__parse_callchain(struct record_opts *record, int sample__resolve_callchain(struct perf_sample *sample, struct callchain_cursor *cursor, struct symbol **parent, - struct evsel *evsel, struct addr_location *al, + struct addr_location *al, int max_stack); int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample); int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node, @@ -314,7 +313,7 @@ s64 callchain_avg_cycles(struct callchain_node *cnode); typedef int (*callchain_iter_fn)(struct callchain_cursor_node *node, void *data); -int sample__for_each_callchain_node(struct thread *thread, struct evsel *evsel, +int sample__for_each_callchain_node(struct thread *thread, struct perf_sample *sample, int max_stack, bool symbols, callchain_iter_fn cb, void *data); diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index ae9a9065aab7..a1f578c3a8d5 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -209,8 +209,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al, static struct call_path *call_path_from_sample(struct db_export *dbe, struct machine *machine, struct thread *thread, - struct perf_sample *sample, - struct evsel *evsel) + struct perf_sample *sample) { u64 kernel_start = machine__kernel_start(machine); struct call_path *current = &dbe->cpr->call_path; @@ -228,7 +227,7 @@ static struct call_path *call_path_from_sample(struct db_export *dbe, */ callchain_param.order = ORDER_CALLER; cursor = get_tls_callchain_cursor(); - err = thread__resolve_callchain(thread, cursor, evsel, + err = thread__resolve_callchain(thread, cursor, sample, NULL, NULL, PERF_MAX_STACK_DEPTH); if (err) { callchain_param.order = saved_order; @@ -391,8 +390,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, if (dbe->cpr) { struct call_path *cp = call_path_from_sample(dbe, machine, - thread, sample, - evsel); + thread, sample); if (cp) { db_export__call_path(dbe, cp); es.call_path_id = cp->db_id; diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 7ffaa3d9851b..84a402d248a3 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -1339,7 +1339,7 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, alm = map__get(al->map); err = sample__resolve_callchain(iter->sample, get_tls_callchain_cursor(), &iter->parent, - iter->evsel, al, max_stack_depth); + al, max_stack_depth); if (err) { map__put(alm); return err; diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index e76f8c86e62a..c2e0a99efe97 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2778,13 +2778,13 @@ static u64 get_leaf_frame_caller(struct perf_sample *sample, static int thread__resolve_callchain_sample(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, int max_stack, bool symbols) { + struct evsel *evsel = sample->evsel; struct branch_stack *branch = sample->branch_stack; struct branch_entry *entries = perf_sample__branch_entries(sample); struct ip_callchain *chain = sample->callchain; @@ -2986,10 +2986,11 @@ static int unwind_entry(struct unwind_entry *entry, void *arg) static int thread__resolve_callchain_unwind(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, int max_stack, bool symbols) { + struct evsel *evsel = sample->evsel; + /* Can we do dwarf post unwind? */ if (!((evsel->core.attr.sample_type & PERF_SAMPLE_REGS_USER) && (evsel->core.attr.sample_type & PERF_SAMPLE_STACK_USER))) @@ -3009,7 +3010,6 @@ static int thread__resolve_callchain_unwind(struct thread *thread, int __thread__resolve_callchain(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, @@ -3025,22 +3025,22 @@ int __thread__resolve_callchain(struct thread *thread, if (callchain_param.order == ORDER_CALLEE) { ret = thread__resolve_callchain_sample(thread, cursor, - evsel, sample, + sample, parent, root_al, max_stack, symbols); if (ret) return ret; ret = thread__resolve_callchain_unwind(thread, cursor, - evsel, sample, + sample, max_stack, symbols); } else { ret = thread__resolve_callchain_unwind(thread, cursor, - evsel, sample, + sample, max_stack, symbols); if (ret) return ret; ret = thread__resolve_callchain_sample(thread, cursor, - evsel, sample, + sample, parent, root_al, max_stack, symbols); } diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index 22a42c5825fa..048b24e9bd38 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -187,7 +187,6 @@ struct callchain_cursor; int __thread__resolve_callchain(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, @@ -196,7 +195,6 @@ int __thread__resolve_callchain(struct thread *thread, static inline int thread__resolve_callchain(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, @@ -204,7 +202,6 @@ static inline int thread__resolve_callchain(struct thread *thread, { return __thread__resolve_callchain(thread, cursor, - evsel, sample, parent, root_al, diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index e261a57b87d4..850a0048df82 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -272,7 +272,7 @@ static SV *perl_process_callchain(struct perf_sample *sample, cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack) != 0) { pr_err("Failed to resolve callchain. Skipping\n"); goto exit; diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 2b0df7bd9a46..0d8665c75d30 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -404,7 +404,7 @@ static PyObject *python_process_callchain(struct perf_sample *sample, goto exit; cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack) != 0) { pr_err("Failed to resolve callchain. Skipping\n"); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 09/25] perf lock: Only pass sample to handlers 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (7 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 08/25] perf callchain: Don't pass evsel and sample Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 10/25] perf lock: Constify trace_lock_handler variables Ian Rogers ` (16 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The evsel is within the sample and so only the sample needs to be passed. Remove the parameter and fix call site. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-lock.c | 65 ++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index a35e8ea4e2ef..78fb39d06e7c 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -473,28 +473,22 @@ static struct lock_stat *pop_from_result(void) struct trace_lock_handler { /* it's used on CONFIG_LOCKDEP */ - int (*acquire_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*acquire_event)(struct perf_sample *sample); /* it's used on CONFIG_LOCKDEP && CONFIG_LOCK_STAT */ - int (*acquired_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*acquired_event)(struct perf_sample *sample); /* it's used on CONFIG_LOCKDEP && CONFIG_LOCK_STAT */ - int (*contended_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*contended_event)(struct perf_sample *sample); /* it's used on CONFIG_LOCKDEP */ - int (*release_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*release_event)(struct perf_sample *sample); /* it's used when CONFIG_LOCKDEP is off */ - int (*contention_begin_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*contention_begin_event)(struct perf_sample *sample); /* it's used when CONFIG_LOCKDEP is off */ - int (*contention_end_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*contention_end_event)(struct perf_sample *sample); }; static struct lock_seq_stat *get_seq(struct thread_stat *ts, u64 addr) @@ -563,8 +557,7 @@ static int get_key_by_aggr_mode(u64 *key, u64 addr, return get_key_by_aggr_mode_simple(key, addr, sample->tid); } -static int report_lock_acquire_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_acquire_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -638,8 +631,7 @@ static int report_lock_acquire_event(struct evsel *evsel __maybe_unused, return 0; } -static int report_lock_acquired_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_acquired_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -704,8 +696,7 @@ static int report_lock_acquired_event(struct evsel *evsel __maybe_unused, return 0; } -static int report_lock_contended_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_contended_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -762,8 +753,7 @@ static int report_lock_contended_event(struct evsel *evsel __maybe_unused, return 0; } -static int report_lock_release_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_release_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -963,8 +953,7 @@ static u64 *get_callstack(struct perf_sample *sample, int max_stack) return callstack; } -static int report_lock_contention_begin_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_contention_begin_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -1127,8 +1116,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel __maybe_unused return 0; } -static int report_lock_contention_end_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_contention_end_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -1208,45 +1196,45 @@ static struct trace_lock_handler contention_lock_ops = { static struct trace_lock_handler *trace_handler; -static int evsel__process_lock_acquire(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_acquire(struct perf_sample *sample) { if (trace_handler->acquire_event) - return trace_handler->acquire_event(evsel, sample); + return trace_handler->acquire_event(sample); return 0; } -static int evsel__process_lock_acquired(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_acquired(struct perf_sample *sample) { if (trace_handler->acquired_event) - return trace_handler->acquired_event(evsel, sample); + return trace_handler->acquired_event(sample); return 0; } -static int evsel__process_lock_contended(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_contended(struct perf_sample *sample) { if (trace_handler->contended_event) - return trace_handler->contended_event(evsel, sample); + return trace_handler->contended_event(sample); return 0; } -static int evsel__process_lock_release(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_release(struct perf_sample *sample) { if (trace_handler->release_event) - return trace_handler->release_event(evsel, sample); + return trace_handler->release_event(sample); return 0; } -static int evsel__process_contention_begin(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_contention_begin(struct perf_sample *sample) { if (trace_handler->contention_begin_event) - return trace_handler->contention_begin_event(evsel, sample); + return trace_handler->contention_begin_event(sample); return 0; } -static int evsel__process_contention_end(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_contention_end(struct perf_sample *sample) { if (trace_handler->contention_end_event) - return trace_handler->contention_end_event(evsel, sample); + return trace_handler->contention_end_event(sample); return 0; } @@ -1424,8 +1412,7 @@ static int process_event_update(const struct perf_tool *tool, return 0; } -typedef int (*tracepoint_handler)(struct evsel *evsel, - struct perf_sample *sample); +typedef int (*tracepoint_handler)(struct perf_sample *sample); static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, @@ -1445,7 +1432,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(evsel, sample); + err = f(sample); } thread__put(thread); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 10/25] perf lock: Constify trace_lock_handler variables 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (8 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 09/25] perf lock: Only pass sample to handlers Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 11/25] perf hist: Remove evsel parameter from inc samples functions Ian Rogers ` (15 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Structs don't change and so constify. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-lock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 78fb39d06e7c..735e6bb234ae 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1179,7 +1179,7 @@ static int report_lock_contention_end_event(struct perf_sample *sample) /* lock oriented handlers */ /* TODO: handlers for CPU oriented, thread oriented */ -static struct trace_lock_handler report_lock_ops = { +static const struct trace_lock_handler report_lock_ops = { .acquire_event = report_lock_acquire_event, .acquired_event = report_lock_acquired_event, .contended_event = report_lock_contended_event, @@ -1188,13 +1188,13 @@ static struct trace_lock_handler report_lock_ops = { .contention_end_event = report_lock_contention_end_event, }; -static struct trace_lock_handler contention_lock_ops = { +static const struct trace_lock_handler contention_lock_ops = { .contention_begin_event = report_lock_contention_begin_event, .contention_end_event = report_lock_contention_end_event, }; -static struct trace_lock_handler *trace_handler; +static const struct trace_lock_handler *trace_handler; static int evsel__process_lock_acquire(struct perf_sample *sample) { -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 11/25] perf hist: Remove evsel parameter from inc samples functions 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (9 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 10/25] perf lock: Constify trace_lock_handler variables Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 12/25] perf db-export: Remove evsel from struct export_sample Ian Rogers ` (14 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan hist_entry__inc_addr_samples and addr_map_symbol__inc_samples unnecessarily take an evsel argument. Read the evsel from the sample instead. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 7 +++---- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-report.c | 18 ++++++++---------- tools/perf/builtin-top.c | 6 +++--- tools/perf/util/annotate.c | 19 +++++++++---------- tools/perf/util/annotate.h | 6 ++---- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index c97a0fe159f8..c2d0599fe5f5 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -177,16 +177,15 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, struct hist_entry *he = iter->he; struct branch_info *bi; struct perf_sample *sample = iter->sample; - struct evsel *evsel = iter->evsel; int err; bi = he->branch_info; - err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; - err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->to, sample); out: return err; @@ -276,7 +275,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, if (he == NULL) return -ENOMEM; - ret = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + ret = hist_entry__inc_addr_samples(he, sample, al->addr); hists__inc_nr_samples(hists, true); return ret; } diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index f9ac871264af..5684c14c2bf6 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -371,7 +371,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, if (perf_c2c__has_annotation(NULL)) { perf_c2c__evsel_hists_inc_stats(evsel, he, sample); - addr_map_symbol__inc_samples(mem_info__iaddr(mi), sample, evsel); + addr_map_symbol__inc_samples(mem_info__iaddr(mi), sample); } ret = hist_entry__append_callchain(he, sample); diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 507002cbdd5b..39968ae5cfb0 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -170,7 +170,6 @@ static int hist_iter__report_callback(struct hist_entry_iter *iter, int err = 0; struct report *rep = arg; struct hist_entry *he = iter->he; - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; struct mem_info *mi; struct branch_info *bi; @@ -180,25 +179,25 @@ static int hist_iter__report_callback(struct hist_entry_iter *iter, if (sort__mode == SORT_MODE__BRANCH) { bi = he->branch_info; - err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; - err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->to, sample); } else if (rep->mem_mode) { mi = he->mem_info; - err = addr_map_symbol__inc_samples(mem_info__daddr(mi), sample, evsel); + err = addr_map_symbol__inc_samples(mem_info__daddr(mi), sample); if (err) goto out; - err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err = hist_entry__inc_addr_samples(he, sample, al->addr); } else if (symbol_conf.cumulate_callchain) { if (single) - err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err = hist_entry__inc_addr_samples(he, sample, al->addr); } else { - err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err = hist_entry__inc_addr_samples(he, sample, al->addr); } out: @@ -214,7 +213,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, struct report *rep = arg; struct branch_info *bi = he->branch_info; struct perf_sample *sample = iter->sample; - struct evsel *evsel = iter->evsel; int err; branch_type_count(&rep->brtype_stat, &bi->flags, @@ -223,11 +221,11 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, if (!ui__has_annotation() && !rep->symbol_ipc) return 0; - err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; - err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->to, sample); out: return err; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 710604c4f6f6..e863f9ef581f 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -198,7 +198,7 @@ static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip) static void perf_top__record_precise_ip(struct perf_top *top, struct hist_entry *he, struct perf_sample *sample, - struct evsel *evsel, u64 ip) + u64 ip) EXCLUSIVE_LOCKS_REQUIRED(he->hists->lock) { struct annotation *notes; @@ -215,7 +215,7 @@ static void perf_top__record_precise_ip(struct perf_top *top, if (!annotation__trylock(notes)) return; - err = hist_entry__inc_addr_samples(he, sample, evsel, ip); + err = hist_entry__inc_addr_samples(he, sample, ip); annotation__unlock(notes); @@ -734,7 +734,7 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter, struct evsel *evsel = iter->evsel; if (perf_hpp_list.sym && single) - perf_top__record_precise_ip(top, iter->he, iter->sample, evsel, al->addr); + perf_top__record_precise_ip(top, iter->he, iter->sample, al->addr); hist__account_cycles(iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY), diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 2e3522905046..15ff0443c312 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -211,9 +211,10 @@ static int __symbol__account_cycles(struct cyc_hist *ch, } static int __symbol__inc_addr_samples(struct map_symbol *ms, - struct annotated_source *src, struct evsel *evsel, u64 addr, + struct annotated_source *src, u64 addr, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; struct symbol *sym = ms->sym; long hash_key; u64 offset; @@ -316,7 +317,7 @@ struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists) } static int symbol__inc_addr_samples(struct map_symbol *ms, - struct evsel *evsel, u64 addr, + u64 addr, struct perf_sample *sample) { struct symbol *sym = ms->sym; @@ -324,8 +325,8 @@ static int symbol__inc_addr_samples(struct map_symbol *ms, if (sym == NULL) return 0; - src = symbol__hists(sym, evsel->evlist->core.nr_entries); - return src ? __symbol__inc_addr_samples(ms, src, evsel, addr, sample) : 0; + src = symbol__hists(sym, sample->evsel->evlist->core.nr_entries); + return src ? __symbol__inc_addr_samples(ms, src, addr, sample) : 0; } static int symbol__account_br_cntr(struct annotated_branch *branch, @@ -579,16 +580,14 @@ static int annotation__compute_ipc(struct annotation *notes, size_t size, return 0; } -int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample, - struct evsel *evsel) +int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample) { - return symbol__inc_addr_samples(&ams->ms, evsel, ams->al_addr, sample); + return symbol__inc_addr_samples(&ams->ms, ams->al_addr, sample); } -int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, - struct evsel *evsel, u64 ip) +int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, u64 ip) { - return symbol__inc_addr_samples(&he->ms, evsel, ip, sample); + return symbol__inc_addr_samples(&he->ms, ip, sample); } diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 696e36dbf013..1aa6df7d1618 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -422,8 +422,7 @@ static inline struct annotation *symbol__annotation(struct symbol *sym) return (void *)sym - symbol_conf.priv_size; } -int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample, - struct evsel *evsel); +int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample); struct annotated_branch *annotation__get_branch(struct annotation *notes); @@ -433,8 +432,7 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams, struct evsel *evsel, u64 br_cntr); -int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, - struct evsel *evsel, u64 addr); +int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, u64 addr); struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists); void symbol__annotate_zero_histograms(struct symbol *sym); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 12/25] perf db-export: Remove evsel from struct export_sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (10 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 11/25] perf hist: Remove evsel parameter from inc samples functions Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 13/25] perf hist: Remove evsel from struct hist_entry_iter Ian Rogers ` (13 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan As the sample contains the evsel avoid the duplication. Remove the evsel from db_export__sample as it can also read from the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/db-export.c | 5 ++--- tools/perf/util/db-export.h | 3 +-- tools/perf/util/scripting-engines/trace-event-python.c | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index a1f578c3a8d5..fdfd825c7ef4 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -345,14 +345,13 @@ static int db_export__threads(struct db_export *dbe, struct thread *thread, } int db_export__sample(struct db_export *dbe, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al) { struct thread *thread = al->thread; struct export_sample es = { .event = event, .sample = sample, - .evsel = evsel, .al = al, }; struct thread *main_thread; @@ -365,7 +364,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, if (!machine) return -1; - err = db_export__evsel(dbe, evsel); + err = db_export__evsel(dbe, sample->evsel); if (err) return err; diff --git a/tools/perf/util/db-export.h b/tools/perf/util/db-export.h index 23983cb35706..1abbfd398e3a 100644 --- a/tools/perf/util/db-export.h +++ b/tools/perf/util/db-export.h @@ -25,7 +25,6 @@ struct call_return; struct export_sample { union perf_event *event; struct perf_sample *sample; - struct evsel *evsel; struct addr_location *al; u64 db_id; u64 comm_db_id; @@ -96,7 +95,7 @@ int db_export__symbol(struct db_export *dbe, struct symbol *sym, int db_export__branch_type(struct db_export *dbe, u32 branch_type, const char *name); int db_export__sample(struct db_export *dbe, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al); int db_export__branch_types(struct db_export *dbe); diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 0d8665c75d30..9f5c6e5e6ebe 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1312,7 +1312,7 @@ static void python_export_sample_table(struct db_export *dbe, t = tuple_new(28); tuple_set_d64(t, 0, es->db_id); - tuple_set_d64(t, 1, es->evsel->db_id); + tuple_set_d64(t, 1, es->sample->evsel->db_id); tuple_set_d64(t, 2, maps__machine(thread__maps(es->al->thread))->db_id); tuple_set_d64(t, 3, thread__db_id(es->al->thread)); tuple_set_d64(t, 4, es->comm_db_id); @@ -1353,7 +1353,7 @@ static void python_export_synth(struct db_export *dbe, struct export_sample *es) t = tuple_new(3); tuple_set_d64(t, 0, es->db_id); - tuple_set_d64(t, 1, es->evsel->core.attr.config); + tuple_set_d64(t, 1, es->sample->evsel->core.attr.config); tuple_set_bytes(t, 2, es->sample->raw_data, es->sample->raw_size); call_object(tables->synth_handler, t, "synth_data"); @@ -1368,7 +1368,7 @@ static int python_export_sample(struct db_export *dbe, python_export_sample_table(dbe, es); - if (es->evsel->core.attr.type == PERF_TYPE_SYNTH && tables->synth_handler) + if (es->sample->evsel->core.attr.type == PERF_TYPE_SYNTH && tables->synth_handler) python_export_synth(dbe, es); return 0; @@ -1517,7 +1517,7 @@ static void python_process_event(union perf_event *event, /* Reserve for future process_hw/sw/raw APIs */ default: if (tables->db_export_mode) - db_export__sample(&tables->dbe, event, sample, evsel, al, addr_al); + db_export__sample(&tables->dbe, event, sample, al, addr_al); else python_process_general_event(sample, evsel, al, addr_al); } -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 13/25] perf hist: Remove evsel from struct hist_entry_iter 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (11 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 12/25] perf db-export: Remove evsel from struct export_sample Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id Ian Rogers ` (12 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan struct hist_entry_iter has the sample within it so the evsel is unnecessary. Remove the evsel and update uses. Also remove the evsel from hist__account_cycles and derive it from the sample too. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 10 ++++------ tools/perf/builtin-diff.c | 3 +-- tools/perf/builtin-report.c | 6 ++---- tools/perf/builtin-top.c | 9 +++------ tools/perf/tests/hists_cumulate.c | 1 - tools/perf/tests/hists_filter.c | 1 - tools/perf/tests/hists_output.c | 1 - tools/perf/util/hist.c | 24 ++++++++++++------------ tools/perf/util/hist.h | 3 +-- 9 files changed, 23 insertions(+), 35 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index c2d0599fe5f5..041f5dc92ea8 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -191,14 +191,12 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, return err; } -static int process_branch_callback(struct evsel *evsel, - struct perf_sample *sample, +static int process_branch_callback(struct perf_sample *sample, struct addr_location *al, struct perf_annotate *ann, struct machine *machine) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .add_entry_cb = hist_iter__branch_callback, .hide_unresolved = symbol_conf.hide_unresolved, @@ -221,8 +219,8 @@ static int process_branch_callback(struct evsel *evsel, if (a.map != NULL) dso__set_hit(map__dso(a.map)); - hist__account_cycles(sample->branch_stack, al, sample, false, - NULL, evsel); + hist__account_cycles(sample->branch_stack, al, sample, /*nonany_branch_mode=*/false, + /*total_cycles=*/NULL); ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann); out: @@ -269,7 +267,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, process_branch_stack(sample->branch_stack, al, sample); if (ann->has_br_stack && has_annotation(ann)) - return process_branch_callback(evsel, sample, al, ann, machine); + return process_branch_callback(sample, al, ann, machine); he = hists__add_entry(hists, al, NULL, NULL, NULL, NULL, sample, true); if (he == NULL) diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 096adc65451c..67cf5bbaab29 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -397,7 +397,6 @@ static int diff__process_sample_event(const struct perf_tool *tool, struct evsel *evsel = sample->evsel; struct hists *hists = evsel__hists(evsel); struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .ops = &hist_iter_normal, }; @@ -431,7 +430,7 @@ static int diff__process_sample_event(const struct perf_tool *tool, } hist__account_cycles(sample->branch_stack, &al, sample, - false, NULL, evsel); + /*nonany_branch_mode=*/false, /*total_cycles=*/NULL); break; case COMPUTE_STREAM: diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 39968ae5cfb0..1051d7b75361 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -270,10 +270,8 @@ static int process_sample_event(const struct perf_tool *tool, struct machine *machine) { struct report *rep = container_of(tool, struct report, tool); - struct evsel *evsel = sample->evsel; struct addr_location al; struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .hide_unresolved = symbol_conf.hide_unresolved, .add_entry_cb = hist_iter__report_callback, @@ -285,7 +283,7 @@ static int process_sample_event(const struct perf_tool *tool, return 0; } - if (evswitch__discard(&rep->evswitch, evsel)) + if (evswitch__discard(&rep->evswitch, sample->evsel)) return 0; addr_location__init(&al); @@ -329,7 +327,7 @@ static int process_sample_event(const struct perf_tool *tool, if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) { hist__account_cycles(sample->branch_stack, &al, sample, rep->nonany_branch_mode, - &rep->total_cycles, evsel); + &rep->total_cycles); } rep->total_samples++; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index e863f9ef581f..b89ca48e5d02 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -731,20 +731,18 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter, EXCLUSIVE_LOCKS_REQUIRED(iter->he->hists->lock) { struct perf_top *top = arg; - struct evsel *evsel = iter->evsel; if (perf_hpp_list.sym && single) perf_top__record_precise_ip(top, iter->he, iter->sample, al->addr); hist__account_cycles(iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY), - NULL, evsel); + /*total_cycles=*/NULL); return 0; } static void perf_event__process_sample(const struct perf_tool *tool, const union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -830,9 +828,8 @@ static void perf_event__process_sample(const struct perf_tool *tool, } if (al.sym == NULL || !al.sym->idle) { - struct hists *hists = evsel__hists(evsel); + struct hists *hists = evsel__hists(sample->evsel); struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .add_entry_cb = hist_iter__top_callback, }; @@ -1210,7 +1207,7 @@ static int deliver_event(struct ordered_events *qe, } if (event->header.type == PERF_RECORD_SAMPLE) { - perf_event__process_sample(&top->tool, event, evsel, + perf_event__process_sample(&top->tool, event, &sample, machine); } else if (event->header.type == PERF_RECORD_LOST) { perf_top__process_lost(top, event, evsel); diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c index 606aa926a8fc..267cbc24691a 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -87,7 +87,6 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) addr_location__init(&al); for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = &sample, .hide_unresolved = false, }; diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c index cc6b26e373d1..002e3a4c1ca5 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -63,7 +63,6 @@ static int add_hist_entries(struct evlist *evlist, evlist__for_each_entry(evlist, evsel) { for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = &sample, .ops = &hist_iter_normal, .hide_unresolved = false, diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c index 7818950d786e..fa683fd7b1e5 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -57,7 +57,6 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) addr_location__init(&al); for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = &sample, .ops = &hist_iter_normal, .hide_unresolved = false, diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 84a402d248a3..632c1edcab9a 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -932,8 +932,8 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al { u64 cost; struct mem_info *mi = iter->mi; - struct hists *hists = evsel__hists(iter->evsel); struct perf_sample *sample = iter->sample; + struct hists *hists = evsel__hists(sample->evsel); struct hist_entry *he; if (mi == NULL) @@ -965,7 +965,7 @@ static int iter_finish_mem_entry(struct hist_entry_iter *iter, struct addr_location *al __maybe_unused) { - struct evsel *evsel = iter->evsel; + struct evsel *evsel = iter->sample->evsel; struct hists *hists = evsel__hists(evsel); struct hist_entry *he = iter->he; int err = -EINVAL; @@ -1033,9 +1033,9 @@ static int iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) { struct branch_info *bi; - struct evsel *evsel = iter->evsel; - struct hists *hists = evsel__hists(evsel); struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; + struct hists *hists = evsel__hists(evsel); struct hist_entry *he = NULL; int i = iter->curr; int err = 0; @@ -1075,7 +1075,7 @@ static int iter_finish_branch_entry(struct hist_entry_iter *iter, struct addr_location *al __maybe_unused) { - struct evsel *evsel = iter->evsel; + struct evsel *evsel = iter->sample->evsel; struct hists *hists = evsel__hists(evsel); for (int i = 0; i < iter->total; i++) @@ -1100,8 +1100,8 @@ iter_prepare_normal_entry(struct hist_entry_iter *iter __maybe_unused, static int iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; struct hist_entry *he; he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, @@ -1118,8 +1118,8 @@ iter_finish_normal_entry(struct hist_entry_iter *iter, struct addr_location *al __maybe_unused) { struct hist_entry *he = iter->he; - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; if (he == NULL) return 0; @@ -1162,9 +1162,9 @@ static int iter_add_single_cumulative_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel = iter->evsel; - struct hists *hists = evsel__hists(evsel); struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; + struct hists *hists = evsel__hists(evsel); struct hist_entry **he_cache = iter->he_cache; struct hist_entry *he; int err = 0; @@ -1221,8 +1221,8 @@ static int iter_add_next_cumulative_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; struct hist_entry **he_cache = iter->he_cache; struct hist_entry *he; struct hist_entry he_tmp = { @@ -2823,7 +2823,7 @@ int hists__unlink(struct hists *hists) void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, struct perf_sample *sample, bool nonany_branch_mode, - u64 *total_cycles, struct evsel *evsel) + u64 *total_cycles) { struct branch_info *bi; struct branch_entry *entries = perf_sample__branch_entries(sample); @@ -2847,7 +2847,7 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, for (int i = bs->nr - 1; i >= 0; i--) { addr_map_symbol__account_cycles(&bi[i].from, nonany_branch_mode ? NULL : prev, - bi[i].flags.cycles, evsel, + bi[i].flags.cycles, sample->evsel, bi[i].branch_stack_cntr); prev = &bi[i].to; diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 1d5ea632ca4e..ee92fffc53a9 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -155,7 +155,6 @@ struct hist_entry_iter { int total; int curr; - struct evsel *evsel; struct perf_sample *sample; struct hist_entry *he; struct symbol *parent; @@ -797,7 +796,7 @@ unsigned int hists__overhead_width(struct hists *hists); void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, struct perf_sample *sample, bool nonany_branch_mode, - u64 *total_cycles, struct evsel *evsel); + u64 *total_cycles); struct option; int parse_filter_percentage(const struct option *opt, const char *arg, int unset); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (12 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 13/25] perf hist: Remove evsel from struct hist_entry_iter Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 15/25] perf annotate: Don't pass evsel to add_sample Ian Rogers ` (11 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan In count_lost_samples_events try to avoid searching for the evsel for the sample, just use the variable within the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-report.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 1051d7b75361..d53aa7a94192 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -793,9 +793,11 @@ static int count_lost_samples_event(const struct perf_tool *tool, struct machine *machine __maybe_unused) { struct report *rep = container_of(tool, struct report, tool); - struct evsel *evsel; + struct evsel *evsel = sample->evsel; + + if (!evsel) + evsel = evlist__id2evsel(rep->session->evlist, sample->id); - evsel = evlist__id2evsel(rep->session->evlist, sample->id); if (evsel) { struct hists *hists = evsel__hists(evsel); u32 count = event->lost_samples.lost; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 15/25] perf annotate: Don't pass evsel to add_sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (13 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 16/25] perf inject: Don't pass evsel with sample Ian Rogers ` (10 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel so read it rather than pass it. Update call site. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 041f5dc92ea8..894e57aa50cd 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -233,11 +233,11 @@ static bool has_annotation(struct perf_annotate *ann) return ui__has_annotation() || ann->use_stdio2; } -static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, - struct addr_location *al, struct perf_annotate *ann, - struct machine *machine) +static int add_sample(struct perf_sample *sample, + struct addr_location *al, struct perf_annotate *ann, + struct machine *machine) { - struct hists *hists = evsel__hists(evsel); + struct hists *hists = evsel__hists(sample->evsel); struct hist_entry *he; int ret; @@ -299,7 +299,7 @@ static int process_sample_event(const struct perf_tool *tool, goto out_put; if (!al.filtered && - evsel__add_sample(sample->evsel, sample, &al, ann, machine)) { + add_sample(sample, &al, ann, machine)) { pr_warning("problem incrementing symbol count, " "skipping event\n"); ret = -1; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 16/25] perf inject: Don't pass evsel with sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (14 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 15/25] perf annotate: Don't pass evsel to add_sample Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 17/25] perf kmem: " Ian Rogers ` (9 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 37 +++++++++++------------------- tools/perf/util/synthetic-events.c | 9 ++++---- tools/perf/util/synthetic-events.h | 2 -- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index bc6d94806080..6e265b66a551 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -146,14 +146,12 @@ struct event_entry { static int tool__inject_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, const char *filename, struct dso *dso, u32 flags); static int tool__inject_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -357,7 +355,6 @@ perf_inject__cut_auxtrace_sample(struct perf_inject *inject, typedef int (*inject_handler)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); static int perf_event__repipe_sample(const struct perf_tool *tool, @@ -370,7 +367,7 @@ static int perf_event__repipe_sample(const struct perf_tool *tool, if (evsel && evsel->handler) { inject_handler f = evsel->handler; - return f(tool, event, sample, evsel, machine); + return f(tool, event, sample, machine); } build_id__mark_dso_hit(tool, event, sample, machine); @@ -584,11 +581,14 @@ static int perf_event__repipe_common_mmap(const struct perf_tool *tool, } if (dso && !dso__hit(dso)) { - struct evsel *evsel = evlist__event2evsel(inject->session->evlist, event); + struct evsel *evsel = sample->evsel; + + if (!evsel) + evsel = evlist__event2evsel(inject->session->evlist, event); if (evsel) { dso__set_hit(dso); - tool__inject_build_id(tool, sample, machine, evsel, + tool__inject_build_id(tool, sample, machine, /*misc=*/sample->cpumode, filename, dso, flags); } @@ -622,7 +622,7 @@ static int perf_event__repipe_common_mmap(const struct perf_tool *tool, dso_sought = true; } if (evsel && dso && - !tool__inject_mmap2_build_id(tool, sample, machine, evsel, + !tool__inject_mmap2_build_id(tool, sample, machine, sample->cpumode | PERF_RECORD_MISC_MMAP_BUILD_ID, pid, tid, start, len, pgoff, dso, @@ -836,7 +836,6 @@ static bool perf_inject__lookup_known_build_id(struct perf_inject *inject, static int tool__inject_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, const char *filename, struct dso *dso, u32 flags) @@ -860,7 +859,7 @@ static int tool__inject_build_id(const struct perf_tool *tool, err = perf_event__synthesize_build_id(tool, sample, machine, perf_event__repipe, - evsel, misc, dso__bid(dso), + misc, dso__bid(dso), filename); if (err) { pr_err("Can't synthesize build_id event for %s\n", filename); @@ -873,7 +872,6 @@ static int tool__inject_build_id(const struct perf_tool *tool, static int tool__inject_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -896,7 +894,6 @@ static int tool__inject_mmap2_build_id(const struct perf_tool *tool, err = perf_event__synthesize_mmap2_build_id(tool, sample, machine, perf_event__repipe, - evsel, misc, pid, tid, start, len, pgoff, dso__bid(dso), @@ -913,7 +910,6 @@ static int mark_dso_hit(const struct perf_inject *inject, const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *mmap_evsel, struct map *map, bool sample_in_dso) { struct dso *dso; @@ -943,7 +939,7 @@ static int mark_dso_hit(const struct perf_inject *inject, if (dso && !dso__hit(dso)) { dso__set_hit(dso); tool__inject_build_id(tool, sample, machine, - mmap_evsel, misc, dso__long_name(dso), dso, + misc, dso__long_name(dso), dso, map__flags(map)); } } else if (inject->build_id_style == BID_RWS__MMAP2_BUILDID_LAZY) { @@ -955,7 +951,6 @@ static int mark_dso_hit(const struct perf_inject *inject, map__set_hit(map); perf_event__synthesize_mmap2_build_id(tool, sample, machine, perf_event__repipe, - mmap_evsel, misc, sample->pid, sample->tid, map__start(map), @@ -975,7 +970,6 @@ struct mark_dso_hit_args { const struct perf_tool *tool; struct perf_sample *sample; struct machine *machine; - const struct evsel *mmap_evsel; }; static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data) @@ -984,7 +978,7 @@ static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data) struct map *map = node->ms.map; return mark_dso_hit(args->inject, args->tool, args->sample, args->machine, - args->mmap_evsel, map, /*sample_in_dso=*/false); + map, /*sample_in_dso=*/false); } static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, @@ -1002,7 +996,6 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e */ .sample = sample, .machine = machine, - .mmap_evsel = inject__mmap_evsel(inject), }; struct evsel *saved_evsel = sample->evsel; @@ -1015,7 +1008,7 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e } if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) { - mark_dso_hit(inject, tool, sample, machine, args.mmap_evsel, al.map, + mark_dso_hit(inject, tool, sample, machine, al.map, /*sample_in_dso=*/true); } @@ -1033,7 +1026,6 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e static int perf_inject__sched_process_exit(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine __maybe_unused) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); @@ -1053,13 +1045,12 @@ static int perf_inject__sched_process_exit(const struct perf_tool *tool, static int perf_inject__sched_switch(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); struct event_entry *ent; - perf_inject__sched_process_exit(tool, event, sample, evsel, machine); + perf_inject__sched_process_exit(tool, event, sample, machine); ent = malloc(event->header.size + sizeof(struct event_entry)); if (ent == NULL) { @@ -1078,13 +1069,13 @@ static int perf_inject__sched_switch(const struct perf_tool *tool, static int perf_inject__sched_stat(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct event_entry *ent; union perf_event *event_sw; struct perf_sample sample_sw; struct perf_inject *inject = container_of(tool, struct perf_inject, tool); + struct evsel *evsel = sample->evsel; u32 pid = perf_sample__intval(sample, "pid"); int ret; @@ -1449,7 +1440,7 @@ static int synthesize_build_id(struct perf_inject *inject, struct dso *dso, pid_ dso__set_hit(dso); return perf_event__synthesize_build_id(&inject->tool, &synth_sample, machine, - process_build_id, inject__mmap_evsel(inject), + process_build_id, /*misc=*/synth_sample.cpumode, dso__bid(dso), dso__long_name(dso)); } diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index ef79433ebc3a..53e411cf33cc 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2247,7 +2247,6 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, const struct build_id *bid, const char *filename) @@ -2270,12 +2269,13 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, ev.build_id.header.size = len; strcpy(ev.build_id.filename, filename); - if (evsel) { + if (sample->evsel) { void *array = &ev; int ret; array += ev.header.size; - ret = perf_event__synthesize_id_sample(array, evsel->core.attr.sample_type, sample); + ret = perf_event__synthesize_id_sample(array, sample->evsel->core.attr.sample_type, + sample); if (ret < 0) return ret; @@ -2294,7 +2294,6 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -2334,7 +2333,7 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, array = &ev; array += ev.header.size; - ret = perf_event__synthesize_id_sample(array, evsel->core.attr.sample_type, sample); + ret = perf_event__synthesize_id_sample(array, sample->evsel->core.attr.sample_type, sample); if (ret < 0) return ret; diff --git a/tools/perf/util/synthetic-events.h b/tools/perf/util/synthetic-events.h index b0edad0c3100..473a43a78993 100644 --- a/tools/perf/util/synthetic-events.h +++ b/tools/perf/util/synthetic-events.h @@ -50,7 +50,6 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, const struct build_id *bid, const char *filename); @@ -58,7 +57,6 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 17/25] perf kmem: Don't pass evsel with sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (15 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 16/25] perf inject: Don't pass evsel with sample Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 18/25] perf kwork: " Ian Rogers ` (8 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-kmem.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 19b12209fc08..ea2437971e8b 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -171,7 +171,7 @@ static int insert_caller_stat(unsigned long call_site, return 0; } -static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_alloc_event(struct perf_sample *sample) { unsigned long ptr = perf_sample__intval(sample, "ptr"), call_site = perf_sample__intval(sample, "call_site"); @@ -198,7 +198,7 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s * If the tracepoint contains the field "node" the tool stats the * cross allocation. */ - if (evsel__field(evsel, "node")) { + if (evsel__field(sample->evsel, "node")) { int node1, node2; node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}); @@ -243,7 +243,7 @@ static struct alloc_stat *search_alloc_stat(unsigned long ptr, return NULL; } -static int evsel__process_free_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) +static int evsel__process_free_event(struct perf_sample *sample) { unsigned long ptr = perf_sample__intval(sample, "ptr"); struct alloc_stat *s_alloc, *s_caller; @@ -751,8 +751,7 @@ static char *compact_gfp_string(unsigned long gfp_flags) return NULL; } -static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, - unsigned int gfp_flags) +static int parse_gfp_flags(struct perf_sample *sample, unsigned int gfp_flags) { struct tep_record record = { .cpu = sample->cpu, @@ -773,7 +772,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, } trace_seq_init(&seq); - tp_format = evsel__tp_format(evsel); + tp_format = evsel__tp_format(sample->evsel); if (tp_format) tep_print_event(tp_format->tep, &seq, &record, "%s", TEP_PRINT_INFO); @@ -805,7 +804,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, return 0; } -static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_page_alloc_event(struct perf_sample *sample) { u64 page; unsigned int order = perf_sample__intval(sample, "order"); @@ -836,7 +835,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp return 0; } - if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) + if (parse_gfp_flags(sample, gfp_flags) < 0) return -1; callsite = find_callsite(sample); @@ -877,8 +876,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp return 0; } -static int evsel__process_page_free_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int evsel__process_page_free_event(struct perf_sample *sample) { u64 page; unsigned int order = perf_sample__intval(sample, "order"); @@ -955,8 +953,7 @@ static bool perf_kmem__skip_sample(struct perf_sample *sample) return false; } -typedef int (*tracepoint_handler)(struct evsel *evsel, - struct perf_sample *sample); +typedef int (*tracepoint_handler)(struct perf_sample *sample); static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, @@ -981,7 +978,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(evsel, sample); + err = f(sample); } thread__put(thread); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 18/25] perf kwork: Don't pass evsel with sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (16 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 17/25] perf kmem: " Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 19/25] perf sched: " Ian Rogers ` (7 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Remove the evsel from struct kwork_class. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-kwork.c | 74 +++++++++++++------------------------- tools/perf/util/kwork.h | 9 +++-- 2 files changed, 28 insertions(+), 55 deletions(-) diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 043da61cdcef..bbc6c209eb14 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -448,7 +448,6 @@ static int work_push_atom(struct perf_kwork *kwork, struct kwork_class *class, enum kwork_trace_type src_type, enum kwork_trace_type dst_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct kwork_work **ret_work, @@ -458,7 +457,7 @@ static int work_push_atom(struct perf_kwork *kwork, struct kwork_work *work, key; BUG_ON(class->work_init == NULL); - class->work_init(kwork, class, &key, src_type, evsel, sample, machine); + class->work_init(kwork, class, &key, src_type, sample, machine); atom = atom_new(kwork, sample); if (atom == NULL) @@ -507,7 +506,6 @@ static struct kwork_atom *work_pop_atom(struct perf_kwork *kwork, struct kwork_class *class, enum kwork_trace_type src_type, enum kwork_trace_type dst_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct kwork_work **ret_work) @@ -516,7 +514,7 @@ static struct kwork_atom *work_pop_atom(struct perf_kwork *kwork, struct kwork_work *work, key; BUG_ON(class->work_init == NULL); - class->work_init(kwork, class, &key, src_type, evsel, sample, machine); + class->work_init(kwork, class, &key, src_type, sample, machine); work = work_findnew(&class->work_root, &key, &kwork->cmp_id); if (ret_work != NULL) @@ -599,18 +597,16 @@ static void report_update_exit_event(struct kwork_work *work, static int report_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int report_exit_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -618,7 +614,7 @@ static int report_exit_event(struct perf_kwork *kwork, struct kwork_work *work = NULL; atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (work == NULL) return -1; @@ -654,18 +650,16 @@ static void latency_update_entry_event(struct kwork_work *work, static int latency_raise_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_RAISE, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int latency_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -673,7 +667,7 @@ static int latency_entry_event(struct perf_kwork *kwork, struct kwork_work *work = NULL; atom = work_pop_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_RAISE, evsel, sample, + KWORK_TRACE_RAISE, sample, machine, &work); if (work == NULL) return -1; @@ -812,18 +806,16 @@ static void timehist_print_event(struct perf_kwork *kwork, static int timehist_raise_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_RAISE, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int timehist_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -831,7 +823,7 @@ static int timehist_entry_event(struct perf_kwork *kwork, struct kwork_work *work = NULL; ret = work_push_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_RAISE, evsel, sample, + KWORK_TRACE_RAISE, sample, machine, &work, true); if (ret) return ret; @@ -844,7 +836,6 @@ static int timehist_entry_event(struct perf_kwork *kwork, static int timehist_exit_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -861,7 +852,7 @@ static int timehist_exit_event(struct perf_kwork *kwork, } atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (work == NULL) { ret = -1; @@ -895,18 +886,16 @@ static void top_update_runtime(struct kwork_work *work, static int top_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int top_exit_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -915,7 +904,7 @@ static int top_exit_event(struct perf_kwork *kwork, struct kwork_atom *atom; atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (!work) return -1; @@ -936,7 +925,6 @@ static int top_exit_event(struct perf_kwork *kwork, static int top_sched_switch_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -944,7 +932,7 @@ static int top_sched_switch_event(struct perf_kwork *kwork, struct kwork_work *work; atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (!work) return -1; @@ -954,12 +942,11 @@ static int top_sched_switch_event(struct perf_kwork *kwork, atom_del(atom); } - return top_entry_event(kwork, class, evsel, sample, machine); + return top_entry_event(kwork, class, sample, machine); } static struct kwork_class kwork_irq; static int process_irq_handler_entry_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -967,12 +954,11 @@ static int process_irq_handler_entry_event(const struct perf_tool *tool, if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_irq, - evsel, sample, machine); + sample, machine); return 0; } static int process_irq_handler_exit_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -980,7 +966,7 @@ static int process_irq_handler_exit_event(const struct perf_tool *tool, if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_irq, - evsel, sample, machine); + sample, machine); return 0; } @@ -1005,7 +991,6 @@ static void irq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1038,7 +1023,6 @@ static struct kwork_class kwork_irq = { static struct kwork_class kwork_softirq; static int process_softirq_raise_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1046,13 +1030,12 @@ static int process_softirq_raise_event(const struct perf_tool *tool, if (kwork->tp_handler->raise_event) return kwork->tp_handler->raise_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); return 0; } static int process_softirq_entry_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1060,13 +1043,12 @@ static int process_softirq_entry_event(const struct perf_tool *tool, if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); return 0; } static int process_softirq_exit_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1074,7 +1056,7 @@ static int process_softirq_exit_event(const struct perf_tool *tool, if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); return 0; } @@ -1133,7 +1115,6 @@ static void softirq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1148,7 +1129,7 @@ static void softirq_work_init(struct perf_kwork *kwork, } else { num = perf_sample__intval(sample, "vec"); work->id = num; - work->name = evsel__softirq_name(evsel, num); + work->name = evsel__softirq_name(sample->evsel, num); } } @@ -1169,7 +1150,6 @@ static struct kwork_class kwork_softirq = { static struct kwork_class kwork_workqueue; static int process_workqueue_activate_work_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1177,13 +1157,12 @@ static int process_workqueue_activate_work_event(const struct perf_tool *tool, if (kwork->tp_handler->raise_event) return kwork->tp_handler->raise_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); return 0; } static int process_workqueue_execute_start_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1191,13 +1170,12 @@ static int process_workqueue_execute_start_event(const struct perf_tool *tool, if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); return 0; } static int process_workqueue_execute_end_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1205,7 +1183,7 @@ static int process_workqueue_execute_end_event(const struct perf_tool *tool, if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); return 0; } @@ -1233,7 +1211,6 @@ static void workqueue_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1267,7 +1244,6 @@ static struct kwork_class kwork_workqueue = { static struct kwork_class kwork_sched; static int process_sched_switch_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1275,7 +1251,7 @@ static int process_sched_switch_event(const struct perf_tool *tool, if (kwork->tp_handler->sched_switch_event) return kwork->tp_handler->sched_switch_event(kwork, &kwork_sched, - evsel, sample, machine); + sample, machine); return 0; } @@ -1300,7 +1276,6 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1946,7 +1921,6 @@ static int perf_kwork__report(struct perf_kwork *kwork) } typedef int (*tracepoint_handler)(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -1961,7 +1935,7 @@ static int perf_kwork__process_tracepoint_sample(const struct perf_tool *tool, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(tool, evsel, sample, machine); + err = f(tool, sample, machine); } return err; diff --git a/tools/perf/util/kwork.h b/tools/perf/util/kwork.h index db00269b73f2..abf637d44794 100644 --- a/tools/perf/util/kwork.h +++ b/tools/perf/util/kwork.h @@ -157,7 +157,6 @@ struct kwork_class { struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -167,19 +166,19 @@ struct kwork_class { struct trace_kwork_handler { int (*raise_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); int (*entry_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); int (*exit_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); int (*sched_switch_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); }; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 19/25] perf sched: Don't pass evsel with sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (17 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 18/25] perf kwork: " Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 20/25] perf timechart: " Ian Rogers ` (6 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-sched.c | 92 ++++++++++++++------------------------ 1 file changed, 34 insertions(+), 58 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 854e29bbd6a9..ad397c6766a2 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -129,21 +129,20 @@ typedef int (*sort_fn_t)(struct work_atoms *, struct work_atoms *); struct perf_sched; struct trace_sched_handler { - int (*switch_event)(struct perf_sched *sched, struct evsel *evsel, - struct perf_sample *sample, struct machine *machine); + int (*switch_event)(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine); - int (*runtime_event)(struct perf_sched *sched, struct evsel *evsel, - struct perf_sample *sample, struct machine *machine); + int (*runtime_event)(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine); - int (*wakeup_event)(struct perf_sched *sched, struct evsel *evsel, - struct perf_sample *sample, struct machine *machine); + int (*wakeup_event)(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine); /* PERF_RECORD_FORK event, not sched_process_fork tracepoint */ int (*fork_event)(struct perf_sched *sched, union perf_event *event, struct machine *machine); int (*migrate_task_event)(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); }; @@ -826,7 +825,7 @@ static void test_calibrations(struct perf_sched *sched) static int replay_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, + struct perf_sample *sample, struct machine *machine __maybe_unused) { const char *comm = perf_sample__strval(sample, "comm"); @@ -834,7 +833,7 @@ replay_wakeup_event(struct perf_sched *sched, struct task_desc *waker, *wakee; if (verbose > 0) { - printf("sched_wakeup event %p\n", evsel); + printf("sched_wakeup event %p\n", sample->evsel); printf(" ... pid %d woke up %s/%d\n", sample->tid, comm, pid); } @@ -847,7 +846,6 @@ replay_wakeup_event(struct perf_sched *sched, } static int replay_switch_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -861,7 +859,7 @@ static int replay_switch_event(struct perf_sched *sched, s64 delta; if (verbose > 0) - printf("sched_switch event %p\n", evsel); + printf("sched_switch event %p\n", sample->evsel); if (cpu >= MAX_CPUS || cpu < 0) return 0; @@ -1134,7 +1132,6 @@ static void free_work_atoms(struct work_atoms *atoms) } static int latency_switch_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1204,7 +1201,6 @@ static int latency_switch_event(struct perf_sched *sched, } static int latency_runtime_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1239,7 +1235,6 @@ static int latency_runtime_event(struct perf_sched *sched, } static int latency_wakeup_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1300,7 +1295,6 @@ static int latency_wakeup_event(struct perf_sched *sched, } static int latency_migrate_task_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1519,20 +1513,18 @@ static void perf_sched__sort_lat(struct perf_sched *sched) } static int process_sched_wakeup_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); if (sched->tp_handler->wakeup_event) - return sched->tp_handler->wakeup_event(sched, evsel, sample, machine); + return sched->tp_handler->wakeup_event(sched, sample, machine); return 0; } static int process_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused) { @@ -1626,8 +1618,8 @@ static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu, } } -static int map_switch_event(struct perf_sched *sched, struct evsel *evsel __maybe_unused, - struct perf_sample *sample, struct machine *machine) +static int map_switch_event(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine) { const u32 next_pid = perf_sample__intval(sample, "next_pid"); const u32 prev_pid = perf_sample__intval(sample, "prev_pid"); @@ -1791,7 +1783,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel __mayb } static int process_sched_switch_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1810,21 +1801,20 @@ static int process_sched_switch_event(const struct perf_tool *tool, } if (sched->tp_handler->switch_event) - err = sched->tp_handler->switch_event(sched, evsel, sample, machine); + err = sched->tp_handler->switch_event(sched, sample, machine); sched->curr_pid[this_cpu] = next_pid; return err; } static int process_sched_runtime_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); if (sched->tp_handler->runtime_event) - return sched->tp_handler->runtime_event(sched, evsel, sample, machine); + return sched->tp_handler->runtime_event(sched, sample, machine); return 0; } @@ -1847,20 +1837,18 @@ static int perf_sched__process_fork_event(const struct perf_tool *tool, } static int process_sched_migrate_task_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); if (sched->tp_handler->migrate_task_event) - return sched->tp_handler->migrate_task_event(sched, evsel, sample, machine); + return sched->tp_handler->migrate_task_event(sched, sample, machine); return 0; } typedef int (*tracepoint_handler)(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -1874,7 +1862,7 @@ static int perf_sched__process_tracepoint_sample(const struct perf_tool *tool __ if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(tool, evsel, sample, machine); + err = f(tool, sample, machine); } return err; @@ -2313,11 +2301,10 @@ static void timehist_update_runtime_stats(struct thread_runtime *r, r->total_pre_mig_time += r->dt_pre_mig; } -static bool is_idle_sample(struct perf_sample *sample, - struct evsel *evsel) +static bool is_idle_sample(struct perf_sample *sample) { /* pid 0 == swapper == idle task */ - if (evsel__name_is(evsel, "sched:sched_switch")) + if (evsel__name_is(sample->evsel, "sched:sched_switch")) return perf_sample__intval(sample, "prev_pid") == 0; return sample->pid == 0; @@ -2499,12 +2486,11 @@ static void save_idle_callchain(struct perf_sched *sched, static struct thread *timehist_get_thread(struct perf_sched *sched, struct perf_sample *sample, - struct machine *machine, - struct evsel *evsel) + struct machine *machine) { struct thread *thread; - if (is_idle_sample(sample, evsel)) { + if (is_idle_sample(sample)) { thread = get_idle_thread(sample->cpu); if (thread == NULL) pr_err("Failed to get idle thread for cpu %d.\n", sample->cpu); @@ -2547,7 +2533,6 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, static bool timehist_skip_sample(struct perf_sched *sched, struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { bool rc = false; @@ -2569,7 +2554,7 @@ static bool timehist_skip_sample(struct perf_sched *sched, tr = thread__get_runtime(thread); if (tr && tr->prio != -1) prio = tr->prio; - else if (evsel__name_is(evsel, "sched:sched_switch")) + else if (evsel__name_is(sample->evsel, "sched:sched_switch")) prio = perf_sample__intval(sample, "prev_prio"); if (prio != -1 && !test_bit(prio, sched->prio_bitmap)) { @@ -2579,7 +2564,7 @@ static bool timehist_skip_sample(struct perf_sched *sched, } if (sched->idle_hist) { - if (!evsel__name_is(evsel, "sched:sched_switch")) + if (!evsel__name_is(sample->evsel, "sched:sched_switch")) rc = true; else if (perf_sample__intval(sample, "prev_pid") != 0 && perf_sample__intval(sample, "next_pid") != 0) @@ -2590,7 +2575,6 @@ static bool timehist_skip_sample(struct perf_sched *sched, } static void timehist_print_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct thread *awakened) @@ -2603,8 +2587,8 @@ static void timehist_print_wakeup_event(struct perf_sched *sched, return; /* show wakeup unless both awakee and awaker are filtered */ - if (timehist_skip_sample(sched, thread, evsel, sample) && - timehist_skip_sample(sched, awakened, evsel, sample)) { + if (timehist_skip_sample(sched, thread, sample) && + timehist_skip_sample(sched, awakened, sample)) { thread__put(thread); return; } @@ -2628,7 +2612,6 @@ static void timehist_print_wakeup_event(struct perf_sched *sched, static int timehist_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused) { @@ -2637,7 +2620,6 @@ static int timehist_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unu static int timehist_sched_wakeup_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2663,14 +2645,13 @@ static int timehist_sched_wakeup_event(const struct perf_tool *tool, /* show wakeups if requested */ if (sched->show_wakeups && !perf_time__skip_sample(&sched->ptime, sample->time)) - timehist_print_wakeup_event(sched, evsel, sample, machine, thread); + timehist_print_wakeup_event(sched, sample, machine, thread); thread__put(thread); return 0; } static void timehist_print_migration_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct thread *migrated) @@ -2691,8 +2672,8 @@ static void timehist_print_migration_event(struct perf_sched *sched, if (thread == NULL) return; - if (timehist_skip_sample(sched, thread, evsel, sample) && - timehist_skip_sample(sched, migrated, evsel, sample)) { + if (timehist_skip_sample(sched, thread, sample) && + timehist_skip_sample(sched, migrated, sample)) { thread__put(thread); return; } @@ -2726,7 +2707,6 @@ static void timehist_print_migration_event(struct perf_sched *sched, static int timehist_migrate_task_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2751,8 +2731,7 @@ static int timehist_migrate_task_event(const struct perf_tool *tool, /* show migrations if requested */ if (sched->show_migrations) { - timehist_print_migration_event(sched, evsel, sample, - machine, thread); + timehist_print_migration_event(sched, sample, machine, thread); } thread__put(thread); @@ -2784,7 +2763,6 @@ static void timehist_update_task_prio(struct perf_sample *sample, static int timehist_sched_change_event(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2808,13 +2786,13 @@ static int timehist_sched_change_event(const struct perf_tool *tool, if (sched->show_prio || sched->prio_str) timehist_update_task_prio(sample, machine); - thread = timehist_get_thread(sched, sample, machine, evsel); + thread = timehist_get_thread(sched, sample, machine); if (thread == NULL) { rc = -1; goto out; } - if (timehist_skip_sample(sched, thread, evsel, sample)) + if (timehist_skip_sample(sched, thread, sample)) goto out; tr = thread__get_runtime(thread); @@ -2823,7 +2801,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, goto out; } - tprev = evsel__get_time(evsel, sample->cpu); + tprev = evsel__get_time(sample->evsel, sample->cpu); /* * If start time given: @@ -2913,7 +2891,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, tr->migrated = 0; } - evsel__save_time(evsel, sample->time, sample->cpu); + evsel__save_time(sample->evsel, sample->time, sample->cpu); thread__put(thread); addr_location__exit(&al); @@ -2922,11 +2900,10 @@ static int timehist_sched_change_event(const struct perf_tool *tool, static int timehist_sched_switch_event(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { - return timehist_sched_change_event(tool, event, evsel, sample, machine); + return timehist_sched_change_event(tool, event, sample, machine); } static int process_lost(const struct perf_tool *tool __maybe_unused, @@ -3174,7 +3151,6 @@ static void timehist_print_summary(struct perf_sched *sched, typedef int (*sched_handler)(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -3196,7 +3172,7 @@ static int perf_timehist__process_sample(const struct perf_tool *tool, if (evsel->handler != NULL) { sched_handler f = evsel->handler; - err = f(tool, event, evsel, sample, machine); + err = f(tool, event, sample, machine); } return err; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 20/25] perf timechart: Don't pass evsel with sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (18 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 19/25] perf sched: " Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 21/25] perf trace: " Ian Rogers ` (5 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-timechart.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 034e0ba3f9cb..de551c9d3053 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -567,7 +567,6 @@ static const char *cat_backtrace(union perf_event *event, } typedef int (*tracepoint_handler)(struct timechart *tchart, - struct evsel *evsel, struct perf_sample *sample, const char *backtrace); @@ -588,7 +587,7 @@ static int process_sample_event(const struct perf_tool *tool, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - return f(tchart, evsel, sample, + return f(tchart, sample, cat_backtrace(event, sample, machine)); } @@ -597,7 +596,6 @@ static int process_sample_event(const struct perf_tool *tool, static int process_sample_cpu_idle(struct timechart *tchart __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -613,7 +611,6 @@ process_sample_cpu_idle(struct timechart *tchart __maybe_unused, static int process_sample_cpu_frequency(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -626,7 +623,6 @@ process_sample_cpu_frequency(struct timechart *tchart, static int process_sample_sched_wakeup(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { @@ -640,7 +636,6 @@ process_sample_sched_wakeup(struct timechart *tchart, static int process_sample_sched_switch(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { @@ -656,7 +651,6 @@ process_sample_sched_switch(struct timechart *tchart, #ifdef SUPPORT_OLD_POWER_EVENTS static int process_sample_power_start(struct timechart *tchart __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -669,7 +663,6 @@ process_sample_power_start(struct timechart *tchart __maybe_unused, static int process_sample_power_end(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -679,7 +672,6 @@ process_sample_power_end(struct timechart *tchart, static int process_sample_power_frequency(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -849,7 +841,6 @@ static int pid_end_io_sample(struct timechart *tchart, int pid, int type, static int process_enter_read(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long fd = perf_sample__intval(sample, "fd"); @@ -859,7 +850,6 @@ process_enter_read(struct timechart *tchart, static int process_exit_read(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long ret = perf_sample__intval(sample, "ret"); @@ -869,7 +859,6 @@ process_exit_read(struct timechart *tchart, static int process_enter_write(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long fd = perf_sample__intval(sample, "fd"); @@ -879,7 +868,6 @@ process_enter_write(struct timechart *tchart, static int process_exit_write(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long ret = perf_sample__intval(sample, "ret"); @@ -889,7 +877,6 @@ process_exit_write(struct timechart *tchart, static int process_enter_sync(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long fd = perf_sample__intval(sample, "fd"); @@ -899,7 +886,6 @@ process_enter_sync(struct timechart *tchart, static int process_exit_sync(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long ret = perf_sample__intval(sample, "ret"); @@ -909,7 +895,6 @@ process_exit_sync(struct timechart *tchart, static int process_enter_tx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long fd = perf_sample__intval(sample, "fd"); @@ -919,7 +904,6 @@ process_enter_tx(struct timechart *tchart, static int process_exit_tx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long ret = perf_sample__intval(sample, "ret"); @@ -929,7 +913,6 @@ process_exit_tx(struct timechart *tchart, static int process_enter_rx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long fd = perf_sample__intval(sample, "fd"); @@ -939,7 +922,6 @@ process_enter_rx(struct timechart *tchart, static int process_exit_rx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long ret = perf_sample__intval(sample, "ret"); @@ -949,7 +931,6 @@ process_exit_rx(struct timechart *tchart, static int process_enter_poll(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long fd = perf_sample__intval(sample, "fd"); @@ -959,7 +940,6 @@ process_enter_poll(struct timechart *tchart, static int process_exit_poll(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample) { long ret = perf_sample__intval(sample, "ret"); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 21/25] perf trace: Don't pass evsel with sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (19 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 20/25] perf timechart: " Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 22/25] perf evlist: Try to avoid computing evsel from sample Ian Rogers ` (4 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. In trace__handle_event try to use the evsel from the sample to avoid recomputation. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-trace.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 385a9ac2ae96..c4ec4f603d5f 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2580,7 +2580,7 @@ static struct syscall *trace__find_syscall(struct trace *trace, int e_machine, i return sc; } -typedef int (*tracepoint_handler)(struct trace *trace, struct evsel *evsel, +typedef int (*tracepoint_handler)(struct trace *trace, union perf_event *event, struct perf_sample *sample); @@ -2775,10 +2775,11 @@ static void *syscall__augmented_args(struct syscall *sc, struct perf_sample *sam return NULL; } -static int trace__sys_enter(struct trace *trace, struct evsel *evsel, +static int trace__sys_enter(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; char *msg; void *args; int printed = 0; @@ -2921,10 +2922,11 @@ static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sam return sample__fprintf_callchain(sample, 38, print_opts, get_tls_callchain_cursor(), symbol_conf.bt_stop_list, trace->output); } -static int trace__sys_exit(struct trace *trace, struct evsel *evsel, +static int trace__sys_exit(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; long ret; u64 duration = 0; bool duration_calculated = false; @@ -3059,7 +3061,7 @@ errno_print: { return err; } -static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_unused, +static int trace__vfs_getname(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3120,7 +3122,7 @@ static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_u return 0; } -static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, +static int trace__sched_stat_runtime(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3142,7 +3144,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, out_dump: fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", - evsel->name, + sample->evsel->name, perf_sample__strval(sample, "comm"), (pid_t)perf_sample__intval(sample, "pid"), runtime, @@ -3253,10 +3255,11 @@ static size_t trace__fprintf_tp_fields(struct trace *trace, struct perf_sample * return fprintf(trace->output, "%.*s", (int)printed, bf); } -static int trace__event_handler(struct trace *trace, struct evsel *evsel, +static int trace__event_handler(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; struct thread *thread; int callchain_ret = 0; @@ -3444,7 +3447,6 @@ static int trace__pgfault(struct trace *trace, } static void trace__set_base_time(struct trace *trace, - struct evsel *evsel, struct perf_sample *sample) { /* @@ -3456,7 +3458,7 @@ static void trace__set_base_time(struct trace *trace, * appears in our event stream (vfs_getname comes to mind). */ if (trace->base_time == 0 && !trace->full_time && - (evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) + (sample->evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) trace->base_time = sample->time; } @@ -3476,11 +3478,11 @@ static int trace__process_sample(const struct perf_tool *tool, if (thread && thread__is_filtered(thread)) goto out; - trace__set_base_time(trace, evsel, sample); + trace__set_base_time(trace, sample); if (handler) { ++trace->nr_events; - handler(trace, evsel, event, sample); + handler(trace, event, sample); } out: thread__put(thread); @@ -3622,14 +3624,16 @@ static void evlist__free_syscall_tp_fields(struct evlist *evlist) static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *sample) { const u32 type = event->header.type; - struct evsel *evsel; + struct evsel *evsel = sample->evsel; if (type != PERF_RECORD_SAMPLE) { trace__process_event(trace, trace->host, event, sample); return; } - evsel = evlist__id2evsel(trace->evlist, sample->id); + if (evsel == NULL) + evsel = evlist__id2evsel(trace->evlist, sample->id); + if (evsel == NULL) { fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id); return; @@ -3638,7 +3642,7 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st if (evswitch__discard(&trace->evswitch, evsel)) return; - trace__set_base_time(trace, evsel, sample); + trace__set_base_time(trace, sample); if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT && sample->raw_data == NULL) { @@ -3647,7 +3651,7 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st sample->cpu, sample->raw_size); } else { tracepoint_handler handler = evsel->handler; - handler(trace, evsel, event, sample); + handler(trace, event, sample); } if (trace->nr_events_printed >= trace->max_events && trace->max_events != ULONG_MAX) -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 22/25] perf evlist: Try to avoid computing evsel from sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (20 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 21/25] perf trace: " Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 23/25] perf script: Don't pass evsel with sample Ian Rogers ` (3 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan If the sample has an evsel, don't recompute using the sample.id. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 5 +++-- tools/perf/builtin-top.c | 4 +++- tools/perf/tests/mmap-basic.c | 4 +++- tools/perf/tests/switch-tracking.c | 5 ++++- tools/perf/util/intel-pt.c | 10 +++++++--- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 6e265b66a551..9ea082bccbe6 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1693,11 +1693,12 @@ static int guest_session__fetch(struct guest_session *gs) static int evlist__append_id_sample(struct evlist *evlist, union perf_event *ev, const struct perf_sample *sample) { - struct evsel *evsel; + struct evsel *evsel = sample->evsel; void *array; int ret; - evsel = evlist__id2evsel(evlist, sample->id); + if (!evsel) + evsel = evlist__id2evsel(evlist, sample->id); array = ev; if (!evsel) { diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index b89ca48e5d02..faa422e35166 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1163,7 +1163,9 @@ static int deliver_event(struct ordered_events *qe, goto next_event; } - evsel = evlist__id2evsel(session->evlist, sample.id); + evsel = sample.evsel; + if (!evsel) + evsel = evlist__id2evsel(session->evlist, sample.id); assert(evsel != NULL); if (event->header.type == PERF_RECORD_SAMPLE) { diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 3313c236104e..a18d84d858aa 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -142,7 +142,9 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtest } err = -1; - evsel = evlist__id2evsel(evlist, sample.id); + evsel = sample.evsel; + if (!evsel) + evsel = evlist__id2evsel(evlist, sample.id); perf_sample__exit(&sample); if (evsel == NULL) { pr_debug("event with id %" PRIu64 diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index a7ea4b7874be..ed17c3be71c4 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -138,7 +138,10 @@ static int process_sample_event(struct evlist *evlist, goto out; } - evsel = evlist__id2evsel(evlist, sample.id); + evsel = sample.evsel; + if (!evsel) + evsel = evlist__id2evsel(evlist, sample.id); + if (evsel == switch_tracking->switch_evsel) { next_tid = perf_sample__intval(&sample, "next_pid"); prev_tid = perf_sample__intval(&sample, "prev_pid"); diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index dab23a96b1d8..3d759546a7c0 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -3421,7 +3421,10 @@ static int intel_pt_process_switch(struct intel_pt *pt, { pid_t tid; int cpu, ret; - struct evsel *evsel = evlist__id2evsel(pt->session->evlist, sample->id); + struct evsel *evsel = sample->evsel; + + if (!evsel) + evsel = evlist__id2evsel(pt->session->evlist, sample->id); if (evsel != pt->switch_evsel) return 0; @@ -3611,10 +3614,11 @@ static int intel_pt_process_aux_output_hw_id(struct intel_pt *pt, u64 hw_id = event->aux_output_hw_id.hw_id; struct auxtrace_queue *queue; struct intel_pt_queue *ptq; - struct evsel *evsel; + struct evsel *evsel = sample->evsel; queue = auxtrace_queues__sample_queue(&pt->queues, sample, pt->session); - evsel = evlist__id2evsel_strict(pt->session->evlist, sample->id); + if (!evsel) + evsel = evlist__id2evsel_strict(pt->session->evlist, sample->id); if (!queue || !queue->priv || !evsel || hw_id > INTEL_PT_MAX_PEBS) { pr_err("Bad AUX output hardware ID\n"); return -EINVAL; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 23/25] perf script: Don't pass evsel with sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (21 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 22/25] perf evlist: Try to avoid computing evsel from sample Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 24/25] perf s390-sample-raw: " Ian Rogers ` (2 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Remove the evsel from the struct scripting_context so that the sample version is always accessed. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-script.c | 12 ++++-- .../util/scripting-engines/trace-event-perl.c | 21 +++++------ .../scripting-engines/trace-event-python.c | 37 ++++++++----------- tools/perf/util/trace-event-scripting.c | 5 +-- tools/perf/util/trace-event.h | 3 -- 5 files changed, 33 insertions(+), 45 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8022801721e2..53da706d959f 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2418,12 +2418,13 @@ static bool show_event(struct perf_sample *sample, } static void process_event(struct perf_script *script, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al, struct machine *machine) { struct thread *thread = al->thread; + struct evsel *evsel = sample->evsel; struct perf_event_attr *attr = &evsel->core.attr; unsigned int type = evsel__output_type(evsel); struct evsel_script *es = evsel->priv; @@ -2714,9 +2715,9 @@ static int process_sample_event(const struct perf_tool *tool, thread__resolve(al.thread, &addr_al, sample); addr_al_ptr = &addr_al; } - scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr); + scripting_ops->process_event(event, sample, &al, addr_al_ptr); } else { - process_event(scr, sample, evsel, &al, &addr_al, machine); + process_event(scr, sample, &al, &addr_al, machine); } out_put: @@ -2892,9 +2893,12 @@ static int print_event_with_time(const struct perf_tool *tool, { struct perf_script *script = container_of(tool, struct perf_script, tool); struct perf_session *session = script->session; - struct evsel *evsel = evlist__id2evsel(session->evlist, sample->id); + struct evsel *evsel = sample->evsel; struct thread *thread = NULL; + if (!evsel) + evsel = evlist__id2evsel(session->evlist, sample->id); + if (evsel && !evsel->core.attr.sample_id_all) { sample->cpu = 0; sample->time = timestamp; diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index 850a0048df82..7a18ea4b7d50 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -257,7 +257,6 @@ static void define_event_symbols(struct tep_event *event, } static SV *perl_process_callchain(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al) { struct callchain_cursor *cursor; @@ -340,7 +339,6 @@ static SV *perl_process_callchain(struct perf_sample *sample, } static void perl_process_tracepoint(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al) { struct thread *thread = al->thread; @@ -355,6 +353,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, unsigned long long nsecs = sample->time; const char *comm = thread__comm_str(thread); DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX); + struct evsel *evsel = sample->evsel; bitmap_zero(events_defined, TRACE_EVENT_TYPE_MAX); dSP; @@ -389,7 +388,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, XPUSHs(sv_2mortal(newSVuv(ns))); XPUSHs(sv_2mortal(newSViv(pid))); XPUSHs(sv_2mortal(newSVpv(comm, 0))); - XPUSHs(sv_2mortal(perl_process_callchain(sample, evsel, al))); + XPUSHs(sv_2mortal(perl_process_callchain(sample, al))); /* common fields other than pid can be accessed via xsub fns */ @@ -426,7 +425,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, XPUSHs(sv_2mortal(newSVuv(nsecs))); XPUSHs(sv_2mortal(newSViv(pid))); XPUSHs(sv_2mortal(newSVpv(comm, 0))); - XPUSHs(sv_2mortal(perl_process_callchain(sample, evsel, al))); + XPUSHs(sv_2mortal(perl_process_callchain(sample, al))); call_pv("main::trace_unhandled", G_SCALAR); } SPAGAIN; @@ -435,9 +434,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, LEAVE; } -static void perl_process_event_generic(union perf_event *event, - struct perf_sample *sample, - struct evsel *evsel) +static void perl_process_event_generic(union perf_event *event, struct perf_sample *sample) { dSP; @@ -448,7 +445,8 @@ static void perl_process_event_generic(union perf_event *event, SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVpvn((const char *)event, event->header.size))); - XPUSHs(sv_2mortal(newSVpvn((const char *)&evsel->core.attr, sizeof(evsel->core.attr)))); + XPUSHs(sv_2mortal(newSVpvn((const char *)&sample->evsel->core.attr, + sizeof(sample->evsel->core.attr)))); XPUSHs(sv_2mortal(newSVpvn((const char *)sample, sizeof(*sample)))); XPUSHs(sv_2mortal(newSVpvn((const char *)sample->raw_data, sample->raw_size))); PUTBACK; @@ -461,13 +459,12 @@ static void perl_process_event_generic(union perf_event *event, static void perl_process_event(union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { - scripting_context__update(scripting_context, event, sample, evsel, al, addr_al); - perl_process_tracepoint(sample, evsel, al); - perl_process_event_generic(event, sample, evsel); + scripting_context__update(scripting_context, event, sample, al, addr_al); + perl_process_tracepoint(sample, al); + perl_process_event_generic(event, sample); } static void run_start_sub(void) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 9f5c6e5e6ebe..63d04b051846 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -390,7 +390,6 @@ static unsigned long get_offset(struct symbol *sym, struct addr_location *al) } static PyObject *python_process_callchain(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al) { PyObject *pylist; @@ -651,11 +650,9 @@ static PyObject *get_sample_value_as_tuple(struct sample_read_value *value, return t; } -static void set_sample_read_in_dict(PyObject *dict_sample, - struct perf_sample *sample, - struct evsel *evsel) +static void set_sample_read_in_dict(PyObject *dict_sample, struct perf_sample *sample) { - u64 read_format = evsel->core.attr.read_format; + u64 read_format = sample->evsel->core.attr.read_format; PyObject *values; unsigned int i; @@ -741,11 +738,10 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, uint16_t e_machine, static int set_regs_in_dict(PyObject *dict, struct perf_sample *sample, - struct evsel *evsel, uint16_t e_machine, uint32_t e_flags) { - struct perf_event_attr *attr = &evsel->core.attr; + struct perf_event_attr *attr = &sample->evsel->core.attr; int size = (__sw_hweight64(attr->sample_regs_intr) * MAX_REG_SIZE) + 1; char *bf = NULL; @@ -831,7 +827,6 @@ static void python_process_sample_flags(struct perf_sample *sample, PyObject *di } static PyObject *get_perf_sample_dict(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al, PyObject *callchain) @@ -839,6 +834,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, PyObject *dict, *dict_sample, *brstack, *brstacksym; uint16_t e_machine = EM_HOST; uint32_t e_flags = EF_HOST; + struct evsel *evsel = sample->evsel; dict = PyDict_New(); if (!dict) @@ -871,7 +867,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, PyLong_FromUnsignedLongLong(sample->phys_addr)); pydict_set_item_string_decref(dict_sample, "addr", PyLong_FromUnsignedLongLong(sample->addr)); - set_sample_read_in_dict(dict_sample, sample, evsel); + set_sample_read_in_dict(dict_sample, sample); pydict_set_item_string_decref(dict_sample, "weight", PyLong_FromUnsignedLongLong(sample->weight)); pydict_set_item_string_decref(dict_sample, "ins_lat", @@ -928,7 +924,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, if (al->thread) e_machine = thread__e_machine(al->thread, /*machine=*/NULL, &e_flags); - if (set_regs_in_dict(dict, sample, evsel, e_machine, e_flags)) + if (set_regs_in_dict(dict, sample, e_machine, e_flags)) Py_FatalError("Failed to setting regs in dict"); return dict; @@ -936,7 +932,6 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, #ifdef HAVE_LIBTRACEEVENT static void python_process_tracepoint(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { @@ -954,6 +949,7 @@ static void python_process_tracepoint(struct perf_sample *sample, const char *comm = thread__comm_str(al->thread); const char *default_handler_name = "trace_unhandled"; DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX); + struct evsel *evsel = sample->evsel; bitmap_zero(events_defined, TRACE_EVENT_TYPE_MAX); @@ -995,7 +991,7 @@ static void python_process_tracepoint(struct perf_sample *sample, PyTuple_SetItem(t, n++, context); /* ip unwinding */ - callchain = python_process_callchain(sample, evsel, al); + callchain = python_process_callchain(sample, al); /* Need an additional reference for the perf_sample dict */ Py_INCREF(callchain); @@ -1051,7 +1047,7 @@ static void python_process_tracepoint(struct perf_sample *sample, PyTuple_SetItem(t, n++, dict); if (get_argument_count(handler) == (int) n + 1) { - all_entries_dict = get_perf_sample_dict(sample, evsel, al, addr_al, + all_entries_dict = get_perf_sample_dict(sample, al, addr_al, callchain); PyTuple_SetItem(t, n++, all_entries_dict); } else { @@ -1070,7 +1066,6 @@ static void python_process_tracepoint(struct perf_sample *sample, } #else static void python_process_tracepoint(struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct addr_location *al __maybe_unused, struct addr_location *addr_al __maybe_unused) { @@ -1465,7 +1460,6 @@ static int python_process_call_return(struct call_return *cr, u64 *parent_db_id, } static void python_process_general_event(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { @@ -1488,8 +1482,8 @@ static void python_process_general_event(struct perf_sample *sample, Py_FatalError("couldn't create Python tuple"); /* ip unwinding */ - callchain = python_process_callchain(sample, evsel, al); - dict = get_perf_sample_dict(sample, evsel, al, addr_al, callchain); + callchain = python_process_callchain(sample, al); + dict = get_perf_sample_dict(sample, al, addr_al, callchain); PyTuple_SetItem(t, n++, dict); if (_PyTuple_Resize(&t, n) == -1) @@ -1502,24 +1496,23 @@ static void python_process_general_event(struct perf_sample *sample, static void python_process_event(union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { struct tables *tables = &tables_global; - scripting_context__update(scripting_context, event, sample, evsel, al, addr_al); + scripting_context__update(scripting_context, event, sample, al, addr_al); - switch (evsel->core.attr.type) { + switch (sample->evsel->core.attr.type) { case PERF_TYPE_TRACEPOINT: - python_process_tracepoint(sample, evsel, al, addr_al); + python_process_tracepoint(sample, al, addr_al); break; /* Reserve for future process_hw/sw/raw APIs */ default: if (tables->db_export_mode) db_export__sample(&tables->dbe, event, sample, al, addr_al); else - python_process_general_event(sample, evsel, al, addr_al); + python_process_general_event(sample, al, addr_al); } } diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c index fa850e44cb46..dc584ac316a3 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -103,12 +103,11 @@ int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec) void scripting_context__update(struct scripting_context *c, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { #ifdef HAVE_LIBTRACEEVENT - const struct tep_event *tp_format = evsel__tp_format(evsel); + const struct tep_event *tp_format = evsel__tp_format(sample->evsel); c->pevent = tp_format ? tp_format->tep : NULL; #else @@ -117,7 +116,6 @@ void scripting_context__update(struct scripting_context *c, c->event_data = sample->raw_data; c->event = event; c->sample = sample; - c->evsel = evsel; c->al = al; c->addr_al = addr_al; } @@ -134,7 +132,6 @@ static int stop_script_unsupported(void) static void process_event_unsupported(union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct addr_location *al __maybe_unused, struct addr_location *addr_al __maybe_unused) { diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 914d9b69ed62..720121c74f1d 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -94,7 +94,6 @@ struct scripting_ops { int (*stop_script) (void); void (*process_event) (union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al); void (*process_switch)(union perf_event *event, @@ -124,7 +123,6 @@ struct scripting_context { void *event_data; union perf_event *event; struct perf_sample *sample; - struct evsel *evsel; struct addr_location *al; struct addr_location *addr_al; struct perf_session *session; @@ -133,7 +131,6 @@ struct scripting_context { void scripting_context__update(struct scripting_context *scripting_context, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 24/25] perf s390-sample-raw: Don't pass evsel with sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (22 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 23/25] perf script: Don't pass evsel with sample Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 25/25] perf evsel: " Ian Rogers 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/s390-sample-raw.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c index c6ae0ae8d86a..bfa342536b9b 100644 --- a/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -284,8 +284,9 @@ static bool s390_pai_all_test(struct perf_sample *sample) return true; } -static void s390_pai_all_dump(struct evsel *evsel, struct perf_sample *sample) +static void s390_pai_all_dump(struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; size_t len = sample->raw_size, offset = 0; unsigned char *p = sample->raw_data; const char *color = PERF_COLOR_BLUE; @@ -332,14 +333,16 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, struct perf_sample *sample) { const char *pai_name; - struct evsel *evsel; + struct evsel *evsel = sample->evsel; if (event->header.type != PERF_RECORD_SAMPLE) return; - evsel = evlist__event2evsel(evlist, event); - if (!evsel) - return; + if (!evsel) { + evsel = evlist__event2evsel(evlist, event); + if (!evsel) + return; + } /* Check for raw data in sample */ if (!sample->raw_size || !sample->raw_data) @@ -372,6 +375,6 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, } else { if (!evsel->pmu) evsel->pmu = perf_pmus__find_by_type(evsel->core.attr.type); - s390_pai_all_dump(evsel, sample); + s390_pai_all_dump(sample); } } -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v2 25/25] perf evsel: Don't pass evsel with sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (23 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 24/25] perf s390-sample-raw: " Ian Rogers @ 2026-03-19 23:23 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-19 23:23 UTC (permalink / raw) To: acme, namhyung Cc: irogers, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Arrange for the sample to contain the evsel and so it is unnecessary to pass the evsel as well. This is done for uniformity, although parsing of the sample is arguably a special case. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/evsel.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 041766d39ec3..21602d121260 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2997,10 +2997,10 @@ 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; @@ -3239,14 +3239,14 @@ 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); + perf_evsel__parse_id_sample(event, data); return 0; } if (event->header.type != PERF_RECORD_SAMPLE) { if (evsel->core.attr.sample_id_all) - perf_evsel__parse_id_sample(evsel, event, data); + perf_evsel__parse_id_sample(event, data); return 0; } @@ -3606,12 +3606,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; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 00/25] perf tool: Add evsel to perf_sample 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers ` (24 preceding siblings ...) 2026-03-19 23:23 ` [PATCH v2 25/25] perf evsel: " Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 01/25] perf sample: Document struct perf_sample Ian Rogers ` (25 more replies) 25 siblings, 26 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Nearly all perf code ends up passing an evsel with the perf_sample, which is problematic if you want to rewrite the evsel such as with off-CPU processing - all uses of the evsel need fixing up. Previously I'd mailed this patch as an RFC with everything combined: https://lore.kernel.org/lkml/20260126071822.447368-1-irogers@google.com/ and there was a request to break it up. I've started the series by adding documentation to struct perf_sample. Next I fixed missing perf_sample__init/exit largely from the recent perf inject callchain rewriting work. The 3rd patch adds the evsel to struct perf_sample and ensures it is correctly initialized. The next 22 patches avoid passing the evsel along with sample for different parts of the perf tool, along with some minor tweaks like constification and not determining the evsel if it is present in the sample. v3: Fix various sashiko review comments particularly about unintended behavior changes. v2: Add review feedback on the first 2 patches from Namhyung, fix a missed evsel assignment running event2evsel in builtin-inject. https://lore.kernel.org/lkml/20260319232334.287517-1-irogers@google.com/ v1: https://lore.kernel.org/lkml/20260209174032.4142096-1-irogers@google.com/ Ian Rogers (25): perf sample: Document struct perf_sample perf sample: Make sure perf_sample__init/exit are used perf sample: Add evsel to struct perf_sample perf tool: Remove evsel from tool APIs that pass the sample perf kvm: Don't pass evsel with sample perf evsel: Refactor evsel__intval to perf_sample__intval perf trace: Don't pass evsel with sample perf callchain: Don't pass evsel and sample perf lock: Only pass sample to handlers perf lock: Constify trace_lock_handler variables perf hist: Remove evsel parameter from inc samples functions perf db-export: Remove evsel from struct export_sample perf hist: Remove evsel from struct hist_entry_iter perf report: Directly use sample->evsel to avoid computing from sample->id perf annotate: Don't pass evsel to add_sample perf inject: Don't pass evsel with sample perf kmem: Don't pass evsel with sample perf kwork: Don't pass evsel with sample perf sched: Don't pass evsel with sample perf timechart: Don't pass evsel with sample perf trace: Don't pass evsel with sample perf evlist: Try to avoid computing evsel from sample perf script: Don't pass evsel with sample perf s390-sample-raw: Don't pass evsel with sample perf evsel: Don't pass evsel with sample tools/perf/builtin-annotate.c | 28 ++- tools/perf/builtin-c2c.c | 6 +- tools/perf/builtin-diff.c | 5 +- tools/perf/builtin-inject.c | 83 ++++---- tools/perf/builtin-kmem.c | 69 ++++--- tools/perf/builtin-kvm.c | 22 +- tools/perf/builtin-kwork.c | 104 ++++------ tools/perf/builtin-lock.c | 117 +++++------ tools/perf/builtin-mem.c | 1 - tools/perf/builtin-record.c | 3 +- tools/perf/builtin-report.c | 38 ++-- tools/perf/builtin-sched.c | 188 ++++++++---------- tools/perf/builtin-script.c | 26 ++- tools/perf/builtin-timechart.c | 129 ++++++------ tools/perf/builtin-top.c | 19 +- tools/perf/builtin-trace.c | 103 +++++----- tools/perf/tests/hists_cumulate.c | 3 +- tools/perf/tests/hists_filter.c | 2 +- tools/perf/tests/hists_output.c | 3 +- tools/perf/tests/mmap-basic.c | 4 +- tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/tests/switch-tracking.c | 9 +- tools/perf/util/annotate.c | 19 +- tools/perf/util/annotate.h | 6 +- tools/perf/util/build-id.c | 3 +- tools/perf/util/build-id.h | 7 +- tools/perf/util/callchain.c | 9 +- tools/perf/util/callchain.h | 5 +- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data-convert-json.c | 5 +- tools/perf/util/db-export.c | 13 +- tools/perf/util/db-export.h | 3 +- tools/perf/util/evlist.c | 5 +- tools/perf/util/evsel.c | 72 ++++--- tools/perf/util/evsel.h | 12 +- tools/perf/util/hist.c | 26 +-- tools/perf/util/hist.h | 3 +- tools/perf/util/intel-pt.c | 2 +- tools/perf/util/intel-tpebs.c | 3 +- tools/perf/util/jitdump.c | 2 +- .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 19 +- .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 +- .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 +- .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 17 +- tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +- tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 +++---- tools/perf/util/kvm-stat.c | 19 +- tools/perf/util/kvm-stat.h | 18 +- tools/perf/util/kwork.h | 9 +- tools/perf/util/machine.c | 14 +- tools/perf/util/machine.h | 3 - tools/perf/util/powerpc-vpadtl.c | 10 +- tools/perf/util/s390-sample-raw.c | 15 +- tools/perf/util/sample.c | 11 +- tools/perf/util/sample.h | 119 ++++++++++- .../util/scripting-engines/trace-event-perl.c | 23 +-- .../scripting-engines/trace-event-python.c | 47 ++--- tools/perf/util/session.c | 74 ++++--- tools/perf/util/synthetic-events.c | 9 +- tools/perf/util/synthetic-events.h | 2 - tools/perf/util/tool.c | 4 +- tools/perf/util/tool.h | 4 +- tools/perf/util/trace-event-scripting.c | 5 +- tools/perf/util/trace-event.h | 3 - 64 files changed, 861 insertions(+), 849 deletions(-) -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply [flat|nested] 112+ messages in thread
* [PATCH v3 01/25] perf sample: Document struct perf_sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers ` (24 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Add kernel-doc for struct perf_sample capturing the somewhat unusual population of fields and lifetime relationships. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/sample.h | 109 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 3cce8dd202aa..8d4ace0e6594 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -81,47 +81,148 @@ struct simd_flags { #define SIMD_OP_FLAGS_PRED_PARTIAL 0x01 /* partial predicate */ #define SIMD_OP_FLAGS_PRED_EMPTY 0x02 /* empty predicate */ +/** + * struct perf_sample + * + * A sample is generally filled in by evlist__parse_sample/evsel__parse_sample + * which fills in the variables from a "union perf_event *event" which is data + * from a perf ring buffer or perf.data file. The "event" sample is variable in + * length as determined by the perf_event_attr (in the evsel) and details within + * the sample event itself. A struct perf_sample avoids needing to care about + * the variable length nature of the original event. + * + * To avoid being excessively large parts of the struct perf_sample are pointers + * into the original sample event. In general the lifetime of a struct + * perf_sample needs to be less than the "union perf_event *event" it was + * derived from. + * + * The struct regs_dump user_regs and intr_regs are lazily allocated again for + * size reasons, due to them holding a cache of looked up registers. The + * function pair of perf_sample__init and perf_sample__exit correctly initialize + * and clean up these values. + */ struct perf_sample { + /** @ip: The sample event PERF_SAMPLE_IP value. */ u64 ip; - u32 pid, tid; + /** @pid: The sample event PERF_SAMPLE_TID pid value. */ + u32 pid; + /** @tid: The sample event PERF_SAMPLE_TID tid value. */ + u32 tid; + /** @time: The sample event PERF_SAMPLE_TIME value. */ u64 time; + /** @addr: The sample event PERF_SAMPLE_ADDR value. */ u64 addr; + /** @id: The sample event PERF_SAMPLE_ID value. */ u64 id; + /** @stream_id: The sample event PERF_SAMPLE_STREAM_ID value. */ u64 stream_id; + /** @period: The sample event PERF_SAMPLE_PERIOD value. */ u64 period; + /** @weight: Data determined by PERF_SAMPLE_WEIGHT or PERF_SAMPLE_WEIGHT_STRUCT. */ u64 weight; + /** @transaction: The sample event PERF_SAMPLE_TRANSACTION value. */ u64 transaction; + /** @insn_cnt: Filled in and used by intel-pt. */ u64 insn_cnt; + /** @cyc_cnt: Filled in and used by intel-pt. */ u64 cyc_cnt; + /** @cpu: The sample event PERF_SAMPLE_CPU value. */ u32 cpu; + /** + * @raw_size: The size in bytes of raw data from PERF_SAMPLE_RAW. For + * alignment reasons this should always be sizeof(u32) + * followed by a multiple of sizeof(u64). + */ u32 raw_size; + /** @data_src: The sample event PERF_SAMPLE_DATA_SRC value. */ u64 data_src; + /** @phys_addr: The sample event PERF_SAMPLE_PHYS_ADDR value. */ u64 phys_addr; + /** @data_page_size: The sample event PERF_SAMPLE_DATA_PAGE_SIZE value. */ u64 data_page_size; + /** @code_page_size: The sample event PERF_SAMPLE_CODE_PAGE_SIZE value. */ u64 code_page_size; + /** @cgroup: The sample event PERF_SAMPLE_CGROUP value. */ u64 cgroup; + /** @flags: Extra flag data from auxiliary events like intel-pt. */ u32 flags; + /** @machine_pid: The guest machine pid derived from the sample id. */ u32 machine_pid; + /** @vcpu: The guest machine vcpu derived from the sample id. */ u32 vcpu; + /** + * @insn_len: Instruction length from auxiliary events like + * intel-pt. The instruction itself is held in insn. + */ u16 insn_len; + /** + * @cpumode: The cpumode from struct perf_event_header misc variable + * masked with CPUMODE_MASK. Gives user, kernel and hypervisor + * information. + */ u8 cpumode; + /** @misc: The entire struct perf_event_header misc variable. */ u16 misc; + /** + * @ins_lat: Instruction latency information from weight2 in + * PERF_SAMPLE_WEIGHT_STRUCT or auxiliary events like + * intel-pt. + */ u16 ins_lat; - /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */ + /** + * @weight3: From PERF_SAMPLE_WEIGHT_STRUCT. On x86 holds retire_lat, on + * powerpc holds p_stage_cyc. + */ u16 weight3; - bool no_hw_idx; /* No hw_idx collected in branch_stack */ - bool deferred_callchain; /* Has deferred user callchains */ + /** + * @no_hw_idx: For PERF_SAMPLE_BRANCH_STACK, true when + * PERF_SAMPLE_BRANCH_HW_INDEX isn't set. + */ + bool no_hw_idx; + /** + * @deferred_callchain: When processing PERF_SAMPLE_CALLCHAIN a deferred + * user callchain marker was encountered. + */ + bool deferred_callchain; + /** + * @deferred_cookie: Identifier of the deferred callchain in the later + * PERF_RECORD_CALLCHAIN_DEFERRED event. + */ u64 deferred_cookie; + /** @insn: A copy of the sampled instruction filled in by perf_sample__fetch_insn. */ char insn[MAX_INSN]; + /** @raw_data: Pointer into the original event for PERF_SAMPLE_RAW data. */ void *raw_data; + /** + * @callchain: Pointer into the original event for PERF_SAMPLE_CALLCHAIN + * data. For deferred callchains this may be a copy that + * needs freeing, see sample__merge_deferred_callchain. + */ struct ip_callchain *callchain; + /** @branch_stack: Pointer into the original event for PERF_SAMPLE_BRANCH_STACK data. */ struct branch_stack *branch_stack; + /** + * @branch_stack_cntr: Pointer into the original event for + * PERF_SAMPLE_BRANCH_COUNTERS data. + */ u64 *branch_stack_cntr; + /** @user_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_USER. */ struct regs_dump *user_regs; + /** @intr_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_INTR. */ struct regs_dump *intr_regs; + /** @user_stack: Size and pointer into the sample for PERF_SAMPLE_STACK_USER. */ struct stack_dump user_stack; + /** + * @read: The sample event PERF_SAMPLE_READ counter values. The valid + * values depend on the attr.read_format PERF_FORMAT_ values. + */ struct sample_read read; + /** + * @aux_sample: Similar to raw data but with a 64-bit size and + * alignment, PERF_SAMPLE_AUX data. + */ struct aux_sample aux_sample; + /** @simd_flags: SIMD flag information from ARM SPE auxiliary events. */ struct simd_flags simd_flags; }; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 02/25] perf sample: Make sure perf_sample__init/exit are used 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 01/25] perf sample: Document struct perf_sample Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 03/25] perf sample: Add evsel to struct perf_sample Ian Rogers ` (23 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The deferred stack trace code wasn't using perf_sample__init/exit. Add the deferred stack trace clean up to perf_sample__exit which requires proper NULL initialization in perf_sample__init. Make the perf_sample__exit robust to being called more than once by using zfree. Make the error paths in evsel__parse_sample exit the sample. Add a merged_callchain boolean to capture that callchain is allocated, deferred_callchain doen't suffice for this. Pack the struct variables to avoid padding bytes for this. Similiarly powerpc_vpadtl_sample wasn't using perf_sample__init/exit, use it for consistency and potential issues with uninitialized variables. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 5 ++++- tools/perf/util/callchain.c | 1 + tools/perf/util/evlist.c | 5 ++++- tools/perf/util/evsel.c | 34 ++++++++++++++++++++------------ tools/perf/util/powerpc-vpadtl.c | 10 ++++++---- tools/perf/util/sample.c | 10 ++++++++-- tools/perf/util/sample.h | 17 ++++++++++------ tools/perf/util/session.c | 13 ++++++++---- 8 files changed, 64 insertions(+), 31 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 5b29f4296861..039323908ebf 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1087,6 +1087,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, struct perf_sample sample_sw; struct perf_inject *inject = container_of(tool, struct perf_inject, tool); u32 pid = evsel__intval(evsel, sample, "pid"); + int ret; list_for_each_entry(ent, &inject->samples, node) { if (pid == ent->tid) @@ -1103,7 +1104,9 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, evsel->core.attr.read_format, &sample_sw); build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); - return perf_event__repipe(tool, event_sw, &sample_sw, machine); + ret = perf_event__repipe(tool, event_sw, &sample_sw, machine); + perf_sample__exit(&sample_sw); + return ret; } #endif diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 8ff0898799ee..94ae45fd1f27 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1872,6 +1872,7 @@ int sample__merge_deferred_callchain(struct perf_sample *sample_orig, memcpy(&callchain->ips[nr_orig], sample_callchain->callchain->ips, nr_deferred * sizeof(u64)); + sample_orig->merged_callchain = true; sample_orig->callchain = callchain; return 0; } diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 591bdf0b3e2a..bdb196425071 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1622,8 +1622,11 @@ int evlist__parse_sample(struct evlist *evlist, union perf_event *event, struct struct evsel *evsel = evlist__event2evsel(evlist, event); int ret; - if (!evsel) + if (!evsel) { + /* Ensure the sample is okay for perf_sample__exit. */ + perf_sample__init(sample, /*all=*/false); return -EFAULT; + } ret = evsel__parse_sample(evsel, event, sample); if (ret) return ret; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f59228c1a39e..59efe460d9bc 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3067,7 +3067,7 @@ static inline bool overflow(const void *endp, u16 max_size, const void *offset, #define OVERFLOW_CHECK(offset, size, max_size) \ do { \ if (overflow(endp, (max_size), (offset), (size))) \ - return -EFAULT; \ + goto out_efault; \ } while (0) #define OVERFLOW_CHECK_u64(offset) \ @@ -3199,6 +3199,8 @@ static int __set_offcpu_sample(struct perf_sample *data) data->cgroup = *array; return 0; +out_efault: + return -EFAULT; } int evsel__parse_sample(struct evsel *evsel, union perf_event *event, @@ -3217,7 +3219,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, */ union u64_swap u; - memset(data, 0, sizeof(*data)); + perf_sample__init(data, /*all=*/true); data->cpu = data->pid = data->tid = -1; data->stream_id = data->id = data->time = -1ULL; data->period = evsel->core.attr.sample_period; @@ -3231,25 +3233,26 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->callchain = (struct ip_callchain *)&event->callchain_deferred.nr; if (data->callchain->nr > max_callchain_nr) - return -EFAULT; + goto out_efault; data->deferred_cookie = event->callchain_deferred.cookie; if (evsel->core.attr.sample_id_all) perf_evsel__parse_id_sample(evsel, event, data); + return 0; } if (event->header.type != PERF_RECORD_SAMPLE) { - if (!evsel->core.attr.sample_id_all) - return 0; - return perf_evsel__parse_id_sample(evsel, event, data); + if (evsel->core.attr.sample_id_all) + perf_evsel__parse_id_sample(evsel, event, data); + return 0; } array = event->sample.array; if (perf_event__check_size(event, evsel->sample_size)) - return -EFAULT; + goto out_efault; if (type & PERF_SAMPLE_IDENTIFIER) { data->id = *array; @@ -3342,7 +3345,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, sizeof(struct sample_read_value); if (data->read.group.nr > max_group_nr) - return -EFAULT; + goto out_efault; sz = data->read.group.nr * sample_read_value_size(read_format); OVERFLOW_CHECK(array, sz, max_size); @@ -3370,7 +3373,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->callchain = (struct ip_callchain *)array++; callchain_nr = data->callchain->nr; if (callchain_nr > max_callchain_nr) - return -EFAULT; + goto out_efault; sz = callchain_nr * sizeof(u64); /* * Save the cookie for the deferred user callchain. The last 2 @@ -3428,7 +3431,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->branch_stack = (struct branch_stack *)array++; if (data->branch_stack->nr > max_branch_nr) - return -EFAULT; + goto out_efault; sz = data->branch_stack->nr * sizeof(struct branch_entry); if (evsel__has_branch_hw_idx(evsel)) { @@ -3505,7 +3508,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->user_stack.size = *array++; if (WARN_ONCE(data->user_stack.size > sz, "user stack dump failure\n")) - return -EFAULT; + goto out_efault; } } @@ -3582,10 +3585,15 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, array = (void *)array + sz; } - if (evsel__is_offcpu_event(evsel)) - return __set_offcpu_sample(data); + if (evsel__is_offcpu_event(evsel)) { + if (__set_offcpu_sample(data)) + goto out_efault; + } return 0; +out_efault: + perf_sample__exit(data); + return -EFAULT; } int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event, diff --git a/tools/perf/util/powerpc-vpadtl.c b/tools/perf/util/powerpc-vpadtl.c index d1c3396f182f..d1c1b8a59e07 100644 --- a/tools/perf/util/powerpc-vpadtl.c +++ b/tools/perf/util/powerpc-vpadtl.c @@ -182,7 +182,9 @@ static int powerpc_vpadtl_sample(struct powerpc_vpadtl_entry *record, { struct perf_sample sample; union perf_event event; + int ret; + perf_sample__init(&sample, /*all=*/false); sample.ip = be64_to_cpu(record->srr0); sample.period = 1; sample.cpu = cpu; @@ -198,12 +200,12 @@ static int powerpc_vpadtl_sample(struct powerpc_vpadtl_entry *record, event.sample.header.misc = sample.cpumode; event.sample.header.size = sizeof(struct perf_event_header); - if (perf_session__deliver_synth_event(vpa->session, &event, &sample)) { + ret = perf_session__deliver_synth_event(vpa->session, &event, &sample); + if (ret) pr_debug("Failed to create sample for dtl entry\n"); - return -1; - } - return 0; + perf_sample__exit(&sample); + return ret; } static int powerpc_vpadtl_get_buffer(struct powerpc_vpadtl_queue *vpaq) diff --git a/tools/perf/util/sample.c b/tools/perf/util/sample.c index 8f82aaf1aab6..2a30de4573f6 100644 --- a/tools/perf/util/sample.c +++ b/tools/perf/util/sample.c @@ -21,13 +21,19 @@ void perf_sample__init(struct perf_sample *sample, bool all) } else { sample->user_regs = NULL; sample->intr_regs = NULL; + sample->merged_callchain = false; + sample->callchain = NULL; } } void perf_sample__exit(struct perf_sample *sample) { - free(sample->user_regs); - free(sample->intr_regs); + zfree(&sample->user_regs); + zfree(&sample->intr_regs); + if (sample->merged_callchain) { + zfree(&sample->callchain); + sample->merged_callchain = false; + } } struct regs_dump *perf_sample__user_regs(struct perf_sample *sample) diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 8d4ace0e6594..5809c42631e5 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -155,12 +155,6 @@ struct perf_sample { * intel-pt. The instruction itself is held in insn. */ u16 insn_len; - /** - * @cpumode: The cpumode from struct perf_event_header misc variable - * masked with CPUMODE_MASK. Gives user, kernel and hypervisor - * information. - */ - u8 cpumode; /** @misc: The entire struct perf_event_header misc variable. */ u16 misc; /** @@ -174,6 +168,12 @@ struct perf_sample { * powerpc holds p_stage_cyc. */ u16 weight3; + /** + * @cpumode: The cpumode from struct perf_event_header misc variable + * masked with CPUMODE_MASK. Gives user, kernel and hypervisor + * information. + */ + u8 cpumode; /** * @no_hw_idx: For PERF_SAMPLE_BRANCH_STACK, true when * PERF_SAMPLE_BRANCH_HW_INDEX isn't set. @@ -184,6 +184,11 @@ struct perf_sample { * user callchain marker was encountered. */ bool deferred_callchain; + /** + * @merged_callchain: A synthesized merged callchain that is allocated + * and needs freeing. + */ + bool merged_callchain; /** * @deferred_cookie: Identifier of the deferred callchain in the later * PERF_RECORD_CALLCHAIN_DEFERRED event. diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 4b465abfa36c..c48e840da7d4 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1367,14 +1367,18 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { struct perf_sample orig_sample; + perf_sample__init(&orig_sample, /*all=*/false); ret = evlist__parse_sample(evlist, de->event, &orig_sample); if (ret < 0) { pr_err("failed to parse original sample\n"); + perf_sample__exit(&orig_sample); break; } - if (sample->tid != orig_sample.tid) + if (sample->tid != orig_sample.tid) { + perf_sample__exit(&orig_sample); continue; + } if (event->callchain_deferred.cookie == orig_sample.deferred_cookie) sample__merge_deferred_callchain(&orig_sample, sample); @@ -1385,9 +1389,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, ret = evlist__deliver_sample(evlist, tool, de->event, &orig_sample, evsel, machine); - if (orig_sample.deferred_callchain) - free(orig_sample.callchain); - + perf_sample__exit(&orig_sample); list_del(&de->list); free(de->event); free(de); @@ -1414,9 +1416,11 @@ static int session__flush_deferred_samples(struct perf_session *session, list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { struct perf_sample sample; + perf_sample__init(&sample, /*all=*/false); ret = evlist__parse_sample(evlist, de->event, &sample); if (ret < 0) { pr_err("failed to parse original sample\n"); + perf_sample__exit(&sample); break; } @@ -1424,6 +1428,7 @@ static int session__flush_deferred_samples(struct perf_session *session, ret = evlist__deliver_sample(evlist, tool, de->event, &sample, evsel, machine); + perf_sample__exit(&sample); list_del(&de->list); free(de->event); free(de); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 03/25] perf sample: Add evsel to struct perf_sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 01/25] perf sample: Document struct perf_sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 04/25] perf tool: Remove evsel from tool APIs that pass the sample Ian Rogers ` (22 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Add the evsel from evsel__parse_sample into the struct perf_sample. Sometimes we want to alter the evsel associated with a sample, such as with off-cpu bpf-output events. In general the evsel and perf_sample are passed as a pair, but this makes an altered evsel something of a chore to keep checking for and setting up. Later patches will remove passing an evsel with the perf_sample and switch to just using the perf_sample's value. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 9 +++++--- tools/perf/builtin-script.c | 4 ++++ tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 1 + tools/perf/tests/hists_output.c | 2 +- tools/perf/util/evsel.c | 1 + tools/perf/util/sample.c | 1 + tools/perf/util/sample.h | 3 +++ tools/perf/util/session.c | 35 +++++++++++++++++++------------ 9 files changed, 40 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 039323908ebf..52d74542f65f 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -133,7 +133,7 @@ struct perf_inject { struct perf_file_section secs[HEADER_FEAT_BITS]; struct guest_session guest_session; struct strlist *known_build_ids; - const struct evsel *mmap_evsel; + struct evsel *mmap_evsel; struct ip_callchain *raw_callchain; }; @@ -519,7 +519,7 @@ static struct dso *findnew_dso(int pid, int tid, const char *filename, * processing mmap events. If not stashed, search the evlist for the first mmap * gathering event. */ -static const struct evsel *inject__mmap_evsel(struct perf_inject *inject) +static struct evsel *inject__mmap_evsel(struct perf_inject *inject) { struct evsel *pos; @@ -1007,6 +1007,7 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e .machine = machine, .mmap_evsel = inject__mmap_evsel(inject), }; + struct evsel *saved_evsel = sample->evsel; addr_location__init(&al); thread = machine__findnew_thread(machine, sample->pid, sample->tid); @@ -1016,6 +1017,7 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e goto repipe; } + sample->evsel = inject__mmap_evsel(inject); if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) { mark_dso_hit(inject, tool, sample, machine, args.mmap_evsel, al.map, /*sample_in_dso=*/true); @@ -1023,7 +1025,7 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, &args); - + sample->evsel = saved_evsel; thread__put(thread); repipe: perf_event__repipe(tool, event, sample, machine); @@ -1432,6 +1434,7 @@ static int synthesize_build_id(struct perf_inject *inject, struct dso *dso, pid_ { struct machine *machine = perf_session__findnew_machine(inject->session, machine_pid); struct perf_sample synth_sample = { + .evsel = inject__mmap_evsel(inject), .pid = -1, .tid = -1, .time = -1, diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index b80c406d1fc1..8c3d06a3db62 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2909,8 +2909,12 @@ static int print_event_with_time(const struct perf_tool *tool, thread = machine__findnew_thread(machine, pid, tid); if (evsel) { + struct evsel *saved_evsel = sample->evsel; + + sample->evsel = evsel; perf_sample__fprintf_start(script, sample, thread, evsel, event->header.type, stdout); + sample->evsel = saved_evsel; } perf_event__fprintf(event, machine, stdout); diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c index 3eb9ef8d7ec6..606aa926a8fc 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -81,7 +81,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) { struct addr_location al; struct evsel *evsel = hists_to_evsel(hists); - struct perf_sample sample = { .period = 1000, }; + struct perf_sample sample = { .evsel = evsel, .period = 1000, }; size_t i; addr_location__init(&al); diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c index 1cebd20cc91c..cc6b26e373d1 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -70,6 +70,7 @@ static int add_hist_entries(struct evlist *evlist, }; struct hists *hists = evsel__hists(evsel); + sample.evsel = evsel; /* make sure it has no filter at first */ hists->thread_filter = NULL; hists->dso_filter = NULL; diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c index ee5ec8bda60e..7818950d786e 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -51,7 +51,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) { struct addr_location al; struct evsel *evsel = hists_to_evsel(hists); - struct perf_sample sample = { .period = 100, }; + struct perf_sample sample = { .evsel = evsel, .period = 100, }; size_t i; addr_location__init(&al); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 59efe460d9bc..29b1df875953 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3220,6 +3220,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, union u64_swap u; perf_sample__init(data, /*all=*/true); + data->evsel = evsel; data->cpu = data->pid = data->tid = -1; data->stream_id = data->id = data->time = -1ULL; data->period = evsel->core.attr.sample_period; diff --git a/tools/perf/util/sample.c b/tools/perf/util/sample.c index 2a30de4573f6..cf73329326d7 100644 --- a/tools/perf/util/sample.c +++ b/tools/perf/util/sample.c @@ -19,6 +19,7 @@ void perf_sample__init(struct perf_sample *sample, bool all) if (all) { memset(sample, 0, sizeof(*sample)); } else { + sample->evsel = NULL; sample->user_regs = NULL; sample->intr_regs = NULL; sample->merged_callchain = false; diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 5809c42631e5..3bd6d8b60586 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -5,6 +5,7 @@ #include <linux/perf_event.h> #include <linux/types.h> +struct evsel; struct machine; struct thread; @@ -102,6 +103,8 @@ struct simd_flags { * and clean up these values. */ struct perf_sample { + /** @evsel: Backward reference to the evsel used when constructing the sample. */ + struct evsel *evsel; /** @ip: The sample event PERF_SAMPLE_IP value. */ u64 ip; /** @pid: The sample event PERF_SAMPLE_TID pid value. */ diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c48e840da7d4..3794d3a04afb 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1257,8 +1257,9 @@ static int deliver_sample_value(struct evlist *evlist, bool per_thread) { struct perf_sample_id *sid = evlist__id2sid(evlist, v->id); - struct evsel *evsel; + struct evsel *saved_evsel = sample->evsel; u64 *storage = NULL; + int ret; if (sid) { storage = perf_sample_id__get_period_storage(sid, sample->tid, per_thread); @@ -1282,8 +1283,10 @@ static int deliver_sample_value(struct evlist *evlist, if (!sample->period) return 0; - evsel = container_of(sid->evsel, struct evsel, core); - return tool->sample(tool, event, sample, evsel, machine); + sample->evsel = container_of(sid->evsel, struct evsel, core); + ret = tool->sample(tool, event, sample, sample->evsel, machine); + sample->evsel = saved_evsel; + return ret; } static int deliver_sample_group(struct evlist *evlist, @@ -1355,13 +1358,16 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, struct machine *machine) { struct deferred_event *de, *tmp; - struct evsel *evsel; int ret = 0; if (!tool->merge_deferred_callchains) { - evsel = evlist__id2evsel(evlist, sample->id); - return tool->callchain_deferred(tool, event, sample, - evsel, machine); + struct evsel *saved_evsel = sample->evsel; + + sample->evsel = evlist__id2evsel(evlist, sample->id); + ret = tool->callchain_deferred(tool, event, sample, + sample->evsel, machine); + sample->evsel = saved_evsel; + return ret; } list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { @@ -1385,9 +1391,9 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, else orig_sample.deferred_callchain = false; - evsel = evlist__id2evsel(evlist, orig_sample.id); + orig_sample.evsel = evlist__id2evsel(evlist, orig_sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &orig_sample, evsel, machine); + &orig_sample, orig_sample.evsel, machine); perf_sample__exit(&orig_sample); list_del(&de->list); @@ -1410,7 +1416,6 @@ static int session__flush_deferred_samples(struct perf_session *session, struct evlist *evlist = session->evlist; struct machine *machine = &session->machines.host; struct deferred_event *de, *tmp; - struct evsel *evsel; int ret = 0; list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { @@ -1424,9 +1429,9 @@ static int session__flush_deferred_samples(struct perf_session *session, break; } - evsel = evlist__id2evsel(evlist, sample.id); + sample.evsel = evlist__id2evsel(evlist, sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &sample, evsel, machine); + &sample, sample.evsel, machine); perf_sample__exit(&sample); list_del(&de->list); @@ -1451,8 +1456,12 @@ static int machines__deliver_event(struct machines *machines, dump_event(evlist, event, file_offset, sample, file_path); - evsel = evlist__id2evsel(evlist, sample->id); + if (!sample->evsel) + sample->evsel = evlist__id2evsel(evlist, sample->id); + else + assert(sample->evsel == evlist__id2evsel(evlist, sample->id)); + evsel = sample->evsel; machine = machines__find_for_cpumode(machines, event, sample); switch (event->header.type) { -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 04/25] perf tool: Remove evsel from tool APIs that pass the sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (2 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 03/25] perf sample: Add evsel to struct perf_sample Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 05/25] perf kvm: Don't pass evsel with sample Ian Rogers ` (21 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Now struct perf_sample has the evsel within it there is no need to pass the evsel along with the sample. In the called functions read the sample's evsel in to a variable if there are multiple uses, or use directly if there is just one use - the goal being to leave the code with as little change as possible. Some functions only use the evsel to pass to another function which they also pass the sample, in those cases just pass the sample and get the evsel in the called function. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 3 +-- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-inject.c | 19 ++++++--------- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 5 ++-- tools/perf/builtin-kwork.c | 2 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-mem.c | 1 - tools/perf/builtin-record.c | 3 +-- tools/perf/builtin-report.c | 10 +++----- tools/perf/builtin-sched.c | 4 +-- tools/perf/builtin-script.c | 4 +-- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/build-id.c | 3 +-- tools/perf/util/build-id.h | 7 +----- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data-convert-json.c | 5 ++-- tools/perf/util/intel-tpebs.c | 3 +-- tools/perf/util/jitdump.c | 2 +- tools/perf/util/session.c | 38 ++++++++++++++--------------- tools/perf/util/tool.c | 4 +-- tools/perf/util/tool.h | 4 +-- 24 files changed, 55 insertions(+), 76 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 686ad08561d6..c97a0fe159f8 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -284,7 +284,6 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool); @@ -303,7 +302,7 @@ static int process_sample_event(const struct perf_tool *tool, goto out_put; if (!al.filtered && - evsel__add_sample(evsel, sample, &al, ann, machine)) { + evsel__add_sample(sample->evsel, sample, &al, ann, machine)) { pr_warning("problem incrementing symbol count, " "skipping event\n"); ret = -1; diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index d390ae4e3ec8..89456ba6fcbb 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -314,9 +314,9 @@ static void perf_c2c__evsel_hists_inc_stats(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; struct c2c_hists *c2c_hists = &c2c.hists; struct c2c_hist_entry *c2c_he; struct c2c_stats stats = { .nr_entries = 0, }; diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 69069926dd0b..096adc65451c 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -390,11 +390,11 @@ struct hist_entry_ops block_hist_ops = { static int diff__process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_diff *pdiff = container_of(tool, struct perf_diff, tool); struct addr_location al; + struct evsel *evsel = sample->evsel; struct hists *hists = evsel__hists(evsel); struct hist_entry_iter iter = { .evsel = evsel, diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 52d74542f65f..4912ae92473a 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -363,18 +363,17 @@ typedef int (*inject_handler)(const struct perf_tool *tool, static int perf_event__repipe_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { - struct perf_inject *inject = container_of(tool, struct perf_inject, - tool); + struct perf_inject *inject = container_of(tool, struct perf_inject, tool); + struct evsel *evsel = sample->evsel; if (evsel && evsel->handler) { inject_handler f = evsel->handler; return f(tool, event, sample, evsel, machine); } - build_id__mark_dso_hit(tool, event, sample, evsel, machine); + build_id__mark_dso_hit(tool, event, sample, machine); if (inject->itrace_synth_opts.set && sample->aux_sample.size) { event = perf_inject__cut_auxtrace_sample(inject, event, sample); @@ -388,10 +387,10 @@ static int perf_event__repipe_sample(const struct perf_tool *tool, static int perf_event__convert_sample_callchain(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); + struct evsel *evsel = sample->evsel; struct callchain_cursor *cursor = get_tls_callchain_cursor(); union perf_event *event_copy = (void *)inject->event_copy; struct callchain_cursor_node *node; @@ -988,10 +987,8 @@ static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data) args->mmap_evsel, map, /*sample_in_dso=*/false); } -int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, - struct perf_sample *sample, - struct evsel *evsel __maybe_unused, - struct machine *machine) +static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, + struct perf_sample *sample, struct machine *machine) { struct addr_location al; struct thread *thread; @@ -1023,7 +1020,7 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e /*sample_in_dso=*/true); } - sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, &args); sample->evsel = saved_evsel; thread__put(thread); @@ -1105,7 +1102,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, sample_sw.time = sample->time; perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, evsel->core.attr.read_format, &sample_sw); - build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); + build_id__mark_dso_hit(tool, event_sw, &sample_sw, machine); ret = perf_event__repipe(tool, event_sw, &sample_sw, machine); perf_sample__exit(&sample_sw); return ret; diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 7929a5fa5f46..34852a4c3fc8 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -960,9 +960,9 @@ typedef int (*tracepoint_handler)(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; struct thread *thread = machine__findnew_thread(machine, sample->pid, sample->tid); diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 0c5e6b3aac74..5e8e6fde097a 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -941,9 +941,9 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, static bool handle_kvm_event(struct perf_kvm_stat *kvm, struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; struct vcpu_event_record *vcpu_record; struct event_key key = { .key = INVALID_KEY, .exit_reasons = kvm->exit_reasons }; @@ -1133,7 +1133,6 @@ static bool skip_sample(struct perf_kvm_stat *kvm, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { int err = 0; @@ -1156,7 +1155,7 @@ static int process_sample_event(const struct perf_tool *tool, return -1; } - if (!handle_kvm_event(kvm, thread, evsel, sample)) + if (!handle_kvm_event(kvm, thread, sample)) err = -1; thread__put(thread); diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 6f94a8f45f60..e34a1f35439e 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1955,9 +1955,9 @@ typedef int (*tracepoint_handler)(const struct perf_tool *tool, static int perf_kwork__process_tracepoint_sample(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; if (evsel->handler != NULL) { diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index e8962c985d34..dc8d1d3b4cd7 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1430,9 +1430,9 @@ typedef int (*tracepoint_handler)(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; struct thread *thread = machine__findnew_thread(machine, sample->pid, sample->tid); diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index d43500b92a7b..6101a26b3a78 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -255,7 +255,6 @@ dump_raw_samples(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine) { return dump_raw_samples(tool, event, sample, machine); diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 40917a0be238..09d6af344f3e 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1488,7 +1488,6 @@ static void set_timestamp_boundary(struct record *rec, u64 sample_time) static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct record *rec = container_of(tool, struct record, tool); @@ -1499,7 +1498,7 @@ static int process_sample_event(const struct perf_tool *tool, return 0; rec->samples++; - return build_id__mark_dso_hit(tool, event, sample, evsel, machine); + return build_id__mark_dso_hit(tool, event, sample, machine); } static int process_buildids(struct record *rec) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 343c0ada5ea1..507002cbdd5b 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -269,10 +269,10 @@ static int process_feature_event(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct report *rep = container_of(tool, struct report, tool); + struct evsel *evsel = sample->evsel; struct addr_location al; struct hist_entry_iter iter = { .evsel = evsel, @@ -349,7 +349,6 @@ static int process_sample_event(const struct perf_tool *tool, static int process_read_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct report *rep = container_of(tool, struct report, tool); @@ -357,7 +356,7 @@ static int process_read_event(const struct perf_tool *tool, if (rep->show_threads) { int err = perf_read_values_add_value(&rep->show_threads_values, event->read.pid, event->read.tid, - evsel, + sample->evsel, event->read.value); if (err) @@ -783,11 +782,10 @@ static void report__output_resort(struct report *rep) static int count_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, - struct perf_sample *sample __maybe_unused, - struct evsel *evsel, + struct perf_sample *sample, struct machine *machine __maybe_unused) { - struct hists *hists = evsel__hists(evsel); + struct hists *hists = evsel__hists(sample->evsel); hists__inc_nr_events(hists); return 0; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index d083e2bb7703..296b9837278a 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -1867,9 +1867,9 @@ typedef int (*tracepoint_handler)(const struct perf_tool *tool, static int perf_sched__process_tracepoint_sample(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; if (evsel->handler != NULL) { @@ -3184,10 +3184,10 @@ typedef int (*sched_handler)(const struct perf_tool *tool, static int perf_timehist__process_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); + struct evsel *evsel = sample->evsel; int err = 0; struct perf_cpu this_cpu = { .cpu = sample->cpu, diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8c3d06a3db62..8724c4ab3e88 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2644,10 +2644,10 @@ static bool filter_cpu(struct perf_sample *sample) static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_script *scr = container_of(tool, struct perf_script, tool); + struct evsel *evsel = sample->evsel; struct addr_location al; struct addr_location addr_al; int ret = 0; @@ -2728,10 +2728,10 @@ static int process_sample_event(const struct perf_tool *tool, static int process_deferred_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_script *scr = container_of(tool, struct perf_script, tool); + struct evsel *evsel = sample->evsel; struct perf_event_attr *attr = &evsel->core.attr; struct evsel_script *es = evsel->priv; unsigned int type = output_type(attr->type); diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 28f33e39895d..8692d11ccd29 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -574,10 +574,10 @@ typedef int (*tracepoint_handler)(struct timechart *tchart, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct timechart *tchart = container_of(tool, struct timechart, tool); + struct evsel *evsel = sample->evsel; if (evsel->core.attr.sample_type & PERF_SAMPLE_TIME) { if (!tchart->first_time || tchart->first_time > sample->time) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 1c38f3d16a31..e86a3d375757 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3462,10 +3462,10 @@ static void trace__set_base_time(struct trace *trace, static int trace__process_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct trace *trace = container_of(tool, struct trace, tool); + struct evsel *evsel = sample->evsel; struct thread *thread; int err = 0; diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index fdb35133fde4..55b72235f891 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -55,7 +55,6 @@ static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct addr_location al; @@ -74,7 +73,7 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, addr_location__exit(&al); - sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, /*data=*/NULL); diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index 47e621cebe1b..73bad90b06f9 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h @@ -34,12 +34,7 @@ char *__dso__build_id_filename(const struct dso *dso, char *bf, size_t size, bool is_debug, bool is_kallsyms); int build_id__mark_dso_hit(const struct perf_tool *tool, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, - struct machine *machine); - -int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, - struct machine *machine); + struct perf_sample *sample, struct machine *machine); bool perf_session__read_build_ids(struct perf_session *session, bool with_hits); int perf_session__write_buildid_table(struct perf_session *session, diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c index ba1c8e48d495..32e2173b86e3 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c @@ -803,10 +803,10 @@ static bool is_flush_needed(struct ctf_stream *cs) static int process_sample_event(const struct perf_tool *tool, union perf_event *_event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct convert *c = container_of(tool, struct convert, tool); + struct evsel *evsel = sample->evsel; struct evsel_priv *priv = evsel->priv; struct ctf_writer *cw = &c->writer; struct ctf_stream *cs; diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c index 6a626322476a..d1f931ee565a 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -159,13 +159,12 @@ static void output_sample_callchain_entry(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine) { struct convert_json *c = container_of(tool, struct convert_json, tool); FILE *out = c->out; struct addr_location al; - u64 sample_type = __evlist__combined_sample_type(evsel->evlist); + u64 sample_type = __evlist__combined_sample_type(sample->evsel->evlist); u8 cpumode = PERF_RECORD_MISC_USER; addr_location__init(&al); @@ -245,7 +244,7 @@ static int process_sample_event(const struct perf_tool *tool, #ifdef HAVE_LIBTRACEEVENT if (sample->raw_data) { - struct tep_event *tp_format = evsel__tp_format(evsel); + struct tep_event *tp_format = evsel__tp_format(sample->evsel); struct tep_format_field **fields = tp_format ? tep_event_fields(tp_format) : NULL; if (fields) { diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 2af5455488b2..01e030862d5d 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -185,7 +185,6 @@ static bool should_ignore_sample(const struct perf_sample *sample, const struct static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct tpebs_retire_lat *t; @@ -196,7 +195,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, mutex_unlock(tpebs_mtx_get()); return 0; } - t = tpebs_retire_lat__find(evsel); + t = tpebs_retire_lat__find(sample->evsel); if (!t) { mutex_unlock(tpebs_mtx_get()); return -EINVAL; diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c index e0ce8b904729..52e6ffac2b3e 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -642,7 +642,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr) ret = jit_inject_event(jd, event); if (!ret) - build_id__mark_dso_hit(tool, event, &sample, NULL, jd->machine); + build_id__mark_dso_hit(tool, event, &sample, jd->machine); out: perf_sample__exit(&sample); return ret; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 3794d3a04afb..150398b383fe 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1110,9 +1110,10 @@ char *get_page_size_name(u64 size, char *str) return str; } -static void dump_sample(struct machine *machine, struct evsel *evsel, union perf_event *event, +static void dump_sample(struct machine *machine, union perf_event *event, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; u64 sample_type; char str[PAGE_SIZE_NAME_LEN]; uint16_t e_machine = EM_NONE; @@ -1176,9 +1177,10 @@ static void dump_sample(struct machine *machine, struct evsel *evsel, union perf sample_read__printf(sample, evsel->core.attr.read_format); } -static void dump_deferred_callchain(struct evsel *evsel, union perf_event *event, - struct perf_sample *sample) +static void dump_deferred_callchain(union perf_event *event, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; + if (!dump_trace) return; @@ -1284,7 +1286,7 @@ static int deliver_sample_value(struct evlist *evlist, return 0; sample->evsel = container_of(sid->evsel, struct evsel, core); - ret = tool->sample(tool, event, sample, sample->evsel, machine); + ret = tool->sample(tool, event, sample, machine); sample->evsel = saved_evsel; return ret; } @@ -1316,8 +1318,9 @@ static int deliver_sample_group(struct evlist *evlist, static int evlist__deliver_sample(struct evlist *evlist, const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) + struct machine *machine) { + struct evsel *evsel = sample->evsel; /* We know evsel != NULL. */ u64 sample_type = evsel->core.attr.sample_type; u64 read_format = evsel->core.attr.read_format; @@ -1325,7 +1328,7 @@ static int evlist__deliver_sample(struct evlist *evlist, const struct perf_tool /* Standard sample delivery. */ if (!(sample_type & PERF_SAMPLE_READ)) - return tool->sample(tool, event, sample, evsel, machine); + return tool->sample(tool, event, sample, machine); /* For PERF_SAMPLE_READ we have either single or group mode. */ if (read_format & PERF_FORMAT_GROUP) @@ -1364,8 +1367,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, struct evsel *saved_evsel = sample->evsel; sample->evsel = evlist__id2evsel(evlist, sample->id); - ret = tool->callchain_deferred(tool, event, sample, - sample->evsel, machine); + ret = tool->callchain_deferred(tool, event, sample, machine); sample->evsel = saved_evsel; return ret; } @@ -1393,7 +1395,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, orig_sample.evsel = evlist__id2evsel(evlist, orig_sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &orig_sample, orig_sample.evsel, machine); + &orig_sample, machine); perf_sample__exit(&orig_sample); list_del(&de->list); @@ -1431,7 +1433,7 @@ static int session__flush_deferred_samples(struct perf_session *session, sample.evsel = evlist__id2evsel(evlist, sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &sample, sample.evsel, machine); + &sample, machine); perf_sample__exit(&sample); list_del(&de->list); @@ -1451,7 +1453,6 @@ static int machines__deliver_event(struct machines *machines, const struct perf_tool *tool, u64 file_offset, const char *file_path) { - struct evsel *evsel; struct machine *machine; dump_event(evlist, event, file_offset, sample, file_path); @@ -1461,21 +1462,20 @@ static int machines__deliver_event(struct machines *machines, else assert(sample->evsel == evlist__id2evsel(evlist, sample->id)); - evsel = sample->evsel; machine = machines__find_for_cpumode(machines, event, sample); switch (event->header.type) { case PERF_RECORD_SAMPLE: - if (evsel == NULL) { + if (sample->evsel == NULL) { ++evlist->stats.nr_unknown_id; return 0; } if (machine == NULL) { ++evlist->stats.nr_unprocessable_samples; - dump_sample(machine, evsel, event, sample); + dump_sample(machine, event, sample); return 0; } - dump_sample(machine, evsel, event, sample); + dump_sample(machine, event, sample); if (sample->deferred_callchain && tool->merge_deferred_callchains) { struct deferred_event *de = malloc(sizeof(*de)); size_t sz = event->header.size; @@ -1492,7 +1492,7 @@ static int machines__deliver_event(struct machines *machines, list_add_tail(&de->list, &evlist->deferred_samples); return 0; } - return evlist__deliver_sample(evlist, tool, event, sample, evsel, machine); + return evlist__deliver_sample(evlist, tool, event, sample, machine); case PERF_RECORD_MMAP: return tool->mmap(tool, event, sample, machine); case PERF_RECORD_MMAP2: @@ -1520,8 +1520,8 @@ static int machines__deliver_event(struct machines *machines, evlist->stats.total_lost_samples += event->lost_samples.lost; return tool->lost_samples(tool, event, sample, machine); case PERF_RECORD_READ: - dump_read(evsel, event); - return tool->read(tool, event, sample, evsel, machine); + dump_read(sample->evsel, event); + return tool->read(tool, event, sample, machine); case PERF_RECORD_THROTTLE: return tool->throttle(tool, event, sample, machine); case PERF_RECORD_UNTHROTTLE: @@ -1550,7 +1550,7 @@ static int machines__deliver_event(struct machines *machines, case PERF_RECORD_AUX_OUTPUT_HW_ID: return tool->aux_output_hw_id(tool, event, sample, machine); case PERF_RECORD_CALLCHAIN_DEFERRED: - dump_deferred_callchain(evsel, event, sample); + dump_deferred_callchain(event, sample); return evlist__deliver_deferred_callchain(evlist, tool, event, sample, machine); default: diff --git a/tools/perf/util/tool.c b/tools/perf/util/tool.c index 013c7839e2cf..0f285a2574c8 100644 --- a/tools/perf/util/tool.c +++ b/tools/perf/util/tool.c @@ -110,7 +110,6 @@ static int process_event_synth_event_update_stub(const struct perf_tool *tool __ int process_event_sample_stub(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct machine *machine __maybe_unused) { dump_printf(": unhandled!\n"); @@ -348,12 +347,11 @@ bool perf_tool__compressed_is_stub(const struct perf_tool *tool) static int delegate_ ## name(const struct perf_tool *tool, \ union perf_event *event, \ struct perf_sample *sample, \ - struct evsel *evsel, \ struct machine *machine) \ { \ struct delegate_tool *del_tool = container_of(tool, struct delegate_tool, tool); \ struct perf_tool *delegate = del_tool->delegate; \ - return delegate->name(delegate, event, sample, evsel, machine); \ + return delegate->name(delegate, event, sample, machine); \ } CREATE_DELEGATE_SAMPLE(read); CREATE_DELEGATE_SAMPLE(sample); diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h index 2d9a4b1ca9d0..2a4f124ffd8d 100644 --- a/tools/perf/util/tool.h +++ b/tools/perf/util/tool.h @@ -9,7 +9,6 @@ struct perf_session; union perf_event; struct evlist; -struct evsel; struct perf_sample; struct perf_tool; struct machine; @@ -17,7 +16,7 @@ struct ordered_events; typedef int (*event_sample)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); + struct machine *machine); typedef int (*event_op)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine); @@ -103,7 +102,6 @@ bool perf_tool__compressed_is_stub(const struct perf_tool *tool); int process_event_sample_stub(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); struct delegate_tool { -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 05/25] perf kvm: Don't pass evsel with sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (3 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 04/25] perf tool: Remove evsel from tool APIs that pass the sample Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval Ian Rogers ` (20 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan As the sample now contains the evsel, read the evsel from the sample rather than passing them as a pair. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-kvm.c | 19 +++-- .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 17 +++-- .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 ++--- .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 ++--- .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 18 +++-- tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +++--- tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 ++++++++----------- tools/perf/util/kvm-stat.c | 19 +++-- tools/perf/util/kvm-stat.h | 18 ++--- 9 files changed, 89 insertions(+), 126 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 5e8e6fde097a..d9b9792894a8 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -806,7 +806,6 @@ static bool update_kvm_event(struct perf_kvm_stat *kvm, } static bool is_child_event(struct perf_kvm_stat *kvm, - struct evsel *evsel, struct perf_sample *sample, struct event_key *key) { @@ -818,8 +817,8 @@ static bool is_child_event(struct perf_kvm_stat *kvm, return false; for (; child_ops->name; child_ops++) { - if (evsel__name_is(evsel, child_ops->name)) { - child_ops->get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, child_ops->name)) { + child_ops->get_key(sample, key); return true; } } @@ -917,11 +916,10 @@ static bool handle_end_event(struct perf_kvm_stat *kvm, static struct vcpu_event_record *per_vcpu_record(struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { /* Only kvm_entry records vcpu id. */ - if (!thread__priv(thread) && kvm_entry_event(evsel)) { + if (!thread__priv(thread) && kvm_entry_event(sample->evsel)) { struct vcpu_event_record *vcpu_record; struct machine *machine = maps__machine(thread__maps(thread)); uint16_t e_machine = thread__e_machine(thread, machine, /*e_flags=*/NULL); @@ -932,7 +930,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, return NULL; } - vcpu_record->vcpu_id = evsel__intval(evsel, sample, vcpu_id_str(e_machine)); + vcpu_record->vcpu_id = evsel__intval(sample->evsel, sample, vcpu_id_str(e_machine)); thread__set_priv(thread, vcpu_record); } @@ -943,12 +941,11 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, struct thread *thread, struct perf_sample *sample) { - struct evsel *evsel = sample->evsel; struct vcpu_event_record *vcpu_record; struct event_key key = { .key = INVALID_KEY, .exit_reasons = kvm->exit_reasons }; - vcpu_record = per_vcpu_record(thread, evsel, sample); + vcpu_record = per_vcpu_record(thread, sample); if (!vcpu_record) return true; @@ -957,13 +954,13 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, (kvm->trace_vcpu != vcpu_record->vcpu_id)) return true; - if (kvm->events_ops->is_begin_event(evsel, sample, &key)) + if (kvm->events_ops->is_begin_event(sample, &key)) return handle_begin_event(kvm, vcpu_record, &key, sample); - if (is_child_event(kvm, evsel, sample, &key)) + if (is_child_event(kvm, sample, &key)) return handle_child_event(kvm, vcpu_record, &key, sample); - if (kvm->events_ops->is_end_event(evsel, sample, &key)) + if (kvm->events_ops->is_end_event(sample, &key)) return handle_end_event(kvm, vcpu_record, &key, sample); return true; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c index c640dcd8af7c..1e76906f719c 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c @@ -17,10 +17,11 @@ static const char * const __kvm_events_tp[] = { NULL, }; -static void event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_get_key(struct perf_sample *sample, struct event_key *key) { + struct evsel *evsel = sample->evsel; + key->info = 0; key->key = evsel__intval(evsel, sample, kvm_exit_reason(EM_AARCH64)); key->exit_reasons = arm64_exit_reasons; @@ -36,19 +37,17 @@ static void event_get_key(struct evsel *evsel, } } -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_begin(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, kvm_entry_trace(EM_AARCH64)); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_AARCH64)); } -static bool event_end(struct evsel *evsel, - struct perf_sample *sample, +static bool event_end(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, kvm_exit_trace(EM_AARCH64))) { - event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, kvm_exit_trace(EM_AARCH64))) { + event_get_key(sample, key); return true; } return false; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c index b802e516b138..9d6265290f6d 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c @@ -53,14 +53,12 @@ static const char * const __kvm_events_tp[] = { NULL, }; -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool event_begin(struct perf_sample *sample, struct event_key *key) { - return exit_event_begin(evsel, sample, key); + return exit_event_begin(sample, key); } -static bool event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { /* @@ -71,17 +69,16 @@ static bool event_end(struct evsel *evsel, * kvm:kvm_enter means returning to vmm and then to guest * kvm:kvm_reenter means returning to guest immediately */ - return evsel__name_is(evsel, kvm_entry_trace(EM_LOONGARCH)) || - evsel__name_is(evsel, kvm_reenter_trace); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_LOONGARCH)) || + evsel__name_is(sample->evsel, kvm_reenter_trace); } -static void event_gspr_get_key(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static void event_gspr_get_key(struct perf_sample *sample, struct event_key *key) { unsigned int insn; key->key = LOONGARCH_EXCEPTION_OTHERS; - insn = evsel__intval(evsel, sample, "inst_word"); + insn = evsel__intval(sample->evsel, sample, "inst_word"); switch (insn >> 24) { case 0: diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c index 42182d70beb6..5158d7e88ee6 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c @@ -28,12 +28,11 @@ static const char * const ppc_book3s_hv_kvm_tp[] = { /* 1 extra placeholder for NULL */ static const char *__kvm_events_tp[NR_TPS + 1]; -static void hcall_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void hcall_event_get_key(struct perf_sample *sample, struct event_key *key) { key->info = 0; - key->key = evsel__intval(evsel, sample, "req"); + key->key = evsel__intval(sample->evsel, sample, "req"); } static const char *get_hcall_exit_reason(u64 exit_code) @@ -51,18 +50,16 @@ static const char *get_hcall_exit_reason(u64 exit_code) return "UNKNOWN"; } -static bool hcall_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool hcall_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, __kvm_events_tp[3]); + return evsel__name_is(sample->evsel, __kvm_events_tp[3]); } -static bool hcall_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool hcall_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, __kvm_events_tp[2])) { - hcall_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, __kvm_events_tp[2])) { + hcall_event_get_key(sample, key); return true; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c index 8d4d5d6ce720..e8db8b4f8e2e 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c @@ -20,30 +20,28 @@ static const char * const __kvm_events_tp[] = { NULL, }; -static void event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_get_key(struct perf_sample *sample, struct event_key *key) { int xlen = 64; // TODO: 32-bit support. key->info = 0; - key->key = evsel__intval(evsel, sample, kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); + key->key = evsel__intval(sample->evsel, sample, + kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); key->exit_reasons = riscv_exit_reasons; } -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_begin(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, kvm_entry_trace(EM_RISCV)); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_RISCV)); } -static bool event_end(struct evsel *evsel, - struct perf_sample *sample, +static bool event_end(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, kvm_exit_trace(EM_RISCV))) { - event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, kvm_exit_trace(EM_RISCV))) { + event_get_key(sample, key); return true; } return false; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c index 7e29169f5bb0..158372ba0205 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c @@ -18,38 +18,34 @@ define_exit_reasons_table(sie_sigp_order_codes, sigp_order_codes); define_exit_reasons_table(sie_diagnose_codes, diagnose_codes); define_exit_reasons_table(sie_icpt_prog_codes, icpt_prog_codes); -static void event_icpt_insn_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_icpt_insn_get_key(struct perf_sample *sample, struct event_key *key) { u64 insn; - insn = evsel__intval(evsel, sample, "instruction"); + insn = evsel__intval(sample->evsel, sample, "instruction"); key->key = icpt_insn_decoder(insn); key->exit_reasons = sie_icpt_insn_codes; } -static void event_sigp_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_sigp_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "order_code"); + key->key = evsel__intval(sample->evsel, sample, "order_code"); key->exit_reasons = sie_sigp_order_codes; } -static void event_diag_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_diag_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "code"); + key->key = evsel__intval(sample->evsel, sample, "code"); key->exit_reasons = sie_diagnose_codes; } -static void event_icpt_prog_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_icpt_prog_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "code"); + key->key = evsel__intval(sample->evsel, sample, "code"); key->exit_reasons = sie_icpt_prog_codes; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c index 0f626db3a439..0ce543d82850 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c @@ -24,45 +24,43 @@ static const struct kvm_events_ops exit_events = { * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...). */ -static void mmio_event_get_key(struct evsel *evsel, struct perf_sample *sample, +static void mmio_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "gpa"); - key->info = evsel__intval(evsel, sample, "type"); + key->key = evsel__intval(sample->evsel, sample, "gpa"); + key->info = evsel__intval(sample->evsel, sample, "type"); } #define KVM_TRACE_MMIO_READ_UNSATISFIED 0 #define KVM_TRACE_MMIO_READ 1 #define KVM_TRACE_MMIO_WRITE 2 -static bool mmio_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool mmio_event_begin(struct perf_sample *sample, struct event_key *key) { /* MMIO read begin event in kernel. */ - if (kvm_exit_event(evsel)) + if (kvm_exit_event(sample->evsel)) return true; /* MMIO write begin event in kernel. */ - if (evsel__name_is(evsel, "kvm:kvm_mmio") && - evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { - mmio_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && + evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { + mmio_event_get_key(sample, key); return true; } return false; } -static bool mmio_event_end(struct evsel *evsel, struct perf_sample *sample, - struct event_key *key) +static bool mmio_event_end(struct perf_sample *sample, struct event_key *key) { /* MMIO write end event in kernel. */ - if (kvm_entry_event(evsel)) + if (kvm_entry_event(sample->evsel)) return true; /* MMIO read end event in kernel.*/ - if (evsel__name_is(evsel, "kvm:kvm_mmio") && - evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) { - mmio_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && + evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_READ) { + mmio_event_get_key(sample, key); return true; } @@ -86,31 +84,27 @@ static const struct kvm_events_ops mmio_events = { }; /* The time of emulation pio access is from kvm_pio to kvm_entry. */ -static void ioport_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void ioport_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "port"); - key->info = evsel__intval(evsel, sample, "rw"); + key->key = evsel__intval(sample->evsel, sample, "port"); + key->info = evsel__intval(sample->evsel, sample, "rw"); } -static bool ioport_event_begin(struct evsel *evsel, - struct perf_sample *sample, +static bool ioport_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, "kvm:kvm_pio")) { - ioport_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_pio")) { + ioport_event_get_key(sample, key); return true; } return false; } -static bool ioport_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) +static bool ioport_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, @@ -130,31 +124,25 @@ static const struct kvm_events_ops ioport_events = { }; /* The time of emulation msr is from kvm_msr to kvm_entry. */ -static void msr_event_get_key(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) +static void msr_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "ecx"); - key->info = evsel__intval(evsel, sample, "write"); + key->key = evsel__intval(sample->evsel, sample, "ecx"); + key->info = evsel__intval(sample->evsel, sample, "write"); } -static bool msr_event_begin(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) +static bool msr_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, "kvm:kvm_msr")) { - msr_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_msr")) { + msr_event_get_key(sample, key); return true; } return false; } -static bool msr_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) +static bool msr_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } static void msr_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c index 27f16810498c..f17a6132958d 100644 --- a/tools/perf/util/kvm-stat.c +++ b/tools/perf/util/kvm-stat.c @@ -11,22 +11,20 @@ bool kvm_exit_event(struct evsel *evsel) return evsel__name_is(evsel, kvm_exit_trace(e_machine)); } -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +void exit_event_get_key(struct perf_sample *sample, struct event_key *key) { - uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL); + uint16_t e_machine = evsel__e_machine(sample->evsel, /*e_flags=*/NULL); key->info = 0; - key->key = evsel__intval(evsel, sample, kvm_exit_reason(e_machine)); + key->key = evsel__intval(sample->evsel, sample, kvm_exit_reason(e_machine)); } -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +bool exit_event_begin(struct perf_sample *sample, struct event_key *key) { - if (kvm_exit_event(evsel)) { - exit_event_get_key(evsel, sample, key); + if (kvm_exit_event(sample->evsel)) { + exit_event_get_key(sample, key); return true; } @@ -40,11 +38,10 @@ bool kvm_entry_event(struct evsel *evsel) return evsel__name_is(evsel, kvm_entry_trace(e_machine)); } -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +bool exit_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } static const char *get_exit_reason(struct perf_kvm_stat *kvm, diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 4a998aaece5d..cdbd921a555f 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -53,18 +53,15 @@ struct kvm_event { }; struct child_event_ops { - void (*get_key)(struct evsel *evsel, - struct perf_sample *sample, + void (*get_key)(struct perf_sample *sample, struct event_key *key); const char *name; }; struct kvm_events_ops { - bool (*is_begin_event)(struct evsel *evsel, - struct perf_sample *sample, + bool (*is_begin_event)(struct perf_sample *sample, struct event_key *key); - bool (*is_end_event)(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key); + bool (*is_end_event)(struct perf_sample *sample, struct event_key *key); const struct child_event_ops *child_ops; void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key, char *decode); @@ -116,14 +113,11 @@ struct kvm_reg_events_ops { #ifdef HAVE_LIBTRACEEVENT -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +void exit_event_get_key(struct perf_sample *sample, struct event_key *key); -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, +bool exit_event_begin(struct perf_sample *sample, struct event_key *key); -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample, +bool exit_event_end(struct perf_sample *sample, struct event_key *key); void exit_event_decode_key(struct perf_kvm_stat *kvm, struct event_key *key, -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (4 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 05/25] perf kvm: Don't pass evsel with sample Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 07/25] perf trace: Don't pass evsel with sample Ian Rogers ` (19 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The evsel argument to evsel__intval, and similar functions, is unnecessary as it can be read from the sample. Remove the evsel and rename the function to match that the data is coming from the sample. Add bounds checks to read values. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 44 +++++---- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-kwork.c | 29 +++--- tools/perf/builtin-lock.c | 32 +++--- tools/perf/builtin-sched.c | 97 ++++++++++--------- tools/perf/builtin-timechart.c | 92 +++++++++--------- tools/perf/builtin-trace.c | 12 +-- tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/tests/switch-tracking.c | 4 +- tools/perf/util/evsel.c | 28 +++--- tools/perf/util/evsel.h | 12 +-- tools/perf/util/intel-pt.c | 2 +- .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 6 +- .../util/kvm-stat-arch/kvm-stat-loongarch.c | 2 +- .../util/kvm-stat-arch/kvm-stat-powerpc.c | 2 +- .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 3 +- tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 8 +- tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 16 +-- tools/perf/util/kvm-stat.c | 2 +- 20 files changed, 208 insertions(+), 189 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 4912ae92473a..d03d38a18aa0 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1085,7 +1085,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, union perf_event *event_sw; struct perf_sample sample_sw; struct perf_inject *inject = container_of(tool, struct perf_inject, tool); - u32 pid = evsel__intval(evsel, sample, "pid"); + u32 pid = perf_sample__intval(sample, "pid"); int ret; list_for_each_entry(ent, &inject->samples, node) { diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 34852a4c3fc8..7e6b976a2cab 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -173,10 +173,10 @@ static int insert_caller_stat(unsigned long call_site, static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *sample) { - unsigned long ptr = evsel__intval(evsel, sample, "ptr"), - call_site = evsel__intval(evsel, sample, "call_site"); - int bytes_req = evsel__intval(evsel, sample, "bytes_req"), - bytes_alloc = evsel__intval(evsel, sample, "bytes_alloc"); + unsigned long ptr = perf_sample__intval(sample, "ptr"), + call_site = perf_sample__intval(sample, "call_site"); + int bytes_req = perf_sample__intval(sample, "bytes_req"), + bytes_alloc = perf_sample__intval(sample, "bytes_alloc"); if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) || insert_caller_stat(call_site, bytes_req, bytes_alloc)) @@ -202,7 +202,7 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s int node1, node2; node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}); - node2 = evsel__intval(evsel, sample, "node"); + node2 = perf_sample__intval(sample, "node"); /* * If the field "node" is NUMA_NO_NODE (-1), we don't take it @@ -243,9 +243,9 @@ static struct alloc_stat *search_alloc_stat(unsigned long ptr, return NULL; } -static int evsel__process_free_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_free_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - unsigned long ptr = evsel__intval(evsel, sample, "ptr"); + unsigned long ptr = perf_sample__intval(sample, "ptr"); struct alloc_stat *s_alloc, *s_caller; s_alloc = search_alloc_stat(ptr, 0, &root_alloc_stat, ptr_cmp); @@ -808,10 +808,9 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sample *sample) { u64 page; - unsigned int order = evsel__intval(evsel, sample, "order"); - unsigned int gfp_flags = evsel__intval(evsel, sample, "gfp_flags"); - unsigned int migrate_type = evsel__intval(evsel, sample, - "migratetype"); + unsigned int order = perf_sample__intval(sample, "order"); + unsigned int gfp_flags = perf_sample__intval(sample, "gfp_flags"); + unsigned int migrate_type = perf_sample__intval(sample, "migratetype"); u64 bytes = kmem_page_size << order; u64 callsite; struct page_stat *pstat; @@ -821,10 +820,20 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp .migrate_type = migrate_type, }; + if (order >= MAX_PAGE_ORDER) { + pr_debug("Out-of-bounds order %u\n", order); + return -1; + } + + if (migrate_type >= MAX_MIGRATE_TYPES) { + pr_debug("Out-of-bounds migratetype %u\n", migrate_type); + return -1; + } + if (use_pfn) - page = evsel__intval(evsel, sample, "pfn"); + page = perf_sample__intval(sample, "pfn"); else - page = evsel__intval(evsel, sample, "page"); + page = perf_sample__intval(sample, "page"); nr_page_allocs++; total_page_alloc_bytes += bytes; @@ -877,10 +886,11 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp return 0; } -static int evsel__process_page_free_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_page_free_event(struct evsel *evsel __maybe_unused, + struct perf_sample *sample) { u64 page; - unsigned int order = evsel__intval(evsel, sample, "order"); + unsigned int order = perf_sample__intval(sample, "order"); u64 bytes = kmem_page_size << order; struct page_stat *pstat; struct page_stat this = { @@ -888,9 +898,9 @@ static int evsel__process_page_free_event(struct evsel *evsel, struct perf_sampl }; if (use_pfn) - page = evsel__intval(evsel, sample, "pfn"); + page = perf_sample__intval(sample, "pfn"); else - page = evsel__intval(evsel, sample, "page"); + page = perf_sample__intval(sample, "page"); nr_page_frees++; total_page_free_bytes += bytes; diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index d9b9792894a8..dd2ed21596aa 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -930,7 +930,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, return NULL; } - vcpu_record->vcpu_id = evsel__intval(sample->evsel, sample, vcpu_id_str(e_machine)); + vcpu_record->vcpu_id = perf_sample__intval(sample, vcpu_id_str(e_machine)); thread__set_priv(thread, vcpu_record); } diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index e34a1f35439e..111ae53025d1 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1006,7 +1006,7 @@ static void irq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1014,11 +1014,11 @@ static void irq_work_init(struct perf_kwork *kwork, work->cpu = sample->cpu; if (kwork->report == KWORK_REPORT_TOP) { - work->id = evsel__intval_common(evsel, sample, "common_pid"); + work->id = perf_sample__intval_common(sample, "common_pid"); work->name = NULL; } else { - work->id = evsel__intval(evsel, sample, "irq"); - work->name = evsel__strval(evsel, sample, "name"); + work->id = perf_sample__intval(sample, "irq"); + work->name = perf_sample__strval(sample, "name"); } } @@ -1144,10 +1144,10 @@ static void softirq_work_init(struct perf_kwork *kwork, work->cpu = sample->cpu; if (kwork->report == KWORK_REPORT_TOP) { - work->id = evsel__intval_common(evsel, sample, "common_pid"); + work->id = perf_sample__intval_common(sample, "common_pid"); work->name = NULL; } else { - num = evsel__intval(evsel, sample, "vec"); + num = perf_sample__intval(sample, "vec"); work->id = num; work->name = evsel__softirq_name(evsel, num); } @@ -1234,17 +1234,16 @@ static void workqueue_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { char *modp = NULL; - unsigned long long function_addr = evsel__intval(evsel, - sample, "function"); + unsigned long long function_addr = perf_sample__intval(sample, "function"); work->class = class; work->cpu = sample->cpu; - work->id = evsel__intval(evsel, sample, "work"); + work->id = perf_sample__intval(sample, "work"); work->name = function_addr == 0 ? NULL : machine__resolve_kernel_addr(machine, &function_addr, &modp); } @@ -1302,7 +1301,7 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1310,11 +1309,11 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused, work->cpu = sample->cpu; if (src_type == KWORK_TRACE_EXIT) { - work->id = evsel__intval(evsel, sample, "prev_pid"); - work->name = strdup(evsel__strval(evsel, sample, "prev_comm")); + work->id = perf_sample__intval(sample, "prev_pid"); + work->name = strdup(perf_sample__strval(sample, "prev_comm")); } else if (src_type == KWORK_TRACE_ENTRY) { - work->id = evsel__intval(evsel, sample, "next_pid"); - work->name = strdup(evsel__strval(evsel, sample, "next_comm")); + work->id = perf_sample__intval(sample, "next_pid"); + work->name = strdup(perf_sample__strval(sample, "next_comm")); } } diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index dc8d1d3b4cd7..baf0c99df5df 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -563,15 +563,15 @@ static int get_key_by_aggr_mode(u64 *key, u64 addr, struct evsel *evsel, return get_key_by_aggr_mode_simple(key, addr, sample->tid); } -static int report_lock_acquire_event(struct evsel *evsel, +static int report_lock_acquire_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); - int flag = evsel__intval(evsel, sample, "flags"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); + int flag = perf_sample__intval(sample, "flags"); u64 key; int ret; @@ -638,15 +638,15 @@ static int report_lock_acquire_event(struct evsel *evsel, return 0; } -static int report_lock_acquired_event(struct evsel *evsel, +static int report_lock_acquired_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; u64 contended_term; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; @@ -704,14 +704,14 @@ static int report_lock_acquired_event(struct evsel *evsel, return 0; } -static int report_lock_contended_event(struct evsel *evsel, +static int report_lock_contended_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; @@ -762,14 +762,14 @@ static int report_lock_contended_event(struct evsel *evsel, return 0; } -static int report_lock_release_event(struct evsel *evsel, +static int report_lock_release_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; @@ -969,8 +969,8 @@ static int report_lock_contention_begin_event(struct evsel *evsel, struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - u64 addr = evsel__intval(evsel, sample, "lock_addr"); - unsigned int flags = evsel__intval(evsel, sample, "flags"); + u64 addr = perf_sample__intval(sample, "lock_addr"); + unsigned int flags = perf_sample__intval(sample, "flags"); u64 key; int i, ret; static bool kmap_loaded; @@ -1134,7 +1134,7 @@ static int report_lock_contention_end_event(struct evsel *evsel, struct thread_stat *ts; struct lock_seq_stat *seq; u64 contended_term; - u64 addr = evsel__intval(evsel, sample, "lock_addr"); + u64 addr = perf_sample__intval(sample, "lock_addr"); u64 key; int ret; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 296b9837278a..3e7e8ad0bc13 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -829,8 +829,8 @@ replay_wakeup_event(struct perf_sched *sched, struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { - const char *comm = evsel__strval(evsel, sample, "comm"); - const u32 pid = evsel__intval(evsel, sample, "pid"); + const char *comm = perf_sample__strval(sample, "comm"); + const u32 pid = perf_sample__intval(sample, "pid"); struct task_desc *waker, *wakee; if (verbose > 0) { @@ -851,10 +851,10 @@ static int replay_switch_event(struct perf_sched *sched, struct perf_sample *sample, struct machine *machine __maybe_unused) { - const char *prev_comm = evsel__strval(evsel, sample, "prev_comm"), - *next_comm = evsel__strval(evsel, sample, "next_comm"); - const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), - next_pid = evsel__intval(evsel, sample, "next_pid"); + const char *prev_comm = perf_sample__strval(sample, "prev_comm"), + *next_comm = perf_sample__strval(sample, "next_comm"); + const u32 prev_pid = perf_sample__intval(sample, "prev_pid"), + next_pid = perf_sample__intval(sample, "next_pid"); struct task_desc *prev, __maybe_unused *next; u64 timestamp0, timestamp = sample->time; int cpu = sample->cpu; @@ -1134,13 +1134,13 @@ static void free_work_atoms(struct work_atoms *atoms) } static int latency_switch_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), - next_pid = evsel__intval(evsel, sample, "next_pid"); - const char prev_state = evsel__taskstate(evsel, sample, "prev_state"); + const u32 prev_pid = perf_sample__intval(sample, "prev_pid"), + next_pid = perf_sample__intval(sample, "next_pid"); + const char prev_state = perf_sample__taskstate(sample, "prev_state"); struct work_atoms *out_events, *in_events; struct thread *sched_out, *sched_in; u64 timestamp0, timestamp = sample->time; @@ -1204,12 +1204,12 @@ static int latency_switch_event(struct perf_sched *sched, } static int latency_runtime_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid = evsel__intval(evsel, sample, "pid"); - const u64 runtime = evsel__intval(evsel, sample, "runtime"); + const u32 pid = perf_sample__intval(sample, "pid"); + const u64 runtime = perf_sample__intval(sample, "runtime"); struct thread *thread = machine__findnew_thread(machine, -1, pid); struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); u64 timestamp = sample->time; @@ -1239,11 +1239,11 @@ static int latency_runtime_event(struct perf_sched *sched, } static int latency_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); struct work_atoms *atoms; struct work_atom *atom; struct thread *wakee; @@ -1300,11 +1300,11 @@ static int latency_wakeup_event(struct perf_sched *sched, } static int latency_migrate_task_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); u64 timestamp = sample->time; struct work_atoms *atoms; struct work_atom *atom; @@ -1626,11 +1626,11 @@ static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu, } } -static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, +static int map_switch_event(struct perf_sched *sched, struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); - const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"); + const u32 next_pid = perf_sample__intval(sample, "next_pid"); + const u32 prev_pid = perf_sample__intval(sample, "prev_pid"); struct thread *sched_in, *sched_out; struct thread_runtime *tr; int new_shortname; @@ -1797,8 +1797,13 @@ static int process_sched_switch_event(const struct perf_tool *tool, { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); int this_cpu = sample->cpu, err = 0; - u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), - next_pid = evsel__intval(evsel, sample, "next_pid"); + u32 prev_pid = perf_sample__intval(sample, "prev_pid"), + next_pid = perf_sample__intval(sample, "next_pid"); + + if (this_cpu < 0 || this_cpu >= MAX_CPUS) { + pr_debug("Out-of-bound sample CPU %d\n", this_cpu); + return -1; + } if (sched->curr_pid[this_cpu] != (u32)-1) { /* @@ -2068,12 +2073,11 @@ static char *timehist_get_commstr(struct thread *thread) /* prio field format: xxx or xxx->yyy */ #define MAX_PRIO_STR_LEN 8 -static char *timehist_get_priostr(struct evsel *evsel, - struct thread *thread, +static char *timehist_get_priostr(struct thread *thread, struct perf_sample *sample) { static char prio_str[16]; - int prev_prio = (int)evsel__intval(evsel, sample, "prev_prio"); + int prev_prio = (int)perf_sample__intval(sample, "prev_prio"); struct thread_runtime *tr = thread__priv(thread); if (tr->prio != prev_prio && tr->prio != -1) @@ -2161,15 +2165,14 @@ static void timehist_header(struct perf_sched *sched) } static void timehist_print_sample(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct addr_location *al, struct thread *thread, u64 t, const char state) { struct thread_runtime *tr = thread__priv(thread); - const char *next_comm = evsel__strval(evsel, sample, "next_comm"); - const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); + const char *next_comm = perf_sample__strval(sample, "next_comm"); + const u32 next_pid = perf_sample__intval(sample, "next_pid"); u32 max_cpus = sched->max_cpu.cpu + 1; char tstr[64]; char nstr[30]; @@ -2198,14 +2201,15 @@ static void timehist_print_sample(struct perf_sched *sched, } if (!thread__comm_set(thread)) { - const char *prev_comm = evsel__strval(evsel, sample, "prev_comm"); - thread__set_comm(thread, prev_comm, sample->time); + const char *prev_comm = perf_sample__strval(sample, "prev_comm"); + + thread__set_comm(thread, prev_comm, sample->time); } printf(" %-*s ", comm_width, timehist_get_commstr(thread)); if (sched->show_prio) - printf(" %-*s ", MAX_PRIO_STR_LEN, timehist_get_priostr(evsel, thread, sample)); + printf(" %-*s ", MAX_PRIO_STR_LEN, timehist_get_priostr(thread, sample)); wait_time = tr->dt_sleep + tr->dt_iowait + tr->dt_preempt; print_sched_time(wait_time, 6); @@ -2319,7 +2323,7 @@ static bool is_idle_sample(struct perf_sample *sample, { /* pid 0 == swapper == idle task */ if (evsel__name_is(evsel, "sched:sched_switch")) - return evsel__intval(evsel, sample, "prev_pid") == 0; + return perf_sample__intval(sample, "prev_pid") == 0; return sample->pid == 0; } @@ -2539,7 +2543,7 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, itr->last_thread = thread__get(thread); /* copy task callchain when entering to idle */ - if (evsel__intval(evsel, sample, "next_pid") == 0) + if (perf_sample__intval(sample, "next_pid") == 0) save_idle_callchain(sched, itr, sample); } } @@ -2572,7 +2576,7 @@ static bool timehist_skip_sample(struct perf_sched *sched, if (tr && tr->prio != -1) prio = tr->prio; else if (evsel__name_is(evsel, "sched:sched_switch")) - prio = evsel__intval(evsel, sample, "prev_prio"); + prio = perf_sample__intval(sample, "prev_prio"); if (prio != -1 && !test_bit(prio, sched->prio_bitmap)) { rc = true; @@ -2583,8 +2587,8 @@ static bool timehist_skip_sample(struct perf_sched *sched, if (sched->idle_hist) { if (!evsel__name_is(evsel, "sched:sched_switch")) rc = true; - else if (evsel__intval(evsel, sample, "prev_pid") != 0 && - evsel__intval(evsel, sample, "next_pid") != 0) + else if (perf_sample__intval(sample, "prev_pid") != 0 && + perf_sample__intval(sample, "next_pid") != 0) rc = true; } @@ -2647,7 +2651,7 @@ static int timehist_sched_wakeup_event(const struct perf_tool *tool, struct thread *thread; struct thread_runtime *tr = NULL; /* want pid of awakened task not pid in sample */ - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); thread = machine__findnew_thread(machine, 0, pid); if (thread == NULL) @@ -2686,8 +2690,8 @@ static void timehist_print_migration_event(struct perf_sched *sched, return; max_cpus = sched->max_cpu.cpu + 1; - ocpu = evsel__intval(evsel, sample, "orig_cpu"); - dcpu = evsel__intval(evsel, sample, "dest_cpu"); + ocpu = perf_sample__intval(sample, "orig_cpu"); + dcpu = perf_sample__intval(sample, "dest_cpu"); thread = machine__findnew_thread(machine, sample->pid, sample->tid); if (thread == NULL) @@ -2736,7 +2740,7 @@ static int timehist_migrate_task_event(const struct perf_tool *tool, struct thread *thread; struct thread_runtime *tr = NULL; /* want pid of migrated task not pid in sample */ - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); thread = machine__findnew_thread(machine, 0, pid); if (thread == NULL) @@ -2761,14 +2765,13 @@ static int timehist_migrate_task_event(const struct perf_tool *tool, return 0; } -static void timehist_update_task_prio(struct evsel *evsel, - struct perf_sample *sample, +static void timehist_update_task_prio(struct perf_sample *sample, struct machine *machine) { struct thread *thread; struct thread_runtime *tr = NULL; - const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); - const u32 next_prio = evsel__intval(evsel, sample, "next_prio"); + const u32 next_pid = perf_sample__intval(sample, "next_pid"); + const u32 next_prio = perf_sample__intval(sample, "next_prio"); if (next_pid == 0) thread = get_idle_thread(sample->cpu); @@ -2798,7 +2801,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, struct thread_runtime *tr = NULL; u64 tprev, t = sample->time; int rc = 0; - const char state = evsel__taskstate(evsel, sample, "prev_state"); + const char state = perf_sample__taskstate(sample, "prev_state"); addr_location__init(&al); if (machine__resolve(machine, &al, sample) < 0) { @@ -2809,7 +2812,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, } if (sched->show_prio || sched->prio_str) - timehist_update_task_prio(evsel, sample, machine); + timehist_update_task_prio(sample, machine); thread = timehist_get_thread(sched, sample, machine, evsel); if (thread == NULL) { @@ -2891,7 +2894,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, } if (!sched->summary_only) - timehist_print_sample(sched, evsel, sample, &al, thread, t, state); + timehist_print_sample(sched, sample, &al, thread, t, state); } out: diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 8692d11ccd29..657aab126477 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -597,13 +597,17 @@ static int process_sample_event(const struct perf_tool *tool, static int process_sample_cpu_idle(struct timechart *tchart __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u32 state = evsel__intval(evsel, sample, "state"); - u32 cpu_id = evsel__intval(evsel, sample, "cpu_id"); + u32 state = perf_sample__intval(sample, "state"); + u32 cpu_id = perf_sample__intval(sample, "cpu_id"); + if (cpu_id >= MAX_CPUS) { + pr_debug("Out-of-bounds cpu_id %u\n", cpu_id); + return -1; + } if (state == (u32)PWR_EVENT_EXIT) c_state_end(tchart, cpu_id, sample->time); else @@ -613,12 +617,12 @@ process_sample_cpu_idle(struct timechart *tchart __maybe_unused, static int process_sample_cpu_frequency(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u32 state = evsel__intval(evsel, sample, "state"); - u32 cpu_id = evsel__intval(evsel, sample, "cpu_id"); + u32 state = perf_sample__intval(sample, "state"); + u32 cpu_id = perf_sample__intval(sample, "cpu_id"); p_state_change(tchart, cpu_id, sample->time, state); return 0; @@ -626,13 +630,13 @@ process_sample_cpu_frequency(struct timechart *tchart, static int process_sample_sched_wakeup(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { - u8 flags = evsel__intval(evsel, sample, "common_flags"); - int waker = evsel__intval(evsel, sample, "common_pid"); - int wakee = evsel__intval(evsel, sample, "pid"); + u8 flags = perf_sample__intval(sample, "common_flags"); + int waker = perf_sample__intval(sample, "common_pid"); + int wakee = perf_sample__intval(sample, "pid"); sched_wakeup(tchart, sample->cpu, sample->time, waker, wakee, flags, backtrace); return 0; @@ -640,13 +644,13 @@ process_sample_sched_wakeup(struct timechart *tchart, static int process_sample_sched_switch(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { - int prev_pid = evsel__intval(evsel, sample, "prev_pid"); - int next_pid = evsel__intval(evsel, sample, "next_pid"); - u64 prev_state = evsel__intval(evsel, sample, "prev_state"); + int prev_pid = perf_sample__intval(sample, "prev_pid"); + int next_pid = perf_sample__intval(sample, "next_pid"); + u64 prev_state = perf_sample__intval(sample, "prev_state"); sched_switch(tchart, sample->cpu, sample->time, prev_pid, next_pid, prev_state, backtrace); @@ -656,12 +660,12 @@ process_sample_sched_switch(struct timechart *tchart, #ifdef SUPPORT_OLD_POWER_EVENTS static int process_sample_power_start(struct timechart *tchart __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u64 cpu_id = evsel__intval(evsel, sample, "cpu_id"); - u64 value = evsel__intval(evsel, sample, "value"); + u64 cpu_id = perf_sample__intval(sample, "cpu_id"); + u64 value = perf_sample__intval(sample, "value"); c_state_start(cpu_id, sample->time, value); return 0; @@ -679,12 +683,12 @@ process_sample_power_end(struct timechart *tchart, static int process_sample_power_frequency(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u64 cpu_id = evsel__intval(evsel, sample, "cpu_id"); - u64 value = evsel__intval(evsel, sample, "value"); + u64 cpu_id = perf_sample__intval(sample, "cpu_id"); + u64 value = perf_sample__intval(sample, "value"); p_state_change(tchart, cpu_id, sample->time, value); return 0; @@ -849,120 +853,120 @@ static int pid_end_io_sample(struct timechart *tchart, int pid, int type, static int process_enter_read(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ, sample->time, fd); } static int process_exit_read(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_READ, sample->time, ret); } static int process_enter_write(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE, sample->time, fd); } static int process_exit_write(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_WRITE, sample->time, ret); } static int process_enter_sync(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC, sample->time, fd); } static int process_exit_sync(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_SYNC, sample->time, ret); } static int process_enter_tx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX, sample->time, fd); } static int process_exit_tx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_TX, sample->time, ret); } static int process_enter_rx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX, sample->time, fd); } static int process_exit_rx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_RX, sample->time, ret); } static int process_enter_poll(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL, sample->time, fd); } static int process_exit_poll(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_POLL, sample->time, ret); } diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index e86a3d375757..493eecf218b4 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3059,7 +3059,7 @@ errno_print: { return err; } -static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, +static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3068,7 +3068,7 @@ static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, size_t filename_len, entry_str_len, to_move; ssize_t remaining_space; char *pos; - const char *filename = evsel__rawptr(evsel, sample, "pathname"); + const char *filename = perf_sample__rawptr(sample, "pathname"); if (!thread) goto out; @@ -3124,7 +3124,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, union perf_event *event __maybe_unused, struct perf_sample *sample) { - u64 runtime = evsel__intval(evsel, sample, "runtime"); + u64 runtime = perf_sample__intval(sample, "runtime"); double runtime_ms = (double)runtime / NSEC_PER_MSEC; struct thread *thread = machine__findnew_thread(trace->host, sample->pid, @@ -3143,10 +3143,10 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, out_dump: fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", evsel->name, - evsel__strval(evsel, sample, "comm"), - (pid_t)evsel__intval(evsel, sample, "pid"), + perf_sample__strval(sample, "comm"), + (pid_t)perf_sample__intval(sample, "pid"), runtime, - evsel__intval(evsel, sample, "vruntime")); + perf_sample__intval(sample, "vruntime")); goto out_put; } diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c index 2a139d2781a8..97550b349418 100644 --- a/tools/perf/tests/openat-syscall-tp-fields.c +++ b/tools/perf/tests/openat-syscall-tp-fields.c @@ -118,7 +118,7 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused goto out_delete_evlist; } - tp_flags = evsel__intval(evsel, &sample, "flags"); + tp_flags = perf_sample__intval(&sample, "flags"); perf_sample__exit(&sample); if (flags != tp_flags) { pr_debug("%s: Expected flags=%#x, got %#x\n", diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index 15791fcb76b2..a7ea4b7874be 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -140,8 +140,8 @@ static int process_sample_event(struct evlist *evlist, evsel = evlist__id2evsel(evlist, sample.id); if (evsel == switch_tracking->switch_evsel) { - next_tid = evsel__intval(evsel, &sample, "next_pid"); - prev_tid = evsel__intval(evsel, &sample, "prev_pid"); + next_tid = perf_sample__intval(&sample, "next_pid"); + prev_tid = perf_sample__intval(&sample, "prev_pid"); cpu = sample.cpu; pr_debug3("sched_switch: cpu: %d prev_tid %d next_tid %d\n", cpu, prev_tid, next_tid); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 29b1df875953..1074eebbda89 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3681,9 +3681,9 @@ struct tep_format_field *evsel__common_field(struct evsel *evsel, const char *na return tp_format ? tep_find_common_field(tp_format, name) : NULL; } -void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name) +void *perf_sample__rawptr(struct perf_sample *sample, const char *name) { - struct tep_format_field *field = evsel__field(evsel, name); + struct tep_format_field *field = evsel__field(sample->evsel, name); int offset; if (!field) @@ -3698,6 +3698,12 @@ void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char offset += field->offset + field->size; } + if ((u32)(offset + field->size) >= sample->raw_size) { + pr_debug("Invalid trace point field offset %d for field of length %d in sample raw data of size %u\n", + offset, field->size, sample->raw_size); + return NULL; + } + return sample->raw_data + offset; } @@ -3740,21 +3746,21 @@ u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sam return 0; } -u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name) +u64 perf_sample__intval(struct perf_sample *sample, const char *name) { - struct tep_format_field *field = evsel__field(evsel, name); + struct tep_format_field *field = evsel__field(sample->evsel, name); - return field ? format_field__intval(field, sample, evsel->needs_swap) : 0; + return field ? format_field__intval(field, sample, sample->evsel->needs_swap) : 0; } -u64 evsel__intval_common(struct evsel *evsel, struct perf_sample *sample, const char *name) +u64 perf_sample__intval_common(struct perf_sample *sample, const char *name) { - struct tep_format_field *field = evsel__common_field(evsel, name); + struct tep_format_field *field = evsel__common_field(sample->evsel, name); - return field ? format_field__intval(field, sample, evsel->needs_swap) : 0; + return field ? format_field__intval(field, sample, sample->evsel->needs_swap) : 0; } -char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const char *name) +char perf_sample__taskstate(struct perf_sample *sample, const char *name) { static struct tep_format_field *prev_state_field; static const char *states; @@ -3763,7 +3769,7 @@ char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const cha unsigned int bit; char state = '?'; /* '?' denotes unknown task state */ - field = evsel__field(evsel, name); + field = evsel__field(sample->evsel, name); if (!field) return state; @@ -3782,7 +3788,7 @@ char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const cha * * We can change this if we have a good reason in the future. */ - val = evsel__intval(evsel, sample, name); + val = perf_sample__intval(sample, name); bit = val ? ffs(val) : 0; state = (!bit || bit > strlen(states)) ? 'R' : states[bit-1]; return state; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index a3d754c029a0..c9d3e6de9677 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -369,14 +369,14 @@ bool evsel__precise_ip_fallback(struct evsel *evsel); struct perf_sample; #ifdef HAVE_LIBTRACEEVENT -void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name); -u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name); -u64 evsel__intval_common(struct evsel *evsel, struct perf_sample *sample, const char *name); -char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const char *name); +void *perf_sample__rawptr(struct perf_sample *sample, const char *name); +u64 perf_sample__intval(struct perf_sample *sample, const char *name); +u64 perf_sample__intval_common(struct perf_sample *sample, const char *name); +char perf_sample__taskstate(struct perf_sample *sample, const char *name); -static inline char *evsel__strval(struct evsel *evsel, struct perf_sample *sample, const char *name) +static inline char *perf_sample__strval(struct perf_sample *sample, const char *name) { - return evsel__rawptr(evsel, sample, name); + return perf_sample__rawptr(sample, name); } #endif diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index fc9eec8b54b8..dab23a96b1d8 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -3426,7 +3426,7 @@ static int intel_pt_process_switch(struct intel_pt *pt, if (evsel != pt->switch_evsel) return 0; - tid = evsel__intval(evsel, sample, "next_pid"); + tid = perf_sample__intval(sample, "next_pid"); cpu = sample->cpu; intel_pt_log("sched_switch: cpu %d tid %d time %"PRIu64" tsc %#"PRIx64"\n", diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c index 1e76906f719c..018b0db0e6e7 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c @@ -20,10 +20,8 @@ static const char * const __kvm_events_tp[] = { static void event_get_key(struct perf_sample *sample, struct event_key *key) { - struct evsel *evsel = sample->evsel; - key->info = 0; - key->key = evsel__intval(evsel, sample, kvm_exit_reason(EM_AARCH64)); + key->key = perf_sample__intval(sample, kvm_exit_reason(EM_AARCH64)); key->exit_reasons = arm64_exit_reasons; /* @@ -32,7 +30,7 @@ static void event_get_key(struct perf_sample *sample, * properly decode event's est_ec. */ if (key->key == ARM_EXCEPTION_TRAP) { - key->key = evsel__intval(evsel, sample, kvm_trap_exit_reason); + key->key = perf_sample__intval(sample, kvm_trap_exit_reason); key->exit_reasons = arm64_trap_exit_reasons; } } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c index 9d6265290f6d..a04cd09e3361 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c @@ -78,7 +78,7 @@ static void event_gspr_get_key(struct perf_sample *sample, struct event_key *key unsigned int insn; key->key = LOONGARCH_EXCEPTION_OTHERS; - insn = evsel__intval(sample->evsel, sample, "inst_word"); + insn = perf_sample__intval(sample, "inst_word"); switch (insn >> 24) { case 0: diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c index 5158d7e88ee6..96d9c4ae0209 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c @@ -32,7 +32,7 @@ static void hcall_event_get_key(struct perf_sample *sample, struct event_key *key) { key->info = 0; - key->key = evsel__intval(sample->evsel, sample, "req"); + key->key = perf_sample__intval(sample, "req"); } static const char *get_hcall_exit_reason(u64 exit_code) diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c index e8db8b4f8e2e..967bba261a47 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c @@ -26,8 +26,7 @@ static void event_get_key(struct perf_sample *sample, int xlen = 64; // TODO: 32-bit support. key->info = 0; - key->key = evsel__intval(sample->evsel, sample, - kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); + key->key = perf_sample__intval(sample, kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); key->exit_reasons = riscv_exit_reasons; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c index 158372ba0205..4771fc69fa39 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c @@ -23,7 +23,7 @@ static void event_icpt_insn_get_key(struct perf_sample *sample, { u64 insn; - insn = evsel__intval(sample->evsel, sample, "instruction"); + insn = perf_sample__intval(sample, "instruction"); key->key = icpt_insn_decoder(insn); key->exit_reasons = sie_icpt_insn_codes; } @@ -31,21 +31,21 @@ static void event_icpt_insn_get_key(struct perf_sample *sample, static void event_sigp_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "order_code"); + key->key = perf_sample__intval(sample, "order_code"); key->exit_reasons = sie_sigp_order_codes; } static void event_diag_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "code"); + key->key = perf_sample__intval(sample, "code"); key->exit_reasons = sie_diagnose_codes; } static void event_icpt_prog_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "code"); + key->key = perf_sample__intval(sample, "code"); key->exit_reasons = sie_icpt_prog_codes; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c index 0ce543d82850..788d216f0852 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c @@ -27,8 +27,8 @@ static const struct kvm_events_ops exit_events = { static void mmio_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "gpa"); - key->info = evsel__intval(sample->evsel, sample, "type"); + key->key = perf_sample__intval(sample, "gpa"); + key->info = perf_sample__intval(sample, "type"); } #define KVM_TRACE_MMIO_READ_UNSATISFIED 0 @@ -43,7 +43,7 @@ static bool mmio_event_begin(struct perf_sample *sample, struct event_key *key) /* MMIO write begin event in kernel. */ if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && - evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { + perf_sample__intval(sample, "type") == KVM_TRACE_MMIO_WRITE) { mmio_event_get_key(sample, key); return true; } @@ -59,7 +59,7 @@ static bool mmio_event_end(struct perf_sample *sample, struct event_key *key) /* MMIO read end event in kernel.*/ if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && - evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_READ) { + perf_sample__intval(sample, "type") == KVM_TRACE_MMIO_READ) { mmio_event_get_key(sample, key); return true; } @@ -87,8 +87,8 @@ static const struct kvm_events_ops mmio_events = { static void ioport_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "port"); - key->info = evsel__intval(sample->evsel, sample, "rw"); + key->key = perf_sample__intval(sample, "port"); + key->info = perf_sample__intval(sample, "rw"); } static bool ioport_event_begin(struct perf_sample *sample, @@ -126,8 +126,8 @@ static const struct kvm_events_ops ioport_events = { /* The time of emulation msr is from kvm_msr to kvm_entry. */ static void msr_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "ecx"); - key->info = evsel__intval(sample->evsel, sample, "write"); + key->key = perf_sample__intval(sample, "ecx"); + key->info = perf_sample__intval(sample, "write"); } static bool msr_event_begin(struct perf_sample *sample, struct event_key *key) diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c index f17a6132958d..755ab659a05c 100644 --- a/tools/perf/util/kvm-stat.c +++ b/tools/perf/util/kvm-stat.c @@ -17,7 +17,7 @@ void exit_event_get_key(struct perf_sample *sample, uint16_t e_machine = evsel__e_machine(sample->evsel, /*e_flags=*/NULL); key->info = 0; - key->key = evsel__intval(sample->evsel, sample, kvm_exit_reason(e_machine)); + key->key = perf_sample__intval(sample, kvm_exit_reason(e_machine)); } -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 07/25] perf trace: Don't pass evsel with sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (5 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 08/25] perf callchain: Don't pass evsel and sample Ian Rogers ` (18 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample now contains the evsel and so don't unnecessarily pass the evsel. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-trace.c | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 493eecf218b4..33199ff2bbfd 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -535,12 +535,12 @@ static struct evsel *perf_evsel__raw_syscall_newtp(const char *direction, void * return NULL; } -#define perf_evsel__sc_tp_uint(evsel, name, sample) \ - ({ struct syscall_tp *fields = __evsel__syscall_tp(evsel); \ +#define perf_evsel__sc_tp_uint(name, sample) \ + ({ struct syscall_tp *fields = __evsel__syscall_tp(sample->evsel); \ fields->name.integer(&fields->name, sample); }) -#define perf_evsel__sc_tp_ptr(evsel, name, sample) \ - ({ struct syscall_tp *fields = __evsel__syscall_tp(evsel); \ +#define perf_evsel__sc_tp_ptr(name, sample) \ + ({ struct syscall_tp *fields = __evsel__syscall_tp(sample->evsel); \ fields->name.pointer(&fields->name, sample); }) size_t strarray__scnprintf_suffix(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_suffix, int val) @@ -2719,8 +2719,8 @@ static int trace__printf_interrupted_entry(struct trace *trace) return printed; } -static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, - struct perf_sample *sample, struct thread *thread) +static int trace__fprintf_sample(struct trace *trace, struct perf_sample *sample, + struct thread *thread) { int printed = 0; @@ -2728,7 +2728,7 @@ static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, double ts = (double)sample->time / NSEC_PER_MSEC; printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n", - evsel__name(evsel), ts, + evsel__name(sample->evsel), ts, thread__comm_str(thread), sample->pid, sample->tid, sample->cpu); } @@ -2783,7 +2783,7 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel, void *args; int printed = 0; struct thread *thread; - int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; + int id = perf_evsel__sc_tp_uint(id, sample), err = -1; int augmented_args_size = 0, e_machine; void *augmented_args = NULL; struct syscall *sc; @@ -2798,9 +2798,9 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel, if (ttrace == NULL) goto out_put; - trace__fprintf_sample(trace, evsel, sample, thread); + trace__fprintf_sample(trace, sample, thread); - args = perf_evsel__sc_tp_ptr(evsel, args, sample); + args = perf_evsel__sc_tp_ptr(args, sample); if (ttrace->entry_str == NULL) { ttrace->entry_str = malloc(trace__entry_str_size); @@ -2855,12 +2855,11 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel, return err; } -static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, - struct perf_sample *sample) +static int trace__fprintf_sys_enter(struct trace *trace, struct perf_sample *sample) { struct thread_trace *ttrace; struct thread *thread; - int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; + int id = perf_evsel__sc_tp_uint(id, sample), err = -1; struct syscall *sc; char msg[1024]; void *args, *augmented_args = NULL; @@ -2870,7 +2869,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); e_machine = thread__e_machine(thread, trace->host, /*e_flags=*/NULL); - sc = trace__syscall_info(trace, evsel, e_machine, id); + sc = trace__syscall_info(trace, sample->evsel, e_machine, id); if (sc == NULL) goto out_put; ttrace = thread__trace(thread, trace); @@ -2881,7 +2880,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, if (ttrace == NULL) goto out_put; - args = perf_evsel__sc_tp_ptr(evsel, args, sample); + args = perf_evsel__sc_tp_ptr(args, sample); augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_syscalls_args_size); printed += syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread); fprintf(trace->output, "%.*s", (int)printed, msg); @@ -2891,10 +2890,11 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, return err; } -static int trace__resolve_callchain(struct trace *trace, struct evsel *evsel, +static int trace__resolve_callchain(struct trace *trace, struct perf_sample *sample, struct callchain_cursor *cursor) { + struct evsel *evsel = sample->evsel; struct addr_location al; int max_stack = evsel->core.attr.sample_max_stack ? evsel->core.attr.sample_max_stack : @@ -2929,7 +2929,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, u64 duration = 0; bool duration_calculated = false; struct thread *thread; - int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1, callchain_ret = 0, printed = 0; + int id = perf_evsel__sc_tp_uint(id, sample), err = -1, callchain_ret = 0, printed = 0; int alignment = trace->args_alignment, e_machine; struct syscall *sc; struct thread_trace *ttrace; @@ -2943,9 +2943,9 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, if (ttrace == NULL) goto out_put; - trace__fprintf_sample(trace, evsel, sample, thread); + trace__fprintf_sample(trace, sample, thread); - ret = perf_evsel__sc_tp_uint(evsel, ret, sample); + ret = perf_evsel__sc_tp_uint(ret, sample); if (trace->summary) thread__update_stats(thread, ttrace, id, sample, ret, trace); @@ -2967,7 +2967,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, if (sample->callchain) { struct callchain_cursor *cursor = get_tls_callchain_cursor(); - callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret = trace__resolve_callchain(trace, sample, cursor); if (callchain_ret == 0) { if (cursor->nr < trace->min_stack) goto out; @@ -3182,9 +3182,10 @@ static void bpf_output__fprintf(struct trace *trace, ++trace->nr_events_printed; } -static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample *sample, +static size_t trace__fprintf_tp_fields(struct trace *trace, struct perf_sample *sample, struct thread *thread, void *augmented_args, int augmented_args_size) { + struct evsel *evsel = sample->evsel; char bf[2048]; size_t size = sizeof(bf); const struct tep_event *tp_format = evsel__tp_format(evsel); @@ -3267,7 +3268,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, if (sample->callchain) { struct callchain_cursor *cursor = get_tls_callchain_cursor(); - callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret = trace__resolve_callchain(trace, sample, cursor); if (callchain_ret == 0) { if (cursor->nr < trace->min_stack) goto out; @@ -3285,7 +3286,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, trace__fprintf_comm_tid(trace, thread, trace->output); if (evsel == trace->syscalls.events.bpf_output) { - int id = perf_evsel__sc_tp_uint(evsel, id, sample); + int id = perf_evsel__sc_tp_uint(id, sample); int e_machine = thread ? thread__e_machine(thread, trace->host, /*e_flags=*/NULL) : EM_HOST; @@ -3293,7 +3294,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, if (sc) { fprintf(trace->output, "%s(", sc->name); - trace__fprintf_sys_enter(trace, evsel, sample); + trace__fprintf_sys_enter(trace, sample); fputc(')', trace->output); goto newline; } @@ -3313,13 +3314,13 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, const struct tep_event *tp_format = evsel__tp_format(evsel); if (tp_format && (strncmp(tp_format->name, "sys_enter_", 10) || - trace__fprintf_sys_enter(trace, evsel, sample))) { + trace__fprintf_sys_enter(trace, sample))) { if (trace->libtraceevent_print) { event_format__fprintf(tp_format, sample->cpu, sample->raw_data, sample->raw_size, trace->output); } else { - trace__fprintf_tp_fields(trace, evsel, sample, thread, NULL, 0); + trace__fprintf_tp_fields(trace, sample, thread, NULL, 0); } } } @@ -3378,7 +3379,7 @@ static int trace__pgfault(struct trace *trace, if (sample->callchain) { struct callchain_cursor *cursor = get_tls_callchain_cursor(); - callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret = trace__resolve_callchain(trace, sample, cursor); if (callchain_ret == 0) { if (cursor->nr < trace->min_stack) goto out_put; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 08/25] perf callchain: Don't pass evsel and sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (6 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 07/25] perf trace: Don't pass evsel with sample Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 09/25] perf lock: Only pass sample to handlers Ian Rogers ` (17 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Change callchain resolve code to not pass an evsel with the sample, instead just read the evsel from the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-inject.c | 4 ++-- tools/perf/builtin-kmem.c | 6 ++--- tools/perf/builtin-kwork.c | 5 ++-- tools/perf/builtin-lock.c | 24 +++++++++---------- tools/perf/builtin-sched.c | 5 ++-- tools/perf/builtin-script.c | 6 ++--- tools/perf/builtin-trace.c | 2 +- tools/perf/util/build-id.c | 2 +- tools/perf/util/callchain.c | 8 +++---- tools/perf/util/callchain.h | 5 ++-- tools/perf/util/db-export.c | 8 +++---- tools/perf/util/hist.c | 2 +- tools/perf/util/machine.c | 14 +++++------ tools/perf/util/machine.h | 3 --- .../util/scripting-engines/trace-event-perl.c | 4 ++-- .../scripting-engines/trace-event-python.c | 4 ++-- 17 files changed, 48 insertions(+), 56 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 89456ba6fcbb..f9ac871264af 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -339,7 +339,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, cursor = get_tls_callchain_cursor(); ret = sample__resolve_callchain(sample, cursor, NULL, - evsel, &al, sysctl_perf_event_max_stack); + &al, sysctl_perf_event_max_stack); if (ret) goto out; diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index d03d38a18aa0..1b873377c6ad 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -418,7 +418,7 @@ static int perf_event__convert_sample_callchain(const struct perf_tool *tool, goto out; /* this will parse DWARF using stack and register data */ - ret = thread__resolve_callchain(thread, cursor, evsel, sample, + ret = thread__resolve_callchain(thread, cursor, sample, /*parent=*/NULL, /*root_al=*/NULL, PERF_MAX_STACK_DEPTH); thread__put(thread); @@ -1020,7 +1020,7 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e /*sample_in_dso=*/true); } - sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, &args); sample->evsel = saved_evsel; thread__put(thread); diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 7e6b976a2cab..df3bfb8fd9c0 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -394,7 +394,7 @@ static int build_alloc_func_list(void) * Find first non-memory allocation function from callchain. * The allocation functions are in the 'alloc_func_list'. */ -static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample) +static u64 find_callsite(struct perf_sample *sample) { struct addr_location al; struct machine *machine = &kmem_session->machines.host; @@ -414,7 +414,7 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample) if (cursor == NULL) goto out; - sample__resolve_callchain(sample, cursor, NULL, evsel, &al, 16); + sample__resolve_callchain(sample, cursor, /*parent=*/NULL, &al, 16); callchain_cursor_commit(cursor); while (true) { @@ -848,7 +848,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) return -1; - callsite = find_callsite(evsel, sample); + callsite = find_callsite(sample); /* * This is to find the current page (with correct gfp flags and diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 111ae53025d1..043da61cdcef 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -688,7 +688,6 @@ static int latency_entry_event(struct perf_kwork *kwork, static void timehist_save_callchain(struct perf_kwork *kwork, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct symbol *sym; @@ -708,7 +707,7 @@ static void timehist_save_callchain(struct perf_kwork *kwork, cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(thread, cursor, evsel, sample, + if (thread__resolve_callchain(thread, cursor, sample, NULL, NULL, kwork->max_stack + 2) != 0) { pr_debug("Failed to resolve callchain, skipping\n"); goto out_put; @@ -838,7 +837,7 @@ static int timehist_entry_event(struct perf_kwork *kwork, return ret; if (work != NULL) - timehist_save_callchain(kwork, sample, evsel, machine); + timehist_save_callchain(kwork, sample, machine); return 0; } diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index baf0c99df5df..a35e8ea4e2ef 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -551,13 +551,13 @@ static int get_key_by_aggr_mode_simple(u64 *key, u64 addr, u32 tid) return 0; } -static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample); +static u64 callchain_id(struct perf_sample *sample); -static int get_key_by_aggr_mode(u64 *key, u64 addr, struct evsel *evsel, +static int get_key_by_aggr_mode(u64 *key, u64 addr, struct perf_sample *sample) { if (aggr_mode == LOCK_AGGR_CALLER) { - *key = callchain_id(evsel, sample); + *key = callchain_id(sample); return 0; } return get_key_by_aggr_mode_simple(key, addr, sample->tid); @@ -841,7 +841,7 @@ static int get_symbol_name_offset(struct map *map, struct symbol *sym, u64 ip, else return strlcpy(buf, sym->name, size); } -static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sample, +static int lock_contention_caller(struct perf_sample *sample, char *buf, int size) { struct thread *thread; @@ -862,7 +862,7 @@ static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sampl cursor = get_tls_callchain_cursor(); /* use caller function name from the callchain */ - ret = thread__resolve_callchain(thread, cursor, evsel, sample, + ret = thread__resolve_callchain(thread, cursor, sample, NULL, NULL, max_stack_depth); if (ret != 0) { thread__put(thread); @@ -896,7 +896,7 @@ static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sampl return -1; } -static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample) +static u64 callchain_id(struct perf_sample *sample) { struct callchain_cursor *cursor; struct machine *machine = &session->machines.host; @@ -911,7 +911,7 @@ static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample) cursor = get_tls_callchain_cursor(); /* use caller function name from the callchain */ - ret = thread__resolve_callchain(thread, cursor, evsel, sample, + ret = thread__resolve_callchain(thread, cursor, sample, NULL, NULL, max_stack_depth); thread__put(thread); @@ -963,7 +963,7 @@ static u64 *get_callstack(struct perf_sample *sample, int max_stack) return callstack; } -static int report_lock_contention_begin_event(struct evsel *evsel, +static int report_lock_contention_begin_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; @@ -978,7 +978,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, struct map *kmap; struct symbol *sym; - ret = get_key_by_aggr_mode(&key, addr, evsel, sample); + ret = get_key_by_aggr_mode(&key, addr, sample); if (ret < 0) return ret; @@ -1025,7 +1025,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, break; case LOCK_AGGR_CALLER: name = buf; - if (lock_contention_caller(evsel, sample, buf, sizeof(buf)) < 0) + if (lock_contention_caller(sample, buf, sizeof(buf)) < 0) name = "Unknown"; break; case LOCK_AGGR_CGROUP: @@ -1127,7 +1127,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, return 0; } -static int report_lock_contention_end_event(struct evsel *evsel, +static int report_lock_contention_end_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; @@ -1138,7 +1138,7 @@ static int report_lock_contention_end_event(struct evsel *evsel, u64 key; int ret; - ret = get_key_by_aggr_mode(&key, addr, evsel, sample); + ret = get_key_by_aggr_mode(&key, addr, sample); if (ret < 0) return ret; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 3e7e8ad0bc13..b6271a5ec8de 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -2330,7 +2330,6 @@ static bool is_idle_sample(struct perf_sample *sample, static void save_task_callchain(struct perf_sched *sched, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct callchain_cursor *cursor; @@ -2350,7 +2349,7 @@ static void save_task_callchain(struct perf_sched *sched, cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(thread, cursor, evsel, sample, + if (thread__resolve_callchain(thread, cursor, sample, NULL, NULL, sched->max_stack + 2) != 0) { if (verbose > 0) pr_err("Failed to resolve callchain. Skipping\n"); @@ -2524,7 +2523,7 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, sample->tid); } - save_task_callchain(sched, sample, evsel, machine); + save_task_callchain(sched, sample, machine); if (sched->idle_hist) { struct thread *idle; struct idle_thread_runtime *itr; diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8724c4ab3e88..8022801721e2 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1683,7 +1683,7 @@ static int perf_sample__fprintf_bts(struct perf_sample *sample, if (symbol_conf.use_callchain && sample->callchain) { cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack)) cursor = NULL; @@ -2506,7 +2506,7 @@ static void process_event(struct perf_script *script, if (symbol_conf.use_callchain && sample->callchain) { cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack)) cursor = NULL; @@ -2790,7 +2790,7 @@ static int process_deferred_sample_event(const struct perf_tool *tool, if (symbol_conf.use_callchain && sample->callchain) { cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al.thread, cursor, evsel, + if (thread__resolve_callchain(al.thread, cursor, sample, NULL, NULL, scripting_max_stack)) { pr_info("cannot resolve deferred callchains\n"); diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 33199ff2bbfd..385a9ac2ae96 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2905,7 +2905,7 @@ static int trace__resolve_callchain(struct trace *trace, if (machine__resolve(trace->host, &al, sample) < 0) goto out; - err = thread__resolve_callchain(al.thread, cursor, evsel, sample, NULL, NULL, max_stack); + err = thread__resolve_callchain(al.thread, cursor, sample, NULL, NULL, max_stack); out: addr_location__exit(&al); return err; diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 55b72235f891..af4d874f1381 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -73,7 +73,7 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, addr_location__exit(&al); - sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, /*data=*/NULL); diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 94ae45fd1f27..32ef786abd1f 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1123,7 +1123,7 @@ int callchain_cursor_append(struct callchain_cursor *cursor, int sample__resolve_callchain(struct perf_sample *sample, struct callchain_cursor *cursor, struct symbol **parent, - struct evsel *evsel, struct addr_location *al, + struct addr_location *al, int max_stack) { if (sample->callchain == NULL && !symbol_conf.show_branchflag_count) @@ -1131,7 +1131,7 @@ int sample__resolve_callchain(struct perf_sample *sample, if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain || perf_hpp_list.parent || symbol_conf.show_branchflag_count) { - return thread__resolve_callchain(al->thread, cursor, evsel, sample, + return thread__resolve_callchain(al->thread, cursor, sample, parent, al, max_stack); } return 0; @@ -1806,7 +1806,7 @@ s64 callchain_avg_cycles(struct callchain_node *cnode) return cycles; } -int sample__for_each_callchain_node(struct thread *thread, struct evsel *evsel, +int sample__for_each_callchain_node(struct thread *thread, struct perf_sample *sample, int max_stack, bool symbols, callchain_iter_fn cb, void *data) { @@ -1817,7 +1817,7 @@ int sample__for_each_callchain_node(struct thread *thread, struct evsel *evsel, return -ENOMEM; /* Fill in the callchain. */ - ret = __thread__resolve_callchain(thread, cursor, evsel, sample, + ret = __thread__resolve_callchain(thread, cursor, sample, /*parent=*/NULL, /*root_al=*/NULL, max_stack, symbols); if (ret) diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index df54ddb8c0cb..6eb3e20349a9 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -8,7 +8,6 @@ #include "branch.h" struct addr_location; -struct evsel; struct ip_callchain; struct map; struct perf_sample; @@ -251,7 +250,7 @@ int record_opts__parse_callchain(struct record_opts *record, int sample__resolve_callchain(struct perf_sample *sample, struct callchain_cursor *cursor, struct symbol **parent, - struct evsel *evsel, struct addr_location *al, + struct addr_location *al, int max_stack); int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample); int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node, @@ -314,7 +313,7 @@ s64 callchain_avg_cycles(struct callchain_node *cnode); typedef int (*callchain_iter_fn)(struct callchain_cursor_node *node, void *data); -int sample__for_each_callchain_node(struct thread *thread, struct evsel *evsel, +int sample__for_each_callchain_node(struct thread *thread, struct perf_sample *sample, int max_stack, bool symbols, callchain_iter_fn cb, void *data); diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index ae9a9065aab7..a1f578c3a8d5 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -209,8 +209,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al, static struct call_path *call_path_from_sample(struct db_export *dbe, struct machine *machine, struct thread *thread, - struct perf_sample *sample, - struct evsel *evsel) + struct perf_sample *sample) { u64 kernel_start = machine__kernel_start(machine); struct call_path *current = &dbe->cpr->call_path; @@ -228,7 +227,7 @@ static struct call_path *call_path_from_sample(struct db_export *dbe, */ callchain_param.order = ORDER_CALLER; cursor = get_tls_callchain_cursor(); - err = thread__resolve_callchain(thread, cursor, evsel, + err = thread__resolve_callchain(thread, cursor, sample, NULL, NULL, PERF_MAX_STACK_DEPTH); if (err) { callchain_param.order = saved_order; @@ -391,8 +390,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, if (dbe->cpr) { struct call_path *cp = call_path_from_sample(dbe, machine, - thread, sample, - evsel); + thread, sample); if (cp) { db_export__call_path(dbe, cp); es.call_path_id = cp->db_id; diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 7ffaa3d9851b..84a402d248a3 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -1339,7 +1339,7 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, alm = map__get(al->map); err = sample__resolve_callchain(iter->sample, get_tls_callchain_cursor(), &iter->parent, - iter->evsel, al, max_stack_depth); + al, max_stack_depth); if (err) { map__put(alm); return err; diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index e76f8c86e62a..c2e0a99efe97 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2778,13 +2778,13 @@ static u64 get_leaf_frame_caller(struct perf_sample *sample, static int thread__resolve_callchain_sample(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, int max_stack, bool symbols) { + struct evsel *evsel = sample->evsel; struct branch_stack *branch = sample->branch_stack; struct branch_entry *entries = perf_sample__branch_entries(sample); struct ip_callchain *chain = sample->callchain; @@ -2986,10 +2986,11 @@ static int unwind_entry(struct unwind_entry *entry, void *arg) static int thread__resolve_callchain_unwind(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, int max_stack, bool symbols) { + struct evsel *evsel = sample->evsel; + /* Can we do dwarf post unwind? */ if (!((evsel->core.attr.sample_type & PERF_SAMPLE_REGS_USER) && (evsel->core.attr.sample_type & PERF_SAMPLE_STACK_USER))) @@ -3009,7 +3010,6 @@ static int thread__resolve_callchain_unwind(struct thread *thread, int __thread__resolve_callchain(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, @@ -3025,22 +3025,22 @@ int __thread__resolve_callchain(struct thread *thread, if (callchain_param.order == ORDER_CALLEE) { ret = thread__resolve_callchain_sample(thread, cursor, - evsel, sample, + sample, parent, root_al, max_stack, symbols); if (ret) return ret; ret = thread__resolve_callchain_unwind(thread, cursor, - evsel, sample, + sample, max_stack, symbols); } else { ret = thread__resolve_callchain_unwind(thread, cursor, - evsel, sample, + sample, max_stack, symbols); if (ret) return ret; ret = thread__resolve_callchain_sample(thread, cursor, - evsel, sample, + sample, parent, root_al, max_stack, symbols); } diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index 22a42c5825fa..048b24e9bd38 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -187,7 +187,6 @@ struct callchain_cursor; int __thread__resolve_callchain(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, @@ -196,7 +195,6 @@ int __thread__resolve_callchain(struct thread *thread, static inline int thread__resolve_callchain(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, @@ -204,7 +202,6 @@ static inline int thread__resolve_callchain(struct thread *thread, { return __thread__resolve_callchain(thread, cursor, - evsel, sample, parent, root_al, diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index e261a57b87d4..af0d514b2397 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -257,7 +257,7 @@ static void define_event_symbols(struct tep_event *event, } static SV *perl_process_callchain(struct perf_sample *sample, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct addr_location *al) { struct callchain_cursor *cursor; @@ -272,7 +272,7 @@ static SV *perl_process_callchain(struct perf_sample *sample, cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack) != 0) { pr_err("Failed to resolve callchain. Skipping\n"); goto exit; diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 2b0df7bd9a46..08197cef44c8 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -390,7 +390,7 @@ static unsigned long get_offset(struct symbol *sym, struct addr_location *al) } static PyObject *python_process_callchain(struct perf_sample *sample, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct addr_location *al) { PyObject *pylist; @@ -404,7 +404,7 @@ static PyObject *python_process_callchain(struct perf_sample *sample, goto exit; cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack) != 0) { pr_err("Failed to resolve callchain. Skipping\n"); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 09/25] perf lock: Only pass sample to handlers 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (7 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 08/25] perf callchain: Don't pass evsel and sample Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 10/25] perf lock: Constify trace_lock_handler variables Ian Rogers ` (16 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The evsel is within the sample and so only the sample needs to be passed. Remove the parameter and fix call site. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-lock.c | 65 ++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index a35e8ea4e2ef..78fb39d06e7c 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -473,28 +473,22 @@ static struct lock_stat *pop_from_result(void) struct trace_lock_handler { /* it's used on CONFIG_LOCKDEP */ - int (*acquire_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*acquire_event)(struct perf_sample *sample); /* it's used on CONFIG_LOCKDEP && CONFIG_LOCK_STAT */ - int (*acquired_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*acquired_event)(struct perf_sample *sample); /* it's used on CONFIG_LOCKDEP && CONFIG_LOCK_STAT */ - int (*contended_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*contended_event)(struct perf_sample *sample); /* it's used on CONFIG_LOCKDEP */ - int (*release_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*release_event)(struct perf_sample *sample); /* it's used when CONFIG_LOCKDEP is off */ - int (*contention_begin_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*contention_begin_event)(struct perf_sample *sample); /* it's used when CONFIG_LOCKDEP is off */ - int (*contention_end_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*contention_end_event)(struct perf_sample *sample); }; static struct lock_seq_stat *get_seq(struct thread_stat *ts, u64 addr) @@ -563,8 +557,7 @@ static int get_key_by_aggr_mode(u64 *key, u64 addr, return get_key_by_aggr_mode_simple(key, addr, sample->tid); } -static int report_lock_acquire_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_acquire_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -638,8 +631,7 @@ static int report_lock_acquire_event(struct evsel *evsel __maybe_unused, return 0; } -static int report_lock_acquired_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_acquired_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -704,8 +696,7 @@ static int report_lock_acquired_event(struct evsel *evsel __maybe_unused, return 0; } -static int report_lock_contended_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_contended_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -762,8 +753,7 @@ static int report_lock_contended_event(struct evsel *evsel __maybe_unused, return 0; } -static int report_lock_release_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_release_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -963,8 +953,7 @@ static u64 *get_callstack(struct perf_sample *sample, int max_stack) return callstack; } -static int report_lock_contention_begin_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_contention_begin_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -1127,8 +1116,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel __maybe_unused return 0; } -static int report_lock_contention_end_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_contention_end_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -1208,45 +1196,45 @@ static struct trace_lock_handler contention_lock_ops = { static struct trace_lock_handler *trace_handler; -static int evsel__process_lock_acquire(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_acquire(struct perf_sample *sample) { if (trace_handler->acquire_event) - return trace_handler->acquire_event(evsel, sample); + return trace_handler->acquire_event(sample); return 0; } -static int evsel__process_lock_acquired(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_acquired(struct perf_sample *sample) { if (trace_handler->acquired_event) - return trace_handler->acquired_event(evsel, sample); + return trace_handler->acquired_event(sample); return 0; } -static int evsel__process_lock_contended(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_contended(struct perf_sample *sample) { if (trace_handler->contended_event) - return trace_handler->contended_event(evsel, sample); + return trace_handler->contended_event(sample); return 0; } -static int evsel__process_lock_release(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_release(struct perf_sample *sample) { if (trace_handler->release_event) - return trace_handler->release_event(evsel, sample); + return trace_handler->release_event(sample); return 0; } -static int evsel__process_contention_begin(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_contention_begin(struct perf_sample *sample) { if (trace_handler->contention_begin_event) - return trace_handler->contention_begin_event(evsel, sample); + return trace_handler->contention_begin_event(sample); return 0; } -static int evsel__process_contention_end(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_contention_end(struct perf_sample *sample) { if (trace_handler->contention_end_event) - return trace_handler->contention_end_event(evsel, sample); + return trace_handler->contention_end_event(sample); return 0; } @@ -1424,8 +1412,7 @@ static int process_event_update(const struct perf_tool *tool, return 0; } -typedef int (*tracepoint_handler)(struct evsel *evsel, - struct perf_sample *sample); +typedef int (*tracepoint_handler)(struct perf_sample *sample); static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, @@ -1445,7 +1432,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(evsel, sample); + err = f(sample); } thread__put(thread); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 10/25] perf lock: Constify trace_lock_handler variables 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (8 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 09/25] perf lock: Only pass sample to handlers Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 11/25] perf hist: Remove evsel parameter from inc samples functions Ian Rogers ` (15 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Structs don't change and so constify. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-lock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 78fb39d06e7c..735e6bb234ae 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1179,7 +1179,7 @@ static int report_lock_contention_end_event(struct perf_sample *sample) /* lock oriented handlers */ /* TODO: handlers for CPU oriented, thread oriented */ -static struct trace_lock_handler report_lock_ops = { +static const struct trace_lock_handler report_lock_ops = { .acquire_event = report_lock_acquire_event, .acquired_event = report_lock_acquired_event, .contended_event = report_lock_contended_event, @@ -1188,13 +1188,13 @@ static struct trace_lock_handler report_lock_ops = { .contention_end_event = report_lock_contention_end_event, }; -static struct trace_lock_handler contention_lock_ops = { +static const struct trace_lock_handler contention_lock_ops = { .contention_begin_event = report_lock_contention_begin_event, .contention_end_event = report_lock_contention_end_event, }; -static struct trace_lock_handler *trace_handler; +static const struct trace_lock_handler *trace_handler; static int evsel__process_lock_acquire(struct perf_sample *sample) { -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 11/25] perf hist: Remove evsel parameter from inc samples functions 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (9 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 10/25] perf lock: Constify trace_lock_handler variables Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 12/25] perf db-export: Remove evsel from struct export_sample Ian Rogers ` (14 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan hist_entry__inc_addr_samples and addr_map_symbol__inc_samples unnecessarily take an evsel argument. Read the evsel from the sample instead. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 7 +++---- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-report.c | 18 ++++++++---------- tools/perf/builtin-top.c | 6 +++--- tools/perf/util/annotate.c | 19 +++++++++---------- tools/perf/util/annotate.h | 6 ++---- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index c97a0fe159f8..c2d0599fe5f5 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -177,16 +177,15 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, struct hist_entry *he = iter->he; struct branch_info *bi; struct perf_sample *sample = iter->sample; - struct evsel *evsel = iter->evsel; int err; bi = he->branch_info; - err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; - err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->to, sample); out: return err; @@ -276,7 +275,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, if (he == NULL) return -ENOMEM; - ret = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + ret = hist_entry__inc_addr_samples(he, sample, al->addr); hists__inc_nr_samples(hists, true); return ret; } diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index f9ac871264af..5684c14c2bf6 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -371,7 +371,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, if (perf_c2c__has_annotation(NULL)) { perf_c2c__evsel_hists_inc_stats(evsel, he, sample); - addr_map_symbol__inc_samples(mem_info__iaddr(mi), sample, evsel); + addr_map_symbol__inc_samples(mem_info__iaddr(mi), sample); } ret = hist_entry__append_callchain(he, sample); diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 507002cbdd5b..39968ae5cfb0 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -170,7 +170,6 @@ static int hist_iter__report_callback(struct hist_entry_iter *iter, int err = 0; struct report *rep = arg; struct hist_entry *he = iter->he; - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; struct mem_info *mi; struct branch_info *bi; @@ -180,25 +179,25 @@ static int hist_iter__report_callback(struct hist_entry_iter *iter, if (sort__mode == SORT_MODE__BRANCH) { bi = he->branch_info; - err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; - err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->to, sample); } else if (rep->mem_mode) { mi = he->mem_info; - err = addr_map_symbol__inc_samples(mem_info__daddr(mi), sample, evsel); + err = addr_map_symbol__inc_samples(mem_info__daddr(mi), sample); if (err) goto out; - err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err = hist_entry__inc_addr_samples(he, sample, al->addr); } else if (symbol_conf.cumulate_callchain) { if (single) - err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err = hist_entry__inc_addr_samples(he, sample, al->addr); } else { - err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err = hist_entry__inc_addr_samples(he, sample, al->addr); } out: @@ -214,7 +213,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, struct report *rep = arg; struct branch_info *bi = he->branch_info; struct perf_sample *sample = iter->sample; - struct evsel *evsel = iter->evsel; int err; branch_type_count(&rep->brtype_stat, &bi->flags, @@ -223,11 +221,11 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, if (!ui__has_annotation() && !rep->symbol_ipc) return 0; - err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; - err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->to, sample); out: return err; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 710604c4f6f6..e863f9ef581f 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -198,7 +198,7 @@ static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip) static void perf_top__record_precise_ip(struct perf_top *top, struct hist_entry *he, struct perf_sample *sample, - struct evsel *evsel, u64 ip) + u64 ip) EXCLUSIVE_LOCKS_REQUIRED(he->hists->lock) { struct annotation *notes; @@ -215,7 +215,7 @@ static void perf_top__record_precise_ip(struct perf_top *top, if (!annotation__trylock(notes)) return; - err = hist_entry__inc_addr_samples(he, sample, evsel, ip); + err = hist_entry__inc_addr_samples(he, sample, ip); annotation__unlock(notes); @@ -734,7 +734,7 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter, struct evsel *evsel = iter->evsel; if (perf_hpp_list.sym && single) - perf_top__record_precise_ip(top, iter->he, iter->sample, evsel, al->addr); + perf_top__record_precise_ip(top, iter->he, iter->sample, al->addr); hist__account_cycles(iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY), diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 2e3522905046..15ff0443c312 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -211,9 +211,10 @@ static int __symbol__account_cycles(struct cyc_hist *ch, } static int __symbol__inc_addr_samples(struct map_symbol *ms, - struct annotated_source *src, struct evsel *evsel, u64 addr, + struct annotated_source *src, u64 addr, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; struct symbol *sym = ms->sym; long hash_key; u64 offset; @@ -316,7 +317,7 @@ struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists) } static int symbol__inc_addr_samples(struct map_symbol *ms, - struct evsel *evsel, u64 addr, + u64 addr, struct perf_sample *sample) { struct symbol *sym = ms->sym; @@ -324,8 +325,8 @@ static int symbol__inc_addr_samples(struct map_symbol *ms, if (sym == NULL) return 0; - src = symbol__hists(sym, evsel->evlist->core.nr_entries); - return src ? __symbol__inc_addr_samples(ms, src, evsel, addr, sample) : 0; + src = symbol__hists(sym, sample->evsel->evlist->core.nr_entries); + return src ? __symbol__inc_addr_samples(ms, src, addr, sample) : 0; } static int symbol__account_br_cntr(struct annotated_branch *branch, @@ -579,16 +580,14 @@ static int annotation__compute_ipc(struct annotation *notes, size_t size, return 0; } -int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample, - struct evsel *evsel) +int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample) { - return symbol__inc_addr_samples(&ams->ms, evsel, ams->al_addr, sample); + return symbol__inc_addr_samples(&ams->ms, ams->al_addr, sample); } -int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, - struct evsel *evsel, u64 ip) +int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, u64 ip) { - return symbol__inc_addr_samples(&he->ms, evsel, ip, sample); + return symbol__inc_addr_samples(&he->ms, ip, sample); } diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 696e36dbf013..1aa6df7d1618 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -422,8 +422,7 @@ static inline struct annotation *symbol__annotation(struct symbol *sym) return (void *)sym - symbol_conf.priv_size; } -int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample, - struct evsel *evsel); +int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample); struct annotated_branch *annotation__get_branch(struct annotation *notes); @@ -433,8 +432,7 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams, struct evsel *evsel, u64 br_cntr); -int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, - struct evsel *evsel, u64 addr); +int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, u64 addr); struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists); void symbol__annotate_zero_histograms(struct symbol *sym); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 12/25] perf db-export: Remove evsel from struct export_sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (10 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 11/25] perf hist: Remove evsel parameter from inc samples functions Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 13/25] perf hist: Remove evsel from struct hist_entry_iter Ian Rogers ` (13 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan As the sample contains the evsel avoid the duplication. Remove the evsel from db_export__sample as it can also read from the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/db-export.c | 5 ++--- tools/perf/util/db-export.h | 3 +-- tools/perf/util/scripting-engines/trace-event-python.c | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index a1f578c3a8d5..fdfd825c7ef4 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -345,14 +345,13 @@ static int db_export__threads(struct db_export *dbe, struct thread *thread, } int db_export__sample(struct db_export *dbe, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al) { struct thread *thread = al->thread; struct export_sample es = { .event = event, .sample = sample, - .evsel = evsel, .al = al, }; struct thread *main_thread; @@ -365,7 +364,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, if (!machine) return -1; - err = db_export__evsel(dbe, evsel); + err = db_export__evsel(dbe, sample->evsel); if (err) return err; diff --git a/tools/perf/util/db-export.h b/tools/perf/util/db-export.h index 23983cb35706..1abbfd398e3a 100644 --- a/tools/perf/util/db-export.h +++ b/tools/perf/util/db-export.h @@ -25,7 +25,6 @@ struct call_return; struct export_sample { union perf_event *event; struct perf_sample *sample; - struct evsel *evsel; struct addr_location *al; u64 db_id; u64 comm_db_id; @@ -96,7 +95,7 @@ int db_export__symbol(struct db_export *dbe, struct symbol *sym, int db_export__branch_type(struct db_export *dbe, u32 branch_type, const char *name); int db_export__sample(struct db_export *dbe, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al); int db_export__branch_types(struct db_export *dbe); diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 08197cef44c8..8de08cebe240 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1312,7 +1312,7 @@ static void python_export_sample_table(struct db_export *dbe, t = tuple_new(28); tuple_set_d64(t, 0, es->db_id); - tuple_set_d64(t, 1, es->evsel->db_id); + tuple_set_d64(t, 1, es->sample->evsel->db_id); tuple_set_d64(t, 2, maps__machine(thread__maps(es->al->thread))->db_id); tuple_set_d64(t, 3, thread__db_id(es->al->thread)); tuple_set_d64(t, 4, es->comm_db_id); @@ -1353,7 +1353,7 @@ static void python_export_synth(struct db_export *dbe, struct export_sample *es) t = tuple_new(3); tuple_set_d64(t, 0, es->db_id); - tuple_set_d64(t, 1, es->evsel->core.attr.config); + tuple_set_d64(t, 1, es->sample->evsel->core.attr.config); tuple_set_bytes(t, 2, es->sample->raw_data, es->sample->raw_size); call_object(tables->synth_handler, t, "synth_data"); @@ -1368,7 +1368,7 @@ static int python_export_sample(struct db_export *dbe, python_export_sample_table(dbe, es); - if (es->evsel->core.attr.type == PERF_TYPE_SYNTH && tables->synth_handler) + if (es->sample->evsel->core.attr.type == PERF_TYPE_SYNTH && tables->synth_handler) python_export_synth(dbe, es); return 0; @@ -1517,7 +1517,7 @@ static void python_process_event(union perf_event *event, /* Reserve for future process_hw/sw/raw APIs */ default: if (tables->db_export_mode) - db_export__sample(&tables->dbe, event, sample, evsel, al, addr_al); + db_export__sample(&tables->dbe, event, sample, al, addr_al); else python_process_general_event(sample, evsel, al, addr_al); } -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 13/25] perf hist: Remove evsel from struct hist_entry_iter 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (11 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 12/25] perf db-export: Remove evsel from struct export_sample Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id Ian Rogers ` (12 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan struct hist_entry_iter has the sample within it so the evsel is unnecessary. Remove the evsel and update uses. Also remove the evsel from hist__account_cycles and derive it from the sample too. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 10 ++++------ tools/perf/builtin-diff.c | 3 +-- tools/perf/builtin-report.c | 6 ++---- tools/perf/builtin-top.c | 9 +++------ tools/perf/tests/hists_cumulate.c | 1 - tools/perf/tests/hists_filter.c | 1 - tools/perf/tests/hists_output.c | 1 - tools/perf/util/hist.c | 24 ++++++++++++------------ tools/perf/util/hist.h | 3 +-- 9 files changed, 23 insertions(+), 35 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index c2d0599fe5f5..041f5dc92ea8 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -191,14 +191,12 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, return err; } -static int process_branch_callback(struct evsel *evsel, - struct perf_sample *sample, +static int process_branch_callback(struct perf_sample *sample, struct addr_location *al, struct perf_annotate *ann, struct machine *machine) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .add_entry_cb = hist_iter__branch_callback, .hide_unresolved = symbol_conf.hide_unresolved, @@ -221,8 +219,8 @@ static int process_branch_callback(struct evsel *evsel, if (a.map != NULL) dso__set_hit(map__dso(a.map)); - hist__account_cycles(sample->branch_stack, al, sample, false, - NULL, evsel); + hist__account_cycles(sample->branch_stack, al, sample, /*nonany_branch_mode=*/false, + /*total_cycles=*/NULL); ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann); out: @@ -269,7 +267,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, process_branch_stack(sample->branch_stack, al, sample); if (ann->has_br_stack && has_annotation(ann)) - return process_branch_callback(evsel, sample, al, ann, machine); + return process_branch_callback(sample, al, ann, machine); he = hists__add_entry(hists, al, NULL, NULL, NULL, NULL, sample, true); if (he == NULL) diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 096adc65451c..67cf5bbaab29 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -397,7 +397,6 @@ static int diff__process_sample_event(const struct perf_tool *tool, struct evsel *evsel = sample->evsel; struct hists *hists = evsel__hists(evsel); struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .ops = &hist_iter_normal, }; @@ -431,7 +430,7 @@ static int diff__process_sample_event(const struct perf_tool *tool, } hist__account_cycles(sample->branch_stack, &al, sample, - false, NULL, evsel); + /*nonany_branch_mode=*/false, /*total_cycles=*/NULL); break; case COMPUTE_STREAM: diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 39968ae5cfb0..1051d7b75361 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -270,10 +270,8 @@ static int process_sample_event(const struct perf_tool *tool, struct machine *machine) { struct report *rep = container_of(tool, struct report, tool); - struct evsel *evsel = sample->evsel; struct addr_location al; struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .hide_unresolved = symbol_conf.hide_unresolved, .add_entry_cb = hist_iter__report_callback, @@ -285,7 +283,7 @@ static int process_sample_event(const struct perf_tool *tool, return 0; } - if (evswitch__discard(&rep->evswitch, evsel)) + if (evswitch__discard(&rep->evswitch, sample->evsel)) return 0; addr_location__init(&al); @@ -329,7 +327,7 @@ static int process_sample_event(const struct perf_tool *tool, if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) { hist__account_cycles(sample->branch_stack, &al, sample, rep->nonany_branch_mode, - &rep->total_cycles, evsel); + &rep->total_cycles); } rep->total_samples++; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index e863f9ef581f..b89ca48e5d02 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -731,20 +731,18 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter, EXCLUSIVE_LOCKS_REQUIRED(iter->he->hists->lock) { struct perf_top *top = arg; - struct evsel *evsel = iter->evsel; if (perf_hpp_list.sym && single) perf_top__record_precise_ip(top, iter->he, iter->sample, al->addr); hist__account_cycles(iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY), - NULL, evsel); + /*total_cycles=*/NULL); return 0; } static void perf_event__process_sample(const struct perf_tool *tool, const union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -830,9 +828,8 @@ static void perf_event__process_sample(const struct perf_tool *tool, } if (al.sym == NULL || !al.sym->idle) { - struct hists *hists = evsel__hists(evsel); + struct hists *hists = evsel__hists(sample->evsel); struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .add_entry_cb = hist_iter__top_callback, }; @@ -1210,7 +1207,7 @@ static int deliver_event(struct ordered_events *qe, } if (event->header.type == PERF_RECORD_SAMPLE) { - perf_event__process_sample(&top->tool, event, evsel, + perf_event__process_sample(&top->tool, event, &sample, machine); } else if (event->header.type == PERF_RECORD_LOST) { perf_top__process_lost(top, event, evsel); diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c index 606aa926a8fc..267cbc24691a 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -87,7 +87,6 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) addr_location__init(&al); for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = &sample, .hide_unresolved = false, }; diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c index cc6b26e373d1..002e3a4c1ca5 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -63,7 +63,6 @@ static int add_hist_entries(struct evlist *evlist, evlist__for_each_entry(evlist, evsel) { for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = &sample, .ops = &hist_iter_normal, .hide_unresolved = false, diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c index 7818950d786e..fa683fd7b1e5 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -57,7 +57,6 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) addr_location__init(&al); for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = &sample, .ops = &hist_iter_normal, .hide_unresolved = false, diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 84a402d248a3..632c1edcab9a 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -932,8 +932,8 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al { u64 cost; struct mem_info *mi = iter->mi; - struct hists *hists = evsel__hists(iter->evsel); struct perf_sample *sample = iter->sample; + struct hists *hists = evsel__hists(sample->evsel); struct hist_entry *he; if (mi == NULL) @@ -965,7 +965,7 @@ static int iter_finish_mem_entry(struct hist_entry_iter *iter, struct addr_location *al __maybe_unused) { - struct evsel *evsel = iter->evsel; + struct evsel *evsel = iter->sample->evsel; struct hists *hists = evsel__hists(evsel); struct hist_entry *he = iter->he; int err = -EINVAL; @@ -1033,9 +1033,9 @@ static int iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) { struct branch_info *bi; - struct evsel *evsel = iter->evsel; - struct hists *hists = evsel__hists(evsel); struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; + struct hists *hists = evsel__hists(evsel); struct hist_entry *he = NULL; int i = iter->curr; int err = 0; @@ -1075,7 +1075,7 @@ static int iter_finish_branch_entry(struct hist_entry_iter *iter, struct addr_location *al __maybe_unused) { - struct evsel *evsel = iter->evsel; + struct evsel *evsel = iter->sample->evsel; struct hists *hists = evsel__hists(evsel); for (int i = 0; i < iter->total; i++) @@ -1100,8 +1100,8 @@ iter_prepare_normal_entry(struct hist_entry_iter *iter __maybe_unused, static int iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; struct hist_entry *he; he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, @@ -1118,8 +1118,8 @@ iter_finish_normal_entry(struct hist_entry_iter *iter, struct addr_location *al __maybe_unused) { struct hist_entry *he = iter->he; - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; if (he == NULL) return 0; @@ -1162,9 +1162,9 @@ static int iter_add_single_cumulative_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel = iter->evsel; - struct hists *hists = evsel__hists(evsel); struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; + struct hists *hists = evsel__hists(evsel); struct hist_entry **he_cache = iter->he_cache; struct hist_entry *he; int err = 0; @@ -1221,8 +1221,8 @@ static int iter_add_next_cumulative_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; struct hist_entry **he_cache = iter->he_cache; struct hist_entry *he; struct hist_entry he_tmp = { @@ -2823,7 +2823,7 @@ int hists__unlink(struct hists *hists) void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, struct perf_sample *sample, bool nonany_branch_mode, - u64 *total_cycles, struct evsel *evsel) + u64 *total_cycles) { struct branch_info *bi; struct branch_entry *entries = perf_sample__branch_entries(sample); @@ -2847,7 +2847,7 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, for (int i = bs->nr - 1; i >= 0; i--) { addr_map_symbol__account_cycles(&bi[i].from, nonany_branch_mode ? NULL : prev, - bi[i].flags.cycles, evsel, + bi[i].flags.cycles, sample->evsel, bi[i].branch_stack_cntr); prev = &bi[i].to; diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 1d5ea632ca4e..ee92fffc53a9 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -155,7 +155,6 @@ struct hist_entry_iter { int total; int curr; - struct evsel *evsel; struct perf_sample *sample; struct hist_entry *he; struct symbol *parent; @@ -797,7 +796,7 @@ unsigned int hists__overhead_width(struct hists *hists); void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, struct perf_sample *sample, bool nonany_branch_mode, - u64 *total_cycles, struct evsel *evsel); + u64 *total_cycles); struct option; int parse_filter_percentage(const struct option *opt, const char *arg, int unset); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (12 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 13/25] perf hist: Remove evsel from struct hist_entry_iter Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 15/25] perf annotate: Don't pass evsel to add_sample Ian Rogers ` (11 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan In count_lost_samples_events try to avoid searching for the evsel for the sample, just use the variable within the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-report.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 1051d7b75361..d53aa7a94192 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -793,9 +793,11 @@ static int count_lost_samples_event(const struct perf_tool *tool, struct machine *machine __maybe_unused) { struct report *rep = container_of(tool, struct report, tool); - struct evsel *evsel; + struct evsel *evsel = sample->evsel; + + if (!evsel) + evsel = evlist__id2evsel(rep->session->evlist, sample->id); - evsel = evlist__id2evsel(rep->session->evlist, sample->id); if (evsel) { struct hists *hists = evsel__hists(evsel); u32 count = event->lost_samples.lost; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 15/25] perf annotate: Don't pass evsel to add_sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (13 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 16/25] perf inject: Don't pass evsel with sample Ian Rogers ` (10 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel so read it rather than pass it. Update call site. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 041f5dc92ea8..894e57aa50cd 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -233,11 +233,11 @@ static bool has_annotation(struct perf_annotate *ann) return ui__has_annotation() || ann->use_stdio2; } -static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, - struct addr_location *al, struct perf_annotate *ann, - struct machine *machine) +static int add_sample(struct perf_sample *sample, + struct addr_location *al, struct perf_annotate *ann, + struct machine *machine) { - struct hists *hists = evsel__hists(evsel); + struct hists *hists = evsel__hists(sample->evsel); struct hist_entry *he; int ret; @@ -299,7 +299,7 @@ static int process_sample_event(const struct perf_tool *tool, goto out_put; if (!al.filtered && - evsel__add_sample(sample->evsel, sample, &al, ann, machine)) { + add_sample(sample, &al, ann, machine)) { pr_warning("problem incrementing symbol count, " "skipping event\n"); ret = -1; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 16/25] perf inject: Don't pass evsel with sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (14 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 15/25] perf annotate: Don't pass evsel to add_sample Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 17/25] perf kmem: " Ian Rogers ` (9 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 46 ++++++++++++------------------ tools/perf/util/synthetic-events.c | 9 +++--- tools/perf/util/synthetic-events.h | 2 -- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 1b873377c6ad..0b2326ea63ad 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -146,14 +146,12 @@ struct event_entry { static int tool__inject_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, const char *filename, struct dso *dso, u32 flags); static int tool__inject_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -357,7 +355,6 @@ perf_inject__cut_auxtrace_sample(struct perf_inject *inject, typedef int (*inject_handler)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); static int perf_event__repipe_sample(const struct perf_tool *tool, @@ -370,7 +367,7 @@ static int perf_event__repipe_sample(const struct perf_tool *tool, if (evsel && evsel->handler) { inject_handler f = evsel->handler; - return f(tool, event, sample, evsel, machine); + return f(tool, event, sample, machine); } build_id__mark_dso_hit(tool, event, sample, machine); @@ -584,11 +581,12 @@ static int perf_event__repipe_common_mmap(const struct perf_tool *tool, } if (dso && !dso__hit(dso)) { - struct evsel *evsel = evlist__event2evsel(inject->session->evlist, event); + if (!sample->evsel) + sample->evsel = evlist__event2evsel(inject->session->evlist, event); - if (evsel) { + if (sample->evsel) { dso__set_hit(dso); - tool__inject_build_id(tool, sample, machine, evsel, + tool__inject_build_id(tool, sample, machine, /*misc=*/sample->cpumode, filename, dso, flags); } @@ -615,23 +613,26 @@ static int perf_event__repipe_common_mmap(const struct perf_tool *tool, } if ((inject->build_id_style == BID_RWS__MMAP2_BUILDID_ALL) && !(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) { - struct evsel *evsel = evlist__event2evsel(inject->session->evlist, event); + struct evsel *saved_evsel = sample->evsel; - if (evsel && !dso_sought) { + sample->evsel = evlist__event2evsel(inject->session->evlist, event); + if (sample->evsel && !dso_sought) { dso = findnew_dso(pid, tid, filename, dso_id, machine); dso_sought = true; } - if (evsel && dso && - !tool__inject_mmap2_build_id(tool, sample, machine, evsel, + if (sample->evsel && dso && + !tool__inject_mmap2_build_id(tool, sample, machine, sample->cpumode | PERF_RECORD_MISC_MMAP_BUILD_ID, pid, tid, start, len, pgoff, dso, prot, flags, filename)) { /* Injected mmap2 so no need to repipe. */ + sample->evsel = saved_evsel; dso__put(dso); return 0; } + sample->evsel = saved_evsel; } dso__put(dso); if (inject->build_id_style == BID_RWS__MMAP2_BUILDID_LAZY) @@ -836,7 +837,6 @@ static bool perf_inject__lookup_known_build_id(struct perf_inject *inject, static int tool__inject_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, const char *filename, struct dso *dso, u32 flags) @@ -860,7 +860,7 @@ static int tool__inject_build_id(const struct perf_tool *tool, err = perf_event__synthesize_build_id(tool, sample, machine, perf_event__repipe, - evsel, misc, dso__bid(dso), + misc, dso__bid(dso), filename); if (err) { pr_err("Can't synthesize build_id event for %s\n", filename); @@ -873,7 +873,6 @@ static int tool__inject_build_id(const struct perf_tool *tool, static int tool__inject_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -896,7 +895,6 @@ static int tool__inject_mmap2_build_id(const struct perf_tool *tool, err = perf_event__synthesize_mmap2_build_id(tool, sample, machine, perf_event__repipe, - evsel, misc, pid, tid, start, len, pgoff, dso__bid(dso), @@ -913,7 +911,6 @@ static int mark_dso_hit(const struct perf_inject *inject, const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *mmap_evsel, struct map *map, bool sample_in_dso) { struct dso *dso; @@ -943,7 +940,7 @@ static int mark_dso_hit(const struct perf_inject *inject, if (dso && !dso__hit(dso)) { dso__set_hit(dso); tool__inject_build_id(tool, sample, machine, - mmap_evsel, misc, dso__long_name(dso), dso, + misc, dso__long_name(dso), dso, map__flags(map)); } } else if (inject->build_id_style == BID_RWS__MMAP2_BUILDID_LAZY) { @@ -955,7 +952,6 @@ static int mark_dso_hit(const struct perf_inject *inject, map__set_hit(map); perf_event__synthesize_mmap2_build_id(tool, sample, machine, perf_event__repipe, - mmap_evsel, misc, sample->pid, sample->tid, map__start(map), @@ -975,7 +971,6 @@ struct mark_dso_hit_args { const struct perf_tool *tool; struct perf_sample *sample; struct machine *machine; - const struct evsel *mmap_evsel; }; static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data) @@ -984,7 +979,7 @@ static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data) struct map *map = node->ms.map; return mark_dso_hit(args->inject, args->tool, args->sample, args->machine, - args->mmap_evsel, map, /*sample_in_dso=*/false); + map, /*sample_in_dso=*/false); } static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, @@ -1002,7 +997,6 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e */ .sample = sample, .machine = machine, - .mmap_evsel = inject__mmap_evsel(inject), }; struct evsel *saved_evsel = sample->evsel; @@ -1016,7 +1010,7 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e sample->evsel = inject__mmap_evsel(inject); if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) { - mark_dso_hit(inject, tool, sample, machine, args.mmap_evsel, al.map, + mark_dso_hit(inject, tool, sample, machine, al.map, /*sample_in_dso=*/true); } @@ -1033,7 +1027,6 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e static int perf_inject__sched_process_exit(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine __maybe_unused) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); @@ -1053,13 +1046,12 @@ static int perf_inject__sched_process_exit(const struct perf_tool *tool, static int perf_inject__sched_switch(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); struct event_entry *ent; - perf_inject__sched_process_exit(tool, event, sample, evsel, machine); + perf_inject__sched_process_exit(tool, event, sample, machine); ent = malloc(event->header.size + sizeof(struct event_entry)); if (ent == NULL) { @@ -1078,13 +1070,13 @@ static int perf_inject__sched_switch(const struct perf_tool *tool, static int perf_inject__sched_stat(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct event_entry *ent; union perf_event *event_sw; struct perf_sample sample_sw; struct perf_inject *inject = container_of(tool, struct perf_inject, tool); + struct evsel *evsel = sample->evsel; u32 pid = perf_sample__intval(sample, "pid"); int ret; @@ -1449,7 +1441,7 @@ static int synthesize_build_id(struct perf_inject *inject, struct dso *dso, pid_ dso__set_hit(dso); return perf_event__synthesize_build_id(&inject->tool, &synth_sample, machine, - process_build_id, inject__mmap_evsel(inject), + process_build_id, /*misc=*/synth_sample.cpumode, dso__bid(dso), dso__long_name(dso)); } diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index ef79433ebc3a..53e411cf33cc 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2247,7 +2247,6 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, const struct build_id *bid, const char *filename) @@ -2270,12 +2269,13 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, ev.build_id.header.size = len; strcpy(ev.build_id.filename, filename); - if (evsel) { + if (sample->evsel) { void *array = &ev; int ret; array += ev.header.size; - ret = perf_event__synthesize_id_sample(array, evsel->core.attr.sample_type, sample); + ret = perf_event__synthesize_id_sample(array, sample->evsel->core.attr.sample_type, + sample); if (ret < 0) return ret; @@ -2294,7 +2294,6 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -2334,7 +2333,7 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, array = &ev; array += ev.header.size; - ret = perf_event__synthesize_id_sample(array, evsel->core.attr.sample_type, sample); + ret = perf_event__synthesize_id_sample(array, sample->evsel->core.attr.sample_type, sample); if (ret < 0) return ret; diff --git a/tools/perf/util/synthetic-events.h b/tools/perf/util/synthetic-events.h index b0edad0c3100..473a43a78993 100644 --- a/tools/perf/util/synthetic-events.h +++ b/tools/perf/util/synthetic-events.h @@ -50,7 +50,6 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, const struct build_id *bid, const char *filename); @@ -58,7 +57,6 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 17/25] perf kmem: Don't pass evsel with sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (15 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 16/25] perf inject: Don't pass evsel with sample Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 18/25] perf kwork: " Ian Rogers ` (8 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-kmem.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index df3bfb8fd9c0..6dbb2b2f1f59 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -171,7 +171,7 @@ static int insert_caller_stat(unsigned long call_site, return 0; } -static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_alloc_event(struct perf_sample *sample) { unsigned long ptr = perf_sample__intval(sample, "ptr"), call_site = perf_sample__intval(sample, "call_site"); @@ -198,7 +198,7 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s * If the tracepoint contains the field "node" the tool stats the * cross allocation. */ - if (evsel__field(evsel, "node")) { + if (evsel__field(sample->evsel, "node")) { int node1, node2; node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}); @@ -243,7 +243,7 @@ static struct alloc_stat *search_alloc_stat(unsigned long ptr, return NULL; } -static int evsel__process_free_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) +static int evsel__process_free_event(struct perf_sample *sample) { unsigned long ptr = perf_sample__intval(sample, "ptr"); struct alloc_stat *s_alloc, *s_caller; @@ -751,8 +751,7 @@ static char *compact_gfp_string(unsigned long gfp_flags) return NULL; } -static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, - unsigned int gfp_flags) +static int parse_gfp_flags(struct perf_sample *sample, unsigned int gfp_flags) { struct tep_record record = { .cpu = sample->cpu, @@ -773,7 +772,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, } trace_seq_init(&seq); - tp_format = evsel__tp_format(evsel); + tp_format = evsel__tp_format(sample->evsel); if (tp_format) tep_print_event(tp_format->tep, &seq, &record, "%s", TEP_PRINT_INFO); @@ -805,7 +804,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, return 0; } -static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_page_alloc_event(struct perf_sample *sample) { u64 page; unsigned int order = perf_sample__intval(sample, "order"); @@ -845,7 +844,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp return 0; } - if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) + if (parse_gfp_flags(sample, gfp_flags) < 0) return -1; callsite = find_callsite(sample); @@ -886,8 +885,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp return 0; } -static int evsel__process_page_free_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int evsel__process_page_free_event(struct perf_sample *sample) { u64 page; unsigned int order = perf_sample__intval(sample, "order"); @@ -964,8 +962,7 @@ static bool perf_kmem__skip_sample(struct perf_sample *sample) return false; } -typedef int (*tracepoint_handler)(struct evsel *evsel, - struct perf_sample *sample); +typedef int (*tracepoint_handler)(struct perf_sample *sample); static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, @@ -990,7 +987,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(evsel, sample); + err = f(sample); } thread__put(thread); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 18/25] perf kwork: Don't pass evsel with sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (16 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 17/25] perf kmem: " Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 19/25] perf sched: " Ian Rogers ` (7 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Remove the evsel from struct kwork_class. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-kwork.c | 74 +++++++++++++------------------------- tools/perf/util/kwork.h | 9 +++-- 2 files changed, 28 insertions(+), 55 deletions(-) diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 043da61cdcef..bbc6c209eb14 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -448,7 +448,6 @@ static int work_push_atom(struct perf_kwork *kwork, struct kwork_class *class, enum kwork_trace_type src_type, enum kwork_trace_type dst_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct kwork_work **ret_work, @@ -458,7 +457,7 @@ static int work_push_atom(struct perf_kwork *kwork, struct kwork_work *work, key; BUG_ON(class->work_init == NULL); - class->work_init(kwork, class, &key, src_type, evsel, sample, machine); + class->work_init(kwork, class, &key, src_type, sample, machine); atom = atom_new(kwork, sample); if (atom == NULL) @@ -507,7 +506,6 @@ static struct kwork_atom *work_pop_atom(struct perf_kwork *kwork, struct kwork_class *class, enum kwork_trace_type src_type, enum kwork_trace_type dst_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct kwork_work **ret_work) @@ -516,7 +514,7 @@ static struct kwork_atom *work_pop_atom(struct perf_kwork *kwork, struct kwork_work *work, key; BUG_ON(class->work_init == NULL); - class->work_init(kwork, class, &key, src_type, evsel, sample, machine); + class->work_init(kwork, class, &key, src_type, sample, machine); work = work_findnew(&class->work_root, &key, &kwork->cmp_id); if (ret_work != NULL) @@ -599,18 +597,16 @@ static void report_update_exit_event(struct kwork_work *work, static int report_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int report_exit_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -618,7 +614,7 @@ static int report_exit_event(struct perf_kwork *kwork, struct kwork_work *work = NULL; atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (work == NULL) return -1; @@ -654,18 +650,16 @@ static void latency_update_entry_event(struct kwork_work *work, static int latency_raise_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_RAISE, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int latency_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -673,7 +667,7 @@ static int latency_entry_event(struct perf_kwork *kwork, struct kwork_work *work = NULL; atom = work_pop_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_RAISE, evsel, sample, + KWORK_TRACE_RAISE, sample, machine, &work); if (work == NULL) return -1; @@ -812,18 +806,16 @@ static void timehist_print_event(struct perf_kwork *kwork, static int timehist_raise_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_RAISE, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int timehist_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -831,7 +823,7 @@ static int timehist_entry_event(struct perf_kwork *kwork, struct kwork_work *work = NULL; ret = work_push_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_RAISE, evsel, sample, + KWORK_TRACE_RAISE, sample, machine, &work, true); if (ret) return ret; @@ -844,7 +836,6 @@ static int timehist_entry_event(struct perf_kwork *kwork, static int timehist_exit_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -861,7 +852,7 @@ static int timehist_exit_event(struct perf_kwork *kwork, } atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (work == NULL) { ret = -1; @@ -895,18 +886,16 @@ static void top_update_runtime(struct kwork_work *work, static int top_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int top_exit_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -915,7 +904,7 @@ static int top_exit_event(struct perf_kwork *kwork, struct kwork_atom *atom; atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (!work) return -1; @@ -936,7 +925,6 @@ static int top_exit_event(struct perf_kwork *kwork, static int top_sched_switch_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -944,7 +932,7 @@ static int top_sched_switch_event(struct perf_kwork *kwork, struct kwork_work *work; atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (!work) return -1; @@ -954,12 +942,11 @@ static int top_sched_switch_event(struct perf_kwork *kwork, atom_del(atom); } - return top_entry_event(kwork, class, evsel, sample, machine); + return top_entry_event(kwork, class, sample, machine); } static struct kwork_class kwork_irq; static int process_irq_handler_entry_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -967,12 +954,11 @@ static int process_irq_handler_entry_event(const struct perf_tool *tool, if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_irq, - evsel, sample, machine); + sample, machine); return 0; } static int process_irq_handler_exit_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -980,7 +966,7 @@ static int process_irq_handler_exit_event(const struct perf_tool *tool, if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_irq, - evsel, sample, machine); + sample, machine); return 0; } @@ -1005,7 +991,6 @@ static void irq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1038,7 +1023,6 @@ static struct kwork_class kwork_irq = { static struct kwork_class kwork_softirq; static int process_softirq_raise_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1046,13 +1030,12 @@ static int process_softirq_raise_event(const struct perf_tool *tool, if (kwork->tp_handler->raise_event) return kwork->tp_handler->raise_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); return 0; } static int process_softirq_entry_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1060,13 +1043,12 @@ static int process_softirq_entry_event(const struct perf_tool *tool, if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); return 0; } static int process_softirq_exit_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1074,7 +1056,7 @@ static int process_softirq_exit_event(const struct perf_tool *tool, if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); return 0; } @@ -1133,7 +1115,6 @@ static void softirq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1148,7 +1129,7 @@ static void softirq_work_init(struct perf_kwork *kwork, } else { num = perf_sample__intval(sample, "vec"); work->id = num; - work->name = evsel__softirq_name(evsel, num); + work->name = evsel__softirq_name(sample->evsel, num); } } @@ -1169,7 +1150,6 @@ static struct kwork_class kwork_softirq = { static struct kwork_class kwork_workqueue; static int process_workqueue_activate_work_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1177,13 +1157,12 @@ static int process_workqueue_activate_work_event(const struct perf_tool *tool, if (kwork->tp_handler->raise_event) return kwork->tp_handler->raise_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); return 0; } static int process_workqueue_execute_start_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1191,13 +1170,12 @@ static int process_workqueue_execute_start_event(const struct perf_tool *tool, if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); return 0; } static int process_workqueue_execute_end_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1205,7 +1183,7 @@ static int process_workqueue_execute_end_event(const struct perf_tool *tool, if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); return 0; } @@ -1233,7 +1211,6 @@ static void workqueue_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1267,7 +1244,6 @@ static struct kwork_class kwork_workqueue = { static struct kwork_class kwork_sched; static int process_sched_switch_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1275,7 +1251,7 @@ static int process_sched_switch_event(const struct perf_tool *tool, if (kwork->tp_handler->sched_switch_event) return kwork->tp_handler->sched_switch_event(kwork, &kwork_sched, - evsel, sample, machine); + sample, machine); return 0; } @@ -1300,7 +1276,6 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1946,7 +1921,6 @@ static int perf_kwork__report(struct perf_kwork *kwork) } typedef int (*tracepoint_handler)(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -1961,7 +1935,7 @@ static int perf_kwork__process_tracepoint_sample(const struct perf_tool *tool, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(tool, evsel, sample, machine); + err = f(tool, sample, machine); } return err; diff --git a/tools/perf/util/kwork.h b/tools/perf/util/kwork.h index db00269b73f2..abf637d44794 100644 --- a/tools/perf/util/kwork.h +++ b/tools/perf/util/kwork.h @@ -157,7 +157,6 @@ struct kwork_class { struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -167,19 +166,19 @@ struct kwork_class { struct trace_kwork_handler { int (*raise_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); int (*entry_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); int (*exit_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); int (*sched_switch_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); }; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 19/25] perf sched: Don't pass evsel with sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (17 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 18/25] perf kwork: " Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 20/25] perf timechart: " Ian Rogers ` (6 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-sched.c | 92 ++++++++++++++------------------------ 1 file changed, 34 insertions(+), 58 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index b6271a5ec8de..fdfa2fec0fe6 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -129,21 +129,20 @@ typedef int (*sort_fn_t)(struct work_atoms *, struct work_atoms *); struct perf_sched; struct trace_sched_handler { - int (*switch_event)(struct perf_sched *sched, struct evsel *evsel, - struct perf_sample *sample, struct machine *machine); + int (*switch_event)(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine); - int (*runtime_event)(struct perf_sched *sched, struct evsel *evsel, - struct perf_sample *sample, struct machine *machine); + int (*runtime_event)(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine); - int (*wakeup_event)(struct perf_sched *sched, struct evsel *evsel, - struct perf_sample *sample, struct machine *machine); + int (*wakeup_event)(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine); /* PERF_RECORD_FORK event, not sched_process_fork tracepoint */ int (*fork_event)(struct perf_sched *sched, union perf_event *event, struct machine *machine); int (*migrate_task_event)(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); }; @@ -826,7 +825,7 @@ static void test_calibrations(struct perf_sched *sched) static int replay_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, + struct perf_sample *sample, struct machine *machine __maybe_unused) { const char *comm = perf_sample__strval(sample, "comm"); @@ -834,7 +833,7 @@ replay_wakeup_event(struct perf_sched *sched, struct task_desc *waker, *wakee; if (verbose > 0) { - printf("sched_wakeup event %p\n", evsel); + printf("sched_wakeup event %p\n", sample->evsel); printf(" ... pid %d woke up %s/%d\n", sample->tid, comm, pid); } @@ -847,7 +846,6 @@ replay_wakeup_event(struct perf_sched *sched, } static int replay_switch_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -861,7 +859,7 @@ static int replay_switch_event(struct perf_sched *sched, s64 delta; if (verbose > 0) - printf("sched_switch event %p\n", evsel); + printf("sched_switch event %p\n", sample->evsel); if (cpu >= MAX_CPUS || cpu < 0) return 0; @@ -1134,7 +1132,6 @@ static void free_work_atoms(struct work_atoms *atoms) } static int latency_switch_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1204,7 +1201,6 @@ static int latency_switch_event(struct perf_sched *sched, } static int latency_runtime_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1239,7 +1235,6 @@ static int latency_runtime_event(struct perf_sched *sched, } static int latency_wakeup_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1300,7 +1295,6 @@ static int latency_wakeup_event(struct perf_sched *sched, } static int latency_migrate_task_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1519,20 +1513,18 @@ static void perf_sched__sort_lat(struct perf_sched *sched) } static int process_sched_wakeup_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); if (sched->tp_handler->wakeup_event) - return sched->tp_handler->wakeup_event(sched, evsel, sample, machine); + return sched->tp_handler->wakeup_event(sched, sample, machine); return 0; } static int process_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused) { @@ -1626,8 +1618,8 @@ static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu, } } -static int map_switch_event(struct perf_sched *sched, struct evsel *evsel __maybe_unused, - struct perf_sample *sample, struct machine *machine) +static int map_switch_event(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine) { const u32 next_pid = perf_sample__intval(sample, "next_pid"); const u32 prev_pid = perf_sample__intval(sample, "prev_pid"); @@ -1791,7 +1783,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel __mayb } static int process_sched_switch_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1815,21 +1806,20 @@ static int process_sched_switch_event(const struct perf_tool *tool, } if (sched->tp_handler->switch_event) - err = sched->tp_handler->switch_event(sched, evsel, sample, machine); + err = sched->tp_handler->switch_event(sched, sample, machine); sched->curr_pid[this_cpu] = next_pid; return err; } static int process_sched_runtime_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); if (sched->tp_handler->runtime_event) - return sched->tp_handler->runtime_event(sched, evsel, sample, machine); + return sched->tp_handler->runtime_event(sched, sample, machine); return 0; } @@ -1852,20 +1842,18 @@ static int perf_sched__process_fork_event(const struct perf_tool *tool, } static int process_sched_migrate_task_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); if (sched->tp_handler->migrate_task_event) - return sched->tp_handler->migrate_task_event(sched, evsel, sample, machine); + return sched->tp_handler->migrate_task_event(sched, sample, machine); return 0; } typedef int (*tracepoint_handler)(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -1879,7 +1867,7 @@ static int perf_sched__process_tracepoint_sample(const struct perf_tool *tool __ if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(tool, evsel, sample, machine); + err = f(tool, sample, machine); } return err; @@ -2318,11 +2306,10 @@ static void timehist_update_runtime_stats(struct thread_runtime *r, r->total_pre_mig_time += r->dt_pre_mig; } -static bool is_idle_sample(struct perf_sample *sample, - struct evsel *evsel) +static bool is_idle_sample(struct perf_sample *sample) { /* pid 0 == swapper == idle task */ - if (evsel__name_is(evsel, "sched:sched_switch")) + if (evsel__name_is(sample->evsel, "sched:sched_switch")) return perf_sample__intval(sample, "prev_pid") == 0; return sample->pid == 0; @@ -2504,12 +2491,11 @@ static void save_idle_callchain(struct perf_sched *sched, static struct thread *timehist_get_thread(struct perf_sched *sched, struct perf_sample *sample, - struct machine *machine, - struct evsel *evsel) + struct machine *machine) { struct thread *thread; - if (is_idle_sample(sample, evsel)) { + if (is_idle_sample(sample)) { thread = get_idle_thread(sample->cpu); if (thread == NULL) pr_err("Failed to get idle thread for cpu %d.\n", sample->cpu); @@ -2552,7 +2538,6 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, static bool timehist_skip_sample(struct perf_sched *sched, struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { bool rc = false; @@ -2574,7 +2559,7 @@ static bool timehist_skip_sample(struct perf_sched *sched, tr = thread__get_runtime(thread); if (tr && tr->prio != -1) prio = tr->prio; - else if (evsel__name_is(evsel, "sched:sched_switch")) + else if (evsel__name_is(sample->evsel, "sched:sched_switch")) prio = perf_sample__intval(sample, "prev_prio"); if (prio != -1 && !test_bit(prio, sched->prio_bitmap)) { @@ -2584,7 +2569,7 @@ static bool timehist_skip_sample(struct perf_sched *sched, } if (sched->idle_hist) { - if (!evsel__name_is(evsel, "sched:sched_switch")) + if (!evsel__name_is(sample->evsel, "sched:sched_switch")) rc = true; else if (perf_sample__intval(sample, "prev_pid") != 0 && perf_sample__intval(sample, "next_pid") != 0) @@ -2595,7 +2580,6 @@ static bool timehist_skip_sample(struct perf_sched *sched, } static void timehist_print_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct thread *awakened) @@ -2608,8 +2592,8 @@ static void timehist_print_wakeup_event(struct perf_sched *sched, return; /* show wakeup unless both awakee and awaker are filtered */ - if (timehist_skip_sample(sched, thread, evsel, sample) && - timehist_skip_sample(sched, awakened, evsel, sample)) { + if (timehist_skip_sample(sched, thread, sample) && + timehist_skip_sample(sched, awakened, sample)) { thread__put(thread); return; } @@ -2633,7 +2617,6 @@ static void timehist_print_wakeup_event(struct perf_sched *sched, static int timehist_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused) { @@ -2642,7 +2625,6 @@ static int timehist_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unu static int timehist_sched_wakeup_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2668,14 +2650,13 @@ static int timehist_sched_wakeup_event(const struct perf_tool *tool, /* show wakeups if requested */ if (sched->show_wakeups && !perf_time__skip_sample(&sched->ptime, sample->time)) - timehist_print_wakeup_event(sched, evsel, sample, machine, thread); + timehist_print_wakeup_event(sched, sample, machine, thread); thread__put(thread); return 0; } static void timehist_print_migration_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct thread *migrated) @@ -2696,8 +2677,8 @@ static void timehist_print_migration_event(struct perf_sched *sched, if (thread == NULL) return; - if (timehist_skip_sample(sched, thread, evsel, sample) && - timehist_skip_sample(sched, migrated, evsel, sample)) { + if (timehist_skip_sample(sched, thread, sample) && + timehist_skip_sample(sched, migrated, sample)) { thread__put(thread); return; } @@ -2731,7 +2712,6 @@ static void timehist_print_migration_event(struct perf_sched *sched, static int timehist_migrate_task_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2756,8 +2736,7 @@ static int timehist_migrate_task_event(const struct perf_tool *tool, /* show migrations if requested */ if (sched->show_migrations) { - timehist_print_migration_event(sched, evsel, sample, - machine, thread); + timehist_print_migration_event(sched, sample, machine, thread); } thread__put(thread); @@ -2789,7 +2768,6 @@ static void timehist_update_task_prio(struct perf_sample *sample, static int timehist_sched_change_event(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2813,13 +2791,13 @@ static int timehist_sched_change_event(const struct perf_tool *tool, if (sched->show_prio || sched->prio_str) timehist_update_task_prio(sample, machine); - thread = timehist_get_thread(sched, sample, machine, evsel); + thread = timehist_get_thread(sched, sample, machine); if (thread == NULL) { rc = -1; goto out; } - if (timehist_skip_sample(sched, thread, evsel, sample)) + if (timehist_skip_sample(sched, thread, sample)) goto out; tr = thread__get_runtime(thread); @@ -2828,7 +2806,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, goto out; } - tprev = evsel__get_time(evsel, sample->cpu); + tprev = evsel__get_time(sample->evsel, sample->cpu); /* * If start time given: @@ -2918,7 +2896,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, tr->migrated = 0; } - evsel__save_time(evsel, sample->time, sample->cpu); + evsel__save_time(sample->evsel, sample->time, sample->cpu); thread__put(thread); addr_location__exit(&al); @@ -2927,11 +2905,10 @@ static int timehist_sched_change_event(const struct perf_tool *tool, static int timehist_sched_switch_event(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { - return timehist_sched_change_event(tool, event, evsel, sample, machine); + return timehist_sched_change_event(tool, event, sample, machine); } static int process_lost(const struct perf_tool *tool __maybe_unused, @@ -3179,7 +3156,6 @@ static void timehist_print_summary(struct perf_sched *sched, typedef int (*sched_handler)(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -3201,7 +3177,7 @@ static int perf_timehist__process_sample(const struct perf_tool *tool, if (evsel->handler != NULL) { sched_handler f = evsel->handler; - err = f(tool, event, evsel, sample, machine); + err = f(tool, event, sample, machine); } return err; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 20/25] perf timechart: Don't pass evsel with sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (18 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 19/25] perf sched: " Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 21/25] perf trace: " Ian Rogers ` (5 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Add missing backtrace argument to tracepoint_handler functions and mark them unused. Fix missing free from cat_backtrace. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-timechart.c | 71 ++++++++++++++++------------------ 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 657aab126477..13edcfe39d2d 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -489,9 +489,9 @@ static void sched_switch(struct timechart *tchart, int cpu, u64 timestamp, } } -static const char *cat_backtrace(union perf_event *event, - struct perf_sample *sample, - struct machine *machine) +static char *cat_backtrace(union perf_event *event, + struct perf_sample *sample, + struct machine *machine) { struct addr_location al; unsigned int i; @@ -567,7 +567,6 @@ static const char *cat_backtrace(union perf_event *event, } typedef int (*tracepoint_handler)(struct timechart *tchart, - struct evsel *evsel, struct perf_sample *sample, const char *backtrace); @@ -578,6 +577,7 @@ static int process_sample_event(const struct perf_tool *tool, { struct timechart *tchart = container_of(tool, struct timechart, tool); struct evsel *evsel = sample->evsel; + int ret = 0; if (evsel->core.attr.sample_type & PERF_SAMPLE_TIME) { if (!tchart->first_time || tchart->first_time > sample->time) @@ -588,16 +588,17 @@ static int process_sample_event(const struct perf_tool *tool, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - return f(tchart, evsel, sample, - cat_backtrace(event, sample, machine)); + char *backtrace = cat_backtrace(event, sample, machine); + + ret = f(tchart, sample, backtrace); + free(backtrace); } - return 0; + return ret; } static int process_sample_cpu_idle(struct timechart *tchart __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -617,7 +618,6 @@ process_sample_cpu_idle(struct timechart *tchart __maybe_unused, static int process_sample_cpu_frequency(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -630,7 +630,6 @@ process_sample_cpu_frequency(struct timechart *tchart, static int process_sample_sched_wakeup(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { @@ -644,7 +643,6 @@ process_sample_sched_wakeup(struct timechart *tchart, static int process_sample_sched_switch(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { @@ -660,7 +658,6 @@ process_sample_sched_switch(struct timechart *tchart, #ifdef SUPPORT_OLD_POWER_EVENTS static int process_sample_power_start(struct timechart *tchart __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -673,7 +670,6 @@ process_sample_power_start(struct timechart *tchart __maybe_unused, static int process_sample_power_end(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -683,7 +679,6 @@ process_sample_power_end(struct timechart *tchart, static int process_sample_power_frequency(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -853,8 +848,8 @@ static int pid_end_io_sample(struct timechart *tchart, int pid, int type, static int process_enter_read(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ, @@ -863,8 +858,8 @@ process_enter_read(struct timechart *tchart, static int process_exit_read(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_READ, @@ -873,8 +868,8 @@ process_exit_read(struct timechart *tchart, static int process_enter_write(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE, @@ -883,8 +878,8 @@ process_enter_write(struct timechart *tchart, static int process_exit_write(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_WRITE, @@ -893,8 +888,8 @@ process_exit_write(struct timechart *tchart, static int process_enter_sync(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC, @@ -903,8 +898,8 @@ process_enter_sync(struct timechart *tchart, static int process_exit_sync(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_SYNC, @@ -913,8 +908,8 @@ process_exit_sync(struct timechart *tchart, static int process_enter_tx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX, @@ -923,8 +918,8 @@ process_enter_tx(struct timechart *tchart, static int process_exit_tx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_TX, @@ -933,8 +928,8 @@ process_exit_tx(struct timechart *tchart, static int process_enter_rx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX, @@ -943,8 +938,8 @@ process_enter_rx(struct timechart *tchart, static int process_exit_rx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_RX, @@ -953,8 +948,8 @@ process_exit_rx(struct timechart *tchart, static int process_enter_poll(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL, @@ -963,8 +958,8 @@ process_enter_poll(struct timechart *tchart, static int process_exit_poll(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_POLL, -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 21/25] perf trace: Don't pass evsel with sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (19 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 20/25] perf timechart: " Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 22/25] perf evlist: Try to avoid computing evsel from sample Ian Rogers ` (4 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. In trace__handle_event try to use the evsel from the sample to avoid recomputation. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-trace.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 385a9ac2ae96..c4ec4f603d5f 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2580,7 +2580,7 @@ static struct syscall *trace__find_syscall(struct trace *trace, int e_machine, i return sc; } -typedef int (*tracepoint_handler)(struct trace *trace, struct evsel *evsel, +typedef int (*tracepoint_handler)(struct trace *trace, union perf_event *event, struct perf_sample *sample); @@ -2775,10 +2775,11 @@ static void *syscall__augmented_args(struct syscall *sc, struct perf_sample *sam return NULL; } -static int trace__sys_enter(struct trace *trace, struct evsel *evsel, +static int trace__sys_enter(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; char *msg; void *args; int printed = 0; @@ -2921,10 +2922,11 @@ static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sam return sample__fprintf_callchain(sample, 38, print_opts, get_tls_callchain_cursor(), symbol_conf.bt_stop_list, trace->output); } -static int trace__sys_exit(struct trace *trace, struct evsel *evsel, +static int trace__sys_exit(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; long ret; u64 duration = 0; bool duration_calculated = false; @@ -3059,7 +3061,7 @@ errno_print: { return err; } -static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_unused, +static int trace__vfs_getname(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3120,7 +3122,7 @@ static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_u return 0; } -static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, +static int trace__sched_stat_runtime(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3142,7 +3144,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, out_dump: fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", - evsel->name, + sample->evsel->name, perf_sample__strval(sample, "comm"), (pid_t)perf_sample__intval(sample, "pid"), runtime, @@ -3253,10 +3255,11 @@ static size_t trace__fprintf_tp_fields(struct trace *trace, struct perf_sample * return fprintf(trace->output, "%.*s", (int)printed, bf); } -static int trace__event_handler(struct trace *trace, struct evsel *evsel, +static int trace__event_handler(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; struct thread *thread; int callchain_ret = 0; @@ -3444,7 +3447,6 @@ static int trace__pgfault(struct trace *trace, } static void trace__set_base_time(struct trace *trace, - struct evsel *evsel, struct perf_sample *sample) { /* @@ -3456,7 +3458,7 @@ static void trace__set_base_time(struct trace *trace, * appears in our event stream (vfs_getname comes to mind). */ if (trace->base_time == 0 && !trace->full_time && - (evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) + (sample->evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) trace->base_time = sample->time; } @@ -3476,11 +3478,11 @@ static int trace__process_sample(const struct perf_tool *tool, if (thread && thread__is_filtered(thread)) goto out; - trace__set_base_time(trace, evsel, sample); + trace__set_base_time(trace, sample); if (handler) { ++trace->nr_events; - handler(trace, evsel, event, sample); + handler(trace, event, sample); } out: thread__put(thread); @@ -3622,14 +3624,16 @@ static void evlist__free_syscall_tp_fields(struct evlist *evlist) static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *sample) { const u32 type = event->header.type; - struct evsel *evsel; + struct evsel *evsel = sample->evsel; if (type != PERF_RECORD_SAMPLE) { trace__process_event(trace, trace->host, event, sample); return; } - evsel = evlist__id2evsel(trace->evlist, sample->id); + if (evsel == NULL) + evsel = evlist__id2evsel(trace->evlist, sample->id); + if (evsel == NULL) { fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id); return; @@ -3638,7 +3642,7 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st if (evswitch__discard(&trace->evswitch, evsel)) return; - trace__set_base_time(trace, evsel, sample); + trace__set_base_time(trace, sample); if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT && sample->raw_data == NULL) { @@ -3647,7 +3651,7 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st sample->cpu, sample->raw_size); } else { tracepoint_handler handler = evsel->handler; - handler(trace, evsel, event, sample); + handler(trace, event, sample); } if (trace->nr_events_printed >= trace->max_events && trace->max_events != ULONG_MAX) -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 22/25] perf evlist: Try to avoid computing evsel from sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (20 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 21/25] perf trace: " Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 23/25] perf script: Don't pass evsel with sample Ian Rogers ` (3 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan If the sample has an evsel, don't recompute using the sample.id. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-top.c | 4 +++- tools/perf/tests/mmap-basic.c | 4 +++- tools/perf/tests/switch-tracking.c | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index b89ca48e5d02..faa422e35166 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1163,7 +1163,9 @@ static int deliver_event(struct ordered_events *qe, goto next_event; } - evsel = evlist__id2evsel(session->evlist, sample.id); + evsel = sample.evsel; + if (!evsel) + evsel = evlist__id2evsel(session->evlist, sample.id); assert(evsel != NULL); if (event->header.type == PERF_RECORD_SAMPLE) { diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 3313c236104e..a18d84d858aa 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -142,7 +142,9 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtest } err = -1; - evsel = evlist__id2evsel(evlist, sample.id); + evsel = sample.evsel; + if (!evsel) + evsel = evlist__id2evsel(evlist, sample.id); perf_sample__exit(&sample); if (evsel == NULL) { pr_debug("event with id %" PRIu64 diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index a7ea4b7874be..ed17c3be71c4 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -138,7 +138,10 @@ static int process_sample_event(struct evlist *evlist, goto out; } - evsel = evlist__id2evsel(evlist, sample.id); + evsel = sample.evsel; + if (!evsel) + evsel = evlist__id2evsel(evlist, sample.id); + if (evsel == switch_tracking->switch_evsel) { next_tid = perf_sample__intval(&sample, "next_pid"); prev_tid = perf_sample__intval(&sample, "prev_pid"); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 23/25] perf script: Don't pass evsel with sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (21 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 22/25] perf evlist: Try to avoid computing evsel from sample Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 24/25] perf s390-sample-raw: " Ian Rogers ` (2 subsequent siblings) 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Remove the evsel from the struct scripting_context so that the sample version is always accessed. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-script.c | 12 ++++-- .../util/scripting-engines/trace-event-perl.c | 21 +++++------ .../scripting-engines/trace-event-python.c | 37 ++++++++----------- tools/perf/util/trace-event-scripting.c | 5 +-- tools/perf/util/trace-event.h | 3 -- 5 files changed, 33 insertions(+), 45 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8022801721e2..53da706d959f 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2418,12 +2418,13 @@ static bool show_event(struct perf_sample *sample, } static void process_event(struct perf_script *script, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al, struct machine *machine) { struct thread *thread = al->thread; + struct evsel *evsel = sample->evsel; struct perf_event_attr *attr = &evsel->core.attr; unsigned int type = evsel__output_type(evsel); struct evsel_script *es = evsel->priv; @@ -2714,9 +2715,9 @@ static int process_sample_event(const struct perf_tool *tool, thread__resolve(al.thread, &addr_al, sample); addr_al_ptr = &addr_al; } - scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr); + scripting_ops->process_event(event, sample, &al, addr_al_ptr); } else { - process_event(scr, sample, evsel, &al, &addr_al, machine); + process_event(scr, sample, &al, &addr_al, machine); } out_put: @@ -2892,9 +2893,12 @@ static int print_event_with_time(const struct perf_tool *tool, { struct perf_script *script = container_of(tool, struct perf_script, tool); struct perf_session *session = script->session; - struct evsel *evsel = evlist__id2evsel(session->evlist, sample->id); + struct evsel *evsel = sample->evsel; struct thread *thread = NULL; + if (!evsel) + evsel = evlist__id2evsel(session->evlist, sample->id); + if (evsel && !evsel->core.attr.sample_id_all) { sample->cpu = 0; sample->time = timestamp; diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index af0d514b2397..7a18ea4b7d50 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -257,7 +257,6 @@ static void define_event_symbols(struct tep_event *event, } static SV *perl_process_callchain(struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct addr_location *al) { struct callchain_cursor *cursor; @@ -340,7 +339,6 @@ static SV *perl_process_callchain(struct perf_sample *sample, } static void perl_process_tracepoint(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al) { struct thread *thread = al->thread; @@ -355,6 +353,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, unsigned long long nsecs = sample->time; const char *comm = thread__comm_str(thread); DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX); + struct evsel *evsel = sample->evsel; bitmap_zero(events_defined, TRACE_EVENT_TYPE_MAX); dSP; @@ -389,7 +388,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, XPUSHs(sv_2mortal(newSVuv(ns))); XPUSHs(sv_2mortal(newSViv(pid))); XPUSHs(sv_2mortal(newSVpv(comm, 0))); - XPUSHs(sv_2mortal(perl_process_callchain(sample, evsel, al))); + XPUSHs(sv_2mortal(perl_process_callchain(sample, al))); /* common fields other than pid can be accessed via xsub fns */ @@ -426,7 +425,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, XPUSHs(sv_2mortal(newSVuv(nsecs))); XPUSHs(sv_2mortal(newSViv(pid))); XPUSHs(sv_2mortal(newSVpv(comm, 0))); - XPUSHs(sv_2mortal(perl_process_callchain(sample, evsel, al))); + XPUSHs(sv_2mortal(perl_process_callchain(sample, al))); call_pv("main::trace_unhandled", G_SCALAR); } SPAGAIN; @@ -435,9 +434,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, LEAVE; } -static void perl_process_event_generic(union perf_event *event, - struct perf_sample *sample, - struct evsel *evsel) +static void perl_process_event_generic(union perf_event *event, struct perf_sample *sample) { dSP; @@ -448,7 +445,8 @@ static void perl_process_event_generic(union perf_event *event, SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVpvn((const char *)event, event->header.size))); - XPUSHs(sv_2mortal(newSVpvn((const char *)&evsel->core.attr, sizeof(evsel->core.attr)))); + XPUSHs(sv_2mortal(newSVpvn((const char *)&sample->evsel->core.attr, + sizeof(sample->evsel->core.attr)))); XPUSHs(sv_2mortal(newSVpvn((const char *)sample, sizeof(*sample)))); XPUSHs(sv_2mortal(newSVpvn((const char *)sample->raw_data, sample->raw_size))); PUTBACK; @@ -461,13 +459,12 @@ static void perl_process_event_generic(union perf_event *event, static void perl_process_event(union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { - scripting_context__update(scripting_context, event, sample, evsel, al, addr_al); - perl_process_tracepoint(sample, evsel, al); - perl_process_event_generic(event, sample, evsel); + scripting_context__update(scripting_context, event, sample, al, addr_al); + perl_process_tracepoint(sample, al); + perl_process_event_generic(event, sample); } static void run_start_sub(void) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 8de08cebe240..63d04b051846 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -390,7 +390,6 @@ static unsigned long get_offset(struct symbol *sym, struct addr_location *al) } static PyObject *python_process_callchain(struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct addr_location *al) { PyObject *pylist; @@ -651,11 +650,9 @@ static PyObject *get_sample_value_as_tuple(struct sample_read_value *value, return t; } -static void set_sample_read_in_dict(PyObject *dict_sample, - struct perf_sample *sample, - struct evsel *evsel) +static void set_sample_read_in_dict(PyObject *dict_sample, struct perf_sample *sample) { - u64 read_format = evsel->core.attr.read_format; + u64 read_format = sample->evsel->core.attr.read_format; PyObject *values; unsigned int i; @@ -741,11 +738,10 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, uint16_t e_machine, static int set_regs_in_dict(PyObject *dict, struct perf_sample *sample, - struct evsel *evsel, uint16_t e_machine, uint32_t e_flags) { - struct perf_event_attr *attr = &evsel->core.attr; + struct perf_event_attr *attr = &sample->evsel->core.attr; int size = (__sw_hweight64(attr->sample_regs_intr) * MAX_REG_SIZE) + 1; char *bf = NULL; @@ -831,7 +827,6 @@ static void python_process_sample_flags(struct perf_sample *sample, PyObject *di } static PyObject *get_perf_sample_dict(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al, PyObject *callchain) @@ -839,6 +834,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, PyObject *dict, *dict_sample, *brstack, *brstacksym; uint16_t e_machine = EM_HOST; uint32_t e_flags = EF_HOST; + struct evsel *evsel = sample->evsel; dict = PyDict_New(); if (!dict) @@ -871,7 +867,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, PyLong_FromUnsignedLongLong(sample->phys_addr)); pydict_set_item_string_decref(dict_sample, "addr", PyLong_FromUnsignedLongLong(sample->addr)); - set_sample_read_in_dict(dict_sample, sample, evsel); + set_sample_read_in_dict(dict_sample, sample); pydict_set_item_string_decref(dict_sample, "weight", PyLong_FromUnsignedLongLong(sample->weight)); pydict_set_item_string_decref(dict_sample, "ins_lat", @@ -928,7 +924,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, if (al->thread) e_machine = thread__e_machine(al->thread, /*machine=*/NULL, &e_flags); - if (set_regs_in_dict(dict, sample, evsel, e_machine, e_flags)) + if (set_regs_in_dict(dict, sample, e_machine, e_flags)) Py_FatalError("Failed to setting regs in dict"); return dict; @@ -936,7 +932,6 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, #ifdef HAVE_LIBTRACEEVENT static void python_process_tracepoint(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { @@ -954,6 +949,7 @@ static void python_process_tracepoint(struct perf_sample *sample, const char *comm = thread__comm_str(al->thread); const char *default_handler_name = "trace_unhandled"; DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX); + struct evsel *evsel = sample->evsel; bitmap_zero(events_defined, TRACE_EVENT_TYPE_MAX); @@ -995,7 +991,7 @@ static void python_process_tracepoint(struct perf_sample *sample, PyTuple_SetItem(t, n++, context); /* ip unwinding */ - callchain = python_process_callchain(sample, evsel, al); + callchain = python_process_callchain(sample, al); /* Need an additional reference for the perf_sample dict */ Py_INCREF(callchain); @@ -1051,7 +1047,7 @@ static void python_process_tracepoint(struct perf_sample *sample, PyTuple_SetItem(t, n++, dict); if (get_argument_count(handler) == (int) n + 1) { - all_entries_dict = get_perf_sample_dict(sample, evsel, al, addr_al, + all_entries_dict = get_perf_sample_dict(sample, al, addr_al, callchain); PyTuple_SetItem(t, n++, all_entries_dict); } else { @@ -1070,7 +1066,6 @@ static void python_process_tracepoint(struct perf_sample *sample, } #else static void python_process_tracepoint(struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct addr_location *al __maybe_unused, struct addr_location *addr_al __maybe_unused) { @@ -1465,7 +1460,6 @@ static int python_process_call_return(struct call_return *cr, u64 *parent_db_id, } static void python_process_general_event(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { @@ -1488,8 +1482,8 @@ static void python_process_general_event(struct perf_sample *sample, Py_FatalError("couldn't create Python tuple"); /* ip unwinding */ - callchain = python_process_callchain(sample, evsel, al); - dict = get_perf_sample_dict(sample, evsel, al, addr_al, callchain); + callchain = python_process_callchain(sample, al); + dict = get_perf_sample_dict(sample, al, addr_al, callchain); PyTuple_SetItem(t, n++, dict); if (_PyTuple_Resize(&t, n) == -1) @@ -1502,24 +1496,23 @@ static void python_process_general_event(struct perf_sample *sample, static void python_process_event(union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { struct tables *tables = &tables_global; - scripting_context__update(scripting_context, event, sample, evsel, al, addr_al); + scripting_context__update(scripting_context, event, sample, al, addr_al); - switch (evsel->core.attr.type) { + switch (sample->evsel->core.attr.type) { case PERF_TYPE_TRACEPOINT: - python_process_tracepoint(sample, evsel, al, addr_al); + python_process_tracepoint(sample, al, addr_al); break; /* Reserve for future process_hw/sw/raw APIs */ default: if (tables->db_export_mode) db_export__sample(&tables->dbe, event, sample, al, addr_al); else - python_process_general_event(sample, evsel, al, addr_al); + python_process_general_event(sample, al, addr_al); } } diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c index fa850e44cb46..dc584ac316a3 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -103,12 +103,11 @@ int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec) void scripting_context__update(struct scripting_context *c, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { #ifdef HAVE_LIBTRACEEVENT - const struct tep_event *tp_format = evsel__tp_format(evsel); + const struct tep_event *tp_format = evsel__tp_format(sample->evsel); c->pevent = tp_format ? tp_format->tep : NULL; #else @@ -117,7 +116,6 @@ void scripting_context__update(struct scripting_context *c, c->event_data = sample->raw_data; c->event = event; c->sample = sample; - c->evsel = evsel; c->al = al; c->addr_al = addr_al; } @@ -134,7 +132,6 @@ static int stop_script_unsupported(void) static void process_event_unsupported(union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct addr_location *al __maybe_unused, struct addr_location *addr_al __maybe_unused) { diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 914d9b69ed62..720121c74f1d 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -94,7 +94,6 @@ struct scripting_ops { int (*stop_script) (void); void (*process_event) (union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al); void (*process_switch)(union perf_event *event, @@ -124,7 +123,6 @@ struct scripting_context { void *event_data; union perf_event *event; struct perf_sample *sample; - struct evsel *evsel; struct addr_location *al; struct addr_location *addr_al; struct perf_session *session; @@ -133,7 +131,6 @@ struct scripting_context { void scripting_context__update(struct scripting_context *scripting_context, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 24/25] perf s390-sample-raw: Don't pass evsel with sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (22 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 23/25] perf script: Don't pass evsel with sample Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 8:08 ` [PATCH v3 25/25] perf evsel: " Ian Rogers 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/s390-sample-raw.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c index c6ae0ae8d86a..bfa342536b9b 100644 --- a/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -284,8 +284,9 @@ static bool s390_pai_all_test(struct perf_sample *sample) return true; } -static void s390_pai_all_dump(struct evsel *evsel, struct perf_sample *sample) +static void s390_pai_all_dump(struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; size_t len = sample->raw_size, offset = 0; unsigned char *p = sample->raw_data; const char *color = PERF_COLOR_BLUE; @@ -332,14 +333,16 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, struct perf_sample *sample) { const char *pai_name; - struct evsel *evsel; + struct evsel *evsel = sample->evsel; if (event->header.type != PERF_RECORD_SAMPLE) return; - evsel = evlist__event2evsel(evlist, event); - if (!evsel) - return; + if (!evsel) { + evsel = evlist__event2evsel(evlist, event); + if (!evsel) + return; + } /* Check for raw data in sample */ if (!sample->raw_size || !sample->raw_data) @@ -372,6 +375,6 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, } else { if (!evsel->pmu) evsel->pmu = perf_pmus__find_by_type(evsel->core.attr.type); - s390_pai_all_dump(evsel, sample); + s390_pai_all_dump(sample); } } -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v3 25/25] perf evsel: Don't pass evsel with sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (23 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 24/25] perf s390-sample-raw: " Ian Rogers @ 2026-03-20 8:08 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers 25 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 8:08 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Arrange for the sample to contain the evsel and so it is unnecessary to pass the evsel as well. This is done for uniformity, although parsing of the sample is arguably a special case. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/evsel.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 1074eebbda89..9508d9430174 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2997,10 +2997,10 @@ 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; @@ -3239,14 +3239,14 @@ 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); + perf_evsel__parse_id_sample(event, data); return 0; } if (event->header.type != PERF_RECORD_SAMPLE) { if (evsel->core.attr.sample_id_all) - perf_evsel__parse_id_sample(evsel, event, data); + perf_evsel__parse_id_sample(event, data); return 0; } @@ -3608,12 +3608,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; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 00/25] perf tool: Add evsel to perf_sample 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (24 preceding siblings ...) 2026-03-20 8:08 ` [PATCH v3 25/25] perf evsel: " Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 01/25] perf sample: Document struct perf_sample Ian Rogers ` (24 more replies) 25 siblings, 25 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Nearly all perf code ends up passing an evsel with the perf_sample, which is problematic if you want to rewrite the evsel such as with off-CPU processing - all uses of the evsel need fixing up. Previously I'd mailed this patch as an RFC with everything combined: https://lore.kernel.org/lkml/20260126071822.447368-1-irogers@google.com/ and there was a request to break it up. I've started the series by adding documentation to struct perf_sample. Next I fixed missing perf_sample__init/exit largely from the recent perf inject callchain rewriting work. The 3rd patch adds the evsel to struct perf_sample and ensures it is correctly initialized. The next 22 patches avoid passing the evsel along with sample for different parts of the perf tool, along with some minor tweaks like constification and not determining the evsel if it is present in the sample. v4: Fix more sashiko issues: bounds checks, memory safety, making refactors better, inconsistent evsels, mmap2 buildid injection choice of evsel, mismatched function arguments. https://sashiko.dev/#/patchset/20260320080835.724836-1-irogers%40google.com v3: Fix various sashiko review comments particularly about unintended behavior changes. https://lore.kernel.org/lkml/20260320080835.724836-1-irogers@google.com/ v2: Add review feedback on the first 2 patches from Namhyung, fix a missed evsel assignment running event2evsel in builtin-inject. https://lore.kernel.org/lkml/20260319232334.287517-1-irogers@google.com/ v1: https://lore.kernel.org/lkml/20260209174032.4142096-1-irogers@google.com/ Ian Rogers (25): perf sample: Document struct perf_sample perf sample: Make sure perf_sample__init/exit are used perf sample: Add evsel to struct perf_sample perf tool: Remove evsel from tool APIs that pass the sample perf kvm: Don't pass evsel with sample perf evsel: Refactor evsel__intval to perf_sample__intval perf trace: Don't pass evsel with sample perf callchain: Don't pass evsel and sample perf lock: Only pass sample to handlers perf lock: Constify trace_lock_handler variables perf hist: Remove evsel parameter from inc samples functions perf db-export: Remove evsel from struct export_sample perf hist: Remove evsel from struct hist_entry_iter perf report: Directly use sample->evsel to avoid computing from sample->id perf annotate: Don't pass evsel to add_sample perf inject: Don't pass evsel with sample perf kmem: Don't pass evsel with sample perf kwork: Don't pass evsel with sample perf sched: Don't pass evsel with sample perf timechart: Don't pass evsel with sample perf trace: Don't pass evsel with sample perf evlist: Try to avoid computing evsel from sample perf script: Don't pass evsel with sample perf s390-sample-raw: Don't pass evsel or its PMU with sample perf evsel: Don't pass evsel with sample tools/perf/builtin-annotate.c | 28 ++- tools/perf/builtin-c2c.c | 6 +- tools/perf/builtin-diff.c | 5 +- tools/perf/builtin-inject.c | 87 ++++---- tools/perf/builtin-kmem.c | 85 ++++---- tools/perf/builtin-kvm.c | 22 +- tools/perf/builtin-kwork.c | 104 ++++------ tools/perf/builtin-lock.c | 117 +++++------ tools/perf/builtin-mem.c | 1 - tools/perf/builtin-record.c | 3 +- tools/perf/builtin-report.c | 38 ++-- tools/perf/builtin-sched.c | 188 ++++++++---------- tools/perf/builtin-script.c | 26 ++- tools/perf/builtin-timechart.c | 145 +++++++------- tools/perf/builtin-top.c | 19 +- tools/perf/builtin-trace.c | 120 +++++------ tools/perf/tests/hists_cumulate.c | 3 +- tools/perf/tests/hists_filter.c | 2 +- tools/perf/tests/hists_output.c | 3 +- tools/perf/tests/mmap-basic.c | 4 +- tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/tests/perf-record.c | 1 + tools/perf/tests/switch-tracking.c | 11 +- tools/perf/util/annotate.c | 19 +- tools/perf/util/annotate.h | 6 +- tools/perf/util/build-id.c | 3 +- tools/perf/util/build-id.h | 7 +- tools/perf/util/callchain.c | 18 +- tools/perf/util/callchain.h | 5 +- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data-convert-json.c | 5 +- tools/perf/util/db-export.c | 13 +- tools/perf/util/db-export.h | 3 +- tools/perf/util/evlist.c | 5 +- tools/perf/util/evsel.c | 101 +++++++--- tools/perf/util/evsel.h | 12 +- tools/perf/util/hist.c | 26 +-- tools/perf/util/hist.h | 3 +- tools/perf/util/intel-pt.c | 2 +- tools/perf/util/intel-tpebs.c | 3 +- tools/perf/util/jitdump.c | 2 +- .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 19 +- .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 +- .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 +- .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 17 +- tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +- tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 +++---- tools/perf/util/kvm-stat.c | 19 +- tools/perf/util/kvm-stat.h | 18 +- tools/perf/util/kwork.h | 9 +- tools/perf/util/machine.c | 14 +- tools/perf/util/machine.h | 3 - tools/perf/util/powerpc-vpadtl.c | 10 +- tools/perf/util/s390-sample-raw.c | 31 +-- tools/perf/util/sample.c | 11 +- tools/perf/util/sample.h | 119 ++++++++++- .../util/scripting-engines/trace-event-perl.c | 23 +-- .../scripting-engines/trace-event-python.c | 47 ++--- tools/perf/util/session.c | 74 ++++--- tools/perf/util/synthetic-events.c | 45 +++-- tools/perf/util/synthetic-events.h | 2 - tools/perf/util/tool.c | 4 +- tools/perf/util/tool.h | 4 +- tools/perf/util/trace-event-scripting.c | 5 +- tools/perf/util/trace-event.h | 3 - 65 files changed, 973 insertions(+), 883 deletions(-) -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply [flat|nested] 112+ messages in thread
* [PATCH v4 01/25] perf sample: Document struct perf_sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers ` (23 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Add kernel-doc for struct perf_sample capturing the somewhat unusual population of fields and lifetime relationships. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/sample.h | 109 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 3cce8dd202aa..8d4ace0e6594 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -81,47 +81,148 @@ struct simd_flags { #define SIMD_OP_FLAGS_PRED_PARTIAL 0x01 /* partial predicate */ #define SIMD_OP_FLAGS_PRED_EMPTY 0x02 /* empty predicate */ +/** + * struct perf_sample + * + * A sample is generally filled in by evlist__parse_sample/evsel__parse_sample + * which fills in the variables from a "union perf_event *event" which is data + * from a perf ring buffer or perf.data file. The "event" sample is variable in + * length as determined by the perf_event_attr (in the evsel) and details within + * the sample event itself. A struct perf_sample avoids needing to care about + * the variable length nature of the original event. + * + * To avoid being excessively large parts of the struct perf_sample are pointers + * into the original sample event. In general the lifetime of a struct + * perf_sample needs to be less than the "union perf_event *event" it was + * derived from. + * + * The struct regs_dump user_regs and intr_regs are lazily allocated again for + * size reasons, due to them holding a cache of looked up registers. The + * function pair of perf_sample__init and perf_sample__exit correctly initialize + * and clean up these values. + */ struct perf_sample { + /** @ip: The sample event PERF_SAMPLE_IP value. */ u64 ip; - u32 pid, tid; + /** @pid: The sample event PERF_SAMPLE_TID pid value. */ + u32 pid; + /** @tid: The sample event PERF_SAMPLE_TID tid value. */ + u32 tid; + /** @time: The sample event PERF_SAMPLE_TIME value. */ u64 time; + /** @addr: The sample event PERF_SAMPLE_ADDR value. */ u64 addr; + /** @id: The sample event PERF_SAMPLE_ID value. */ u64 id; + /** @stream_id: The sample event PERF_SAMPLE_STREAM_ID value. */ u64 stream_id; + /** @period: The sample event PERF_SAMPLE_PERIOD value. */ u64 period; + /** @weight: Data determined by PERF_SAMPLE_WEIGHT or PERF_SAMPLE_WEIGHT_STRUCT. */ u64 weight; + /** @transaction: The sample event PERF_SAMPLE_TRANSACTION value. */ u64 transaction; + /** @insn_cnt: Filled in and used by intel-pt. */ u64 insn_cnt; + /** @cyc_cnt: Filled in and used by intel-pt. */ u64 cyc_cnt; + /** @cpu: The sample event PERF_SAMPLE_CPU value. */ u32 cpu; + /** + * @raw_size: The size in bytes of raw data from PERF_SAMPLE_RAW. For + * alignment reasons this should always be sizeof(u32) + * followed by a multiple of sizeof(u64). + */ u32 raw_size; + /** @data_src: The sample event PERF_SAMPLE_DATA_SRC value. */ u64 data_src; + /** @phys_addr: The sample event PERF_SAMPLE_PHYS_ADDR value. */ u64 phys_addr; + /** @data_page_size: The sample event PERF_SAMPLE_DATA_PAGE_SIZE value. */ u64 data_page_size; + /** @code_page_size: The sample event PERF_SAMPLE_CODE_PAGE_SIZE value. */ u64 code_page_size; + /** @cgroup: The sample event PERF_SAMPLE_CGROUP value. */ u64 cgroup; + /** @flags: Extra flag data from auxiliary events like intel-pt. */ u32 flags; + /** @machine_pid: The guest machine pid derived from the sample id. */ u32 machine_pid; + /** @vcpu: The guest machine vcpu derived from the sample id. */ u32 vcpu; + /** + * @insn_len: Instruction length from auxiliary events like + * intel-pt. The instruction itself is held in insn. + */ u16 insn_len; + /** + * @cpumode: The cpumode from struct perf_event_header misc variable + * masked with CPUMODE_MASK. Gives user, kernel and hypervisor + * information. + */ u8 cpumode; + /** @misc: The entire struct perf_event_header misc variable. */ u16 misc; + /** + * @ins_lat: Instruction latency information from weight2 in + * PERF_SAMPLE_WEIGHT_STRUCT or auxiliary events like + * intel-pt. + */ u16 ins_lat; - /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */ + /** + * @weight3: From PERF_SAMPLE_WEIGHT_STRUCT. On x86 holds retire_lat, on + * powerpc holds p_stage_cyc. + */ u16 weight3; - bool no_hw_idx; /* No hw_idx collected in branch_stack */ - bool deferred_callchain; /* Has deferred user callchains */ + /** + * @no_hw_idx: For PERF_SAMPLE_BRANCH_STACK, true when + * PERF_SAMPLE_BRANCH_HW_INDEX isn't set. + */ + bool no_hw_idx; + /** + * @deferred_callchain: When processing PERF_SAMPLE_CALLCHAIN a deferred + * user callchain marker was encountered. + */ + bool deferred_callchain; + /** + * @deferred_cookie: Identifier of the deferred callchain in the later + * PERF_RECORD_CALLCHAIN_DEFERRED event. + */ u64 deferred_cookie; + /** @insn: A copy of the sampled instruction filled in by perf_sample__fetch_insn. */ char insn[MAX_INSN]; + /** @raw_data: Pointer into the original event for PERF_SAMPLE_RAW data. */ void *raw_data; + /** + * @callchain: Pointer into the original event for PERF_SAMPLE_CALLCHAIN + * data. For deferred callchains this may be a copy that + * needs freeing, see sample__merge_deferred_callchain. + */ struct ip_callchain *callchain; + /** @branch_stack: Pointer into the original event for PERF_SAMPLE_BRANCH_STACK data. */ struct branch_stack *branch_stack; + /** + * @branch_stack_cntr: Pointer into the original event for + * PERF_SAMPLE_BRANCH_COUNTERS data. + */ u64 *branch_stack_cntr; + /** @user_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_USER. */ struct regs_dump *user_regs; + /** @intr_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_INTR. */ struct regs_dump *intr_regs; + /** @user_stack: Size and pointer into the sample for PERF_SAMPLE_STACK_USER. */ struct stack_dump user_stack; + /** + * @read: The sample event PERF_SAMPLE_READ counter values. The valid + * values depend on the attr.read_format PERF_FORMAT_ values. + */ struct sample_read read; + /** + * @aux_sample: Similar to raw data but with a 64-bit size and + * alignment, PERF_SAMPLE_AUX data. + */ struct aux_sample aux_sample; + /** @simd_flags: SIMD flag information from ARM SPE auxiliary events. */ struct simd_flags simd_flags; }; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 02/25] perf sample: Make sure perf_sample__init/exit are used 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 01/25] perf sample: Document struct perf_sample Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 03/25] perf sample: Add evsel to struct perf_sample Ian Rogers ` (22 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The deferred stack trace code wasn't using perf_sample__init/exit. Add the deferred stack trace clean up to perf_sample__exit which requires proper NULL initialization in perf_sample__init. Make the perf_sample__exit robust to being called more than once by using zfree. Make the error paths in evsel__parse_sample exit the sample. Add a merged_callchain boolean to capture that callchain is allocated, deferred_callchain doen't suffice for this. Pack the struct variables to avoid padding bytes for this. Similiarly powerpc_vpadtl_sample wasn't using perf_sample__init/exit, use it for consistency and potential issues with uninitialized variables. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 6 +++++- tools/perf/tests/perf-record.c | 1 + tools/perf/tests/switch-tracking.c | 2 ++ tools/perf/util/callchain.c | 10 ++++++--- tools/perf/util/evlist.c | 5 ++++- tools/perf/util/evsel.c | 34 ++++++++++++++++++------------ tools/perf/util/powerpc-vpadtl.c | 10 +++++---- tools/perf/util/sample.c | 10 +++++++-- tools/perf/util/sample.h | 17 +++++++++------ tools/perf/util/session.c | 13 ++++++++---- 10 files changed, 74 insertions(+), 34 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 5b29f4296861..8b9a0a4097af 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1087,6 +1087,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, struct perf_sample sample_sw; struct perf_inject *inject = container_of(tool, struct perf_inject, tool); u32 pid = evsel__intval(evsel, sample, "pid"); + int ret; list_for_each_entry(ent, &inject->samples, node) { if (pid == ent->tid) @@ -1103,7 +1104,9 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, evsel->core.attr.read_format, &sample_sw); build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); - return perf_event__repipe(tool, event_sw, &sample_sw, machine); + ret = perf_event__repipe(tool, event_sw, &sample_sw, machine); + perf_sample__exit(&sample_sw); + return ret; } #endif @@ -1826,6 +1829,7 @@ static int guest_session__inject_events(struct guest_session *gs, u64 timestamp) return -EINVAL; } + perf_sample__exit(sample); gs->fetched = false; ret = output_bytes(inject, ev, ev->header.size); diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index efbd9cd60c63..7b881f08906d 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -297,6 +297,7 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest } perf_mmap__consume(&md->core); + perf_sample__exit(&sample); } perf_mmap__read_done(&md->core); } diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index 15791fcb76b2..72a8289e846d 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -239,11 +239,13 @@ static int add_event(struct evlist *evlist, struct list_head *events, if (!sample.time) { pr_debug("event with no time\n"); + perf_sample__exit(&sample); return -1; } node->event_time = sample.time; + perf_sample__exit(&sample); return 0; } diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 8ff0898799ee..19c97137103c 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1854,16 +1854,19 @@ int sample__merge_deferred_callchain(struct perf_sample *sample_orig, u64 nr_deferred = sample_callchain->callchain->nr; struct ip_callchain *callchain; + if (sample_orig->merged_callchain) { + /* Already merged. */ + return -EINVAL; + } + if (sample_orig->callchain->nr < 2) { sample_orig->deferred_callchain = false; return -EINVAL; } callchain = calloc(1 + nr_orig + nr_deferred, sizeof(u64)); - if (callchain == NULL) { - sample_orig->deferred_callchain = false; + if (callchain == NULL) return -ENOMEM; - } callchain->nr = nr_orig + nr_deferred; /* copy original including PERF_CONTEXT_USER_DEFERRED (but the cookie) */ @@ -1872,6 +1875,7 @@ int sample__merge_deferred_callchain(struct perf_sample *sample_orig, memcpy(&callchain->ips[nr_orig], sample_callchain->callchain->ips, nr_deferred * sizeof(u64)); + sample_orig->merged_callchain = true; sample_orig->callchain = callchain; return 0; } diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 591bdf0b3e2a..bdb196425071 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1622,8 +1622,11 @@ int evlist__parse_sample(struct evlist *evlist, union perf_event *event, struct struct evsel *evsel = evlist__event2evsel(evlist, event); int ret; - if (!evsel) + if (!evsel) { + /* Ensure the sample is okay for perf_sample__exit. */ + perf_sample__init(sample, /*all=*/false); return -EFAULT; + } ret = evsel__parse_sample(evsel, event, sample); if (ret) return ret; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f59228c1a39e..59efe460d9bc 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3067,7 +3067,7 @@ static inline bool overflow(const void *endp, u16 max_size, const void *offset, #define OVERFLOW_CHECK(offset, size, max_size) \ do { \ if (overflow(endp, (max_size), (offset), (size))) \ - return -EFAULT; \ + goto out_efault; \ } while (0) #define OVERFLOW_CHECK_u64(offset) \ @@ -3199,6 +3199,8 @@ static int __set_offcpu_sample(struct perf_sample *data) data->cgroup = *array; return 0; +out_efault: + return -EFAULT; } int evsel__parse_sample(struct evsel *evsel, union perf_event *event, @@ -3217,7 +3219,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, */ union u64_swap u; - memset(data, 0, sizeof(*data)); + perf_sample__init(data, /*all=*/true); data->cpu = data->pid = data->tid = -1; data->stream_id = data->id = data->time = -1ULL; data->period = evsel->core.attr.sample_period; @@ -3231,25 +3233,26 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->callchain = (struct ip_callchain *)&event->callchain_deferred.nr; if (data->callchain->nr > max_callchain_nr) - return -EFAULT; + goto out_efault; data->deferred_cookie = event->callchain_deferred.cookie; if (evsel->core.attr.sample_id_all) perf_evsel__parse_id_sample(evsel, event, data); + return 0; } if (event->header.type != PERF_RECORD_SAMPLE) { - if (!evsel->core.attr.sample_id_all) - return 0; - return perf_evsel__parse_id_sample(evsel, event, data); + if (evsel->core.attr.sample_id_all) + perf_evsel__parse_id_sample(evsel, event, data); + return 0; } array = event->sample.array; if (perf_event__check_size(event, evsel->sample_size)) - return -EFAULT; + goto out_efault; if (type & PERF_SAMPLE_IDENTIFIER) { data->id = *array; @@ -3342,7 +3345,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, sizeof(struct sample_read_value); if (data->read.group.nr > max_group_nr) - return -EFAULT; + goto out_efault; sz = data->read.group.nr * sample_read_value_size(read_format); OVERFLOW_CHECK(array, sz, max_size); @@ -3370,7 +3373,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->callchain = (struct ip_callchain *)array++; callchain_nr = data->callchain->nr; if (callchain_nr > max_callchain_nr) - return -EFAULT; + goto out_efault; sz = callchain_nr * sizeof(u64); /* * Save the cookie for the deferred user callchain. The last 2 @@ -3428,7 +3431,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->branch_stack = (struct branch_stack *)array++; if (data->branch_stack->nr > max_branch_nr) - return -EFAULT; + goto out_efault; sz = data->branch_stack->nr * sizeof(struct branch_entry); if (evsel__has_branch_hw_idx(evsel)) { @@ -3505,7 +3508,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->user_stack.size = *array++; if (WARN_ONCE(data->user_stack.size > sz, "user stack dump failure\n")) - return -EFAULT; + goto out_efault; } } @@ -3582,10 +3585,15 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, array = (void *)array + sz; } - if (evsel__is_offcpu_event(evsel)) - return __set_offcpu_sample(data); + if (evsel__is_offcpu_event(evsel)) { + if (__set_offcpu_sample(data)) + goto out_efault; + } return 0; +out_efault: + perf_sample__exit(data); + return -EFAULT; } int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event, diff --git a/tools/perf/util/powerpc-vpadtl.c b/tools/perf/util/powerpc-vpadtl.c index d1c3396f182f..993ab16614c7 100644 --- a/tools/perf/util/powerpc-vpadtl.c +++ b/tools/perf/util/powerpc-vpadtl.c @@ -182,7 +182,9 @@ static int powerpc_vpadtl_sample(struct powerpc_vpadtl_entry *record, { struct perf_sample sample; union perf_event event; + int ret; + perf_sample__init(&sample, /*all=*/true); sample.ip = be64_to_cpu(record->srr0); sample.period = 1; sample.cpu = cpu; @@ -198,12 +200,12 @@ static int powerpc_vpadtl_sample(struct powerpc_vpadtl_entry *record, event.sample.header.misc = sample.cpumode; event.sample.header.size = sizeof(struct perf_event_header); - if (perf_session__deliver_synth_event(vpa->session, &event, &sample)) { + ret = perf_session__deliver_synth_event(vpa->session, &event, &sample); + if (ret) pr_debug("Failed to create sample for dtl entry\n"); - return -1; - } - return 0; + perf_sample__exit(&sample); + return ret; } static int powerpc_vpadtl_get_buffer(struct powerpc_vpadtl_queue *vpaq) diff --git a/tools/perf/util/sample.c b/tools/perf/util/sample.c index 8f82aaf1aab6..2a30de4573f6 100644 --- a/tools/perf/util/sample.c +++ b/tools/perf/util/sample.c @@ -21,13 +21,19 @@ void perf_sample__init(struct perf_sample *sample, bool all) } else { sample->user_regs = NULL; sample->intr_regs = NULL; + sample->merged_callchain = false; + sample->callchain = NULL; } } void perf_sample__exit(struct perf_sample *sample) { - free(sample->user_regs); - free(sample->intr_regs); + zfree(&sample->user_regs); + zfree(&sample->intr_regs); + if (sample->merged_callchain) { + zfree(&sample->callchain); + sample->merged_callchain = false; + } } struct regs_dump *perf_sample__user_regs(struct perf_sample *sample) diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 8d4ace0e6594..5809c42631e5 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -155,12 +155,6 @@ struct perf_sample { * intel-pt. The instruction itself is held in insn. */ u16 insn_len; - /** - * @cpumode: The cpumode from struct perf_event_header misc variable - * masked with CPUMODE_MASK. Gives user, kernel and hypervisor - * information. - */ - u8 cpumode; /** @misc: The entire struct perf_event_header misc variable. */ u16 misc; /** @@ -174,6 +168,12 @@ struct perf_sample { * powerpc holds p_stage_cyc. */ u16 weight3; + /** + * @cpumode: The cpumode from struct perf_event_header misc variable + * masked with CPUMODE_MASK. Gives user, kernel and hypervisor + * information. + */ + u8 cpumode; /** * @no_hw_idx: For PERF_SAMPLE_BRANCH_STACK, true when * PERF_SAMPLE_BRANCH_HW_INDEX isn't set. @@ -184,6 +184,11 @@ struct perf_sample { * user callchain marker was encountered. */ bool deferred_callchain; + /** + * @merged_callchain: A synthesized merged callchain that is allocated + * and needs freeing. + */ + bool merged_callchain; /** * @deferred_cookie: Identifier of the deferred callchain in the later * PERF_RECORD_CALLCHAIN_DEFERRED event. diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 4b465abfa36c..c48e840da7d4 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1367,14 +1367,18 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { struct perf_sample orig_sample; + perf_sample__init(&orig_sample, /*all=*/false); ret = evlist__parse_sample(evlist, de->event, &orig_sample); if (ret < 0) { pr_err("failed to parse original sample\n"); + perf_sample__exit(&orig_sample); break; } - if (sample->tid != orig_sample.tid) + if (sample->tid != orig_sample.tid) { + perf_sample__exit(&orig_sample); continue; + } if (event->callchain_deferred.cookie == orig_sample.deferred_cookie) sample__merge_deferred_callchain(&orig_sample, sample); @@ -1385,9 +1389,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, ret = evlist__deliver_sample(evlist, tool, de->event, &orig_sample, evsel, machine); - if (orig_sample.deferred_callchain) - free(orig_sample.callchain); - + perf_sample__exit(&orig_sample); list_del(&de->list); free(de->event); free(de); @@ -1414,9 +1416,11 @@ static int session__flush_deferred_samples(struct perf_session *session, list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { struct perf_sample sample; + perf_sample__init(&sample, /*all=*/false); ret = evlist__parse_sample(evlist, de->event, &sample); if (ret < 0) { pr_err("failed to parse original sample\n"); + perf_sample__exit(&sample); break; } @@ -1424,6 +1428,7 @@ static int session__flush_deferred_samples(struct perf_session *session, ret = evlist__deliver_sample(evlist, tool, de->event, &sample, evsel, machine); + perf_sample__exit(&sample); list_del(&de->list); free(de->event); free(de); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 03/25] perf sample: Add evsel to struct perf_sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 01/25] perf sample: Document struct perf_sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 04/25] perf tool: Remove evsel from tool APIs that pass the sample Ian Rogers ` (21 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Add the evsel from evsel__parse_sample into the struct perf_sample. Sometimes we want to alter the evsel associated with a sample, such as with off-cpu bpf-output events. In general the evsel and perf_sample are passed as a pair, but this makes an altered evsel something of a chore to keep checking for and setting up. Later patches will remove passing an evsel with the perf_sample and switch to just using the perf_sample's value. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 6 +++--- tools/perf/builtin-script.c | 4 ++++ tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 1 + tools/perf/tests/hists_output.c | 2 +- tools/perf/util/evsel.c | 1 + tools/perf/util/sample.c | 1 + tools/perf/util/sample.h | 3 +++ tools/perf/util/session.c | 35 +++++++++++++++++++------------ 9 files changed, 37 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 8b9a0a4097af..b7ecf78ef79b 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -133,7 +133,7 @@ struct perf_inject { struct perf_file_section secs[HEADER_FEAT_BITS]; struct guest_session guest_session; struct strlist *known_build_ids; - const struct evsel *mmap_evsel; + struct evsel *mmap_evsel; struct ip_callchain *raw_callchain; }; @@ -519,7 +519,7 @@ static struct dso *findnew_dso(int pid, int tid, const char *filename, * processing mmap events. If not stashed, search the evlist for the first mmap * gathering event. */ -static const struct evsel *inject__mmap_evsel(struct perf_inject *inject) +static struct evsel *inject__mmap_evsel(struct perf_inject *inject) { struct evsel *pos; @@ -1023,7 +1023,6 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, &args); - thread__put(thread); repipe: perf_event__repipe(tool, event, sample, machine); @@ -1432,6 +1431,7 @@ static int synthesize_build_id(struct perf_inject *inject, struct dso *dso, pid_ { struct machine *machine = perf_session__findnew_machine(inject->session, machine_pid); struct perf_sample synth_sample = { + .evsel = inject__mmap_evsel(inject), .pid = -1, .tid = -1, .time = -1, diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index b80c406d1fc1..8c3d06a3db62 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2909,8 +2909,12 @@ static int print_event_with_time(const struct perf_tool *tool, thread = machine__findnew_thread(machine, pid, tid); if (evsel) { + struct evsel *saved_evsel = sample->evsel; + + sample->evsel = evsel; perf_sample__fprintf_start(script, sample, thread, evsel, event->header.type, stdout); + sample->evsel = saved_evsel; } perf_event__fprintf(event, machine, stdout); diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c index 3eb9ef8d7ec6..606aa926a8fc 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -81,7 +81,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) { struct addr_location al; struct evsel *evsel = hists_to_evsel(hists); - struct perf_sample sample = { .period = 1000, }; + struct perf_sample sample = { .evsel = evsel, .period = 1000, }; size_t i; addr_location__init(&al); diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c index 1cebd20cc91c..cc6b26e373d1 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -70,6 +70,7 @@ static int add_hist_entries(struct evlist *evlist, }; struct hists *hists = evsel__hists(evsel); + sample.evsel = evsel; /* make sure it has no filter at first */ hists->thread_filter = NULL; hists->dso_filter = NULL; diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c index ee5ec8bda60e..7818950d786e 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -51,7 +51,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) { struct addr_location al; struct evsel *evsel = hists_to_evsel(hists); - struct perf_sample sample = { .period = 100, }; + struct perf_sample sample = { .evsel = evsel, .period = 100, }; size_t i; addr_location__init(&al); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 59efe460d9bc..29b1df875953 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3220,6 +3220,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, union u64_swap u; perf_sample__init(data, /*all=*/true); + data->evsel = evsel; data->cpu = data->pid = data->tid = -1; data->stream_id = data->id = data->time = -1ULL; data->period = evsel->core.attr.sample_period; diff --git a/tools/perf/util/sample.c b/tools/perf/util/sample.c index 2a30de4573f6..cf73329326d7 100644 --- a/tools/perf/util/sample.c +++ b/tools/perf/util/sample.c @@ -19,6 +19,7 @@ void perf_sample__init(struct perf_sample *sample, bool all) if (all) { memset(sample, 0, sizeof(*sample)); } else { + sample->evsel = NULL; sample->user_regs = NULL; sample->intr_regs = NULL; sample->merged_callchain = false; diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 5809c42631e5..3bd6d8b60586 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -5,6 +5,7 @@ #include <linux/perf_event.h> #include <linux/types.h> +struct evsel; struct machine; struct thread; @@ -102,6 +103,8 @@ struct simd_flags { * and clean up these values. */ struct perf_sample { + /** @evsel: Backward reference to the evsel used when constructing the sample. */ + struct evsel *evsel; /** @ip: The sample event PERF_SAMPLE_IP value. */ u64 ip; /** @pid: The sample event PERF_SAMPLE_TID pid value. */ diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c48e840da7d4..3794d3a04afb 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1257,8 +1257,9 @@ static int deliver_sample_value(struct evlist *evlist, bool per_thread) { struct perf_sample_id *sid = evlist__id2sid(evlist, v->id); - struct evsel *evsel; + struct evsel *saved_evsel = sample->evsel; u64 *storage = NULL; + int ret; if (sid) { storage = perf_sample_id__get_period_storage(sid, sample->tid, per_thread); @@ -1282,8 +1283,10 @@ static int deliver_sample_value(struct evlist *evlist, if (!sample->period) return 0; - evsel = container_of(sid->evsel, struct evsel, core); - return tool->sample(tool, event, sample, evsel, machine); + sample->evsel = container_of(sid->evsel, struct evsel, core); + ret = tool->sample(tool, event, sample, sample->evsel, machine); + sample->evsel = saved_evsel; + return ret; } static int deliver_sample_group(struct evlist *evlist, @@ -1355,13 +1358,16 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, struct machine *machine) { struct deferred_event *de, *tmp; - struct evsel *evsel; int ret = 0; if (!tool->merge_deferred_callchains) { - evsel = evlist__id2evsel(evlist, sample->id); - return tool->callchain_deferred(tool, event, sample, - evsel, machine); + struct evsel *saved_evsel = sample->evsel; + + sample->evsel = evlist__id2evsel(evlist, sample->id); + ret = tool->callchain_deferred(tool, event, sample, + sample->evsel, machine); + sample->evsel = saved_evsel; + return ret; } list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { @@ -1385,9 +1391,9 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, else orig_sample.deferred_callchain = false; - evsel = evlist__id2evsel(evlist, orig_sample.id); + orig_sample.evsel = evlist__id2evsel(evlist, orig_sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &orig_sample, evsel, machine); + &orig_sample, orig_sample.evsel, machine); perf_sample__exit(&orig_sample); list_del(&de->list); @@ -1410,7 +1416,6 @@ static int session__flush_deferred_samples(struct perf_session *session, struct evlist *evlist = session->evlist; struct machine *machine = &session->machines.host; struct deferred_event *de, *tmp; - struct evsel *evsel; int ret = 0; list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { @@ -1424,9 +1429,9 @@ static int session__flush_deferred_samples(struct perf_session *session, break; } - evsel = evlist__id2evsel(evlist, sample.id); + sample.evsel = evlist__id2evsel(evlist, sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &sample, evsel, machine); + &sample, sample.evsel, machine); perf_sample__exit(&sample); list_del(&de->list); @@ -1451,8 +1456,12 @@ static int machines__deliver_event(struct machines *machines, dump_event(evlist, event, file_offset, sample, file_path); - evsel = evlist__id2evsel(evlist, sample->id); + if (!sample->evsel) + sample->evsel = evlist__id2evsel(evlist, sample->id); + else + assert(sample->evsel == evlist__id2evsel(evlist, sample->id)); + evsel = sample->evsel; machine = machines__find_for_cpumode(machines, event, sample); switch (event->header.type) { -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 04/25] perf tool: Remove evsel from tool APIs that pass the sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (2 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 03/25] perf sample: Add evsel to struct perf_sample Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 05/25] perf kvm: Don't pass evsel with sample Ian Rogers ` (20 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Now struct perf_sample has the evsel within it there is no need to pass the evsel along with the sample. In the called functions read the sample's evsel in to a variable if there are multiple uses, or use directly if there is just one use - the goal being to leave the code with as little change as possible. Some functions only use the evsel to pass to another function which they also pass the sample, in those cases just pass the sample and get the evsel in the called function. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 3 +-- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-inject.c | 19 ++++++--------- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 5 ++-- tools/perf/builtin-kwork.c | 2 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-mem.c | 1 - tools/perf/builtin-record.c | 3 +-- tools/perf/builtin-report.c | 10 +++----- tools/perf/builtin-sched.c | 4 +-- tools/perf/builtin-script.c | 4 +-- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/build-id.c | 3 +-- tools/perf/util/build-id.h | 7 +----- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data-convert-json.c | 5 ++-- tools/perf/util/intel-tpebs.c | 3 +-- tools/perf/util/jitdump.c | 2 +- tools/perf/util/session.c | 38 ++++++++++++++--------------- tools/perf/util/tool.c | 4 +-- tools/perf/util/tool.h | 4 +-- 24 files changed, 55 insertions(+), 76 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 686ad08561d6..c97a0fe159f8 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -284,7 +284,6 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool); @@ -303,7 +302,7 @@ static int process_sample_event(const struct perf_tool *tool, goto out_put; if (!al.filtered && - evsel__add_sample(evsel, sample, &al, ann, machine)) { + evsel__add_sample(sample->evsel, sample, &al, ann, machine)) { pr_warning("problem incrementing symbol count, " "skipping event\n"); ret = -1; diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index d390ae4e3ec8..89456ba6fcbb 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -314,9 +314,9 @@ static void perf_c2c__evsel_hists_inc_stats(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; struct c2c_hists *c2c_hists = &c2c.hists; struct c2c_hist_entry *c2c_he; struct c2c_stats stats = { .nr_entries = 0, }; diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 69069926dd0b..096adc65451c 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -390,11 +390,11 @@ struct hist_entry_ops block_hist_ops = { static int diff__process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_diff *pdiff = container_of(tool, struct perf_diff, tool); struct addr_location al; + struct evsel *evsel = sample->evsel; struct hists *hists = evsel__hists(evsel); struct hist_entry_iter iter = { .evsel = evsel, diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index b7ecf78ef79b..8de152039f84 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -363,18 +363,17 @@ typedef int (*inject_handler)(const struct perf_tool *tool, static int perf_event__repipe_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { - struct perf_inject *inject = container_of(tool, struct perf_inject, - tool); + struct perf_inject *inject = container_of(tool, struct perf_inject, tool); + struct evsel *evsel = sample->evsel; if (evsel && evsel->handler) { inject_handler f = evsel->handler; return f(tool, event, sample, evsel, machine); } - build_id__mark_dso_hit(tool, event, sample, evsel, machine); + build_id__mark_dso_hit(tool, event, sample, machine); if (inject->itrace_synth_opts.set && sample->aux_sample.size) { event = perf_inject__cut_auxtrace_sample(inject, event, sample); @@ -388,10 +387,10 @@ static int perf_event__repipe_sample(const struct perf_tool *tool, static int perf_event__convert_sample_callchain(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); + struct evsel *evsel = sample->evsel; struct callchain_cursor *cursor = get_tls_callchain_cursor(); union perf_event *event_copy = (void *)inject->event_copy; struct callchain_cursor_node *node; @@ -988,10 +987,8 @@ static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data) args->mmap_evsel, map, /*sample_in_dso=*/false); } -int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, - struct perf_sample *sample, - struct evsel *evsel __maybe_unused, - struct machine *machine) +static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, + struct perf_sample *sample, struct machine *machine) { struct addr_location al; struct thread *thread; @@ -1021,7 +1018,7 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e /*sample_in_dso=*/true); } - sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, &args); thread__put(thread); repipe: @@ -1102,7 +1099,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, sample_sw.time = sample->time; perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, evsel->core.attr.read_format, &sample_sw); - build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); + build_id__mark_dso_hit(tool, event_sw, &sample_sw, machine); ret = perf_event__repipe(tool, event_sw, &sample_sw, machine); perf_sample__exit(&sample_sw); return ret; diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 7929a5fa5f46..34852a4c3fc8 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -960,9 +960,9 @@ typedef int (*tracepoint_handler)(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; struct thread *thread = machine__findnew_thread(machine, sample->pid, sample->tid); diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 0c5e6b3aac74..5e8e6fde097a 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -941,9 +941,9 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, static bool handle_kvm_event(struct perf_kvm_stat *kvm, struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; struct vcpu_event_record *vcpu_record; struct event_key key = { .key = INVALID_KEY, .exit_reasons = kvm->exit_reasons }; @@ -1133,7 +1133,6 @@ static bool skip_sample(struct perf_kvm_stat *kvm, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { int err = 0; @@ -1156,7 +1155,7 @@ static int process_sample_event(const struct perf_tool *tool, return -1; } - if (!handle_kvm_event(kvm, thread, evsel, sample)) + if (!handle_kvm_event(kvm, thread, sample)) err = -1; thread__put(thread); diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 6f94a8f45f60..e34a1f35439e 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1955,9 +1955,9 @@ typedef int (*tracepoint_handler)(const struct perf_tool *tool, static int perf_kwork__process_tracepoint_sample(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; if (evsel->handler != NULL) { diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index e8962c985d34..dc8d1d3b4cd7 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1430,9 +1430,9 @@ typedef int (*tracepoint_handler)(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; struct thread *thread = machine__findnew_thread(machine, sample->pid, sample->tid); diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index d43500b92a7b..6101a26b3a78 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -255,7 +255,6 @@ dump_raw_samples(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine) { return dump_raw_samples(tool, event, sample, machine); diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 40917a0be238..09d6af344f3e 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1488,7 +1488,6 @@ static void set_timestamp_boundary(struct record *rec, u64 sample_time) static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct record *rec = container_of(tool, struct record, tool); @@ -1499,7 +1498,7 @@ static int process_sample_event(const struct perf_tool *tool, return 0; rec->samples++; - return build_id__mark_dso_hit(tool, event, sample, evsel, machine); + return build_id__mark_dso_hit(tool, event, sample, machine); } static int process_buildids(struct record *rec) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 343c0ada5ea1..507002cbdd5b 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -269,10 +269,10 @@ static int process_feature_event(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct report *rep = container_of(tool, struct report, tool); + struct evsel *evsel = sample->evsel; struct addr_location al; struct hist_entry_iter iter = { .evsel = evsel, @@ -349,7 +349,6 @@ static int process_sample_event(const struct perf_tool *tool, static int process_read_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct report *rep = container_of(tool, struct report, tool); @@ -357,7 +356,7 @@ static int process_read_event(const struct perf_tool *tool, if (rep->show_threads) { int err = perf_read_values_add_value(&rep->show_threads_values, event->read.pid, event->read.tid, - evsel, + sample->evsel, event->read.value); if (err) @@ -783,11 +782,10 @@ static void report__output_resort(struct report *rep) static int count_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, - struct perf_sample *sample __maybe_unused, - struct evsel *evsel, + struct perf_sample *sample, struct machine *machine __maybe_unused) { - struct hists *hists = evsel__hists(evsel); + struct hists *hists = evsel__hists(sample->evsel); hists__inc_nr_events(hists); return 0; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index d083e2bb7703..296b9837278a 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -1867,9 +1867,9 @@ typedef int (*tracepoint_handler)(const struct perf_tool *tool, static int perf_sched__process_tracepoint_sample(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel = sample->evsel; int err = 0; if (evsel->handler != NULL) { @@ -3184,10 +3184,10 @@ typedef int (*sched_handler)(const struct perf_tool *tool, static int perf_timehist__process_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); + struct evsel *evsel = sample->evsel; int err = 0; struct perf_cpu this_cpu = { .cpu = sample->cpu, diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8c3d06a3db62..8724c4ab3e88 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2644,10 +2644,10 @@ static bool filter_cpu(struct perf_sample *sample) static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_script *scr = container_of(tool, struct perf_script, tool); + struct evsel *evsel = sample->evsel; struct addr_location al; struct addr_location addr_al; int ret = 0; @@ -2728,10 +2728,10 @@ static int process_sample_event(const struct perf_tool *tool, static int process_deferred_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_script *scr = container_of(tool, struct perf_script, tool); + struct evsel *evsel = sample->evsel; struct perf_event_attr *attr = &evsel->core.attr; struct evsel_script *es = evsel->priv; unsigned int type = output_type(attr->type); diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 28f33e39895d..8692d11ccd29 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -574,10 +574,10 @@ typedef int (*tracepoint_handler)(struct timechart *tchart, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct timechart *tchart = container_of(tool, struct timechart, tool); + struct evsel *evsel = sample->evsel; if (evsel->core.attr.sample_type & PERF_SAMPLE_TIME) { if (!tchart->first_time || tchart->first_time > sample->time) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 1c38f3d16a31..e86a3d375757 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3462,10 +3462,10 @@ static void trace__set_base_time(struct trace *trace, static int trace__process_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct trace *trace = container_of(tool, struct trace, tool); + struct evsel *evsel = sample->evsel; struct thread *thread; int err = 0; diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index fdb35133fde4..55b72235f891 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -55,7 +55,6 @@ static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct addr_location al; @@ -74,7 +73,7 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, addr_location__exit(&al); - sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, /*data=*/NULL); diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index 47e621cebe1b..73bad90b06f9 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h @@ -34,12 +34,7 @@ char *__dso__build_id_filename(const struct dso *dso, char *bf, size_t size, bool is_debug, bool is_kallsyms); int build_id__mark_dso_hit(const struct perf_tool *tool, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, - struct machine *machine); - -int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, - struct machine *machine); + struct perf_sample *sample, struct machine *machine); bool perf_session__read_build_ids(struct perf_session *session, bool with_hits); int perf_session__write_buildid_table(struct perf_session *session, diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c index ba1c8e48d495..32e2173b86e3 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c @@ -803,10 +803,10 @@ static bool is_flush_needed(struct ctf_stream *cs) static int process_sample_event(const struct perf_tool *tool, union perf_event *_event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct convert *c = container_of(tool, struct convert, tool); + struct evsel *evsel = sample->evsel; struct evsel_priv *priv = evsel->priv; struct ctf_writer *cw = &c->writer; struct ctf_stream *cs; diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c index 6a626322476a..d1f931ee565a 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -159,13 +159,12 @@ static void output_sample_callchain_entry(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine) { struct convert_json *c = container_of(tool, struct convert_json, tool); FILE *out = c->out; struct addr_location al; - u64 sample_type = __evlist__combined_sample_type(evsel->evlist); + u64 sample_type = __evlist__combined_sample_type(sample->evsel->evlist); u8 cpumode = PERF_RECORD_MISC_USER; addr_location__init(&al); @@ -245,7 +244,7 @@ static int process_sample_event(const struct perf_tool *tool, #ifdef HAVE_LIBTRACEEVENT if (sample->raw_data) { - struct tep_event *tp_format = evsel__tp_format(evsel); + struct tep_event *tp_format = evsel__tp_format(sample->evsel); struct tep_format_field **fields = tp_format ? tep_event_fields(tp_format) : NULL; if (fields) { diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 2af5455488b2..01e030862d5d 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -185,7 +185,6 @@ static bool should_ignore_sample(const struct perf_sample *sample, const struct static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct tpebs_retire_lat *t; @@ -196,7 +195,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, mutex_unlock(tpebs_mtx_get()); return 0; } - t = tpebs_retire_lat__find(evsel); + t = tpebs_retire_lat__find(sample->evsel); if (!t) { mutex_unlock(tpebs_mtx_get()); return -EINVAL; diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c index e0ce8b904729..52e6ffac2b3e 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -642,7 +642,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr) ret = jit_inject_event(jd, event); if (!ret) - build_id__mark_dso_hit(tool, event, &sample, NULL, jd->machine); + build_id__mark_dso_hit(tool, event, &sample, jd->machine); out: perf_sample__exit(&sample); return ret; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 3794d3a04afb..150398b383fe 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1110,9 +1110,10 @@ char *get_page_size_name(u64 size, char *str) return str; } -static void dump_sample(struct machine *machine, struct evsel *evsel, union perf_event *event, +static void dump_sample(struct machine *machine, union perf_event *event, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; u64 sample_type; char str[PAGE_SIZE_NAME_LEN]; uint16_t e_machine = EM_NONE; @@ -1176,9 +1177,10 @@ static void dump_sample(struct machine *machine, struct evsel *evsel, union perf sample_read__printf(sample, evsel->core.attr.read_format); } -static void dump_deferred_callchain(struct evsel *evsel, union perf_event *event, - struct perf_sample *sample) +static void dump_deferred_callchain(union perf_event *event, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; + if (!dump_trace) return; @@ -1284,7 +1286,7 @@ static int deliver_sample_value(struct evlist *evlist, return 0; sample->evsel = container_of(sid->evsel, struct evsel, core); - ret = tool->sample(tool, event, sample, sample->evsel, machine); + ret = tool->sample(tool, event, sample, machine); sample->evsel = saved_evsel; return ret; } @@ -1316,8 +1318,9 @@ static int deliver_sample_group(struct evlist *evlist, static int evlist__deliver_sample(struct evlist *evlist, const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) + struct machine *machine) { + struct evsel *evsel = sample->evsel; /* We know evsel != NULL. */ u64 sample_type = evsel->core.attr.sample_type; u64 read_format = evsel->core.attr.read_format; @@ -1325,7 +1328,7 @@ static int evlist__deliver_sample(struct evlist *evlist, const struct perf_tool /* Standard sample delivery. */ if (!(sample_type & PERF_SAMPLE_READ)) - return tool->sample(tool, event, sample, evsel, machine); + return tool->sample(tool, event, sample, machine); /* For PERF_SAMPLE_READ we have either single or group mode. */ if (read_format & PERF_FORMAT_GROUP) @@ -1364,8 +1367,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, struct evsel *saved_evsel = sample->evsel; sample->evsel = evlist__id2evsel(evlist, sample->id); - ret = tool->callchain_deferred(tool, event, sample, - sample->evsel, machine); + ret = tool->callchain_deferred(tool, event, sample, machine); sample->evsel = saved_evsel; return ret; } @@ -1393,7 +1395,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist, orig_sample.evsel = evlist__id2evsel(evlist, orig_sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &orig_sample, orig_sample.evsel, machine); + &orig_sample, machine); perf_sample__exit(&orig_sample); list_del(&de->list); @@ -1431,7 +1433,7 @@ static int session__flush_deferred_samples(struct perf_session *session, sample.evsel = evlist__id2evsel(evlist, sample.id); ret = evlist__deliver_sample(evlist, tool, de->event, - &sample, sample.evsel, machine); + &sample, machine); perf_sample__exit(&sample); list_del(&de->list); @@ -1451,7 +1453,6 @@ static int machines__deliver_event(struct machines *machines, const struct perf_tool *tool, u64 file_offset, const char *file_path) { - struct evsel *evsel; struct machine *machine; dump_event(evlist, event, file_offset, sample, file_path); @@ -1461,21 +1462,20 @@ static int machines__deliver_event(struct machines *machines, else assert(sample->evsel == evlist__id2evsel(evlist, sample->id)); - evsel = sample->evsel; machine = machines__find_for_cpumode(machines, event, sample); switch (event->header.type) { case PERF_RECORD_SAMPLE: - if (evsel == NULL) { + if (sample->evsel == NULL) { ++evlist->stats.nr_unknown_id; return 0; } if (machine == NULL) { ++evlist->stats.nr_unprocessable_samples; - dump_sample(machine, evsel, event, sample); + dump_sample(machine, event, sample); return 0; } - dump_sample(machine, evsel, event, sample); + dump_sample(machine, event, sample); if (sample->deferred_callchain && tool->merge_deferred_callchains) { struct deferred_event *de = malloc(sizeof(*de)); size_t sz = event->header.size; @@ -1492,7 +1492,7 @@ static int machines__deliver_event(struct machines *machines, list_add_tail(&de->list, &evlist->deferred_samples); return 0; } - return evlist__deliver_sample(evlist, tool, event, sample, evsel, machine); + return evlist__deliver_sample(evlist, tool, event, sample, machine); case PERF_RECORD_MMAP: return tool->mmap(tool, event, sample, machine); case PERF_RECORD_MMAP2: @@ -1520,8 +1520,8 @@ static int machines__deliver_event(struct machines *machines, evlist->stats.total_lost_samples += event->lost_samples.lost; return tool->lost_samples(tool, event, sample, machine); case PERF_RECORD_READ: - dump_read(evsel, event); - return tool->read(tool, event, sample, evsel, machine); + dump_read(sample->evsel, event); + return tool->read(tool, event, sample, machine); case PERF_RECORD_THROTTLE: return tool->throttle(tool, event, sample, machine); case PERF_RECORD_UNTHROTTLE: @@ -1550,7 +1550,7 @@ static int machines__deliver_event(struct machines *machines, case PERF_RECORD_AUX_OUTPUT_HW_ID: return tool->aux_output_hw_id(tool, event, sample, machine); case PERF_RECORD_CALLCHAIN_DEFERRED: - dump_deferred_callchain(evsel, event, sample); + dump_deferred_callchain(event, sample); return evlist__deliver_deferred_callchain(evlist, tool, event, sample, machine); default: diff --git a/tools/perf/util/tool.c b/tools/perf/util/tool.c index 013c7839e2cf..0f285a2574c8 100644 --- a/tools/perf/util/tool.c +++ b/tools/perf/util/tool.c @@ -110,7 +110,6 @@ static int process_event_synth_event_update_stub(const struct perf_tool *tool __ int process_event_sample_stub(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct machine *machine __maybe_unused) { dump_printf(": unhandled!\n"); @@ -348,12 +347,11 @@ bool perf_tool__compressed_is_stub(const struct perf_tool *tool) static int delegate_ ## name(const struct perf_tool *tool, \ union perf_event *event, \ struct perf_sample *sample, \ - struct evsel *evsel, \ struct machine *machine) \ { \ struct delegate_tool *del_tool = container_of(tool, struct delegate_tool, tool); \ struct perf_tool *delegate = del_tool->delegate; \ - return delegate->name(delegate, event, sample, evsel, machine); \ + return delegate->name(delegate, event, sample, machine); \ } CREATE_DELEGATE_SAMPLE(read); CREATE_DELEGATE_SAMPLE(sample); diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h index 2d9a4b1ca9d0..2a4f124ffd8d 100644 --- a/tools/perf/util/tool.h +++ b/tools/perf/util/tool.h @@ -9,7 +9,6 @@ struct perf_session; union perf_event; struct evlist; -struct evsel; struct perf_sample; struct perf_tool; struct machine; @@ -17,7 +16,7 @@ struct ordered_events; typedef int (*event_sample)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); + struct machine *machine); typedef int (*event_op)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine); @@ -103,7 +102,6 @@ bool perf_tool__compressed_is_stub(const struct perf_tool *tool); int process_event_sample_stub(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); struct delegate_tool { -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 05/25] perf kvm: Don't pass evsel with sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (3 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 04/25] perf tool: Remove evsel from tool APIs that pass the sample Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval Ian Rogers ` (19 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan As the sample now contains the evsel, read the evsel from the sample rather than passing them as a pair. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-kvm.c | 19 +++-- .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 17 +++-- .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 ++--- .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 ++--- .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 18 +++-- tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +++--- tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 ++++++++----------- tools/perf/util/kvm-stat.c | 19 +++-- tools/perf/util/kvm-stat.h | 18 ++--- 9 files changed, 89 insertions(+), 126 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 5e8e6fde097a..d9b9792894a8 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -806,7 +806,6 @@ static bool update_kvm_event(struct perf_kvm_stat *kvm, } static bool is_child_event(struct perf_kvm_stat *kvm, - struct evsel *evsel, struct perf_sample *sample, struct event_key *key) { @@ -818,8 +817,8 @@ static bool is_child_event(struct perf_kvm_stat *kvm, return false; for (; child_ops->name; child_ops++) { - if (evsel__name_is(evsel, child_ops->name)) { - child_ops->get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, child_ops->name)) { + child_ops->get_key(sample, key); return true; } } @@ -917,11 +916,10 @@ static bool handle_end_event(struct perf_kvm_stat *kvm, static struct vcpu_event_record *per_vcpu_record(struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { /* Only kvm_entry records vcpu id. */ - if (!thread__priv(thread) && kvm_entry_event(evsel)) { + if (!thread__priv(thread) && kvm_entry_event(sample->evsel)) { struct vcpu_event_record *vcpu_record; struct machine *machine = maps__machine(thread__maps(thread)); uint16_t e_machine = thread__e_machine(thread, machine, /*e_flags=*/NULL); @@ -932,7 +930,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, return NULL; } - vcpu_record->vcpu_id = evsel__intval(evsel, sample, vcpu_id_str(e_machine)); + vcpu_record->vcpu_id = evsel__intval(sample->evsel, sample, vcpu_id_str(e_machine)); thread__set_priv(thread, vcpu_record); } @@ -943,12 +941,11 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, struct thread *thread, struct perf_sample *sample) { - struct evsel *evsel = sample->evsel; struct vcpu_event_record *vcpu_record; struct event_key key = { .key = INVALID_KEY, .exit_reasons = kvm->exit_reasons }; - vcpu_record = per_vcpu_record(thread, evsel, sample); + vcpu_record = per_vcpu_record(thread, sample); if (!vcpu_record) return true; @@ -957,13 +954,13 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, (kvm->trace_vcpu != vcpu_record->vcpu_id)) return true; - if (kvm->events_ops->is_begin_event(evsel, sample, &key)) + if (kvm->events_ops->is_begin_event(sample, &key)) return handle_begin_event(kvm, vcpu_record, &key, sample); - if (is_child_event(kvm, evsel, sample, &key)) + if (is_child_event(kvm, sample, &key)) return handle_child_event(kvm, vcpu_record, &key, sample); - if (kvm->events_ops->is_end_event(evsel, sample, &key)) + if (kvm->events_ops->is_end_event(sample, &key)) return handle_end_event(kvm, vcpu_record, &key, sample); return true; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c index c640dcd8af7c..1e76906f719c 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c @@ -17,10 +17,11 @@ static const char * const __kvm_events_tp[] = { NULL, }; -static void event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_get_key(struct perf_sample *sample, struct event_key *key) { + struct evsel *evsel = sample->evsel; + key->info = 0; key->key = evsel__intval(evsel, sample, kvm_exit_reason(EM_AARCH64)); key->exit_reasons = arm64_exit_reasons; @@ -36,19 +37,17 @@ static void event_get_key(struct evsel *evsel, } } -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_begin(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, kvm_entry_trace(EM_AARCH64)); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_AARCH64)); } -static bool event_end(struct evsel *evsel, - struct perf_sample *sample, +static bool event_end(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, kvm_exit_trace(EM_AARCH64))) { - event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, kvm_exit_trace(EM_AARCH64))) { + event_get_key(sample, key); return true; } return false; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c index b802e516b138..9d6265290f6d 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c @@ -53,14 +53,12 @@ static const char * const __kvm_events_tp[] = { NULL, }; -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool event_begin(struct perf_sample *sample, struct event_key *key) { - return exit_event_begin(evsel, sample, key); + return exit_event_begin(sample, key); } -static bool event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { /* @@ -71,17 +69,16 @@ static bool event_end(struct evsel *evsel, * kvm:kvm_enter means returning to vmm and then to guest * kvm:kvm_reenter means returning to guest immediately */ - return evsel__name_is(evsel, kvm_entry_trace(EM_LOONGARCH)) || - evsel__name_is(evsel, kvm_reenter_trace); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_LOONGARCH)) || + evsel__name_is(sample->evsel, kvm_reenter_trace); } -static void event_gspr_get_key(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static void event_gspr_get_key(struct perf_sample *sample, struct event_key *key) { unsigned int insn; key->key = LOONGARCH_EXCEPTION_OTHERS; - insn = evsel__intval(evsel, sample, "inst_word"); + insn = evsel__intval(sample->evsel, sample, "inst_word"); switch (insn >> 24) { case 0: diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c index 42182d70beb6..5158d7e88ee6 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c @@ -28,12 +28,11 @@ static const char * const ppc_book3s_hv_kvm_tp[] = { /* 1 extra placeholder for NULL */ static const char *__kvm_events_tp[NR_TPS + 1]; -static void hcall_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void hcall_event_get_key(struct perf_sample *sample, struct event_key *key) { key->info = 0; - key->key = evsel__intval(evsel, sample, "req"); + key->key = evsel__intval(sample->evsel, sample, "req"); } static const char *get_hcall_exit_reason(u64 exit_code) @@ -51,18 +50,16 @@ static const char *get_hcall_exit_reason(u64 exit_code) return "UNKNOWN"; } -static bool hcall_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool hcall_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, __kvm_events_tp[3]); + return evsel__name_is(sample->evsel, __kvm_events_tp[3]); } -static bool hcall_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool hcall_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, __kvm_events_tp[2])) { - hcall_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, __kvm_events_tp[2])) { + hcall_event_get_key(sample, key); return true; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c index 8d4d5d6ce720..e8db8b4f8e2e 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c @@ -20,30 +20,28 @@ static const char * const __kvm_events_tp[] = { NULL, }; -static void event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_get_key(struct perf_sample *sample, struct event_key *key) { int xlen = 64; // TODO: 32-bit support. key->info = 0; - key->key = evsel__intval(evsel, sample, kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); + key->key = evsel__intval(sample->evsel, sample, + kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); key->exit_reasons = riscv_exit_reasons; } -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_begin(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, kvm_entry_trace(EM_RISCV)); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_RISCV)); } -static bool event_end(struct evsel *evsel, - struct perf_sample *sample, +static bool event_end(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, kvm_exit_trace(EM_RISCV))) { - event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, kvm_exit_trace(EM_RISCV))) { + event_get_key(sample, key); return true; } return false; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c index 7e29169f5bb0..158372ba0205 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c @@ -18,38 +18,34 @@ define_exit_reasons_table(sie_sigp_order_codes, sigp_order_codes); define_exit_reasons_table(sie_diagnose_codes, diagnose_codes); define_exit_reasons_table(sie_icpt_prog_codes, icpt_prog_codes); -static void event_icpt_insn_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_icpt_insn_get_key(struct perf_sample *sample, struct event_key *key) { u64 insn; - insn = evsel__intval(evsel, sample, "instruction"); + insn = evsel__intval(sample->evsel, sample, "instruction"); key->key = icpt_insn_decoder(insn); key->exit_reasons = sie_icpt_insn_codes; } -static void event_sigp_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_sigp_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "order_code"); + key->key = evsel__intval(sample->evsel, sample, "order_code"); key->exit_reasons = sie_sigp_order_codes; } -static void event_diag_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_diag_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "code"); + key->key = evsel__intval(sample->evsel, sample, "code"); key->exit_reasons = sie_diagnose_codes; } -static void event_icpt_prog_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_icpt_prog_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "code"); + key->key = evsel__intval(sample->evsel, sample, "code"); key->exit_reasons = sie_icpt_prog_codes; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c index 0f626db3a439..0ce543d82850 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c @@ -24,45 +24,43 @@ static const struct kvm_events_ops exit_events = { * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...). */ -static void mmio_event_get_key(struct evsel *evsel, struct perf_sample *sample, +static void mmio_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "gpa"); - key->info = evsel__intval(evsel, sample, "type"); + key->key = evsel__intval(sample->evsel, sample, "gpa"); + key->info = evsel__intval(sample->evsel, sample, "type"); } #define KVM_TRACE_MMIO_READ_UNSATISFIED 0 #define KVM_TRACE_MMIO_READ 1 #define KVM_TRACE_MMIO_WRITE 2 -static bool mmio_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool mmio_event_begin(struct perf_sample *sample, struct event_key *key) { /* MMIO read begin event in kernel. */ - if (kvm_exit_event(evsel)) + if (kvm_exit_event(sample->evsel)) return true; /* MMIO write begin event in kernel. */ - if (evsel__name_is(evsel, "kvm:kvm_mmio") && - evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { - mmio_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && + evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { + mmio_event_get_key(sample, key); return true; } return false; } -static bool mmio_event_end(struct evsel *evsel, struct perf_sample *sample, - struct event_key *key) +static bool mmio_event_end(struct perf_sample *sample, struct event_key *key) { /* MMIO write end event in kernel. */ - if (kvm_entry_event(evsel)) + if (kvm_entry_event(sample->evsel)) return true; /* MMIO read end event in kernel.*/ - if (evsel__name_is(evsel, "kvm:kvm_mmio") && - evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) { - mmio_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && + evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_READ) { + mmio_event_get_key(sample, key); return true; } @@ -86,31 +84,27 @@ static const struct kvm_events_ops mmio_events = { }; /* The time of emulation pio access is from kvm_pio to kvm_entry. */ -static void ioport_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void ioport_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "port"); - key->info = evsel__intval(evsel, sample, "rw"); + key->key = evsel__intval(sample->evsel, sample, "port"); + key->info = evsel__intval(sample->evsel, sample, "rw"); } -static bool ioport_event_begin(struct evsel *evsel, - struct perf_sample *sample, +static bool ioport_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, "kvm:kvm_pio")) { - ioport_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_pio")) { + ioport_event_get_key(sample, key); return true; } return false; } -static bool ioport_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) +static bool ioport_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, @@ -130,31 +124,25 @@ static const struct kvm_events_ops ioport_events = { }; /* The time of emulation msr is from kvm_msr to kvm_entry. */ -static void msr_event_get_key(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) +static void msr_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(evsel, sample, "ecx"); - key->info = evsel__intval(evsel, sample, "write"); + key->key = evsel__intval(sample->evsel, sample, "ecx"); + key->info = evsel__intval(sample->evsel, sample, "write"); } -static bool msr_event_begin(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) +static bool msr_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, "kvm:kvm_msr")) { - msr_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_msr")) { + msr_event_get_key(sample, key); return true; } return false; } -static bool msr_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) +static bool msr_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } static void msr_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c index 27f16810498c..f17a6132958d 100644 --- a/tools/perf/util/kvm-stat.c +++ b/tools/perf/util/kvm-stat.c @@ -11,22 +11,20 @@ bool kvm_exit_event(struct evsel *evsel) return evsel__name_is(evsel, kvm_exit_trace(e_machine)); } -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +void exit_event_get_key(struct perf_sample *sample, struct event_key *key) { - uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL); + uint16_t e_machine = evsel__e_machine(sample->evsel, /*e_flags=*/NULL); key->info = 0; - key->key = evsel__intval(evsel, sample, kvm_exit_reason(e_machine)); + key->key = evsel__intval(sample->evsel, sample, kvm_exit_reason(e_machine)); } -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +bool exit_event_begin(struct perf_sample *sample, struct event_key *key) { - if (kvm_exit_event(evsel)) { - exit_event_get_key(evsel, sample, key); + if (kvm_exit_event(sample->evsel)) { + exit_event_get_key(sample, key); return true; } @@ -40,11 +38,10 @@ bool kvm_entry_event(struct evsel *evsel) return evsel__name_is(evsel, kvm_entry_trace(e_machine)); } -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +bool exit_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } static const char *get_exit_reason(struct perf_kvm_stat *kvm, diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 4a998aaece5d..cdbd921a555f 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -53,18 +53,15 @@ struct kvm_event { }; struct child_event_ops { - void (*get_key)(struct evsel *evsel, - struct perf_sample *sample, + void (*get_key)(struct perf_sample *sample, struct event_key *key); const char *name; }; struct kvm_events_ops { - bool (*is_begin_event)(struct evsel *evsel, - struct perf_sample *sample, + bool (*is_begin_event)(struct perf_sample *sample, struct event_key *key); - bool (*is_end_event)(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key); + bool (*is_end_event)(struct perf_sample *sample, struct event_key *key); const struct child_event_ops *child_ops; void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key, char *decode); @@ -116,14 +113,11 @@ struct kvm_reg_events_ops { #ifdef HAVE_LIBTRACEEVENT -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +void exit_event_get_key(struct perf_sample *sample, struct event_key *key); -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, +bool exit_event_begin(struct perf_sample *sample, struct event_key *key); -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample, +bool exit_event_end(struct perf_sample *sample, struct event_key *key); void exit_event_decode_key(struct perf_kvm_stat *kvm, struct event_key *key, -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (4 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 05/25] perf kvm: Don't pass evsel with sample Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 07/25] perf trace: Don't pass evsel with sample Ian Rogers ` (18 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The evsel argument to evsel__intval, and similar functions, is unnecessary as it can be read from the sample. Remove the evsel and rename the function to match that the data is coming from the sample. Add bounds checks to a number read values from review feedback. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 49 ++++++--- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-kwork.c | 29 +++-- tools/perf/builtin-lock.c | 32 +++--- tools/perf/builtin-sched.c | 97 ++++++++-------- tools/perf/builtin-timechart.c | 104 ++++++++++-------- tools/perf/builtin-trace.c | 12 +- tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/tests/switch-tracking.c | 4 +- tools/perf/util/evsel.c | 34 ++++-- tools/perf/util/evsel.h | 12 +- tools/perf/util/intel-pt.c | 2 +- .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 6 +- .../util/kvm-stat-arch/kvm-stat-loongarch.c | 2 +- .../util/kvm-stat-arch/kvm-stat-powerpc.c | 2 +- .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 3 +- tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 8 +- tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 16 +-- tools/perf/util/kvm-stat.c | 2 +- 20 files changed, 231 insertions(+), 189 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 8de152039f84..23217bc3754f 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1082,7 +1082,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool, union perf_event *event_sw; struct perf_sample sample_sw; struct perf_inject *inject = container_of(tool, struct perf_inject, tool); - u32 pid = evsel__intval(evsel, sample, "pid"); + u32 pid = perf_sample__intval(sample, "pid"); int ret; list_for_each_entry(ent, &inject->samples, node) { diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 34852a4c3fc8..4f3ff29d2a9f 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -173,10 +173,10 @@ static int insert_caller_stat(unsigned long call_site, static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *sample) { - unsigned long ptr = evsel__intval(evsel, sample, "ptr"), - call_site = evsel__intval(evsel, sample, "call_site"); - int bytes_req = evsel__intval(evsel, sample, "bytes_req"), - bytes_alloc = evsel__intval(evsel, sample, "bytes_alloc"); + unsigned long ptr = perf_sample__intval(sample, "ptr"), + call_site = perf_sample__intval(sample, "call_site"); + int bytes_req = perf_sample__intval(sample, "bytes_req"), + bytes_alloc = perf_sample__intval(sample, "bytes_alloc"); if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) || insert_caller_stat(call_site, bytes_req, bytes_alloc)) @@ -202,7 +202,7 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s int node1, node2; node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}); - node2 = evsel__intval(evsel, sample, "node"); + node2 = perf_sample__intval(sample, "node"); /* * If the field "node" is NUMA_NO_NODE (-1), we don't take it @@ -243,9 +243,9 @@ static struct alloc_stat *search_alloc_stat(unsigned long ptr, return NULL; } -static int evsel__process_free_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_free_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - unsigned long ptr = evsel__intval(evsel, sample, "ptr"); + unsigned long ptr = perf_sample__intval(sample, "ptr"); struct alloc_stat *s_alloc, *s_caller; s_alloc = search_alloc_stat(ptr, 0, &root_alloc_stat, ptr_cmp); @@ -808,10 +808,9 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sample *sample) { u64 page; - unsigned int order = evsel__intval(evsel, sample, "order"); - unsigned int gfp_flags = evsel__intval(evsel, sample, "gfp_flags"); - unsigned int migrate_type = evsel__intval(evsel, sample, - "migratetype"); + unsigned int order = perf_sample__intval(sample, "order"); + unsigned int gfp_flags = perf_sample__intval(sample, "gfp_flags"); + unsigned int migrate_type = perf_sample__intval(sample, "migratetype"); u64 bytes = kmem_page_size << order; u64 callsite; struct page_stat *pstat; @@ -821,10 +820,20 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp .migrate_type = migrate_type, }; + if (order >= MAX_PAGE_ORDER) { + pr_debug("Out-of-bounds order %u\n", order); + return -1; + } + + if (migrate_type >= MAX_MIGRATE_TYPES) { + pr_debug("Out-of-bounds migratetype %u\n", migrate_type); + return -1; + } + if (use_pfn) - page = evsel__intval(evsel, sample, "pfn"); + page = perf_sample__intval(sample, "pfn"); else - page = evsel__intval(evsel, sample, "page"); + page = perf_sample__intval(sample, "page"); nr_page_allocs++; total_page_alloc_bytes += bytes; @@ -877,20 +886,26 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp return 0; } -static int evsel__process_page_free_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_page_free_event(struct evsel *evsel __maybe_unused, + struct perf_sample *sample) { u64 page; - unsigned int order = evsel__intval(evsel, sample, "order"); + unsigned int order = perf_sample__intval(sample, "order"); u64 bytes = kmem_page_size << order; struct page_stat *pstat; struct page_stat this = { .order = order, }; + if (order >= MAX_PAGE_ORDER) { + pr_debug("Out-of-bounds order %u\n", order); + return -1; + } + if (use_pfn) - page = evsel__intval(evsel, sample, "pfn"); + page = perf_sample__intval(sample, "pfn"); else - page = evsel__intval(evsel, sample, "page"); + page = perf_sample__intval(sample, "page"); nr_page_frees++; total_page_free_bytes += bytes; diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index d9b9792894a8..dd2ed21596aa 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -930,7 +930,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, return NULL; } - vcpu_record->vcpu_id = evsel__intval(sample->evsel, sample, vcpu_id_str(e_machine)); + vcpu_record->vcpu_id = perf_sample__intval(sample, vcpu_id_str(e_machine)); thread__set_priv(thread, vcpu_record); } diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index e34a1f35439e..f600037ee460 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1006,7 +1006,7 @@ static void irq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1014,11 +1014,11 @@ static void irq_work_init(struct perf_kwork *kwork, work->cpu = sample->cpu; if (kwork->report == KWORK_REPORT_TOP) { - work->id = evsel__intval_common(evsel, sample, "common_pid"); + work->id = perf_sample__intval_common(sample, "common_pid"); work->name = NULL; } else { - work->id = evsel__intval(evsel, sample, "irq"); - work->name = evsel__strval(evsel, sample, "name"); + work->id = perf_sample__intval(sample, "irq"); + work->name = perf_sample__strval(sample, "name"); } } @@ -1144,10 +1144,10 @@ static void softirq_work_init(struct perf_kwork *kwork, work->cpu = sample->cpu; if (kwork->report == KWORK_REPORT_TOP) { - work->id = evsel__intval_common(evsel, sample, "common_pid"); + work->id = perf_sample__intval_common(sample, "common_pid"); work->name = NULL; } else { - num = evsel__intval(evsel, sample, "vec"); + num = perf_sample__intval(sample, "vec"); work->id = num; work->name = evsel__softirq_name(evsel, num); } @@ -1234,17 +1234,16 @@ static void workqueue_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { char *modp = NULL; - unsigned long long function_addr = evsel__intval(evsel, - sample, "function"); + unsigned long long function_addr = perf_sample__intval(sample, "function"); work->class = class; work->cpu = sample->cpu; - work->id = evsel__intval(evsel, sample, "work"); + work->id = perf_sample__intval(sample, "work"); work->name = function_addr == 0 ? NULL : machine__resolve_kernel_addr(machine, &function_addr, &modp); } @@ -1302,7 +1301,7 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1310,11 +1309,11 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused, work->cpu = sample->cpu; if (src_type == KWORK_TRACE_EXIT) { - work->id = evsel__intval(evsel, sample, "prev_pid"); - work->name = strdup(evsel__strval(evsel, sample, "prev_comm")); + work->id = perf_sample__intval(sample, "prev_pid"); + work->name = strdup(perf_sample__strval(sample, "prev_comm") ?: "<unknown>"); } else if (src_type == KWORK_TRACE_ENTRY) { - work->id = evsel__intval(evsel, sample, "next_pid"); - work->name = strdup(evsel__strval(evsel, sample, "next_comm")); + work->id = perf_sample__intval(sample, "next_pid"); + work->name = strdup(perf_sample__strval(sample, "next_comm") ?: "<unknown>"); } } diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index dc8d1d3b4cd7..baf0c99df5df 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -563,15 +563,15 @@ static int get_key_by_aggr_mode(u64 *key, u64 addr, struct evsel *evsel, return get_key_by_aggr_mode_simple(key, addr, sample->tid); } -static int report_lock_acquire_event(struct evsel *evsel, +static int report_lock_acquire_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); - int flag = evsel__intval(evsel, sample, "flags"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); + int flag = perf_sample__intval(sample, "flags"); u64 key; int ret; @@ -638,15 +638,15 @@ static int report_lock_acquire_event(struct evsel *evsel, return 0; } -static int report_lock_acquired_event(struct evsel *evsel, +static int report_lock_acquired_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; u64 contended_term; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; @@ -704,14 +704,14 @@ static int report_lock_acquired_event(struct evsel *evsel, return 0; } -static int report_lock_contended_event(struct evsel *evsel, +static int report_lock_contended_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; @@ -762,14 +762,14 @@ static int report_lock_contended_event(struct evsel *evsel, return 0; } -static int report_lock_release_event(struct evsel *evsel, +static int report_lock_release_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - const char *name = evsel__strval(evsel, sample, "name"); - u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); + const char *name = perf_sample__strval(sample, "name"); + u64 addr = perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; @@ -969,8 +969,8 @@ static int report_lock_contention_begin_event(struct evsel *evsel, struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - u64 addr = evsel__intval(evsel, sample, "lock_addr"); - unsigned int flags = evsel__intval(evsel, sample, "flags"); + u64 addr = perf_sample__intval(sample, "lock_addr"); + unsigned int flags = perf_sample__intval(sample, "flags"); u64 key; int i, ret; static bool kmap_loaded; @@ -1134,7 +1134,7 @@ static int report_lock_contention_end_event(struct evsel *evsel, struct thread_stat *ts; struct lock_seq_stat *seq; u64 contended_term; - u64 addr = evsel__intval(evsel, sample, "lock_addr"); + u64 addr = perf_sample__intval(sample, "lock_addr"); u64 key; int ret; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 296b9837278a..3e7e8ad0bc13 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -829,8 +829,8 @@ replay_wakeup_event(struct perf_sched *sched, struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { - const char *comm = evsel__strval(evsel, sample, "comm"); - const u32 pid = evsel__intval(evsel, sample, "pid"); + const char *comm = perf_sample__strval(sample, "comm"); + const u32 pid = perf_sample__intval(sample, "pid"); struct task_desc *waker, *wakee; if (verbose > 0) { @@ -851,10 +851,10 @@ static int replay_switch_event(struct perf_sched *sched, struct perf_sample *sample, struct machine *machine __maybe_unused) { - const char *prev_comm = evsel__strval(evsel, sample, "prev_comm"), - *next_comm = evsel__strval(evsel, sample, "next_comm"); - const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), - next_pid = evsel__intval(evsel, sample, "next_pid"); + const char *prev_comm = perf_sample__strval(sample, "prev_comm"), + *next_comm = perf_sample__strval(sample, "next_comm"); + const u32 prev_pid = perf_sample__intval(sample, "prev_pid"), + next_pid = perf_sample__intval(sample, "next_pid"); struct task_desc *prev, __maybe_unused *next; u64 timestamp0, timestamp = sample->time; int cpu = sample->cpu; @@ -1134,13 +1134,13 @@ static void free_work_atoms(struct work_atoms *atoms) } static int latency_switch_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), - next_pid = evsel__intval(evsel, sample, "next_pid"); - const char prev_state = evsel__taskstate(evsel, sample, "prev_state"); + const u32 prev_pid = perf_sample__intval(sample, "prev_pid"), + next_pid = perf_sample__intval(sample, "next_pid"); + const char prev_state = perf_sample__taskstate(sample, "prev_state"); struct work_atoms *out_events, *in_events; struct thread *sched_out, *sched_in; u64 timestamp0, timestamp = sample->time; @@ -1204,12 +1204,12 @@ static int latency_switch_event(struct perf_sched *sched, } static int latency_runtime_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid = evsel__intval(evsel, sample, "pid"); - const u64 runtime = evsel__intval(evsel, sample, "runtime"); + const u32 pid = perf_sample__intval(sample, "pid"); + const u64 runtime = perf_sample__intval(sample, "runtime"); struct thread *thread = machine__findnew_thread(machine, -1, pid); struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); u64 timestamp = sample->time; @@ -1239,11 +1239,11 @@ static int latency_runtime_event(struct perf_sched *sched, } static int latency_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); struct work_atoms *atoms; struct work_atom *atom; struct thread *wakee; @@ -1300,11 +1300,11 @@ static int latency_wakeup_event(struct perf_sched *sched, } static int latency_migrate_task_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); u64 timestamp = sample->time; struct work_atoms *atoms; struct work_atom *atom; @@ -1626,11 +1626,11 @@ static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu, } } -static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, +static int map_switch_event(struct perf_sched *sched, struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); - const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"); + const u32 next_pid = perf_sample__intval(sample, "next_pid"); + const u32 prev_pid = perf_sample__intval(sample, "prev_pid"); struct thread *sched_in, *sched_out; struct thread_runtime *tr; int new_shortname; @@ -1797,8 +1797,13 @@ static int process_sched_switch_event(const struct perf_tool *tool, { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); int this_cpu = sample->cpu, err = 0; - u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), - next_pid = evsel__intval(evsel, sample, "next_pid"); + u32 prev_pid = perf_sample__intval(sample, "prev_pid"), + next_pid = perf_sample__intval(sample, "next_pid"); + + if (this_cpu < 0 || this_cpu >= MAX_CPUS) { + pr_debug("Out-of-bound sample CPU %d\n", this_cpu); + return -1; + } if (sched->curr_pid[this_cpu] != (u32)-1) { /* @@ -2068,12 +2073,11 @@ static char *timehist_get_commstr(struct thread *thread) /* prio field format: xxx or xxx->yyy */ #define MAX_PRIO_STR_LEN 8 -static char *timehist_get_priostr(struct evsel *evsel, - struct thread *thread, +static char *timehist_get_priostr(struct thread *thread, struct perf_sample *sample) { static char prio_str[16]; - int prev_prio = (int)evsel__intval(evsel, sample, "prev_prio"); + int prev_prio = (int)perf_sample__intval(sample, "prev_prio"); struct thread_runtime *tr = thread__priv(thread); if (tr->prio != prev_prio && tr->prio != -1) @@ -2161,15 +2165,14 @@ static void timehist_header(struct perf_sched *sched) } static void timehist_print_sample(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct addr_location *al, struct thread *thread, u64 t, const char state) { struct thread_runtime *tr = thread__priv(thread); - const char *next_comm = evsel__strval(evsel, sample, "next_comm"); - const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); + const char *next_comm = perf_sample__strval(sample, "next_comm"); + const u32 next_pid = perf_sample__intval(sample, "next_pid"); u32 max_cpus = sched->max_cpu.cpu + 1; char tstr[64]; char nstr[30]; @@ -2198,14 +2201,15 @@ static void timehist_print_sample(struct perf_sched *sched, } if (!thread__comm_set(thread)) { - const char *prev_comm = evsel__strval(evsel, sample, "prev_comm"); - thread__set_comm(thread, prev_comm, sample->time); + const char *prev_comm = perf_sample__strval(sample, "prev_comm"); + + thread__set_comm(thread, prev_comm, sample->time); } printf(" %-*s ", comm_width, timehist_get_commstr(thread)); if (sched->show_prio) - printf(" %-*s ", MAX_PRIO_STR_LEN, timehist_get_priostr(evsel, thread, sample)); + printf(" %-*s ", MAX_PRIO_STR_LEN, timehist_get_priostr(thread, sample)); wait_time = tr->dt_sleep + tr->dt_iowait + tr->dt_preempt; print_sched_time(wait_time, 6); @@ -2319,7 +2323,7 @@ static bool is_idle_sample(struct perf_sample *sample, { /* pid 0 == swapper == idle task */ if (evsel__name_is(evsel, "sched:sched_switch")) - return evsel__intval(evsel, sample, "prev_pid") == 0; + return perf_sample__intval(sample, "prev_pid") == 0; return sample->pid == 0; } @@ -2539,7 +2543,7 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, itr->last_thread = thread__get(thread); /* copy task callchain when entering to idle */ - if (evsel__intval(evsel, sample, "next_pid") == 0) + if (perf_sample__intval(sample, "next_pid") == 0) save_idle_callchain(sched, itr, sample); } } @@ -2572,7 +2576,7 @@ static bool timehist_skip_sample(struct perf_sched *sched, if (tr && tr->prio != -1) prio = tr->prio; else if (evsel__name_is(evsel, "sched:sched_switch")) - prio = evsel__intval(evsel, sample, "prev_prio"); + prio = perf_sample__intval(sample, "prev_prio"); if (prio != -1 && !test_bit(prio, sched->prio_bitmap)) { rc = true; @@ -2583,8 +2587,8 @@ static bool timehist_skip_sample(struct perf_sched *sched, if (sched->idle_hist) { if (!evsel__name_is(evsel, "sched:sched_switch")) rc = true; - else if (evsel__intval(evsel, sample, "prev_pid") != 0 && - evsel__intval(evsel, sample, "next_pid") != 0) + else if (perf_sample__intval(sample, "prev_pid") != 0 && + perf_sample__intval(sample, "next_pid") != 0) rc = true; } @@ -2647,7 +2651,7 @@ static int timehist_sched_wakeup_event(const struct perf_tool *tool, struct thread *thread; struct thread_runtime *tr = NULL; /* want pid of awakened task not pid in sample */ - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); thread = machine__findnew_thread(machine, 0, pid); if (thread == NULL) @@ -2686,8 +2690,8 @@ static void timehist_print_migration_event(struct perf_sched *sched, return; max_cpus = sched->max_cpu.cpu + 1; - ocpu = evsel__intval(evsel, sample, "orig_cpu"); - dcpu = evsel__intval(evsel, sample, "dest_cpu"); + ocpu = perf_sample__intval(sample, "orig_cpu"); + dcpu = perf_sample__intval(sample, "dest_cpu"); thread = machine__findnew_thread(machine, sample->pid, sample->tid); if (thread == NULL) @@ -2736,7 +2740,7 @@ static int timehist_migrate_task_event(const struct perf_tool *tool, struct thread *thread; struct thread_runtime *tr = NULL; /* want pid of migrated task not pid in sample */ - const u32 pid = evsel__intval(evsel, sample, "pid"); + const u32 pid = perf_sample__intval(sample, "pid"); thread = machine__findnew_thread(machine, 0, pid); if (thread == NULL) @@ -2761,14 +2765,13 @@ static int timehist_migrate_task_event(const struct perf_tool *tool, return 0; } -static void timehist_update_task_prio(struct evsel *evsel, - struct perf_sample *sample, +static void timehist_update_task_prio(struct perf_sample *sample, struct machine *machine) { struct thread *thread; struct thread_runtime *tr = NULL; - const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); - const u32 next_prio = evsel__intval(evsel, sample, "next_prio"); + const u32 next_pid = perf_sample__intval(sample, "next_pid"); + const u32 next_prio = perf_sample__intval(sample, "next_prio"); if (next_pid == 0) thread = get_idle_thread(sample->cpu); @@ -2798,7 +2801,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, struct thread_runtime *tr = NULL; u64 tprev, t = sample->time; int rc = 0; - const char state = evsel__taskstate(evsel, sample, "prev_state"); + const char state = perf_sample__taskstate(sample, "prev_state"); addr_location__init(&al); if (machine__resolve(machine, &al, sample) < 0) { @@ -2809,7 +2812,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, } if (sched->show_prio || sched->prio_str) - timehist_update_task_prio(evsel, sample, machine); + timehist_update_task_prio(sample, machine); thread = timehist_get_thread(sched, sample, machine, evsel); if (thread == NULL) { @@ -2891,7 +2894,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, } if (!sched->summary_only) - timehist_print_sample(sched, evsel, sample, &al, thread, t, state); + timehist_print_sample(sched, sample, &al, thread, t, state); } out: diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 8692d11ccd29..782ede4258a2 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -597,13 +597,17 @@ static int process_sample_event(const struct perf_tool *tool, static int process_sample_cpu_idle(struct timechart *tchart __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u32 state = evsel__intval(evsel, sample, "state"); - u32 cpu_id = evsel__intval(evsel, sample, "cpu_id"); + u32 state = perf_sample__intval(sample, "state"); + u32 cpu_id = perf_sample__intval(sample, "cpu_id"); + if (cpu_id >= MAX_CPUS) { + pr_debug("Out-of-bounds cpu_id %u\n", cpu_id); + return -1; + } if (state == (u32)PWR_EVENT_EXIT) c_state_end(tchart, cpu_id, sample->time); else @@ -613,26 +617,30 @@ process_sample_cpu_idle(struct timechart *tchart __maybe_unused, static int process_sample_cpu_frequency(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u32 state = evsel__intval(evsel, sample, "state"); - u32 cpu_id = evsel__intval(evsel, sample, "cpu_id"); + u32 state = perf_sample__intval(sample, "state"); + u32 cpu_id = perf_sample__intval(sample, "cpu_id"); + if (cpu_id >= MAX_CPUS) { + pr_debug("Out-of-bounds cpu_id %u\n", cpu_id); + return -1; + } p_state_change(tchart, cpu_id, sample->time, state); return 0; } static int process_sample_sched_wakeup(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { - u8 flags = evsel__intval(evsel, sample, "common_flags"); - int waker = evsel__intval(evsel, sample, "common_pid"); - int wakee = evsel__intval(evsel, sample, "pid"); + u8 flags = perf_sample__intval(sample, "common_flags"); + int waker = perf_sample__intval(sample, "common_pid"); + int wakee = perf_sample__intval(sample, "pid"); sched_wakeup(tchart, sample->cpu, sample->time, waker, wakee, flags, backtrace); return 0; @@ -640,13 +648,13 @@ process_sample_sched_wakeup(struct timechart *tchart, static int process_sample_sched_switch(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { - int prev_pid = evsel__intval(evsel, sample, "prev_pid"); - int next_pid = evsel__intval(evsel, sample, "next_pid"); - u64 prev_state = evsel__intval(evsel, sample, "prev_state"); + int prev_pid = perf_sample__intval(sample, "prev_pid"); + int next_pid = perf_sample__intval(sample, "next_pid"); + u64 prev_state = perf_sample__intval(sample, "prev_state"); sched_switch(tchart, sample->cpu, sample->time, prev_pid, next_pid, prev_state, backtrace); @@ -656,13 +664,17 @@ process_sample_sched_switch(struct timechart *tchart, #ifdef SUPPORT_OLD_POWER_EVENTS static int process_sample_power_start(struct timechart *tchart __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u64 cpu_id = evsel__intval(evsel, sample, "cpu_id"); - u64 value = evsel__intval(evsel, sample, "value"); + u64 cpu_id = perf_sample__intval(sample, "cpu_id"); + u64 value = perf_sample__intval(sample, "value"); + if (cpu_id >= MAX_CPUS) { + pr_debug("Out-of-bounds cpu_id %llu\n", (unsigned long long)cpu_id); + return -1; + } c_state_start(cpu_id, sample->time, value); return 0; } @@ -679,13 +691,17 @@ process_sample_power_end(struct timechart *tchart, static int process_sample_power_frequency(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u64 cpu_id = evsel__intval(evsel, sample, "cpu_id"); - u64 value = evsel__intval(evsel, sample, "value"); + u64 cpu_id = perf_sample__intval(sample, "cpu_id"); + u64 value = perf_sample__intval(sample, "value"); + if (cpu_id >= MAX_CPUS) { + pr_debug("Out-of-bounds cpu_id %llu\n", (unsigned long long)cpu_id); + return -1; + } p_state_change(tchart, cpu_id, sample->time, value); return 0; } @@ -849,120 +865,120 @@ static int pid_end_io_sample(struct timechart *tchart, int pid, int type, static int process_enter_read(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ, sample->time, fd); } static int process_exit_read(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_READ, sample->time, ret); } static int process_enter_write(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE, sample->time, fd); } static int process_exit_write(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_WRITE, sample->time, ret); } static int process_enter_sync(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC, sample->time, fd); } static int process_exit_sync(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_SYNC, sample->time, ret); } static int process_enter_tx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX, sample->time, fd); } static int process_exit_tx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_TX, sample->time, ret); } static int process_enter_rx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX, sample->time, fd); } static int process_exit_rx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_RX, sample->time, ret); } static int process_enter_poll(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd = evsel__intval(evsel, sample, "fd"); + long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL, sample->time, fd); } static int process_exit_poll(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret = evsel__intval(evsel, sample, "ret"); + long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_POLL, sample->time, ret); } diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index e86a3d375757..493eecf218b4 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3059,7 +3059,7 @@ errno_print: { return err; } -static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, +static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3068,7 +3068,7 @@ static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, size_t filename_len, entry_str_len, to_move; ssize_t remaining_space; char *pos; - const char *filename = evsel__rawptr(evsel, sample, "pathname"); + const char *filename = perf_sample__rawptr(sample, "pathname"); if (!thread) goto out; @@ -3124,7 +3124,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, union perf_event *event __maybe_unused, struct perf_sample *sample) { - u64 runtime = evsel__intval(evsel, sample, "runtime"); + u64 runtime = perf_sample__intval(sample, "runtime"); double runtime_ms = (double)runtime / NSEC_PER_MSEC; struct thread *thread = machine__findnew_thread(trace->host, sample->pid, @@ -3143,10 +3143,10 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, out_dump: fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", evsel->name, - evsel__strval(evsel, sample, "comm"), - (pid_t)evsel__intval(evsel, sample, "pid"), + perf_sample__strval(sample, "comm"), + (pid_t)perf_sample__intval(sample, "pid"), runtime, - evsel__intval(evsel, sample, "vruntime")); + perf_sample__intval(sample, "vruntime")); goto out_put; } diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c index 2a139d2781a8..97550b349418 100644 --- a/tools/perf/tests/openat-syscall-tp-fields.c +++ b/tools/perf/tests/openat-syscall-tp-fields.c @@ -118,7 +118,7 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused goto out_delete_evlist; } - tp_flags = evsel__intval(evsel, &sample, "flags"); + tp_flags = perf_sample__intval(&sample, "flags"); perf_sample__exit(&sample); if (flags != tp_flags) { pr_debug("%s: Expected flags=%#x, got %#x\n", diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index 72a8289e846d..22b0302252db 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -140,8 +140,8 @@ static int process_sample_event(struct evlist *evlist, evsel = evlist__id2evsel(evlist, sample.id); if (evsel == switch_tracking->switch_evsel) { - next_tid = evsel__intval(evsel, &sample, "next_pid"); - prev_tid = evsel__intval(evsel, &sample, "prev_pid"); + next_tid = perf_sample__intval(&sample, "next_pid"); + prev_tid = perf_sample__intval(&sample, "prev_pid"); cpu = sample.cpu; pr_debug3("sched_switch: cpu: %d prev_tid %d next_tid %d\n", cpu, prev_tid, next_tid); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 29b1df875953..a4fe37f2a276 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3681,9 +3681,9 @@ struct tep_format_field *evsel__common_field(struct evsel *evsel, const char *na return tp_format ? tep_find_common_field(tp_format, name) : NULL; } -void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name) +void *perf_sample__rawptr(struct perf_sample *sample, const char *name) { - struct tep_format_field *field = evsel__field(evsel, name); + struct tep_format_field *field = evsel__field(sample->evsel, name); int offset; if (!field) @@ -3698,6 +3698,12 @@ void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char offset += field->offset + field->size; } + if ((u32)(offset + field->size) > sample->raw_size) { + pr_warning("Invalid trace point field offset %d for field of length %d in sample raw data of size %u\n", + offset, field->size, sample->raw_size); + return NULL; + } + return sample->raw_data + offset; } @@ -3707,6 +3713,12 @@ u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sam u64 value; void *ptr = sample->raw_data + field->offset; + if ((u32)(field->offset + field->size) > sample->raw_size) { + pr_warning("Invalid trace point field offset %d for field of length %d in sample raw data of size %u\n", + field->offset, field->size, sample->raw_size); + return 0; + } + switch (field->size) { case 1: return *(u8 *)ptr; @@ -3740,21 +3752,21 @@ u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sam return 0; } -u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name) +u64 perf_sample__intval(struct perf_sample *sample, const char *name) { - struct tep_format_field *field = evsel__field(evsel, name); + struct tep_format_field *field = evsel__field(sample->evsel, name); - return field ? format_field__intval(field, sample, evsel->needs_swap) : 0; + return field ? format_field__intval(field, sample, sample->evsel->needs_swap) : 0; } -u64 evsel__intval_common(struct evsel *evsel, struct perf_sample *sample, const char *name) +u64 perf_sample__intval_common(struct perf_sample *sample, const char *name) { - struct tep_format_field *field = evsel__common_field(evsel, name); + struct tep_format_field *field = evsel__common_field(sample->evsel, name); - return field ? format_field__intval(field, sample, evsel->needs_swap) : 0; + return field ? format_field__intval(field, sample, sample->evsel->needs_swap) : 0; } -char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const char *name) +char perf_sample__taskstate(struct perf_sample *sample, const char *name) { static struct tep_format_field *prev_state_field; static const char *states; @@ -3763,7 +3775,7 @@ char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const cha unsigned int bit; char state = '?'; /* '?' denotes unknown task state */ - field = evsel__field(evsel, name); + field = evsel__field(sample->evsel, name); if (!field) return state; @@ -3782,7 +3794,7 @@ char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const cha * * We can change this if we have a good reason in the future. */ - val = evsel__intval(evsel, sample, name); + val = perf_sample__intval(sample, name); bit = val ? ffs(val) : 0; state = (!bit || bit > strlen(states)) ? 'R' : states[bit-1]; return state; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index a3d754c029a0..c9d3e6de9677 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -369,14 +369,14 @@ bool evsel__precise_ip_fallback(struct evsel *evsel); struct perf_sample; #ifdef HAVE_LIBTRACEEVENT -void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name); -u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name); -u64 evsel__intval_common(struct evsel *evsel, struct perf_sample *sample, const char *name); -char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const char *name); +void *perf_sample__rawptr(struct perf_sample *sample, const char *name); +u64 perf_sample__intval(struct perf_sample *sample, const char *name); +u64 perf_sample__intval_common(struct perf_sample *sample, const char *name); +char perf_sample__taskstate(struct perf_sample *sample, const char *name); -static inline char *evsel__strval(struct evsel *evsel, struct perf_sample *sample, const char *name) +static inline char *perf_sample__strval(struct perf_sample *sample, const char *name) { - return evsel__rawptr(evsel, sample, name); + return perf_sample__rawptr(sample, name); } #endif diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index fc9eec8b54b8..dab23a96b1d8 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -3426,7 +3426,7 @@ static int intel_pt_process_switch(struct intel_pt *pt, if (evsel != pt->switch_evsel) return 0; - tid = evsel__intval(evsel, sample, "next_pid"); + tid = perf_sample__intval(sample, "next_pid"); cpu = sample->cpu; intel_pt_log("sched_switch: cpu %d tid %d time %"PRIu64" tsc %#"PRIx64"\n", diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c index 1e76906f719c..018b0db0e6e7 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c @@ -20,10 +20,8 @@ static const char * const __kvm_events_tp[] = { static void event_get_key(struct perf_sample *sample, struct event_key *key) { - struct evsel *evsel = sample->evsel; - key->info = 0; - key->key = evsel__intval(evsel, sample, kvm_exit_reason(EM_AARCH64)); + key->key = perf_sample__intval(sample, kvm_exit_reason(EM_AARCH64)); key->exit_reasons = arm64_exit_reasons; /* @@ -32,7 +30,7 @@ static void event_get_key(struct perf_sample *sample, * properly decode event's est_ec. */ if (key->key == ARM_EXCEPTION_TRAP) { - key->key = evsel__intval(evsel, sample, kvm_trap_exit_reason); + key->key = perf_sample__intval(sample, kvm_trap_exit_reason); key->exit_reasons = arm64_trap_exit_reasons; } } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c index 9d6265290f6d..a04cd09e3361 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c @@ -78,7 +78,7 @@ static void event_gspr_get_key(struct perf_sample *sample, struct event_key *key unsigned int insn; key->key = LOONGARCH_EXCEPTION_OTHERS; - insn = evsel__intval(sample->evsel, sample, "inst_word"); + insn = perf_sample__intval(sample, "inst_word"); switch (insn >> 24) { case 0: diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c index 5158d7e88ee6..96d9c4ae0209 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c @@ -32,7 +32,7 @@ static void hcall_event_get_key(struct perf_sample *sample, struct event_key *key) { key->info = 0; - key->key = evsel__intval(sample->evsel, sample, "req"); + key->key = perf_sample__intval(sample, "req"); } static const char *get_hcall_exit_reason(u64 exit_code) diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c index e8db8b4f8e2e..967bba261a47 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c @@ -26,8 +26,7 @@ static void event_get_key(struct perf_sample *sample, int xlen = 64; // TODO: 32-bit support. key->info = 0; - key->key = evsel__intval(sample->evsel, sample, - kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); + key->key = perf_sample__intval(sample, kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); key->exit_reasons = riscv_exit_reasons; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c index 158372ba0205..4771fc69fa39 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c @@ -23,7 +23,7 @@ static void event_icpt_insn_get_key(struct perf_sample *sample, { u64 insn; - insn = evsel__intval(sample->evsel, sample, "instruction"); + insn = perf_sample__intval(sample, "instruction"); key->key = icpt_insn_decoder(insn); key->exit_reasons = sie_icpt_insn_codes; } @@ -31,21 +31,21 @@ static void event_icpt_insn_get_key(struct perf_sample *sample, static void event_sigp_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "order_code"); + key->key = perf_sample__intval(sample, "order_code"); key->exit_reasons = sie_sigp_order_codes; } static void event_diag_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "code"); + key->key = perf_sample__intval(sample, "code"); key->exit_reasons = sie_diagnose_codes; } static void event_icpt_prog_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "code"); + key->key = perf_sample__intval(sample, "code"); key->exit_reasons = sie_icpt_prog_codes; } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c index 0ce543d82850..788d216f0852 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c @@ -27,8 +27,8 @@ static const struct kvm_events_ops exit_events = { static void mmio_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "gpa"); - key->info = evsel__intval(sample->evsel, sample, "type"); + key->key = perf_sample__intval(sample, "gpa"); + key->info = perf_sample__intval(sample, "type"); } #define KVM_TRACE_MMIO_READ_UNSATISFIED 0 @@ -43,7 +43,7 @@ static bool mmio_event_begin(struct perf_sample *sample, struct event_key *key) /* MMIO write begin event in kernel. */ if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && - evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { + perf_sample__intval(sample, "type") == KVM_TRACE_MMIO_WRITE) { mmio_event_get_key(sample, key); return true; } @@ -59,7 +59,7 @@ static bool mmio_event_end(struct perf_sample *sample, struct event_key *key) /* MMIO read end event in kernel.*/ if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && - evsel__intval(sample->evsel, sample, "type") == KVM_TRACE_MMIO_READ) { + perf_sample__intval(sample, "type") == KVM_TRACE_MMIO_READ) { mmio_event_get_key(sample, key); return true; } @@ -87,8 +87,8 @@ static const struct kvm_events_ops mmio_events = { static void ioport_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "port"); - key->info = evsel__intval(sample->evsel, sample, "rw"); + key->key = perf_sample__intval(sample, "port"); + key->info = perf_sample__intval(sample, "rw"); } static bool ioport_event_begin(struct perf_sample *sample, @@ -126,8 +126,8 @@ static const struct kvm_events_ops ioport_events = { /* The time of emulation msr is from kvm_msr to kvm_entry. */ static void msr_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key = evsel__intval(sample->evsel, sample, "ecx"); - key->info = evsel__intval(sample->evsel, sample, "write"); + key->key = perf_sample__intval(sample, "ecx"); + key->info = perf_sample__intval(sample, "write"); } static bool msr_event_begin(struct perf_sample *sample, struct event_key *key) diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c index f17a6132958d..755ab659a05c 100644 --- a/tools/perf/util/kvm-stat.c +++ b/tools/perf/util/kvm-stat.c @@ -17,7 +17,7 @@ void exit_event_get_key(struct perf_sample *sample, uint16_t e_machine = evsel__e_machine(sample->evsel, /*e_flags=*/NULL); key->info = 0; - key->key = evsel__intval(sample->evsel, sample, kvm_exit_reason(e_machine)); + key->key = perf_sample__intval(sample, kvm_exit_reason(e_machine)); } -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 07/25] perf trace: Don't pass evsel with sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (5 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 08/25] perf callchain: Don't pass evsel and sample Ian Rogers ` (17 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample now contains the evsel and so don't unnecessarily pass the evsel. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-trace.c | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 493eecf218b4..33199ff2bbfd 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -535,12 +535,12 @@ static struct evsel *perf_evsel__raw_syscall_newtp(const char *direction, void * return NULL; } -#define perf_evsel__sc_tp_uint(evsel, name, sample) \ - ({ struct syscall_tp *fields = __evsel__syscall_tp(evsel); \ +#define perf_evsel__sc_tp_uint(name, sample) \ + ({ struct syscall_tp *fields = __evsel__syscall_tp(sample->evsel); \ fields->name.integer(&fields->name, sample); }) -#define perf_evsel__sc_tp_ptr(evsel, name, sample) \ - ({ struct syscall_tp *fields = __evsel__syscall_tp(evsel); \ +#define perf_evsel__sc_tp_ptr(name, sample) \ + ({ struct syscall_tp *fields = __evsel__syscall_tp(sample->evsel); \ fields->name.pointer(&fields->name, sample); }) size_t strarray__scnprintf_suffix(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_suffix, int val) @@ -2719,8 +2719,8 @@ static int trace__printf_interrupted_entry(struct trace *trace) return printed; } -static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, - struct perf_sample *sample, struct thread *thread) +static int trace__fprintf_sample(struct trace *trace, struct perf_sample *sample, + struct thread *thread) { int printed = 0; @@ -2728,7 +2728,7 @@ static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, double ts = (double)sample->time / NSEC_PER_MSEC; printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n", - evsel__name(evsel), ts, + evsel__name(sample->evsel), ts, thread__comm_str(thread), sample->pid, sample->tid, sample->cpu); } @@ -2783,7 +2783,7 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel, void *args; int printed = 0; struct thread *thread; - int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; + int id = perf_evsel__sc_tp_uint(id, sample), err = -1; int augmented_args_size = 0, e_machine; void *augmented_args = NULL; struct syscall *sc; @@ -2798,9 +2798,9 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel, if (ttrace == NULL) goto out_put; - trace__fprintf_sample(trace, evsel, sample, thread); + trace__fprintf_sample(trace, sample, thread); - args = perf_evsel__sc_tp_ptr(evsel, args, sample); + args = perf_evsel__sc_tp_ptr(args, sample); if (ttrace->entry_str == NULL) { ttrace->entry_str = malloc(trace__entry_str_size); @@ -2855,12 +2855,11 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel, return err; } -static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, - struct perf_sample *sample) +static int trace__fprintf_sys_enter(struct trace *trace, struct perf_sample *sample) { struct thread_trace *ttrace; struct thread *thread; - int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; + int id = perf_evsel__sc_tp_uint(id, sample), err = -1; struct syscall *sc; char msg[1024]; void *args, *augmented_args = NULL; @@ -2870,7 +2869,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); e_machine = thread__e_machine(thread, trace->host, /*e_flags=*/NULL); - sc = trace__syscall_info(trace, evsel, e_machine, id); + sc = trace__syscall_info(trace, sample->evsel, e_machine, id); if (sc == NULL) goto out_put; ttrace = thread__trace(thread, trace); @@ -2881,7 +2880,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, if (ttrace == NULL) goto out_put; - args = perf_evsel__sc_tp_ptr(evsel, args, sample); + args = perf_evsel__sc_tp_ptr(args, sample); augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_syscalls_args_size); printed += syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread); fprintf(trace->output, "%.*s", (int)printed, msg); @@ -2891,10 +2890,11 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, return err; } -static int trace__resolve_callchain(struct trace *trace, struct evsel *evsel, +static int trace__resolve_callchain(struct trace *trace, struct perf_sample *sample, struct callchain_cursor *cursor) { + struct evsel *evsel = sample->evsel; struct addr_location al; int max_stack = evsel->core.attr.sample_max_stack ? evsel->core.attr.sample_max_stack : @@ -2929,7 +2929,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, u64 duration = 0; bool duration_calculated = false; struct thread *thread; - int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1, callchain_ret = 0, printed = 0; + int id = perf_evsel__sc_tp_uint(id, sample), err = -1, callchain_ret = 0, printed = 0; int alignment = trace->args_alignment, e_machine; struct syscall *sc; struct thread_trace *ttrace; @@ -2943,9 +2943,9 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, if (ttrace == NULL) goto out_put; - trace__fprintf_sample(trace, evsel, sample, thread); + trace__fprintf_sample(trace, sample, thread); - ret = perf_evsel__sc_tp_uint(evsel, ret, sample); + ret = perf_evsel__sc_tp_uint(ret, sample); if (trace->summary) thread__update_stats(thread, ttrace, id, sample, ret, trace); @@ -2967,7 +2967,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, if (sample->callchain) { struct callchain_cursor *cursor = get_tls_callchain_cursor(); - callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret = trace__resolve_callchain(trace, sample, cursor); if (callchain_ret == 0) { if (cursor->nr < trace->min_stack) goto out; @@ -3182,9 +3182,10 @@ static void bpf_output__fprintf(struct trace *trace, ++trace->nr_events_printed; } -static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample *sample, +static size_t trace__fprintf_tp_fields(struct trace *trace, struct perf_sample *sample, struct thread *thread, void *augmented_args, int augmented_args_size) { + struct evsel *evsel = sample->evsel; char bf[2048]; size_t size = sizeof(bf); const struct tep_event *tp_format = evsel__tp_format(evsel); @@ -3267,7 +3268,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, if (sample->callchain) { struct callchain_cursor *cursor = get_tls_callchain_cursor(); - callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret = trace__resolve_callchain(trace, sample, cursor); if (callchain_ret == 0) { if (cursor->nr < trace->min_stack) goto out; @@ -3285,7 +3286,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, trace__fprintf_comm_tid(trace, thread, trace->output); if (evsel == trace->syscalls.events.bpf_output) { - int id = perf_evsel__sc_tp_uint(evsel, id, sample); + int id = perf_evsel__sc_tp_uint(id, sample); int e_machine = thread ? thread__e_machine(thread, trace->host, /*e_flags=*/NULL) : EM_HOST; @@ -3293,7 +3294,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, if (sc) { fprintf(trace->output, "%s(", sc->name); - trace__fprintf_sys_enter(trace, evsel, sample); + trace__fprintf_sys_enter(trace, sample); fputc(')', trace->output); goto newline; } @@ -3313,13 +3314,13 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, const struct tep_event *tp_format = evsel__tp_format(evsel); if (tp_format && (strncmp(tp_format->name, "sys_enter_", 10) || - trace__fprintf_sys_enter(trace, evsel, sample))) { + trace__fprintf_sys_enter(trace, sample))) { if (trace->libtraceevent_print) { event_format__fprintf(tp_format, sample->cpu, sample->raw_data, sample->raw_size, trace->output); } else { - trace__fprintf_tp_fields(trace, evsel, sample, thread, NULL, 0); + trace__fprintf_tp_fields(trace, sample, thread, NULL, 0); } } } @@ -3378,7 +3379,7 @@ static int trace__pgfault(struct trace *trace, if (sample->callchain) { struct callchain_cursor *cursor = get_tls_callchain_cursor(); - callchain_ret = trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret = trace__resolve_callchain(trace, sample, cursor); if (callchain_ret == 0) { if (cursor->nr < trace->min_stack) goto out_put; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 08/25] perf callchain: Don't pass evsel and sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (6 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 07/25] perf trace: Don't pass evsel with sample Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 09/25] perf lock: Only pass sample to handlers Ian Rogers ` (16 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Change callchain resolve code to not pass an evsel with the sample, instead just read the evsel from the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-inject.c | 4 ++-- tools/perf/builtin-kmem.c | 6 ++--- tools/perf/builtin-kwork.c | 5 ++-- tools/perf/builtin-lock.c | 24 +++++++++---------- tools/perf/builtin-sched.c | 5 ++-- tools/perf/builtin-script.c | 6 ++--- tools/perf/builtin-trace.c | 2 +- tools/perf/util/build-id.c | 2 +- tools/perf/util/callchain.c | 8 +++---- tools/perf/util/callchain.h | 5 ++-- tools/perf/util/db-export.c | 8 +++---- tools/perf/util/hist.c | 2 +- tools/perf/util/machine.c | 14 +++++------ tools/perf/util/machine.h | 3 --- .../util/scripting-engines/trace-event-perl.c | 4 ++-- .../scripting-engines/trace-event-python.c | 4 ++-- 17 files changed, 48 insertions(+), 56 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 89456ba6fcbb..f9ac871264af 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -339,7 +339,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, cursor = get_tls_callchain_cursor(); ret = sample__resolve_callchain(sample, cursor, NULL, - evsel, &al, sysctl_perf_event_max_stack); + &al, sysctl_perf_event_max_stack); if (ret) goto out; diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 23217bc3754f..0f8789dd2b68 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -418,7 +418,7 @@ static int perf_event__convert_sample_callchain(const struct perf_tool *tool, goto out; /* this will parse DWARF using stack and register data */ - ret = thread__resolve_callchain(thread, cursor, evsel, sample, + ret = thread__resolve_callchain(thread, cursor, sample, /*parent=*/NULL, /*root_al=*/NULL, PERF_MAX_STACK_DEPTH); thread__put(thread); @@ -1018,7 +1018,7 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e /*sample_in_dso=*/true); } - sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, &args); thread__put(thread); repipe: diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 4f3ff29d2a9f..b04f5d578e7a 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -394,7 +394,7 @@ static int build_alloc_func_list(void) * Find first non-memory allocation function from callchain. * The allocation functions are in the 'alloc_func_list'. */ -static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample) +static u64 find_callsite(struct perf_sample *sample) { struct addr_location al; struct machine *machine = &kmem_session->machines.host; @@ -414,7 +414,7 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample) if (cursor == NULL) goto out; - sample__resolve_callchain(sample, cursor, NULL, evsel, &al, 16); + sample__resolve_callchain(sample, cursor, /*parent=*/NULL, &al, 16); callchain_cursor_commit(cursor); while (true) { @@ -848,7 +848,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) return -1; - callsite = find_callsite(evsel, sample); + callsite = find_callsite(sample); /* * This is to find the current page (with correct gfp flags and diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index f600037ee460..ba6b021543eb 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -688,7 +688,6 @@ static int latency_entry_event(struct perf_kwork *kwork, static void timehist_save_callchain(struct perf_kwork *kwork, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct symbol *sym; @@ -708,7 +707,7 @@ static void timehist_save_callchain(struct perf_kwork *kwork, cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(thread, cursor, evsel, sample, + if (thread__resolve_callchain(thread, cursor, sample, NULL, NULL, kwork->max_stack + 2) != 0) { pr_debug("Failed to resolve callchain, skipping\n"); goto out_put; @@ -838,7 +837,7 @@ static int timehist_entry_event(struct perf_kwork *kwork, return ret; if (work != NULL) - timehist_save_callchain(kwork, sample, evsel, machine); + timehist_save_callchain(kwork, sample, machine); return 0; } diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index baf0c99df5df..a35e8ea4e2ef 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -551,13 +551,13 @@ static int get_key_by_aggr_mode_simple(u64 *key, u64 addr, u32 tid) return 0; } -static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample); +static u64 callchain_id(struct perf_sample *sample); -static int get_key_by_aggr_mode(u64 *key, u64 addr, struct evsel *evsel, +static int get_key_by_aggr_mode(u64 *key, u64 addr, struct perf_sample *sample) { if (aggr_mode == LOCK_AGGR_CALLER) { - *key = callchain_id(evsel, sample); + *key = callchain_id(sample); return 0; } return get_key_by_aggr_mode_simple(key, addr, sample->tid); @@ -841,7 +841,7 @@ static int get_symbol_name_offset(struct map *map, struct symbol *sym, u64 ip, else return strlcpy(buf, sym->name, size); } -static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sample, +static int lock_contention_caller(struct perf_sample *sample, char *buf, int size) { struct thread *thread; @@ -862,7 +862,7 @@ static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sampl cursor = get_tls_callchain_cursor(); /* use caller function name from the callchain */ - ret = thread__resolve_callchain(thread, cursor, evsel, sample, + ret = thread__resolve_callchain(thread, cursor, sample, NULL, NULL, max_stack_depth); if (ret != 0) { thread__put(thread); @@ -896,7 +896,7 @@ static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sampl return -1; } -static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample) +static u64 callchain_id(struct perf_sample *sample) { struct callchain_cursor *cursor; struct machine *machine = &session->machines.host; @@ -911,7 +911,7 @@ static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample) cursor = get_tls_callchain_cursor(); /* use caller function name from the callchain */ - ret = thread__resolve_callchain(thread, cursor, evsel, sample, + ret = thread__resolve_callchain(thread, cursor, sample, NULL, NULL, max_stack_depth); thread__put(thread); @@ -963,7 +963,7 @@ static u64 *get_callstack(struct perf_sample *sample, int max_stack) return callstack; } -static int report_lock_contention_begin_event(struct evsel *evsel, +static int report_lock_contention_begin_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; @@ -978,7 +978,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, struct map *kmap; struct symbol *sym; - ret = get_key_by_aggr_mode(&key, addr, evsel, sample); + ret = get_key_by_aggr_mode(&key, addr, sample); if (ret < 0) return ret; @@ -1025,7 +1025,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, break; case LOCK_AGGR_CALLER: name = buf; - if (lock_contention_caller(evsel, sample, buf, sizeof(buf)) < 0) + if (lock_contention_caller(sample, buf, sizeof(buf)) < 0) name = "Unknown"; break; case LOCK_AGGR_CGROUP: @@ -1127,7 +1127,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, return 0; } -static int report_lock_contention_end_event(struct evsel *evsel, +static int report_lock_contention_end_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) { struct lock_stat *ls; @@ -1138,7 +1138,7 @@ static int report_lock_contention_end_event(struct evsel *evsel, u64 key; int ret; - ret = get_key_by_aggr_mode(&key, addr, evsel, sample); + ret = get_key_by_aggr_mode(&key, addr, sample); if (ret < 0) return ret; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 3e7e8ad0bc13..b6271a5ec8de 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -2330,7 +2330,6 @@ static bool is_idle_sample(struct perf_sample *sample, static void save_task_callchain(struct perf_sched *sched, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct callchain_cursor *cursor; @@ -2350,7 +2349,7 @@ static void save_task_callchain(struct perf_sched *sched, cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(thread, cursor, evsel, sample, + if (thread__resolve_callchain(thread, cursor, sample, NULL, NULL, sched->max_stack + 2) != 0) { if (verbose > 0) pr_err("Failed to resolve callchain. Skipping\n"); @@ -2524,7 +2523,7 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, sample->tid); } - save_task_callchain(sched, sample, evsel, machine); + save_task_callchain(sched, sample, machine); if (sched->idle_hist) { struct thread *idle; struct idle_thread_runtime *itr; diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8724c4ab3e88..8022801721e2 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1683,7 +1683,7 @@ static int perf_sample__fprintf_bts(struct perf_sample *sample, if (symbol_conf.use_callchain && sample->callchain) { cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack)) cursor = NULL; @@ -2506,7 +2506,7 @@ static void process_event(struct perf_script *script, if (symbol_conf.use_callchain && sample->callchain) { cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack)) cursor = NULL; @@ -2790,7 +2790,7 @@ static int process_deferred_sample_event(const struct perf_tool *tool, if (symbol_conf.use_callchain && sample->callchain) { cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al.thread, cursor, evsel, + if (thread__resolve_callchain(al.thread, cursor, sample, NULL, NULL, scripting_max_stack)) { pr_info("cannot resolve deferred callchains\n"); diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 33199ff2bbfd..385a9ac2ae96 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2905,7 +2905,7 @@ static int trace__resolve_callchain(struct trace *trace, if (machine__resolve(trace->host, &al, sample) < 0) goto out; - err = thread__resolve_callchain(al.thread, cursor, evsel, sample, NULL, NULL, max_stack); + err = thread__resolve_callchain(al.thread, cursor, sample, NULL, NULL, max_stack); out: addr_location__exit(&al); return err; diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 55b72235f891..af4d874f1381 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -73,7 +73,7 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, addr_location__exit(&al); - sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_STACK_DEPTH, + sample__for_each_callchain_node(thread, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, /*data=*/NULL); diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 19c97137103c..98038d2eb0db 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1123,7 +1123,7 @@ int callchain_cursor_append(struct callchain_cursor *cursor, int sample__resolve_callchain(struct perf_sample *sample, struct callchain_cursor *cursor, struct symbol **parent, - struct evsel *evsel, struct addr_location *al, + struct addr_location *al, int max_stack) { if (sample->callchain == NULL && !symbol_conf.show_branchflag_count) @@ -1131,7 +1131,7 @@ int sample__resolve_callchain(struct perf_sample *sample, if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain || perf_hpp_list.parent || symbol_conf.show_branchflag_count) { - return thread__resolve_callchain(al->thread, cursor, evsel, sample, + return thread__resolve_callchain(al->thread, cursor, sample, parent, al, max_stack); } return 0; @@ -1806,7 +1806,7 @@ s64 callchain_avg_cycles(struct callchain_node *cnode) return cycles; } -int sample__for_each_callchain_node(struct thread *thread, struct evsel *evsel, +int sample__for_each_callchain_node(struct thread *thread, struct perf_sample *sample, int max_stack, bool symbols, callchain_iter_fn cb, void *data) { @@ -1817,7 +1817,7 @@ int sample__for_each_callchain_node(struct thread *thread, struct evsel *evsel, return -ENOMEM; /* Fill in the callchain. */ - ret = __thread__resolve_callchain(thread, cursor, evsel, sample, + ret = __thread__resolve_callchain(thread, cursor, sample, /*parent=*/NULL, /*root_al=*/NULL, max_stack, symbols); if (ret) diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index df54ddb8c0cb..6eb3e20349a9 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -8,7 +8,6 @@ #include "branch.h" struct addr_location; -struct evsel; struct ip_callchain; struct map; struct perf_sample; @@ -251,7 +250,7 @@ int record_opts__parse_callchain(struct record_opts *record, int sample__resolve_callchain(struct perf_sample *sample, struct callchain_cursor *cursor, struct symbol **parent, - struct evsel *evsel, struct addr_location *al, + struct addr_location *al, int max_stack); int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample); int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node, @@ -314,7 +313,7 @@ s64 callchain_avg_cycles(struct callchain_node *cnode); typedef int (*callchain_iter_fn)(struct callchain_cursor_node *node, void *data); -int sample__for_each_callchain_node(struct thread *thread, struct evsel *evsel, +int sample__for_each_callchain_node(struct thread *thread, struct perf_sample *sample, int max_stack, bool symbols, callchain_iter_fn cb, void *data); diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index ae9a9065aab7..a1f578c3a8d5 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -209,8 +209,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al, static struct call_path *call_path_from_sample(struct db_export *dbe, struct machine *machine, struct thread *thread, - struct perf_sample *sample, - struct evsel *evsel) + struct perf_sample *sample) { u64 kernel_start = machine__kernel_start(machine); struct call_path *current = &dbe->cpr->call_path; @@ -228,7 +227,7 @@ static struct call_path *call_path_from_sample(struct db_export *dbe, */ callchain_param.order = ORDER_CALLER; cursor = get_tls_callchain_cursor(); - err = thread__resolve_callchain(thread, cursor, evsel, + err = thread__resolve_callchain(thread, cursor, sample, NULL, NULL, PERF_MAX_STACK_DEPTH); if (err) { callchain_param.order = saved_order; @@ -391,8 +390,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, if (dbe->cpr) { struct call_path *cp = call_path_from_sample(dbe, machine, - thread, sample, - evsel); + thread, sample); if (cp) { db_export__call_path(dbe, cp); es.call_path_id = cp->db_id; diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 7ffaa3d9851b..84a402d248a3 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -1339,7 +1339,7 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, alm = map__get(al->map); err = sample__resolve_callchain(iter->sample, get_tls_callchain_cursor(), &iter->parent, - iter->evsel, al, max_stack_depth); + al, max_stack_depth); if (err) { map__put(alm); return err; diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index e76f8c86e62a..c2e0a99efe97 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2778,13 +2778,13 @@ static u64 get_leaf_frame_caller(struct perf_sample *sample, static int thread__resolve_callchain_sample(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, int max_stack, bool symbols) { + struct evsel *evsel = sample->evsel; struct branch_stack *branch = sample->branch_stack; struct branch_entry *entries = perf_sample__branch_entries(sample); struct ip_callchain *chain = sample->callchain; @@ -2986,10 +2986,11 @@ static int unwind_entry(struct unwind_entry *entry, void *arg) static int thread__resolve_callchain_unwind(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, int max_stack, bool symbols) { + struct evsel *evsel = sample->evsel; + /* Can we do dwarf post unwind? */ if (!((evsel->core.attr.sample_type & PERF_SAMPLE_REGS_USER) && (evsel->core.attr.sample_type & PERF_SAMPLE_STACK_USER))) @@ -3009,7 +3010,6 @@ static int thread__resolve_callchain_unwind(struct thread *thread, int __thread__resolve_callchain(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, @@ -3025,22 +3025,22 @@ int __thread__resolve_callchain(struct thread *thread, if (callchain_param.order == ORDER_CALLEE) { ret = thread__resolve_callchain_sample(thread, cursor, - evsel, sample, + sample, parent, root_al, max_stack, symbols); if (ret) return ret; ret = thread__resolve_callchain_unwind(thread, cursor, - evsel, sample, + sample, max_stack, symbols); } else { ret = thread__resolve_callchain_unwind(thread, cursor, - evsel, sample, + sample, max_stack, symbols); if (ret) return ret; ret = thread__resolve_callchain_sample(thread, cursor, - evsel, sample, + sample, parent, root_al, max_stack, symbols); } diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index 22a42c5825fa..048b24e9bd38 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -187,7 +187,6 @@ struct callchain_cursor; int __thread__resolve_callchain(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, @@ -196,7 +195,6 @@ int __thread__resolve_callchain(struct thread *thread, static inline int thread__resolve_callchain(struct thread *thread, struct callchain_cursor *cursor, - struct evsel *evsel, struct perf_sample *sample, struct symbol **parent, struct addr_location *root_al, @@ -204,7 +202,6 @@ static inline int thread__resolve_callchain(struct thread *thread, { return __thread__resolve_callchain(thread, cursor, - evsel, sample, parent, root_al, diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index e261a57b87d4..af0d514b2397 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -257,7 +257,7 @@ static void define_event_symbols(struct tep_event *event, } static SV *perl_process_callchain(struct perf_sample *sample, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct addr_location *al) { struct callchain_cursor *cursor; @@ -272,7 +272,7 @@ static SV *perl_process_callchain(struct perf_sample *sample, cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack) != 0) { pr_err("Failed to resolve callchain. Skipping\n"); goto exit; diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 2b0df7bd9a46..08197cef44c8 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -390,7 +390,7 @@ static unsigned long get_offset(struct symbol *sym, struct addr_location *al) } static PyObject *python_process_callchain(struct perf_sample *sample, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct addr_location *al) { PyObject *pylist; @@ -404,7 +404,7 @@ static PyObject *python_process_callchain(struct perf_sample *sample, goto exit; cursor = get_tls_callchain_cursor(); - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack) != 0) { pr_err("Failed to resolve callchain. Skipping\n"); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 09/25] perf lock: Only pass sample to handlers 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (7 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 08/25] perf callchain: Don't pass evsel and sample Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 10/25] perf lock: Constify trace_lock_handler variables Ian Rogers ` (15 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The evsel is within the sample and so only the sample needs to be passed. Remove the parameter and fix call site. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-lock.c | 65 ++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index a35e8ea4e2ef..78fb39d06e7c 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -473,28 +473,22 @@ static struct lock_stat *pop_from_result(void) struct trace_lock_handler { /* it's used on CONFIG_LOCKDEP */ - int (*acquire_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*acquire_event)(struct perf_sample *sample); /* it's used on CONFIG_LOCKDEP && CONFIG_LOCK_STAT */ - int (*acquired_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*acquired_event)(struct perf_sample *sample); /* it's used on CONFIG_LOCKDEP && CONFIG_LOCK_STAT */ - int (*contended_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*contended_event)(struct perf_sample *sample); /* it's used on CONFIG_LOCKDEP */ - int (*release_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*release_event)(struct perf_sample *sample); /* it's used when CONFIG_LOCKDEP is off */ - int (*contention_begin_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*contention_begin_event)(struct perf_sample *sample); /* it's used when CONFIG_LOCKDEP is off */ - int (*contention_end_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*contention_end_event)(struct perf_sample *sample); }; static struct lock_seq_stat *get_seq(struct thread_stat *ts, u64 addr) @@ -563,8 +557,7 @@ static int get_key_by_aggr_mode(u64 *key, u64 addr, return get_key_by_aggr_mode_simple(key, addr, sample->tid); } -static int report_lock_acquire_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_acquire_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -638,8 +631,7 @@ static int report_lock_acquire_event(struct evsel *evsel __maybe_unused, return 0; } -static int report_lock_acquired_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_acquired_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -704,8 +696,7 @@ static int report_lock_acquired_event(struct evsel *evsel __maybe_unused, return 0; } -static int report_lock_contended_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_contended_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -762,8 +753,7 @@ static int report_lock_contended_event(struct evsel *evsel __maybe_unused, return 0; } -static int report_lock_release_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_release_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -963,8 +953,7 @@ static u64 *get_callstack(struct perf_sample *sample, int max_stack) return callstack; } -static int report_lock_contention_begin_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_contention_begin_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -1127,8 +1116,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel __maybe_unused return 0; } -static int report_lock_contention_end_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int report_lock_contention_end_event(struct perf_sample *sample) { struct lock_stat *ls; struct thread_stat *ts; @@ -1208,45 +1196,45 @@ static struct trace_lock_handler contention_lock_ops = { static struct trace_lock_handler *trace_handler; -static int evsel__process_lock_acquire(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_acquire(struct perf_sample *sample) { if (trace_handler->acquire_event) - return trace_handler->acquire_event(evsel, sample); + return trace_handler->acquire_event(sample); return 0; } -static int evsel__process_lock_acquired(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_acquired(struct perf_sample *sample) { if (trace_handler->acquired_event) - return trace_handler->acquired_event(evsel, sample); + return trace_handler->acquired_event(sample); return 0; } -static int evsel__process_lock_contended(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_contended(struct perf_sample *sample) { if (trace_handler->contended_event) - return trace_handler->contended_event(evsel, sample); + return trace_handler->contended_event(sample); return 0; } -static int evsel__process_lock_release(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_lock_release(struct perf_sample *sample) { if (trace_handler->release_event) - return trace_handler->release_event(evsel, sample); + return trace_handler->release_event(sample); return 0; } -static int evsel__process_contention_begin(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_contention_begin(struct perf_sample *sample) { if (trace_handler->contention_begin_event) - return trace_handler->contention_begin_event(evsel, sample); + return trace_handler->contention_begin_event(sample); return 0; } -static int evsel__process_contention_end(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_contention_end(struct perf_sample *sample) { if (trace_handler->contention_end_event) - return trace_handler->contention_end_event(evsel, sample); + return trace_handler->contention_end_event(sample); return 0; } @@ -1424,8 +1412,7 @@ static int process_event_update(const struct perf_tool *tool, return 0; } -typedef int (*tracepoint_handler)(struct evsel *evsel, - struct perf_sample *sample); +typedef int (*tracepoint_handler)(struct perf_sample *sample); static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, @@ -1445,7 +1432,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(evsel, sample); + err = f(sample); } thread__put(thread); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 10/25] perf lock: Constify trace_lock_handler variables 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (8 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 09/25] perf lock: Only pass sample to handlers Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 11/25] perf hist: Remove evsel parameter from inc samples functions Ian Rogers ` (14 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Structs don't change and so constify. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-lock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 78fb39d06e7c..735e6bb234ae 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1179,7 +1179,7 @@ static int report_lock_contention_end_event(struct perf_sample *sample) /* lock oriented handlers */ /* TODO: handlers for CPU oriented, thread oriented */ -static struct trace_lock_handler report_lock_ops = { +static const struct trace_lock_handler report_lock_ops = { .acquire_event = report_lock_acquire_event, .acquired_event = report_lock_acquired_event, .contended_event = report_lock_contended_event, @@ -1188,13 +1188,13 @@ static struct trace_lock_handler report_lock_ops = { .contention_end_event = report_lock_contention_end_event, }; -static struct trace_lock_handler contention_lock_ops = { +static const struct trace_lock_handler contention_lock_ops = { .contention_begin_event = report_lock_contention_begin_event, .contention_end_event = report_lock_contention_end_event, }; -static struct trace_lock_handler *trace_handler; +static const struct trace_lock_handler *trace_handler; static int evsel__process_lock_acquire(struct perf_sample *sample) { -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 11/25] perf hist: Remove evsel parameter from inc samples functions 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (9 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 10/25] perf lock: Constify trace_lock_handler variables Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 12/25] perf db-export: Remove evsel from struct export_sample Ian Rogers ` (13 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan hist_entry__inc_addr_samples and addr_map_symbol__inc_samples unnecessarily take an evsel argument. Read the evsel from the sample instead. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 7 +++---- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-report.c | 18 ++++++++---------- tools/perf/builtin-top.c | 6 +++--- tools/perf/util/annotate.c | 19 +++++++++---------- tools/perf/util/annotate.h | 6 ++---- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index c97a0fe159f8..c2d0599fe5f5 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -177,16 +177,15 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, struct hist_entry *he = iter->he; struct branch_info *bi; struct perf_sample *sample = iter->sample; - struct evsel *evsel = iter->evsel; int err; bi = he->branch_info; - err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; - err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->to, sample); out: return err; @@ -276,7 +275,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, if (he == NULL) return -ENOMEM; - ret = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + ret = hist_entry__inc_addr_samples(he, sample, al->addr); hists__inc_nr_samples(hists, true); return ret; } diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index f9ac871264af..5684c14c2bf6 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -371,7 +371,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, if (perf_c2c__has_annotation(NULL)) { perf_c2c__evsel_hists_inc_stats(evsel, he, sample); - addr_map_symbol__inc_samples(mem_info__iaddr(mi), sample, evsel); + addr_map_symbol__inc_samples(mem_info__iaddr(mi), sample); } ret = hist_entry__append_callchain(he, sample); diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 507002cbdd5b..39968ae5cfb0 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -170,7 +170,6 @@ static int hist_iter__report_callback(struct hist_entry_iter *iter, int err = 0; struct report *rep = arg; struct hist_entry *he = iter->he; - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; struct mem_info *mi; struct branch_info *bi; @@ -180,25 +179,25 @@ static int hist_iter__report_callback(struct hist_entry_iter *iter, if (sort__mode == SORT_MODE__BRANCH) { bi = he->branch_info; - err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; - err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->to, sample); } else if (rep->mem_mode) { mi = he->mem_info; - err = addr_map_symbol__inc_samples(mem_info__daddr(mi), sample, evsel); + err = addr_map_symbol__inc_samples(mem_info__daddr(mi), sample); if (err) goto out; - err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err = hist_entry__inc_addr_samples(he, sample, al->addr); } else if (symbol_conf.cumulate_callchain) { if (single) - err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err = hist_entry__inc_addr_samples(he, sample, al->addr); } else { - err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err = hist_entry__inc_addr_samples(he, sample, al->addr); } out: @@ -214,7 +213,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, struct report *rep = arg; struct branch_info *bi = he->branch_info; struct perf_sample *sample = iter->sample; - struct evsel *evsel = iter->evsel; int err; branch_type_count(&rep->brtype_stat, &bi->flags, @@ -223,11 +221,11 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, if (!ui__has_annotation() && !rep->symbol_ipc) return 0; - err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; - err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err = addr_map_symbol__inc_samples(&bi->to, sample); out: return err; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 710604c4f6f6..e863f9ef581f 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -198,7 +198,7 @@ static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip) static void perf_top__record_precise_ip(struct perf_top *top, struct hist_entry *he, struct perf_sample *sample, - struct evsel *evsel, u64 ip) + u64 ip) EXCLUSIVE_LOCKS_REQUIRED(he->hists->lock) { struct annotation *notes; @@ -215,7 +215,7 @@ static void perf_top__record_precise_ip(struct perf_top *top, if (!annotation__trylock(notes)) return; - err = hist_entry__inc_addr_samples(he, sample, evsel, ip); + err = hist_entry__inc_addr_samples(he, sample, ip); annotation__unlock(notes); @@ -734,7 +734,7 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter, struct evsel *evsel = iter->evsel; if (perf_hpp_list.sym && single) - perf_top__record_precise_ip(top, iter->he, iter->sample, evsel, al->addr); + perf_top__record_precise_ip(top, iter->he, iter->sample, al->addr); hist__account_cycles(iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY), diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 2e3522905046..15ff0443c312 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -211,9 +211,10 @@ static int __symbol__account_cycles(struct cyc_hist *ch, } static int __symbol__inc_addr_samples(struct map_symbol *ms, - struct annotated_source *src, struct evsel *evsel, u64 addr, + struct annotated_source *src, u64 addr, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; struct symbol *sym = ms->sym; long hash_key; u64 offset; @@ -316,7 +317,7 @@ struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists) } static int symbol__inc_addr_samples(struct map_symbol *ms, - struct evsel *evsel, u64 addr, + u64 addr, struct perf_sample *sample) { struct symbol *sym = ms->sym; @@ -324,8 +325,8 @@ static int symbol__inc_addr_samples(struct map_symbol *ms, if (sym == NULL) return 0; - src = symbol__hists(sym, evsel->evlist->core.nr_entries); - return src ? __symbol__inc_addr_samples(ms, src, evsel, addr, sample) : 0; + src = symbol__hists(sym, sample->evsel->evlist->core.nr_entries); + return src ? __symbol__inc_addr_samples(ms, src, addr, sample) : 0; } static int symbol__account_br_cntr(struct annotated_branch *branch, @@ -579,16 +580,14 @@ static int annotation__compute_ipc(struct annotation *notes, size_t size, return 0; } -int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample, - struct evsel *evsel) +int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample) { - return symbol__inc_addr_samples(&ams->ms, evsel, ams->al_addr, sample); + return symbol__inc_addr_samples(&ams->ms, ams->al_addr, sample); } -int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, - struct evsel *evsel, u64 ip) +int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, u64 ip) { - return symbol__inc_addr_samples(&he->ms, evsel, ip, sample); + return symbol__inc_addr_samples(&he->ms, ip, sample); } diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 696e36dbf013..1aa6df7d1618 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -422,8 +422,7 @@ static inline struct annotation *symbol__annotation(struct symbol *sym) return (void *)sym - symbol_conf.priv_size; } -int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample, - struct evsel *evsel); +int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample); struct annotated_branch *annotation__get_branch(struct annotation *notes); @@ -433,8 +432,7 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams, struct evsel *evsel, u64 br_cntr); -int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, - struct evsel *evsel, u64 addr); +int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, u64 addr); struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists); void symbol__annotate_zero_histograms(struct symbol *sym); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 12/25] perf db-export: Remove evsel from struct export_sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (10 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 11/25] perf hist: Remove evsel parameter from inc samples functions Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 13/25] perf hist: Remove evsel from struct hist_entry_iter Ian Rogers ` (12 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan As the sample contains the evsel avoid the duplication. Remove the evsel from db_export__sample as it can also read from the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/db-export.c | 5 ++--- tools/perf/util/db-export.h | 3 +-- tools/perf/util/scripting-engines/trace-event-python.c | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index a1f578c3a8d5..fdfd825c7ef4 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -345,14 +345,13 @@ static int db_export__threads(struct db_export *dbe, struct thread *thread, } int db_export__sample(struct db_export *dbe, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al) { struct thread *thread = al->thread; struct export_sample es = { .event = event, .sample = sample, - .evsel = evsel, .al = al, }; struct thread *main_thread; @@ -365,7 +364,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, if (!machine) return -1; - err = db_export__evsel(dbe, evsel); + err = db_export__evsel(dbe, sample->evsel); if (err) return err; diff --git a/tools/perf/util/db-export.h b/tools/perf/util/db-export.h index 23983cb35706..1abbfd398e3a 100644 --- a/tools/perf/util/db-export.h +++ b/tools/perf/util/db-export.h @@ -25,7 +25,6 @@ struct call_return; struct export_sample { union perf_event *event; struct perf_sample *sample; - struct evsel *evsel; struct addr_location *al; u64 db_id; u64 comm_db_id; @@ -96,7 +95,7 @@ int db_export__symbol(struct db_export *dbe, struct symbol *sym, int db_export__branch_type(struct db_export *dbe, u32 branch_type, const char *name); int db_export__sample(struct db_export *dbe, union perf_event *event, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al); int db_export__branch_types(struct db_export *dbe); diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 08197cef44c8..8de08cebe240 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1312,7 +1312,7 @@ static void python_export_sample_table(struct db_export *dbe, t = tuple_new(28); tuple_set_d64(t, 0, es->db_id); - tuple_set_d64(t, 1, es->evsel->db_id); + tuple_set_d64(t, 1, es->sample->evsel->db_id); tuple_set_d64(t, 2, maps__machine(thread__maps(es->al->thread))->db_id); tuple_set_d64(t, 3, thread__db_id(es->al->thread)); tuple_set_d64(t, 4, es->comm_db_id); @@ -1353,7 +1353,7 @@ static void python_export_synth(struct db_export *dbe, struct export_sample *es) t = tuple_new(3); tuple_set_d64(t, 0, es->db_id); - tuple_set_d64(t, 1, es->evsel->core.attr.config); + tuple_set_d64(t, 1, es->sample->evsel->core.attr.config); tuple_set_bytes(t, 2, es->sample->raw_data, es->sample->raw_size); call_object(tables->synth_handler, t, "synth_data"); @@ -1368,7 +1368,7 @@ static int python_export_sample(struct db_export *dbe, python_export_sample_table(dbe, es); - if (es->evsel->core.attr.type == PERF_TYPE_SYNTH && tables->synth_handler) + if (es->sample->evsel->core.attr.type == PERF_TYPE_SYNTH && tables->synth_handler) python_export_synth(dbe, es); return 0; @@ -1517,7 +1517,7 @@ static void python_process_event(union perf_event *event, /* Reserve for future process_hw/sw/raw APIs */ default: if (tables->db_export_mode) - db_export__sample(&tables->dbe, event, sample, evsel, al, addr_al); + db_export__sample(&tables->dbe, event, sample, al, addr_al); else python_process_general_event(sample, evsel, al, addr_al); } -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 13/25] perf hist: Remove evsel from struct hist_entry_iter 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (11 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 12/25] perf db-export: Remove evsel from struct export_sample Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id Ian Rogers ` (11 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan struct hist_entry_iter has the sample within it so the evsel is unnecessary. Remove the evsel and update uses. Also remove the evsel from hist__account_cycles and derive it from the sample too. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 10 ++++------ tools/perf/builtin-diff.c | 3 +-- tools/perf/builtin-report.c | 6 ++---- tools/perf/builtin-top.c | 9 +++------ tools/perf/tests/hists_cumulate.c | 1 - tools/perf/tests/hists_filter.c | 1 - tools/perf/tests/hists_output.c | 1 - tools/perf/util/hist.c | 24 ++++++++++++------------ tools/perf/util/hist.h | 3 +-- 9 files changed, 23 insertions(+), 35 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index c2d0599fe5f5..041f5dc92ea8 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -191,14 +191,12 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter, return err; } -static int process_branch_callback(struct evsel *evsel, - struct perf_sample *sample, +static int process_branch_callback(struct perf_sample *sample, struct addr_location *al, struct perf_annotate *ann, struct machine *machine) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .add_entry_cb = hist_iter__branch_callback, .hide_unresolved = symbol_conf.hide_unresolved, @@ -221,8 +219,8 @@ static int process_branch_callback(struct evsel *evsel, if (a.map != NULL) dso__set_hit(map__dso(a.map)); - hist__account_cycles(sample->branch_stack, al, sample, false, - NULL, evsel); + hist__account_cycles(sample->branch_stack, al, sample, /*nonany_branch_mode=*/false, + /*total_cycles=*/NULL); ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann); out: @@ -269,7 +267,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, process_branch_stack(sample->branch_stack, al, sample); if (ann->has_br_stack && has_annotation(ann)) - return process_branch_callback(evsel, sample, al, ann, machine); + return process_branch_callback(sample, al, ann, machine); he = hists__add_entry(hists, al, NULL, NULL, NULL, NULL, sample, true); if (he == NULL) diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 096adc65451c..67cf5bbaab29 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -397,7 +397,6 @@ static int diff__process_sample_event(const struct perf_tool *tool, struct evsel *evsel = sample->evsel; struct hists *hists = evsel__hists(evsel); struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .ops = &hist_iter_normal, }; @@ -431,7 +430,7 @@ static int diff__process_sample_event(const struct perf_tool *tool, } hist__account_cycles(sample->branch_stack, &al, sample, - false, NULL, evsel); + /*nonany_branch_mode=*/false, /*total_cycles=*/NULL); break; case COMPUTE_STREAM: diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 39968ae5cfb0..1051d7b75361 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -270,10 +270,8 @@ static int process_sample_event(const struct perf_tool *tool, struct machine *machine) { struct report *rep = container_of(tool, struct report, tool); - struct evsel *evsel = sample->evsel; struct addr_location al; struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .hide_unresolved = symbol_conf.hide_unresolved, .add_entry_cb = hist_iter__report_callback, @@ -285,7 +283,7 @@ static int process_sample_event(const struct perf_tool *tool, return 0; } - if (evswitch__discard(&rep->evswitch, evsel)) + if (evswitch__discard(&rep->evswitch, sample->evsel)) return 0; addr_location__init(&al); @@ -329,7 +327,7 @@ static int process_sample_event(const struct perf_tool *tool, if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) { hist__account_cycles(sample->branch_stack, &al, sample, rep->nonany_branch_mode, - &rep->total_cycles, evsel); + &rep->total_cycles); } rep->total_samples++; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index e863f9ef581f..b89ca48e5d02 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -731,20 +731,18 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter, EXCLUSIVE_LOCKS_REQUIRED(iter->he->hists->lock) { struct perf_top *top = arg; - struct evsel *evsel = iter->evsel; if (perf_hpp_list.sym && single) perf_top__record_precise_ip(top, iter->he, iter->sample, al->addr); hist__account_cycles(iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY), - NULL, evsel); + /*total_cycles=*/NULL); return 0; } static void perf_event__process_sample(const struct perf_tool *tool, const union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -830,9 +828,8 @@ static void perf_event__process_sample(const struct perf_tool *tool, } if (al.sym == NULL || !al.sym->idle) { - struct hists *hists = evsel__hists(evsel); + struct hists *hists = evsel__hists(sample->evsel); struct hist_entry_iter iter = { - .evsel = evsel, .sample = sample, .add_entry_cb = hist_iter__top_callback, }; @@ -1210,7 +1207,7 @@ static int deliver_event(struct ordered_events *qe, } if (event->header.type == PERF_RECORD_SAMPLE) { - perf_event__process_sample(&top->tool, event, evsel, + perf_event__process_sample(&top->tool, event, &sample, machine); } else if (event->header.type == PERF_RECORD_LOST) { perf_top__process_lost(top, event, evsel); diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c index 606aa926a8fc..267cbc24691a 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -87,7 +87,6 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) addr_location__init(&al); for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = &sample, .hide_unresolved = false, }; diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c index cc6b26e373d1..002e3a4c1ca5 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -63,7 +63,6 @@ static int add_hist_entries(struct evlist *evlist, evlist__for_each_entry(evlist, evsel) { for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = &sample, .ops = &hist_iter_normal, .hide_unresolved = false, diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c index 7818950d786e..fa683fd7b1e5 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -57,7 +57,6 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) addr_location__init(&al); for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter = { - .evsel = evsel, .sample = &sample, .ops = &hist_iter_normal, .hide_unresolved = false, diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 84a402d248a3..632c1edcab9a 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -932,8 +932,8 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al { u64 cost; struct mem_info *mi = iter->mi; - struct hists *hists = evsel__hists(iter->evsel); struct perf_sample *sample = iter->sample; + struct hists *hists = evsel__hists(sample->evsel); struct hist_entry *he; if (mi == NULL) @@ -965,7 +965,7 @@ static int iter_finish_mem_entry(struct hist_entry_iter *iter, struct addr_location *al __maybe_unused) { - struct evsel *evsel = iter->evsel; + struct evsel *evsel = iter->sample->evsel; struct hists *hists = evsel__hists(evsel); struct hist_entry *he = iter->he; int err = -EINVAL; @@ -1033,9 +1033,9 @@ static int iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) { struct branch_info *bi; - struct evsel *evsel = iter->evsel; - struct hists *hists = evsel__hists(evsel); struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; + struct hists *hists = evsel__hists(evsel); struct hist_entry *he = NULL; int i = iter->curr; int err = 0; @@ -1075,7 +1075,7 @@ static int iter_finish_branch_entry(struct hist_entry_iter *iter, struct addr_location *al __maybe_unused) { - struct evsel *evsel = iter->evsel; + struct evsel *evsel = iter->sample->evsel; struct hists *hists = evsel__hists(evsel); for (int i = 0; i < iter->total; i++) @@ -1100,8 +1100,8 @@ iter_prepare_normal_entry(struct hist_entry_iter *iter __maybe_unused, static int iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; struct hist_entry *he; he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, @@ -1118,8 +1118,8 @@ iter_finish_normal_entry(struct hist_entry_iter *iter, struct addr_location *al __maybe_unused) { struct hist_entry *he = iter->he; - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; if (he == NULL) return 0; @@ -1162,9 +1162,9 @@ static int iter_add_single_cumulative_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel = iter->evsel; - struct hists *hists = evsel__hists(evsel); struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; + struct hists *hists = evsel__hists(evsel); struct hist_entry **he_cache = iter->he_cache; struct hist_entry *he; int err = 0; @@ -1221,8 +1221,8 @@ static int iter_add_next_cumulative_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel = iter->evsel; struct perf_sample *sample = iter->sample; + struct evsel *evsel = sample->evsel; struct hist_entry **he_cache = iter->he_cache; struct hist_entry *he; struct hist_entry he_tmp = { @@ -2823,7 +2823,7 @@ int hists__unlink(struct hists *hists) void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, struct perf_sample *sample, bool nonany_branch_mode, - u64 *total_cycles, struct evsel *evsel) + u64 *total_cycles) { struct branch_info *bi; struct branch_entry *entries = perf_sample__branch_entries(sample); @@ -2847,7 +2847,7 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, for (int i = bs->nr - 1; i >= 0; i--) { addr_map_symbol__account_cycles(&bi[i].from, nonany_branch_mode ? NULL : prev, - bi[i].flags.cycles, evsel, + bi[i].flags.cycles, sample->evsel, bi[i].branch_stack_cntr); prev = &bi[i].to; diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 1d5ea632ca4e..ee92fffc53a9 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -155,7 +155,6 @@ struct hist_entry_iter { int total; int curr; - struct evsel *evsel; struct perf_sample *sample; struct hist_entry *he; struct symbol *parent; @@ -797,7 +796,7 @@ unsigned int hists__overhead_width(struct hists *hists); void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, struct perf_sample *sample, bool nonany_branch_mode, - u64 *total_cycles, struct evsel *evsel); + u64 *total_cycles); struct option; int parse_filter_percentage(const struct option *opt, const char *arg, int unset); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (12 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 13/25] perf hist: Remove evsel from struct hist_entry_iter Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 15/25] perf annotate: Don't pass evsel to add_sample Ian Rogers ` (10 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan In count_lost_samples_events try to avoid searching for the evsel for the sample, just use the variable within the sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-report.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 1051d7b75361..d53aa7a94192 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -793,9 +793,11 @@ static int count_lost_samples_event(const struct perf_tool *tool, struct machine *machine __maybe_unused) { struct report *rep = container_of(tool, struct report, tool); - struct evsel *evsel; + struct evsel *evsel = sample->evsel; + + if (!evsel) + evsel = evlist__id2evsel(rep->session->evlist, sample->id); - evsel = evlist__id2evsel(rep->session->evlist, sample->id); if (evsel) { struct hists *hists = evsel__hists(evsel); u32 count = event->lost_samples.lost; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 15/25] perf annotate: Don't pass evsel to add_sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (13 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 16/25] perf inject: Don't pass evsel with sample Ian Rogers ` (9 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel so read it rather than pass it. Update call site. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-annotate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 041f5dc92ea8..894e57aa50cd 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -233,11 +233,11 @@ static bool has_annotation(struct perf_annotate *ann) return ui__has_annotation() || ann->use_stdio2; } -static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, - struct addr_location *al, struct perf_annotate *ann, - struct machine *machine) +static int add_sample(struct perf_sample *sample, + struct addr_location *al, struct perf_annotate *ann, + struct machine *machine) { - struct hists *hists = evsel__hists(evsel); + struct hists *hists = evsel__hists(sample->evsel); struct hist_entry *he; int ret; @@ -299,7 +299,7 @@ static int process_sample_event(const struct perf_tool *tool, goto out_put; if (!al.filtered && - evsel__add_sample(sample->evsel, sample, &al, ann, machine)) { + add_sample(sample, &al, ann, machine)) { pr_warning("problem incrementing symbol count, " "skipping event\n"); ret = -1; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 16/25] perf inject: Don't pass evsel with sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (14 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 15/25] perf annotate: Don't pass evsel to add_sample Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 17/25] perf kmem: " Ian Rogers ` (8 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Clean up handling of sample and mmap_evsel when synthesizing build id events and mmap2 events with build ids. For callchain walking and things that expect the evsel to match sample, the sample->evsel shouldn't change. The mmap_evsel should be used when making mmap2 events. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-inject.c | 52 ++++++++++++++++-------------- tools/perf/util/synthetic-events.c | 45 ++++++++++++++++++-------- tools/perf/util/synthetic-events.h | 2 -- 3 files changed, 59 insertions(+), 40 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 0f8789dd2b68..7e0dc0f2dd70 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -146,14 +146,12 @@ struct event_entry { static int tool__inject_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, const char *filename, struct dso *dso, u32 flags); static int tool__inject_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -357,7 +355,6 @@ perf_inject__cut_auxtrace_sample(struct perf_inject *inject, typedef int (*inject_handler)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); static int perf_event__repipe_sample(const struct perf_tool *tool, @@ -370,7 +367,7 @@ static int perf_event__repipe_sample(const struct perf_tool *tool, if (evsel && evsel->handler) { inject_handler f = evsel->handler; - return f(tool, event, sample, evsel, machine); + return f(tool, event, sample, machine); } build_id__mark_dso_hit(tool, event, sample, machine); @@ -584,11 +581,12 @@ static int perf_event__repipe_common_mmap(const struct perf_tool *tool, } if (dso && !dso__hit(dso)) { - struct evsel *evsel = evlist__event2evsel(inject->session->evlist, event); + if (!sample->evsel) + sample->evsel = evlist__event2evsel(inject->session->evlist, event); - if (evsel) { + if (sample->evsel) { dso__set_hit(dso); - tool__inject_build_id(tool, sample, machine, evsel, + tool__inject_build_id(tool, sample, machine, /*misc=*/sample->cpumode, filename, dso, flags); } @@ -615,23 +613,26 @@ static int perf_event__repipe_common_mmap(const struct perf_tool *tool, } if ((inject->build_id_style == BID_RWS__MMAP2_BUILDID_ALL) && !(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) { - struct evsel *evsel = evlist__event2evsel(inject->session->evlist, event); + struct evsel *saved_evsel = sample->evsel; - if (evsel && !dso_sought) { + sample->evsel = evlist__event2evsel(inject->session->evlist, event); + if (sample->evsel && !dso_sought) { dso = findnew_dso(pid, tid, filename, dso_id, machine); dso_sought = true; } - if (evsel && dso && - !tool__inject_mmap2_build_id(tool, sample, machine, evsel, + if (sample->evsel && dso && + !tool__inject_mmap2_build_id(tool, sample, machine, sample->cpumode | PERF_RECORD_MISC_MMAP_BUILD_ID, pid, tid, start, len, pgoff, dso, prot, flags, filename)) { /* Injected mmap2 so no need to repipe. */ + sample->evsel = saved_evsel; dso__put(dso); return 0; } + sample->evsel = saved_evsel; } dso__put(dso); if (inject->build_id_style == BID_RWS__MMAP2_BUILDID_LAZY) @@ -836,7 +837,6 @@ static bool perf_inject__lookup_known_build_id(struct perf_inject *inject, static int tool__inject_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, const char *filename, struct dso *dso, u32 flags) @@ -860,7 +860,7 @@ static int tool__inject_build_id(const struct perf_tool *tool, err = perf_event__synthesize_build_id(tool, sample, machine, perf_event__repipe, - evsel, misc, dso__bid(dso), + misc, dso__bid(dso), filename); if (err) { pr_err("Can't synthesize build_id event for %s\n", filename); @@ -873,7 +873,6 @@ static int tool__inject_build_id(const struct perf_tool *tool, static int tool__inject_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -896,7 +895,6 @@ static int tool__inject_mmap2_build_id(const struct perf_tool *tool, err = perf_event__synthesize_mmap2_build_id(tool, sample, machine, perf_event__repipe, - evsel, misc, pid, tid, start, len, pgoff, dso__bid(dso), @@ -913,7 +911,7 @@ static int mark_dso_hit(const struct perf_inject *inject, const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *mmap_evsel, + struct evsel *mmap_evsel, struct map *map, bool sample_in_dso) { struct dso *dso; @@ -941,9 +939,13 @@ static int mark_dso_hit(const struct perf_inject *inject, dso = map__dso(map); if (inject->build_id_style == BID_RWS__INJECT_HEADER_LAZY) { if (dso && !dso__hit(dso)) { + /* + * The sample is just read for identifiers which we want + * to match the for the event of the sample. + */ dso__set_hit(dso); tool__inject_build_id(tool, sample, machine, - mmap_evsel, misc, dso__long_name(dso), dso, + misc, dso__long_name(dso), dso, map__flags(map)); } } else if (inject->build_id_style == BID_RWS__MMAP2_BUILDID_LAZY) { @@ -951,11 +953,13 @@ static int mark_dso_hit(const struct perf_inject *inject, const struct build_id null_bid = { .size = 0 }; const struct build_id *bid = dso ? dso__bid(dso) : &null_bid; const char *filename = dso ? dso__long_name(dso) : ""; + struct evsel *saved_evsel = sample->evsel; map__set_hit(map); + /* Creating a new mmap2 event which has an evsel for the mmap event. */ + sample->evsel = mmap_evsel; perf_event__synthesize_mmap2_build_id(tool, sample, machine, perf_event__repipe, - mmap_evsel, misc, sample->pid, sample->tid, map__start(map), @@ -965,6 +969,7 @@ static int mark_dso_hit(const struct perf_inject *inject, map__prot(map), map__flags(map), filename); + sample->evsel = saved_evsel; } } return 0; @@ -975,7 +980,7 @@ struct mark_dso_hit_args { const struct perf_tool *tool; struct perf_sample *sample; struct machine *machine; - const struct evsel *mmap_evsel; + struct evsel *mmap_evsel; }; static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data) @@ -1030,7 +1035,6 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_e static int perf_inject__sched_process_exit(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine __maybe_unused) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); @@ -1050,13 +1054,12 @@ static int perf_inject__sched_process_exit(const struct perf_tool *tool, static int perf_inject__sched_switch(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_inject *inject = container_of(tool, struct perf_inject, tool); struct event_entry *ent; - perf_inject__sched_process_exit(tool, event, sample, evsel, machine); + perf_inject__sched_process_exit(tool, event, sample, machine); ent = malloc(event->header.size + sizeof(struct event_entry)); if (ent == NULL) { @@ -1075,13 +1078,13 @@ static int perf_inject__sched_switch(const struct perf_tool *tool, static int perf_inject__sched_stat(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct event_entry *ent; union perf_event *event_sw; struct perf_sample sample_sw; struct perf_inject *inject = container_of(tool, struct perf_inject, tool); + struct evsel *evsel = sample->evsel; u32 pid = perf_sample__intval(sample, "pid"); int ret; @@ -1446,7 +1449,7 @@ static int synthesize_build_id(struct perf_inject *inject, struct dso *dso, pid_ dso__set_hit(dso); return perf_event__synthesize_build_id(&inject->tool, &synth_sample, machine, - process_build_id, inject__mmap_evsel(inject), + process_build_id, /*misc=*/synth_sample.cpumode, dso__bid(dso), dso__long_name(dso)); } @@ -1989,7 +1992,6 @@ static int evsel__check_stype(struct evsel *evsel, u64 sample_type, const char * static int drop_sample(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct machine *machine __maybe_unused) { return 0; diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index ef79433ebc3a..1e6705bcb3e0 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -1797,7 +1797,12 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_fo return 0; } -int perf_event__synthesize_id_sample(__u64 *array, u64 type, const struct perf_sample *sample) +static int __perf_event__synthesize_id_sample(__u64 *array, u64 type, + __u32 pid, __u32 tid, + __u64 sample_time, + __u64 sample_id, + __u64 stream_id, + __u32 cpu) { __u64 *start = array; @@ -1808,42 +1813,52 @@ int perf_event__synthesize_id_sample(__u64 *array, u64 type, const struct perf_s union u64_swap u; if (type & PERF_SAMPLE_TID) { - u.val32[0] = sample->pid; - u.val32[1] = sample->tid; + u.val32[0] = pid; + u.val32[1] = tid; *array = u.val64; array++; } if (type & PERF_SAMPLE_TIME) { - *array = sample->time; + *array = sample_time; array++; } if (type & PERF_SAMPLE_ID) { - *array = sample->id; + *array = sample_id; array++; } if (type & PERF_SAMPLE_STREAM_ID) { - *array = sample->stream_id; + *array = stream_id; array++; } if (type & PERF_SAMPLE_CPU) { - u.val32[0] = sample->cpu; + u.val32[0] = cpu; u.val32[1] = 0; *array = u.val64; array++; } if (type & PERF_SAMPLE_IDENTIFIER) { - *array = sample->id; + *array = sample_id; array++; } return (void *)array - (void *)start; } +int perf_event__synthesize_id_sample(__u64 *array, u64 type, const struct perf_sample *sample) +{ + return __perf_event__synthesize_id_sample(array, type, + sample->pid, sample->tid, + sample->time, + sample->id, + sample->stream_id, + sample->cpu); +} + int __perf_event__synthesize_id_index(const struct perf_tool *tool, perf_event__handler_t process, struct evlist *evlist, struct machine *machine, size_t from) { @@ -2247,7 +2262,6 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, const struct build_id *bid, const char *filename) @@ -2270,12 +2284,13 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, ev.build_id.header.size = len; strcpy(ev.build_id.filename, filename); - if (evsel) { + if (sample->evsel) { void *array = &ev; int ret; array += ev.header.size; - ret = perf_event__synthesize_id_sample(array, evsel->core.attr.sample_type, sample); + ret = perf_event__synthesize_id_sample(array, sample->evsel->core.attr.sample_type, + sample); if (ret < 0) return ret; @@ -2294,7 +2309,6 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -2334,7 +2348,12 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, array = &ev; array += ev.header.size; - ret = perf_event__synthesize_id_sample(array, evsel->core.attr.sample_type, sample); + ret = __perf_event__synthesize_id_sample(array, sample->evsel->core.attr.sample_type, + pid, tid, + sample->time, + sample->id, + sample->stream_id, + sample->cpu); if (ret < 0) return ret; diff --git a/tools/perf/util/synthetic-events.h b/tools/perf/util/synthetic-events.h index b0edad0c3100..473a43a78993 100644 --- a/tools/perf/util/synthetic-events.h +++ b/tools/perf/util/synthetic-events.h @@ -50,7 +50,6 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, const struct build_id *bid, const char *filename); @@ -58,7 +57,6 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, perf_event__handler_t process, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 17/25] perf kmem: Don't pass evsel with sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (15 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 16/25] perf inject: Don't pass evsel with sample Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 18/25] perf kwork: " Ian Rogers ` (7 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Fix memory leaks on error paths spotted during code review. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-kmem.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index b04f5d578e7a..8eb4eff4e469 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -171,7 +171,7 @@ static int insert_caller_stat(unsigned long call_site, return 0; } -static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_alloc_event(struct perf_sample *sample) { unsigned long ptr = perf_sample__intval(sample, "ptr"), call_site = perf_sample__intval(sample, "call_site"); @@ -198,7 +198,7 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s * If the tracepoint contains the field "node" the tool stats the * cross allocation. */ - if (evsel__field(evsel, "node")) { + if (evsel__field(sample->evsel, "node")) { int node1, node2; node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}); @@ -243,7 +243,7 @@ static struct alloc_stat *search_alloc_stat(unsigned long ptr, return NULL; } -static int evsel__process_free_event(struct evsel *evsel __maybe_unused, struct perf_sample *sample) +static int evsel__process_free_event(struct perf_sample *sample) { unsigned long ptr = perf_sample__intval(sample, "ptr"); struct alloc_stat *s_alloc, *s_caller; @@ -751,8 +751,7 @@ static char *compact_gfp_string(unsigned long gfp_flags) return NULL; } -static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, - unsigned int gfp_flags) +static int parse_gfp_flags(struct perf_sample *sample, unsigned int gfp_flags) { struct tep_record record = { .cpu = sample->cpu, @@ -773,7 +772,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, } trace_seq_init(&seq); - tp_format = evsel__tp_format(evsel); + tp_format = evsel__tp_format(sample->evsel); if (tp_format) tep_print_event(tp_format->tep, &seq, &record, "%s", TEP_PRINT_INFO); @@ -784,7 +783,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, new = realloc(gfps, (nr_gfps + 1) * sizeof(*gfps)); if (new == NULL) - return -ENOMEM; + goto err_out; gfps = new; new += nr_gfps++; @@ -793,7 +792,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, new->human_readable = strdup(str + 10); new->compact_str = compact_gfp_flags(str + 10); if (!new->human_readable || !new->compact_str) - return -ENOMEM; + goto err_out; qsort(gfps, nr_gfps, sizeof(*gfps), gfpcmp); } @@ -803,9 +802,12 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, trace_seq_destroy(&seq); return 0; +err_out: + trace_seq_destroy(&seq); + return -ENOMEM; } -static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sample *sample) +static int evsel__process_page_alloc_event(struct perf_sample *sample) { u64 page; unsigned int order = perf_sample__intval(sample, "order"); @@ -845,7 +847,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp return 0; } - if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) + if (parse_gfp_flags(sample, gfp_flags) < 0) return -1; callsite = find_callsite(sample); @@ -886,8 +888,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp return 0; } -static int evsel__process_page_free_event(struct evsel *evsel __maybe_unused, - struct perf_sample *sample) +static int evsel__process_page_free_event(struct perf_sample *sample) { u64 page; unsigned int order = perf_sample__intval(sample, "order"); @@ -969,8 +970,7 @@ static bool perf_kmem__skip_sample(struct perf_sample *sample) return false; } -typedef int (*tracepoint_handler)(struct evsel *evsel, - struct perf_sample *sample); +typedef int (*tracepoint_handler)(struct perf_sample *sample); static int process_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event, @@ -988,14 +988,16 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, return -1; } - if (perf_kmem__skip_sample(sample)) + if (perf_kmem__skip_sample(sample)) { + thread__put(thread); return 0; + } dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread__tid(thread)); if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(evsel, sample); + err = f(sample); } thread__put(thread); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 18/25] perf kwork: Don't pass evsel with sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (16 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 17/25] perf kmem: " Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 19/25] perf sched: " Ian Rogers ` (6 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Remove the evsel from struct kwork_class. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-kwork.c | 74 +++++++++++++------------------------- tools/perf/util/kwork.h | 9 +++-- 2 files changed, 28 insertions(+), 55 deletions(-) diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index ba6b021543eb..f63a7eb5cb91 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -448,7 +448,6 @@ static int work_push_atom(struct perf_kwork *kwork, struct kwork_class *class, enum kwork_trace_type src_type, enum kwork_trace_type dst_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct kwork_work **ret_work, @@ -458,7 +457,7 @@ static int work_push_atom(struct perf_kwork *kwork, struct kwork_work *work, key; BUG_ON(class->work_init == NULL); - class->work_init(kwork, class, &key, src_type, evsel, sample, machine); + class->work_init(kwork, class, &key, src_type, sample, machine); atom = atom_new(kwork, sample); if (atom == NULL) @@ -507,7 +506,6 @@ static struct kwork_atom *work_pop_atom(struct perf_kwork *kwork, struct kwork_class *class, enum kwork_trace_type src_type, enum kwork_trace_type dst_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct kwork_work **ret_work) @@ -516,7 +514,7 @@ static struct kwork_atom *work_pop_atom(struct perf_kwork *kwork, struct kwork_work *work, key; BUG_ON(class->work_init == NULL); - class->work_init(kwork, class, &key, src_type, evsel, sample, machine); + class->work_init(kwork, class, &key, src_type, sample, machine); work = work_findnew(&class->work_root, &key, &kwork->cmp_id); if (ret_work != NULL) @@ -599,18 +597,16 @@ static void report_update_exit_event(struct kwork_work *work, static int report_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int report_exit_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -618,7 +614,7 @@ static int report_exit_event(struct perf_kwork *kwork, struct kwork_work *work = NULL; atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (work == NULL) return -1; @@ -654,18 +650,16 @@ static void latency_update_entry_event(struct kwork_work *work, static int latency_raise_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_RAISE, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int latency_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -673,7 +667,7 @@ static int latency_entry_event(struct perf_kwork *kwork, struct kwork_work *work = NULL; atom = work_pop_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_RAISE, evsel, sample, + KWORK_TRACE_RAISE, sample, machine, &work); if (work == NULL) return -1; @@ -812,18 +806,16 @@ static void timehist_print_event(struct perf_kwork *kwork, static int timehist_raise_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_RAISE, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int timehist_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -831,7 +823,7 @@ static int timehist_entry_event(struct perf_kwork *kwork, struct kwork_work *work = NULL; ret = work_push_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_RAISE, evsel, sample, + KWORK_TRACE_RAISE, sample, machine, &work, true); if (ret) return ret; @@ -844,7 +836,6 @@ static int timehist_entry_event(struct perf_kwork *kwork, static int timehist_exit_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -861,7 +852,7 @@ static int timehist_exit_event(struct perf_kwork *kwork, } atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (work == NULL) { ret = -1; @@ -895,18 +886,16 @@ static void top_update_runtime(struct kwork_work *work, static int top_entry_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { return work_push_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_MAX, evsel, sample, + KWORK_TRACE_MAX, sample, machine, NULL, true); } static int top_exit_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -915,7 +904,7 @@ static int top_exit_event(struct perf_kwork *kwork, struct kwork_atom *atom; atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (!work) return -1; @@ -936,7 +925,6 @@ static int top_exit_event(struct perf_kwork *kwork, static int top_sched_switch_event(struct perf_kwork *kwork, struct kwork_class *class, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -944,7 +932,7 @@ static int top_sched_switch_event(struct perf_kwork *kwork, struct kwork_work *work; atom = work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (!work) return -1; @@ -954,12 +942,11 @@ static int top_sched_switch_event(struct perf_kwork *kwork, atom_del(atom); } - return top_entry_event(kwork, class, evsel, sample, machine); + return top_entry_event(kwork, class, sample, machine); } static struct kwork_class kwork_irq; static int process_irq_handler_entry_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -967,12 +954,11 @@ static int process_irq_handler_entry_event(const struct perf_tool *tool, if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_irq, - evsel, sample, machine); + sample, machine); return 0; } static int process_irq_handler_exit_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -980,7 +966,7 @@ static int process_irq_handler_exit_event(const struct perf_tool *tool, if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_irq, - evsel, sample, machine); + sample, machine); return 0; } @@ -1005,7 +991,6 @@ static void irq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1038,7 +1023,6 @@ static struct kwork_class kwork_irq = { static struct kwork_class kwork_softirq; static int process_softirq_raise_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1046,13 +1030,12 @@ static int process_softirq_raise_event(const struct perf_tool *tool, if (kwork->tp_handler->raise_event) return kwork->tp_handler->raise_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); return 0; } static int process_softirq_entry_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1060,13 +1043,12 @@ static int process_softirq_entry_event(const struct perf_tool *tool, if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); return 0; } static int process_softirq_exit_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1074,7 +1056,7 @@ static int process_softirq_exit_event(const struct perf_tool *tool, if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); return 0; } @@ -1133,7 +1115,6 @@ static void softirq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1148,7 +1129,7 @@ static void softirq_work_init(struct perf_kwork *kwork, } else { num = perf_sample__intval(sample, "vec"); work->id = num; - work->name = evsel__softirq_name(evsel, num); + work->name = evsel__softirq_name(sample->evsel, num); } } @@ -1169,7 +1150,6 @@ static struct kwork_class kwork_softirq = { static struct kwork_class kwork_workqueue; static int process_workqueue_activate_work_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1177,13 +1157,12 @@ static int process_workqueue_activate_work_event(const struct perf_tool *tool, if (kwork->tp_handler->raise_event) return kwork->tp_handler->raise_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); return 0; } static int process_workqueue_execute_start_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1191,13 +1170,12 @@ static int process_workqueue_execute_start_event(const struct perf_tool *tool, if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); return 0; } static int process_workqueue_execute_end_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1205,7 +1183,7 @@ static int process_workqueue_execute_end_event(const struct perf_tool *tool, if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); return 0; } @@ -1233,7 +1211,6 @@ static void workqueue_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1267,7 +1244,6 @@ static struct kwork_class kwork_workqueue = { static struct kwork_class kwork_sched; static int process_sched_switch_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1275,7 +1251,7 @@ static int process_sched_switch_event(const struct perf_tool *tool, if (kwork->tp_handler->sched_switch_event) return kwork->tp_handler->sched_switch_event(kwork, &kwork_sched, - evsel, sample, machine); + sample, machine); return 0; } @@ -1300,7 +1276,6 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1946,7 +1921,6 @@ static int perf_kwork__report(struct perf_kwork *kwork) } typedef int (*tracepoint_handler)(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -1961,7 +1935,7 @@ static int perf_kwork__process_tracepoint_sample(const struct perf_tool *tool, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(tool, evsel, sample, machine); + err = f(tool, sample, machine); } return err; diff --git a/tools/perf/util/kwork.h b/tools/perf/util/kwork.h index db00269b73f2..abf637d44794 100644 --- a/tools/perf/util/kwork.h +++ b/tools/perf/util/kwork.h @@ -157,7 +157,6 @@ struct kwork_class { struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -167,19 +166,19 @@ struct kwork_class { struct trace_kwork_handler { int (*raise_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); int (*entry_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); int (*exit_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); int (*sched_switch_event)(struct perf_kwork *kwork, - struct kwork_class *class, struct evsel *evsel, + struct kwork_class *class, struct perf_sample *sample, struct machine *machine); }; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 19/25] perf sched: Don't pass evsel with sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (17 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 18/25] perf kwork: " Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 20/25] perf timechart: " Ian Rogers ` (5 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-sched.c | 92 ++++++++++++++------------------------ 1 file changed, 34 insertions(+), 58 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index b6271a5ec8de..fdfa2fec0fe6 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -129,21 +129,20 @@ typedef int (*sort_fn_t)(struct work_atoms *, struct work_atoms *); struct perf_sched; struct trace_sched_handler { - int (*switch_event)(struct perf_sched *sched, struct evsel *evsel, - struct perf_sample *sample, struct machine *machine); + int (*switch_event)(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine); - int (*runtime_event)(struct perf_sched *sched, struct evsel *evsel, - struct perf_sample *sample, struct machine *machine); + int (*runtime_event)(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine); - int (*wakeup_event)(struct perf_sched *sched, struct evsel *evsel, - struct perf_sample *sample, struct machine *machine); + int (*wakeup_event)(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine); /* PERF_RECORD_FORK event, not sched_process_fork tracepoint */ int (*fork_event)(struct perf_sched *sched, union perf_event *event, struct machine *machine); int (*migrate_task_event)(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); }; @@ -826,7 +825,7 @@ static void test_calibrations(struct perf_sched *sched) static int replay_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, + struct perf_sample *sample, struct machine *machine __maybe_unused) { const char *comm = perf_sample__strval(sample, "comm"); @@ -834,7 +833,7 @@ replay_wakeup_event(struct perf_sched *sched, struct task_desc *waker, *wakee; if (verbose > 0) { - printf("sched_wakeup event %p\n", evsel); + printf("sched_wakeup event %p\n", sample->evsel); printf(" ... pid %d woke up %s/%d\n", sample->tid, comm, pid); } @@ -847,7 +846,6 @@ replay_wakeup_event(struct perf_sched *sched, } static int replay_switch_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -861,7 +859,7 @@ static int replay_switch_event(struct perf_sched *sched, s64 delta; if (verbose > 0) - printf("sched_switch event %p\n", evsel); + printf("sched_switch event %p\n", sample->evsel); if (cpu >= MAX_CPUS || cpu < 0) return 0; @@ -1134,7 +1132,6 @@ static void free_work_atoms(struct work_atoms *atoms) } static int latency_switch_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1204,7 +1201,6 @@ static int latency_switch_event(struct perf_sched *sched, } static int latency_runtime_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1239,7 +1235,6 @@ static int latency_runtime_event(struct perf_sched *sched, } static int latency_wakeup_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1300,7 +1295,6 @@ static int latency_wakeup_event(struct perf_sched *sched, } static int latency_migrate_task_event(struct perf_sched *sched, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -1519,20 +1513,18 @@ static void perf_sched__sort_lat(struct perf_sched *sched) } static int process_sched_wakeup_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); if (sched->tp_handler->wakeup_event) - return sched->tp_handler->wakeup_event(sched, evsel, sample, machine); + return sched->tp_handler->wakeup_event(sched, sample, machine); return 0; } static int process_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused) { @@ -1626,8 +1618,8 @@ static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu, } } -static int map_switch_event(struct perf_sched *sched, struct evsel *evsel __maybe_unused, - struct perf_sample *sample, struct machine *machine) +static int map_switch_event(struct perf_sched *sched, struct perf_sample *sample, + struct machine *machine) { const u32 next_pid = perf_sample__intval(sample, "next_pid"); const u32 prev_pid = perf_sample__intval(sample, "prev_pid"); @@ -1791,7 +1783,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel __mayb } static int process_sched_switch_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1815,21 +1806,20 @@ static int process_sched_switch_event(const struct perf_tool *tool, } if (sched->tp_handler->switch_event) - err = sched->tp_handler->switch_event(sched, evsel, sample, machine); + err = sched->tp_handler->switch_event(sched, sample, machine); sched->curr_pid[this_cpu] = next_pid; return err; } static int process_sched_runtime_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); if (sched->tp_handler->runtime_event) - return sched->tp_handler->runtime_event(sched, evsel, sample, machine); + return sched->tp_handler->runtime_event(sched, sample, machine); return 0; } @@ -1852,20 +1842,18 @@ static int perf_sched__process_fork_event(const struct perf_tool *tool, } static int process_sched_migrate_task_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); if (sched->tp_handler->migrate_task_event) - return sched->tp_handler->migrate_task_event(sched, evsel, sample, machine); + return sched->tp_handler->migrate_task_event(sched, sample, machine); return 0; } typedef int (*tracepoint_handler)(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -1879,7 +1867,7 @@ static int perf_sched__process_tracepoint_sample(const struct perf_tool *tool __ if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - err = f(tool, evsel, sample, machine); + err = f(tool, sample, machine); } return err; @@ -2318,11 +2306,10 @@ static void timehist_update_runtime_stats(struct thread_runtime *r, r->total_pre_mig_time += r->dt_pre_mig; } -static bool is_idle_sample(struct perf_sample *sample, - struct evsel *evsel) +static bool is_idle_sample(struct perf_sample *sample) { /* pid 0 == swapper == idle task */ - if (evsel__name_is(evsel, "sched:sched_switch")) + if (evsel__name_is(sample->evsel, "sched:sched_switch")) return perf_sample__intval(sample, "prev_pid") == 0; return sample->pid == 0; @@ -2504,12 +2491,11 @@ static void save_idle_callchain(struct perf_sched *sched, static struct thread *timehist_get_thread(struct perf_sched *sched, struct perf_sample *sample, - struct machine *machine, - struct evsel *evsel) + struct machine *machine) { struct thread *thread; - if (is_idle_sample(sample, evsel)) { + if (is_idle_sample(sample)) { thread = get_idle_thread(sample->cpu); if (thread == NULL) pr_err("Failed to get idle thread for cpu %d.\n", sample->cpu); @@ -2552,7 +2538,6 @@ static struct thread *timehist_get_thread(struct perf_sched *sched, static bool timehist_skip_sample(struct perf_sched *sched, struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { bool rc = false; @@ -2574,7 +2559,7 @@ static bool timehist_skip_sample(struct perf_sched *sched, tr = thread__get_runtime(thread); if (tr && tr->prio != -1) prio = tr->prio; - else if (evsel__name_is(evsel, "sched:sched_switch")) + else if (evsel__name_is(sample->evsel, "sched:sched_switch")) prio = perf_sample__intval(sample, "prev_prio"); if (prio != -1 && !test_bit(prio, sched->prio_bitmap)) { @@ -2584,7 +2569,7 @@ static bool timehist_skip_sample(struct perf_sched *sched, } if (sched->idle_hist) { - if (!evsel__name_is(evsel, "sched:sched_switch")) + if (!evsel__name_is(sample->evsel, "sched:sched_switch")) rc = true; else if (perf_sample__intval(sample, "prev_pid") != 0 && perf_sample__intval(sample, "next_pid") != 0) @@ -2595,7 +2580,6 @@ static bool timehist_skip_sample(struct perf_sched *sched, } static void timehist_print_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct thread *awakened) @@ -2608,8 +2592,8 @@ static void timehist_print_wakeup_event(struct perf_sched *sched, return; /* show wakeup unless both awakee and awaker are filtered */ - if (timehist_skip_sample(sched, thread, evsel, sample) && - timehist_skip_sample(sched, awakened, evsel, sample)) { + if (timehist_skip_sample(sched, thread, sample) && + timehist_skip_sample(sched, awakened, sample)) { thread__put(thread); return; } @@ -2633,7 +2617,6 @@ static void timehist_print_wakeup_event(struct perf_sched *sched, static int timehist_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused) { @@ -2642,7 +2625,6 @@ static int timehist_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unu static int timehist_sched_wakeup_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2668,14 +2650,13 @@ static int timehist_sched_wakeup_event(const struct perf_tool *tool, /* show wakeups if requested */ if (sched->show_wakeups && !perf_time__skip_sample(&sched->ptime, sample->time)) - timehist_print_wakeup_event(sched, evsel, sample, machine, thread); + timehist_print_wakeup_event(sched, sample, machine, thread); thread__put(thread); return 0; } static void timehist_print_migration_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct thread *migrated) @@ -2696,8 +2677,8 @@ static void timehist_print_migration_event(struct perf_sched *sched, if (thread == NULL) return; - if (timehist_skip_sample(sched, thread, evsel, sample) && - timehist_skip_sample(sched, migrated, evsel, sample)) { + if (timehist_skip_sample(sched, thread, sample) && + timehist_skip_sample(sched, migrated, sample)) { thread__put(thread); return; } @@ -2731,7 +2712,6 @@ static void timehist_print_migration_event(struct perf_sched *sched, static int timehist_migrate_task_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2756,8 +2736,7 @@ static int timehist_migrate_task_event(const struct perf_tool *tool, /* show migrations if requested */ if (sched->show_migrations) { - timehist_print_migration_event(sched, evsel, sample, - machine, thread); + timehist_print_migration_event(sched, sample, machine, thread); } thread__put(thread); @@ -2789,7 +2768,6 @@ static void timehist_update_task_prio(struct perf_sample *sample, static int timehist_sched_change_event(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2813,13 +2791,13 @@ static int timehist_sched_change_event(const struct perf_tool *tool, if (sched->show_prio || sched->prio_str) timehist_update_task_prio(sample, machine); - thread = timehist_get_thread(sched, sample, machine, evsel); + thread = timehist_get_thread(sched, sample, machine); if (thread == NULL) { rc = -1; goto out; } - if (timehist_skip_sample(sched, thread, evsel, sample)) + if (timehist_skip_sample(sched, thread, sample)) goto out; tr = thread__get_runtime(thread); @@ -2828,7 +2806,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, goto out; } - tprev = evsel__get_time(evsel, sample->cpu); + tprev = evsel__get_time(sample->evsel, sample->cpu); /* * If start time given: @@ -2918,7 +2896,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool, tr->migrated = 0; } - evsel__save_time(evsel, sample->time, sample->cpu); + evsel__save_time(sample->evsel, sample->time, sample->cpu); thread__put(thread); addr_location__exit(&al); @@ -2927,11 +2905,10 @@ static int timehist_sched_change_event(const struct perf_tool *tool, static int timehist_sched_switch_event(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { - return timehist_sched_change_event(tool, event, evsel, sample, machine); + return timehist_sched_change_event(tool, event, sample, machine); } static int process_lost(const struct perf_tool *tool __maybe_unused, @@ -3179,7 +3156,6 @@ static void timehist_print_summary(struct perf_sched *sched, typedef int (*sched_handler)(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); @@ -3201,7 +3177,7 @@ static int perf_timehist__process_sample(const struct perf_tool *tool, if (evsel->handler != NULL) { sched_handler f = evsel->handler; - err = f(tool, event, evsel, sample, machine); + err = f(tool, event, sample, machine); } return err; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 20/25] perf timechart: Don't pass evsel with sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (18 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 19/25] perf sched: " Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 21/25] perf trace: " Ian Rogers ` (4 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Add missing backtrace argument to tracepoint_handler functions and mark them unused. Fix missing free from cat_backtrace, which requires copies of the backtrace being made in functions that save it. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-timechart.c | 75 ++++++++++++++++------------------ 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 782ede4258a2..69ee08a8295f 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -299,7 +299,7 @@ static void pid_put_sample(struct timechart *tchart, int pid, int type, sample->type = type; sample->next = c->samples; sample->cpu = cpu; - sample->backtrace = backtrace; + sample->backtrace = backtrace ? strdup(backtrace) : NULL; c->samples = sample; if (sample->type == TYPE_RUNNING && end > start && start > 0) { @@ -433,7 +433,7 @@ static void sched_wakeup(struct timechart *tchart, int cpu, u64 timestamp, we->time = timestamp; we->waker = waker; - we->backtrace = backtrace; + we->backtrace = backtrace ? strdup(backtrace) : NULL; if ((flags & TRACE_FLAG_HARDIRQ) || (flags & TRACE_FLAG_SOFTIRQ)) we->waker = -1; @@ -489,9 +489,9 @@ static void sched_switch(struct timechart *tchart, int cpu, u64 timestamp, } } -static const char *cat_backtrace(union perf_event *event, - struct perf_sample *sample, - struct machine *machine) +static char *cat_backtrace(union perf_event *event, + struct perf_sample *sample, + struct machine *machine) { struct addr_location al; unsigned int i; @@ -567,7 +567,6 @@ static const char *cat_backtrace(union perf_event *event, } typedef int (*tracepoint_handler)(struct timechart *tchart, - struct evsel *evsel, struct perf_sample *sample, const char *backtrace); @@ -578,6 +577,7 @@ static int process_sample_event(const struct perf_tool *tool, { struct timechart *tchart = container_of(tool, struct timechart, tool); struct evsel *evsel = sample->evsel; + int ret = 0; if (evsel->core.attr.sample_type & PERF_SAMPLE_TIME) { if (!tchart->first_time || tchart->first_time > sample->time) @@ -588,16 +588,17 @@ static int process_sample_event(const struct perf_tool *tool, if (evsel->handler != NULL) { tracepoint_handler f = evsel->handler; - return f(tchart, evsel, sample, - cat_backtrace(event, sample, machine)); + char *backtrace = cat_backtrace(event, sample, machine); + + ret = f(tchart, sample, backtrace); + free(backtrace); } - return 0; + return ret; } static int process_sample_cpu_idle(struct timechart *tchart __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -617,7 +618,6 @@ process_sample_cpu_idle(struct timechart *tchart __maybe_unused, static int process_sample_cpu_frequency(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -634,7 +634,6 @@ process_sample_cpu_frequency(struct timechart *tchart, static int process_sample_sched_wakeup(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { @@ -648,7 +647,6 @@ process_sample_sched_wakeup(struct timechart *tchart, static int process_sample_sched_switch(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { @@ -664,7 +662,6 @@ process_sample_sched_switch(struct timechart *tchart, #ifdef SUPPORT_OLD_POWER_EVENTS static int process_sample_power_start(struct timechart *tchart __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -681,7 +678,6 @@ process_sample_power_start(struct timechart *tchart __maybe_unused, static int process_sample_power_end(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -691,7 +687,6 @@ process_sample_power_end(struct timechart *tchart, static int process_sample_power_frequency(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -865,8 +860,8 @@ static int pid_end_io_sample(struct timechart *tchart, int pid, int type, static int process_enter_read(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ, @@ -875,8 +870,8 @@ process_enter_read(struct timechart *tchart, static int process_exit_read(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_READ, @@ -885,8 +880,8 @@ process_exit_read(struct timechart *tchart, static int process_enter_write(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE, @@ -895,8 +890,8 @@ process_enter_write(struct timechart *tchart, static int process_exit_write(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_WRITE, @@ -905,8 +900,8 @@ process_exit_write(struct timechart *tchart, static int process_enter_sync(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC, @@ -915,8 +910,8 @@ process_enter_sync(struct timechart *tchart, static int process_exit_sync(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_SYNC, @@ -925,8 +920,8 @@ process_exit_sync(struct timechart *tchart, static int process_enter_tx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX, @@ -935,8 +930,8 @@ process_enter_tx(struct timechart *tchart, static int process_exit_tx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_TX, @@ -945,8 +940,8 @@ process_exit_tx(struct timechart *tchart, static int process_enter_rx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX, @@ -955,8 +950,8 @@ process_enter_rx(struct timechart *tchart, static int process_exit_rx(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_RX, @@ -965,8 +960,8 @@ process_exit_rx(struct timechart *tchart, static int process_enter_poll(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long fd = perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL, @@ -975,8 +970,8 @@ process_enter_poll(struct timechart *tchart, static int process_exit_poll(struct timechart *tchart, - struct evsel *evsel __maybe_unused, - struct perf_sample *sample) + struct perf_sample *sample, + const char *backtrace __maybe_unused) { long ret = perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_POLL, -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 21/25] perf trace: Don't pass evsel with sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (19 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 20/25] perf timechart: " Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 22/25] perf evlist: Try to avoid computing evsel from sample Ian Rogers ` (3 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. In trace__handle_event try to use the evsel from the sample to avoid recomputation. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-trace.c | 51 ++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 385a9ac2ae96..6fbdb5799e81 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2580,7 +2580,7 @@ static struct syscall *trace__find_syscall(struct trace *trace, int e_machine, i return sc; } -typedef int (*tracepoint_handler)(struct trace *trace, struct evsel *evsel, +typedef int (*tracepoint_handler)(struct trace *trace, union perf_event *event, struct perf_sample *sample); @@ -2775,10 +2775,11 @@ static void *syscall__augmented_args(struct syscall *sc, struct perf_sample *sam return NULL; } -static int trace__sys_enter(struct trace *trace, struct evsel *evsel, +static int trace__sys_enter(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; char *msg; void *args; int printed = 0; @@ -2921,10 +2922,11 @@ static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sam return sample__fprintf_callchain(sample, 38, print_opts, get_tls_callchain_cursor(), symbol_conf.bt_stop_list, trace->output); } -static int trace__sys_exit(struct trace *trace, struct evsel *evsel, +static int trace__sys_exit(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; long ret; u64 duration = 0; bool duration_calculated = false; @@ -3059,7 +3061,7 @@ errno_print: { return err; } -static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_unused, +static int trace__vfs_getname(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3120,7 +3122,7 @@ static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_u return 0; } -static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, +static int trace__sched_stat_runtime(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3142,7 +3144,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, out_dump: fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", - evsel->name, + sample->evsel->name, perf_sample__strval(sample, "comm"), (pid_t)perf_sample__intval(sample, "pid"), runtime, @@ -3253,10 +3255,11 @@ static size_t trace__fprintf_tp_fields(struct trace *trace, struct perf_sample * return fprintf(trace->output, "%.*s", (int)printed, bf); } -static int trace__event_handler(struct trace *trace, struct evsel *evsel, +static int trace__event_handler(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; struct thread *thread; int callchain_ret = 0; @@ -3362,7 +3365,6 @@ static void print_location(FILE *f, struct perf_sample *sample, } static int trace__pgfault(struct trace *trace, - struct evsel *evsel, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3391,7 +3393,7 @@ static int trace__pgfault(struct trace *trace, if (ttrace == NULL) goto out_put; - if (evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ) { + if (sample->evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ) { ttrace->pfmaj++; trace->pfmaj++; } else { @@ -3407,7 +3409,7 @@ static int trace__pgfault(struct trace *trace, trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output); fprintf(trace->output, "%sfault [", - evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ ? + sample->evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ ? "maj" : "min"); print_location(trace->output, sample, &al, false, true); @@ -3432,7 +3434,8 @@ static int trace__pgfault(struct trace *trace, if (callchain_ret > 0) trace__fprintf_callchain(trace, sample); else if (callchain_ret < 0) - pr_err("Problem processing %s callchain, skipping...\n", evsel__name(evsel)); + pr_err("Problem processing %s callchain, skipping...\n", + evsel__name(sample->evsel)); ++trace->nr_events_printed; out: @@ -3444,7 +3447,6 @@ static int trace__pgfault(struct trace *trace, } static void trace__set_base_time(struct trace *trace, - struct evsel *evsel, struct perf_sample *sample) { /* @@ -3456,7 +3458,7 @@ static void trace__set_base_time(struct trace *trace, * appears in our event stream (vfs_getname comes to mind). */ if (trace->base_time == 0 && !trace->full_time && - (evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) + (sample->evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) trace->base_time = sample->time; } @@ -3476,11 +3478,11 @@ static int trace__process_sample(const struct perf_tool *tool, if (thread && thread__is_filtered(thread)) goto out; - trace__set_base_time(trace, evsel, sample); + trace__set_base_time(trace, sample); if (handler) { ++trace->nr_events; - handler(trace, evsel, event, sample); + handler(trace, event, sample); } out: thread__put(thread); @@ -3622,32 +3624,33 @@ static void evlist__free_syscall_tp_fields(struct evlist *evlist) static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *sample) { const u32 type = event->header.type; - struct evsel *evsel; if (type != PERF_RECORD_SAMPLE) { trace__process_event(trace, trace->host, event, sample); return; } - evsel = evlist__id2evsel(trace->evlist, sample->id); - if (evsel == NULL) { + if (sample->evsel == NULL) + sample->evsel = evlist__id2evsel(trace->evlist, sample->id); + + if (sample->evsel == NULL) { fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id); return; } - if (evswitch__discard(&trace->evswitch, evsel)) + if (evswitch__discard(&trace->evswitch, sample->evsel)) return; - trace__set_base_time(trace, evsel, sample); + trace__set_base_time(trace, sample); - if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT && + if (sample->evsel->core.attr.type == PERF_TYPE_TRACEPOINT && sample->raw_data == NULL) { fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", - evsel__name(evsel), sample->tid, + evsel__name(sample->evsel), sample->tid, sample->cpu, sample->raw_size); } else { - tracepoint_handler handler = evsel->handler; - handler(trace, evsel, event, sample); + tracepoint_handler handler = sample->evsel->handler; + handler(trace, event, sample); } if (trace->nr_events_printed >= trace->max_events && trace->max_events != ULONG_MAX) -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 22/25] perf evlist: Try to avoid computing evsel from sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (20 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 21/25] perf trace: " Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 23/25] perf script: Don't pass evsel with sample Ian Rogers ` (2 subsequent siblings) 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan If the sample has an evsel, don't recompute using the sample.id. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-top.c | 4 +++- tools/perf/tests/mmap-basic.c | 4 +++- tools/perf/tests/switch-tracking.c | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index b89ca48e5d02..faa422e35166 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1163,7 +1163,9 @@ static int deliver_event(struct ordered_events *qe, goto next_event; } - evsel = evlist__id2evsel(session->evlist, sample.id); + evsel = sample.evsel; + if (!evsel) + evsel = evlist__id2evsel(session->evlist, sample.id); assert(evsel != NULL); if (event->header.type == PERF_RECORD_SAMPLE) { diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 3313c236104e..a18d84d858aa 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -142,7 +142,9 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtest } err = -1; - evsel = evlist__id2evsel(evlist, sample.id); + evsel = sample.evsel; + if (!evsel) + evsel = evlist__id2evsel(evlist, sample.id); perf_sample__exit(&sample); if (evsel == NULL) { pr_debug("event with id %" PRIu64 diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index 22b0302252db..e32331fee277 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -138,7 +138,10 @@ static int process_sample_event(struct evlist *evlist, goto out; } - evsel = evlist__id2evsel(evlist, sample.id); + evsel = sample.evsel; + if (!evsel) + evsel = evlist__id2evsel(evlist, sample.id); + if (evsel == switch_tracking->switch_evsel) { next_tid = perf_sample__intval(&sample, "next_pid"); prev_tid = perf_sample__intval(&sample, "prev_pid"); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 23/25] perf script: Don't pass evsel with sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (21 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 22/25] perf evlist: Try to avoid computing evsel from sample Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 24/25] perf s390-sample-raw: Don't pass evsel or its PMU " Ian Rogers 2026-03-20 19:26 ` [PATCH v4 25/25] perf evsel: Don't pass evsel " Ian Rogers 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and so it is unnecessary to pass the evsel as well. Remove the evsel from the struct scripting_context so that the sample version is always accessed. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/builtin-script.c | 12 ++++-- .../util/scripting-engines/trace-event-perl.c | 21 +++++------ .../scripting-engines/trace-event-python.c | 37 ++++++++----------- tools/perf/util/trace-event-scripting.c | 5 +-- tools/perf/util/trace-event.h | 3 -- 5 files changed, 33 insertions(+), 45 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8022801721e2..53da706d959f 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2418,12 +2418,13 @@ static bool show_event(struct perf_sample *sample, } static void process_event(struct perf_script *script, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al, struct machine *machine) { struct thread *thread = al->thread; + struct evsel *evsel = sample->evsel; struct perf_event_attr *attr = &evsel->core.attr; unsigned int type = evsel__output_type(evsel); struct evsel_script *es = evsel->priv; @@ -2714,9 +2715,9 @@ static int process_sample_event(const struct perf_tool *tool, thread__resolve(al.thread, &addr_al, sample); addr_al_ptr = &addr_al; } - scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr); + scripting_ops->process_event(event, sample, &al, addr_al_ptr); } else { - process_event(scr, sample, evsel, &al, &addr_al, machine); + process_event(scr, sample, &al, &addr_al, machine); } out_put: @@ -2892,9 +2893,12 @@ static int print_event_with_time(const struct perf_tool *tool, { struct perf_script *script = container_of(tool, struct perf_script, tool); struct perf_session *session = script->session; - struct evsel *evsel = evlist__id2evsel(session->evlist, sample->id); + struct evsel *evsel = sample->evsel; struct thread *thread = NULL; + if (!evsel) + evsel = evlist__id2evsel(session->evlist, sample->id); + if (evsel && !evsel->core.attr.sample_id_all) { sample->cpu = 0; sample->time = timestamp; diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index af0d514b2397..7a18ea4b7d50 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -257,7 +257,6 @@ static void define_event_symbols(struct tep_event *event, } static SV *perl_process_callchain(struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct addr_location *al) { struct callchain_cursor *cursor; @@ -340,7 +339,6 @@ static SV *perl_process_callchain(struct perf_sample *sample, } static void perl_process_tracepoint(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al) { struct thread *thread = al->thread; @@ -355,6 +353,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, unsigned long long nsecs = sample->time; const char *comm = thread__comm_str(thread); DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX); + struct evsel *evsel = sample->evsel; bitmap_zero(events_defined, TRACE_EVENT_TYPE_MAX); dSP; @@ -389,7 +388,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, XPUSHs(sv_2mortal(newSVuv(ns))); XPUSHs(sv_2mortal(newSViv(pid))); XPUSHs(sv_2mortal(newSVpv(comm, 0))); - XPUSHs(sv_2mortal(perl_process_callchain(sample, evsel, al))); + XPUSHs(sv_2mortal(perl_process_callchain(sample, al))); /* common fields other than pid can be accessed via xsub fns */ @@ -426,7 +425,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, XPUSHs(sv_2mortal(newSVuv(nsecs))); XPUSHs(sv_2mortal(newSViv(pid))); XPUSHs(sv_2mortal(newSVpv(comm, 0))); - XPUSHs(sv_2mortal(perl_process_callchain(sample, evsel, al))); + XPUSHs(sv_2mortal(perl_process_callchain(sample, al))); call_pv("main::trace_unhandled", G_SCALAR); } SPAGAIN; @@ -435,9 +434,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, LEAVE; } -static void perl_process_event_generic(union perf_event *event, - struct perf_sample *sample, - struct evsel *evsel) +static void perl_process_event_generic(union perf_event *event, struct perf_sample *sample) { dSP; @@ -448,7 +445,8 @@ static void perl_process_event_generic(union perf_event *event, SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVpvn((const char *)event, event->header.size))); - XPUSHs(sv_2mortal(newSVpvn((const char *)&evsel->core.attr, sizeof(evsel->core.attr)))); + XPUSHs(sv_2mortal(newSVpvn((const char *)&sample->evsel->core.attr, + sizeof(sample->evsel->core.attr)))); XPUSHs(sv_2mortal(newSVpvn((const char *)sample, sizeof(*sample)))); XPUSHs(sv_2mortal(newSVpvn((const char *)sample->raw_data, sample->raw_size))); PUTBACK; @@ -461,13 +459,12 @@ static void perl_process_event_generic(union perf_event *event, static void perl_process_event(union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { - scripting_context__update(scripting_context, event, sample, evsel, al, addr_al); - perl_process_tracepoint(sample, evsel, al); - perl_process_event_generic(event, sample, evsel); + scripting_context__update(scripting_context, event, sample, al, addr_al); + perl_process_tracepoint(sample, al); + perl_process_event_generic(event, sample); } static void run_start_sub(void) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 8de08cebe240..63d04b051846 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -390,7 +390,6 @@ static unsigned long get_offset(struct symbol *sym, struct addr_location *al) } static PyObject *python_process_callchain(struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct addr_location *al) { PyObject *pylist; @@ -651,11 +650,9 @@ static PyObject *get_sample_value_as_tuple(struct sample_read_value *value, return t; } -static void set_sample_read_in_dict(PyObject *dict_sample, - struct perf_sample *sample, - struct evsel *evsel) +static void set_sample_read_in_dict(PyObject *dict_sample, struct perf_sample *sample) { - u64 read_format = evsel->core.attr.read_format; + u64 read_format = sample->evsel->core.attr.read_format; PyObject *values; unsigned int i; @@ -741,11 +738,10 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, uint16_t e_machine, static int set_regs_in_dict(PyObject *dict, struct perf_sample *sample, - struct evsel *evsel, uint16_t e_machine, uint32_t e_flags) { - struct perf_event_attr *attr = &evsel->core.attr; + struct perf_event_attr *attr = &sample->evsel->core.attr; int size = (__sw_hweight64(attr->sample_regs_intr) * MAX_REG_SIZE) + 1; char *bf = NULL; @@ -831,7 +827,6 @@ static void python_process_sample_flags(struct perf_sample *sample, PyObject *di } static PyObject *get_perf_sample_dict(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al, PyObject *callchain) @@ -839,6 +834,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, PyObject *dict, *dict_sample, *brstack, *brstacksym; uint16_t e_machine = EM_HOST; uint32_t e_flags = EF_HOST; + struct evsel *evsel = sample->evsel; dict = PyDict_New(); if (!dict) @@ -871,7 +867,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, PyLong_FromUnsignedLongLong(sample->phys_addr)); pydict_set_item_string_decref(dict_sample, "addr", PyLong_FromUnsignedLongLong(sample->addr)); - set_sample_read_in_dict(dict_sample, sample, evsel); + set_sample_read_in_dict(dict_sample, sample); pydict_set_item_string_decref(dict_sample, "weight", PyLong_FromUnsignedLongLong(sample->weight)); pydict_set_item_string_decref(dict_sample, "ins_lat", @@ -928,7 +924,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, if (al->thread) e_machine = thread__e_machine(al->thread, /*machine=*/NULL, &e_flags); - if (set_regs_in_dict(dict, sample, evsel, e_machine, e_flags)) + if (set_regs_in_dict(dict, sample, e_machine, e_flags)) Py_FatalError("Failed to setting regs in dict"); return dict; @@ -936,7 +932,6 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, #ifdef HAVE_LIBTRACEEVENT static void python_process_tracepoint(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { @@ -954,6 +949,7 @@ static void python_process_tracepoint(struct perf_sample *sample, const char *comm = thread__comm_str(al->thread); const char *default_handler_name = "trace_unhandled"; DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX); + struct evsel *evsel = sample->evsel; bitmap_zero(events_defined, TRACE_EVENT_TYPE_MAX); @@ -995,7 +991,7 @@ static void python_process_tracepoint(struct perf_sample *sample, PyTuple_SetItem(t, n++, context); /* ip unwinding */ - callchain = python_process_callchain(sample, evsel, al); + callchain = python_process_callchain(sample, al); /* Need an additional reference for the perf_sample dict */ Py_INCREF(callchain); @@ -1051,7 +1047,7 @@ static void python_process_tracepoint(struct perf_sample *sample, PyTuple_SetItem(t, n++, dict); if (get_argument_count(handler) == (int) n + 1) { - all_entries_dict = get_perf_sample_dict(sample, evsel, al, addr_al, + all_entries_dict = get_perf_sample_dict(sample, al, addr_al, callchain); PyTuple_SetItem(t, n++, all_entries_dict); } else { @@ -1070,7 +1066,6 @@ static void python_process_tracepoint(struct perf_sample *sample, } #else static void python_process_tracepoint(struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct addr_location *al __maybe_unused, struct addr_location *addr_al __maybe_unused) { @@ -1465,7 +1460,6 @@ static int python_process_call_return(struct call_return *cr, u64 *parent_db_id, } static void python_process_general_event(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { @@ -1488,8 +1482,8 @@ static void python_process_general_event(struct perf_sample *sample, Py_FatalError("couldn't create Python tuple"); /* ip unwinding */ - callchain = python_process_callchain(sample, evsel, al); - dict = get_perf_sample_dict(sample, evsel, al, addr_al, callchain); + callchain = python_process_callchain(sample, al); + dict = get_perf_sample_dict(sample, al, addr_al, callchain); PyTuple_SetItem(t, n++, dict); if (_PyTuple_Resize(&t, n) == -1) @@ -1502,24 +1496,23 @@ static void python_process_general_event(struct perf_sample *sample, static void python_process_event(union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { struct tables *tables = &tables_global; - scripting_context__update(scripting_context, event, sample, evsel, al, addr_al); + scripting_context__update(scripting_context, event, sample, al, addr_al); - switch (evsel->core.attr.type) { + switch (sample->evsel->core.attr.type) { case PERF_TYPE_TRACEPOINT: - python_process_tracepoint(sample, evsel, al, addr_al); + python_process_tracepoint(sample, al, addr_al); break; /* Reserve for future process_hw/sw/raw APIs */ default: if (tables->db_export_mode) db_export__sample(&tables->dbe, event, sample, al, addr_al); else - python_process_general_event(sample, evsel, al, addr_al); + python_process_general_event(sample, al, addr_al); } } diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c index fa850e44cb46..dc584ac316a3 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -103,12 +103,11 @@ int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec) void scripting_context__update(struct scripting_context *c, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { #ifdef HAVE_LIBTRACEEVENT - const struct tep_event *tp_format = evsel__tp_format(evsel); + const struct tep_event *tp_format = evsel__tp_format(sample->evsel); c->pevent = tp_format ? tp_format->tep : NULL; #else @@ -117,7 +116,6 @@ void scripting_context__update(struct scripting_context *c, c->event_data = sample->raw_data; c->event = event; c->sample = sample; - c->evsel = evsel; c->al = al; c->addr_al = addr_al; } @@ -134,7 +132,6 @@ static int stop_script_unsupported(void) static void process_event_unsupported(union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct addr_location *al __maybe_unused, struct addr_location *addr_al __maybe_unused) { diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 914d9b69ed62..720121c74f1d 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -94,7 +94,6 @@ struct scripting_ops { int (*stop_script) (void); void (*process_event) (union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al); void (*process_switch)(union perf_event *event, @@ -124,7 +123,6 @@ struct scripting_context { void *event_data; union perf_event *event; struct perf_sample *sample; - struct evsel *evsel; struct addr_location *al; struct addr_location *addr_al; struct perf_session *session; @@ -133,7 +131,6 @@ struct scripting_context { void scripting_context__update(struct scripting_context *scripting_context, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al); -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 24/25] perf s390-sample-raw: Don't pass evsel or its PMU with sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (22 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 23/25] perf script: Don't pass evsel with sample Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 2026-03-20 19:26 ` [PATCH v4 25/25] perf evsel: Don't pass evsel " Ian Rogers 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan The sample contains the evsel and its PMU so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/s390-sample-raw.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c index c6ae0ae8d86a..52bbca5c56c8 100644 --- a/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -222,8 +222,9 @@ static char *get_counter_name(int set, int nr, struct perf_pmu *pmu) return result; } -static void s390_cpumcfdg_dump(struct perf_pmu *pmu, struct perf_sample *sample) +static void s390_cpumcfdg_dump(struct perf_sample *sample) { + struct perf_pmu *pmu = sample->evsel->pmu; size_t i, len = sample->raw_size, offset = 0; unsigned char *buf = sample->raw_data; const char *color = PERF_COLOR_BLUE; @@ -284,8 +285,9 @@ static bool s390_pai_all_test(struct perf_sample *sample) return true; } -static void s390_pai_all_dump(struct evsel *evsel, struct perf_sample *sample) +static void s390_pai_all_dump(struct perf_sample *sample) { + struct evsel *evsel = sample->evsel; size_t len = sample->raw_size, offset = 0; unsigned char *p = sample->raw_data; const char *color = PERF_COLOR_BLUE; @@ -332,31 +334,32 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, struct perf_sample *sample) { const char *pai_name; - struct evsel *evsel; if (event->header.type != PERF_RECORD_SAMPLE) return; - evsel = evlist__event2evsel(evlist, event); - if (!evsel) - return; + if (!sample->evsel) { + sample->evsel = evlist__event2evsel(evlist, event); + if (!sample->evsel) + return; + } /* Check for raw data in sample */ if (!sample->raw_size || !sample->raw_data) return; /* Display raw data on screen */ - if (evsel->core.attr.config == PERF_EVENT_CPUM_CF_DIAG) { - if (!evsel->pmu) - evsel->pmu = perf_pmus__find("cpum_cf"); + if (sample->evsel->core.attr.config == PERF_EVENT_CPUM_CF_DIAG) { + if (!sample->evsel->pmu) + sample->evsel->pmu = perf_pmus__find("cpum_cf"); if (!s390_cpumcfdg_testctr(sample)) pr_err("Invalid counter set data encountered\n"); else - s390_cpumcfdg_dump(evsel->pmu, sample); + s390_cpumcfdg_dump(sample); return; } - switch (evsel->core.attr.config) { + switch (sample->evsel->core.attr.config) { case PERF_EVENT_PAI_NNPA_ALL: pai_name = "NNPA_ALL"; break; @@ -370,8 +373,8 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, if (!s390_pai_all_test(sample)) { pr_err("Invalid %s raw data encountered\n", pai_name); } else { - if (!evsel->pmu) - evsel->pmu = perf_pmus__find_by_type(evsel->core.attr.type); - s390_pai_all_dump(evsel, sample); + if (!sample->evsel->pmu) + sample->evsel->pmu = perf_pmus__find_by_type(sample->evsel->core.attr.type); + s390_pai_all_dump(sample); } } -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
* [PATCH v4 25/25] perf evsel: Don't pass evsel with sample 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers ` (23 preceding siblings ...) 2026-03-20 19:26 ` [PATCH v4 24/25] perf s390-sample-raw: Don't pass evsel or its PMU " Ian Rogers @ 2026-03-20 19:26 ` Ian Rogers 24 siblings, 0 replies; 112+ messages in thread From: Ian Rogers @ 2026-03-20 19:26 UTC (permalink / raw) To: namhyung Cc: irogers, acme, adrian.hunter, ajones, ak, alex, alexander.shishkin, anup, aou, atrajeev, blakejones, ctshao, dapeng1.mi, derek.foreman, dvyukov, howardchu95, hrishikesh123s, james.clark, jolsa, krzysztof.m.lopatowski, leo.yan, linux-kernel, linux-perf-users, linux, mingo, nichen, palmer, peterz, pjw, ravi.bangoria, swapnil.sapkal, tanze, thomas.falcon, tianyou.li, yujie.liu, zhouquan Arrange for the sample to contain the evsel and so it is unnecessary to pass the evsel as well. This is done for uniformity, although parsing of the sample is arguably a special case. Add missing bound check in perf_evsel__parse_id_sample. Signed-off-by: Ian Rogers <irogers@google.com> --- tools/perf/util/evsel.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index a4fe37f2a276..1085bcf3b54b 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2997,24 +2997,29 @@ 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; + const __u64 *array, *array_begin = event->sample.array; bool swapped = evsel->needs_swap; union u64_swap u; - array += ((event->header.size - - sizeof(event->header)) / sizeof(u64)) - 1; + array = array_begin + ((event->header.size - sizeof(event->header)) / sizeof(u64)) - 1; if (type & PERF_SAMPLE_IDENTIFIER) { + if (array < array_begin) + return -EFAULT; + sample->id = *array; array--; } if (type & PERF_SAMPLE_CPU) { + if (array < array_begin) + return -EFAULT; + u.val64 = *array; if (swapped) { /* undo swap of u64, then swap on individual u32s */ @@ -3027,21 +3032,33 @@ static int perf_evsel__parse_id_sample(const struct evsel *evsel, } if (type & PERF_SAMPLE_STREAM_ID) { + if (array < array_begin) + return -EFAULT; + sample->stream_id = *array; array--; } if (type & PERF_SAMPLE_ID) { + if (array < array_begin) + return -EFAULT; + sample->id = *array; array--; } if (type & PERF_SAMPLE_TIME) { + if (array < array_begin) + return -EFAULT; + sample->time = *array; array--; } if (type & PERF_SAMPLE_TID) { + if (array < array_begin) + return -EFAULT; + u.val64 = *array; if (swapped) { /* undo swap of u64, then swap on individual u32s */ @@ -3239,14 +3256,14 @@ 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); + perf_evsel__parse_id_sample(event, data); return 0; } if (event->header.type != PERF_RECORD_SAMPLE) { if (evsel->core.attr.sample_id_all) - perf_evsel__parse_id_sample(evsel, event, data); + perf_evsel__parse_id_sample(event, data); return 0; } @@ -3608,12 +3625,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; -- 2.53.0.959.g497ff81fa9-goog ^ permalink raw reply related [flat|nested] 112+ messages in thread
end of thread, other threads:[~2026-03-20 19:29 UTC | newest] Thread overview: 112+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-02-09 17:40 [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 01/25] perf sample: Document struct perf_sample Ian Rogers 2026-03-03 3:07 ` Namhyung Kim 2026-03-20 4:41 ` Ian Rogers 2026-02-09 17:40 ` [PATCH v1 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers 2026-03-03 22:38 ` Namhyung Kim 2026-02-09 17:40 ` [PATCH v1 03/25] perf sample: Add evsel to struct perf_sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 04/25] perf tool: Remove evsel from tool APIs that pass the sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 05/25] perf kvm: Don't pass evsel with sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval Ian Rogers 2026-02-09 17:40 ` [PATCH v1 07/25] perf trace: Don't pass evsel with sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 08/25] perf callchain: Don't pass evsel and sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 09/25] perf lock: Only pass sample to handlers Ian Rogers 2026-02-09 17:40 ` [PATCH v1 10/25] perf lock: Constify trace_lock_handler variables Ian Rogers 2026-02-09 17:40 ` [PATCH v1 11/25] perf hist: Remove evsel parameter from inc samples functions Ian Rogers 2026-02-09 17:40 ` [PATCH v1 12/25] perf db-export: Remove evsel from struct export_sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 13/25] perf hist: Remove evsel from struct hist_entry_iter Ian Rogers 2026-02-09 17:40 ` [PATCH v1 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id Ian Rogers 2026-02-09 17:40 ` [PATCH v1 15/25] perf annotate: Don't pass evsel to add_sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 16/25] perf inject: Don't pass evsel with sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 17/25] perf kmem: " Ian Rogers 2026-02-09 17:40 ` [PATCH v1 18/25] perf kwork: " Ian Rogers 2026-02-09 17:40 ` [PATCH v1 19/25] perf sched: " Ian Rogers 2026-02-09 17:40 ` [PATCH v1 20/25] perf timechart: " Ian Rogers 2026-02-09 17:40 ` [PATCH v1 21/25] perf trace: " Ian Rogers 2026-02-09 17:40 ` [PATCH v1 22/25] perf evlist: Try to avoid computing evsel from sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 23/25] perf script: Don't pass evsel with sample Ian Rogers 2026-02-09 17:40 ` [PATCH v1 24/25] perf s390-sample-raw: " Ian Rogers 2026-02-09 17:40 ` [PATCH v1 25/25] perf evsel: " Ian Rogers 2026-02-23 19:15 ` [PATCH v1 00/25] perf tool: Add evsel to perf_sample Ian Rogers 2026-03-02 17:56 ` Ian Rogers 2026-03-03 1:15 ` Namhyung Kim 2026-03-04 1:02 ` Namhyung Kim 2026-03-04 16:19 ` Ian Rogers 2026-03-19 23:23 ` [PATCH v2 " Ian Rogers 2026-03-19 23:23 ` [PATCH v2 01/25] perf sample: Document struct perf_sample Ian Rogers 2026-03-19 23:23 ` [PATCH v2 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers 2026-03-19 23:23 ` [PATCH v2 03/25] perf sample: Add evsel to struct perf_sample Ian Rogers 2026-03-19 23:23 ` [PATCH v2 04/25] perf tool: Remove evsel from tool APIs that pass the sample Ian Rogers 2026-03-19 23:23 ` [PATCH v2 05/25] perf kvm: Don't pass evsel with sample Ian Rogers 2026-03-19 23:23 ` [PATCH v2 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval Ian Rogers 2026-03-19 23:23 ` [PATCH v2 07/25] perf trace: Don't pass evsel with sample Ian Rogers 2026-03-19 23:23 ` [PATCH v2 08/25] perf callchain: Don't pass evsel and sample Ian Rogers 2026-03-19 23:23 ` [PATCH v2 09/25] perf lock: Only pass sample to handlers Ian Rogers 2026-03-19 23:23 ` [PATCH v2 10/25] perf lock: Constify trace_lock_handler variables Ian Rogers 2026-03-19 23:23 ` [PATCH v2 11/25] perf hist: Remove evsel parameter from inc samples functions Ian Rogers 2026-03-19 23:23 ` [PATCH v2 12/25] perf db-export: Remove evsel from struct export_sample Ian Rogers 2026-03-19 23:23 ` [PATCH v2 13/25] perf hist: Remove evsel from struct hist_entry_iter Ian Rogers 2026-03-19 23:23 ` [PATCH v2 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id Ian Rogers 2026-03-19 23:23 ` [PATCH v2 15/25] perf annotate: Don't pass evsel to add_sample Ian Rogers 2026-03-19 23:23 ` [PATCH v2 16/25] perf inject: Don't pass evsel with sample Ian Rogers 2026-03-19 23:23 ` [PATCH v2 17/25] perf kmem: " Ian Rogers 2026-03-19 23:23 ` [PATCH v2 18/25] perf kwork: " Ian Rogers 2026-03-19 23:23 ` [PATCH v2 19/25] perf sched: " Ian Rogers 2026-03-19 23:23 ` [PATCH v2 20/25] perf timechart: " Ian Rogers 2026-03-19 23:23 ` [PATCH v2 21/25] perf trace: " Ian Rogers 2026-03-19 23:23 ` [PATCH v2 22/25] perf evlist: Try to avoid computing evsel from sample Ian Rogers 2026-03-19 23:23 ` [PATCH v2 23/25] perf script: Don't pass evsel with sample Ian Rogers 2026-03-19 23:23 ` [PATCH v2 24/25] perf s390-sample-raw: " Ian Rogers 2026-03-19 23:23 ` [PATCH v2 25/25] perf evsel: " Ian Rogers 2026-03-20 8:08 ` [PATCH v3 00/25] perf tool: Add evsel to perf_sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 01/25] perf sample: Document struct perf_sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers 2026-03-20 8:08 ` [PATCH v3 03/25] perf sample: Add evsel to struct perf_sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 04/25] perf tool: Remove evsel from tool APIs that pass the sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 05/25] perf kvm: Don't pass evsel with sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval Ian Rogers 2026-03-20 8:08 ` [PATCH v3 07/25] perf trace: Don't pass evsel with sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 08/25] perf callchain: Don't pass evsel and sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 09/25] perf lock: Only pass sample to handlers Ian Rogers 2026-03-20 8:08 ` [PATCH v3 10/25] perf lock: Constify trace_lock_handler variables Ian Rogers 2026-03-20 8:08 ` [PATCH v3 11/25] perf hist: Remove evsel parameter from inc samples functions Ian Rogers 2026-03-20 8:08 ` [PATCH v3 12/25] perf db-export: Remove evsel from struct export_sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 13/25] perf hist: Remove evsel from struct hist_entry_iter Ian Rogers 2026-03-20 8:08 ` [PATCH v3 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id Ian Rogers 2026-03-20 8:08 ` [PATCH v3 15/25] perf annotate: Don't pass evsel to add_sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 16/25] perf inject: Don't pass evsel with sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 17/25] perf kmem: " Ian Rogers 2026-03-20 8:08 ` [PATCH v3 18/25] perf kwork: " Ian Rogers 2026-03-20 8:08 ` [PATCH v3 19/25] perf sched: " Ian Rogers 2026-03-20 8:08 ` [PATCH v3 20/25] perf timechart: " Ian Rogers 2026-03-20 8:08 ` [PATCH v3 21/25] perf trace: " Ian Rogers 2026-03-20 8:08 ` [PATCH v3 22/25] perf evlist: Try to avoid computing evsel from sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 23/25] perf script: Don't pass evsel with sample Ian Rogers 2026-03-20 8:08 ` [PATCH v3 24/25] perf s390-sample-raw: " Ian Rogers 2026-03-20 8:08 ` [PATCH v3 25/25] perf evsel: " Ian Rogers 2026-03-20 19:26 ` [PATCH v4 00/25] perf tool: Add evsel to perf_sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 01/25] perf sample: Document struct perf_sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 02/25] perf sample: Make sure perf_sample__init/exit are used Ian Rogers 2026-03-20 19:26 ` [PATCH v4 03/25] perf sample: Add evsel to struct perf_sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 04/25] perf tool: Remove evsel from tool APIs that pass the sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 05/25] perf kvm: Don't pass evsel with sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 06/25] perf evsel: Refactor evsel__intval to perf_sample__intval Ian Rogers 2026-03-20 19:26 ` [PATCH v4 07/25] perf trace: Don't pass evsel with sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 08/25] perf callchain: Don't pass evsel and sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 09/25] perf lock: Only pass sample to handlers Ian Rogers 2026-03-20 19:26 ` [PATCH v4 10/25] perf lock: Constify trace_lock_handler variables Ian Rogers 2026-03-20 19:26 ` [PATCH v4 11/25] perf hist: Remove evsel parameter from inc samples functions Ian Rogers 2026-03-20 19:26 ` [PATCH v4 12/25] perf db-export: Remove evsel from struct export_sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 13/25] perf hist: Remove evsel from struct hist_entry_iter Ian Rogers 2026-03-20 19:26 ` [PATCH v4 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id Ian Rogers 2026-03-20 19:26 ` [PATCH v4 15/25] perf annotate: Don't pass evsel to add_sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 16/25] perf inject: Don't pass evsel with sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 17/25] perf kmem: " Ian Rogers 2026-03-20 19:26 ` [PATCH v4 18/25] perf kwork: " Ian Rogers 2026-03-20 19:26 ` [PATCH v4 19/25] perf sched: " Ian Rogers 2026-03-20 19:26 ` [PATCH v4 20/25] perf timechart: " Ian Rogers 2026-03-20 19:26 ` [PATCH v4 21/25] perf trace: " Ian Rogers 2026-03-20 19:26 ` [PATCH v4 22/25] perf evlist: Try to avoid computing evsel from sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 23/25] perf script: Don't pass evsel with sample Ian Rogers 2026-03-20 19:26 ` [PATCH v4 24/25] perf s390-sample-raw: Don't pass evsel or its PMU " Ian Rogers 2026-03-20 19:26 ` [PATCH v4 25/25] perf evsel: Don't pass evsel " Ian Rogers
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox