perf tool: Add evsel to perf_sample
Subsystems (2)
Ian Rogers
reviewerPATCH v14 3/32 perf evsel: Refactor evsel tracepoint sample accessors perf_sample
In reply to Ian RogersThe evsel argument to evsel__intval, evsel__rawptr, 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.
--- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 34 +++---- 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(+), 189 deletions(-)
tools/perf/builtin-inject.c +1 -1
@@ -1083,7 +1083,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) {
tools/perf/builtin-kmem.c +17 -17
@@ -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 *sint 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;
@@ -822,9 +821,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 +876,11 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sampreturn 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 +888,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;
tools/perf/builtin-kvm.c +1 -1
@@ -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); }
tools/perf/builtin-kwork.c +14 -15
@@ -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" )); } }
tools/perf/builtin-lock.c +16 -16
@@ -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;
tools/perf/builtin-sched.c +45 -47
256 lines not on this page · raw message
tools/perf/builtin-timechart.c +44 -44
238 lines not on this page · raw message
tools/perf/builtin-trace.c +6 -6
@@ -3094,7 +3094,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) {
@@ -3103,7 +3103,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__strval (sample,"pathname" );if (!thread) goto out;
@@ -3159,7 +3159,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,
@@ -3178,10 +3178,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; }
tools/perf/tests/openat-syscall-tp-fields.c +1 -1
@@ -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);/* C library wrapper may set additional flags, access mode must be unchanged */
tools/perf/tests/switch-tracking.c +2 -2
@@ -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);
tools/perf/util/evsel.c +11 -11
@@ -3687,9 +3687,9 @@ struct tep_format_field *evsel__common_field(struct evsel *evsel, const char *nareturn 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)
@@ -3746,21 +3746,21 @@ u64 format_field__intval(struct tep_format_field *field, struct perf_sample *samreturn 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;
@@ -3769,7 +3769,7 @@ char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const chaunsigned int bit;char state ='?' ;/* '?' denotes unknown task state */ - field =evsel__field (evsel, name); + field =evsel__field (sample->evsel, name);if (!field)return state;
@@ -3788,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;
tools/perf/util/evsel.h +6 -6
@@ -371,14 +371,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
tools/perf/util/intel-pt.c +1 -1
@@ -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",
tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c +2 -4
@@ -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; } }
tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c +1 -1
@@ -78,7 +78,7 @@ static void event_gspr_get_key(struct perf_sample *sample, struct event_key *keyunsigned 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 :
tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c +1 -1
@@ -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)
tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c +1 -2
@@ -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; }
tools/perf/util/kvm-stat-arch/kvm-stat-s390.c +4 -4
@@ -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; }
tools/perf/util/kvm-stat-arch/kvm-stat-x86.c +8 -8
@@ -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)
tools/perf/util/kvm-stat.c +1 -1
@@ -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)); }
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 4/32 perf trace: Don't pass evsel with sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from trace-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- tools/perf/builtin-trace.c | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-)
tools/perf/builtin-trace.c +28 -27
@@ -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)
@@ -2749,8 +2749,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 ;
@@ -2758,7 +2758,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); }
@@ -2813,7 +2813,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;
@@ -2828,9 +2828,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);
@@ -2888,12 +2888,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 ;
@@ -2903,7 +2902,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);
@@ -2914,7 +2913,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);
@@ -2924,10 +2923,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 :
@@ -2962,7 +2962,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;
@@ -2976,9 +2976,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);
@@ -3000,7 +3000,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;
@@ -3217,9 +3217,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);
@@ -3302,7 +3303,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;
@@ -3323,7 +3324,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 ;
@@ -3331,7 +3332,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; }
@@ -3351,13 +3352,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 ); } } }
@@ -3416,7 +3417,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;
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 5/32 perf callchain: Don't pass evsel and sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from callchain-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- 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 | 6 ++--- 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(+), 57 deletions(-)
tools/perf/builtin-c2c.c +1 -1
@@ -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;
tools/perf/builtin-inject.c +2 -2
@@ -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);
@@ -1019,7 +1019,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:
tools/perf/builtin-kmem.c +3 -3
@@ -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) {
@@ -838,7 +838,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sampif (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
tools/perf/builtin-kwork.c +2 -3
@@ -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 ; }
tools/perf/builtin-lock.c +12 -12
@@ -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 *samplreturn -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;
tools/perf/builtin-sched.c +2 -3
@@ -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;
tools/perf/builtin-script.c +3 -3
@@ -1684,7 +1684,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 ;
@@ -2507,7 +2507,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 ;
@@ -2792,7 +2792,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" );
tools/perf/builtin-trace.c +1 -1
@@ -2938,7 +2938,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;
tools/perf/util/build-id.c +1 -1
@@ -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 );
tools/perf/util/callchain.c +4 -4
@@ -1170,7 +1170,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)
@@ -1178,7 +1178,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 ;
@@ -1853,7 +1853,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) {
@@ -1864,7 +1864,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)
tools/perf/util/callchain.h +2 -4
@@ -8,11 +8,9 @@#include "branch.h" struct addr_location ; -struct evsel ;struct hist_entry ;struct hists ;struct ip_callchain ; -struct map ;struct perf_sample ;struct record_opts ;struct thread ;
@@ -245,7 +243,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,
@@ -306,7 +304,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);
tools/perf/util/db-export.c +3 -5
@@ -208,8 +208,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;
@@ -227,7 +226,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;
@@ -390,8 +389,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;
tools/perf/util/hist.c +1 -1
@@ -1342,7 +1342,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;
tools/perf/util/machine.c +7 -7
@@ -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); }
tools/perf/util/machine.h +0 -3
@@ -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,
tools/perf/util/scripting-engines/trace-event-perl.c +2 -2
@@ -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;
tools/perf/util/scripting-engines/trace-event-python.c +2 -2
@@ -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" );
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 6/32 perf lock: Only pass sample to handlers
In reply to Ian RogersThe evsel is within the sample and so only the sample needs to be passed. Remove the parameter and fix call site.
--- tools/perf/builtin-lock.c | 65 ++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 39 deletions(-)
tools/perf/builtin-lock.c +26 -39
@@ -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_unusedreturn 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);
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 7/32 perf hist: Remove evsel parameter from inc samples functions
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from hist-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- 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(-)
tools/perf/builtin-annotate.c +3 -4
@@ -176,16 +176,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;
@@ -275,7 +274,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; }
tools/perf/builtin-c2c.c +1 -1
@@ -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);
tools/perf/builtin-report.c +8 -10
@@ -171,7 +171,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;
@@ -181,25 +180,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:
@@ -215,7 +214,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,
@@ -224,11 +222,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;
tools/perf/builtin-top.c +3 -3
@@ -199,7 +199,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;
@@ -216,7 +216,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);
@@ -735,7 +735,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),
tools/perf/util/annotate.c +9 -10
@@ -213,9 +213,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;
@@ -318,7 +319,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;
@@ -326,8 +327,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,
@@ -581,16 +582,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); }
tools/perf/util/annotate.h +2 -4
@@ -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);
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 8/32 perf db-export: Remove evsel from struct export_sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from db-export-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- 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(-)
tools/perf/util/db-export.c +2 -3
@@ -344,14 +344,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;
@@ -364,7 +363,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;
tools/perf/util/db-export.h +1 -2
@@ -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);
tools/perf/util/scripting-engines/trace-event-python.c +4 -4
@@ -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); }
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 9/32 perf hist: Remove evsel from struct hist_entry_iter
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from hist-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- 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(-)
tools/perf/builtin-annotate.c +4 -6
@@ -190,14 +190,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,
@@ -220,8 +218,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:
@@ -268,7 +266,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 )
tools/perf/builtin-diff.c +1 -2
@@ -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 :
tools/perf/builtin-report.c +2 -4
@@ -266,10 +266,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,
@@ -281,7 +279,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);
@@ -325,7 +323,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++;
tools/perf/builtin-top.c +3 -6
@@ -732,20 +732,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) {
@@ -831,9 +829,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, };
@@ -1211,7 +1208,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);
tools/perf/tests/hists_cumulate.c +0 -1
@@ -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, };
tools/perf/tests/hists_filter.c +0 -1
@@ -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,
tools/perf/tests/hists_output.c +0 -1
@@ -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,
tools/perf/util/hist.c +12 -12
@@ -935,8 +935,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 )
@@ -968,7 +968,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 ;
@@ -1036,9 +1036,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 ;
@@ -1078,7 +1078,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++)
@@ -1103,8 +1103,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,
@@ -1121,8 +1121,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 ;
@@ -1165,9 +1165,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 ;
@@ -1224,8 +1224,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 = {
@@ -2826,7 +2826,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);
@@ -2850,7 +2850,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;
tools/perf/util/hist.h +1 -2
@@ -156,7 +156,6 @@ struct hist_entry_iter {int total;int curr; -struct evsel *evsel;struct perf_sample *sample;struct hist_entry *he;struct symbol *parent;
@@ -799,7 +798,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);
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 10/32 perf report: Directly use sample->evsel to avoid computing from sample->id
In reply to Ian RogersIn count_lost_samples_events try to avoid searching for the evsel for the sample, just use the variable within the sample.
--- tools/perf/builtin-report.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/builtin-report.c +4 -2
@@ -789,9 +789,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;
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 11/32 perf annotate: Don't pass evsel to add_sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from annotate-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- tools/perf/builtin-annotate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
tools/perf/builtin-annotate.c +5 -5
@@ -232,11 +232,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;
@@ -298,7 +298,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 ;
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 12/32 perf inject: Don't pass evsel with sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from inject-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- tools/perf/builtin-inject.c | 52 ++++++++++++++++-------------- tools/perf/util/synthetic-events.c | 30 ++++++++--------- tools/perf/util/synthetic-events.h | 2 -- 3 files changed, 40 insertions(+), 44 deletions(-)
tools/perf/builtin-inject.c +27 -25
@@ -147,14 +147,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);
@@ -585,11 +582,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); }
@@ -616,23 +614,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 )
@@ -837,7 +838,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)
@@ -861,7 +861,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);
@@ -874,7 +874,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,
@@ -897,7 +896,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),
@@ -914,7 +912,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;
@@ -942,9 +940,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 ) {
@@ -952,11 +954,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),
@@ -966,6 +970,7 @@ static int mark_dso_hit(const struct perf_inject *inject,map__prot (map),map__flags (map), filename); + sample->evsel = saved_evsel; } }return 0 ;
@@ -976,7 +981,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)
@@ -1031,7 +1036,6 @@ static int perf_event__inject_buildid(const struct perf_tool *tool, union perf_estatic 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);
@@ -1051,13 +1055,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 ) {
@@ -1076,13 +1079,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;
@@ -1447,7 +1450,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)); }
@@ -2009,7 +2012,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 ;
tools/perf/util/synthetic-events.c +13 -17
@@ -2252,13 +2252,15 @@ 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) { union perf_event ev;size_t len; +u64 sample_type = sample->evsel ? sample->evsel->core.attr.sample_type :0 ; +void *array = &ev; +int ret; len =sizeof (ev.build_id) +strlen (filename) +1 ; len =PERF_ALIGN (len,sizeof (u64));
@@ -2275,23 +2277,17 @@ 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) { -void *array = &ev; -int ret; - - array += ev.header.size; - ret =perf_event__synthesize_id_sample (array, evsel->core.attr.sample_type, sample); -if (ret <0 ) -return ret; - -if (ret &7 ) { -pr_err ("Bad id sample size %d\n" , ret); -return -EINVAL ; - } + array += ev.header.size; + ret =perf_event__synthesize_id_sample (array, sample_type, sample); +if (ret <0 ) +return ret; - ev.header.size += ret; +if (ret &7 ) { +pr_err ("Bad id sample size %d\n" , ret); +return -EINVAL ; } + ev.header.size += ret;return process (tool, &ev, sample, machine); }
@@ -2299,7 +2295,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,
@@ -2309,6 +2304,7 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, {union perf_event ev;size_t ev_len; +u64 sample_type = sample->evsel ? sample->evsel->core.attr.sample_type :0 ;void *array;int ret;
@@ -2339,7 +2335,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_type, sample);if (ret <0 )return ret;
tools/perf/util/synthetic-events.h +0 -2
@@ -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,
Signature · 1 line
2.54.0.746.g67dd491aae-goog
[email protected]
AI reviewRe: [PATCH v14 12/32] perf inject: Don't pass evsel with sample
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Buffer overflow and event corruption in perf_event__synthesize_mmap2_build_id() due to a typo when capping build_id_size. --
commit 2cd2e94f594b8a44bc5330a9f9007347d463ab0e
Author: Ian Rogers <[email protected]>
perf inject: Don't pass evsel with sample
As struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface. Remove the redundant evsel parameter from inject-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample.
Quoted 4 lines
tools/perf/util/synthetic-events.c +0
-0
[ ... ]
tools/perf/util/synthetic-events.c int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, · line 2309
Quoted 7 lines
tools/perf/util/synthetic-events.c +1
-0@@ -2309,6 +2304,7 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, {union perf_event ev;size_t ev_len; +u64 sample_type = sample->evsel ? sample->evsel->core.attr.sample_type :0 ;void *array;int ret;
[Severity: High]
This is a pre-existing issue, but while reviewing this function, I noticed a buffer overflow in the build ID capping logic further down in the function.
When capping the build ID size, the code assigns the capped size to ev.build_id.size instead of ev.mmap2.build_id_size:
ev.mmap2.build_id_size = bid->size; if (ev.mmap2.build_id_size > sizeof(ev.mmap2.build_id)) ev.build_id.size = sizeof(ev.mmap2.build_id); memcpy(ev.mmap2.build_id, bid->data, ev.mmap2.build_id_size);
Because ev.mmap2.build_id_size remains untouched, the subsequent memcpy() can write past the end of the ev.mmap2.build_id array on the stack.
Does this typo allow for a stack buffer overflow when processing crafted perf.data files or ELF notes with arbitrarily large build IDs?
I understand this is fixed later in the patch series by the commit "perf
synthetic-events: Bound check when synthesizing mmap2 and build_id events".
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Ian Rogers
reviewerPATCH v14 13/32 perf kmem: Don't pass evsel with sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from kmem-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- tools/perf/builtin-kmem.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
tools/perf/builtin-kmem.c +12 -14
@@ -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" );
@@ -835,7 +834,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sampreturn 0 ; } -if (parse_gfp_flags (evsel, sample, gfp_flags) <0 ) +if (parse_gfp_flags (sample, gfp_flags) <0 )return -1 ; callsite =find_callsite (sample);
@@ -876,8 +875,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sampreturn 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" );
@@ -954,8 +952,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,
@@ -973,14 +970,15 @@ 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)) {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);
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 14/32 perf kwork: Don't pass evsel with sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from kwork-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- tools/perf/builtin-kwork.c | 74 +++++++++++++------------------------- tools/perf/util/kwork.h | 9 +++-- 2 files changed, 28 insertions(+), 55 deletions(-)
tools/perf/builtin-kwork.c +24 -50
@@ -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;
tools/perf/util/kwork.h +4 -5
@@ -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); };
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 15/32 perf sched: Don't pass evsel with sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from sched-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- tools/perf/builtin-sched.c | 92 ++++++++++++++------------------------ 1 file changed, 34 insertions(+), 58 deletions(-)
tools/perf/builtin-sched.c +34 -58
@@ -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_unustatic 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;
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 16/32 perf timechart: Don't pass evsel with sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from timechart-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- tools/perf/builtin-timechart.c | 60 +++++++++++++++------------------- 1 file changed, 26 insertions(+), 34 deletions(-)
tools/perf/builtin-timechart.c +26 -34
@@ -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,8 +587,8 @@ 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)); + +return f (tchart, sample,cat_backtrace (event, sample, machine)); }return 0 ;
@@ -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,8 +841,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,
@@ -859,8 +851,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,
@@ -869,8 +861,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,
@@ -879,8 +871,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,
@@ -889,8 +881,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,
@@ -899,8 +891,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,
@@ -909,8 +901,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,
@@ -919,8 +911,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,
@@ -929,8 +921,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,
@@ -939,8 +931,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,
@@ -949,8 +941,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,
@@ -959,8 +951,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,
Signature · 1 line
2.54.0.746.g67dd491aae-goog
[email protected]
AI reviewRe: [PATCH v14 16/32] perf timechart: Don't pass evsel with sample
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Freeing the memstream buffer before calling fclose() causes use-after-free and heap corruption. --
commit e026d352d2888e166740c26a9158bb9831a672e5
Author: Ian Rogers <[email protected]>
perf timechart: Don't pass evsel with sample
This commit removes the redundant evsel parameter from timechart-specific handlers and structures. Since the perf_sample struct now contains its own resolved evsel pointer, the tool can directly access it, simplifying the API and eliminating the risk of passing inconsistent evsels.
tools/perf/builtin-timechart.c static const char *cat_backtrace(union perf_event *event, · line 567
Quoted 6 lines
tools/perf/builtin-timechart.c +0
-0@@ -567,7 +567,6 @@ static const char *cat_backtrace(union perf_event *event, }
[Severity: High]
This is a pre-existing issue, but can this cause a use-after-free and heap corruption when the callchain context is invalid?
Looking at cat_backtrace() earlier in this file, if an invalid callchain context is encountered, the code directly frees the stream's internal buffer:
zfree(&p);
goto exit;And at the exit label, it calls:
exit:
...
fclose(f);In the open_memstream implementation, the buffer pointer p is allocated and assigned upon stream initialization. Freeing it before calling fclose() means fclose() will attempt to flush the stream and write a terminating null byte to the internal buffer, which has already been freed.
Could this write-after-free corrupt the heap? Should the buffer be freed after the stream is closed?
Quoted 5 lines
tools/perf/builtin-timechart.c +0
-1typedef int (*tracepoint_handler )(struct timechart *tchart, -struct evsel *evsel,struct perf_sample *sample,const char *backtrace);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
Ian Rogers
reviewerPATCH v14 17/32 perf trace: Don't pass evsel with sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from trace-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- tools/perf/builtin-trace.c | 52 ++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 24 deletions(-)
tools/perf/builtin-trace.c +28 -24
@@ -2608,7 +2608,7 @@ static struct syscall *trace__find_syscall(struct trace *trace, int e_machine, ireturn 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);
@@ -2805,10 +2805,11 @@ static void *syscall__augmented_args(struct syscall *sc, struct perf_sample *samreturn 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 ;
@@ -2954,10 +2955,11 @@ static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *samreturn 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;
@@ -3094,7 +3096,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) {
@@ -3155,7 +3157,7 @@ static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __maybe_ureturn 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) {
@@ -3177,7 +3179,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,
@@ -3288,10 +3290,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 ;
@@ -3400,7 +3403,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) {
@@ -3429,7 +3431,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 {
@@ -3446,7 +3448,7 @@ static int trace__pgfault(struct trace *trace, sample->cpu, 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);
@@ -3471,7 +3473,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:
@@ -3483,7 +3486,6 @@ static int trace__pgfault(struct trace *trace, }static void trace__set_base_time (struct trace *trace, -struct evsel *evsel,struct perf_sample *sample) {/*
@@ -3495,7 +3497,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; }
@@ -3515,11 +3517,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);
@@ -3661,32 +3663,34 @@ 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 )
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 18/32 perf evlist: Try to avoid computing evsel from sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from evlist-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- 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(-)
tools/perf/builtin-top.c +3 -1
@@ -1164,7 +1164,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 ) {
tools/perf/tests/mmap-basic.c +3 -1
@@ -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
tools/perf/tests/switch-tracking.c +4 -1
@@ -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" );
Signature · 1 line
2.54.0.746.g67dd491aae-goog
[email protected]
AI reviewRe: [PATCH v14 18/32] perf evlist: Try to avoid computing evsel from sample
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The commit message claims to 'Remove the redundant evsel parameter from evlist-specific handlers…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message claims to 'Remove the redundant evsel parameter from evlist-specific handlers and structures... simplif[ying] the API signatures', but the provided patch does not remove any evsel parameters or change any function signatures. It only updates local variable assignments in three files to opportunistically use sample.evsel. --
commit eb9b929e5a0b2b55ad4f0c2af1f0f2627d324f83
Author: Ian Rogers <[email protected]>
perf evlist: Try to avoid computing evsel from sample
This commit updates multiple tools to use the resolved evsel pointer directly from the perf_sample struct when available, falling back to evlist__id2evsel when it is not.
Quoted 4 lines
Remove the redundant evsel parameter from evlist-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
[Severity: Medium]
Does the commit message accurately reflect the changes in the patch?
The patch updates local variable assignments to opportunistically use sample.evsel, but it does not appear to remove any evsel parameters from handlers or change any function API signatures.
Could the commit message be updated to better match the actual code changes, or are there missing hunks that perform the described refactoring?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
Ian Rogers
reviewerPATCH v14 19/32 perf script: Don't pass evsel with sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from script-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- 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(-)
tools/perf/builtin-script.c +8 -4
@@ -2419,12 +2419,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;
@@ -2716,9 +2717,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:
@@ -2894,9 +2895,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;
tools/perf/util/scripting-engines/trace-event-perl.c +9 -12
@@ -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 )
tools/perf/util/scripting-engines/trace-event-python.c +15 -22
@@ -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); } }
tools/perf/util/trace-event-scripting.c +1 -4
@@ -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 ) {
tools/perf/util/trace-event.h +0 -3
@@ -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);
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 20/32 perf s390-sample-raw: Don't pass evsel or its PMU with sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from s390-sample-raw-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- tools/perf/util/s390-sample-raw.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-)
tools/perf/util/s390-sample-raw.c +17 -14
@@ -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); } }
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 21/32 perf evsel: Don't pass evsel with sample
In reply to Ian RogersAs struct perf_sample now directly contains its own resolved evsel pointer, passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from evsel-specific handlers and structures, ensuring the tool always directly accesses the evsel bound to the sample. This simplifies the API signatures and eliminates the risk of passing an inconsistent evsel.
--- tools/perf/util/evsel.c | 61 +++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 24 deletions(-)
tools/perf/util/evsel.c +37 -24
@@ -3003,52 +3003,62 @@ int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads)return ret; } -static int perf_evsel__parse_id_sample (const struct evsel *evsel, -const union perf_event *event, +static int perf_evsel__parse_id_sample (const union perf_event *event,struct perf_sample *sample) { +const struct evsel *evsel = sample->evsel;u64 type = evsel->core.attr.sample_type;const __u64 *array = event->sample.array;bool swapped = evsel->needs_swap;union u64_swap u; - - array += ((event->header.size - -sizeof (event->header)) /sizeof (u64)) -1 ; +int i = ((event->header.size -sizeof (event->header)) /sizeof (u64)) -1 ;if (type &PERF_SAMPLE_IDENTIFIER ) { - sample->id = *array; - array--; +if (i <0 ) +return -EFAULT ; + + sample->id = array[i--]; }if (type &PERF_SAMPLE_CPU ) { - u.val64 = *array; +if (i <0 ) +return -EFAULT ; + + u.val64 = array[i--];if (swapped) {/* undo swap of u64, then swap on individual u32s */ u.val64 =bswap_64 (u.val64); u.val32[0 ] =bswap_32 (u.val32[0 ]); } - sample->cpu = u.val32[0 ]; - array--; }if (type &PERF_SAMPLE_STREAM_ID ) { - sample->stream_id = *array; - array--; +if (i <0 ) +return -EFAULT ; + + sample->stream_id = array[i--]; }if (type &PERF_SAMPLE_ID ) { - sample->id = *array; - array--; +if (i <0 ) +return -EFAULT ; + + sample->id = array[i--]; }if (type &PERF_SAMPLE_TIME ) { - sample->time = *array; - array--; +if (i <0 ) +return -EFAULT ; + + sample->time = array[i--]; }if (type &PERF_SAMPLE_TID ) { - u.val64 = *array; +if (i <0 ) +return -EFAULT ; + + u.val64 = array[i--];if (swapped) {/* undo swap of u64, then swap on individual u32s */ u.val64 =bswap_64 (u.val64);
@@ -3058,7 +3068,6 @@ static int perf_evsel__parse_id_sample(const struct evsel *evsel, sample->pid = u.val32[0 ]; sample->tid = u.val32[1 ]; - array--; }return 0 ;
@@ -3244,15 +3253,18 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->deferred_cookie = event->callchain_deferred.cookie; -if (evsel->core.attr.sample_id_all) -perf_evsel__parse_id_sample (evsel, event, data); - +if (evsel->core.attr.sample_id_all) { +if (perf_evsel__parse_id_sample (event, data)) + goto out_efault; + }return 0 ; }if (event->header.type !=PERF_RECORD_SAMPLE ) { -if (evsel->core.attr.sample_id_all) -perf_evsel__parse_id_sample (evsel, event, data); +if (evsel->core.attr.sample_id_all) { +if (perf_evsel__parse_id_sample (event, data)) + goto out_efault; + }return 0 ; }
@@ -3614,12 +3626,13 @@ int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event,if (event->header.type !=PERF_RECORD_SAMPLE ) {struct perf_sample data = { + .evsel = evsel, .time =-1ULL , };if (!evsel->core.attr.sample_id_all)return -1 ; -if (perf_evsel__parse_id_sample (evsel, event, &data)) +if (perf_evsel__parse_id_sample (event, &data))return -1 ; *timestamp = data.time;
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 22/32 perf lock: Constify trace_lock_handler variables
In reply to Ian RogersConstify the static trace_lock_handler structures.
Since the trace lock handler callbacks and definitions do not change at runtime, declare them const to enforce read-only memory placement and improve safety.
--- tools/perf/builtin-lock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/builtin-lock.c +3 -3
@@ -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) {
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 23/32 perf lock: Avoid segv if event is missing a callchain
In reply to Ian RogersAvoid a potential segmentation fault if a parsed sample unexpectedly lacks a valid callchain pointer.
Add a check for a NULL sample->callchain pointer in get_callstack(). If the callchain is missing, return NULL to safely skip the event and log a debug warning rather than causing a tool segfault.
--- tools/perf/builtin-lock.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tools/perf/builtin-lock.c +9 -2
@@ -938,9 +938,16 @@ static u64 *get_callstack(struct perf_sample *sample, int max_stack)u64 i;int c; +if (!sample->callchain) { +pr_debug ("Sample unexpectedly missing callchain\n" ); +return NULL ; + } + callstack =calloc (max_stack,sizeof (*callstack)); -if (callstack ==NULL ) +if (callstack ==NULL ) { +pr_debug ("Failed to allocate callstack\n" );return NULL ; + }for (i =0 , c =0 ; i < sample->callchain->nr && c < max_stack; i++) {u64 ip = sample->callchain->ips[i];
@@ -1059,7 +1066,7 @@ static int report_lock_contention_begin_event(struct perf_sample *sample)if (needs_callstack ()) {u64 *callstack =get_callstack (sample, max_stack_depth);if (callstack ==NULL ) -return -ENOMEM ; +return 0 ;if (!match_callstack_filter (machine, callstack, max_stack_depth)) {free (callstack);
Signature · 1 line
2.54.0.746.g67dd491aae-goog
[email protected]
AI reviewRe: [PATCH v14 23/32] perf lock: Avoid segv if event is missing a callchain
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch conflates a missing callchain condition with a memory allocation failure, causing…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch conflates a missing callchain condition with a memory allocation failure, causing out-of-memory errors to be silently ignored. --
commit a2151c29777424e46f4107c3691772f24c892171
Author: Ian Rogers <[email protected]>
perf lock: Avoid segv if event is missing a callchain
This commit avoids a potential segmentation fault by checking for a missing callchain pointer in get_callstack(), returning NULL if it is missing. It also updates the caller to return 0 instead of -ENOMEM when a NULL callstack is returned.
Quoted 4 lines
tools/perf/builtin-lock.c +0
-0
[ ... ]
Quoted 15 lines
tools/perf/builtin-lock.c +8
-1@@ -938,9 +938,16 @@ static u64 *get_callstack(struct perf_sample *sample, int max_stack)u64 i;int c; +if (!sample->callchain) { +pr_debug ("Sample unexpectedly missing callchain\n" ); +return NULL ; + } + callstack =calloc (max_stack,sizeof (*callstack)); -if (callstack ==NULL ) +if (callstack ==NULL ) { +pr_debug ("Failed to allocate callstack\n" );return NULL ; + }
[ ... ]
tools/perf/builtin-lock.c static int report_lock_contention_begin_event(struct perf_sample *sample) · line 1069
Quoted 6 lines
tools/perf/builtin-lock.c +1
-1@@ -1059,7 +1066,7 @@ static int report_lock_contention_begin_event(struct perf_sample *sample)if (needs_callstack ()) {u64 *callstack =get_callstack (sample, max_stack_depth);if (callstack ==NULL ) -return -ENOMEM ; +return 0 ;
[Severity: Medium]
Will this change inadvertently swallow memory allocation failures?
Because get_callstack() returns NULL both when the callchain is missing and when calloc() fails, returning 0 here means out-of-memory errors will now be silently ignored and treated as gracefully skipped events.
Should get_callstack() perhaps return an error pointer or an explicit status code so the caller can distinguish between a missing callchain (returning 0) and an actual ENOMEM condition?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
Ian Rogers
reviewerPATCH v14 24/32 perf timechart: Fix memory leaks
In reply to Ian RogersResolve a major execution-time leak of backtrace strings in the timechart tool.
- Modify cat_backtrace() to return dynamically allocated memory via open_memstream(), transferring ownership to the caller.
- Free the returned backtrace string inside process_sample_event() immediately after invoking the tracepoint handler.
- In handlers like pid_put_sample() and sched_wakeup(), make a separate copy of the backtrace using strdup() if it needs to be persisted in the sample struct, preventing lifetime issues and double-free vulnerabilities.
--- tools/perf/builtin-timechart.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
tools/perf/builtin-timechart.c +10 -7
@@ -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;
@@ -577,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)
@@ -587,11 +588,13 @@ static int process_sample_event(const struct perf_tool *tool,if (evsel->handler !=NULL ) {tracepoint_handler f = evsel->handler; +char *backtrace =cat_backtrace (event, sample, machine); -return f (tchart, sample,cat_backtrace (event, sample, machine)); + ret =f (tchart, sample, backtrace); +free (backtrace); } -return 0 ; +return ret; } static int
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 25/32 perf kmem: Fix memory leaks on error path and when skipping
In reply to Ian RogersFix memory leaks on the error paths and skipped sample handling paths in the perf kmem tool.
Ensure that all allocated GFP flags and thread references are properly freed and released via thread__put() when skipping samples or encountering parsing failures, preventing long-term memory usage leaks during large trace analyses.
--- tools/perf/builtin-kmem.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
tools/perf/builtin-kmem.c +13 -5
@@ -783,17 +783,21 @@ static int parse_gfp_flags(struct perf_sample *sample, unsigned int gfp_flags) new =realloc (gfps, (nr_gfps +1 ) *sizeof (*gfps));if (new ==NULL ) -return -ENOMEM ; + goto err_out; gfps = new; - new += nr_gfps++; + new += nr_gfps; new->flags = gfp_flags; new->human_readable =strdup (str +10 ); +if (!new->human_readable) + goto err_out; new->compact_str =compact_gfp_flags (str +10 ); -if (!new->human_readable || !new->compact_str) -return -ENOMEM ; - +if (!new->compact_str) { +free (new->human_readable); + goto err_out; + } + nr_gfps++;qsort (gfps, nr_gfps,sizeof (*gfps), gfpcmp); }
@@ -802,6 +806,9 @@ static int parse_gfp_flags(struct perf_sample *sample, unsigned int gfp_flags)trace_seq_destroy (&seq);return 0 ; +err_out: +trace_seq_destroy (&seq); +return -ENOMEM ; }static int evsel__process_page_alloc_event (struct perf_sample *sample)
@@ -971,6 +978,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, }if (perf_kmem__skip_sample (sample)) { +thread__put (thread);return 0 ; }
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 26/32 perf synthetic-events: Bound check when synthesizing mmap2 and build_id events
In reply to Ian RogersAdd robust boundary checks when synthesizing mmap2 and build_id events to ensure that filename fields do not overflow the fixed-size stack allocations or the synthesized event structures.
Verify that the filename fits safely within the allocated boundaries of the mmap2 event structure, and prevent potential heap/stack overflow corruptions from excessively long or corrupted kernel filenames.
--- tools/perf/util/synthetic-events.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
tools/perf/util/synthetic-events.c +16 -3
@@ -2257,14 +2257,20 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool, const char *filename) {union perf_event ev; -size_t len; +size_t len, filename_len =strlen (filename);u64 sample_type = sample->evsel ? sample->evsel->core.attr.sample_type :0 ;void *array = &ev;int ret; - len =sizeof (ev.build_id) +strlen (filename) +1 ; +if (filename_len >=PATH_MAX ) +return -EINVAL ; + + len =sizeof (ev.build_id) + filename_len +1 ; len =PERF_ALIGN (len,sizeof (u64)); +if (len +MAX_ID_HDR_ENTRIES *sizeof (__u64) >sizeof (ev)) +return -E2BIG ; +memset (&ev,0 , len); ev.build_id.size = bid->size;
@@ -2303,14 +2309,21 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, const char *filename) {union perf_event ev; +size_t filename_len =strlen (filename);size_t ev_len;u64 sample_type = sample->evsel ? sample->evsel->core.attr.sample_type :0 ;void *array;int ret; - ev_len =sizeof (ev.mmap2) -sizeof (ev.mmap2.filename) +strlen (filename) +1 ; +if (filename_len >=sizeof (ev.mmap2.filename)) +return -EINVAL ; + + ev_len =sizeof (ev.mmap2) -sizeof (ev.mmap2.filename) + filename_len +1 ; ev_len =PERF_ALIGN (ev_len,sizeof (u64)); +if (ev_len +MAX_ID_HDR_ENTRIES *sizeof (__u64) >sizeof (ev)) +return -E2BIG ; +memset (&ev,0 , ev_len); ev.mmap2.header.type =PERF_RECORD_MMAP2 ;
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 27/32 perf kmem: Add bounds checks to tracepoint read values
In reply to Ian RogersSanitize order and migrate_type values from tracepoint payloads before using them as array indexes.
When processing page_alloc_event and page_free_event, verify that 'order' is less than MAX_PAGE_ORDER and 'migrate_type' is less than MAX_MIGRATE_TYPES. This guarantees that indexing into order_stats[MAX_PAGE_ORDER][MAX_MIGRATE_TYPES] remains strictly within bounds, avoiding out-of-bound heap or static segment accesses.
--- tools/perf/builtin-kmem.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
tools/perf/builtin-kmem.c +15 -0
@@ -826,6 +826,16 @@ static int evsel__process_page_alloc_event(struct perf_sample *sample) .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 =perf_sample__intval (sample,"pfn" );else
@@ -892,6 +902,11 @@ static int evsel__process_page_free_event(struct perf_sample *sample) .order = order, }; +if (order >=MAX_PAGE_ORDER ) { +pr_debug ("Out-of-bounds order %u\n" , order); +return -1 ; + } +if (use_pfn) page =perf_sample__intval (sample,"pfn" );else
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 28/32 perf sched: Bounds check CPU in sched switch events
In reply to Ian RogersEnsure CPU indexes parsed from sched switch and runtime events fit within the MAX_CPUS limit to prevent out-of-bounds indexing.
Add explicit bounds checks for sample->cpu against MAX_CPUS inside process_sched_switch_event, process_sched_runtime_event, and timehist_sched_change_event. This prevents indexing beyond the boundaries of the sched->curr_pid tracking array, avoiding potential memory corruption or undefined behavior.
--- tools/perf/builtin-sched.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
tools/perf/builtin-sched.c +15 -0
@@ -1791,6 +1791,11 @@ static int process_sched_switch_event(const struct perf_tool *tool,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_warning ("Out-of-bound sample CPU %d. Skipping sample\n" , this_cpu); +return 0 ; + } +if (sched->curr_pid[this_cpu] != (u32)-1 ) {/* * Are we trying to switch away a PID that is
@@ -1813,6 +1818,11 @@ static int process_sched_runtime_event(const struct perf_tool *tool, { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); +if (sample->cpu >=MAX_CPUS ) { +pr_warning ("Out-of-bound sample CPU %u. Skipping sample\n" , sample->cpu); +return 0 ; + } +if (sched->tp_handler->runtime_event)return sched->tp_handler->runtime_event (sched, sample, machine);
@@ -2775,6 +2785,11 @@ static int timehist_sched_change_event(const struct perf_tool *tool,int rc =0 ;const char state =perf_sample__taskstate (sample,"prev_state" ); +if (sample->cpu >=MAX_CPUS ) { +pr_warning ("Out-of-bound sample CPU %d. Skipping sample\n" , sample->cpu); +return 0 ; + } +addr_location__init (&al);if (machine__resolve (machine, &al, sample) <0 ) { pr_err("problem processing %d event. skipping it\n",
Signature · 1 line
2.54.0.746.g67dd491aae-goog
Ian Rogers
reviewerPATCH v14 29/32 perf timechart: Bounds check CPU
In reply to Ian RogersPrevent out-of-bounds writes/reads in CPU state tracking arrays by enforcing strict MAX_CPUS bounds checks in timechart's tracepoint handlers.
Ensure that cpu_id retrieved from idle/frequency and sched tracepoints is less than MAX_CPUS before indexing into cpus_cstate_state, cpus_cstate_start_times, and similar tracking arrays. Also, fix an off-by-one error in the CPU iteration loop inside end_sample_processing() by changing the loop condition from 'cpu <= tchart->numcpus' to 'cpu < tchart->numcpus'.
--- tools/perf/builtin-timechart.c | 35 +++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)
tools/perf/builtin-timechart.c +32 -3
@@ -605,6 +605,10 @@ process_sample_cpu_idle(struct timechart *tchart __maybe_unused,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
@@ -620,6 +624,10 @@ process_sample_cpu_frequency(struct timechart *tchart,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 ; }
@@ -633,6 +641,10 @@ process_sample_sched_wakeup(struct timechart *tchart,int waker =perf_sample__intval (sample,"common_pid" );int wakee =perf_sample__intval (sample,"pid" ); +if (sample->cpu >=MAX_CPUS ) { +pr_debug ("Out-of-bounds cpu %u\n" , sample->cpu); +return -1 ; + }sched_wakeup (tchart, sample->cpu, sample->time, waker, wakee, flags, backtrace);return 0 ; }
@@ -646,6 +658,10 @@ process_sample_sched_switch(struct timechart *tchart,int next_pid =perf_sample__intval (sample,"next_pid" );u64 prev_state =perf_sample__intval (sample,"prev_state" ); +if (sample->cpu >=MAX_CPUS ) { +pr_debug ("Out-of-bounds cpu %u\n" , sample->cpu); +return -1 ; + }sched_switch (tchart, sample->cpu, sample->time, prev_pid, next_pid, prev_state, backtrace);return 0 ;
@@ -660,6 +676,10 @@ process_sample_power_start(struct timechart *tchart __maybe_unused,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 ; }
@@ -669,6 +689,10 @@ process_sample_power_end(struct timechart *tchart, struct perf_sample *sample, const char *backtrace __maybe_unused) { +if (sample->cpu >=MAX_CPUS ) { +pr_debug ("Out-of-bounds cpu %u\n" , sample->cpu); +return -1 ; + }c_state_end (tchart, sample->cpu, sample->time);return 0 ; }
@@ -681,6 +705,10 @@ process_sample_power_frequency(struct timechart *tchart,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 ; }
@@ -692,10 +720,9 @@ process_sample_power_frequency(struct timechart *tchart,*/ static void end_sample_processing (struct timechart *tchart) { -u64 cpu; -struct power_event *pwr; +for (u64 cpu =0 ; cpu < tchart->numcpus; cpu++) { +struct power_event *pwr; -for (cpu =0 ; cpu <= tchart->numcpus; cpu++) {/* C state */ #if 0 pwr =zalloc (sizeof (*pwr));
@@ -1515,6 +1542,8 @@ static int process_header(struct perf_file_section *section __maybe_unused,switch (feat) {case HEADER_NRCPUS : tchart->numcpus = ph->env.nr_cpus_avail; +if (tchart->numcpus >MAX_CPUS ) + tchart->numcpus =MAX_CPUS ;break ;case HEADER_CPU_TOPOLOGY :
Signature · 1 line
2.54.0.746.g67dd491aae-goog
[email protected]
AI reviewRe: [PATCH v14 29/32] perf timechart: Bounds check CPU
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Returning -1 from tracepoint handlers causes full session abort instead of just dropping the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Returning -1 from tracepoint handlers causes full session abort instead of just dropping the out-of-bounds sample. --
commit 3886673c573a53ceabf60565604906fa2eeab45d
Author: Ian Rogers <[email protected]>
perf timechart: Bounds check CPU
Prevent out-of-bounds writes/reads in CPU state tracking arrays by enforcing strict MAX_CPUS bounds checks in timechart's tracepoint handlers.
tools/perf/builtin-timechart.c process_sample_cpu_idle(struct timechart *tchart __maybe_unused, · line 611
Quoted 12 lines
tools/perf/builtin-timechart.c +4
-0@@ -605,6 +605,10 @@ process_sample_cpu_idle(struct timechart *tchart __maybe_unused,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 ; + }
[Severity: High]
Does returning -1 here cause the entire session processing to abort?
When tool->sample returns a negative value, it propagates up through perf_session__deliver_event(), reader__read_event(), and perf_session__process_events(), causing the entire processing loop to fail.
If a file contains a single corrupted event, or if it runs on a system with more than 4096 CPUs, would this completely abort execution and fail to generate an SVG?
Could we return 0 instead to gracefully skip the invalid sample?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
Ian Rogers
reviewerPATCH v14 30/32 perf evsel: Add bounds checking to trace point raw data accessors
In reply to Ian RogersPrevent out-of-bounds memory reads when parsing corrupted or maliciously crafted perf.data files by introducing robust bounds validation to raw data accessors.
- Add a helper out_of_bounds() to check if field offsets and sizes exceed the sample's raw_size boundary, preventing heap read overflows.
- In perf_sample__rawptr(), properly resolve newer relative dynamic tracepoint fields (__rel_loc) by checking the boundaries before and after reading the dynamic field descriptor.
- Byte-swap dynamic field offsets and sizes dynamically when endianness varies, ensuring cross-endian parsing is robust.
--- tools/perf/util/evsel.c | 54 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-)
tools/perf/util/evsel.c +49 -5
@@ -3700,22 +3700,63 @@ struct tep_format_field *evsel__common_field(struct evsel *evsel, const char *nareturn tp_format ?tep_find_common_field (tp_format, name) :NULL ; } +static bool out_of_bounds (const struct tep_format_field *field,int offset,int size,u32 raw_size) +{ +if (offset <0 ) { +pr_warning ("Negative trace point field offset %d in %s\n" , + offset, field->name); +return true; + } +if (size <0 ) { +pr_warning ("Negative trace point field size %d in %s\n" , + size, field->name); +return true; + } +if ((u32 )offset + (u32 )size > raw_size) { +pr_warning ("Out of bound tracepoint field (%s) offset %d size %d in %u\n" , + field->name, offset, size, raw_size); +return true; + } +return false; +} +void *perf_sample__rawptr (struct perf_sample *sample,const char *name) {struct tep_format_field *field =evsel__field (sample->evsel, name); -int offset; +int offset, size;if (!field)return NULL ; offset = field->offset; - + size = field->size;if (field->flags &TEP_FIELD_IS_DYNAMIC ) { - offset = *(int *)(sample->raw_data + field->offset); - offset &=0xffff ; -if (tep_field_is_relative (field->flags)) +int dynamic_data; + +if (out_of_bounds (field, offset,4 , sample->raw_size)) +return NULL ; + + dynamic_data = *(int *)(sample->raw_data + field->offset); + +if (sample->evsel->needs_swap) + dynamic_data =bswap_32 (dynamic_data); + + offset = dynamic_data &0xffff ; + size = (dynamic_data >>16 ) &0xffff ; + +if (tep_field_is_relative (field->flags)) { +/* +* Newer kernel feature: Relative offsets (__rel_loc). +* If the relative flag is set, the parsed offset is not +* absolute from the start of the record. Instead, it is +* relative to the *end* of the dynamic field descriptor +* itself. +*/ offset += field->offset + field->size; + } } +if (out_of_bounds (field, offset, size, sample->raw_size)) +return NULL ;return sample->raw_data + offset; }
@@ -3726,6 +3767,9 @@ u64 format_field__intval(struct tep_format_field *field, struct perf_sample *samu64 value;void *ptr = sample->raw_data + field->offset; +if (out_of_bounds (field, field->offset, field->size, sample->raw_size)) +return 0 ; +switch (field->size) {case 1 :return *(u8 *)ptr;
Signature · 1 line
2.54.0.746.g67dd491aae-goog
[email protected]
AI reviewRe: [PATCH v14 30/32] perf evsel: Add bounds checking to trace point raw data accessors
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The newly added out_of_bounds() helper prints warnings without rate limiting, which can lead to…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The newly added out_of_bounds() helper prints warnings without rate limiting, which can lead to excessive log spam. --
commit f6d9f44b46370b4bf2d18ef92c31007bb8804554
Author: Ian Rogers <[email protected]>
perf evsel: Add bounds checking to trace point raw data accessors
This commit adds bounds checking to tracepoint raw data accessors to prevent out-of-bounds memory reads when parsing perf.data files. It introduces an out_of_bounds helper to validate field offsets and sizes against the sample raw_size. It also handles newer relative dynamic tracepoint fields and byte-swapping for cross-endian parsing.
Quoted 13 lines
tools/perf/util/evsel.c +5
-0@@ -3700,22 +3700,63 @@ struct tep_format_field *evsel__common_field(struct evsel *evsel, const char *nareturn tp_format ?tep_find_common_field (tp_format, name) :NULL ; } +static bool out_of_bounds (const struct tep_format_field *field,int offset,int size,u32 raw_size) +{ +if (offset <0 ) { +pr_warning ("Negative trace point field offset %d in %s\n" , + offset, field->name);
tools/perf/util/evsel.c struct tep_format_field *evsel__common_field(struct evsel *evsel, const char *na · line 3717
Quoted 10 lines
tools/perf/util/evsel.c +10
-0+return true; + } +if (size <0 ) { +pr_warning ("Negative trace point field size %d in %s\n" , + size, field->name); +return true; + } +if ((u32 )offset + (u32 )size > raw_size) { +pr_warning ("Out of bound tracepoint field (%s) offset %d size %d in %u\n" , + field->name, offset, size, raw_size);
[Severity: Low]
Since perf_sample__rawptr and format_field__intval are called for every parsed field across potentially millions of samples, could these pr_warning calls lead to excessive log spam when parsing a corrupted file?
Would it be better to use pr_warning_once or similar rate limiting to prevent flooding the terminal?
Quoted 4 lines
tools/perf/util/evsel.c +4
-0+return true; + } +return false; +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=30
Ian Rogers
reviewerPATCH v14 31/32 perf kwork: Fix address sanitizer issues
In reply to Ian RogersThere is a double free in the record array due to how parse_options will mutate the array. Fix by keeping an array that isn't mutated. Ensure kwork_usage is freed on all paths.
--- tools/perf/builtin-kwork.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
tools/perf/builtin-kwork.c +21 -9
@@ -2258,7 +2258,7 @@ static void setup_event_list(struct perf_kwork *kwork,static int perf_kwork__record (struct perf_kwork *kwork,int argc,const char **argv) { -const char **rec_argv; +const char **rec_argv, **to_free =NULL ;unsigned int rec_argc, i, j;struct kwork_class *class;int ret;
@@ -2295,16 +2295,27 @@ static int perf_kwork__record(struct perf_kwork *kwork,BUG_ON (i != rec_argc); +/* Save the pointers as the array will be mutated by cmd_record. */ + to_free =calloc (rec_argc +1 ,sizeof (char *)); +if (to_free ==NULL ) { + ret = -ENOMEM ; + goto EXIT; + } +pr_debug ("record comm: " ); -for (j =0 ; j < rec_argc; j++) +for (j =0 ; j < rec_argc; j++) {pr_debug ("%s " , rec_argv[j]); + to_free[j] = rec_argv[j]; + }pr_debug ("\n" ); ret =cmd_record (i, rec_argv); EXIT:for (i =0 ; i < rec_argc; i++) -free ((void *)rec_argv[i]); +free ((void *)(to_free ? to_free[i] : rec_argv[i])); + +free (to_free);free (rec_argv);return ret; }
@@ -2447,6 +2458,7 @@ int cmd_kwork(int argc, const char **argv)const char *const kwork_subcommands[] = {"record" ,"report" ,"latency" ,"timehist" ,"top" ,NULL }; +int ret =0 ;perf_tool__init (&kwork.tool,/*ordered_events=*/ true); kwork.tool.mmap = perf_event__process_mmap;
@@ -2463,7 +2475,7 @@ int cmd_kwork(int argc, const char **argv)if (strlen (argv[0 ]) >2 &&strstarts ("record" , argv[0 ])) {setup_event_list (&kwork, kwork_options, kwork_usage); -return perf_kwork__record (&kwork, argc, argv); + ret =perf_kwork__record (&kwork, argc, argv); }else if (strlen (argv[0 ]) >2 &&strstarts ("report" , argv[0 ])) { kwork.sort_order = default_report_sort_order;if (argc >1 ) {
@@ -2474,7 +2486,7 @@ int cmd_kwork(int argc, const char **argv) kwork.report =KWORK_REPORT_RUNTIME ;setup_sorting (&kwork, report_options, report_usage);setup_event_list (&kwork, kwork_options, kwork_usage); -return perf_kwork__report (&kwork); + ret =perf_kwork__report (&kwork); }else if (strlen (argv[0 ]) >2 &&strstarts ("latency" , argv[0 ])) { kwork.sort_order = default_latency_sort_order;if (argc >1 ) {
@@ -2485,7 +2497,7 @@ int cmd_kwork(int argc, const char **argv) kwork.report =KWORK_REPORT_LATENCY ;setup_sorting (&kwork, latency_options, latency_usage);setup_event_list (&kwork, kwork_options, kwork_usage); -return perf_kwork__report (&kwork); + ret =perf_kwork__report (&kwork); }else if (strlen (argv[0 ]) >2 &&strstarts ("timehist" , argv[0 ])) {if (argc >1 ) { argc =parse_options (argc, argv, timehist_options, timehist_usage,0 );
@@ -2494,7 +2506,7 @@ int cmd_kwork(int argc, const char **argv) } kwork.report =KWORK_REPORT_TIMEHIST ;setup_event_list (&kwork, kwork_options, kwork_usage); -return perf_kwork__timehist (&kwork); + ret =perf_kwork__timehist (&kwork); }else if (strlen (argv[0 ]) >2 &&strstarts ("top" , argv[0 ])) { kwork.sort_order = default_top_sort_order;if (argc >1 ) {
@@ -2507,12 +2519,12 @@ int cmd_kwork(int argc, const char **argv) kwork.event_list_str ="sched, irq, softirq" ;setup_event_list (&kwork, kwork_options, kwork_usage);setup_sorting (&kwork, top_options, top_usage); -return perf_kwork__top (&kwork); + ret =perf_kwork__top (&kwork); }else usage_with_options (kwork_usage, kwork_options);/* free usage string allocated by parse_options_subcommand */ free ((void *)kwork_usage[0 ]); -return 0 ; +return ret; }
Signature · 1 line
2.54.0.746.g67dd491aae-goog
[email protected]
AI reviewRe: [PATCH v14 31/32] perf kwork: Fix address sanitizer issues
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Double free and memory leak vulnerabilities in builtin-kvm.c command wrappers.
- [High] List corruption and infinite loop when duplicate events are specified. --
commit 603fea0ed7e7d37e22b905275e056a33548f710e
Author: Ian Rogers <[email protected]>
perf kwork: Fix address sanitizer issues
This commit fixes a double free in the record array caused by parse_options mutating the argument array. It introduces a separate array to track the original pointers so they can be safely freed.
tools/perf/builtin-kwork.c static int perf_kwork__record(struct perf_kwork *kwork, · line 2299
Quoted 10 lines
tools/perf/builtin-kwork.c +2
-0@@ -2295,16 +2295,27 @@ static int perf_kwork__record(struct perf_kwork *kwork,BUG_ON (i != rec_argc); +/* Save the pointers as the array will be mutated by cmd_record. */ + to_free =calloc (rec_argc +1 ,sizeof (char *));
[Severity: High]
This isn't a bug introduced by this patch, but does the exact same memory corruption vulnerability fixed here exist in tools/perf/builtin-kvm.c?
Functions like __cmd_record(), __cmd_report(), __cmd_top(), and __cmd_buildid_list() allocate arguments dynamically in rec_argv and pass the array to their respective cmd_*() functions. These downstream functions call parse_options(), which mutates the rec_argv array in-place by shifting non-option arguments.
The subsequent cleanup loop then double-frees any duplicated pointers and leaks overwritten ones. Should a similar fix be applied there?
[ ... ]
tools/perf/builtin-kwork.c int cmd_kwork(int argc, const char **argv) · line 2477
Quoted 4 lines
tools/perf/builtin-kwork.c +0
-0@@ -2463,7 +2475,7 @@ int cmd_kwork(int argc, const char **argv)if (strlen (argv[0 ]) >2 &&strstarts ("record" , argv[0 ])) {setup_event_list (&kwork, kwork_options, kwork_usage);
[Severity: High]
This is a pre-existing issue, but does setup_event_list() cause list corruption and an infinite loop if duplicate events are specified?
The user-provided event string is tokenized by comma. For each token, the code finds the corresponding kwork_class from kwork_class_supported_list and unconditionally adds its class->list node to kwork->class_list using list_add_tail().
Since class points to a statically allocated structure, adding the same event twice (e.g., perf kwork -k irq,irq record) calls list_add_tail() on a node already linked in the list. This corrupts its next/prev pointers, creating a circular list and causing subsequent list_for_each_entry() loops to hang indefinitely.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=31
Ian Rogers
reviewerPATCH v14 32/32 perf kwork: Fix memory management of kwork_work
In reply to Ian RogersThis commit addresses several memory management issues in builtin-kwork.c:
1. Implements a global cleanup function perf_kwork__exit to free all kwork_work and kwork_atom_page objects at the end of the command.
2. Ensures all 'name' fields in struct kwork_work are malloc-ed (or NULL) and properly freed by using strdup and zfree.
3. Fixes memory leaks in top_merge_tasks where kwork_work objects were dropped without being freed.
4. Adds robustness with NULL checks for name fields.
5. Fixes workqueue_work_init to correctly resolve and strdup kernel function names, preventing bad-free errors.
--- tools/perf/builtin-kwork.c | 121 ++++++++++++++++++++++++++++-------- tools/perf/util/bpf_kwork.c | 22 +++++-- tools/perf/util/kwork.h | 2 + 3 files changed, 116 insertions(+), 29 deletions(-)
tools/perf/builtin-kwork.c +96 -25
@@ -323,8 +323,8 @@ static struct kwork_work *work_search(struct rb_root_cached *root,else if (cmp <0 ) node = node->rb_right;else { -if (work->name ==NULL ) - work->name = key->name; +if (work->name ==NULL && key->name !=NULL ) + work->name =strdup (key->name);return work; } }
@@ -371,11 +371,54 @@ static struct kwork_work *work_new(struct kwork_work *key) work->id = key->id; work->cpu = key->cpu; - work->name = key->name; + work->name = key->name ?strdup (key->name) :NULL ; work->class = key->class;return work; } + +static void work_delete (struct kwork_work *work) +{ +if (work) { +work_exit (work); +free (work); + } +} + +static void kwork_work__free_root (struct rb_root_cached *root) +{ +struct rb_node *next; +struct kwork_work *work; + +while ((next =rb_first_cached (root))) { + work = rb_entry(next, struct kwork_work, node); +rb_erase_cached (next, root); +work_delete (work); + } +} + +static void perf_kwork__exit (struct perf_kwork *kwork) +{ +struct kwork_class *class; +struct kwork_atom_page *page, *tmp_page; + +list_for_each_entry (class, &kwork->class_list, list) { +kwork_work__free_root (&class->work_root); + } + +kwork_work__free_root (&kwork->sorted_work_root); + +list_for_each_entry_safe (page, tmp_page, &kwork->atom_page_list, list) { +list_del_init (&page->list); +free (page); + } + +INIT_LIST_HEAD (&kwork->class_list); +INIT_LIST_HEAD (&kwork->atom_page_list); +INIT_LIST_HEAD (&kwork->sort_list); +INIT_LIST_HEAD (&kwork->cmp_id); +} +static struct kwork_work *work_findnew (struct rb_root_cached *root,struct kwork_work *key,struct list_head *sort_list)
@@ -453,25 +496,29 @@ static int work_push_atom(struct perf_kwork *kwork, struct kwork_work **ret_work, bool overwrite) { -struct kwork_atom *atom, *dst_atom, *last_atom; +struct kwork_atom *atom =NULL , *dst_atom, *last_atom;struct kwork_work *work, key; +int ret =0 ;BUG_ON (class->work_init ==NULL ); class->work_init (kwork, class, &key, src_type, sample, machine); atom =atom_new (kwork, sample); -if (atom ==NULL ) -return -1 ; +if (atom ==NULL ) { + ret =-1 ; + goto out; + } work =work_findnew (&class->work_root, &key, &kwork->cmp_id);if (work ==NULL ) {atom_free (atom); -return -1 ; + ret =-1 ; + goto out; }if (!profile_event_match (kwork, work, sample)) {atom_free (atom); -return 0 ; + goto out; }if (dst_type <KWORK_TRACE_MAX ) {
@@ -498,8 +545,9 @@ static int work_push_atom(struct perf_kwork *kwork, }list_add_tail (&atom->list, &work->atom_list[src_type]); - -return 0 ; +out: +work_exit (&key); +return ret; } static struct kwork_atom *work_pop_atom(struct perf_kwork *kwork,
@@ -510,7 +558,7 @@ static struct kwork_atom *work_pop_atom(struct perf_kwork *kwork,struct machine *machine, struct kwork_work **ret_work) { - struct kwork_atom *atom, *src_atom; + struct kwork_atom *atom = NULL, *src_atom;struct kwork_work *work, key;BUG_ON (class->work_init ==NULL );
@@ -521,15 +569,15 @@ static struct kwork_atom *work_pop_atom(struct perf_kwork *kwork, *ret_work = work;if (work ==NULL ) -return NULL ; + goto out;if (!profile_event_match (kwork, work, sample)) -return NULL ; + goto out; atom =list_last_entry_or_null (&work->atom_list[dst_type], struct kwork_atom, list);if (atom !=NULL ) -return atom; + goto out; src_atom =atom_new (kwork, sample);if (src_atom !=NULL )
@@ -538,8 +586,9 @@ static struct kwork_atom *work_pop_atom(struct perf_kwork *kwork,if (ret_work !=NULL ) *ret_work =NULL ; } - -return NULL ; +out: +work_exit (&key); +return atom; } static struct kwork_work *find_work_by_id(struct rb_root_cached *root,
@@ -1002,13 +1051,16 @@ static void irq_work_init(struct perf_kwork *kwork, work->name =NULL ; }else { work->id =perf_sample__intval (sample,"irq" ); - work->name =perf_sample__strval (sample,"name" ); + work->name =strdup (perf_sample__strval (sample,"name" ) ?:"<unknown>" ); } }static void irq_work_name (struct kwork_work *work,char *buf,int len) { -snprintf (buf, len,"%s:%" PRIu64"" , work->name, work->id); +if (work->name !=NULL ) +snprintf (buf, len,"%s:%" PRIu64"" , work->name, work->id); +else +snprintf (buf, len,"%" PRIu64"" , work->id); }static struct kwork_class kwork_irq = {
@@ -1135,7 +1187,10 @@ static void softirq_work_init(struct perf_kwork *kwork,static void softirq_work_name (struct kwork_work *work,char *buf,int len) { -snprintf (buf, len,"(s)%s:%" PRIu64"" , work->name, work->id); +if (work->name !=NULL ) +snprintf (buf, len,"(s)%s:%" PRIu64"" , work->name, work->id); +else +snprintf (buf, len,"(s)%" PRIu64"" , work->id); }static struct kwork_class kwork_softirq = {
@@ -1220,8 +1275,14 @@ static void workqueue_work_init(struct perf_kwork *kwork __maybe_unused, work->class = class; work->cpu = sample->cpu; work->id =perf_sample__intval (sample,"work" ); - work->name = function_addr ==0 ?NULL : -machine__resolve_kernel_addr (machine, &function_addr, &modp); + work->name =NULL ; + +if (function_addr !=0 ) { +const char *name =machine__resolve_kernel_addr (machine, &function_addr, &modp); + +if (name) + work->name =strdup (name); + } }static void workqueue_work_name (struct kwork_work *work,char *buf,int len)
@@ -1284,16 +1345,16 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused,if (src_type ==KWORK_TRACE_EXIT ) { work->id =perf_sample__intval (sample,"prev_pid" ); - work->name =strdup (perf_sample__strval (sample,"prev_comm" )); + work->name =strdup (perf_sample__strval (sample,"prev_comm" ) ?:"<unknown>" ); }else if (src_type ==KWORK_TRACE_ENTRY ) { work->id =perf_sample__intval (sample,"next_pid" ); - work->name =strdup (perf_sample__strval (sample,"next_comm" )); + work->name =strdup (perf_sample__strval (sample,"next_comm" ) ?:"<unknown>" ); } }static void sched_work_name (struct kwork_work *work,char *buf,int len) { -snprintf (buf, len,"%s" , work->name); +snprintf (buf, len,"%s" , work->name ?:"" ); }static struct kwork_class kwork_sched = {
@@ -2100,8 +2161,10 @@ static void top_merge_tasks(struct perf_kwork *kwork)rb_erase_cached (node, &class->work_root); data = rb_entry(node, struct kwork_work, node); -if (!profile_name_match (kwork, data)) +if (!profile_name_match (kwork, data)) { +work_delete (data);continue ; + } cpu = data->cpu; merged_work = find_work_by_id(&merged_root, data->id,
@@ -2109,11 +2172,17 @@ static void top_merge_tasks(struct perf_kwork *kwork)if (!merged_work) {work_insert (&merged_root, data, &kwork->cmp_id); }else { +if (merged_work->name ==NULL && data->name !=NULL ) + merged_work->name =strdup (data->name); + merged_work->total_runtime += data->total_runtime; merged_work->cpu_usage += data->cpu_usage; }top_calc_load_runtime (kwork, data); + +if (merged_work) +work_delete (data); }work_sort (kwork, class, &merged_root);
@@ -2523,6 +2592,8 @@ int cmd_kwork(int argc, const char **argv) }else usage_with_options (kwork_usage, kwork_options); +perf_kwork__exit (&kwork); +/* free usage string allocated by parse_options_subcommand */ free ((void *)kwork_usage[0 ]);
tools/perf/util/bpf_kwork.c +18 -4
@@ -53,6 +53,14 @@ static struct kwork_trace_bpf *skel;static struct timespec ts_start;static struct timespec ts_end; +void work_exit (struct kwork_work *work) +{ +if (work) { +free (work->name); + work->name =NULL ; + } +} +void perf_kwork__trace_start (void ) {clock_gettime (CLOCK_MONOTONIC , &ts_start);
@@ -273,6 +281,7 @@ static int add_work(struct perf_kwork *kwork, .cpu = key->cpu, };enum kwork_class_type type = key->type; +int ret =0 ;if (!valid_kwork_class_type (type)) {pr_debug ("Invalid class type %d to add work\n" , type);
@@ -287,8 +296,10 @@ static int add_work(struct perf_kwork *kwork,return -1 ; work = kwork->add_work (kwork, tmp.class, &tmp); -if (work ==NULL ) -return -1 ; +if (work ==NULL ) { + ret =-1 ; + goto out; + }if (kwork->report ==KWORK_REPORT_RUNTIME ) { work->nr_atoms = data->nr;
@@ -304,13 +315,16 @@ static int add_work(struct perf_kwork *kwork, work->max_latency_end = data->max_time_end; }else {pr_debug ("Invalid bpf report type %d\n" , kwork->report); -return -1 ; + ret =-1 ; + goto out; } kwork->timestart = (u64 )ts_start.tv_sec *NSEC_PER_SEC + ts_start.tv_nsec; kwork->timeend = (u64 )ts_end.tv_sec *NSEC_PER_SEC + ts_end.tv_nsec; -return 0 ; +out: +work_exit (&tmp); +return ret; }int perf_kwork__report_read_bpf (struct perf_kwork *kwork)
tools/perf/util/kwork.h +2 -0
@@ -164,6 +164,8 @@ struct kwork_class { char *buf, int len); }; +void work_exit (struct kwork_work *work); +struct trace_kwork_handler { int (*raise_event)(struct perf_kwork *kwork, struct kwork_class *class,
Signature · 1 line
2.54.0.746.g67dd491aae-goog
[email protected]
AI reviewRe: [PATCH v14 32/32] perf kwork: Fix memory management of kwork_work
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The function `work_exit()` is called unconditionally from `builtin-kwork.c` but defined in a…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The function work_exit() is called unconditionally from builtin-kwork.c but defined in a conditionally compiled file, breaking builds without BPF skeleton support. --
commit 215df5dc0c33de431c1c387ccda2468e8d531dee
Author: Ian Rogers <[email protected]>
perf kwork: Fix memory management of kwork_work
This commit introduces a global cleanup function and fixes memory leaks related to kwork_work objects in builtin-kwork.c. It ensures that name fields are properly allocated and freed by using strdup and adding work_exit routines.
Quoted 4 lines
tools/perf/builtin-kwork.c +0
-0
[ ... ]
Quoted 5 lines
tools/perf/builtin-kwork.c +0
-1@@ -371,11 +371,54 @@ static struct kwork_work *work_new(struct kwork_work *key) work->id = key->id; work->cpu = key->cpu; - work->name = key->name;
tools/perf/builtin-kwork.c static struct kwork_work *work_new(struct kwork_work *key) · line 383
Quoted 10 lines
tools/perf/builtin-kwork.c +6
-0+ work->name = key->name ?strdup (key->name) :NULL ; work->class = key->class;return work; } + +static void work_delete (struct kwork_work *work) +{ +if (work) { +work_exit (work);
[Severity: Low]
Will this cause a build failure when perf is built without BPF skeleton support?
work_exit() is called unconditionally here (and in work_push_atom and work_pop_atom) in builtin-kwork.c. However, the definition for work_exit() was placed in util/bpf_kwork.c.
If a user compiles perf on a system where HAVE_BPF_SKEL is disabled, bpf_kwork.o will not be linked. Could this lead to an undefined reference linker error for work_exit()?
Quoted 3 lines
tools/perf/builtin-kwork.c +3
-0+free (work); + } +}
[ ... ]
Quoted 18 lines
tools/perf/util/bpf_kwork.c +8
-0@@ -53,6 +53,14 @@ static struct kwork_trace_bpf *skel;static struct timespec ts_start;static struct timespec ts_end; +void work_exit (struct kwork_work *work) +{ +if (work) { +free (work->name); + work->name =NULL ; + } +} +void perf_kwork__trace_start (void ) {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=32
kernel test robot
build botRe: [PATCH v14 32/32] perf kwork: Fix memory management of kwork_work
In reply to Ian Rogerskernel test robot noticed "perf-stat-tests.perf.make.fail" on:
Hello,
kernel test robot noticed "perf-stat-tests.perf.make.fail" on:
commit: 7f9aae3554b369864c01505b2ec02ddf6f6e12f3 ("[PATCH v14 32/32] perf kwork: Fix memory management of kwork_work")
url: https://github.com/intel-lab-lkp/linux/commits/Ian-Rogers/perf-tool-Remove-evsel-from-tool-APIs-that-pass-the-sample/20260521-061855
patch link: https://lore.kernel.org/all/[email protected]/
patch subject: [PATCH v14 32/32] perf kwork: Fix memory management of kwork_work
in testcase: perf-stat-tests
version:
with following parameters:
config: x86_64-rhel-9.4-bpf
compiler: gcc-14
test machine: 16 threads Intel(R) Core(TM) i7-13620H (Raptor Lake) with 32G memory
(please refer to attached dmesg/kmsg for entire log/backtrace)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-lkp/[email protected]
The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20260525/[email protected]
==> /tmp/stderr <==
Makefile.config:661: Warning: Disabled BPF skeletons as clang (clang) is missing
Makefile.config:1134: Rust is not found. Test workloads with rust are disabled.
PERF_VERSION = 7.1.0-rc2/usr/bin/ld: perf-in.o: in function `work_delete':
/usr/src/perf_selftests-x86_64-rhel-9.4-bpf-7f9aae3554b369864c01505b2ec02ddf6f6e12f3/tools/perf/builtin-kwork.c:383:(.text+0x1b569b): undefined reference to work_exit' /usr/bin/ld: perf-in.o: in function work_push_atom':
/usr/src/perf_selftests-x86_64-rhel-9.4-bpf-7f9aae3554b369864c01505b2ec02ddf6f6e12f3/tools/perf/builtin-kwork.c:549:(.text+0x1b77d3): undefined reference to work_exit' /usr/bin/ld: perf-in.o: in function work_pop_atom':
/usr/src/perf_selftests-x86_64-rhel-9.4-bpf-7f9aae3554b369864c01505b2ec02ddf6f6e12f3/tools/perf/builtin-kwork.c:590:(.text+0x1b7fc6): undefined reference to `work_exit'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile.perf:803: perf] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
In reply to Ian RogersQuoted 16 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
Quoted 8 lines
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.
Thanks, tentatively applying it to perf-tools-next, for v7.2.
Ian Rogers
reviewerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 22 lines · Arnaldo Carvalho de Melo
Quoted 20 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.
Quoted 8 lines
Quoted 4 lines
v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.Thanks, tentatively applying it to perf-tools-next, for v7.2.
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Thanks Arnaldo! There will be Sashiko reviews to come and the boundary checking is likely to conflict with the boundary checking you are adding in:
https://lore.kernel.org/linux-perf-users/[email protected]/
When feedback arrives, I prefer sending additional fixes rather than issuing a v15. I don't mind if you want to drop the boundary checks I added, they were only included in the series to satisfy Sashiko and because I worried we'd forget about them.
Thanks,
Ian
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
In reply to Arnaldo Carvalho de MeloQuoted 21 lines · Arnaldo Carvalho de Melo
Quoted 20 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.
Quoted 6 lines
Quoted 4 lines
v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.Thanks, tentatively applying it to perf-tools-next, for v7.2.
Had to apply a minor fixup for a conflict with anoter patch series from you, the LBR one.
- Arnaldo
Ian Rogers
reviewerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 24 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.
Quoted 4 lines
Quoted 1 line
Thanks, tentatively applying it to perf-tools-next, for v7.2.
Had to apply a minor fixup for a conflict with anoter patch series from you, the LBR one.
Sorry for that and thanks for dealing with the conflict! Any chance you could push to tmp.perf-tools-next? I have some other series that will conflict and it would be nice to rebase those changes there.
Thanks,
Ian
Quoted 1 line
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 30 lines · Ian Rogers
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 24 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Thanks, tentatively applying it to perf-tools-next, for v7.2.
Had to apply a minor fixup for a conflict with anoter patch series from you, the LBR one.
Sorry for that and thanks for dealing with the conflict! Any chance you could push to tmp.perf-tools-next? I have some other series that will conflict and it would be nice to rebase those changes there.
I just removed the last two patches, the ones for kwork, as:
+ make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= NO_LIBELF=1 -C tools/perf O=/tmp/build/perf
make: Entering directory '/git/perf-7.1.0-rc2/tools/perf'
BUILD: Doing 'make -j32' parallel build
Makefile.config:647: Warning: Disabled BPF skeletons as libelf is required by bpftool
Makefile.config:745: Disabling post unwind, no support found.
Makefile.config:856: Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.
Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ on ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]
... rust: [ OFF ]
CC /tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
<SNIP>
LINK /tmp/build/perf/perf/usr/bin/ld: /tmp/build/perf/perf-in.o: in function `work_pop_atom':
builtin-kwork.c:(.text+0x59c92): undefined reference to work_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in function work_push_atom.constprop.0':
builtin-kwork.c:(.text+0x5aba8): undefined reference to work_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in function cmd_kwork':
(.text+0x5bb4b): undefined reference to `work_exit'/usr/bin/ld: (.text+0x5bbae): undefined reference to work_exit' /usr/bin/ld: (.text+0x5c3b2): undefined reference to work_exit'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile.perf:586: /tmp/build/perf/perf] Error 1 make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-7.1.0-rc2/tools/perf'
+ exit 1
toolsbuilder@five:~$
I'm doing some more tests, just a moment and I'll push what I have to tmp.perf-tools-next.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 89 lines · Arnaldo Carvalho de Melo
Quoted 30 lines · Ian Rogers
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 24 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Thanks, tentatively applying it to perf-tools-next, for v7.2.
Had to apply a minor fixup for a conflict with anoter patch series from you, the LBR one.
Sorry for that and thanks for dealing with the conflict! Any chance you could push to tmp.perf-tools-next? I have some other series that will conflict and it would be nice to rebase those changes there.
I just removed the last two patches, the ones for kwork, as:
+ make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= NO_LIBELF=1 -C
tools/perfO=/tmp/build/perf
make: Entering directory '/git/perf-7.1.0-rc2/tools/perf'
BUILD: Doing 'make -j32' parallel build
Makefile.config:647: Warning: Disabled BPF skeletons as libelf is required by bpftool
Makefile.config:745: Disabling post unwind, no support found.
Makefile.config:856: Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ on ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
<SNIP>
LINK/tmp/build/perf/perf/usr/bin/ld:/tmp/build/perf/perf-in.o: in function `work_pop_atom':
builtin-kwork.c:(.text+0x59c92): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functionwork_push_atom.constprop.0':
builtin-kwork.c:(.text+0x5aba8): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functioncmd_kwork':
(.text+0x5bb4b): undefined reference to `work_exit'/usr/bin/ld: (.text+0x5bbae): undefined reference towork_exit' /usr/bin/ld: (.text+0x5c3b2): undefined reference towork_exit'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile.perf:586:/tmp/build/perf/perf] Error 1 make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-7.1.0-rc2/tools/perf'
+ exit 1
toolsbuilder@five:~$
Quoted 2 lines
I'm doing some more tests, just a moment and I'll push what I have to tmp.perf-tools-next.
Also:
toolsbuilder@five:~$ cat dm.log/almalinux\:8 <SNIP> OLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugs.almalinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) + make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= -C tools/perf O=/tmp/build/perf make: Entering directory '/git/perf-7.1.0-rc2/tools/perf' BUILD: Doing 'make -j32' parallel build Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1061: No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.
Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ OFF ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]
... rust: [ OFF ]
CC /tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
CC /tmp/build/perf/dlfilters/dlfilter-test-api-v2.o
<SNIP>
COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/cache.json
COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/counter.json
COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/floating-point.json
COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/frontend.json
COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/memory.json
COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/other.json
COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/pipeline.json
COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/virtual-memory.json
GEN /tmp/build/perf/pmu-events/test-empty-pmu-events.c
Traceback (most recent call last):
File "pmu-events/jevents.py", line 1524, in <module>
main() File "pmu-events/jevents.py", line 1487, in main
with concurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,)) as executor:
TypeError: __init__() got an unexpected keyword argument 'initializer'
make[3]: *** [pmu-events/Build:176: /tmp/build/perf/pmu-events/test-empty-pmu-events.c] Error 1 make[3]: *** Deleting file '/tmp/build/perf/pmu-events/test-empty-pmu-events.c'
make[2]: *** [Makefile.perf:554: /tmp/build/perf/pmu-events/pmu-events-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 145 lines · Arnaldo Carvalho de Melo
Quoted 89 lines · Arnaldo Carvalho de Melo
Quoted 30 lines · Ian Rogers
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 24 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Thanks, tentatively applying it to perf-tools-next, for v7.2.
Had to apply a minor fixup for a conflict with anoter patch series from you, the LBR one.
Sorry for that and thanks for dealing with the conflict! Any chance you could push to tmp.perf-tools-next? I have some other series that will conflict and it would be nice to rebase those changes there.
I just removed the last two patches, the ones for kwork, as:
+ make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= NO_LIBELF=1 -C
tools/perfO=/tmp/build/perf
make: Entering directory '/git/perf-7.1.0-rc2/tools/perf'
BUILD: Doing 'make -j32' parallel build
Makefile.config:647: Warning: Disabled BPF skeletons as libelf is required by bpftool
Makefile.config:745: Disabling post unwind, no support found.
Makefile.config:856: Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ on ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
<SNIP>
LINK/tmp/build/perf/perf/usr/bin/ld:/tmp/build/perf/perf-in.o: in function `work_pop_atom':
builtin-kwork.c:(.text+0x59c92): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functionwork_push_atom.constprop.0':
builtin-kwork.c:(.text+0x5aba8): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functioncmd_kwork':
(.text+0x5bb4b): undefined reference to `work_exit'/usr/bin/ld: (.text+0x5bbae): undefined reference towork_exit' /usr/bin/ld: (.text+0x5c3b2): undefined reference towork_exit'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile.perf:586:/tmp/build/perf/perf] Error 1 make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-7.1.0-rc2/tools/perf'
+ exit 1
toolsbuilder@five:~$Quoted 2 lines
I'm doing some more tests, just a moment and I'll push what I have to tmp.perf-tools-next.
Also:
toolsbuilder@five:~$ cat dm.log/almalinux\:8 <SNIP> OLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugs.almalinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) + make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= -C tools/perf O=/tmp/build/perf make: Entering directory '/git/perf-7.1.0-rc2/tools/perf' BUILD: Doing 'make -j32' parallel build Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1061: No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ OFF ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
CC/tmp/build/perf/dlfilters/dlfilter-test-api-v2.o
<SNIP>COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/cache.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/counter.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/floating-point.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/frontend.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/memory.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/other.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/pipeline.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/virtual-memory.json GEN /tmp/build/perf/pmu-events/test-empty-pmu-events.c Traceback (most recent call last): File "pmu-events/jevents.py", line 1524, in <module> main()
Quoted 7 lines
File "
pmu-events/jevents.py", line 1487, in main
withconcurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,))as executor:
TypeError:__init__()got an unexpected keyword argument 'initializer'
make[3]: *** [pmu-events/Build:176:/tmp/build/perf/pmu-events/test-empty-pmu-events.c] Error 1 make[3]: *** Deleting file '/tmp/build/perf/pmu-events/test-empty-pmu-events.c'
make[2]: *** [Makefile.perf:554:/tmp/build/perf/pmu-events/pmu-events-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....
But:
toolsbuilder@five:~$ export BUILD_TARBALL=http://192.168.86.5/perf/perf-7.1.0-rc2.tar.xz toolsbuilder@five:~$ time dm 1 8.77 almalinux:8 : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) 2 84.96 almalinux:9 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-11) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-3.el9) flex 2.6.4 3: 103.23 almalinux:9-i386 : Ok gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3) , clang version 17.0.6 (AlmaLinux OS Foundation 17.0.6-5.el9) flex 2.6.4 4 90.91 almalinux:10 : Ok gcc (GCC) 14.3.1 20250617 (Red Hat 14.3.1-2) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-1.el10.alma.1) flex 2.6.4 5 118.21 alpine:3.16 : Ok gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219 , Alpine clang version 13.0.1 flex 2.6.4 ...
Ian Rogers
reviewerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 157 lines · Arnaldo Carvalho de Melo
Quoted 145 lines · Arnaldo Carvalho de Melo
Quoted 89 lines · Arnaldo Carvalho de Melo
Quoted 30 lines · Ian Rogers
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 24 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Thanks, tentatively applying it to perf-tools-next, for v7.2.
Had to apply a minor fixup for a conflict with anoter patch series from you, the LBR one.
Sorry for that and thanks for dealing with the conflict! Any chance you could push to tmp.perf-tools-next? I have some other series that will conflict and it would be nice to rebase those changes there.
I just removed the last two patches, the ones for kwork, as:
+ make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= NO_LIBELF=1 -C
tools/perfO=/tmp/build/perf
make: Entering directory '/git/perf-7.1.0-rc2/tools/perf'
BUILD: Doing 'make -j32' parallel build
Makefile.config:647: Warning: Disabled BPF skeletons as libelf is required by bpftool
Makefile.config:745: Disabling post unwind, no support found.
Makefile.config:856: Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ on ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
<SNIP>
LINK/tmp/build/perf/perf/usr/bin/ld:/tmp/build/perf/perf-in.o: in function `work_pop_atom':
builtin-kwork.c:(.text+0x59c92): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functionwork_push_atom.constprop.0':
builtin-kwork.c:(.text+0x5aba8): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functioncmd_kwork':
(.text+0x5bb4b): undefined reference to `work_exit'/usr/bin/ld: (.text+0x5bbae): undefined reference towork_exit' /usr/bin/ld: (.text+0x5c3b2): undefined reference towork_exit'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile.perf:586:/tmp/build/perf/perf] Error 1 make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-7.1.0-rc2/tools/perf'
+ exit 1
toolsbuilder@five:~$Quoted 2 lines
I'm doing some more tests, just a moment and I'll push what I have to tmp.perf-tools-next.
Also:
toolsbuilder@five:~$ cat dm.log/almalinux\:8 <SNIP> OLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugs.almalinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) + make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= -C tools/perf O=/tmp/build/perf make: Entering directory '/git/perf-7.1.0-rc2/tools/perf' BUILD: Doing 'make -j32' parallel build Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1061: No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ OFF ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
CC/tmp/build/perf/dlfilters/dlfilter-test-api-v2.o
<SNIP>COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/cache.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/counter.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/floating-point.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/frontend.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/memory.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/other.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/pipeline.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/virtual-memory.json GEN /tmp/build/perf/pmu-events/test-empty-pmu-events.c Traceback (most recent call last): File "pmu-events/jevents.py", line 1524, in <module> main()Quoted 7 lines
File "
pmu-events/jevents.py", line 1487, in main
withconcurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,))as executor:
TypeError:__init__()got an unexpected keyword argument 'initializer'
make[3]: *** [pmu-events/Build:176:/tmp/build/perf/pmu-events/test-empty-pmu-events.c] Error 1 make[3]: *** Deleting file '/tmp/build/perf/pmu-events/test-empty-pmu-events.c'
make[2]: *** [Makefile.perf:554:/tmp/build/perf/pmu-events/pmu-events-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....But:
Quoted 8 lines
toolsbuilder@five:~$ export BUILD_TARBALL=http://192.168.86.5/perf/perf-7.1.0-rc2.tar.xz toolsbuilder@five:~$ time dm 1 8.77 almalinux:8 : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) 2 84.96 almalinux:9 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-11) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-3.el9) flex 2.6.4 3: 103.23 almalinux:9-i386 : Ok gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3) , clang version 17.0.6 (AlmaLinux OS Foundation 17.0.6-5.el9) flex 2.6.4 4 90.91 almalinux:10 : Ok gcc (GCC) 14.3.1 20250617 (Red Hat 14.3.1-2) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-1.el10.alma.1) flex 2.6.4 5 118.21 alpine:3.16 : Ok gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219 , Alpine clang version 13.0.1 flex 2.6.4 ...
You can drop the parallelize jevent.py changes and I'll follow up. Sorry for the breakage.
Thanks,
Ian
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 168 lines · Ian Rogers
Quoted 157 lines · Arnaldo Carvalho de Melo
Quoted 145 lines · Arnaldo Carvalho de Melo
Quoted 89 lines · Arnaldo Carvalho de Melo
Quoted 30 lines · Ian Rogers
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 24 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Thanks, tentatively applying it to perf-tools-next, for v7.2.
Had to apply a minor fixup for a conflict with anoter patch series from you, the LBR one.
Sorry for that and thanks for dealing with the conflict! Any chance you could push to tmp.perf-tools-next? I have some other series that will conflict and it would be nice to rebase those changes there.
I just removed the last two patches, the ones for kwork, as:
+ make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= NO_LIBELF=1 -C
tools/perfO=/tmp/build/perf
make: Entering directory '/git/perf-7.1.0-rc2/tools/perf'
BUILD: Doing 'make -j32' parallel build
Makefile.config:647: Warning: Disabled BPF skeletons as libelf is required by bpftool
Makefile.config:745: Disabling post unwind, no support found.
Makefile.config:856: Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ on ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
<SNIP>
LINK/tmp/build/perf/perf/usr/bin/ld:/tmp/build/perf/perf-in.o: in function `work_pop_atom':
builtin-kwork.c:(.text+0x59c92): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functionwork_push_atom.constprop.0':
builtin-kwork.c:(.text+0x5aba8): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functioncmd_kwork':
(.text+0x5bb4b): undefined reference to `work_exit'/usr/bin/ld: (.text+0x5bbae): undefined reference towork_exit' /usr/bin/ld: (.text+0x5c3b2): undefined reference towork_exit'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile.perf:586:/tmp/build/perf/perf] Error 1 make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-7.1.0-rc2/tools/perf'
+ exit 1
toolsbuilder@five:~$Quoted 2 lines
I'm doing some more tests, just a moment and I'll push what I have to tmp.perf-tools-next.
Also:
toolsbuilder@five:~$ cat dm.log/almalinux\:8 <SNIP> OLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugs.almalinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) + make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= -C tools/perf O=/tmp/build/perf make: Entering directory '/git/perf-7.1.0-rc2/tools/perf' BUILD: Doing 'make -j32' parallel build Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1061: No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ OFF ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
CC/tmp/build/perf/dlfilters/dlfilter-test-api-v2.o
<SNIP>COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/cache.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/counter.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/floating-point.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/frontend.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/memory.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/other.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/pipeline.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/virtual-memory.json GEN /tmp/build/perf/pmu-events/test-empty-pmu-events.c Traceback (most recent call last): File "pmu-events/jevents.py", line 1524, in <module> main()Quoted 7 lines
File "
pmu-events/jevents.py", line 1487, in main
withconcurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,))as executor:
TypeError:__init__()got an unexpected keyword argument 'initializer'
make[3]: *** [pmu-events/Build:176:/tmp/build/perf/pmu-events/test-empty-pmu-events.c] Error 1 make[3]: *** Deleting file '/tmp/build/perf/pmu-events/test-empty-pmu-events.c'
make[2]: *** [Makefile.perf:554:/tmp/build/perf/pmu-events/pmu-events-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....But:
Quoted 8 lines
toolsbuilder@five:~$ export BUILD_TARBALL=http://192.168.86.5/perf/perf-7.1.0-rc2.tar.xz toolsbuilder@five:~$ time dm 1 8.77 almalinux:8 : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) 2 84.96 almalinux:9 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-11) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-3.el9) flex 2.6.4 3: 103.23 almalinux:9-i386 : Ok gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3) , clang version 17.0.6 (AlmaLinux OS Foundation 17.0.6-5.el9) flex 2.6.4 4 90.91 almalinux:10 : Ok gcc (GCC) 14.3.1 20250617 (Red Hat 14.3.1-2) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-1.el10.alma.1) flex 2.6.4 5 118.21 alpine:3.16 : Ok gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219 , Alpine clang version 13.0.1 flex 2.6.4 ...
Quoted 2 lines
You can drop the parallelize
jevent.pychanges and I'll follow up. Sorry for the breakage.
It was just that almalinux:8 so far, its an old system, so I'm keeping it to see what other systems fail, if any.
So far:
toolsbuilder@five:~$ export BUILD_TARBALL=http://192.168.86.5/perf/perf-7.1.0-rc2.tar.xz toolsbuilder@five:~$ time dm 1 8.77 almalinux:8 : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) 2 84.96 almalinux:9 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-11) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-3.el9) flex 2.6.4 3: almalinux:9-i386WARNING: image platform (linux/386) does not match the expected platform (linux/amd64) WARNING: image platform (linux/386) does not match the expected platform (linux/amd64) 103.23 almalinux:9-i386 : Ok gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3) , clang version 17.0.6 (AlmaLinux OS Foundation 17.0.6-5.el9) flex 2.6.4 4 90.91 almalinux:10 : Ok gcc (GCC) 14.3.1 20250617 (Red Hat 14.3.1-2) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-1.el10.alma.1) flex 2.6.4 5 118.21 alpine:3.16 : Ok gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219 , Alpine clang version 13.0.1 flex 2.6.4 6 106.13 alpine:3.17 : Ok gcc (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924 , Alpine clang version 15.0.7 flex 2.6.4 7 102.80 alpine:3.18 : Ok gcc (Alpine 12.2.1_git20220924-r10) 12.2.1 20220924 , Alpine clang version 16.0.6 flex 2.6.4 8 114.48 alpine:3.19 : Ok gcc (Alpine 13.2.1_git20231014) 13.2.1 20231014 , Alpine clang version 17.0.5 flex 2.6.4 9 109.53 alpine:3.20 : Ok gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309 , Alpine clang version 17.0.6 flex 2.6.4 10 116.20 alpine:3.22 : Ok gcc (Alpine 14.2.0) 14.2.0 , Alpine clang version 20.1.8 flex 2.6.4 11 109.83 alpine:3.23 : Ok gcc (Alpine 15.2.0) 15.2.0 , Alpine clang version 21.1.2 flex 2.6.4 12 119.23 alpine:edge : Ok gcc (Alpine 14.2.0) 14.2.0 , Alpine clang version 19.1.4 flex 2.6.4 13 93.22 amazonlinux:2023 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5) , clang version 15.0.7 (AWS 15.0.7-3.amzn2023.0.4) flex 2.6.4 14 93.40 amazonlinux:devel : Ok gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4) , clang version 15.0.6 (Amazon Linux 15.0.6-3.amzn2023.0.2) flex 2.6.4 15 102.98 archlinux:base : Ok gcc (GCC) 15.2.1 20250813 , clang version 20.1.8 flex 2.6.4 16 9.58 centos:stream : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-21) (GCC) 17: clearlinux:latest
COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/virtual-memory.json
GEN /tmp/build/perf/pmu-events/test-empty-pmu-events.c
Traceback (most recent call last):
File "pmu-events/jevents.py", line 1524, in <module>
main()
File "pmu-events/jevents.py", line 1487, in main
with concurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,)) as executor:
TypeError: __init__() got an unexpected keyword argument 'initializer'
make[3]: *** [pmu-events/Build:176: /tmp/build/perf/pmu-events/test-empty-pmu-events.c] Error 1 make[3]: *** Deleting file '/tmp/build/perf/pmu-events/test-empty-pmu-events.c'
make[2]: *** [Makefile.perf:554: /tmp/build/perf/pmu-events/pmu-events-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....
Auto-detecting system features:
... clang-bpf-co-re: [ on ] ... llvm: [ on ] ... libcap: [ on ] ... libbfd: [ on ]
MKDIR /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf
centos:stream is the bleeding edge, so I'll drop that as you suggested, ok.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 218 lines · Arnaldo Carvalho de Melo
Quoted 168 lines · Ian Rogers
Quoted 157 lines · Arnaldo Carvalho de Melo
Quoted 145 lines · Arnaldo Carvalho de Melo
Quoted 89 lines · Arnaldo Carvalho de Melo
Quoted 30 lines · Ian Rogers
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 24 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Thanks, tentatively applying it to perf-tools-next, for v7.2.
Had to apply a minor fixup for a conflict with anoter patch series from you, the LBR one.
Sorry for that and thanks for dealing with the conflict! Any chance you could push to tmp.perf-tools-next? I have some other series that will conflict and it would be nice to rebase those changes there.
I just removed the last two patches, the ones for kwork, as:
+ make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= NO_LIBELF=1 -C
tools/perfO=/tmp/build/perf
make: Entering directory '/git/perf-7.1.0-rc2/tools/perf'
BUILD: Doing 'make -j32' parallel build
Makefile.config:647: Warning: Disabled BPF skeletons as libelf is required by bpftool
Makefile.config:745: Disabling post unwind, no support found.
Makefile.config:856: Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ on ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
<SNIP>
LINK/tmp/build/perf/perf/usr/bin/ld:/tmp/build/perf/perf-in.o: in function `work_pop_atom':
builtin-kwork.c:(.text+0x59c92): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functionwork_push_atom.constprop.0':
builtin-kwork.c:(.text+0x5aba8): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functioncmd_kwork':
(.text+0x5bb4b): undefined reference to `work_exit'/usr/bin/ld: (.text+0x5bbae): undefined reference towork_exit' /usr/bin/ld: (.text+0x5c3b2): undefined reference towork_exit'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile.perf:586:/tmp/build/perf/perf] Error 1 make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-7.1.0-rc2/tools/perf'
+ exit 1
toolsbuilder@five:~$Quoted 2 lines
I'm doing some more tests, just a moment and I'll push what I have to tmp.perf-tools-next.
Also:
toolsbuilder@five:~$ cat dm.log/almalinux\:8 <SNIP> OLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugs.almalinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) + make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= -C tools/perf O=/tmp/build/perf make: Entering directory '/git/perf-7.1.0-rc2/tools/perf' BUILD: Doing 'make -j32' parallel build Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1061: No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ OFF ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
CC/tmp/build/perf/dlfilters/dlfilter-test-api-v2.o
<SNIP>COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/cache.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/counter.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/floating-point.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/frontend.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/memory.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/other.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/pipeline.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/virtual-memory.json GEN /tmp/build/perf/pmu-events/test-empty-pmu-events.c Traceback (most recent call last): File "pmu-events/jevents.py", line 1524, in <module> main()Quoted 7 lines
File "
pmu-events/jevents.py", line 1487, in main
withconcurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,))as executor:
TypeError:__init__()got an unexpected keyword argument 'initializer'
make[3]: *** [pmu-events/Build:176:/tmp/build/perf/pmu-events/test-empty-pmu-events.c] Error 1 make[3]: *** Deleting file '/tmp/build/perf/pmu-events/test-empty-pmu-events.c'
make[2]: *** [Makefile.perf:554:/tmp/build/perf/pmu-events/pmu-events-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....But:
Quoted 8 lines
toolsbuilder@five:~$ export BUILD_TARBALL=http://192.168.86.5/perf/perf-7.1.0-rc2.tar.xz toolsbuilder@five:~$ time dm 1 8.77 almalinux:8 : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) 2 84.96 almalinux:9 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-11) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-3.el9) flex 2.6.4 3: 103.23 almalinux:9-i386 : Ok gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3) , clang version 17.0.6 (AlmaLinux OS Foundation 17.0.6-5.el9) flex 2.6.4 4 90.91 almalinux:10 : Ok gcc (GCC) 14.3.1 20250617 (Red Hat 14.3.1-2) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-1.el10.alma.1) flex 2.6.4 5 118.21 alpine:3.16 : Ok gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219 , Alpine clang version 13.0.1 flex 2.6.4 ...Quoted 2 lines
You can drop the parallelize
jevent.pychanges and I'll follow up. Sorry for the breakage.It was just that almalinux:8 so far, its an old system, so I'm keeping it to see what other systems fail, if any.
So far:
toolsbuilder@five:~$ export BUILD_TARBALL=http://192.168.86.5/perf/perf-7.1.0-rc2.tar.xz toolsbuilder@five:~$ time dm 1 8.77 almalinux:8 : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) 2 84.96 almalinux:9 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-11) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-3.el9) flex 2.6.4 3: almalinux:9-i386WARNING: image platform (linux/386) does not match the expected platform (linux/amd64) WARNING: image platform (linux/386) does not match the expected platform (linux/amd64) 103.23 almalinux:9-i386 : Ok gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3) , clang version 17.0.6 (AlmaLinux OS Foundation 17.0.6-5.el9) flex 2.6.4 4 90.91 almalinux:10 : Ok gcc (GCC) 14.3.1 20250617 (Red Hat 14.3.1-2) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-1.el10.alma.1) flex 2.6.4 5 118.21 alpine:3.16 : Ok gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219 , Alpine clang version 13.0.1 flex 2.6.4 6 106.13 alpine:3.17 : Ok gcc (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924 , Alpine clang version 15.0.7 flex 2.6.4 7 102.80 alpine:3.18 : Ok gcc (Alpine 12.2.1_git20220924-r10) 12.2.1 20220924 , Alpine clang version 16.0.6 flex 2.6.4 8 114.48 alpine:3.19 : Ok gcc (Alpine 13.2.1_git20231014) 13.2.1 20231014 , Alpine clang version 17.0.5 flex 2.6.4 9 109.53 alpine:3.20 : Ok gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309 , Alpine clang version 17.0.6 flex 2.6.4 10 116.20 alpine:3.22 : Ok gcc (Alpine 14.2.0) 14.2.0 , Alpine clang version 20.1.8 flex 2.6.4 11 109.83 alpine:3.23 : Ok gcc (Alpine 15.2.0) 15.2.0 , Alpine clang version 21.1.2 flex 2.6.4 12 119.23 alpine:edge : Ok gcc (Alpine 14.2.0) 14.2.0 , Alpine clang version 19.1.4 flex 2.6.4 13 93.22 amazonlinux:2023 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5) , clang version 15.0.7 (AWS 15.0.7-3.amzn2023.0.4) flex 2.6.4 14 93.40 amazonlinux:devel : Ok gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4) , clang version 15.0.6 (Amazon Linux 15.0.6-3.amzn2023.0.2) flex 2.6.4 15 102.98 archlinux:base : Ok gcc (GCC) 15.2.1 20250813 , clang version 20.1.8 flex 2.6.4 16 9.58 centos:stream : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-21) (GCC) 17: clearlinux:latestCOPY
/tmp/build/perf/<-pmu-events/arch/x86/westmereex/virtual-memory.json
GEN/tmp/build/perf/pmu-events/test-empty-pmu-events.c
Traceback (most recent call last):
File "pmu-events/jevents.py", line 1524, in <module>main()File "
pmu-events/jevents.py", line 1487, in main
withconcurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,))as executor:
TypeError:__init__()got an unexpected keyword argument 'initializer'
make[3]: *** [pmu-events/Build:176:/tmp/build/perf/pmu-events/test-empty-pmu-events.c] Error 1 make[3]: *** Deleting file '/tmp/build/perf/pmu-events/test-empty-pmu-events.c'
make[2]: *** [Makefile.perf:554:/tmp/build/perf/pmu-events/pmu-events-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....Auto-detecting system features:
... clang-bpf-co-re: [ on ] ... llvm: [ on ] ... libcap: [ on ] ... libbfd: [ on ]
Quoted 5 lines
MKDIR
/tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpfcentos:stream is the bleeding edge, so I'll drop that as you suggested, ok.
So I removed these, i.e. from the parallelize onwards:
28 O T May 18 Ian Rogers ( 43) │ ├─>[PATCH v7 14/14] perf build: Convert llvm-config shell queries to simply expanded variables 29 O T May 18 Ian Rogers ( 62) │ ├─>[PATCH v7 13/14] perf pmu-events: Convert recursive shell assignments and macros to Make built-ins 30 O T May 18 Ian Rogers ( 47) │ ├─>[PATCH v7 12/14] perf build: Prefix SCRIPTS with output directory to fix continuous rebuilds 31 O T May 18 Ian Rogers ( 97) │ ├─>[PATCH v7 11/14] perf pmu-events: Parallelize JSON and metric pre-computation in jevents.py
Ian Rogers
reviewerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 220 lines · Arnaldo Carvalho de Melo
Quoted 218 lines · Arnaldo Carvalho de Melo
Quoted 168 lines · Ian Rogers
Quoted 157 lines · Arnaldo Carvalho de Melo
Quoted 145 lines · Arnaldo Carvalho de Melo
Quoted 89 lines · Arnaldo Carvalho de Melo
Quoted 30 lines · Ian Rogers
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 24 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Thanks, tentatively applying it to perf-tools-next, for v7.2.
Had to apply a minor fixup for a conflict with anoter patch series from you, the LBR one.
Sorry for that and thanks for dealing with the conflict! Any chance you could push to tmp.perf-tools-next? I have some other series that will conflict and it would be nice to rebase those changes there.
I just removed the last two patches, the ones for kwork, as:
+ make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= NO_LIBELF=1 -C
tools/perfO=/tmp/build/perf
make: Entering directory '/git/perf-7.1.0-rc2/tools/perf'
BUILD: Doing 'make -j32' parallel build
Makefile.config:647: Warning: Disabled BPF skeletons as libelf is required by bpftool
Makefile.config:745: Disabling post unwind, no support found.
Makefile.config:856: Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ on ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
<SNIP>
LINK/tmp/build/perf/perf/usr/bin/ld:/tmp/build/perf/perf-in.o: in function `work_pop_atom':
builtin-kwork.c:(.text+0x59c92): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functionwork_push_atom.constprop.0':
builtin-kwork.c:(.text+0x5aba8): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functioncmd_kwork':
(.text+0x5bb4b): undefined reference to `work_exit'/usr/bin/ld: (.text+0x5bbae): undefined reference towork_exit' /usr/bin/ld: (.text+0x5c3b2): undefined reference towork_exit'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile.perf:586:/tmp/build/perf/perf] Error 1 make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-7.1.0-rc2/tools/perf'
+ exit 1
toolsbuilder@five:~$Quoted 2 lines
I'm doing some more tests, just a moment and I'll push what I have to tmp.perf-tools-next.
Also:
toolsbuilder@five:~$ cat dm.log/almalinux\:8 <SNIP> OLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugs.almalinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) + make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= -C tools/perf O=/tmp/build/perf make: Entering directory '/git/perf-7.1.0-rc2/tools/perf' BUILD: Doing 'make -j32' parallel build Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1061: No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ OFF ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
CC/tmp/build/perf/dlfilters/dlfilter-test-api-v2.o
<SNIP>COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/cache.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/counter.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/floating-point.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/frontend.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/memory.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/other.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/pipeline.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/virtual-memory.json GEN /tmp/build/perf/pmu-events/test-empty-pmu-events.c Traceback (most recent call last): File "pmu-events/jevents.py", line 1524, in <module> main()Quoted 7 lines
File "
pmu-events/jevents.py", line 1487, in main
withconcurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,))as executor:
TypeError:__init__()got an unexpected keyword argument 'initializer'
make[3]: *** [pmu-events/Build:176:/tmp/build/perf/pmu-events/test-empty-pmu-events.c] Error 1 make[3]: *** Deleting file '/tmp/build/perf/pmu-events/test-empty-pmu-events.c'
make[2]: *** [Makefile.perf:554:/tmp/build/perf/pmu-events/pmu-events-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....But:
Quoted 8 lines
toolsbuilder@five:~$ export BUILD_TARBALL=http://192.168.86.5/perf/perf-7.1.0-rc2.tar.xz toolsbuilder@five:~$ time dm 1 8.77 almalinux:8 : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) 2 84.96 almalinux:9 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-11) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-3.el9) flex 2.6.4 3: 103.23 almalinux:9-i386 : Ok gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3) , clang version 17.0.6 (AlmaLinux OS Foundation 17.0.6-5.el9) flex 2.6.4 4 90.91 almalinux:10 : Ok gcc (GCC) 14.3.1 20250617 (Red Hat 14.3.1-2) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-1.el10.alma.1) flex 2.6.4 5 118.21 alpine:3.16 : Ok gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219 , Alpine clang version 13.0.1 flex 2.6.4 ...Quoted 2 lines
You can drop the parallelize
jevent.pychanges and I'll follow up. Sorry for the breakage.It was just that almalinux:8 so far, its an old system, so I'm keeping it to see what other systems fail, if any.
So far:
toolsbuilder@five:~$ export BUILD_TARBALL=http://192.168.86.5/perf/perf-7.1.0-rc2.tar.xz toolsbuilder@five:~$ time dm 1 8.77 almalinux:8 : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) 2 84.96 almalinux:9 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-11) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-3.el9) flex 2.6.4 3: almalinux:9-i386WARNING: image platform (linux/386) does not match the expected platform (linux/amd64) WARNING: image platform (linux/386) does not match the expected platform (linux/amd64) 103.23 almalinux:9-i386 : Ok gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3) , clang version 17.0.6 (AlmaLinux OS Foundation 17.0.6-5.el9) flex 2.6.4 4 90.91 almalinux:10 : Ok gcc (GCC) 14.3.1 20250617 (Red Hat 14.3.1-2) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-1.el10.alma.1) flex 2.6.4 5 118.21 alpine:3.16 : Ok gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219 , Alpine clang version 13.0.1 flex 2.6.4 6 106.13 alpine:3.17 : Ok gcc (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924 , Alpine clang version 15.0.7 flex 2.6.4 7 102.80 alpine:3.18 : Ok gcc (Alpine 12.2.1_git20220924-r10) 12.2.1 20220924 , Alpine clang version 16.0.6 flex 2.6.4 8 114.48 alpine:3.19 : Ok gcc (Alpine 13.2.1_git20231014) 13.2.1 20231014 , Alpine clang version 17.0.5 flex 2.6.4 9 109.53 alpine:3.20 : Ok gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309 , Alpine clang version 17.0.6 flex 2.6.4 10 116.20 alpine:3.22 : Ok gcc (Alpine 14.2.0) 14.2.0 , Alpine clang version 20.1.8 flex 2.6.4 11 109.83 alpine:3.23 : Ok gcc (Alpine 15.2.0) 15.2.0 , Alpine clang version 21.1.2 flex 2.6.4 12 119.23 alpine:edge : Ok gcc (Alpine 14.2.0) 14.2.0 , Alpine clang version 19.1.4 flex 2.6.4 13 93.22 amazonlinux:2023 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5) , clang version 15.0.7 (AWS 15.0.7-3.amzn2023.0.4) flex 2.6.4 14 93.40 amazonlinux:devel : Ok gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4) , clang version 15.0.6 (Amazon Linux 15.0.6-3.amzn2023.0.2) flex 2.6.4 15 102.98 archlinux:base : Ok gcc (GCC) 15.2.1 20250813 , clang version 20.1.8 flex 2.6.4 16 9.58 centos:stream : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-21) (GCC) 17: clearlinux:latestCOPY
/tmp/build/perf/<-pmu-events/arch/x86/westmereex/virtual-memory.json
GEN/tmp/build/perf/pmu-events/test-empty-pmu-events.c
Traceback (most recent call last):
File "pmu-events/jevents.py", line 1524, in <module>main()File "
pmu-events/jevents.py", line 1487, in main
withconcurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,))as executor:
TypeError:__init__()got an unexpected keyword argument 'initializer'
make[3]: *** [pmu-events/Build:176:/tmp/build/perf/pmu-events/test-empty-pmu-events.c] Error 1 make[3]: *** Deleting file '/tmp/build/perf/pmu-events/test-empty-pmu-events.c'
make[2]: *** [Makefile.perf:554:/tmp/build/perf/pmu-events/pmu-events-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....Auto-detecting system features:
... clang-bpf-co-re: [ on ] ... llvm: [ on ] ... libcap: [ on ] ... libbfd: [ on ]
Quoted 5 lines
Quoted 5 lines
MKDIR
/tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpfcentos:stream is the bleeding edge, so I'll drop that as you suggested, ok.
Sgtm. I'm confused though, something old and something new broke? In the "Minimal requirements to compile the Kernel"
(https://www.kernel.org/doc/html/latest/process/changes.html) they state Python must be version 3.9, so it'd be nice to set that as the baseline wrt APIs. We could probably automate that in the build and make the build NO_PYTHON if the version is older than 3.9.
Quoted 7 lines
So I removed these, i.e. from the parallelize onwards:
28 O T May 18 Ian Rogers ( 43) │ ├─>[PATCH v7 14/14] perf build: Convert llvm-config shell queries to simply expanded variables 29 O T May 18 Ian Rogers ( 62) │ ├─>[PATCH v7 13/14] perf pmu-events: Convert recursive shell assignments and macros to Make built-ins 30 O T May 18 Ian Rogers ( 47) │ ├─>[PATCH v7 12/14] perf build: Prefix SCRIPTS with output directory to fix continuous rebuilds 31 O T May 18 Ian Rogers ( 97) │ ├─>[PATCH v7 11/14] perf pmu-events: Parallelize JSON and metric pre-computation in jevents.py
Could we keep 12, 13 and 14? They are independent changes and offer significant build performance improvements.
Thanks,
Ian
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 237 lines · Ian Rogers
Quoted 220 lines · Arnaldo Carvalho de Melo
Quoted 218 lines · Arnaldo Carvalho de Melo
Quoted 168 lines · Ian Rogers
Quoted 157 lines · Arnaldo Carvalho de Melo
Quoted 145 lines · Arnaldo Carvalho de Melo
Quoted 89 lines · Arnaldo Carvalho de Melo
Quoted 30 lines · Ian Rogers
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 24 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Thanks, tentatively applying it to perf-tools-next, for v7.2.
Had to apply a minor fixup for a conflict with anoter patch series from you, the LBR one.
Sorry for that and thanks for dealing with the conflict! Any chance you could push to tmp.perf-tools-next? I have some other series that will conflict and it would be nice to rebase those changes there.
I just removed the last two patches, the ones for kwork, as:
+ make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= NO_LIBELF=1 -C
tools/perfO=/tmp/build/perf
make: Entering directory '/git/perf-7.1.0-rc2/tools/perf'
BUILD: Doing 'make -j32' parallel build
Makefile.config:647: Warning: Disabled BPF skeletons as libelf is required by bpftool
Makefile.config:745: Disabling post unwind, no support found.
Makefile.config:856: Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ on ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
<SNIP>
LINK/tmp/build/perf/perf/usr/bin/ld:/tmp/build/perf/perf-in.o: in function `work_pop_atom':
builtin-kwork.c:(.text+0x59c92): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functionwork_push_atom.constprop.0':
builtin-kwork.c:(.text+0x5aba8): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functioncmd_kwork':
(.text+0x5bb4b): undefined reference to `work_exit'/usr/bin/ld: (.text+0x5bbae): undefined reference towork_exit' /usr/bin/ld: (.text+0x5c3b2): undefined reference towork_exit'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile.perf:586:/tmp/build/perf/perf] Error 1 make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-7.1.0-rc2/tools/perf'
+ exit 1
toolsbuilder@five:~$Quoted 2 lines
I'm doing some more tests, just a moment and I'll push what I have to tmp.perf-tools-next.
Also:
toolsbuilder@five:~$ cat dm.log/almalinux\:8 <SNIP> OLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugs.almalinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) + make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= -C tools/perf O=/tmp/build/perf make: Entering directory '/git/perf-7.1.0-rc2/tools/perf' BUILD: Doing 'make -j32' parallel build Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1061: No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ OFF ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
CC/tmp/build/perf/dlfilters/dlfilter-test-api-v2.o
<SNIP>COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/cache.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/counter.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/floating-point.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/frontend.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/memory.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/other.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/pipeline.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/virtual-memory.json GEN /tmp/build/perf/pmu-events/test-empty-pmu-events.c Traceback (most recent call last): File "pmu-events/jevents.py", line 1524, in <module> main()Quoted 7 lines
File "
pmu-events/jevents.py", line 1487, in main
withconcurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,))as executor:
TypeError:__init__()got an unexpected keyword argument 'initializer'
make[3]: *** [pmu-events/Build:176:/tmp/build/perf/pmu-events/test-empty-pmu-events.c] Error 1 make[3]: *** Deleting file '/tmp/build/perf/pmu-events/test-empty-pmu-events.c'
make[2]: *** [Makefile.perf:554:/tmp/build/perf/pmu-events/pmu-events-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....But:
Quoted 8 lines
toolsbuilder@five:~$ export BUILD_TARBALL=http://192.168.86.5/perf/perf-7.1.0-rc2.tar.xz toolsbuilder@five:~$ time dm 1 8.77 almalinux:8 : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) 2 84.96 almalinux:9 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-11) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-3.el9) flex 2.6.4 3: 103.23 almalinux:9-i386 : Ok gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3) , clang version 17.0.6 (AlmaLinux OS Foundation 17.0.6-5.el9) flex 2.6.4 4 90.91 almalinux:10 : Ok gcc (GCC) 14.3.1 20250617 (Red Hat 14.3.1-2) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-1.el10.alma.1) flex 2.6.4 5 118.21 alpine:3.16 : Ok gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219 , Alpine clang version 13.0.1 flex 2.6.4 ...Quoted 2 lines
You can drop the parallelize
jevent.pychanges and I'll follow up. Sorry for the breakage.It was just that almalinux:8 so far, its an old system, so I'm keeping it to see what other systems fail, if any.
So far:
toolsbuilder@five:~$ export BUILD_TARBALL=http://192.168.86.5/perf/perf-7.1.0-rc2.tar.xz toolsbuilder@five:~$ time dm 1 8.77 almalinux:8 : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) 2 84.96 almalinux:9 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-11) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-3.el9) flex 2.6.4 3: almalinux:9-i386WARNING: image platform (linux/386) does not match the expected platform (linux/amd64) WARNING: image platform (linux/386) does not match the expected platform (linux/amd64) 103.23 almalinux:9-i386 : Ok gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3) , clang version 17.0.6 (AlmaLinux OS Foundation 17.0.6-5.el9) flex 2.6.4 4 90.91 almalinux:10 : Ok gcc (GCC) 14.3.1 20250617 (Red Hat 14.3.1-2) , clang version 20.1.8 (AlmaLinux OS Foundation 20.1.8-1.el10.alma.1) flex 2.6.4 5 118.21 alpine:3.16 : Ok gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219 , Alpine clang version 13.0.1 flex 2.6.4 6 106.13 alpine:3.17 : Ok gcc (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924 , Alpine clang version 15.0.7 flex 2.6.4 7 102.80 alpine:3.18 : Ok gcc (Alpine 12.2.1_git20220924-r10) 12.2.1 20220924 , Alpine clang version 16.0.6 flex 2.6.4 8 114.48 alpine:3.19 : Ok gcc (Alpine 13.2.1_git20231014) 13.2.1 20231014 , Alpine clang version 17.0.5 flex 2.6.4 9 109.53 alpine:3.20 : Ok gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309 , Alpine clang version 17.0.6 flex 2.6.4 10 116.20 alpine:3.22 : Ok gcc (Alpine 14.2.0) 14.2.0 , Alpine clang version 20.1.8 flex 2.6.4 11 109.83 alpine:3.23 : Ok gcc (Alpine 15.2.0) 15.2.0 , Alpine clang version 21.1.2 flex 2.6.4 12 119.23 alpine:edge : Ok gcc (Alpine 14.2.0) 14.2.0 , Alpine clang version 19.1.4 flex 2.6.4 13 93.22 amazonlinux:2023 : Ok gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5) , clang version 15.0.7 (AWS 15.0.7-3.amzn2023.0.4) flex 2.6.4 14 93.40 amazonlinux:devel : Ok gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4) , clang version 15.0.6 (Amazon Linux 15.0.6-3.amzn2023.0.2) flex 2.6.4 15 102.98 archlinux:base : Ok gcc (GCC) 15.2.1 20250813 , clang version 20.1.8 flex 2.6.4 16 9.58 centos:stream : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-21) (GCC) 17: clearlinux:latestCOPY
/tmp/build/perf/<-pmu-events/arch/x86/westmereex/virtual-memory.json
GEN/tmp/build/perf/pmu-events/test-empty-pmu-events.c
Traceback (most recent call last):
File "pmu-events/jevents.py", line 1524, in <module>main()File "
pmu-events/jevents.py", line 1487, in main
withconcurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,))as executor:
TypeError:__init__()got an unexpected keyword argument 'initializer'
make[3]: *** [pmu-events/Build:176:/tmp/build/perf/pmu-events/test-empty-pmu-events.c] Error 1 make[3]: *** Deleting file '/tmp/build/perf/pmu-events/test-empty-pmu-events.c'
make[2]: *** [Makefile.perf:554:/tmp/build/perf/pmu-events/pmu-events-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....Auto-detecting system features:
... clang-bpf-co-re: [ on ] ... llvm: [ on ] ... libcap: [ on ] ... libbfd: [ on ]Quoted 5 lines
Quoted 5 lines
MKDIR
/tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpfcentos:stream is the bleeding edge, so I'll drop that as you suggested, ok.
Sgtm. I'm confused though, something old and something new broke? In the "Minimal requirements to compile the Kernel"
(https://www.kernel.org/doc/html/latest/process/changes.html) they state Python must be version 3.9, so it'd be nice to set that as the baseline wrt APIs. We could probably automate that in the build and make the buildNO_PYTHONif the version is older than 3.9.Quoted 2 lines
So I removed these, i.e. from the parallelize onwards:
Quoted 8 lines
Quoted 5 lines
28 O T May 18 Ian Rogers ( 43) │ ├─>[PATCH v7 14/14] perf build: Convert llvm-config shell queries to simply expanded variables 29 O T May 18 Ian Rogers ( 62) │ ├─>[PATCH v7 13/14] perf pmu-events: Convert recursive shell assignments and macros to Make built-ins 30 O T May 18 Ian Rogers ( 47) │ ├─>[PATCH v7 12/14] perf build: Prefix SCRIPTS with output directory to fix continuous rebuilds 31 O T May 18 Ian Rogers ( 97) │ ├─>[PATCH v7 11/14] perf pmu-events: Parallelize JSON and metric pre-computation in jevents.pyCould we keep 12, 13 and 14? They are independent changes and offer significant build performance improvements.
Lemme try cherry picking them then. I removed without checking if there were any deps.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Everything is at
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git tmp.perf-tools-next
I also rebased my perf.data validation (that has some extra fixes, because... Sashiko):
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-data-validation
I think I addressed some of your review comments, if bored, take a look, I'll submit as soon as I get what is in tmp.perf-tools-next moved to perf-tools-next which I plan/hope to do later today, after the container build tests finish.
- Arnaldo
Ian Rogers
reviewerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 6 lines · Arnaldo Carvalho de Melo
Everything is at
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git tmp.perf-tools-next
Quoted 8 lines
I also rebased my perf.data validation (that has some extra fixes, because... Sashiko):
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-data-validation
I think I addressed some of your review comments, if bored, take a look, I'll submit as soon as I get what is in tmp.perf-tools-next moved to perf-tools-next which I plan/hope to do later today, after the container build tests finish.
I'll look at the perf-data-validation branch. Would it be okay to post the patches to LKML so that we can get the Sashiko review on them?
Thanks,
Ian
Quoted 1 line
- Arnaldo
Ian Rogers
reviewerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 13 lines · Ian Rogers
Quoted 10 lines · Arnaldo Carvalho de Melo
Everything is at
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git tmp.perf-tools-next
I also rebased my perf.data validation (that has some extra fixes, because... Sashiko):
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-data-validation
Quoted 7 lines
Quoted 4 lines
I think I addressed some of your review comments, if bored, take a look, I'll submit as soon as I get what is in tmp.perf-tools-next moved to perf-tools-next which I plan/hope to do later today, after the container build tests finish.
I'll look at the perf-data-validation branch. Would it be okay to post the patches to LKML so that we can get the Sashiko review on them?
In "perf session: Bound nr_cpus_avail and validate sample CPU" the perf_session__deliver_event change appears to inline evlist__parse_sample which seems unfortunate from a code reuse point-of-view. The commit message calls this out but doesn't describe the motivation for the change. Could we fix evlist__parse_sample?
Thanks,
Ian
Quoted 4 lines
Thanks,
IanQuoted 1 line
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
Quoted 9 lines · Ian Rogers
Quoted 2 lines · Ian Rogers
I'll look at the perf-data-validation branch. Would it be okay to post the patches to LKML so that we can get the Sashiko review on them?
In "perf session: Bound
nr_cpus_availand validate sample CPU" theperf_session__deliver_eventchange appears to inlineevlist__parse_samplewhich seems unfortunate from a code reuse point-of-view. The commit message calls this out but doesn't describe the motivation for the change. Could we fixevlist__parse_sample?
The motivation:
18 -Also refactor the sample parsing in perf_session__deliver_event() 19 -to call evsel__parse_sample() directly (via evlist__event2evsel() 20 -for evsel lookup), with explicit guest VM SID resolution for 21 -machine_pid and vcpu fields.
18 +Inline evlist__parse_sample() into perf_session__deliver_event() 19 +so the evsel lookup needed for sample_type checking reuses the same 20 +evsel that parsed the sample, avoiding a second evlist__event2evsel() 21 +call on every event.
A follow up patch could introduce a evlist__parse_sample variation that passes a evsel pointer address where to store the evsel used so that it can be reused and avoid the duplicate lookup.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
In reply to Ian RogersQuoted 12 lines · Ian Rogers
Quoted 10 lines · Arnaldo Carvalho de Melo
Everything is at
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git tmp.perf-tools-next
I also rebased my perf.data validation (that has some extra fixes, because... Sashiko):
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-data-validation
Quoted 7 lines
Quoted 4 lines
I think I addressed some of your review comments, if bored, take a look, I'll submit as soon as I get what is in tmp.perf-tools-next moved to perf-tools-next which I plan/hope to do later today, after the container build tests finish.
I'll look at the perf-data-validation branch. Would it be okay to post the patches to LKML so that we can get the Sashiko review on them?
I did it, and having passed thru sashiko locally dozens of times it ended up being rather clean :-)
I'm addressing some of the valid concerns raised now and will send a v2.
- Arnaldo
Ian Rogers
reviewerRe: [PATCH v14 00/32] perf tools: Add evsel to perf_sample
In reply to Arnaldo Carvalho de MeloQuoted 146 lines · Arnaldo Carvalho de Melo
Quoted 89 lines · Arnaldo Carvalho de Melo
Quoted 30 lines · Ian Rogers
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 24 lines · Ian Rogers
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) because all uses of the evsel need to be fixed up. Since theperf_samplenow carries its own resolved evsel pointer, passing evsel separately is redundant and error-prone (allowing parameter divergence bugs).This series cleans up the redundant evsel parameter across all perf tool subcommands and APIs, ensuring that tools uniformly retrieve event attributes directly from the sample itself. This simplifies function signatures and improves API consistency.
Additionally, this series incorporates subsequent memory safety improvements, robust bounds checking, and memory leak corrections prompted by address sanitizers and Sashiko code reviews.
The original combined RFC patch:
https://lore.kernel.org/lkml/[email protected]/
was split up per reviewer requests.v14:
- Incorporate Acked-by tags from Namhyung Kim.
- Re-polish and expand commit descriptions to provide thorough explanations of the changes and their rationale.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Thanks, tentatively applying it to perf-tools-next, for v7.2.
Had to apply a minor fixup for a conflict with anoter patch series from you, the LBR one.
Sorry for that and thanks for dealing with the conflict! Any chance you could push to tmp.perf-tools-next? I have some other series that will conflict and it would be nice to rebase those changes there.
I just removed the last two patches, the ones for kwork, as:
+ make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= NO_LIBELF=1 -C
tools/perfO=/tmp/build/perf
make: Entering directory '/git/perf-7.1.0-rc2/tools/perf'
BUILD: Doing 'make -j32' parallel build
Makefile.config:647: Warning: Disabled BPF skeletons as libelf is required by bpftool
Makefile.config:745: Disabling post unwind, no support found.
Makefile.config:856: Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ on ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
<SNIP>
LINK/tmp/build/perf/perf/usr/bin/ld:/tmp/build/perf/perf-in.o: in function `work_pop_atom':
builtin-kwork.c:(.text+0x59c92): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functionwork_push_atom.constprop.0':
builtin-kwork.c:(.text+0x5aba8): undefined reference towork_exit' /usr/bin/ld: /tmp/build/perf/perf-in.o: in functioncmd_kwork':
(.text+0x5bb4b): undefined reference to `work_exit'/usr/bin/ld: (.text+0x5bbae): undefined reference towork_exit' /usr/bin/ld: (.text+0x5c3b2): undefined reference towork_exit'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile.perf:586:/tmp/build/perf/perf] Error 1 make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-7.1.0-rc2/tools/perf'
+ exit 1
toolsbuilder@five:~$Quoted 2 lines
I'm doing some more tests, just a moment and I'll push what I have to tmp.perf-tools-next.
Also:
toolsbuilder@five:~$ cat dm.log/almalinux\:8 <SNIP> OLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugs.almalinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 8.5.0 20210514 (Red Hat 8.5.0-28) (GCC) + make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= -C tools/perf O=/tmp/build/perf make: Entering directory '/git/perf-7.1.0-rc2/tools/perf' BUILD: Doing 'make -j32' parallel build Makefile.config:1045: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1061: No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel Makefile.config:1110: libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev Makefile.config:1135: Rust is not found. Test workloads with rust are disabled.Auto-detecting system features:
... libdw: [ on ] ... glibc: [ on ] ... libelf: [ on ] ... libnuma: [ on ] ... numa_num_possible_cpus: [ on ] ... libpython: [ on ] ... libcapstone: [ OFF ] ... llvm-perf: [ on ] ... zlib: [ on ] ... lzma: [ on ] ... bpf: [ on ] ... libaio: [ on ] ... libzstd: [ on ] ... libopenssl: [ on ]... rust: [ OFF ]
CC
/tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
CC/tmp/build/perf/dlfilters/dlfilter-test-api-v2.o
<SNIP>COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/cache.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/counter.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/floating-point.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/frontend.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/memory.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/other.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/pipeline.json COPY /tmp/build/perf/ <- pmu-events/arch/x86/westmereex/virtual-memory.json GEN /tmp/build/perf/pmu-events/test-empty-pmu-events.c Traceback (most recent call last): File "pmu-events/jevents.py", line 1524, in <module> main()
Quoted 3 lines
File "
pmu-events/jevents.py", line 1487, in main
withconcurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,))as executor:
TypeError:__init__()got an unexpected keyword argument 'initializer'
The initializer and initargs parameters were added to concurrent.futures.ProcessPoolExecutor.futures.ProcessPoolExecutor in Python 3.7. Python 3.7 is past its end of life and the kernel build specified that Python 3.9 is the minimum supported:
https://docs.kernel.org/process/changes.html
A fix for this is to disable jevents for older Python versions, but detecting this will incur a build-time cost.
Thanks,
Ian
Quoted 5 lines
make[3]: *** [pmu-events/Build:176:
/tmp/build/perf/pmu-events/test-empty-pmu-events.c] Error 1 make[3]: *** Deleting file '/tmp/build/perf/pmu-events/test-empty-pmu-events.c' make[2]: *** [Makefile.perf:554:/tmp/build/perf/pmu-events/pmu-events-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
Ian Rogers
reviewerQuoted 19 lines · Namhyung Kim
Quoted 17 lines · Namhyung Kim
Quoted 15 lines · Ian Rogers
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/[email protected]/
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 structperf_sampleand 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.
Quoted 4 lines
Quoted 2 lines
I'll test and process the first 3 patches first as I found an issue in patch 6 and I guess applying patch 4 would break partial imports later.
Applied the first 3 patches to perf-tools-next, thanks!
It looks like you tweaked the documentation of struct perf_sample. There is a typo s/PEF_SAMPLE_IDENTIFIER/PERF_SAMPLE_IDENTIFIER/.
Thanks,
Ian
Quoted 3 lines
Best regards,
Namhyung
Namhyung Kim
maintainerQuoted 20 lines · Ian Rogers
Quoted 19 lines · Namhyung Kim
Quoted 17 lines · Namhyung Kim
Quoted 15 lines · Ian Rogers
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/[email protected]/
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 structperf_sampleand 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.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I'll test and process the first 3 patches first as I found an issue in patch 6 and I guess applying patch 4 would break partial imports later.
Applied the first 3 patches to perf-tools-next, thanks!
It looks like you tweaked the documentation of struct
perf_sample. There is a typo s/PEF_SAMPLE_IDENTIFIER/PERF_SAMPLE_IDENTIFIER/.
Oops, sorry. Yeah, I think it's in my earlier review and forgotten. So I did it myself but made a mistake. :(
Feel free to send a fix.
Thanks,
Namhyung