From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3B74379964 for ; Fri, 3 Apr 2026 20:40:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248830; cv=none; b=TthjC28XayixhIZT5pEHTAP0c1astz/kyD0Ao0X25Q63W8GijRN+e6nx7qb59CA796O8Ff+LcmQsZh5uomsru7uA2uEgIrcXQfmetI8/Xay9+polkVPwMJQQtWcSjAodr9rlUsC4OhOi5BBUtMThOyyEc5A7g1LOqY8TV5iHzh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248830; c=relaxed/simple; bh=LJ0rCMMxmzCEmLBaFftojzkhfuDC5lZaRit25xvqCjQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PEa1y9dnXWFx6xlC8ujNXiHbcS+X9vOOtavkQb343VsMV4R+xwaRWgE1rtCO5upVDFSBqo8zOp4fGAFMg71ipW9magN4HXv8ANdJ+f2FUQbRv3GsqP+RjFlrBATLPjKi/q5C8GOmqoQnJVhSR6Df2L8MBVBI1f8yOEz6JpJ9VW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HrsfPWEK; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HrsfPWEK" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2c16233ee11so3260911eec.1 for ; Fri, 03 Apr 2026 13:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248827; x=1775853627; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0EJppbfK+NrXWp6WattbotTNCAPlbqRovRFGgZkVK3U=; b=HrsfPWEK3IOXyMR03X4OWQvmQBeE0TGyMAL0FBPza51WYuRjytR1xRvWOMX83rItIN mH8RrYCbVv0YlS/5z/p1VWhBypgXi7c60EDJ48ELg4kNzKBN5b3MStqiJvULSi5T6izw afBNkTs8YGU9NbxzYnBMJZVmQGZ0xy+CIhh9JG20s4gDofB3dotNo6xJDm7POwhuqd7/ Bb34uzKL+c2gMMlMWU3lTSIm4xV/+qFevNPHC3Kt1nB+/1Hn69GVxoxTivb12R+UK5Jk Qlqm/aMh9wSJyylcD2MpzrDvd4ywQzLm/VNMsg8Q6pC1RSk+SUIZK3uQooKVqN+QqtlN Z+GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248827; x=1775853627; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0EJppbfK+NrXWp6WattbotTNCAPlbqRovRFGgZkVK3U=; b=fZAhlwmmqWTc1+Y03mxdX7LDKo3MtROCCqx/Yej/kmGq0aK/X3h0mVDOBxP7v4LXaD dapucFsk8f8Ex6k42k1hHWjWenkPUw1B0D8j5J6GvFEZLk7o/DB0gPibOFpTTMBJjYk7 8AU9OwCk6OVbda/JcLCW5eOj76bpQDtXzVRR8refHXRSbFwcjGfKUETcs/r7p3yrmODc 56IrUA4zKYLpWY2ZNUuqPjyAUx1Oey/Qn5PVOrY/J1k2oMpHYJXeoSqp1wgfNkmUieAZ 0qXw9eJ6YsJvL26QbNUD0GEw26e/9fgPkKJo4flrJlz8nCxQE9oW2GweBrkyHZ6OKu// LOIA== X-Forwarded-Encrypted: i=1; AJvYcCU7vdjRGQu7BYSQVC2YZ3Tv/h8h57nbE9+zKebY4+yqRwA3WXFLS67VDWl/cBHKOeZNGodQKBZTStmedWk=@vger.kernel.org X-Gm-Message-State: AOJu0YxJg73GX428ryMM3mG8Oj4b4lj/yCxiRNWog1ZwDCbJTvgf1ynt ef2rjt08NzLzc9ScAC26J/TmUxnxnBKvUW91UNSyTYEf7pPlwNitvx9xYE/nfL8kl+8T+jevTfx CdJ07MWthUw== X-Received: from dydr4.prod.google.com ([2002:a05:7300:50e4:b0:2c1:baf:2b92]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:dc88:b0:2b7:b7e7:9025 with SMTP id 5a478bee46e88-2cbfcb5580fmr2012759eec.31.1775248826503; Fri, 03 Apr 2026 13:40:26 -0700 (PDT) Date: Fri, 3 Apr 2026 13:39:53 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-2-irogers@google.com> Subject: [PATCH v5 01/25] perf sample: Document struct perf_sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add kernel-doc for struct perf_sample capturing the somewhat unusual population of fields and lifetime relationships. Signed-off-by: Ian Rogers --- tools/perf/util/sample.h | 109 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 3cce8dd202aa..8d4ace0e6594 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -81,47 +81,148 @@ struct simd_flags { #define SIMD_OP_FLAGS_PRED_PARTIAL 0x01 /* partial predicate */ #define SIMD_OP_FLAGS_PRED_EMPTY 0x02 /* empty predicate */ =20 +/** + * struct perf_sample + * + * A sample is generally filled in by evlist__parse_sample/evsel__parse_sa= mple + * which fills in the variables from a "union perf_event *event" which is = data + * from a perf ring buffer or perf.data file. The "event" sample is variab= le in + * length as determined by the perf_event_attr (in the evsel) and details = within + * the sample event itself. A struct perf_sample avoids needing to care ab= out + * the variable length nature of the original event. + * + * To avoid being excessively large parts of the struct perf_sample are po= inters + * into the original sample event. In general the lifetime of a struct + * perf_sample needs to be less than the "union perf_event *event" it was + * derived from. + * + * The struct regs_dump user_regs and intr_regs are lazily allocated again= for + * size reasons, due to them holding a cache of looked up registers. The + * function pair of perf_sample__init and perf_sample__exit correctly init= ialize + * and clean up these values. + */ struct perf_sample { + /** @ip: The sample event PERF_SAMPLE_IP value. */ u64 ip; - u32 pid, tid; + /** @pid: The sample event PERF_SAMPLE_TID pid value. */ + u32 pid; + /** @tid: The sample event PERF_SAMPLE_TID tid value. */ + u32 tid; + /** @time: The sample event PERF_SAMPLE_TIME value. */ u64 time; + /** @addr: The sample event PERF_SAMPLE_ADDR value. */ u64 addr; + /** @id: The sample event PERF_SAMPLE_ID value. */ u64 id; + /** @stream_id: The sample event PERF_SAMPLE_STREAM_ID value. */ u64 stream_id; + /** @period: The sample event PERF_SAMPLE_PERIOD value. */ u64 period; + /** @weight: Data determined by PERF_SAMPLE_WEIGHT or PERF_SAMPLE_WEIGHT_= STRUCT. */ u64 weight; + /** @transaction: The sample event PERF_SAMPLE_TRANSACTION value. */ u64 transaction; + /** @insn_cnt: Filled in and used by intel-pt. */ u64 insn_cnt; + /** @cyc_cnt: Filled in and used by intel-pt. */ u64 cyc_cnt; + /** @cpu: The sample event PERF_SAMPLE_CPU value. */ u32 cpu; + /** + * @raw_size: The size in bytes of raw data from PERF_SAMPLE_RAW. For + * alignment reasons this should always be sizeof(u32) + * followed by a multiple of sizeof(u64). + */ u32 raw_size; + /** @data_src: The sample event PERF_SAMPLE_DATA_SRC value. */ u64 data_src; + /** @phys_addr: The sample event PERF_SAMPLE_PHYS_ADDR value. */ u64 phys_addr; + /** @data_page_size: The sample event PERF_SAMPLE_DATA_PAGE_SIZE value. */ u64 data_page_size; + /** @code_page_size: The sample event PERF_SAMPLE_CODE_PAGE_SIZE value. */ u64 code_page_size; + /** @cgroup: The sample event PERF_SAMPLE_CGROUP value. */ u64 cgroup; + /** @flags: Extra flag data from auxiliary events like intel-pt. */ u32 flags; + /** @machine_pid: The guest machine pid derived from the sample id. */ u32 machine_pid; + /** @vcpu: The guest machine vcpu derived from the sample id. */ u32 vcpu; + /** + * @insn_len: Instruction length from auxiliary events like + * intel-pt. The instruction itself is held in insn. + */ u16 insn_len; + /** + * @cpumode: The cpumode from struct perf_event_header misc variable + * masked with CPUMODE_MASK. Gives user, kernel and hypervisor + * information. + */ u8 cpumode; + /** @misc: The entire struct perf_event_header misc variable. */ u16 misc; + /** + * @ins_lat: Instruction latency information from weight2 in + * PERF_SAMPLE_WEIGHT_STRUCT or auxiliary events like + * intel-pt. + */ u16 ins_lat; - /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */ + /** + * @weight3: From PERF_SAMPLE_WEIGHT_STRUCT. On x86 holds retire_lat, on + * powerpc holds p_stage_cyc. + */ u16 weight3; - bool no_hw_idx; /* No hw_idx collected in branch_stack */ - bool deferred_callchain; /* Has deferred user callchains */ + /** + * @no_hw_idx: For PERF_SAMPLE_BRANCH_STACK, true when + * PERF_SAMPLE_BRANCH_HW_INDEX isn't set. + */ + bool no_hw_idx; + /** + * @deferred_callchain: When processing PERF_SAMPLE_CALLCHAIN a deferred + * user callchain marker was encountered. + */ + bool deferred_callchain; + /** + * @deferred_cookie: Identifier of the deferred callchain in the later + * PERF_RECORD_CALLCHAIN_DEFERRED event. + */ u64 deferred_cookie; + /** @insn: A copy of the sampled instruction filled in by perf_sample__fe= tch_insn. */ char insn[MAX_INSN]; + /** @raw_data: Pointer into the original event for PERF_SAMPLE_RAW data. = */ void *raw_data; + /** + * @callchain: Pointer into the original event for PERF_SAMPLE_CALLCHAIN + * data. For deferred callchains this may be a copy that + * needs freeing, see sample__merge_deferred_callchain. + */ struct ip_callchain *callchain; + /** @branch_stack: Pointer into the original event for PERF_SAMPLE_BRANCH= _STACK data. */ struct branch_stack *branch_stack; + /** + * @branch_stack_cntr: Pointer into the original event for + * PERF_SAMPLE_BRANCH_COUNTERS data. + */ u64 *branch_stack_cntr; + /** @user_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_= USER. */ struct regs_dump *user_regs; + /** @intr_regs: Values and pointers into the sample for PERF_SAMPLE_REGS_= INTR. */ struct regs_dump *intr_regs; + /** @user_stack: Size and pointer into the sample for PERF_SAMPLE_STACK_U= SER. */ struct stack_dump user_stack; + /** + * @read: The sample event PERF_SAMPLE_READ counter values. The valid + * values depend on the attr.read_format PERF_FORMAT_ values. + */ struct sample_read read; + /** + * @aux_sample: Similar to raw data but with a 64-bit size and + * alignment, PERF_SAMPLE_AUX data. + */ struct aux_sample aux_sample; + /** @simd_flags: SIMD flag information from ARM SPE auxiliary events. */ struct simd_flags simd_flags; }; =20 --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B7D63AA514 for ; Fri, 3 Apr 2026 20:40:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248832; cv=none; b=aMWgK2Ehrpk70wA3BMfOlaShTPWvO/s+5lNNUZ4kQypLHgbQ1D58FmOLsCIugnGxxygGKAfHKtINBMkHrNmLgwCllgWlnGRf6WhsZc3lEa4yoZyXpMMmmM61Rd4Y6wuwcw1BsYniHQNGsyUyf27e30xME3aZ2T9PpGowMmMLnOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248832; c=relaxed/simple; bh=TRdWBOpLbvs21MuktNzM0nDZKE1WaMzXx3DIutlB0rA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EJBDQJhS/lByOh/GwheZ4jwptHxctopBcVuLhWx7+DPZNgLN20EJHAxg+e/GyZC3INZo6mus1KNO2SKq84YWBlm2wrYNP8dpTwoGlpKmvs4U8Fk/T7qkwjnnyrOF4oy6MajYEFOOAAtPY3PsLBPJ3N7nrnTD193OmpFyIGCG5AA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cXOtYNTe; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cXOtYNTe" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2c0ba59a830so2940242eec.0 for ; Fri, 03 Apr 2026 13:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248829; x=1775853629; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IE+cCiAwugWplxK5FgglpVILmyG+kQdSindz+ACiy+w=; b=cXOtYNTeW05D5QITlwc0Ji7RkON5nhZGmBPlI1sVqOraFqA/LZJ6Ptb2Jpv2DkJ4Iz I4n93lFtVWqaGNjXEac2AtcjwLLEgsYev/xHB1nmxOHMGia1g1CVjxHxphc4uUHedSD0 dHao6a2HSf/KEq1ch/0D0aEbkl7l32LoWq00SUF71I9fMgw3eF/ujNqtKK2q0gjfh2uC h7wpPv9j9rrfr6Ha8fS3Z+6jKGTymO8mQqNmkT7+XlcRhnFc4Ve0GK+/s0vHTGqc9DU6 YqKZK/2l2LMTTRwKm6IvcUNN6qoa8fDmT7FpmF4iyU+Z6canfQJ1EV57p1mI/OTeJ7r8 enrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248829; x=1775853629; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IE+cCiAwugWplxK5FgglpVILmyG+kQdSindz+ACiy+w=; b=Ri+yyFs1ty4BIo5k4f1E18I/9VBUREK1rrIbAXthqwtgnJ5UGyLenVyWrAcHMSL8kY E361aPlpD2xYRE6tC3whqUwLbcsUM2CmUz0lpVFJ17xh1+LwV2fDAN1hbfh38u0JNp/w yHq4k76aMKNvK1asZRZEruBGTZljZswFDVr1cTvr1qpfF1P7eAV38dcHM/o/eDH5LIQD WVOMiHDNAht7OelAFjbUPNpSUHx3QTsSlQNPCy8psEBP4eNNmw8R4Rnd3lRMvAgkGEB/ fw0tV/rhrFmA0t6p9SB553+sBs9JHrMxKnr8o7FWyH+lNvOwOv8aUw0clpAd1y4khxDt jDUQ== X-Forwarded-Encrypted: i=1; AJvYcCUQC5HdwJAPJRk34Kmmj9aCaLIu1KlowhI8+rpcPecG0BAiD3M5ZQUyJUkTDifS3OhU4p2bWz6FIm29Gyk=@vger.kernel.org X-Gm-Message-State: AOJu0YwzOpZpfviSLrkijWPYlgOsIBypdvc6UGlJo6dlI2W2nYikVHIa ke8FNjlNDYqgYODAiB1fImh6Sazpyt6Btvuibw70Tldc0RO++KXSm+F16wHM2mlDK6VTOVsDI+w qn6WO8+WfFg== X-Received: from dltt14.prod.google.com ([2002:a05:701a:c96e:b0:128:d754:39d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:b81:b0:12a:6c4b:9d01 with SMTP id a92af1059eb24-12bfb6e793cmr1883435c88.7.1775248829095; Fri, 03 Apr 2026 13:40:29 -0700 (PDT) Date: Fri, 3 Apr 2026 13:39:54 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-3-irogers@google.com> Subject: [PATCH v5 02/25] perf sample: Make sure perf_sample__init/exit are used From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The deferred stack trace code wasn't using perf_sample__init/exit. Add the deferred stack trace clean up to perf_sample__exit which requires proper NULL initialization in perf_sample__init. Make the perf_sample__exit robust to being called more than once by using zfree. Make the error paths in evsel__parse_sample exit the sample. Add a merged_callchain boolean to capture that callchain is allocated, deferred_callchain doen't suffice for this. Pack the struct variables to avoid padding bytes for this. Similiarly powerpc_vpadtl_sample wasn't using perf_sample__init/exit, use it for consistency and potential issues with uninitialized variables. Similarly guest_session__inject_events in builtin-inject wasn't using perf_sample_init/exit. The lifetime management for fetched events is somewhat complex there, but when an event is fetched the sample should be initialized and needs exiting on error. The sample may be left in place so that future injects have access to it. Signed-off-by: Ian Rogers --- tools/perf/builtin-inject.c | 55 +++++++++++++++++++++--------- tools/perf/tests/perf-record.c | 1 + tools/perf/tests/switch-tracking.c | 2 ++ tools/perf/util/callchain.c | 10 ++++-- tools/perf/util/evlist.c | 5 ++- tools/perf/util/evsel.c | 34 +++++++++++------- tools/perf/util/powerpc-vpadtl.c | 10 +++--- tools/perf/util/sample.c | 10 ++++-- tools/perf/util/sample.h | 17 +++++---- tools/perf/util/session.c | 13 ++++--- 10 files changed, 108 insertions(+), 49 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 5b29f4296861..d63191ae4c5b 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1087,6 +1087,7 @@ static int perf_inject__sched_stat(const struct perf_= tool *tool, struct perf_sample sample_sw; struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); u32 pid =3D evsel__intval(evsel, sample, "pid"); + int ret; =20 list_for_each_entry(ent, &inject->samples, node) { if (pid =3D=3D ent->tid) @@ -1103,7 +1104,9 @@ static int perf_inject__sched_stat(const struct perf_= tool *tool, perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, evsel->core.attr.read_format, &sample_sw); build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); - return perf_event__repipe(tool, event_sw, &sample_sw, machine); + ret =3D perf_event__repipe(tool, event_sw, &sample_sw, machine); + perf_sample__exit(&sample_sw); + return ret; } #endif =20 @@ -1648,6 +1651,7 @@ static int guest_session__fetch(struct guest_session = *gs) size_t hdr_sz =3D sizeof(*hdr); ssize_t ret; =20 + perf_sample__init(&gs->ev.sample, /*all=3D*/false); buf =3D gs->ev.event_buf; if (!buf) { buf =3D malloc(PERF_SAMPLE_MAX_SIZE); @@ -1745,18 +1749,24 @@ static int guest_session__inject_events(struct gues= t_session *gs, u64 timestamp) if (!gs->fetched) { ret =3D guest_session__fetch(gs); if (ret) - return ret; + break; gs->fetched =3D true; } =20 ev =3D gs->ev.event; sample =3D &gs->ev.sample; =20 - if (!ev->header.size) - return 0; /* EOF */ - - if (sample->time > timestamp) - return 0; + if (!ev->header.size) { + /* EOF */ + perf_sample__exit(&gs->ev.sample); + gs->fetched =3D false; + ret =3D 0; + break; + } + if (sample->time > timestamp) { + ret =3D 0; + break; + } =20 /* Change cpumode to guest */ cpumode =3D ev->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; @@ -1779,12 +1789,14 @@ static int guest_session__inject_events(struct gues= t_session *gs, u64 timestamp) =20 if (id_hdr_size & 7) { pr_err("Bad id_hdr_size %u\n", id_hdr_size); - return -EINVAL; + ret =3D -EINVAL; + break; } =20 if (ev->header.size & 7) { pr_err("Bad event size %u\n", ev->header.size); - return -EINVAL; + ret =3D -EINVAL; + break; } =20 /* Remove guest id sample */ @@ -1792,14 +1804,16 @@ static int guest_session__inject_events(struct gues= t_session *gs, u64 timestamp) =20 if (ev->header.size & 7) { pr_err("Bad raw event size %u\n", ev->header.size); - return -EINVAL; + ret =3D -EINVAL; + break; } =20 guest_id =3D guest_session__lookup_id(gs, id); if (!guest_id) { pr_err("Guest event with unknown id %llu\n", (unsigned long long)id); - return -EINVAL; + ret =3D -EINVAL; + break; } =20 /* Change to host ID to avoid conflicting ID values */ @@ -1819,19 +1833,28 @@ static int guest_session__inject_events(struct gues= t_session *gs, u64 timestamp) /* New id sample with new ID and CPU */ ret =3D evlist__append_id_sample(inject->session->evlist, ev, sample); if (ret) - return ret; + break; =20 if (ev->header.size & 7) { pr_err("Bad new event size %u\n", ev->header.size); - return -EINVAL; + ret =3D -EINVAL; + break; } =20 - gs->fetched =3D false; - ret =3D output_bytes(inject, ev, ev->header.size); if (ret) - return ret; + break; + + /* Reset for next guest session event fetch. */ + perf_sample__exit(sample); + gs->fetched =3D false; } + if (ret && gs->fetched) { + /* Clear saved sample state on error. */ + perf_sample__exit(&gs->ev.sample); + gs->fetched =3D false; + } + return ret; } =20 static int guest_session__flush_events(struct guest_session *gs) diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index c6e31ab8a6b8..ad44cc68820b 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -300,6 +300,7 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest } =20 perf_mmap__consume(&md->core); + perf_sample__exit(&sample); } perf_mmap__read_done(&md->core); } diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-t= racking.c index 15791fcb76b2..72a8289e846d 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -239,11 +239,13 @@ static int add_event(struct evlist *evlist, struct li= st_head *events, =20 if (!sample.time) { pr_debug("event with no time\n"); + perf_sample__exit(&sample); return -1; } =20 node->event_time =3D sample.time; =20 + perf_sample__exit(&sample); return 0; } =20 diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index f879b84f8ff9..f031cbbeeba8 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1901,16 +1901,19 @@ int sample__merge_deferred_callchain(struct perf_sa= mple *sample_orig, u64 nr_deferred =3D sample_callchain->callchain->nr; struct ip_callchain *callchain; =20 + if (sample_orig->merged_callchain) { + /* Already merged. */ + return -EINVAL; + } + if (sample_orig->callchain->nr < 2) { sample_orig->deferred_callchain =3D false; return -EINVAL; } =20 callchain =3D calloc(1 + nr_orig + nr_deferred, sizeof(u64)); - if (callchain =3D=3D NULL) { - sample_orig->deferred_callchain =3D false; + if (callchain =3D=3D NULL) return -ENOMEM; - } =20 callchain->nr =3D nr_orig + nr_deferred; /* copy original including PERF_CONTEXT_USER_DEFERRED (but the cookie) */ @@ -1919,6 +1922,7 @@ int sample__merge_deferred_callchain(struct perf_samp= le *sample_orig, memcpy(&callchain->ips[nr_orig], sample_callchain->callchain->ips, nr_deferred * sizeof(u64)); =20 + sample_orig->merged_callchain =3D true; sample_orig->callchain =3D callchain; return 0; } diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index c702741a9173..f46e1d40bad7 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1632,8 +1632,11 @@ int evlist__parse_sample(struct evlist *evlist, unio= n perf_event *event, struct struct evsel *evsel =3D evlist__event2evsel(evlist, event); int ret; =20 - if (!evsel) + if (!evsel) { + /* Ensure the sample is okay for perf_sample__exit. */ + perf_sample__init(sample, /*all=3D*/false); return -EFAULT; + } ret =3D evsel__parse_sample(evsel, event, sample); if (ret) return ret; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 5a294595a677..4d3615d7b885 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3072,7 +3072,7 @@ static inline bool overflow(const void *endp, u16 max= _size, const void *offset, #define OVERFLOW_CHECK(offset, size, max_size) \ do { \ if (overflow(endp, (max_size), (offset), (size))) \ - return -EFAULT; \ + goto out_efault; \ } while (0) =20 #define OVERFLOW_CHECK_u64(offset) \ @@ -3204,6 +3204,8 @@ static int __set_offcpu_sample(struct perf_sample *da= ta) data->cgroup =3D *array; =20 return 0; +out_efault: + return -EFAULT; } =20 int evsel__parse_sample(struct evsel *evsel, union perf_event *event, @@ -3222,7 +3224,7 @@ int evsel__parse_sample(struct evsel *evsel, union pe= rf_event *event, */ union u64_swap u; =20 - memset(data, 0, sizeof(*data)); + perf_sample__init(data, /*all=3D*/true); data->cpu =3D data->pid =3D data->tid =3D -1; data->stream_id =3D data->id =3D data->time =3D -1ULL; data->period =3D evsel->core.attr.sample_period; @@ -3236,25 +3238,26 @@ int evsel__parse_sample(struct evsel *evsel, union = perf_event *event, =20 data->callchain =3D (struct ip_callchain *)&event->callchain_deferred.nr; if (data->callchain->nr > max_callchain_nr) - return -EFAULT; + goto out_efault; =20 data->deferred_cookie =3D event->callchain_deferred.cookie; =20 if (evsel->core.attr.sample_id_all) perf_evsel__parse_id_sample(evsel, event, data); + return 0; } =20 if (event->header.type !=3D PERF_RECORD_SAMPLE) { - if (!evsel->core.attr.sample_id_all) - return 0; - return perf_evsel__parse_id_sample(evsel, event, data); + if (evsel->core.attr.sample_id_all) + perf_evsel__parse_id_sample(evsel, event, data); + return 0; } =20 array =3D event->sample.array; =20 if (perf_event__check_size(event, evsel->sample_size)) - return -EFAULT; + goto out_efault; =20 if (type & PERF_SAMPLE_IDENTIFIER) { data->id =3D *array; @@ -3347,7 +3350,7 @@ int evsel__parse_sample(struct evsel *evsel, union pe= rf_event *event, sizeof(struct sample_read_value); =20 if (data->read.group.nr > max_group_nr) - return -EFAULT; + goto out_efault; =20 sz =3D data->read.group.nr * sample_read_value_size(read_format); OVERFLOW_CHECK(array, sz, max_size); @@ -3375,7 +3378,7 @@ int evsel__parse_sample(struct evsel *evsel, union pe= rf_event *event, data->callchain =3D (struct ip_callchain *)array++; callchain_nr =3D data->callchain->nr; if (callchain_nr > max_callchain_nr) - return -EFAULT; + goto out_efault; sz =3D callchain_nr * sizeof(u64); /* * Save the cookie for the deferred user callchain. The last 2 @@ -3433,7 +3436,7 @@ int evsel__parse_sample(struct evsel *evsel, union pe= rf_event *event, data->branch_stack =3D (struct branch_stack *)array++; =20 if (data->branch_stack->nr > max_branch_nr) - return -EFAULT; + goto out_efault; =20 sz =3D data->branch_stack->nr * sizeof(struct branch_entry); if (evsel__has_branch_hw_idx(evsel)) { @@ -3510,7 +3513,7 @@ int evsel__parse_sample(struct evsel *evsel, union pe= rf_event *event, data->user_stack.size =3D *array++; if (WARN_ONCE(data->user_stack.size > sz, "user stack dump failure\n")) - return -EFAULT; + goto out_efault; } } =20 @@ -3587,10 +3590,15 @@ int evsel__parse_sample(struct evsel *evsel, union = perf_event *event, array =3D (void *)array + sz; } =20 - if (evsel__is_offcpu_event(evsel)) - return __set_offcpu_sample(data); + if (evsel__is_offcpu_event(evsel)) { + if (__set_offcpu_sample(data)) + goto out_efault; + } =20 return 0; +out_efault: + perf_sample__exit(data); + return -EFAULT; } =20 int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *e= vent, diff --git a/tools/perf/util/powerpc-vpadtl.c b/tools/perf/util/powerpc-vpa= dtl.c index d1c3396f182f..993ab16614c7 100644 --- a/tools/perf/util/powerpc-vpadtl.c +++ b/tools/perf/util/powerpc-vpadtl.c @@ -182,7 +182,9 @@ static int powerpc_vpadtl_sample(struct powerpc_vpadtl_= entry *record, { struct perf_sample sample; union perf_event event; + int ret; =20 + perf_sample__init(&sample, /*all=3D*/true); sample.ip =3D be64_to_cpu(record->srr0); sample.period =3D 1; sample.cpu =3D cpu; @@ -198,12 +200,12 @@ static int powerpc_vpadtl_sample(struct powerpc_vpadt= l_entry *record, event.sample.header.misc =3D sample.cpumode; event.sample.header.size =3D sizeof(struct perf_event_header); =20 - if (perf_session__deliver_synth_event(vpa->session, &event, &sample)) { + ret =3D perf_session__deliver_synth_event(vpa->session, &event, &sample); + if (ret) pr_debug("Failed to create sample for dtl entry\n"); - return -1; - } =20 - return 0; + perf_sample__exit(&sample); + return ret; } =20 static int powerpc_vpadtl_get_buffer(struct powerpc_vpadtl_queue *vpaq) diff --git a/tools/perf/util/sample.c b/tools/perf/util/sample.c index 8f82aaf1aab6..2a30de4573f6 100644 --- a/tools/perf/util/sample.c +++ b/tools/perf/util/sample.c @@ -21,13 +21,19 @@ void perf_sample__init(struct perf_sample *sample, bool= all) } else { sample->user_regs =3D NULL; sample->intr_regs =3D NULL; + sample->merged_callchain =3D false; + sample->callchain =3D NULL; } } =20 void perf_sample__exit(struct perf_sample *sample) { - free(sample->user_regs); - free(sample->intr_regs); + zfree(&sample->user_regs); + zfree(&sample->intr_regs); + if (sample->merged_callchain) { + zfree(&sample->callchain); + sample->merged_callchain =3D false; + } } =20 struct regs_dump *perf_sample__user_regs(struct perf_sample *sample) diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 8d4ace0e6594..5809c42631e5 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -155,12 +155,6 @@ struct perf_sample { * intel-pt. The instruction itself is held in insn. */ u16 insn_len; - /** - * @cpumode: The cpumode from struct perf_event_header misc variable - * masked with CPUMODE_MASK. Gives user, kernel and hypervisor - * information. - */ - u8 cpumode; /** @misc: The entire struct perf_event_header misc variable. */ u16 misc; /** @@ -174,6 +168,12 @@ struct perf_sample { * powerpc holds p_stage_cyc. */ u16 weight3; + /** + * @cpumode: The cpumode from struct perf_event_header misc variable + * masked with CPUMODE_MASK. Gives user, kernel and hypervisor + * information. + */ + u8 cpumode; /** * @no_hw_idx: For PERF_SAMPLE_BRANCH_STACK, true when * PERF_SAMPLE_BRANCH_HW_INDEX isn't set. @@ -184,6 +184,11 @@ struct perf_sample { * user callchain marker was encountered. */ bool deferred_callchain; + /** + * @merged_callchain: A synthesized merged callchain that is allocated + * and needs freeing. + */ + bool merged_callchain; /** * @deferred_cookie: Identifier of the deferred callchain in the later * PERF_RECORD_CALLCHAIN_DEFERRED event. diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 4b465abfa36c..c48e840da7d4 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1367,14 +1367,18 @@ static int evlist__deliver_deferred_callchain(struc= t evlist *evlist, list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { struct perf_sample orig_sample; =20 + perf_sample__init(&orig_sample, /*all=3D*/false); ret =3D evlist__parse_sample(evlist, de->event, &orig_sample); if (ret < 0) { pr_err("failed to parse original sample\n"); + perf_sample__exit(&orig_sample); break; } =20 - if (sample->tid !=3D orig_sample.tid) + if (sample->tid !=3D orig_sample.tid) { + perf_sample__exit(&orig_sample); continue; + } =20 if (event->callchain_deferred.cookie =3D=3D orig_sample.deferred_cookie) sample__merge_deferred_callchain(&orig_sample, sample); @@ -1385,9 +1389,7 @@ static int evlist__deliver_deferred_callchain(struct = evlist *evlist, ret =3D evlist__deliver_sample(evlist, tool, de->event, &orig_sample, evsel, machine); =20 - if (orig_sample.deferred_callchain) - free(orig_sample.callchain); - + perf_sample__exit(&orig_sample); list_del(&de->list); free(de->event); free(de); @@ -1414,9 +1416,11 @@ static int session__flush_deferred_samples(struct pe= rf_session *session, list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { struct perf_sample sample; =20 + perf_sample__init(&sample, /*all=3D*/false); ret =3D evlist__parse_sample(evlist, de->event, &sample); if (ret < 0) { pr_err("failed to parse original sample\n"); + perf_sample__exit(&sample); break; } =20 @@ -1424,6 +1428,7 @@ static int session__flush_deferred_samples(struct per= f_session *session, ret =3D evlist__deliver_sample(evlist, tool, de->event, &sample, evsel, machine); =20 + perf_sample__exit(&sample); list_del(&de->list); free(de->event); free(de); --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D4C4375ADF for ; Fri, 3 Apr 2026 20:40:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248834; cv=none; b=mmkHfSVh8C9BKwswBw7YfOJsfx8+54UGVM5IL7pPo/jyZ0Ufo6spZFIfvalqjlLR9oV83mwM7mQugMHl+ThIi2WV7igLHkE5xnBqQiidUS4UqCYXsO6huCVQ4TYbPKeo/5bpVKmT3cIwpspS4MzFWDKTUiuP1AJSEhpFeHf4XK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248834; c=relaxed/simple; bh=HUio6EFUcFG35wrQDexFicGMbtJ1iLBBli9+kdb2WfM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CDBuVFbw8zx7UPVtqrmw7jJMMaq0KY4NwD5qzftPDbh8v0XsjMyeLLW7XvYjsmQ0BsWxD5lq/+YzU/RXEVpwU7siRR2qdM4lN44tFDNwXitTSHrgvbHzWrH0sdHMOT3RrjF9tNAImIbwnOL4qtd6xFl138iyGTKyAK52p1fP3Gc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=etued1T2; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="etued1T2" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12bf921cf49so1977892c88.1 for ; Fri, 03 Apr 2026 13:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248832; x=1775853632; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/SN7H8nXQq0V7cxVTogrrT4hkaEDxSVli8PkUD/+JiU=; b=etued1T2CXC5DZLPc01a7/NRa6VTSjMmraW3GA1l9OXugZJqhBCsJhrHSYjBkim0sY jROJTHBisojGyUJMSxuOfLrxfElBr6CONRMyGTolvTv/OScfwQ/+DwuQNWBxb3H0pSk5 rBPx+XJuNwV035SGGC1TfjYjbmNs17jaW37ttavxh18MkAFPIBa/2/YWmltu3UAeH1aL bCHtmjTubYrNOlBty8qro1hFd3St6nTiH1LgGRYjgDEOsIHS6r2UFpiuOCHRGt/CvUeM wq5xsmPjO5VmxWp9qNQ3LH8p9UibKeT9uWPbf9rKc7xYQ1vkSW/PvOiu1HmuAt2E3qGm qlow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248832; x=1775853632; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/SN7H8nXQq0V7cxVTogrrT4hkaEDxSVli8PkUD/+JiU=; b=KZfQqqOi9x54LiXcBwRb2pfMeIQugrvN5bQzmc+mf7/8EOmDPcIiwLhlHuQjHiQN3A b14vdp1I9YIKgAstdraDjS2FPU1O9t4VKkDSqVJrHdCNmUkIYrt6b7a35k23K68xiB13 Fm4W5NhKmtFEDu4w5gdnLcH1NcmxTbP7760z8807uib1aOInm/zqESjRhaRUboX5s9/8 cY2wAWdJdh3AKC2+uisgbYNCKVmCOKsnEEM2bfdbQ9ejN1TVv8l315OL9/jsIZUrRzV9 6KmoJV3oChaAN1FG58tvbtlOvS8jXjFYZEhoxbjQJ8iov+JfyHKdNmCzDsuQudIfQfsE q0jQ== X-Forwarded-Encrypted: i=1; AJvYcCXp1mEimvox8EVgqL3HZX02MfxAVIPKhoFG12Dq5Mv0Pf1WYdBgm2Q25j2PNA76q4N5HM3bQipdgsFeMQw=@vger.kernel.org X-Gm-Message-State: AOJu0YzRYteDtl0syCqU5+wrfC1wQ5tFoOqWl+VRF1z/PacsSeWKZHLS Sp8RxVp53rZX59+ntEYvDwa1z5uDXGcTgPhS1KHpsRP21UXxskfs8qLdNNfArn9JOqkA/AtlTXh lGIxmU+ydww== X-Received: from dldoa12.prod.google.com ([2002:a05:701a:ca8c:b0:128:ed1b:481d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6613:b0:127:9e95:a2f with SMTP id a92af1059eb24-12bfb6e7cd2mr1980208c88.2.1775248831384; Fri, 03 Apr 2026 13:40:31 -0700 (PDT) Date: Fri, 3 Apr 2026 13:39:55 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-4-irogers@google.com> Subject: [PATCH v5 03/25] perf sample: Add evsel to struct perf_sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the evsel from evsel__parse_sample into the struct perf_sample. Sometimes we want to alter the evsel associated with a sample, such as with off-cpu bpf-output events. In general the evsel and perf_sample are passed as a pair, but this makes an altered evsel something of a chore to keep checking for and setting up. Later patches will remove passing an evsel with the perf_sample and switch to just using the perf_sample's value. Signed-off-by: Ian Rogers --- tools/perf/builtin-inject.c | 6 +++--- tools/perf/builtin-script.c | 4 ++++ tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 1 + tools/perf/tests/hists_output.c | 2 +- tools/perf/util/evsel.c | 1 + tools/perf/util/sample.c | 1 + tools/perf/util/sample.h | 3 +++ tools/perf/util/session.c | 35 +++++++++++++++++++------------ 9 files changed, 37 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index d63191ae4c5b..05b769a2a825 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -133,7 +133,7 @@ struct perf_inject { struct perf_file_section secs[HEADER_FEAT_BITS]; struct guest_session guest_session; struct strlist *known_build_ids; - const struct evsel *mmap_evsel; + struct evsel *mmap_evsel; struct ip_callchain *raw_callchain; }; =20 @@ -519,7 +519,7 @@ static struct dso *findnew_dso(int pid, int tid, const = char *filename, * processing mmap events. If not stashed, search the evlist for the first= mmap * gathering event. */ -static const struct evsel *inject__mmap_evsel(struct perf_inject *inject) +static struct evsel *inject__mmap_evsel(struct perf_inject *inject) { struct evsel *pos; =20 @@ -1023,7 +1023,6 @@ int perf_event__inject_buildid(const struct perf_tool= *tool, union perf_event *e =20 sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEP= TH, /*symbols=3D*/false, mark_dso_hit_callback, &args); - thread__put(thread); repipe: perf_event__repipe(tool, event, sample, machine); @@ -1432,6 +1431,7 @@ static int synthesize_build_id(struct perf_inject *in= ject, struct dso *dso, pid_ { struct machine *machine =3D perf_session__findnew_machine(inject->session= , machine_pid); struct perf_sample synth_sample =3D { + .evsel =3D inject__mmap_evsel(inject), .pid =3D -1, .tid =3D -1, .time =3D -1, diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index b80c406d1fc1..8c3d06a3db62 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2909,8 +2909,12 @@ static int print_event_with_time(const struct perf_t= ool *tool, thread =3D machine__findnew_thread(machine, pid, tid); =20 if (evsel) { + struct evsel *saved_evsel =3D sample->evsel; + + sample->evsel =3D evsel; perf_sample__fprintf_start(script, sample, thread, evsel, event->header.type, stdout); + sample->evsel =3D saved_evsel; } =20 perf_event__fprintf(event, machine, stdout); diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cum= ulate.c index 3eb9ef8d7ec6..606aa926a8fc 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -81,7 +81,7 @@ static int add_hist_entries(struct hists *hists, struct m= achine *machine) { struct addr_location al; struct evsel *evsel =3D hists_to_evsel(hists); - struct perf_sample sample =3D { .period =3D 1000, }; + struct perf_sample sample =3D { .evsel =3D evsel, .period =3D 1000, }; size_t i; =20 addr_location__init(&al); diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filte= r.c index 1cebd20cc91c..cc6b26e373d1 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -70,6 +70,7 @@ static int add_hist_entries(struct evlist *evlist, }; struct hists *hists =3D evsel__hists(evsel); =20 + sample.evsel =3D evsel; /* make sure it has no filter at first */ hists->thread_filter =3D NULL; hists->dso_filter =3D NULL; diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_outpu= t.c index ee5ec8bda60e..7818950d786e 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -51,7 +51,7 @@ static int add_hist_entries(struct hists *hists, struct m= achine *machine) { struct addr_location al; struct evsel *evsel =3D hists_to_evsel(hists); - struct perf_sample sample =3D { .period =3D 100, }; + struct perf_sample sample =3D { .evsel =3D evsel, .period =3D 100, }; size_t i; =20 addr_location__init(&al); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 4d3615d7b885..33b9a4c284ad 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3225,6 +3225,7 @@ int evsel__parse_sample(struct evsel *evsel, union pe= rf_event *event, union u64_swap u; =20 perf_sample__init(data, /*all=3D*/true); + data->evsel =3D evsel; data->cpu =3D data->pid =3D data->tid =3D -1; data->stream_id =3D data->id =3D data->time =3D -1ULL; data->period =3D evsel->core.attr.sample_period; diff --git a/tools/perf/util/sample.c b/tools/perf/util/sample.c index 2a30de4573f6..cf73329326d7 100644 --- a/tools/perf/util/sample.c +++ b/tools/perf/util/sample.c @@ -19,6 +19,7 @@ void perf_sample__init(struct perf_sample *sample, bool a= ll) if (all) { memset(sample, 0, sizeof(*sample)); } else { + sample->evsel =3D NULL; sample->user_regs =3D NULL; sample->intr_regs =3D NULL; sample->merged_callchain =3D false; diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index 5809c42631e5..3bd6d8b60586 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -5,6 +5,7 @@ #include #include =20 +struct evsel; struct machine; struct thread; =20 @@ -102,6 +103,8 @@ struct simd_flags { * and clean up these values. */ struct perf_sample { + /** @evsel: Backward reference to the evsel used when constructing the sa= mple. */ + struct evsel *evsel; /** @ip: The sample event PERF_SAMPLE_IP value. */ u64 ip; /** @pid: The sample event PERF_SAMPLE_TID pid value. */ diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c48e840da7d4..3794d3a04afb 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1257,8 +1257,9 @@ static int deliver_sample_value(struct evlist *evlist, bool per_thread) { struct perf_sample_id *sid =3D evlist__id2sid(evlist, v->id); - struct evsel *evsel; + struct evsel *saved_evsel =3D sample->evsel; u64 *storage =3D NULL; + int ret; =20 if (sid) { storage =3D perf_sample_id__get_period_storage(sid, sample->tid, per_thr= ead); @@ -1282,8 +1283,10 @@ static int deliver_sample_value(struct evlist *evlis= t, if (!sample->period) return 0; =20 - evsel =3D container_of(sid->evsel, struct evsel, core); - return tool->sample(tool, event, sample, evsel, machine); + sample->evsel =3D container_of(sid->evsel, struct evsel, core); + ret =3D tool->sample(tool, event, sample, sample->evsel, machine); + sample->evsel =3D saved_evsel; + return ret; } =20 static int deliver_sample_group(struct evlist *evlist, @@ -1355,13 +1358,16 @@ static int evlist__deliver_deferred_callchain(struc= t evlist *evlist, struct machine *machine) { struct deferred_event *de, *tmp; - struct evsel *evsel; int ret =3D 0; =20 if (!tool->merge_deferred_callchains) { - evsel =3D evlist__id2evsel(evlist, sample->id); - return tool->callchain_deferred(tool, event, sample, - evsel, machine); + struct evsel *saved_evsel =3D sample->evsel; + + sample->evsel =3D evlist__id2evsel(evlist, sample->id); + ret =3D tool->callchain_deferred(tool, event, sample, + sample->evsel, machine); + sample->evsel =3D saved_evsel; + return ret; } =20 list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { @@ -1385,9 +1391,9 @@ static int evlist__deliver_deferred_callchain(struct = evlist *evlist, else orig_sample.deferred_callchain =3D false; =20 - evsel =3D evlist__id2evsel(evlist, orig_sample.id); + orig_sample.evsel =3D evlist__id2evsel(evlist, orig_sample.id); ret =3D evlist__deliver_sample(evlist, tool, de->event, - &orig_sample, evsel, machine); + &orig_sample, orig_sample.evsel, machine); =20 perf_sample__exit(&orig_sample); list_del(&de->list); @@ -1410,7 +1416,6 @@ static int session__flush_deferred_samples(struct per= f_session *session, struct evlist *evlist =3D session->evlist; struct machine *machine =3D &session->machines.host; struct deferred_event *de, *tmp; - struct evsel *evsel; int ret =3D 0; =20 list_for_each_entry_safe(de, tmp, &evlist->deferred_samples, list) { @@ -1424,9 +1429,9 @@ static int session__flush_deferred_samples(struct per= f_session *session, break; } =20 - evsel =3D evlist__id2evsel(evlist, sample.id); + sample.evsel =3D evlist__id2evsel(evlist, sample.id); ret =3D evlist__deliver_sample(evlist, tool, de->event, - &sample, evsel, machine); + &sample, sample.evsel, machine); =20 perf_sample__exit(&sample); list_del(&de->list); @@ -1451,8 +1456,12 @@ static int machines__deliver_event(struct machines *= machines, =20 dump_event(evlist, event, file_offset, sample, file_path); =20 - evsel =3D evlist__id2evsel(evlist, sample->id); + if (!sample->evsel) + sample->evsel =3D evlist__id2evsel(evlist, sample->id); + else + assert(sample->evsel =3D=3D evlist__id2evsel(evlist, sample->id)); =20 + evsel =3D sample->evsel; machine =3D machines__find_for_cpumode(machines, event, sample); =20 switch (event->header.type) { --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7D633D5251 for ; Fri, 3 Apr 2026 20:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248838; cv=none; b=rU5n6NfD0qGNS5U98HyxvTwKVk+QaltFiX5vhq3Q79LYol/TEXNUy/ujdVrfhPWhFBgVG/3+MTzF2a4bEayvoW5pKBPoUPLax95B7D5jmcDUA7mCBkjUKlHAI0AH3wo8Oi73ifcq2b7umhe+F99WYKGdBBZZJniXvTMOnEplR+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248838; c=relaxed/simple; bh=mlGnvRfA+b9xVdjzNq9uW0KmisNC0Qhlw06YwsHA2nE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DjYxau7LrCOeuOrBgtE2VFLOV5+LCY36xcatV1aPKZe4gRLLsPHPSndlbgwbi5FOdsTg4zMUZ3C24sEQ5lkcR7d1v4250wWt7UDEaT1UDJMJpU/7Ye8tz56+bIEkkLnhJlPFDz31SQnelhKY/GsXsssULkQfGRgkyLZOHCuanlg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NTfPqxFL; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NTfPqxFL" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2c4cfe08c9dso12517680eec.1 for ; Fri, 03 Apr 2026 13:40:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248834; x=1775853634; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Uy/k+Js9m6twDWulfmmQQbRWJJI/UR6SoQYeKyiXQDY=; b=NTfPqxFLbIUmJGDzG4nFCa2TQpUqxqmeEJ5k9DAs+eY5TXTpRIwYB4+wgEHvpQFBU6 tT5vAM2M/N03qeaomBUvLkscWKUsCcDBgCt/fbtIGpP3pDRgtFxxen6O6QsTJ54d12Ka 8wRtuEF5nnNXWb9ccttWCLFZGJmP9rF65m49EQxfSA5hIWGkVEINvkR6ngMG/5tBZIxe p5GTuCI+3GyHAeoJ3LlsJc4AVMy2T/uKjVRJj6PH3jl1WJZ44rCPLrvgEWsIByfnUQmT FRAYvxYAx10k8kYXrj20343S/hSd8Xt4YRUFia4rvx6bhlsE/CkcjlnOeeRhOCewahhK LebQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248834; x=1775853634; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Uy/k+Js9m6twDWulfmmQQbRWJJI/UR6SoQYeKyiXQDY=; b=McfPxWpkaZwH+mEmn3OgbBISPgvPruwY9GRbEY//2XF4j/7NkAOLXtn0WMH1dp/6qa YToe1XTp3qCSU4e5bbodY91f8AVNR4HvUjzCH3VFVBnaO7k438IELCoX4nBmF2pSvDUw L8vJcV2ID9wSLzd/PAjcP4u+H3fESE+qyvQLOvs6ngzmIawFCkNq1GOTd7GFJxwkFtWb hVv77nf/nkqBhZ/50coRNei7OP3SYUiAOiOX+djjkiOpLGuyMXd3FCYsZOIVRUTnoOhk LZCuguDPubaj2Bi72ZhVeFuCAN3ZBs9XhtF0ZOBuAfgDbT6SzB/MyjI7Dzb4ZewGBrCB iscg== X-Forwarded-Encrypted: i=1; AJvYcCVA+lfowEKr976eN0NIHAn36krNlRhCbxkisQoxRH5mMfLHHzgFsk1eA0LiGG/eOID9DNYtqoxe2ZbskSE=@vger.kernel.org X-Gm-Message-State: AOJu0YzLrEwKiLNChto8Ehu3qZ564gQPQnIorZqZS7/Rhdem9tY3iuwG WtHwptKpOyU3FXMSn2C4Z55Klm6hz+nnopGH36CrY5/8KkTi+xzPsu4SXVmc4jWb49iVpgXiuD9 0gpAXQcROfw== X-Received: from dycqw14-n2.prod.google.com ([2002:a05:7300:c00e:20b0:2c0:d207:5bbf]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:dc92:b0:2c3:5dc0:a06b with SMTP id 5a478bee46e88-2cbfbc8a603mr2513080eec.20.1775248833653; Fri, 03 Apr 2026 13:40:33 -0700 (PDT) Date: Fri, 3 Apr 2026 13:39:56 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-5-irogers@google.com> Subject: [PATCH v5 04/25] perf tool: Remove evsel from tool APIs that pass the sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now struct perf_sample has the evsel within it there is no need to pass the evsel along with the sample. In the called functions read the sample's evsel in to a variable if there are multiple uses, or use directly if there is just one use - the goal being to leave the code with as little change as possible. Some functions only use the evsel to pass to another function which they also pass the sample, in those cases just pass the sample and get the evsel in the called function. Signed-off-by: Ian Rogers --- tools/perf/builtin-annotate.c | 3 +-- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-inject.c | 19 ++++++--------- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 5 ++-- tools/perf/builtin-kwork.c | 2 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-mem.c | 1 - tools/perf/builtin-record.c | 3 +-- tools/perf/builtin-report.c | 10 +++----- tools/perf/builtin-sched.c | 4 +-- tools/perf/builtin-script.c | 4 +-- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/build-id.c | 3 +-- tools/perf/util/build-id.h | 7 +----- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data-convert-json.c | 5 ++-- tools/perf/util/intel-tpebs.c | 3 +-- tools/perf/util/jitdump.c | 2 +- tools/perf/util/session.c | 38 ++++++++++++++--------------- tools/perf/util/tool.c | 4 +-- tools/perf/util/tool.h | 4 +-- 24 files changed, 55 insertions(+), 76 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 686ad08561d6..c97a0fe159f8 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -284,7 +284,6 @@ static int evsel__add_sample(struct evsel *evsel, struc= t perf_sample *sample, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_annotate *ann =3D container_of(tool, struct perf_annotate, to= ol); @@ -303,7 +302,7 @@ static int process_sample_event(const struct perf_tool = *tool, goto out_put; =20 if (!al.filtered && - evsel__add_sample(evsel, sample, &al, ann, machine)) { + evsel__add_sample(sample->evsel, sample, &al, ann, machine)) { pr_warning("problem incrementing symbol count, " "skipping event\n"); ret =3D -1; diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index d390ae4e3ec8..89456ba6fcbb 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -314,9 +314,9 @@ static void perf_c2c__evsel_hists_inc_stats(struct evse= l *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unuse= d, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel =3D sample->evsel; struct c2c_hists *c2c_hists =3D &c2c.hists; struct c2c_hist_entry *c2c_he; struct c2c_stats stats =3D { .nr_entries =3D 0, }; diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 69069926dd0b..096adc65451c 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -390,11 +390,11 @@ struct hist_entry_ops block_hist_ops =3D { static int diff__process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_diff *pdiff =3D container_of(tool, struct perf_diff, tool); struct addr_location al; + struct evsel *evsel =3D sample->evsel; struct hists *hists =3D evsel__hists(evsel); struct hist_entry_iter iter =3D { .evsel =3D evsel, diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 05b769a2a825..a958ac7cec9d 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -363,18 +363,17 @@ typedef int (*inject_handler)(const struct perf_tool = *tool, static int perf_event__repipe_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { - struct perf_inject *inject =3D container_of(tool, struct perf_inject, - tool); + struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); + struct evsel *evsel =3D sample->evsel; =20 if (evsel && evsel->handler) { inject_handler f =3D evsel->handler; return f(tool, event, sample, evsel, machine); } =20 - build_id__mark_dso_hit(tool, event, sample, evsel, machine); + build_id__mark_dso_hit(tool, event, sample, machine); =20 if (inject->itrace_synth_opts.set && sample->aux_sample.size) { event =3D perf_inject__cut_auxtrace_sample(inject, event, sample); @@ -388,10 +387,10 @@ static int perf_event__repipe_sample(const struct per= f_tool *tool, static int perf_event__convert_sample_callchain(const struct perf_tool *to= ol, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); + struct evsel *evsel =3D sample->evsel; struct callchain_cursor *cursor =3D get_tls_callchain_cursor(); union perf_event *event_copy =3D (void *)inject->event_copy; struct callchain_cursor_node *node; @@ -988,10 +987,8 @@ static int mark_dso_hit_callback(struct callchain_curs= or_node *node, void *data) args->mmap_evsel, map, /*sample_in_dso=3D*/false); } =20 -int perf_event__inject_buildid(const struct perf_tool *tool, union perf_ev= ent *event, - struct perf_sample *sample, - struct evsel *evsel __maybe_unused, - struct machine *machine) +static int perf_event__inject_buildid(const struct perf_tool *tool, union = perf_event *event, + struct perf_sample *sample, struct machine *machine) { struct addr_location al; struct thread *thread; @@ -1021,7 +1018,7 @@ int perf_event__inject_buildid(const struct perf_tool= *tool, union perf_event *e /*sample_in_dso=3D*/true); } =20 - sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEP= TH, + sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_S= TACK_DEPTH, /*symbols=3D*/false, mark_dso_hit_callback, &args); thread__put(thread); repipe: @@ -1102,7 +1099,7 @@ static int perf_inject__sched_stat(const struct perf_= tool *tool, sample_sw.time =3D sample->time; perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, evsel->core.attr.read_format, &sample_sw); - build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); + build_id__mark_dso_hit(tool, event_sw, &sample_sw, machine); ret =3D perf_event__repipe(tool, event_sw, &sample_sw, machine); perf_sample__exit(&sample_sw); return ret; diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 7929a5fa5f46..34852a4c3fc8 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -960,9 +960,9 @@ typedef int (*tracepoint_handler)(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unuse= d, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel =3D sample->evsel; int err =3D 0; struct thread *thread =3D machine__findnew_thread(machine, sample->pid, sample->tid); diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 0c5e6b3aac74..5e8e6fde097a 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -941,9 +941,9 @@ struct vcpu_event_record *per_vcpu_record(struct thread= *thread, =20 static bool handle_kvm_event(struct perf_kvm_stat *kvm, struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { + struct evsel *evsel =3D sample->evsel; struct vcpu_event_record *vcpu_record; struct event_key key =3D { .key =3D INVALID_KEY, .exit_reasons =3D kvm->exit_reasons }; @@ -1133,7 +1133,6 @@ static bool skip_sample(struct perf_kvm_stat *kvm, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { int err =3D 0; @@ -1156,7 +1155,7 @@ static int process_sample_event(const struct perf_too= l *tool, return -1; } =20 - if (!handle_kvm_event(kvm, thread, evsel, sample)) + if (!handle_kvm_event(kvm, thread, sample)) err =3D -1; =20 thread__put(thread); diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 6f94a8f45f60..e34a1f35439e 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1955,9 +1955,9 @@ typedef int (*tracepoint_handler)(const struct perf_t= ool *tool, static int perf_kwork__process_tracepoint_sample(const struct perf_tool *t= ool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel =3D sample->evsel; int err =3D 0; =20 if (evsel->handler !=3D NULL) { diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 5585aeb97684..4d8ddf6391e8 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1430,9 +1430,9 @@ typedef int (*tracepoint_handler)(struct evsel *evsel, static int process_sample_event(const struct perf_tool *tool __maybe_unuse= d, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel =3D sample->evsel; int err =3D 0; struct thread *thread =3D machine__findnew_thread(machine, sample->pid, sample->tid); diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index d43500b92a7b..6101a26b3a78 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -255,7 +255,6 @@ dump_raw_samples(const struct perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine) { return dump_raw_samples(tool, event, sample, machine); diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 3276ffdc3141..4fc01ca76ac3 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1489,7 +1489,6 @@ static void set_timestamp_boundary(struct record *rec= , u64 sample_time) static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct record *rec =3D container_of(tool, struct record, tool); @@ -1500,7 +1499,7 @@ static int process_sample_event(const struct perf_too= l *tool, return 0; =20 rec->samples++; - return build_id__mark_dso_hit(tool, event, sample, evsel, machine); + return build_id__mark_dso_hit(tool, event, sample, machine); } =20 static int process_buildids(struct record *rec) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 343c0ada5ea1..507002cbdd5b 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -269,10 +269,10 @@ static int process_feature_event(const struct perf_to= ol *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct report *rep =3D container_of(tool, struct report, tool); + struct evsel *evsel =3D sample->evsel; struct addr_location al; struct hist_entry_iter iter =3D { .evsel =3D evsel, @@ -349,7 +349,6 @@ static int process_sample_event(const struct perf_tool = *tool, static int process_read_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct report *rep =3D container_of(tool, struct report, tool); @@ -357,7 +356,7 @@ static int process_read_event(const struct perf_tool *t= ool, if (rep->show_threads) { int err =3D perf_read_values_add_value(&rep->show_threads_values, event->read.pid, event->read.tid, - evsel, + sample->evsel, event->read.value); =20 if (err) @@ -783,11 +782,10 @@ static void report__output_resort(struct report *rep) =20 static int count_sample_event(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, - struct perf_sample *sample __maybe_unused, - struct evsel *evsel, + struct perf_sample *sample, struct machine *machine __maybe_unused) { - struct hists *hists =3D evsel__hists(evsel); + struct hists *hists =3D evsel__hists(sample->evsel); =20 hists__inc_nr_events(hists); return 0; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index d083e2bb7703..296b9837278a 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -1867,9 +1867,9 @@ typedef int (*tracepoint_handler)(const struct perf_t= ool *tool, static int perf_sched__process_tracepoint_sample(const struct perf_tool *t= ool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { + struct evsel *evsel =3D sample->evsel; int err =3D 0; =20 if (evsel->handler !=3D NULL) { @@ -3184,10 +3184,10 @@ typedef int (*sched_handler)(const struct perf_tool= *tool, static int perf_timehist__process_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_sched *sched =3D container_of(tool, struct perf_sched, tool); + struct evsel *evsel =3D sample->evsel; int err =3D 0; struct perf_cpu this_cpu =3D { .cpu =3D sample->cpu, diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8c3d06a3db62..8724c4ab3e88 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2644,10 +2644,10 @@ static bool filter_cpu(struct perf_sample *sample) static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_script *scr =3D container_of(tool, struct perf_script, tool); + struct evsel *evsel =3D sample->evsel; struct addr_location al; struct addr_location addr_al; int ret =3D 0; @@ -2728,10 +2728,10 @@ static int process_sample_event(const struct perf_t= ool *tool, static int process_deferred_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct perf_script *scr =3D container_of(tool, struct perf_script, tool); + struct evsel *evsel =3D sample->evsel; struct perf_event_attr *attr =3D &evsel->core.attr; struct evsel_script *es =3D evsel->priv; unsigned int type =3D output_type(attr->type); diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 28f33e39895d..8692d11ccd29 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -574,10 +574,10 @@ typedef int (*tracepoint_handler)(struct timechart *t= chart, static int process_sample_event(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct timechart *tchart =3D container_of(tool, struct timechart, tool); + struct evsel *evsel =3D sample->evsel; =20 if (evsel->core.attr.sample_type & PERF_SAMPLE_TIME) { if (!tchart->first_time || tchart->first_time > sample->time) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index f487fbaa0ad6..aad433b870ee 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3462,10 +3462,10 @@ static void trace__set_base_time(struct trace *trac= e, static int trace__process_sample(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct trace *trace =3D container_of(tool, struct trace, tool); + struct evsel *evsel =3D sample->evsel; struct thread *thread; int err =3D 0; =20 diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index fdb35133fde4..55b72235f891 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -55,7 +55,6 @@ static int mark_dso_hit_callback(struct callchain_cursor_= node *node, void *data int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct addr_location al; @@ -74,7 +73,7 @@ int build_id__mark_dso_hit(const struct perf_tool *tool _= _maybe_unused, =20 addr_location__exit(&al); =20 - sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEP= TH, + sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_S= TACK_DEPTH, /*symbols=3D*/false, mark_dso_hit_callback, /*data=3D*/NULL); =20 =20 diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index 47e621cebe1b..73bad90b06f9 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h @@ -34,12 +34,7 @@ char *__dso__build_id_filename(const struct dso *dso, ch= ar *bf, size_t size, bool is_debug, bool is_kallsyms); =20 int build_id__mark_dso_hit(const struct perf_tool *tool, union perf_event = *event, - struct perf_sample *sample, struct evsel *evsel, - struct machine *machine); - -int perf_event__inject_buildid(const struct perf_tool *tool, union perf_ev= ent *event, - struct perf_sample *sample, struct evsel *evsel, - struct machine *machine); + struct perf_sample *sample, struct machine *machine); =20 bool perf_session__read_build_ids(struct perf_session *session, bool with_= hits); int perf_session__write_buildid_table(struct perf_session *session, diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-conve= rt-bt.c index ba1c8e48d495..32e2173b86e3 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c @@ -803,10 +803,10 @@ static bool is_flush_needed(struct ctf_stream *cs) static int process_sample_event(const struct perf_tool *tool, union perf_event *_event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct convert *c =3D container_of(tool, struct convert, tool); + struct evsel *evsel =3D sample->evsel; struct evsel_priv *priv =3D evsel->priv; struct ctf_writer *cw =3D &c->writer; struct ctf_stream *cs; diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-con= vert-json.c index 6a626322476a..d1f931ee565a 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -159,13 +159,12 @@ static void output_sample_callchain_entry(const struc= t perf_tool *tool, static int process_sample_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine) { struct convert_json *c =3D container_of(tool, struct convert_json, tool); FILE *out =3D c->out; struct addr_location al; - u64 sample_type =3D __evlist__combined_sample_type(evsel->evlist); + u64 sample_type =3D __evlist__combined_sample_type(sample->evsel->evlist); u8 cpumode =3D PERF_RECORD_MISC_USER; =20 addr_location__init(&al); @@ -245,7 +244,7 @@ static int process_sample_event(const struct perf_tool = *tool, =20 #ifdef HAVE_LIBTRACEEVENT if (sample->raw_data) { - struct tep_event *tp_format =3D evsel__tp_format(evsel); + struct tep_event *tp_format =3D evsel__tp_format(sample->evsel); struct tep_format_field **fields =3D tp_format ? tep_event_fields(tp_for= mat) : NULL; =20 if (fields) { diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 2af5455488b2..01e030862d5d 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -185,7 +185,6 @@ static bool should_ignore_sample(const struct perf_samp= le *sample, const struct static int process_sample_event(const struct perf_tool *tool __maybe_unuse= d, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine __maybe_unused) { struct tpebs_retire_lat *t; @@ -196,7 +195,7 @@ static int process_sample_event(const struct perf_tool = *tool __maybe_unused, mutex_unlock(tpebs_mtx_get()); return 0; } - t =3D tpebs_retire_lat__find(evsel); + t =3D tpebs_retire_lat__find(sample->evsel); if (!t) { mutex_unlock(tpebs_mtx_get()); return -EINVAL; diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c index e0ce8b904729..52e6ffac2b3e 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -642,7 +642,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd= , union jr_entry *jr) =20 ret =3D jit_inject_event(jd, event); if (!ret) - build_id__mark_dso_hit(tool, event, &sample, NULL, jd->machine); + build_id__mark_dso_hit(tool, event, &sample, jd->machine); out: perf_sample__exit(&sample); return ret; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 3794d3a04afb..150398b383fe 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1110,9 +1110,10 @@ char *get_page_size_name(u64 size, char *str) return str; } =20 -static void dump_sample(struct machine *machine, struct evsel *evsel, unio= n perf_event *event, +static void dump_sample(struct machine *machine, union perf_event *event, struct perf_sample *sample) { + struct evsel *evsel =3D sample->evsel; u64 sample_type; char str[PAGE_SIZE_NAME_LEN]; uint16_t e_machine =3D EM_NONE; @@ -1176,9 +1177,10 @@ static void dump_sample(struct machine *machine, str= uct evsel *evsel, union perf sample_read__printf(sample, evsel->core.attr.read_format); } =20 -static void dump_deferred_callchain(struct evsel *evsel, union perf_event = *event, - struct perf_sample *sample) +static void dump_deferred_callchain(union perf_event *event, struct perf_s= ample *sample) { + struct evsel *evsel =3D sample->evsel; + if (!dump_trace) return; =20 @@ -1284,7 +1286,7 @@ static int deliver_sample_value(struct evlist *evlist, return 0; =20 sample->evsel =3D container_of(sid->evsel, struct evsel, core); - ret =3D tool->sample(tool, event, sample, sample->evsel, machine); + ret =3D tool->sample(tool, event, sample, machine); sample->evsel =3D saved_evsel; return ret; } @@ -1316,8 +1318,9 @@ static int deliver_sample_group(struct evlist *evlist, =20 static int evlist__deliver_sample(struct evlist *evlist, const struct perf= _tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) + struct machine *machine) { + struct evsel *evsel =3D sample->evsel; /* We know evsel !=3D NULL. */ u64 sample_type =3D evsel->core.attr.sample_type; u64 read_format =3D evsel->core.attr.read_format; @@ -1325,7 +1328,7 @@ static int evlist__deliver_sample(struct evlist *evli= st, const struct perf_tool =20 /* Standard sample delivery. */ if (!(sample_type & PERF_SAMPLE_READ)) - return tool->sample(tool, event, sample, evsel, machine); + return tool->sample(tool, event, sample, machine); =20 /* For PERF_SAMPLE_READ we have either single or group mode. */ if (read_format & PERF_FORMAT_GROUP) @@ -1364,8 +1367,7 @@ static int evlist__deliver_deferred_callchain(struct = evlist *evlist, struct evsel *saved_evsel =3D sample->evsel; =20 sample->evsel =3D evlist__id2evsel(evlist, sample->id); - ret =3D tool->callchain_deferred(tool, event, sample, - sample->evsel, machine); + ret =3D tool->callchain_deferred(tool, event, sample, machine); sample->evsel =3D saved_evsel; return ret; } @@ -1393,7 +1395,7 @@ static int evlist__deliver_deferred_callchain(struct = evlist *evlist, =20 orig_sample.evsel =3D evlist__id2evsel(evlist, orig_sample.id); ret =3D evlist__deliver_sample(evlist, tool, de->event, - &orig_sample, orig_sample.evsel, machine); + &orig_sample, machine); =20 perf_sample__exit(&orig_sample); list_del(&de->list); @@ -1431,7 +1433,7 @@ static int session__flush_deferred_samples(struct per= f_session *session, =20 sample.evsel =3D evlist__id2evsel(evlist, sample.id); ret =3D evlist__deliver_sample(evlist, tool, de->event, - &sample, sample.evsel, machine); + &sample, machine); =20 perf_sample__exit(&sample); list_del(&de->list); @@ -1451,7 +1453,6 @@ static int machines__deliver_event(struct machines *m= achines, const struct perf_tool *tool, u64 file_offset, const char *file_path) { - struct evsel *evsel; struct machine *machine; =20 dump_event(evlist, event, file_offset, sample, file_path); @@ -1461,21 +1462,20 @@ static int machines__deliver_event(struct machines = *machines, else assert(sample->evsel =3D=3D evlist__id2evsel(evlist, sample->id)); =20 - evsel =3D sample->evsel; machine =3D machines__find_for_cpumode(machines, event, sample); =20 switch (event->header.type) { case PERF_RECORD_SAMPLE: - if (evsel =3D=3D NULL) { + if (sample->evsel =3D=3D NULL) { ++evlist->stats.nr_unknown_id; return 0; } if (machine =3D=3D NULL) { ++evlist->stats.nr_unprocessable_samples; - dump_sample(machine, evsel, event, sample); + dump_sample(machine, event, sample); return 0; } - dump_sample(machine, evsel, event, sample); + dump_sample(machine, event, sample); if (sample->deferred_callchain && tool->merge_deferred_callchains) { struct deferred_event *de =3D malloc(sizeof(*de)); size_t sz =3D event->header.size; @@ -1492,7 +1492,7 @@ static int machines__deliver_event(struct machines *m= achines, list_add_tail(&de->list, &evlist->deferred_samples); return 0; } - return evlist__deliver_sample(evlist, tool, event, sample, evsel, machin= e); + return evlist__deliver_sample(evlist, tool, event, sample, machine); case PERF_RECORD_MMAP: return tool->mmap(tool, event, sample, machine); case PERF_RECORD_MMAP2: @@ -1520,8 +1520,8 @@ static int machines__deliver_event(struct machines *m= achines, evlist->stats.total_lost_samples +=3D event->lost_samples.lost; return tool->lost_samples(tool, event, sample, machine); case PERF_RECORD_READ: - dump_read(evsel, event); - return tool->read(tool, event, sample, evsel, machine); + dump_read(sample->evsel, event); + return tool->read(tool, event, sample, machine); case PERF_RECORD_THROTTLE: return tool->throttle(tool, event, sample, machine); case PERF_RECORD_UNTHROTTLE: @@ -1550,7 +1550,7 @@ static int machines__deliver_event(struct machines *m= achines, case PERF_RECORD_AUX_OUTPUT_HW_ID: return tool->aux_output_hw_id(tool, event, sample, machine); case PERF_RECORD_CALLCHAIN_DEFERRED: - dump_deferred_callchain(evsel, event, sample); + dump_deferred_callchain(event, sample); return evlist__deliver_deferred_callchain(evlist, tool, event, sample, machine); default: diff --git a/tools/perf/util/tool.c b/tools/perf/util/tool.c index 013c7839e2cf..0f285a2574c8 100644 --- a/tools/perf/util/tool.c +++ b/tools/perf/util/tool.c @@ -110,7 +110,6 @@ static int process_event_synth_event_update_stub(const = struct perf_tool *tool __ int process_event_sample_stub(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct machine *machine __maybe_unused) { dump_printf(": unhandled!\n"); @@ -348,12 +347,11 @@ bool perf_tool__compressed_is_stub(const struct perf_= tool *tool) static int delegate_ ## name(const struct perf_tool *tool, \ union perf_event *event, \ struct perf_sample *sample, \ - struct evsel *evsel, \ struct machine *machine) \ { \ struct delegate_tool *del_tool =3D container_of(tool, struct delegate_to= ol, tool); \ struct perf_tool *delegate =3D del_tool->delegate; \ - return delegate->name(delegate, event, sample, evsel, machine); \ + return delegate->name(delegate, event, sample, machine); \ } CREATE_DELEGATE_SAMPLE(read); CREATE_DELEGATE_SAMPLE(sample); diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h index 2d9a4b1ca9d0..2a4f124ffd8d 100644 --- a/tools/perf/util/tool.h +++ b/tools/perf/util/tool.h @@ -9,7 +9,6 @@ struct perf_session; union perf_event; struct evlist; -struct evsel; struct perf_sample; struct perf_tool; struct machine; @@ -17,7 +16,7 @@ struct ordered_events; =20 typedef int (*event_sample)(const struct perf_tool *tool, union perf_event= *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); + struct machine *machine); =20 typedef int (*event_op)(const struct perf_tool *tool, union perf_event *ev= ent, struct perf_sample *sample, struct machine *machine); @@ -103,7 +102,6 @@ bool perf_tool__compressed_is_stub(const struct perf_to= ol *tool); int process_event_sample_stub(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); =20 struct delegate_tool { --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 174903D811F for ; Fri, 3 Apr 2026 20:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248840; cv=none; b=U7G7aKghkeESkkgvfbKn6RSi4RBpto3FneitLJLdg3FkEV115V/X4oBPv5FLuu961kPIJD5AbROVtvyQYBwFEoKs06jkTXX+PidoiTQWGIu9VvWG1RBu/9hiwLiJ0CK6coRnT2pDoOMkEoUoz7yPXCeb0fA7DsuvG3q5FHBdSCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248840; c=relaxed/simple; bh=o+Xes5abuH+yASF/5nAM10kbXFW/dLHGpz6yw+ZAltA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oUySvt6U7F6OQGKNNKuRvyeQlsXKIQdU3OL+XrwvH6R2a6LjjbTye8fGtsIDEBPO+Q+TqEvSy65AF3Lb8oiDGW5oK3wc0RptB43UTWV2OxJbK1eQQDdDMXnINxtwE3Q5z2W5lcxgGD3WfyBKgpVMxem9D/bkyFMYr39UAyiVRWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=piaMW1YI; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="piaMW1YI" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2c16233ee11so3261056eec.1 for ; Fri, 03 Apr 2026 13:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248836; x=1775853636; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oannBQ3qlAZji2iUnnBApQPMVduJ0gSlFJ8k8/hJ3qM=; b=piaMW1YI8PUu0TsBBrU8DM9QCz8ygV4nryBIEW5GYShEgsHP1KafLnTGNAj8OQ0jpz cjb0XKMCmTibvFzdZgY5OhR9pmhhuliIyJpq1F60dGCZe3t74I8ozVoIj1P7ziMEXDfg BK/tb50Tib4FuqHN+TWSQAokpfxdgw+LVzteJa7YMpvRGWSwK7vOHO1r6E1/XZCnHxM6 wlUxCL+YxM/XitnwJvoXQEttpxM9poKIqPq3ybuJGNcdgMu3HZgRAR3/WDKYcrswnodT pjCNZaEqD2nQ87schd4mxW3n5PKdadlgV7RGFqnTKCqJIlOD/DxhlBMbBkmwQ4JI0jOo KAtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248836; x=1775853636; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oannBQ3qlAZji2iUnnBApQPMVduJ0gSlFJ8k8/hJ3qM=; b=obaDRAX5NZvFk1vLLfG+/cUEymqAKyllKHGCgLMthxr9kOKdXuvRTPmhYQD3QLOphf bnxx9Kidb/Z49QxrmGea7QUIKHzwCHNzYCyTdEePAF9cxhB07gXOERLw1rEqSbmJXTyL QhKI8JFbnig/tya7mZNM4uFvYZeeuGpdOvYPr+rPOkCX8cWo4/1DFqGmAfNaID0M/D1y q4AnUJWTklLgAibMbhetU5tzBvM0oJUmhJq28bF9y1VyKAfv0TrGi441VHoXr3Y92zDl BAYOLBO72DXEFNHK+KtBq7AceV5IvEmQMKiD7RZ/cjog4MbMbcNh3m/Z66XkjgDgq1DA Zv6w== X-Forwarded-Encrypted: i=1; AJvYcCXzWdR35yqIchzPvfO/xh39gFRyrqGy+XQqRb2FwaJFlXN4AKdm2KfUzsuMxTUx+xlF8FwLQ25yIzJ1cZw=@vger.kernel.org X-Gm-Message-State: AOJu0YyhUt2r8w/hOiWGGH6bS+j2K7OAIq4jmmXZPykKmXHhw0EQYe6e bxE0kFjEvg9rsP1nOTMI/8GJ3gP9fhv9d5dRazQ2ncVw0m4ZWkULYrh8oIwpTM20XAKVV8JfiTE nfWDSTyF1Ng== X-Received: from dybgr28.prod.google.com ([2002:a05:7301:201c:b0:2cb:e0e6:59d4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:e8a7:b0:2be:833c:149d with SMTP id 5a478bee46e88-2cbfc6573c7mr2085421eec.28.1775248835955; Fri, 03 Apr 2026 13:40:35 -0700 (PDT) Date: Fri, 3 Apr 2026 13:39:57 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-6-irogers@google.com> Subject: [PATCH v5 05/25] perf kvm: Don't pass evsel with sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As the sample now contains the evsel, read the evsel from the sample rather than passing them as a pair. Signed-off-by: Ian Rogers --- tools/perf/builtin-kvm.c | 19 +++-- .../perf/util/kvm-stat-arch/kvm-stat-arm64.c | 17 +++-- .../util/kvm-stat-arch/kvm-stat-loongarch.c | 17 ++--- .../util/kvm-stat-arch/kvm-stat-powerpc.c | 17 ++--- .../perf/util/kvm-stat-arch/kvm-stat-riscv.c | 18 +++-- tools/perf/util/kvm-stat-arch/kvm-stat-s390.c | 20 +++--- tools/perf/util/kvm-stat-arch/kvm-stat-x86.c | 70 ++++++++----------- tools/perf/util/kvm-stat.c | 19 +++-- tools/perf/util/kvm-stat.h | 18 ++--- 9 files changed, 89 insertions(+), 126 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 5e8e6fde097a..d9b9792894a8 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -806,7 +806,6 @@ static bool update_kvm_event(struct perf_kvm_stat *kvm, } =20 static bool is_child_event(struct perf_kvm_stat *kvm, - struct evsel *evsel, struct perf_sample *sample, struct event_key *key) { @@ -818,8 +817,8 @@ static bool is_child_event(struct perf_kvm_stat *kvm, return false; =20 for (; child_ops->name; child_ops++) { - if (evsel__name_is(evsel, child_ops->name)) { - child_ops->get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, child_ops->name)) { + child_ops->get_key(sample, key); return true; } } @@ -917,11 +916,10 @@ static bool handle_end_event(struct perf_kvm_stat *kv= m, =20 static struct vcpu_event_record *per_vcpu_record(struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { /* Only kvm_entry records vcpu id. */ - if (!thread__priv(thread) && kvm_entry_event(evsel)) { + if (!thread__priv(thread) && kvm_entry_event(sample->evsel)) { struct vcpu_event_record *vcpu_record; struct machine *machine =3D maps__machine(thread__maps(thread)); uint16_t e_machine =3D thread__e_machine(thread, machine, /*e_flags=3D*/= NULL); @@ -932,7 +930,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread= *thread, return NULL; } =20 - vcpu_record->vcpu_id =3D evsel__intval(evsel, sample, vcpu_id_str(e_mach= ine)); + vcpu_record->vcpu_id =3D evsel__intval(sample->evsel, sample, vcpu_id_st= r(e_machine)); thread__set_priv(thread, vcpu_record); } =20 @@ -943,12 +941,11 @@ static bool handle_kvm_event(struct perf_kvm_stat *kv= m, struct thread *thread, struct perf_sample *sample) { - struct evsel *evsel =3D sample->evsel; struct vcpu_event_record *vcpu_record; struct event_key key =3D { .key =3D INVALID_KEY, .exit_reasons =3D kvm->exit_reasons }; =20 - vcpu_record =3D per_vcpu_record(thread, evsel, sample); + vcpu_record =3D per_vcpu_record(thread, sample); if (!vcpu_record) return true; =20 @@ -957,13 +954,13 @@ static bool handle_kvm_event(struct perf_kvm_stat *kv= m, (kvm->trace_vcpu !=3D vcpu_record->vcpu_id)) return true; =20 - if (kvm->events_ops->is_begin_event(evsel, sample, &key)) + if (kvm->events_ops->is_begin_event(sample, &key)) return handle_begin_event(kvm, vcpu_record, &key, sample); =20 - if (is_child_event(kvm, evsel, sample, &key)) + if (is_child_event(kvm, sample, &key)) return handle_child_event(kvm, vcpu_record, &key, sample); =20 - if (kvm->events_ops->is_end_event(evsel, sample, &key)) + if (kvm->events_ops->is_end_event(sample, &key)) return handle_end_event(kvm, vcpu_record, &key, sample); =20 return true; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c b/tools/perf/ut= il/kvm-stat-arch/kvm-stat-arm64.c index c640dcd8af7c..1e76906f719c 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c @@ -17,10 +17,11 @@ static const char * const __kvm_events_tp[] =3D { NULL, }; =20 -static void event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_get_key(struct perf_sample *sample, struct event_key *key) { + struct evsel *evsel =3D sample->evsel; + key->info =3D 0; key->key =3D evsel__intval(evsel, sample, kvm_exit_reason(EM_AARCH64)); key->exit_reasons =3D arm64_exit_reasons; @@ -36,19 +37,17 @@ static void event_get_key(struct evsel *evsel, } } =20 -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_begin(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, kvm_entry_trace(EM_AARCH64)); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_AARCH64)); } =20 -static bool event_end(struct evsel *evsel, - struct perf_sample *sample, +static bool event_end(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, kvm_exit_trace(EM_AARCH64))) { - event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, kvm_exit_trace(EM_AARCH64))) { + event_get_key(sample, key); return true; } return false; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c b/tools/per= f/util/kvm-stat-arch/kvm-stat-loongarch.c index b802e516b138..9d6265290f6d 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c @@ -53,14 +53,12 @@ static const char * const __kvm_events_tp[] =3D { NULL, }; =20 -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool event_begin(struct perf_sample *sample, struct event_key *key) { - return exit_event_begin(evsel, sample, key); + return exit_event_begin(sample, key); } =20 -static bool event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { /* @@ -71,17 +69,16 @@ static bool event_end(struct evsel *evsel, * kvm:kvm_enter means returning to vmm and then to guest * kvm:kvm_reenter means returning to guest immediately */ - return evsel__name_is(evsel, kvm_entry_trace(EM_LOONGARCH)) || - evsel__name_is(evsel, kvm_reenter_trace); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_LOONGARCH)) || + evsel__name_is(sample->evsel, kvm_reenter_trace); } =20 -static void event_gspr_get_key(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static void event_gspr_get_key(struct perf_sample *sample, struct event_ke= y *key) { unsigned int insn; =20 key->key =3D LOONGARCH_EXCEPTION_OTHERS; - insn =3D evsel__intval(evsel, sample, "inst_word"); + insn =3D evsel__intval(sample->evsel, sample, "inst_word"); =20 switch (insn >> 24) { case 0: diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c b/tools/perf/= util/kvm-stat-arch/kvm-stat-powerpc.c index 42182d70beb6..5158d7e88ee6 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c @@ -28,12 +28,11 @@ static const char * const ppc_book3s_hv_kvm_tp[] =3D { /* 1 extra placeholder for NULL */ static const char *__kvm_events_tp[NR_TPS + 1]; =20 -static void hcall_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void hcall_event_get_key(struct perf_sample *sample, struct event_key *key) { key->info =3D 0; - key->key =3D evsel__intval(evsel, sample, "req"); + key->key =3D evsel__intval(sample->evsel, sample, "req"); } =20 static const char *get_hcall_exit_reason(u64 exit_code) @@ -51,18 +50,16 @@ static const char *get_hcall_exit_reason(u64 exit_code) return "UNKNOWN"; } =20 -static bool hcall_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool hcall_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, __kvm_events_tp[3]); + return evsel__name_is(sample->evsel, __kvm_events_tp[3]); } =20 -static bool hcall_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool hcall_event_begin(struct perf_sample *sample, struct event_key= *key) { - if (evsel__name_is(evsel, __kvm_events_tp[2])) { - hcall_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, __kvm_events_tp[2])) { + hcall_event_get_key(sample, key); return true; } =20 diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c b/tools/perf/ut= il/kvm-stat-arch/kvm-stat-riscv.c index 8d4d5d6ce720..e8db8b4f8e2e 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c @@ -20,30 +20,28 @@ static const char * const __kvm_events_tp[] =3D { NULL, }; =20 -static void event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_get_key(struct perf_sample *sample, struct event_key *key) { int xlen =3D 64; // TODO: 32-bit support. =20 key->info =3D 0; - key->key =3D evsel__intval(evsel, sample, kvm_exit_reason(EM_RISCV)) & ~C= AUSE_IRQ_FLAG(xlen); + key->key =3D evsel__intval(sample->evsel, sample, + kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); key->exit_reasons =3D riscv_exit_reasons; } =20 -static bool event_begin(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +static bool event_begin(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return evsel__name_is(evsel, kvm_entry_trace(EM_RISCV)); + return evsel__name_is(sample->evsel, kvm_entry_trace(EM_RISCV)); } =20 -static bool event_end(struct evsel *evsel, - struct perf_sample *sample, +static bool event_end(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, kvm_exit_trace(EM_RISCV))) { - event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, kvm_exit_trace(EM_RISCV))) { + event_get_key(sample, key); return true; } return false; diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c b/tools/perf/uti= l/kvm-stat-arch/kvm-stat-s390.c index 7e29169f5bb0..158372ba0205 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c @@ -18,38 +18,34 @@ define_exit_reasons_table(sie_sigp_order_codes, sigp_or= der_codes); define_exit_reasons_table(sie_diagnose_codes, diagnose_codes); define_exit_reasons_table(sie_icpt_prog_codes, icpt_prog_codes); =20 -static void event_icpt_insn_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_icpt_insn_get_key(struct perf_sample *sample, struct event_key *key) { u64 insn; =20 - insn =3D evsel__intval(evsel, sample, "instruction"); + insn =3D evsel__intval(sample->evsel, sample, "instruction"); key->key =3D icpt_insn_decoder(insn); key->exit_reasons =3D sie_icpt_insn_codes; } =20 -static void event_sigp_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_sigp_get_key(struct perf_sample *sample, struct event_key *key) { - key->key =3D evsel__intval(evsel, sample, "order_code"); + key->key =3D evsel__intval(sample->evsel, sample, "order_code"); key->exit_reasons =3D sie_sigp_order_codes; } =20 -static void event_diag_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_diag_get_key(struct perf_sample *sample, struct event_key *key) { - key->key =3D evsel__intval(evsel, sample, "code"); + key->key =3D evsel__intval(sample->evsel, sample, "code"); key->exit_reasons =3D sie_diagnose_codes; } =20 -static void event_icpt_prog_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void event_icpt_prog_get_key(struct perf_sample *sample, struct event_key *key) { - key->key =3D evsel__intval(evsel, sample, "code"); + key->key =3D evsel__intval(sample->evsel, sample, "code"); key->exit_reasons =3D sie_icpt_prog_codes; } =20 diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c b/tools/perf/util= /kvm-stat-arch/kvm-stat-x86.c index 0f626db3a439..0ce543d82850 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c @@ -24,45 +24,43 @@ static const struct kvm_events_ops exit_events =3D { * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...). */ -static void mmio_event_get_key(struct evsel *evsel, struct perf_sample *sa= mple, +static void mmio_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key =3D evsel__intval(evsel, sample, "gpa"); - key->info =3D evsel__intval(evsel, sample, "type"); + key->key =3D evsel__intval(sample->evsel, sample, "gpa"); + key->info =3D evsel__intval(sample->evsel, sample, "type"); } =20 #define KVM_TRACE_MMIO_READ_UNSATISFIED 0 #define KVM_TRACE_MMIO_READ 1 #define KVM_TRACE_MMIO_WRITE 2 =20 -static bool mmio_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +static bool mmio_event_begin(struct perf_sample *sample, struct event_key = *key) { /* MMIO read begin event in kernel. */ - if (kvm_exit_event(evsel)) + if (kvm_exit_event(sample->evsel)) return true; =20 /* MMIO write begin event in kernel. */ - if (evsel__name_is(evsel, "kvm:kvm_mmio") && - evsel__intval(evsel, sample, "type") =3D=3D KVM_TRACE_MMIO_WRITE) { - mmio_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && + evsel__intval(sample->evsel, sample, "type") =3D=3D KVM_TRACE_MMIO_WR= ITE) { + mmio_event_get_key(sample, key); return true; } =20 return false; } =20 -static bool mmio_event_end(struct evsel *evsel, struct perf_sample *sample, - struct event_key *key) +static bool mmio_event_end(struct perf_sample *sample, struct event_key *k= ey) { /* MMIO write end event in kernel. */ - if (kvm_entry_event(evsel)) + if (kvm_entry_event(sample->evsel)) return true; =20 /* MMIO read end event in kernel.*/ - if (evsel__name_is(evsel, "kvm:kvm_mmio") && - evsel__intval(evsel, sample, "type") =3D=3D KVM_TRACE_MMIO_READ) { - mmio_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && + evsel__intval(sample->evsel, sample, "type") =3D=3D KVM_TRACE_MMIO_RE= AD) { + mmio_event_get_key(sample, key); return true; } =20 @@ -86,31 +84,27 @@ static const struct kvm_events_ops mmio_events =3D { }; =20 /* The time of emulation pio access is from kvm_pio to kvm_entry. */ -static void ioport_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +static void ioport_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key =3D evsel__intval(evsel, sample, "port"); - key->info =3D evsel__intval(evsel, sample, "rw"); + key->key =3D evsel__intval(sample->evsel, sample, "port"); + key->info =3D evsel__intval(sample->evsel, sample, "rw"); } =20 -static bool ioport_event_begin(struct evsel *evsel, - struct perf_sample *sample, +static bool ioport_event_begin(struct perf_sample *sample, struct event_key *key) { - if (evsel__name_is(evsel, "kvm:kvm_pio")) { - ioport_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_pio")) { + ioport_event_get_key(sample, key); return true; } =20 return false; } =20 -static bool ioport_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) +static bool ioport_event_end(struct perf_sample *sample, struct event_key = *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } =20 static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unus= ed, @@ -130,31 +124,25 @@ static const struct kvm_events_ops ioport_events =3D { }; =20 /* The time of emulation msr is from kvm_msr to kvm_entry. */ -static void msr_event_get_key(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) +static void msr_event_get_key(struct perf_sample *sample, struct event_key= *key) { - key->key =3D evsel__intval(evsel, sample, "ecx"); - key->info =3D evsel__intval(evsel, sample, "write"); + key->key =3D evsel__intval(sample->evsel, sample, "ecx"); + key->info =3D evsel__intval(sample->evsel, sample, "write"); } =20 -static bool msr_event_begin(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) +static bool msr_event_begin(struct perf_sample *sample, struct event_key *= key) { - if (evsel__name_is(evsel, "kvm:kvm_msr")) { - msr_event_get_key(evsel, sample, key); + if (evsel__name_is(sample->evsel, "kvm:kvm_msr")) { + msr_event_get_key(sample, key); return true; } =20 return false; } =20 -static bool msr_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) +static bool msr_event_end(struct perf_sample *sample, struct event_key *ke= y __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } =20 static void msr_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c index 27f16810498c..f17a6132958d 100644 --- a/tools/perf/util/kvm-stat.c +++ b/tools/perf/util/kvm-stat.c @@ -11,22 +11,20 @@ bool kvm_exit_event(struct evsel *evsel) return evsel__name_is(evsel, kvm_exit_trace(e_machine)); } =20 -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +void exit_event_get_key(struct perf_sample *sample, struct event_key *key) { - uint16_t e_machine =3D evsel__e_machine(evsel, /*e_flags=3D*/NULL); + uint16_t e_machine =3D evsel__e_machine(sample->evsel, /*e_flags=3D*/NULL= ); =20 key->info =3D 0; - key->key =3D evsel__intval(evsel, sample, kvm_exit_reason(e_machine)); + key->key =3D evsel__intval(sample->evsel, sample, kvm_exit_reason(e_mach= ine)); } =20 =20 -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) +bool exit_event_begin(struct perf_sample *sample, struct event_key *key) { - if (kvm_exit_event(evsel)) { - exit_event_get_key(evsel, sample, key); + if (kvm_exit_event(sample->evsel)) { + exit_event_get_key(sample, key); return true; } =20 @@ -40,11 +38,10 @@ bool kvm_entry_event(struct evsel *evsel) return evsel__name_is(evsel, kvm_entry_trace(e_machine)); } =20 -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, +bool exit_event_end(struct perf_sample *sample, struct event_key *key __maybe_unused) { - return kvm_entry_event(evsel); + return kvm_entry_event(sample->evsel); } =20 static const char *get_exit_reason(struct perf_kvm_stat *kvm, diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 4a998aaece5d..cdbd921a555f 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -53,18 +53,15 @@ struct kvm_event { }; =20 struct child_event_ops { - void (*get_key)(struct evsel *evsel, - struct perf_sample *sample, + void (*get_key)(struct perf_sample *sample, struct event_key *key); const char *name; }; =20 struct kvm_events_ops { - bool (*is_begin_event)(struct evsel *evsel, - struct perf_sample *sample, + bool (*is_begin_event)(struct perf_sample *sample, struct event_key *key); - bool (*is_end_event)(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key); + bool (*is_end_event)(struct perf_sample *sample, struct event_key *key); const struct child_event_ops *child_ops; void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key, char *decode); @@ -116,14 +113,11 @@ struct kvm_reg_events_ops { =20 #ifdef HAVE_LIBTRACEEVENT =20 -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, +void exit_event_get_key(struct perf_sample *sample, struct event_key *key); -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, +bool exit_event_begin(struct perf_sample *sample, struct event_key *key); -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample, +bool exit_event_end(struct perf_sample *sample, struct event_key *key); void exit_event_decode_key(struct perf_kvm_stat *kvm, struct event_key *key, --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BB953D8135 for ; Fri, 3 Apr 2026 20:40:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248842; cv=none; b=pUkIQSc7s+iSda5pOdNie653aLWumgGuZ/7155UV1fnCZTZFzB1E99C+xx7vN7KE0fHYVQkFiwVPyHoCH4VayjoaagRDb8nh/a3wAuqYbZnZpg8q3JhP1I0p7Yo+RQz07CLLQeUsHdtout3eDevhkEJR0jMLS4lyF51xV3OC7Fo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248842; c=relaxed/simple; bh=NEyWPmTruPfBNWSoOo4CIII6fCmGtHf28Hq+Ln22UmY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sd/dV76UDPzVe76PJ2rw6Ho5FeSZB//kSbDOKIcd9ADAgRqvPQJ+uxGl/kVoagR2P6O0CjpBYPKtfl/npFJCjtklvaRXOsU2LBqcEXCq7yvvgj1w2JozJpFBnqJuHdqDHDlbuPhG8iOsJpmQqxzVCZ5A0TlJ/JvJYBhWHmmGt8U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=oqj1iGKW; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oqj1iGKW" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12776bebeb3so5115962c88.1 for ; Fri, 03 Apr 2026 13:40:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248839; x=1775853639; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xgXa/WFblF5SbB1e+i0mNz9nCyXqv8X/t/HbyuuXVdY=; b=oqj1iGKWZ1dCBy2q3GJ/KaYd583oFuBC26eif4ciDb1TnNMPoWjVPkq3+RAzhz85a0 qvFkdDQDUAbMzOZa7bKpKeWREU0hof8yGCm9T1raF1PeR5wl8KgsSls/ob1uUSXYx3rd 6nmvHIdwcIhM8zj8AGvVfL0ItcAsWxmNmexuR1JYAnIh6NS2BHzCfNZsyT6RSbPdLs+F bhH3i9olQ4AO7gdX1L23HN9sRyXyCfGiWbvzc2/N87nF/dBOnAzKmDxCPhtyI3GGcSd3 683M6bielW5cS6ZUv9l368alOx6+7RkblgYAFZuwagikiFU8WUOk++pGrMXz7NJzeCvU cUGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248839; x=1775853639; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xgXa/WFblF5SbB1e+i0mNz9nCyXqv8X/t/HbyuuXVdY=; b=e1VCpQLPgw/kBkbmy01zyX6TwAX9EXT3KY2ySZmEuKLigVXRrewIAmooNi310QH6rN RDdA9CdLqNhM/hO2g+ro8m/5TOExeGF2JjHWtsx8OqSemJgIQxu6+QboPcgiOeI1+R0G eIdxdnZWtu7WvElqv/PT9Y/qatrUy7GzjUSnNcdJDLT4eSzQe+eqlAgUb9Jp/88NN3jY o1Vv3txb7Mucdj3xQusY9PCuJc387s82J65yelfGmzSnpqqpQwT0+7IDFq3UfMGLv3c5 7ocgOr9olz10Ko0sOVu2z6Sb3ty/X5Y3E4DDoa2r4d4/Zf+KLBSKN1aewu6KQXHbbeTH PK8g== X-Forwarded-Encrypted: i=1; AJvYcCVpv60O7R0CMMkaqjQ8HIDo7piXr66pVZOsoDyv5rGIVXjGTlb+2v5v58p2ZgopCi2cl2WMUF07yU7oVwc=@vger.kernel.org X-Gm-Message-State: AOJu0YycVnYJF4knKmQrLNabarG1lfQXlegvkOf6Nhr0lakJ8vcy6U9y koY764SfJgw4Z1oM0kSPQD8eKAlURRNF9wyroZfwv8Pn8jKhEDCgytWDuUgrpQESXWbt07BNKwb 6Z6Ywcy6D+Q== X-Received: from dlad11.prod.google.com ([2002:a05:701b:220b:b0:128:cffb:50d7]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6725:b0:12a:6a64:8212 with SMTP id a92af1059eb24-12bfb6ecd90mr2018848c88.4.1775248838401; Fri, 03 Apr 2026 13:40:38 -0700 (PDT) Date: Fri, 3 Apr 2026 13:39:58 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-7-irogers@google.com> Subject: [PATCH v5 06/25] perf evsel: Refactor evsel tracepoint sample accessors perf_sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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. Add bounds checks to a number read values from review feedback. Make perf_sample__strval avoid returning NULL pointers, return an empty string instead. Fix the function type to reflect this, catching a bug in kwork where the string wasn't being duplicated. Signed-off-by: Ian Rogers --- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 49 ++++++--- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-kwork.c | 29 +++-- tools/perf/builtin-lock.c | 32 +++--- tools/perf/builtin-sched.c | 97 ++++++++-------- tools/perf/builtin-timechart.c | 104 ++++++++++-------- tools/perf/builtin-trace.c | 12 +- tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/tests/switch-tracking.c | 4 +- tools/perf/util/evsel.c | 33 ++++-- 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, 230 insertions(+), 189 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index a958ac7cec9d..237ee708d689 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1082,7 +1082,7 @@ static int perf_inject__sched_stat(const struct perf_= tool *tool, union perf_event *event_sw; struct perf_sample sample_sw; struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); - u32 pid =3D evsel__intval(evsel, sample, "pid"); + u32 pid =3D perf_sample__intval(sample, "pid"); int ret; =20 list_for_each_entry(ent, &inject->samples, node) { diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 34852a4c3fc8..4f3ff29d2a9f 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -173,10 +173,10 @@ static int insert_caller_stat(unsigned long call_site, =20 static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sam= ple *sample) { - unsigned long ptr =3D evsel__intval(evsel, sample, "ptr"), - call_site =3D evsel__intval(evsel, sample, "call_site"); - int bytes_req =3D evsel__intval(evsel, sample, "bytes_req"), - bytes_alloc =3D evsel__intval(evsel, sample, "bytes_alloc"); + unsigned long ptr =3D perf_sample__intval(sample, "ptr"), + call_site =3D perf_sample__intval(sample, "call_site"); + int bytes_req =3D perf_sample__intval(sample, "bytes_req"), + bytes_alloc =3D perf_sample__intval(sample, "bytes_alloc"); =20 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 *evs= el, struct perf_sample *s int node1, node2; =20 node1 =3D cpu__get_node((struct perf_cpu){.cpu =3D sample->cpu}); - node2 =3D evsel__intval(evsel, sample, "node"); + node2 =3D perf_sample__intval(sample, "node"); =20 /* * 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 lo= ng ptr, return NULL; } =20 -static int evsel__process_free_event(struct evsel *evsel, struct perf_samp= le *sample) +static int evsel__process_free_event(struct evsel *evsel __maybe_unused, s= truct perf_sample *sample) { - unsigned long ptr =3D evsel__intval(evsel, sample, "ptr"); + unsigned long ptr =3D perf_sample__intval(sample, "ptr"); struct alloc_stat *s_alloc, *s_caller; =20 s_alloc =3D 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 per= f_sample *sample) { u64 page; - unsigned int order =3D evsel__intval(evsel, sample, "order"); - unsigned int gfp_flags =3D evsel__intval(evsel, sample, "gfp_flags"); - unsigned int migrate_type =3D evsel__intval(evsel, sample, - "migratetype"); + unsigned int order =3D perf_sample__intval(sample, "order"); + unsigned int gfp_flags =3D perf_sample__intval(sample, "gfp_flags"); + unsigned int migrate_type =3D perf_sample__intval(sample, "migratetype"); u64 bytes =3D kmem_page_size << order; u64 callsite; struct page_stat *pstat; @@ -821,10 +820,20 @@ static int evsel__process_page_alloc_event(struct evs= el *evsel, struct perf_samp .migrate_type =3D migrate_type, }; =20 + if (order >=3D MAX_PAGE_ORDER) { + pr_debug("Out-of-bounds order %u\n", order); + return -1; + } + + if (migrate_type >=3D MAX_MIGRATE_TYPES) { + pr_debug("Out-of-bounds migratetype %u\n", migrate_type); + return -1; + } + if (use_pfn) - page =3D evsel__intval(evsel, sample, "pfn"); + page =3D perf_sample__intval(sample, "pfn"); else - page =3D evsel__intval(evsel, sample, "page"); + page =3D perf_sample__intval(sample, "page"); =20 nr_page_allocs++; total_page_alloc_bytes +=3D bytes; @@ -877,20 +886,26 @@ static int evsel__process_page_alloc_event(struct evs= el *evsel, struct perf_samp return 0; } =20 -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_unus= ed, + struct perf_sample *sample) { u64 page; - unsigned int order =3D evsel__intval(evsel, sample, "order"); + unsigned int order =3D perf_sample__intval(sample, "order"); u64 bytes =3D kmem_page_size << order; struct page_stat *pstat; struct page_stat this =3D { .order =3D order, }; =20 + if (order >=3D MAX_PAGE_ORDER) { + pr_debug("Out-of-bounds order %u\n", order); + return -1; + } + if (use_pfn) - page =3D evsel__intval(evsel, sample, "pfn"); + page =3D perf_sample__intval(sample, "pfn"); else - page =3D evsel__intval(evsel, sample, "page"); + page =3D perf_sample__intval(sample, "page"); =20 nr_page_frees++; total_page_free_bytes +=3D bytes; diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index d9b9792894a8..dd2ed21596aa 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -930,7 +930,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread= *thread, return NULL; } =20 - vcpu_record->vcpu_id =3D evsel__intval(sample->evsel, sample, vcpu_id_st= r(e_machine)); + vcpu_record->vcpu_id =3D perf_sample__intval(sample, vcpu_id_str(e_machi= ne)); thread__set_priv(thread, vcpu_record); } =20 diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index e34a1f35439e..0d45f425c79b 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1006,7 +1006,7 @@ static void irq_work_init(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused) { @@ -1014,11 +1014,11 @@ static void irq_work_init(struct perf_kwork *kwork, work->cpu =3D sample->cpu; =20 if (kwork->report =3D=3D KWORK_REPORT_TOP) { - work->id =3D evsel__intval_common(evsel, sample, "common_pid"); + work->id =3D perf_sample__intval_common(sample, "common_pid"); work->name =3D NULL; } else { - work->id =3D evsel__intval(evsel, sample, "irq"); - work->name =3D evsel__strval(evsel, sample, "name"); + work->id =3D perf_sample__intval(sample, "irq"); + work->name =3D strdup(perf_sample__strval(sample, "name")); } } =20 @@ -1144,10 +1144,10 @@ static void softirq_work_init(struct perf_kwork *kw= ork, work->cpu =3D sample->cpu; =20 if (kwork->report =3D=3D KWORK_REPORT_TOP) { - work->id =3D evsel__intval_common(evsel, sample, "common_pid"); + work->id =3D perf_sample__intval_common(sample, "common_pid"); work->name =3D NULL; } else { - num =3D evsel__intval(evsel, sample, "vec"); + num =3D perf_sample__intval(sample, "vec"); work->id =3D num; work->name =3D 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 =3D NULL; - unsigned long long function_addr =3D evsel__intval(evsel, - sample, "function"); + unsigned long long function_addr =3D perf_sample__intval(sample, "functio= n"); =20 work->class =3D class; work->cpu =3D sample->cpu; - work->id =3D evsel__intval(evsel, sample, "work"); + work->id =3D perf_sample__intval(sample, "work"); work->name =3D function_addr =3D=3D 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 *kwor= k __maybe_unused, work->cpu =3D sample->cpu; =20 if (src_type =3D=3D KWORK_TRACE_EXIT) { - work->id =3D evsel__intval(evsel, sample, "prev_pid"); - work->name =3D strdup(evsel__strval(evsel, sample, "prev_comm")); + work->id =3D perf_sample__intval(sample, "prev_pid"); + work->name =3D strdup(perf_sample__strval(sample, "prev_comm") ?: ""); } else if (src_type =3D=3D KWORK_TRACE_ENTRY) { - work->id =3D evsel__intval(evsel, sample, "next_pid"); - work->name =3D strdup(evsel__strval(evsel, sample, "next_comm")); + work->id =3D perf_sample__intval(sample, "next_pid"); + work->name =3D strdup(perf_sample__strval(sample, "next_comm") ?: ""); } } =20 diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 4d8ddf6391e8..cbf3a39c7837 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -563,15 +563,15 @@ static int get_key_by_aggr_mode(u64 *key, u64 addr, s= truct evsel *evsel, return get_key_by_aggr_mode_simple(key, addr, sample->tid); } =20 -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 =3D evsel__strval(evsel, sample, "name"); - u64 addr =3D evsel__intval(evsel, sample, "lockdep_addr"); - int flag =3D evsel__intval(evsel, sample, "flags"); + const char *name =3D perf_sample__strval(sample, "name"); + u64 addr =3D perf_sample__intval(sample, "lockdep_addr"); + int flag =3D perf_sample__intval(sample, "flags"); u64 key; int ret; =20 @@ -638,15 +638,15 @@ static int report_lock_acquire_event(struct evsel *ev= sel, return 0; } =20 -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 =3D evsel__strval(evsel, sample, "name"); - u64 addr =3D evsel__intval(evsel, sample, "lockdep_addr"); + const char *name =3D perf_sample__strval(sample, "name"); + u64 addr =3D perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; =20 @@ -704,14 +704,14 @@ static int report_lock_acquired_event(struct evsel *e= vsel, return 0; } =20 -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 =3D evsel__strval(evsel, sample, "name"); - u64 addr =3D evsel__intval(evsel, sample, "lockdep_addr"); + const char *name =3D perf_sample__strval(sample, "name"); + u64 addr =3D perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; =20 @@ -762,14 +762,14 @@ static int report_lock_contended_event(struct evsel *= evsel, return 0; } =20 -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 =3D evsel__strval(evsel, sample, "name"); - u64 addr =3D evsel__intval(evsel, sample, "lockdep_addr"); + const char *name =3D perf_sample__strval(sample, "name"); + u64 addr =3D perf_sample__intval(sample, "lockdep_addr"); u64 key; int ret; =20 @@ -969,8 +969,8 @@ static int report_lock_contention_begin_event(struct ev= sel *evsel, struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; - u64 addr =3D evsel__intval(evsel, sample, "lock_addr"); - unsigned int flags =3D evsel__intval(evsel, sample, "flags"); + u64 addr =3D perf_sample__intval(sample, "lock_addr"); + unsigned int flags =3D 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 ev= sel *evsel, struct thread_stat *ts; struct lock_seq_stat *seq; u64 contended_term; - u64 addr =3D evsel__intval(evsel, sample, "lock_addr"); + u64 addr =3D perf_sample__intval(sample, "lock_addr"); u64 key; int ret; =20 diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 296b9837278a..3e7e8ad0bc13 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -829,8 +829,8 @@ replay_wakeup_event(struct perf_sched *sched, struct evsel *evsel, struct perf_sample *sample, struct machine *machine __maybe_unused) { - const char *comm =3D evsel__strval(evsel, sample, "comm"); - const u32 pid =3D evsel__intval(evsel, sample, "pid"); + const char *comm =3D perf_sample__strval(sample, "comm"); + const u32 pid =3D perf_sample__intval(sample, "pid"); struct task_desc *waker, *wakee; =20 if (verbose > 0) { @@ -851,10 +851,10 @@ static int replay_switch_event(struct perf_sched *sch= ed, struct perf_sample *sample, struct machine *machine __maybe_unused) { - const char *prev_comm =3D evsel__strval(evsel, sample, "prev_comm"), - *next_comm =3D evsel__strval(evsel, sample, "next_comm"); - const u32 prev_pid =3D evsel__intval(evsel, sample, "prev_pid"), - next_pid =3D evsel__intval(evsel, sample, "next_pid"); + const char *prev_comm =3D perf_sample__strval(sample, "prev_comm"), + *next_comm =3D perf_sample__strval(sample, "next_comm"); + const u32 prev_pid =3D perf_sample__intval(sample, "prev_pid"), + next_pid =3D perf_sample__intval(sample, "next_pid"); struct task_desc *prev, __maybe_unused *next; u64 timestamp0, timestamp =3D sample->time; int cpu =3D sample->cpu; @@ -1134,13 +1134,13 @@ static void free_work_atoms(struct work_atoms *atom= s) } =20 static int latency_switch_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 prev_pid =3D evsel__intval(evsel, sample, "prev_pid"), - next_pid =3D evsel__intval(evsel, sample, "next_pid"); - const char prev_state =3D evsel__taskstate(evsel, sample, "prev_state"); + const u32 prev_pid =3D perf_sample__intval(sample, "prev_pid"), + next_pid =3D perf_sample__intval(sample, "next_pid"); + const char prev_state =3D perf_sample__taskstate(sample, "prev_state"); struct work_atoms *out_events, *in_events; struct thread *sched_out, *sched_in; u64 timestamp0, timestamp =3D sample->time; @@ -1204,12 +1204,12 @@ static int latency_switch_event(struct perf_sched *= sched, } =20 static int latency_runtime_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid =3D evsel__intval(evsel, sample, "pid"); - const u64 runtime =3D evsel__intval(evsel, sample, "runtime"); + const u32 pid =3D perf_sample__intval(sample, "pid"); + const u64 runtime =3D perf_sample__intval(sample, "runtime"); struct thread *thread =3D machine__findnew_thread(machine, -1, pid); struct work_atoms *atoms =3D thread_atoms_search(&sched->atom_root, threa= d, &sched->cmp_pid); u64 timestamp =3D sample->time; @@ -1239,11 +1239,11 @@ static int latency_runtime_event(struct perf_sched = *sched, } =20 static int latency_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid =3D evsel__intval(evsel, sample, "pid"); + const u32 pid =3D perf_sample__intval(sample, "pid"); struct work_atoms *atoms; struct work_atom *atom; struct thread *wakee; @@ -1300,11 +1300,11 @@ static int latency_wakeup_event(struct perf_sched *= sched, } =20 static int latency_migrate_task_event(struct perf_sched *sched, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 pid =3D evsel__intval(evsel, sample, "pid"); + const u32 pid =3D perf_sample__intval(sample, "pid"); u64 timestamp =3D sample->time; struct work_atoms *atoms; struct work_atom *atom; @@ -1626,11 +1626,11 @@ static void print_sched_map(struct perf_sched *sche= d, struct perf_cpu this_cpu, } } =20 -static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, +static int map_switch_event(struct perf_sched *sched, struct evsel *evsel = __maybe_unused, struct perf_sample *sample, struct machine *machine) { - const u32 next_pid =3D evsel__intval(evsel, sample, "next_pid"); - const u32 prev_pid =3D evsel__intval(evsel, sample, "prev_pid"); + const u32 next_pid =3D perf_sample__intval(sample, "next_pid"); + const u32 prev_pid =3D perf_sample__intval(sample, "prev_pid"); struct thread *sched_in, *sched_out; struct thread_runtime *tr; int new_shortname; @@ -1797,8 +1797,13 @@ static int process_sched_switch_event(const struct p= erf_tool *tool, { struct perf_sched *sched =3D container_of(tool, struct perf_sched, tool); int this_cpu =3D sample->cpu, err =3D 0; - u32 prev_pid =3D evsel__intval(evsel, sample, "prev_pid"), - next_pid =3D evsel__intval(evsel, sample, "next_pid"); + u32 prev_pid =3D perf_sample__intval(sample, "prev_pid"), + next_pid =3D perf_sample__intval(sample, "next_pid"); + + if (this_cpu < 0 || this_cpu >=3D MAX_CPUS) { + pr_debug("Out-of-bound sample CPU %d\n", this_cpu); + return -1; + } =20 if (sched->curr_pid[this_cpu] !=3D (u32)-1) { /* @@ -2068,12 +2073,11 @@ static char *timehist_get_commstr(struct thread *th= read) =20 /* prio field format: xxx or xxx->yyy */ #define MAX_PRIO_STR_LEN 8 -static char *timehist_get_priostr(struct evsel *evsel, - struct thread *thread, +static char *timehist_get_priostr(struct thread *thread, struct perf_sample *sample) { static char prio_str[16]; - int prev_prio =3D (int)evsel__intval(evsel, sample, "prev_prio"); + int prev_prio =3D (int)perf_sample__intval(sample, "prev_prio"); struct thread_runtime *tr =3D thread__priv(thread); =20 if (tr->prio !=3D prev_prio && tr->prio !=3D -1) @@ -2161,15 +2165,14 @@ static void timehist_header(struct perf_sched *sche= d) } =20 static void timehist_print_sample(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct addr_location *al, struct thread *thread, u64 t, const char state) { struct thread_runtime *tr =3D thread__priv(thread); - const char *next_comm =3D evsel__strval(evsel, sample, "next_comm"); - const u32 next_pid =3D evsel__intval(evsel, sample, "next_pid"); + const char *next_comm =3D perf_sample__strval(sample, "next_comm"); + const u32 next_pid =3D perf_sample__intval(sample, "next_pid"); u32 max_cpus =3D sched->max_cpu.cpu + 1; char tstr[64]; char nstr[30]; @@ -2198,14 +2201,15 @@ static void timehist_print_sample(struct perf_sched= *sched, } =20 if (!thread__comm_set(thread)) { - const char *prev_comm =3D evsel__strval(evsel, sample, "pr= ev_comm"); - thread__set_comm(thread, prev_comm, sample->time); + const char *prev_comm =3D perf_sample__strval(sample, "prev_comm"); + + thread__set_comm(thread, prev_comm, sample->time); } =20 printf(" %-*s ", comm_width, timehist_get_commstr(thread)); =20 if (sched->show_prio) - printf(" %-*s ", MAX_PRIO_STR_LEN, timehist_get_priostr(evsel, thread, s= ample)); + printf(" %-*s ", MAX_PRIO_STR_LEN, timehist_get_priostr(thread, sample)); =20 wait_time =3D tr->dt_sleep + tr->dt_iowait + tr->dt_preempt; print_sched_time(wait_time, 6); @@ -2319,7 +2323,7 @@ static bool is_idle_sample(struct perf_sample *sample, { /* pid 0 =3D=3D swapper =3D=3D idle task */ if (evsel__name_is(evsel, "sched:sched_switch")) - return evsel__intval(evsel, sample, "prev_pid") =3D=3D 0; + return perf_sample__intval(sample, "prev_pid") =3D=3D 0; =20 return sample->pid =3D=3D 0; } @@ -2539,7 +2543,7 @@ static struct thread *timehist_get_thread(struct perf= _sched *sched, itr->last_thread =3D thread__get(thread); =20 /* copy task callchain when entering to idle */ - if (evsel__intval(evsel, sample, "next_pid") =3D=3D 0) + if (perf_sample__intval(sample, "next_pid") =3D=3D 0) save_idle_callchain(sched, itr, sample); } } @@ -2572,7 +2576,7 @@ static bool timehist_skip_sample(struct perf_sched *s= ched, if (tr && tr->prio !=3D -1) prio =3D tr->prio; else if (evsel__name_is(evsel, "sched:sched_switch")) - prio =3D evsel__intval(evsel, sample, "prev_prio"); + prio =3D perf_sample__intval(sample, "prev_prio"); =20 if (prio !=3D -1 && !test_bit(prio, sched->prio_bitmap)) { rc =3D true; @@ -2583,8 +2587,8 @@ static bool timehist_skip_sample(struct perf_sched *s= ched, if (sched->idle_hist) { if (!evsel__name_is(evsel, "sched:sched_switch")) rc =3D true; - else if (evsel__intval(evsel, sample, "prev_pid") !=3D 0 && - evsel__intval(evsel, sample, "next_pid") !=3D 0) + else if (perf_sample__intval(sample, "prev_pid") !=3D 0 && + perf_sample__intval(sample, "next_pid") !=3D 0) rc =3D true; } =20 @@ -2647,7 +2651,7 @@ static int timehist_sched_wakeup_event(const struct p= erf_tool *tool, struct thread *thread; struct thread_runtime *tr =3D NULL; /* want pid of awakened task not pid in sample */ - const u32 pid =3D evsel__intval(evsel, sample, "pid"); + const u32 pid =3D perf_sample__intval(sample, "pid"); =20 thread =3D machine__findnew_thread(machine, 0, pid); if (thread =3D=3D NULL) @@ -2686,8 +2690,8 @@ static void timehist_print_migration_event(struct per= f_sched *sched, return; =20 max_cpus =3D sched->max_cpu.cpu + 1; - ocpu =3D evsel__intval(evsel, sample, "orig_cpu"); - dcpu =3D evsel__intval(evsel, sample, "dest_cpu"); + ocpu =3D perf_sample__intval(sample, "orig_cpu"); + dcpu =3D perf_sample__intval(sample, "dest_cpu"); =20 thread =3D machine__findnew_thread(machine, sample->pid, sample->tid); if (thread =3D=3D NULL) @@ -2736,7 +2740,7 @@ static int timehist_migrate_task_event(const struct p= erf_tool *tool, struct thread *thread; struct thread_runtime *tr =3D NULL; /* want pid of migrated task not pid in sample */ - const u32 pid =3D evsel__intval(evsel, sample, "pid"); + const u32 pid =3D perf_sample__intval(sample, "pid"); =20 thread =3D machine__findnew_thread(machine, 0, pid); if (thread =3D=3D NULL) @@ -2761,14 +2765,13 @@ static int timehist_migrate_task_event(const struct= perf_tool *tool, return 0; } =20 -static void timehist_update_task_prio(struct evsel *evsel, - struct perf_sample *sample, +static void timehist_update_task_prio(struct perf_sample *sample, struct machine *machine) { struct thread *thread; struct thread_runtime *tr =3D NULL; - const u32 next_pid =3D evsel__intval(evsel, sample, "next_pid"); - const u32 next_prio =3D evsel__intval(evsel, sample, "next_prio"); + const u32 next_pid =3D perf_sample__intval(sample, "next_pid"); + const u32 next_prio =3D perf_sample__intval(sample, "next_prio"); =20 if (next_pid =3D=3D 0) thread =3D get_idle_thread(sample->cpu); @@ -2798,7 +2801,7 @@ static int timehist_sched_change_event(const struct p= erf_tool *tool, struct thread_runtime *tr =3D NULL; u64 tprev, t =3D sample->time; int rc =3D 0; - const char state =3D evsel__taskstate(evsel, sample, "prev_state"); + const char state =3D perf_sample__taskstate(sample, "prev_state"); =20 addr_location__init(&al); if (machine__resolve(machine, &al, sample) < 0) { @@ -2809,7 +2812,7 @@ static int timehist_sched_change_event(const struct p= erf_tool *tool, } =20 if (sched->show_prio || sched->prio_str) - timehist_update_task_prio(evsel, sample, machine); + timehist_update_task_prio(sample, machine); =20 thread =3D timehist_get_thread(sched, sample, machine, evsel); if (thread =3D=3D NULL) { @@ -2891,7 +2894,7 @@ static int timehist_sched_change_event(const struct p= erf_tool *tool, } =20 if (!sched->summary_only) - timehist_print_sample(sched, evsel, sample, &al, thread, t, state); + timehist_print_sample(sched, sample, &al, thread, t, state); } =20 out: diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 8692d11ccd29..782ede4258a2 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -597,13 +597,17 @@ static int process_sample_event(const struct perf_too= l *tool, =20 static int process_sample_cpu_idle(struct timechart *tchart __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u32 state =3D evsel__intval(evsel, sample, "state"); - u32 cpu_id =3D evsel__intval(evsel, sample, "cpu_id"); + u32 state =3D perf_sample__intval(sample, "state"); + u32 cpu_id =3D perf_sample__intval(sample, "cpu_id"); =20 + if (cpu_id >=3D MAX_CPUS) { + pr_debug("Out-of-bounds cpu_id %u\n", cpu_id); + return -1; + } if (state =3D=3D (u32)PWR_EVENT_EXIT) c_state_end(tchart, cpu_id, sample->time); else @@ -613,26 +617,30 @@ process_sample_cpu_idle(struct timechart *tchart __ma= ybe_unused, =20 static int process_sample_cpu_frequency(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u32 state =3D evsel__intval(evsel, sample, "state"); - u32 cpu_id =3D evsel__intval(evsel, sample, "cpu_id"); + u32 state =3D perf_sample__intval(sample, "state"); + u32 cpu_id =3D perf_sample__intval(sample, "cpu_id"); =20 + if (cpu_id >=3D 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; } =20 static int process_sample_sched_wakeup(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { - u8 flags =3D evsel__intval(evsel, sample, "common_flags"); - int waker =3D evsel__intval(evsel, sample, "common_pid"); - int wakee =3D evsel__intval(evsel, sample, "pid"); + u8 flags =3D perf_sample__intval(sample, "common_flags"); + int waker =3D perf_sample__intval(sample, "common_pid"); + int wakee =3D perf_sample__intval(sample, "pid"); =20 sched_wakeup(tchart, sample->cpu, sample->time, waker, wakee, flags, back= trace); return 0; @@ -640,13 +648,13 @@ process_sample_sched_wakeup(struct timechart *tchart, =20 static int process_sample_sched_switch(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { - int prev_pid =3D evsel__intval(evsel, sample, "prev_pid"); - int next_pid =3D evsel__intval(evsel, sample, "next_pid"); - u64 prev_state =3D evsel__intval(evsel, sample, "prev_state"); + int prev_pid =3D perf_sample__intval(sample, "prev_pid"); + int next_pid =3D perf_sample__intval(sample, "next_pid"); + u64 prev_state =3D perf_sample__intval(sample, "prev_state"); =20 sched_switch(tchart, sample->cpu, sample->time, prev_pid, next_pid, prev_state, backtrace); @@ -656,13 +664,17 @@ process_sample_sched_switch(struct timechart *tchart, #ifdef SUPPORT_OLD_POWER_EVENTS static int process_sample_power_start(struct timechart *tchart __maybe_unused, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u64 cpu_id =3D evsel__intval(evsel, sample, "cpu_id"); - u64 value =3D evsel__intval(evsel, sample, "value"); + u64 cpu_id =3D perf_sample__intval(sample, "cpu_id"); + u64 value =3D perf_sample__intval(sample, "value"); =20 + if (cpu_id >=3D MAX_CPUS) { + pr_debug("Out-of-bounds cpu_id %llu\n", (unsigned long long)cpu_id); + return -1; + } c_state_start(cpu_id, sample->time, value); return 0; } @@ -679,13 +691,17 @@ process_sample_power_end(struct timechart *tchart, =20 static int process_sample_power_frequency(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u64 cpu_id =3D evsel__intval(evsel, sample, "cpu_id"); - u64 value =3D evsel__intval(evsel, sample, "value"); + u64 cpu_id =3D perf_sample__intval(sample, "cpu_id"); + u64 value =3D perf_sample__intval(sample, "value"); =20 + if (cpu_id >=3D MAX_CPUS) { + pr_debug("Out-of-bounds cpu_id %llu\n", (unsigned long long)cpu_id); + return -1; + } p_state_change(tchart, cpu_id, sample->time, value); return 0; } @@ -849,120 +865,120 @@ static int pid_end_io_sample(struct timechart *tcha= rt, int pid, int type, =20 static int process_enter_read(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd =3D evsel__intval(evsel, sample, "fd"); + long fd =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ, sample->time, fd); } =20 static int process_exit_read(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret =3D evsel__intval(evsel, sample, "ret"); + long ret =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_READ, sample->time, ret); } =20 static int process_enter_write(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd =3D evsel__intval(evsel, sample, "fd"); + long fd =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE, sample->time, fd); } =20 static int process_exit_write(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret =3D evsel__intval(evsel, sample, "ret"); + long ret =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_WRITE, sample->time, ret); } =20 static int process_enter_sync(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd =3D evsel__intval(evsel, sample, "fd"); + long fd =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC, sample->time, fd); } =20 static int process_exit_sync(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret =3D evsel__intval(evsel, sample, "ret"); + long ret =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_SYNC, sample->time, ret); } =20 static int process_enter_tx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd =3D evsel__intval(evsel, sample, "fd"); + long fd =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX, sample->time, fd); } =20 static int process_exit_tx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret =3D evsel__intval(evsel, sample, "ret"); + long ret =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_TX, sample->time, ret); } =20 static int process_enter_rx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd =3D evsel__intval(evsel, sample, "fd"); + long fd =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX, sample->time, fd); } =20 static int process_exit_rx(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret =3D evsel__intval(evsel, sample, "ret"); + long ret =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_RX, sample->time, ret); } =20 static int process_enter_poll(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long fd =3D evsel__intval(evsel, sample, "fd"); + long fd =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL, sample->time, fd); } =20 static int process_exit_poll(struct timechart *tchart, - struct evsel *evsel, + struct evsel *evsel __maybe_unused, struct perf_sample *sample) { - long ret =3D evsel__intval(evsel, sample, "ret"); + long ret =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_POLL, sample->time, ret); } diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index aad433b870ee..0d6d3f901f67 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3059,7 +3059,7 @@ errno_print: { return err; } =20 -static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, +static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __m= aybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3068,7 +3068,7 @@ static int trace__vfs_getname(struct trace *trace, st= ruct evsel *evsel, size_t filename_len, entry_str_len, to_move; ssize_t remaining_space; char *pos; - const char *filename =3D evsel__rawptr(evsel, sample, "pathname"); + const char *filename =3D perf_sample__strval(sample, "pathname"); =20 if (!thread) goto out; @@ -3124,7 +3124,7 @@ static int trace__sched_stat_runtime(struct trace *tr= ace, struct evsel *evsel, union perf_event *event __maybe_unused, struct perf_sample *sample) { - u64 runtime =3D evsel__intval(evsel, sample, "runtime"); + u64 runtime =3D perf_sample__intval(sample, "runtime"); double runtime_ms =3D (double)runtime / NSEC_PER_MSEC; struct thread *thread =3D machine__findnew_thread(trace->host, sample->pid, @@ -3143,10 +3143,10 @@ static int trace__sched_stat_runtime(struct trace *= trace, struct evsel *evsel, out_dump: fprintf(trace->output, "%s: comm=3D%s,pid=3D%u,runtime=3D%" PRIu64 ",vrun= time=3D%" 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; } =20 diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests= /openat-syscall-tp-fields.c index 2a139d2781a8..97550b349418 100644 --- a/tools/perf/tests/openat-syscall-tp-fields.c +++ b/tools/perf/tests/openat-syscall-tp-fields.c @@ -118,7 +118,7 @@ static int test__syscall_openat_tp_fields(struct test_s= uite *test __maybe_unused goto out_delete_evlist; } =20 - tp_flags =3D evsel__intval(evsel, &sample, "flags"); + tp_flags =3D perf_sample__intval(&sample, "flags"); perf_sample__exit(&sample); if (flags !=3D tp_flags) { pr_debug("%s: Expected flags=3D%#x, got %#x\n", diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-t= racking.c index 72a8289e846d..22b0302252db 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -140,8 +140,8 @@ static int process_sample_event(struct evlist *evlist, =20 evsel =3D evlist__id2evsel(evlist, sample.id); if (evsel =3D=3D switch_tracking->switch_evsel) { - next_tid =3D evsel__intval(evsel, &sample, "next_pid"); - prev_tid =3D evsel__intval(evsel, &sample, "prev_pid"); + next_tid =3D perf_sample__intval(&sample, "next_pid"); + prev_tid =3D perf_sample__intval(&sample, "prev_pid"); cpu =3D sample.cpu; pr_debug3("sched_switch: cpu: %d prev_tid %d next_tid %d\n", cpu, prev_tid, next_tid); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 33b9a4c284ad..3ff4e466ced9 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3686,15 +3686,20 @@ struct tep_format_field *evsel__common_field(struct= evsel *evsel, const char *na return tp_format ? tep_find_common_field(tp_format, name) : NULL; } =20 -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 =3D evsel__field(evsel, name); + struct tep_format_field *field =3D evsel__field(sample->evsel, name); int offset; =20 if (!field) return NULL; =20 offset =3D field->offset; + if ((u32)(offset + field->size) > sample->raw_size) { + pr_warning("Invalid trace point field offset %d for field of length %d i= n sample raw data of size %u\n", + offset, field->size, sample->raw_size); + return NULL; + } =20 if (field->flags & TEP_FIELD_IS_DYNAMIC) { offset =3D *(int *)(sample->raw_data + field->offset); @@ -3712,6 +3717,12 @@ u64 format_field__intval(struct tep_format_field *fi= eld, struct perf_sample *sam u64 value; void *ptr =3D sample->raw_data + field->offset; =20 + if ((u32)(field->offset + field->size) > sample->raw_size) { + pr_warning("Invalid trace point field offset %d for field of length %d i= n sample raw data of size %u\n", + field->offset, field->size, sample->raw_size); + return 0; + } + switch (field->size) { case 1: return *(u8 *)ptr; @@ -3745,21 +3756,21 @@ u64 format_field__intval(struct tep_format_field *f= ield, struct perf_sample *sam return 0; } =20 -u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const c= har *name) +u64 perf_sample__intval(struct perf_sample *sample, const char *name) { - struct tep_format_field *field =3D evsel__field(evsel, name); + struct tep_format_field *field =3D evsel__field(sample->evsel, name); =20 - return field ? format_field__intval(field, sample, evsel->needs_swap) : 0; + return field ? format_field__intval(field, sample, sample->evsel->needs_s= wap) : 0; } =20 -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 *nam= e) { - struct tep_format_field *field =3D evsel__common_field(evsel, name); + struct tep_format_field *field =3D evsel__common_field(sample->evsel, nam= e); =20 - return field ? format_field__intval(field, sample, evsel->needs_swap) : 0; + return field ? format_field__intval(field, sample, sample->evsel->needs_s= wap) : 0; } =20 -char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, con= st 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; @@ -3768,7 +3779,7 @@ char evsel__taskstate(struct evsel *evsel, struct per= f_sample *sample, const cha unsigned int bit; char state =3D '?'; /* '?' denotes unknown task state */ =20 - field =3D evsel__field(evsel, name); + field =3D evsel__field(sample->evsel, name); =20 if (!field) return state; @@ -3787,7 +3798,7 @@ char evsel__taskstate(struct evsel *evsel, struct per= f_sample *sample, const cha * * We can change this if we have a good reason in the future. */ - val =3D evsel__intval(evsel, sample, name); + val =3D perf_sample__intval(sample, name); bit =3D val ? ffs(val) : 0; state =3D (!bit || bit > strlen(states)) ? 'R' : states[bit-1]; return state; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 339b5c08a33d..862d6eca7998 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -371,14 +371,14 @@ bool evsel__precise_ip_fallback(struct evsel *evsel); struct perf_sample; =20 #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 c= har *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, con= st 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 *nam= e); +char perf_sample__taskstate(struct perf_sample *sample, const char *name); =20 -static inline char *evsel__strval(struct evsel *evsel, struct perf_sample = *sample, const char *name) +static inline const char *perf_sample__strval(struct perf_sample *sample, = const char *name) { - return evsel__rawptr(evsel, sample, name); + return perf_sample__rawptr(sample, name) ?: ""; } #endif =20 diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index fc9eec8b54b8..dab23a96b1d8 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -3426,7 +3426,7 @@ static int intel_pt_process_switch(struct intel_pt *p= t, if (evsel !=3D pt->switch_evsel) return 0; =20 - tid =3D evsel__intval(evsel, sample, "next_pid"); + tid =3D perf_sample__intval(sample, "next_pid"); cpu =3D sample->cpu; =20 intel_pt_log("sched_switch: cpu %d tid %d time %"PRIu64" tsc %#"PRIx64"\n= ", diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c b/tools/perf/ut= il/kvm-stat-arch/kvm-stat-arm64.c index 1e76906f719c..018b0db0e6e7 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c @@ -20,10 +20,8 @@ static const char * const __kvm_events_tp[] =3D { static void event_get_key(struct perf_sample *sample, struct event_key *key) { - struct evsel *evsel =3D sample->evsel; - key->info =3D 0; - key->key =3D evsel__intval(evsel, sample, kvm_exit_reason(EM_AARCH64)); + key->key =3D perf_sample__intval(sample, kvm_exit_reason(EM_AARCH64)); key->exit_reasons =3D arm64_exit_reasons; =20 /* @@ -32,7 +30,7 @@ static void event_get_key(struct perf_sample *sample, * properly decode event's est_ec. */ if (key->key =3D=3D ARM_EXCEPTION_TRAP) { - key->key =3D evsel__intval(evsel, sample, kvm_trap_exit_reason); + key->key =3D perf_sample__intval(sample, kvm_trap_exit_reason); key->exit_reasons =3D arm64_trap_exit_reasons; } } diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c b/tools/per= f/util/kvm-stat-arch/kvm-stat-loongarch.c index 9d6265290f6d..a04cd09e3361 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c @@ -78,7 +78,7 @@ static void event_gspr_get_key(struct perf_sample *sample= , struct event_key *key unsigned int insn; =20 key->key =3D LOONGARCH_EXCEPTION_OTHERS; - insn =3D evsel__intval(sample->evsel, sample, "inst_word"); + insn =3D perf_sample__intval(sample, "inst_word"); =20 switch (insn >> 24) { case 0: diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c b/tools/perf/= util/kvm-stat-arch/kvm-stat-powerpc.c index 5158d7e88ee6..96d9c4ae0209 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-powerpc.c @@ -32,7 +32,7 @@ static void hcall_event_get_key(struct perf_sample *sampl= e, struct event_key *key) { key->info =3D 0; - key->key =3D evsel__intval(sample->evsel, sample, "req"); + key->key =3D perf_sample__intval(sample, "req"); } =20 static const char *get_hcall_exit_reason(u64 exit_code) diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c b/tools/perf/ut= il/kvm-stat-arch/kvm-stat-riscv.c index e8db8b4f8e2e..967bba261a47 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-riscv.c @@ -26,8 +26,7 @@ static void event_get_key(struct perf_sample *sample, int xlen =3D 64; // TODO: 32-bit support. =20 key->info =3D 0; - key->key =3D evsel__intval(sample->evsel, sample, - kvm_exit_reason(EM_RISCV)) & ~CAUSE_IRQ_FLAG(xlen); + key->key =3D perf_sample__intval(sample, kvm_exit_reason(EM_RISCV)) & ~CA= USE_IRQ_FLAG(xlen); key->exit_reasons =3D riscv_exit_reasons; } =20 diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c b/tools/perf/uti= l/kvm-stat-arch/kvm-stat-s390.c index 158372ba0205..4771fc69fa39 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-s390.c @@ -23,7 +23,7 @@ static void event_icpt_insn_get_key(struct perf_sample *s= ample, { u64 insn; =20 - insn =3D evsel__intval(sample->evsel, sample, "instruction"); + insn =3D perf_sample__intval(sample, "instruction"); key->key =3D icpt_insn_decoder(insn); key->exit_reasons =3D 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 =3D evsel__intval(sample->evsel, sample, "order_code"); + key->key =3D perf_sample__intval(sample, "order_code"); key->exit_reasons =3D sie_sigp_order_codes; } =20 static void event_diag_get_key(struct perf_sample *sample, struct event_key *key) { - key->key =3D evsel__intval(sample->evsel, sample, "code"); + key->key =3D perf_sample__intval(sample, "code"); key->exit_reasons =3D sie_diagnose_codes; } =20 static void event_icpt_prog_get_key(struct perf_sample *sample, struct event_key *key) { - key->key =3D evsel__intval(sample->evsel, sample, "code"); + key->key =3D perf_sample__intval(sample, "code"); key->exit_reasons =3D sie_icpt_prog_codes; } =20 diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c b/tools/perf/util= /kvm-stat-arch/kvm-stat-x86.c index 0ce543d82850..788d216f0852 100644 --- a/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c +++ b/tools/perf/util/kvm-stat-arch/kvm-stat-x86.c @@ -27,8 +27,8 @@ static const struct kvm_events_ops exit_events =3D { static void mmio_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key =3D evsel__intval(sample->evsel, sample, "gpa"); - key->info =3D evsel__intval(sample->evsel, sample, "type"); + key->key =3D perf_sample__intval(sample, "gpa"); + key->info =3D perf_sample__intval(sample, "type"); } =20 #define KVM_TRACE_MMIO_READ_UNSATISFIED 0 @@ -43,7 +43,7 @@ static bool mmio_event_begin(struct perf_sample *sample, = struct event_key *key) =20 /* MMIO write begin event in kernel. */ if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && - evsel__intval(sample->evsel, sample, "type") =3D=3D KVM_TRACE_MMIO_WR= ITE) { + perf_sample__intval(sample, "type") =3D=3D 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, st= ruct event_key *key) =20 /* MMIO read end event in kernel.*/ if (evsel__name_is(sample->evsel, "kvm:kvm_mmio") && - evsel__intval(sample->evsel, sample, "type") =3D=3D KVM_TRACE_MMIO_RE= AD) { + perf_sample__intval(sample, "type") =3D=3D KVM_TRACE_MMIO_READ) { mmio_event_get_key(sample, key); return true; } @@ -87,8 +87,8 @@ static const struct kvm_events_ops mmio_events =3D { static void ioport_event_get_key(struct perf_sample *sample, struct event_key *key) { - key->key =3D evsel__intval(sample->evsel, sample, "port"); - key->info =3D evsel__intval(sample->evsel, sample, "rw"); + key->key =3D perf_sample__intval(sample, "port"); + key->info =3D perf_sample__intval(sample, "rw"); } =20 static bool ioport_event_begin(struct perf_sample *sample, @@ -126,8 +126,8 @@ static const struct kvm_events_ops ioport_events =3D { /* 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 =3D evsel__intval(sample->evsel, sample, "ecx"); - key->info =3D evsel__intval(sample->evsel, sample, "write"); + key->key =3D perf_sample__intval(sample, "ecx"); + key->info =3D perf_sample__intval(sample, "write"); } =20 static bool msr_event_begin(struct perf_sample *sample, struct event_key *= key) diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c index f17a6132958d..755ab659a05c 100644 --- a/tools/perf/util/kvm-stat.c +++ b/tools/perf/util/kvm-stat.c @@ -17,7 +17,7 @@ void exit_event_get_key(struct perf_sample *sample, uint16_t e_machine =3D evsel__e_machine(sample->evsel, /*e_flags=3D*/NULL= ); =20 key->info =3D 0; - key->key =3D evsel__intval(sample->evsel, sample, kvm_exit_reason(e_mach= ine)); + key->key =3D perf_sample__intval(sample, kvm_exit_reason(e_machine)); } =20 =20 --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAB233AA514 for ; Fri, 3 Apr 2026 20:40:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248844; cv=none; b=YBN5/9Ew52EEVlyHdeenVCjan7swuMgLAHyVCMppLYd0nnnzhxTu24r1GNt7SWOWwr4GoO4TFRHF7V86yy2E6k/46j9SWh98iWCooYSy1k16Lngt5PBGmD9ShcUInmeRrmQwImLpLkRPKN5/gl4idrQ8vmaXrfleYjcyq6qhfPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248844; c=relaxed/simple; bh=kTw04z7bd7uunsn16wRHAZMezCcsnrfhjYZbE/NBgBo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eokVoPuhb7L3A2ekVv6qRRhbSbmVSgdEWOMY0TCR8RG6l9zAQdhJseKD7qXk0rUJ8DXMRvyZLorLZ5Zq5lo8djJZgXPaD875zMVfaJB4zXYOhjy5W3/SSuywyv/tcKeVsTams9GoLXBRUrXVdgDUnHH39HlDE1I+LLC2heEh0Ig= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GJGLWGb/; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GJGLWGb/" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2c3b8880ca9so2847420eec.1 for ; Fri, 03 Apr 2026 13:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248841; x=1775853641; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wpSygH/mDLUhOtjUbu+lzlrlmYILkWjElGGXPXT6Krg=; b=GJGLWGb/YXvaIKUKO4M9xWcj7NOBFTFK7PM9v7nsZTR0mCfnSTsPW84f8lKVGljNxJ WIUhtxECGJ2hXqgwugAFofiLKHOeK2iREhr0MXVWf+3UrwcsovzoEWaTzY/N0Bb2UYHm NklGCVZnBLZJOGFY+Z0NaNjuVPEtnA2m4ziEdLD+BT5ttKQafnlUlJekw3aMR5v4RwSv IVAQ/LNXHugmbLQQoaPKeU4bScTiJEeK65xNtj0MRzTb2K0Pr7G/BLfj/OFYCp+/DUuN MBfFZgEhgwHBFHDHt3CW425tBEj1wN4nWmkYYM0YTp5Tys/CHJg3hQu/YAQ4CndDdKgu 6wJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248841; x=1775853641; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wpSygH/mDLUhOtjUbu+lzlrlmYILkWjElGGXPXT6Krg=; b=CJTSarKnr4pZ2K+3zB6N9BWxA/+hlRz2SwuuCy/l5tAbT2143bdcECCS2pB8QHi8pB 3YeEUHHrEagvgtyppA2jo3P9qnoqPHncEVRE6u0qJWhl4nBHh4kGPa5Qz0zBdQ4sUmNc Wz+vmNNY59qMccNNcgdPBdgdpUeFeY7D4TRt+5EedIASWeYyCgmx5SWaLrlOHUXH2tBC n2dR8p8x3GYfCOXQuplISEa7RHp8SsUOUBEqC1V4uGpAoYJfWJN7bcx6HNnq8SHwGXoY 1W+QEvGjxXm4UTJYFw6sBDiQvtwxo2GDiyQ9Om8MKkq1FdamEIIXf/6UxxP7rxiyCCZr bkWw== X-Forwarded-Encrypted: i=1; AJvYcCXfQa/Tk3MvBNUbPiug8hBMlBfE5+18rhoutzZWU2k1ZZxIvqENjGHA7aKBE9GX9cdBnHOQzewVEWqbv1w=@vger.kernel.org X-Gm-Message-State: AOJu0YztYaQVGIHpA66+79zXIMSOVmzVwxjr/9fB2xZI1oj8RhK1lRXT 1gBSuOpP6XR4fH0NWRW9l/YnD15lfqTt3EYGZDNaVYZ+7FMmATospdGf87fXGJSm2IqiEJCpO+k sF2OWxC9bHA== X-Received: from dydr4.prod.google.com ([2002:a05:7300:50e4:b0:2cb:b540:9519]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:2d08:b0:2be:1cb2:3a6 with SMTP id 5a478bee46e88-2cbfc6615d7mr2206817eec.33.1775248840818; Fri, 03 Apr 2026 13:40:40 -0700 (PDT) Date: Fri, 3 Apr 2026 13:39:59 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-8-irogers@google.com> Subject: [PATCH v5 07/25] perf trace: Don't pass evsel with sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sample now contains the evsel and so don't unnecessarily pass the evsel. Signed-off-by: Ian Rogers --- tools/perf/builtin-trace.c | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 0d6d3f901f67..88000731e307 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -535,12 +535,12 @@ static struct evsel *perf_evsel__raw_syscall_newtp(co= nst char *direction, void * return NULL; } =20 -#define perf_evsel__sc_tp_uint(evsel, name, sample) \ - ({ struct syscall_tp *fields =3D __evsel__syscall_tp(evsel); \ +#define perf_evsel__sc_tp_uint(name, sample) \ + ({ struct syscall_tp *fields =3D __evsel__syscall_tp(sample->evsel); \ fields->name.integer(&fields->name, sample); }) =20 -#define perf_evsel__sc_tp_ptr(evsel, name, sample) \ - ({ struct syscall_tp *fields =3D __evsel__syscall_tp(evsel); \ +#define perf_evsel__sc_tp_ptr(name, sample) \ + ({ struct syscall_tp *fields =3D __evsel__syscall_tp(sample->evsel); \ fields->name.pointer(&fields->name, sample); }) =20 size_t strarray__scnprintf_suffix(struct strarray *sa, char *bf, size_t si= ze, const char *intfmt, bool show_suffix, int val) @@ -2719,8 +2719,8 @@ static int trace__printf_interrupted_entry(struct tra= ce *trace) return printed; } =20 -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 =3D 0; =20 @@ -2728,7 +2728,7 @@ static int trace__fprintf_sample(struct trace *trace,= struct evsel *evsel, double ts =3D (double)sample->time / NSEC_PER_MSEC; =20 printed +=3D fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n", - evsel__name(evsel), ts, + evsel__name(sample->evsel), ts, thread__comm_str(thread), sample->pid, sample->tid, sample->cpu); } @@ -2783,7 +2783,7 @@ static int trace__sys_enter(struct trace *trace, stru= ct evsel *evsel, void *args; int printed =3D 0; struct thread *thread; - int id =3D perf_evsel__sc_tp_uint(evsel, id, sample), err =3D -1; + int id =3D perf_evsel__sc_tp_uint(id, sample), err =3D -1; int augmented_args_size =3D 0, e_machine; void *augmented_args =3D NULL; struct syscall *sc; @@ -2798,9 +2798,9 @@ static int trace__sys_enter(struct trace *trace, stru= ct evsel *evsel, if (ttrace =3D=3D NULL) goto out_put; =20 - trace__fprintf_sample(trace, evsel, sample, thread); + trace__fprintf_sample(trace, sample, thread); =20 - args =3D perf_evsel__sc_tp_ptr(evsel, args, sample); + args =3D perf_evsel__sc_tp_ptr(args, sample); =20 if (ttrace->entry_str =3D=3D NULL) { ttrace->entry_str =3D malloc(trace__entry_str_size); @@ -2855,12 +2855,11 @@ static int trace__sys_enter(struct trace *trace, st= ruct evsel *evsel, return err; } =20 -static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evs= el, - struct perf_sample *sample) +static int trace__fprintf_sys_enter(struct trace *trace, struct perf_sampl= e *sample) { struct thread_trace *ttrace; struct thread *thread; - int id =3D perf_evsel__sc_tp_uint(evsel, id, sample), err =3D -1; + int id =3D perf_evsel__sc_tp_uint(id, sample), err =3D -1; struct syscall *sc; char msg[1024]; void *args, *augmented_args =3D NULL; @@ -2870,7 +2869,7 @@ static int trace__fprintf_sys_enter(struct trace *tra= ce, struct evsel *evsel, =20 thread =3D machine__findnew_thread(trace->host, sample->pid, sample->tid); e_machine =3D thread__e_machine(thread, trace->host, /*e_flags=3D*/NULL); - sc =3D trace__syscall_info(trace, evsel, e_machine, id); + sc =3D trace__syscall_info(trace, sample->evsel, e_machine, id); if (sc =3D=3D NULL) goto out_put; ttrace =3D thread__trace(thread, trace); @@ -2881,7 +2880,7 @@ static int trace__fprintf_sys_enter(struct trace *tra= ce, struct evsel *evsel, if (ttrace =3D=3D NULL) goto out_put; =20 - args =3D perf_evsel__sc_tp_ptr(evsel, args, sample); + args =3D perf_evsel__sc_tp_ptr(args, sample); augmented_args =3D syscall__augmented_args(sc, sample, &augmented_args_si= ze, trace->raw_augmented_syscalls_args_size); printed +=3D syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmente= d_args, augmented_args_size, trace, thread); fprintf(trace->output, "%.*s", (int)printed, msg); @@ -2891,10 +2890,11 @@ static int trace__fprintf_sys_enter(struct trace *t= race, struct evsel *evsel, return err; } =20 -static int trace__resolve_callchain(struct trace *trace, struct evsel *evs= el, +static int trace__resolve_callchain(struct trace *trace, struct perf_sample *sample, struct callchain_cursor *cursor) { + struct evsel *evsel =3D sample->evsel; struct addr_location al; int max_stack =3D evsel->core.attr.sample_max_stack ? evsel->core.attr.sample_max_stack : @@ -2929,7 +2929,7 @@ static int trace__sys_exit(struct trace *trace, struc= t evsel *evsel, u64 duration =3D 0; bool duration_calculated =3D false; struct thread *thread; - int id =3D perf_evsel__sc_tp_uint(evsel, id, sample), err =3D -1, callcha= in_ret =3D 0, printed =3D 0; + int id =3D perf_evsel__sc_tp_uint(id, sample), err =3D -1, callchain_ret = =3D 0, printed =3D 0; int alignment =3D trace->args_alignment, e_machine; struct syscall *sc; struct thread_trace *ttrace; @@ -2943,9 +2943,9 @@ static int trace__sys_exit(struct trace *trace, struc= t evsel *evsel, if (ttrace =3D=3D NULL) goto out_put; =20 - trace__fprintf_sample(trace, evsel, sample, thread); + trace__fprintf_sample(trace, sample, thread); =20 - ret =3D perf_evsel__sc_tp_uint(evsel, ret, sample); + ret =3D perf_evsel__sc_tp_uint(ret, sample); =20 if (trace->summary) thread__update_stats(thread, ttrace, id, sample, ret, trace); @@ -2967,7 +2967,7 @@ static int trace__sys_exit(struct trace *trace, struc= t evsel *evsel, if (sample->callchain) { struct callchain_cursor *cursor =3D get_tls_callchain_cursor(); =20 - callchain_ret =3D trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret =3D trace__resolve_callchain(trace, sample, cursor); if (callchain_ret =3D=3D 0) { if (cursor->nr < trace->min_stack) goto out; @@ -3182,9 +3182,10 @@ static void bpf_output__fprintf(struct trace *trace, ++trace->nr_events_printed; } =20 -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_sa= mple *sample, struct thread *thread, void *augmented_args, int augmented_args= _size) { + struct evsel *evsel =3D sample->evsel; char bf[2048]; size_t size =3D sizeof(bf); const struct tep_event *tp_format =3D evsel__tp_format(evsel); @@ -3267,7 +3268,7 @@ static int trace__event_handler(struct trace *trace, = struct evsel *evsel, if (sample->callchain) { struct callchain_cursor *cursor =3D get_tls_callchain_cursor(); =20 - callchain_ret =3D trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret =3D trace__resolve_callchain(trace, sample, cursor); if (callchain_ret =3D=3D 0) { if (cursor->nr < trace->min_stack) goto out; @@ -3285,7 +3286,7 @@ static int trace__event_handler(struct trace *trace, = struct evsel *evsel, trace__fprintf_comm_tid(trace, thread, trace->output); =20 if (evsel =3D=3D trace->syscalls.events.bpf_output) { - int id =3D perf_evsel__sc_tp_uint(evsel, id, sample); + int id =3D perf_evsel__sc_tp_uint(id, sample); int e_machine =3D thread ? thread__e_machine(thread, trace->host, /*e_flags=3D*/NULL) : EM_HOST; @@ -3293,7 +3294,7 @@ static int trace__event_handler(struct trace *trace, = struct evsel *evsel, =20 if (sc) { fprintf(trace->output, "%s(", sc->name); - trace__fprintf_sys_enter(trace, evsel, sample); + trace__fprintf_sys_enter(trace, sample); fputc(')', trace->output); goto newline; } @@ -3313,13 +3314,13 @@ static int trace__event_handler(struct trace *trace= , struct evsel *evsel, const struct tep_event *tp_format =3D evsel__tp_format(evsel); =20 if (tp_format && (strncmp(tp_format->name, "sys_enter_", 10) || - trace__fprintf_sys_enter(trace, evsel, sample))) { + trace__fprintf_sys_enter(trace, sample))) { if (trace->libtraceevent_print) { event_format__fprintf(tp_format, sample->cpu, sample->raw_data, sample->raw_size, trace->output); } else { - trace__fprintf_tp_fields(trace, evsel, sample, thread, NULL, 0); + trace__fprintf_tp_fields(trace, sample, thread, NULL, 0); } } } @@ -3378,7 +3379,7 @@ static int trace__pgfault(struct trace *trace, if (sample->callchain) { struct callchain_cursor *cursor =3D get_tls_callchain_cursor(); =20 - callchain_ret =3D trace__resolve_callchain(trace, evsel, sample, cursor); + callchain_ret =3D trace__resolve_callchain(trace, sample, cursor); if (callchain_ret =3D=3D 0) { if (cursor->nr < trace->min_stack) goto out_put; --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41F3C3D8105 for ; Fri, 3 Apr 2026 20:40:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248846; cv=none; b=ZEb8E39jMUKQOQS3U/SvX/4EUTyq+853a/yoQvadARQ0UF/pGA27hJj4g6jypzawjhP2KvDGchLeGNw8Y3VNG0McXDPyOfCGX1TQa39SFyaC0XyzXafEvhZVqVgEkB6xkcUD4VAdgf1LK+VzlyXGUZZA8qq47tm9phvaHptcNKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248846; c=relaxed/simple; bh=OvXaKCfll4qGFqHyoVopFxtuYmb6bhbNaOAnzwuEX40=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ah4uGXW4yqU5XKX9pazvXgIVcU17lagogXQEE2oVPzBHO6T+91pmStHrErkXZnMfoS8BgDOdcykoSKATZ8sMt+w+75lCnBxvCc/+nsvkmlLH3uYD1C3mtK8Fhgvm3l4roIpZxOi2GYfrXYTFSvPZXm+uJDo4JtsqUf4xER8+w2Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OJwF58lI; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OJwF58lI" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-1276e71652fso4452644c88.0 for ; Fri, 03 Apr 2026 13:40:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248843; x=1775853643; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/jopqziVZ417HqQYO9K60PU6J3f3UBv0z8zd0O3IvCE=; b=OJwF58lI2q9j5qwCykyCArRj0cppVHbhf5/XdIZheuE3uf2alPjY2c5wTss4TQxbr1 MvXFiKHhTOZJX2lhDu1Hd2DWF71hjUI7QyRc5Zg6v1GSYY9znGwYr6eCmjictbWBuQyC tBtHYSWI9MvB8Iq9+WnZfMSBOxKc+sJLBk1HBEeq4UQ6/vwhIC1OjcTMvQKQhCSdyozw OGymj6yESYk6OWKvvGbPQiIdThgSS4PmqclLR16bPdQ380se8hbYaxU5rc1C2HAtFcE3 2cBvOOJCK7z/Y+RsV6jvsOxE9bJjJtmC1oHjqqWgypmMD4Qj9koc4vAUJDMEAtgMuH++ sC5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248843; x=1775853643; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/jopqziVZ417HqQYO9K60PU6J3f3UBv0z8zd0O3IvCE=; b=HBpOVu5NHqLMYguz7CCv15ywnKAW3qRKrG8KypnJEURv5R2Xiyqtu2zsITXtd+2ojK BDpG4o4M3E7KrMtqb7DhU1F63tVE6W+Urctpob7JEk48DcZcfesWbIOTQaOwTN+T55vt cr6Xb8ZxwRubyM5G0J2MfV9JMApaKzLSL9RtYpjKQzympnGA2rY1kcNR8wc0kBO62fFU uKai5OOSa6mtyk0tizAy2AkeIsfwEtgJwRxSb8PDx5UEpjNI6KPRuA/yC5Bf3f5afv4j YJflWq1PITR4NMR9y5VDiwPXI8532aiVI91sz6Iy2CHyf/fYw2GFmf7IBk+c3dcSi2l/ JC1A== X-Forwarded-Encrypted: i=1; AJvYcCV0puUxjAWWlnb0GjwSdx5kyyKb2v69udu4O8cjwKR2fJcx3/5wjppl342FiyStHdVLFMH+1lpr+4k929I=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5hNOV+zuABGTLudMsdLoNLlUMpzqa4yeOmo+QCsWfS1p7NEfb rTfd9OiLH/Sp3jmm2H5rt5yLWTuSdyyRbbvojXIEeNglOmfTtKF0/01vf7l9u+hbGsnXfeOFVYS ZQW293pBBaA== X-Received: from dlbqq2.prod.google.com ([2002:a05:7022:ed02:b0:12a:bc7d:34e3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:ea2f:b0:128:d1c9:3633 with SMTP id a92af1059eb24-12bfb6fc76amr2139023c88.13.1775248843163; Fri, 03 Apr 2026 13:40:43 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:00 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-9-irogers@google.com> Subject: [PATCH v5 08/25] perf callchain: Don't pass evsel and sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Change callchain resolve code to not pass an evsel with the sample, instead just read the evsel from the sample. Signed-off-by: Ian Rogers --- 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(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 89456ba6fcbb..f9ac871264af 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -339,7 +339,7 @@ static int process_sample_event(const struct perf_tool = *tool __maybe_unused, =20 cursor =3D get_tls_callchain_cursor(); ret =3D sample__resolve_callchain(sample, cursor, NULL, - evsel, &al, sysctl_perf_event_max_stack); + &al, sysctl_perf_event_max_stack); if (ret) goto out; =20 diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 237ee708d689..ebcbe7a7202c 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -418,7 +418,7 @@ static int perf_event__convert_sample_callchain(const s= truct perf_tool *tool, goto out; =20 /* this will parse DWARF using stack and register data */ - ret =3D thread__resolve_callchain(thread, cursor, evsel, sample, + ret =3D thread__resolve_callchain(thread, cursor, sample, /*parent=3D*/NULL, /*root_al=3D*/NULL, PERF_MAX_STACK_DEPTH); thread__put(thread); @@ -1018,7 +1018,7 @@ static int perf_event__inject_buildid(const struct pe= rf_tool *tool, union perf_e /*sample_in_dso=3D*/true); } =20 - sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_S= TACK_DEPTH, + sample__for_each_callchain_node(thread, sample, PERF_MAX_STACK_DEPTH, /*symbols=3D*/false, mark_dso_hit_callback, &args); thread__put(thread); repipe: diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 4f3ff29d2a9f..b04f5d578e7a 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -394,7 +394,7 @@ static int build_alloc_func_list(void) * Find first non-memory allocation function from callchain. * The allocation functions are in the 'alloc_func_list'. */ -static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample) +static u64 find_callsite(struct perf_sample *sample) { struct addr_location al; struct machine *machine =3D &kmem_session->machines.host; @@ -414,7 +414,7 @@ static u64 find_callsite(struct evsel *evsel, struct pe= rf_sample *sample) if (cursor =3D=3D NULL) goto out; =20 - sample__resolve_callchain(sample, cursor, NULL, evsel, &al, 16); + sample__resolve_callchain(sample, cursor, /*parent=3D*/NULL, &al, 16); =20 callchain_cursor_commit(cursor); while (true) { @@ -848,7 +848,7 @@ static int evsel__process_page_alloc_event(struct evsel= *evsel, struct perf_samp if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) return -1; =20 - callsite =3D find_callsite(evsel, sample); + callsite =3D find_callsite(sample); =20 /* * This is to find the current page (with correct gfp flags and diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 0d45f425c79b..21cbeb233aac 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -688,7 +688,6 @@ static int latency_entry_event(struct perf_kwork *kwork, =20 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, =20 cursor =3D get_tls_callchain_cursor(); =20 - if (thread__resolve_callchain(thread, cursor, evsel, sample, + if (thread__resolve_callchain(thread, cursor, sample, NULL, NULL, kwork->max_stack + 2) !=3D 0) { pr_debug("Failed to resolve callchain, skipping\n"); goto out_put; @@ -838,7 +837,7 @@ static int timehist_entry_event(struct perf_kwork *kwor= k, return ret; =20 if (work !=3D NULL) - timehist_save_callchain(kwork, sample, evsel, machine); + timehist_save_callchain(kwork, sample, machine); =20 return 0; } diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index cbf3a39c7837..e2b585e528ac 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -551,13 +551,13 @@ static int get_key_by_aggr_mode_simple(u64 *key, u64 = addr, u32 tid) return 0; } =20 -static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample); +static u64 callchain_id(struct perf_sample *sample); =20 -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 =3D=3D LOCK_AGGR_CALLER) { - *key =3D callchain_id(evsel, sample); + *key =3D 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, stru= ct 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 =3D get_tls_callchain_cursor(); =20 /* use caller function name from the callchain */ - ret =3D thread__resolve_callchain(thread, cursor, evsel, sample, + ret =3D thread__resolve_callchain(thread, cursor, sample, NULL, NULL, max_stack_depth); if (ret !=3D 0) { thread__put(thread); @@ -896,7 +896,7 @@ static int lock_contention_caller(struct evsel *evsel, = struct perf_sample *sampl return -1; } =20 -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 =3D &session->machines.host; @@ -911,7 +911,7 @@ static u64 callchain_id(struct evsel *evsel, struct per= f_sample *sample) =20 cursor =3D get_tls_callchain_cursor(); /* use caller function name from the callchain */ - ret =3D thread__resolve_callchain(thread, cursor, evsel, sample, + ret =3D thread__resolve_callchain(thread, cursor, sample, NULL, NULL, max_stack_depth); thread__put(thread); =20 @@ -963,7 +963,7 @@ static u64 *get_callstack(struct perf_sample *sample, i= nt max_stack) return callstack; } =20 -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 ev= sel *evsel, struct map *kmap; struct symbol *sym; =20 - ret =3D get_key_by_aggr_mode(&key, addr, evsel, sample); + ret =3D get_key_by_aggr_mode(&key, addr, sample); if (ret < 0) return ret; =20 @@ -1025,7 +1025,7 @@ static int report_lock_contention_begin_event(struct = evsel *evsel, break; case LOCK_AGGR_CALLER: name =3D buf; - if (lock_contention_caller(evsel, sample, buf, sizeof(buf)) < 0) + if (lock_contention_caller(sample, buf, sizeof(buf)) < 0) name =3D "Unknown"; break; case LOCK_AGGR_CGROUP: @@ -1127,7 +1127,7 @@ static int report_lock_contention_begin_event(struct = evsel *evsel, return 0; } =20 -static int report_lock_contention_end_event(struct evsel *evsel, +static int report_lock_contention_end_event(struct evsel *evsel __maybe_un= used, struct perf_sample *sample) { struct lock_stat *ls; @@ -1138,7 +1138,7 @@ static int report_lock_contention_end_event(struct ev= sel *evsel, u64 key; int ret; =20 - ret =3D get_key_by_aggr_mode(&key, addr, evsel, sample); + ret =3D get_key_by_aggr_mode(&key, addr, sample); if (ret < 0) return ret; =20 diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 3e7e8ad0bc13..b6271a5ec8de 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -2330,7 +2330,6 @@ static bool is_idle_sample(struct perf_sample *sample, =20 static void save_task_callchain(struct perf_sched *sched, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine) { struct callchain_cursor *cursor; @@ -2350,7 +2349,7 @@ static void save_task_callchain(struct perf_sched *sc= hed, =20 cursor =3D get_tls_callchain_cursor(); =20 - if (thread__resolve_callchain(thread, cursor, evsel, sample, + if (thread__resolve_callchain(thread, cursor, sample, NULL, NULL, sched->max_stack + 2) !=3D 0) { if (verbose > 0) pr_err("Failed to resolve callchain. Skipping\n"); @@ -2524,7 +2523,7 @@ static struct thread *timehist_get_thread(struct perf= _sched *sched, sample->tid); } =20 - save_task_callchain(sched, sample, evsel, machine); + save_task_callchain(sched, sample, machine); if (sched->idle_hist) { struct thread *idle; struct idle_thread_runtime *itr; diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8724c4ab3e88..8022801721e2 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1683,7 +1683,7 @@ static int perf_sample__fprintf_bts(struct perf_sampl= e *sample, =20 if (symbol_conf.use_callchain && sample->callchain) { cursor =3D 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 =3D NULL; @@ -2506,7 +2506,7 @@ static void process_event(struct perf_script *script, =20 if (symbol_conf.use_callchain && sample->callchain) { cursor =3D 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 =3D NULL; @@ -2790,7 +2790,7 @@ static int process_deferred_sample_event(const struct= perf_tool *tool, =20 if (symbol_conf.use_callchain && sample->callchain) { cursor =3D get_tls_callchain_cursor(); - if (thread__resolve_callchain(al.thread, cursor, evsel, + if (thread__resolve_callchain(al.thread, cursor, sample, NULL, NULL, scripting_max_stack)) { pr_info("cannot resolve deferred callchains\n"); diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 88000731e307..161e2e62bf1e 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2905,7 +2905,7 @@ static int trace__resolve_callchain(struct trace *tra= ce, if (machine__resolve(trace->host, &al, sample) < 0) goto out; =20 - err =3D thread__resolve_callchain(al.thread, cursor, evsel, sample, NULL,= NULL, max_stack); + err =3D thread__resolve_callchain(al.thread, cursor, sample, NULL, NULL, = max_stack); out: addr_location__exit(&al); return err; diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 55b72235f891..af4d874f1381 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -73,7 +73,7 @@ int build_id__mark_dso_hit(const struct perf_tool *tool _= _maybe_unused, =20 addr_location__exit(&al); =20 - sample__for_each_callchain_node(thread, sample->evsel, sample, PERF_MAX_S= TACK_DEPTH, + sample__for_each_callchain_node(thread, sample, PERF_MAX_STACK_DEPTH, /*symbols=3D*/false, mark_dso_hit_callback, /*data=3D*/NULL); =20 =20 diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index f031cbbeeba8..5c2282051e39 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1170,7 +1170,7 @@ int callchain_cursor_append(struct callchain_cursor *= cursor, =20 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 =3D=3D NULL && !symbol_conf.show_branchflag_count) @@ -1178,7 +1178,7 @@ int sample__resolve_callchain(struct perf_sample *sam= ple, =20 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; } =20 -int sample__for_each_callchain_node(struct thread *thread, struct evsel *e= vsel, +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 *th= read, struct evsel *evsel, return -ENOMEM; =20 /* Fill in the callchain. */ - ret =3D __thread__resolve_callchain(thread, cursor, evsel, sample, + ret =3D __thread__resolve_callchain(thread, cursor, sample, /*parent=3D*/NULL, /*root_al=3D*/NULL, max_stack, symbols); if (ret) diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 06d463ccc7a0..27d8e486dc22 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -8,11 +8,9 @@ #include "branch.h" =20 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 *re= cord, =20 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, @@ -308,7 +306,7 @@ s64 callchain_avg_cycles(struct callchain_node *cnode); =20 typedef int (*callchain_iter_fn)(struct callchain_cursor_node *node, void = *data); =20 -int sample__for_each_callchain_node(struct thread *thread, struct evsel *e= vsel, +int sample__for_each_callchain_node(struct thread *thread, struct perf_sample *sample, int max_stack, bool symbols, callchain_iter_fn cb, void *data); =20 diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index ae9a9065aab7..a1f578c3a8d5 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -209,8 +209,7 @@ static int db_ids_from_al(struct db_export *dbe, struct= addr_location *al, static struct call_path *call_path_from_sample(struct db_export *dbe, struct machine *machine, struct thread *thread, - struct perf_sample *sample, - struct evsel *evsel) + struct perf_sample *sample) { u64 kernel_start =3D machine__kernel_start(machine); struct call_path *current =3D &dbe->cpr->call_path; @@ -228,7 +227,7 @@ static struct call_path *call_path_from_sample(struct d= b_export *dbe, */ callchain_param.order =3D ORDER_CALLER; cursor =3D get_tls_callchain_cursor(); - err =3D thread__resolve_callchain(thread, cursor, evsel, + err =3D thread__resolve_callchain(thread, cursor, sample, NULL, NULL, PERF_MAX_STACK_DEPTH); if (err) { callchain_param.order =3D saved_order; @@ -391,8 +390,7 @@ int db_export__sample(struct db_export *dbe, union perf= _event *event, =20 if (dbe->cpr) { struct call_path *cp =3D call_path_from_sample(dbe, machine, - thread, sample, - evsel); + thread, sample); if (cp) { db_export__call_path(dbe, cp); es.call_path_id =3D cp->db_id; diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index fc737a0a8e4d..f51fd439d2dd 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -1342,7 +1342,7 @@ int hist_entry_iter__add(struct hist_entry_iter *iter= , struct addr_location *al, alm =3D map__get(al->map); =20 err =3D sample__resolve_callchain(iter->sample, get_tls_callchain_cursor(= ), &iter->parent, - iter->evsel, al, max_stack_depth); + al, max_stack_depth); if (err) { map__put(alm); return err; diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index e76f8c86e62a..c2e0a99efe97 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2778,13 +2778,13 @@ static u64 get_leaf_frame_caller(struct perf_sample= *sample, =20 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 =3D sample->evsel; struct branch_stack *branch =3D sample->branch_stack; struct branch_entry *entries =3D perf_sample__branch_entries(sample); struct ip_callchain *chain =3D sample->callchain; @@ -2986,10 +2986,11 @@ static int unwind_entry(struct unwind_entry *entry,= void *arg) =20 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 =3D 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 th= read *thread, =20 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 *thre= ad, =20 if (callchain_param.order =3D=3D ORDER_CALLEE) { ret =3D thread__resolve_callchain_sample(thread, cursor, - evsel, sample, + sample, parent, root_al, max_stack, symbols); if (ret) return ret; ret =3D thread__resolve_callchain_unwind(thread, cursor, - evsel, sample, + sample, max_stack, symbols); } else { ret =3D thread__resolve_callchain_unwind(thread, cursor, - evsel, sample, + sample, max_stack, symbols); if (ret) return ret; ret =3D thread__resolve_callchain_sample(thread, cursor, - evsel, sample, + sample, parent, root_al, max_stack, symbols); } diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index 22a42c5825fa..048b24e9bd38 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -187,7 +187,6 @@ struct callchain_cursor; =20 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, =20 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 thre= ad *thread, { return __thread__resolve_callchain(thread, cursor, - evsel, sample, parent, root_al, diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/p= erf/util/scripting-engines/trace-event-perl.c index e261a57b87d4..af0d514b2397 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -257,7 +257,7 @@ static void define_event_symbols(struct tep_event *even= t, } =20 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 *s= ample, =20 cursor =3D get_tls_callchain_cursor(); =20 - if (thread__resolve_callchain(al->thread, cursor, evsel, + if (thread__resolve_callchain(al->thread, cursor, sample, NULL, NULL, scripting_max_stack) !=3D 0) { pr_err("Failed to resolve callchain. Skipping\n"); goto exit; diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index 2b0df7bd9a46..08197cef44c8 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -390,7 +390,7 @@ static unsigned long get_offset(struct symbol *sym, str= uct addr_location *al) } =20 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_s= ample *sample, goto exit; =20 cursor =3D 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) !=3D 0) { pr_err("Failed to resolve callchain. Skipping\n"); --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7819D3D7D9D for ; Fri, 3 Apr 2026 20:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248848; cv=none; b=Zcbzw67kBVsB4MlHcxFZvVInVlbeko8ae2Q/D3QU6U0X82CV3V3XdA/3Te0oOvSbxVGvDY8bMlcp+590ra/0BLypJLrz0if55iE7sw18FaJbj4RwfxRg0IYH15AB6mdAoiyI4p1EwilAPXhwbTGggX37mG71Yk+XSsix3TjDNYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248848; c=relaxed/simple; bh=R10gAxw23kSBK/h718oJExyOmJYEzsW//g5xoEppAlI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AKn4hXr2nDnyL4f0XS/OgXWP9LbEu9bijx2JPTlR56/ItguapBlrmk+6rRxjU0yZ15R5RdzvD3rN21vgK9n0M5P5HbElHPQWsbsQNxFmiWSYTOLkfpT8DDSO889MOajA5nabmcIqrLdZ+5D3614WdtN9whauc5ncJaUR3HjzqpI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Rs9Y/iIy; arc=none smtp.client-ip=74.125.82.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Rs9Y/iIy" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-1276e71652fso4452718c88.0 for ; Fri, 03 Apr 2026 13:40:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248846; x=1775853646; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BStLNx8zvU11CILdD69lDCLupBLvf41S1zWL07N8khM=; b=Rs9Y/iIyOgBj6KNJrMT2qGBFpzEZbtZp/uIdIydlEaxC6/alC+gDaRVpOji8vcjuxp 0Y9xpVvRjT08sHzDOh4dzNKkZ9evbvLWWsDwN4CXlMmCT8CwspzAsnw4ar2JZlxIA9tC M84BzctgG1sg1l7cX6+R7rF7ASqr7JD8GAX3uBYDCIqSOF+uQFMYM14hkXOIyq2VoGoF lR1tOvAY0CaGQgyWKt9mRJOTkFGXNXhbvYpcoHg4W7wwu/O0CRoW0oO1nbcsAWvnyzJ0 F4n1250o0qyMGmkqlMO4BcQ/k7y0/1T7AoptP7F/BiArakpFfEnAip28ukJTh3HdKS2e F9hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248846; x=1775853646; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BStLNx8zvU11CILdD69lDCLupBLvf41S1zWL07N8khM=; b=qe7ud2ptR/16qICC1NSvIDJ3dsFnrxXYIWFMSL62O3vtzM8L7Qs05o9KJWtAl2GyE7 ztnxRMFJQ2oA+7D8AMuJDOqpLIo04/WMHlShahON9qRe0L28fZOl5Z0cgvbqSQ4FD2RI u4tGn9T0C2KUDrBsXrumJlOayQSWep1Pe6b5gxvgIvri6uO+eklSV3FsHENLSH5JH1Xu txeGp1PyaoEawbEBF3WwHNrg35GWbuMo/+JZNatyVWk/t4lqQNuXLTyq/0teLqiYxT/s 5yGPxgLHI0o9uKLohBcJFOSp7bbwn6+DsFyyhp+5xngDiqEdyzFKEi5Az2EIiO8QLf30 V5aw== X-Forwarded-Encrypted: i=1; AJvYcCVnvIVedyy1uDUgTrkR9/K/OsXUJCLqeJv7Lvc+wFLkZx4Iv8vlVAPbyxjB8vv3V7ce/xIa0TGYriZi84A=@vger.kernel.org X-Gm-Message-State: AOJu0YyymtkLF8JXeFYliLnSVsmAc+nDLYax+EretPKgHyOWjGXhW+gA of8ilwfzEdhoveUr28pST4X4g66vQPTB0AJD8zG+jfvpa7nuLrX4dyzMiiCfExUUj9bFOu7rLKN nFH95qlGMaQ== X-Received: from dlak28.prod.google.com ([2002:a05:701b:291c:b0:128:f2cd:cb37]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:69a0:b0:12a:71ab:8235 with SMTP id a92af1059eb24-12bfb6ed5c1mr1956832c88.6.1775248845302; Fri, 03 Apr 2026 13:40:45 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:01 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-10-irogers@google.com> Subject: [PATCH v5 09/25] perf lock: Only pass sample to handlers From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The evsel is within the sample and so only the sample needs to be passed. Remove the parameter and fix call site. Add an additional NULL check in get_callstack, as prompted by Sashiko during review. Signed-off-by: Ian Rogers --- tools/perf/builtin-lock.c | 68 +++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index e2b585e528ac..8ccb64415d3b 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -473,28 +473,22 @@ static struct lock_stat *pop_from_result(void) =20 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); =20 /* 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); =20 /* 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); =20 /* it's used on CONFIG_LOCKDEP */ - int (*release_event)(struct evsel *evsel, - struct perf_sample *sample); + int (*release_event)(struct perf_sample *sample); =20 /* 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); =20 /* 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); }; =20 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); } =20 -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 *evse= l __maybe_unused, return 0; } =20 -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 *evs= el __maybe_unused, return 0; } =20 -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 *ev= sel __maybe_unused, return 0; } =20 -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; @@ -948,6 +938,9 @@ static u64 *get_callstack(struct perf_sample *sample, i= nt max_stack) u64 i; int c; =20 + if (!sample->callchain) + return NULL; + callstack =3D calloc(max_stack, sizeof(*callstack)); if (callstack =3D=3D NULL) return NULL; @@ -963,8 +956,7 @@ static u64 *get_callstack(struct perf_sample *sample, i= nt max_stack) return callstack; } =20 -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 +1119,7 @@ static int report_lock_contention_begin_event(struct = evsel *evsel __maybe_unused return 0; } =20 -static int report_lock_contention_end_event(struct evsel *evsel __maybe_un= used, - 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 +1199,45 @@ static struct trace_lock_handler contention_lock_op= s =3D { =20 static struct trace_lock_handler *trace_handler; =20 -static int evsel__process_lock_acquire(struct evsel *evsel, struct perf_sa= mple *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; } =20 -static int evsel__process_lock_acquired(struct evsel *evsel, struct perf_s= ample *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; } =20 -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; } =20 -static int evsel__process_lock_release(struct evsel *evsel, struct perf_sa= mple *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; } =20 -static int evsel__process_contention_begin(struct evsel *evsel, struct per= f_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; } =20 -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; } =20 @@ -1424,8 +1415,7 @@ static int process_event_update(const struct perf_too= l *tool, return 0; } =20 -typedef int (*tracepoint_handler)(struct evsel *evsel, - struct perf_sample *sample); +typedef int (*tracepoint_handler)(struct perf_sample *sample); =20 static int process_sample_event(const struct perf_tool *tool __maybe_unuse= d, union perf_event *event, @@ -1445,7 +1435,7 @@ static int process_sample_event(const struct perf_too= l *tool __maybe_unused, =20 if (evsel->handler !=3D NULL) { tracepoint_handler f =3D evsel->handler; - err =3D f(evsel, sample); + err =3D f(sample); } =20 thread__put(thread); --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 893AA37881A for ; Fri, 3 Apr 2026 20:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248849; cv=none; b=AMmUIAZDBZmsHBdOBh+c5lBbG65O3S/3zndw9xqaxrDIwZnV5cmd0QiLHG31Jm9WlzVipudiwdc0rfVqacBrg4qFEuk9GljuaFaB3+4P2mnP/Rk0gyLKAgwwyENc210402Z6u3yBbTE1WuMzs08YmxPhi/Fk/S8rSAI9fmJsCuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248849; c=relaxed/simple; bh=SYrJANGR3+3OE2V0oHZ0BNrkaTsib9ddsYIXs4rLT8E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PXZoSFbn0g4slzvSpPsXuZnDMjwkTaxIBIECwo2cRd7TheLDEnF8GdPL6db5zkOU7uV8mYIwkCxpp7cNkWk8wOqmgnLk48Kd+A7aY02TTVhCKMCUXc/Ljg+QAH4qW5H0i176KUvAua9WAADGdvfpaLxVpuQs5nAdl+FLoGPuxWQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Nw65JKWQ; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Nw65JKWQ" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2c3b8880ca9so2847517eec.1 for ; Fri, 03 Apr 2026 13:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248848; x=1775853648; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=n1+MYX0+5YGMm7TjdJ/WWiuEu/OsAkIHeLC0vTnO8zk=; b=Nw65JKWQwISRA8B/kN+sWy4oiWvZ5HLqfm1u2fou2xlodgjv4/FJZU4kh6hGB81rPh aHr7Mu7IwD4QSMmJkvSnu1LpJf4uDQ5jTLHvjAIoXujmtPc0dIk41lK412q+oQcg/5v3 AIOVWEHA6gzvaikwnVdpjjnUrE7xjtZ0po+zw7v9E44+XSiXlFS1eMDDZDAHtvUuEUKF LiaaZuElog3HNmP4+hyc/PLs4J7oFfK3n5MzXHKKJ2gf8hB82RVYz0NCihtjaqvST9TZ 8z9MYVmt77CA4ThCiXVM62awt+EzFCp7iEqs9EP8a81HGt6cy9bF+3cSc5gE3hxLgzqR 7Oxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248848; x=1775853648; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n1+MYX0+5YGMm7TjdJ/WWiuEu/OsAkIHeLC0vTnO8zk=; b=HAuXCdJ5Oiu1ZYSVLCk72RYbt/Cmbs/pEwQtlO9J1+dLUzn1m/x1FMXNBGnGAcGSrn afWaSgPTdF0n8gFKnC3xldA86HtXBr7WDfGWqgiqTnC4b1cCh2GCrefRd6ToENYO7Aaa 1r563f2ehxCP8oyiu7zFicZrAzuCzQf4cWgvCk1sFO5IKZaNuXhBKi6b+2KqGqukVLFA JSB7rR98H70LNhh5YM+2hRr2rcjPhv7rflaIipWDZIxrd1qaazcTCwYfcRP8TvZ4EDpO Q0us5T4mQ2AkPOZyy70doKKozcltjrbBYcLkv76s5t0Oqsbc46O8Yvw3qKWgy+6Aou+L +QHg== X-Forwarded-Encrypted: i=1; AJvYcCXoO/EdsLMupL76M+uBu9OMqHELTUwrOdlnrlakJ5Zn7/KvWI9Or2bnON5BR1bIJAKPnqBH1LKKckO4UYU=@vger.kernel.org X-Gm-Message-State: AOJu0YxFGNLIqUR2X0BerRtUx0aGStfEsl9yTbgafIOw5BM+fLknwSnb snMr3Tk/E0dgwB8oxAzrDLL4wSKdZxCFb0F5nQxAOCYZbadgVm0oUx2IbBGXWP6XgS/A2zFWlu4 vdQvph+rfUg== X-Received: from dlbvv18.prod.google.com ([2002:a05:7022:5f12:b0:12a:7349:f4f6]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:41a3:b0:12a:6ab7:3f71 with SMTP id a92af1059eb24-12bfb6ed48emr1799492c88.7.1775248847610; Fri, 03 Apr 2026 13:40:47 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:02 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-11-irogers@google.com> Subject: [PATCH v5 10/25] perf lock: Constify trace_lock_handler variables From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Structs don't change and so constify. Signed-off-by: Ian Rogers --- tools/perf/builtin-lock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 8ccb64415d3b..7b23d22d8f48 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1182,7 +1182,7 @@ static int report_lock_contention_end_event(struct pe= rf_sample *sample) =20 /* lock oriented handlers */ /* TODO: handlers for CPU oriented, thread oriented */ -static struct trace_lock_handler report_lock_ops =3D { +static const struct trace_lock_handler report_lock_ops =3D { .acquire_event =3D report_lock_acquire_event, .acquired_event =3D report_lock_acquired_event, .contended_event =3D report_lock_contended_event, @@ -1191,13 +1191,13 @@ static struct trace_lock_handler report_lock_ops = =3D { .contention_end_event =3D report_lock_contention_end_event, }; =20 -static struct trace_lock_handler contention_lock_ops =3D { +static const struct trace_lock_handler contention_lock_ops =3D { .contention_begin_event =3D report_lock_contention_begin_event, .contention_end_event =3D report_lock_contention_end_event, }; =20 =20 -static struct trace_lock_handler *trace_handler; +static const struct trace_lock_handler *trace_handler; =20 static int evsel__process_lock_acquire(struct perf_sample *sample) { --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89C5C3D9030 for ; Fri, 3 Apr 2026 20:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248852; cv=none; b=Lgqwd+GdfN/ABo7HP3aBcAae4HuY7VkfOL2kGAkbg40UnEx8k+TwMwaQBtJMyc8zKP0kls5JIm5Vizm1KKgJFg8oYgc9JEg9ZF1nXD2nSVZxGoZ/W3j8WRnQHK04jgUx8HGoYPMOyNc8wG4Gpd93FA6V+2bFszlEMjNjcCFLYiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248852; c=relaxed/simple; bh=dTakRFq+3hjeVloe4iHCXNw7Dee9NH42FeVhCpT0lVE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JIEbOZb+sGCyCD8yN5k5v8eLv+Gyz6eGuR5KRsWiODwJwDNtyUVBe2wk1CldvAUhFGgj8VRo5Uxv+MFGFyz81BSnvAkgsJEtQWB+I2VK/jD0SC6TuAz5BUM4wjwHxvX7OKjIZh+fS+SgAw/npHiO+muelrcxOYVkzxWJJaw6zNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eLxHO7XX; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eLxHO7XX" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12721cd1a2aso11297460c88.1 for ; Fri, 03 Apr 2026 13:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248850; x=1775853650; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=P2FLhx5V0ymgc8/HiT98CwKQoIrTyFPHn++TN0eREEo=; b=eLxHO7XXbQi7baT1EJ3Jt7MUtzfj7wlnN9uQBibyK/QeOQrYJ2ZE+uBWG+MuoBGwMl td+UY89mCkklNMtVRWuSaRX+5vHES2oI/t0Qp7pa9hhsjC81aWtuSDmiqNT7HR77HHYg Qp1Ed7GpYl0xI9PeasDTpCf9t/CF529CQLHxBbJDQVNXxDi6IwZwylGlYMATnR/g59Vt hZaan94LslWDupBd7SJf8TXA0yQ5qeqLZUshUFA9BXx9pePhzbWyHRQpRzdyslq458zz RXsI1eBqBgi7edJSp+gKASvz3WaP7MTZGp8xFF+0Dj+NmrTxrgchfl7jxjrQp2gKAYUN aH8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248850; x=1775853650; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=P2FLhx5V0ymgc8/HiT98CwKQoIrTyFPHn++TN0eREEo=; b=HZfLzVpSOtZqp1+FEB88HdwQoY7zTsv5q9AgiEcTwudCL2ABLBwIX2GOEkMl5Xi8Wb 5icUAnCdS1PzgUc5JEItjzPTlwgroTslg0K3AQmZFGPZJBRIWNlxwpLygLV+KGtvYJLk NwRpUPdBkJsoHaGylifqSP8XoMYW/2U+HUrWKSJdD2/2GEfWINz88OEcj4LYM4iI/RF5 l3V504hWsRhkd1RxR2p7tIui7LvD4d1D89qzTxDp1j95LRN7+H6habShFndFr6DdMo6J TSaqeKEd/tRCbt4srSQMJfiIUooQjRctiIlnBiIcYhJMv9qN7bGUcEjOXIg22mHoqIF6 Ig3Q== X-Forwarded-Encrypted: i=1; AJvYcCWdqEV+4e/aZfT1age/wpKHtfvrAhtTptYpkuXLlNcCu+gIxpXThH5JPnRY/IEjjsTKKETLzXM47LTAyFM=@vger.kernel.org X-Gm-Message-State: AOJu0YwJTWqpFw2rIuASde4d1LQcihN6kasAeIhLJf4rif3F/R015v5Y rm+07wuyXruePoIWuGjQRfKrRFf/+D48cFpx9S0Sm+Ybsn3a04X7yHHJX/2eTkvNjf5tTiRgS/E vRzgdYRGsJA== X-Received: from dldnz7.prod.google.com ([2002:a05:701a:ca07:b0:12a:6c72:daa3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:ea31:b0:128:ce44:be8f with SMTP id a92af1059eb24-12bfb6e980bmr2195283c88.2.1775248849648; Fri, 03 Apr 2026 13:40:49 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:03 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-12-irogers@google.com> Subject: [PATCH v5 11/25] perf hist: Remove evsel parameter from inc samples functions From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" hist_entry__inc_addr_samples and addr_map_symbol__inc_samples unnecessarily take an evsel argument. Read the evsel from the sample instead. Signed-off-by: Ian Rogers --- tools/perf/builtin-annotate.c | 7 +++---- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-report.c | 18 ++++++++---------- tools/perf/builtin-top.c | 6 +++--- tools/perf/util/annotate.c | 19 +++++++++---------- tools/perf/util/annotate.h | 6 ++---- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index c97a0fe159f8..c2d0599fe5f5 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -177,16 +177,15 @@ static int hist_iter__branch_callback(struct hist_ent= ry_iter *iter, struct hist_entry *he =3D iter->he; struct branch_info *bi; struct perf_sample *sample =3D iter->sample; - struct evsel *evsel =3D iter->evsel; int err; =20 bi =3D he->branch_info; - err =3D addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err =3D addr_map_symbol__inc_samples(&bi->from, sample); =20 if (err) goto out; =20 - err =3D addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err =3D addr_map_symbol__inc_samples(&bi->to, sample); =20 out: return err; @@ -276,7 +275,7 @@ static int evsel__add_sample(struct evsel *evsel, struc= t perf_sample *sample, if (he =3D=3D NULL) return -ENOMEM; =20 - ret =3D hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + ret =3D hist_entry__inc_addr_samples(he, sample, al->addr); hists__inc_nr_samples(hists, true); return ret; } diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index f9ac871264af..5684c14c2bf6 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -371,7 +371,7 @@ static int process_sample_event(const struct perf_tool = *tool __maybe_unused, =20 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); } =20 ret =3D hist_entry__append_callchain(he, sample); diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 507002cbdd5b..39968ae5cfb0 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -170,7 +170,6 @@ static int hist_iter__report_callback(struct hist_entry= _iter *iter, int err =3D 0; struct report *rep =3D arg; struct hist_entry *he =3D iter->he; - struct evsel *evsel =3D iter->evsel; struct perf_sample *sample =3D iter->sample; struct mem_info *mi; struct branch_info *bi; @@ -180,25 +179,25 @@ static int hist_iter__report_callback(struct hist_ent= ry_iter *iter, =20 if (sort__mode =3D=3D SORT_MODE__BRANCH) { bi =3D he->branch_info; - err =3D addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err =3D addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; =20 - err =3D addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err =3D addr_map_symbol__inc_samples(&bi->to, sample); =20 } else if (rep->mem_mode) { mi =3D he->mem_info; - err =3D addr_map_symbol__inc_samples(mem_info__daddr(mi), sample, evsel); + err =3D addr_map_symbol__inc_samples(mem_info__daddr(mi), sample); if (err) goto out; =20 - err =3D hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err =3D hist_entry__inc_addr_samples(he, sample, al->addr); =20 } else if (symbol_conf.cumulate_callchain) { if (single) - err =3D hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err =3D hist_entry__inc_addr_samples(he, sample, al->addr); } else { - err =3D hist_entry__inc_addr_samples(he, sample, evsel, al->addr); + err =3D hist_entry__inc_addr_samples(he, sample, al->addr); } =20 out: @@ -214,7 +213,6 @@ static int hist_iter__branch_callback(struct hist_entry= _iter *iter, struct report *rep =3D arg; struct branch_info *bi =3D he->branch_info; struct perf_sample *sample =3D iter->sample; - struct evsel *evsel =3D iter->evsel; int err; =20 branch_type_count(&rep->brtype_stat, &bi->flags, @@ -223,11 +221,11 @@ static int hist_iter__branch_callback(struct hist_ent= ry_iter *iter, if (!ui__has_annotation() && !rep->symbol_ipc) return 0; =20 - err =3D addr_map_symbol__inc_samples(&bi->from, sample, evsel); + err =3D addr_map_symbol__inc_samples(&bi->from, sample); if (err) goto out; =20 - err =3D addr_map_symbol__inc_samples(&bi->to, sample, evsel); + err =3D addr_map_symbol__inc_samples(&bi->to, sample); =20 out: return err; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 37950efb28ac..b879592ae745 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -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; =20 - err =3D hist_entry__inc_addr_samples(he, sample, evsel, ip); + err =3D hist_entry__inc_addr_samples(he, sample, ip); =20 annotation__unlock(notes); =20 @@ -735,7 +735,7 @@ static int hist_iter__top_callback(struct hist_entry_it= er *iter, struct evsel *evsel =3D iter->evsel; =20 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); =20 hist__account_cycles(iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY), diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 63f0ee9d4c03..d97cb087a63e 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -214,9 +214,10 @@ static int __symbol__account_cycles(struct cyc_hist *c= h, } =20 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 =3D sample->evsel; struct symbol *sym =3D ms->sym; long hash_key; u64 offset; @@ -319,7 +320,7 @@ struct annotated_source *symbol__hists(struct symbol *s= ym, int nr_hists) } =20 static int symbol__inc_addr_samples(struct map_symbol *ms, - struct evsel *evsel, u64 addr, + u64 addr, struct perf_sample *sample) { struct symbol *sym =3D ms->sym; @@ -327,8 +328,8 @@ static int symbol__inc_addr_samples(struct map_symbol *= ms, =20 if (sym =3D=3D NULL) return 0; - src =3D symbol__hists(sym, evsel->evlist->core.nr_entries); - return src ? __symbol__inc_addr_samples(ms, src, evsel, addr, sample) : 0; + src =3D symbol__hists(sym, sample->evsel->evlist->core.nr_entries); + return src ? __symbol__inc_addr_samples(ms, src, addr, sample) : 0; } =20 static int symbol__account_br_cntr(struct annotated_branch *branch, @@ -582,16 +583,14 @@ static int annotation__compute_ipc(struct annotation = *notes, size_t size, return 0; } =20 -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); } =20 -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); } =20 =20 diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 696e36dbf013..1aa6df7d1618 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -422,8 +422,7 @@ static inline struct annotation *symbol__annotation(str= uct symbol *sym) return (void *)sym - symbol_conf.priv_size; } =20 -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); =20 struct annotated_branch *annotation__get_branch(struct annotation *notes); =20 @@ -433,8 +432,7 @@ int addr_map_symbol__account_cycles(struct addr_map_sym= bol *ams, struct evsel *evsel, u64 br_cntr); =20 -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); =20 struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists); void symbol__annotate_zero_histograms(struct symbol *sym); --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A4293D9055 for ; Fri, 3 Apr 2026 20:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248855; cv=none; b=m1IYJQ245OoQ6h88vYMCrtE8Ru5i2zZhte6g3foIr22J79niOdeI4r6d9PPPm+AopFRjYDuuvYFXqGnY09G1Q6XzqiLggkk+T4ssXtJ+ewqikQQ9B2m71vOVl8zSIGh6014JbyrbY3+N52wokEook6g4QJAO4osAlep1jOrETQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248855; c=relaxed/simple; bh=KHhk7nT7s6uEMm9uxAq5Q1qjs0+1hn9hTiDZ90j2BXA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rQVQ+g8+IT9SEscHmvNG3otrfZ0CndmZqFaSGUqWw5x+6ot42pMTNfBekAhet5JC5jBZkIXN+RC002QR8u+545m603RasYDLcc/V6P84POLCxt5ChhYV8q54fvA+0vZ/B1lrErpUtoCdw5p8ZaGyVHlDdFapgjoCzr68JyuASJc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pNzU097+; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pNzU097+" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2c3b8880ca9so2847588eec.1 for ; Fri, 03 Apr 2026 13:40:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248852; x=1775853652; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Tdh3bDJf8eAerq7vruCDhEmsabGX5J8RipWgz2KyKOg=; b=pNzU097+FK+28pRtazT7JZ9v5N7d8/CTiuyuKoVHL9Otp83dwoyqe1MrciKfHg8Hum UGXEOXwq0iMoIESEdu8zWbxFbowwTDT5Ck5QrUPHoyqhy2EF7iIcmkANCDQYgXh0JHOI fFB5gfdDfmgasVUiUgn68x5LP0Hg5CXxEHLZ9/ws8EHskt1BcD5vgTWJj+jyijUVXV9x ySkPDrl036vbsU4CV7KRma1DcKKndpL3EnmPlygf1L9nZT01YZdpMkwCN1ALjbbkodb7 T7ecmJBDAkhPAP1WISv+vXmjdzdQu/4DvNIyrGBjQMDlJFhzCPga4xk8Xgtdy7GwdPx8 zQEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248852; x=1775853652; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Tdh3bDJf8eAerq7vruCDhEmsabGX5J8RipWgz2KyKOg=; b=k0ygWG1ad/NnqPdnm7ri2XC4FLMBYvovpdIzQsXk1jashc68Fs0Tcufe6D2h2gxurR AQhltx5eYBDTckDrcBAUHjsUhCJov2hoegduaD9ym9gQaqxKDMlZ7MBTJIPnfZ0VEqKM 1l4FkNNuqWZdsFj6Jw4uEbJnlRO+ON7ZGkXhfgKa5fMUmpIPBWN58bjbi5E2AOHQrGEo 08JnlqPmzg1vZ0rb5bGE7aU8iR4O5IeINQTyWmmmPCVRpPBlMBY2Ze8dP0FUD1h4SIFY Hbq9Us40JSzoJfGhllvusiHqY5C7r8/FMO0FTgEreRJHspEJpSCFspu1nL7H1hJtHgnH CnYA== X-Forwarded-Encrypted: i=1; AJvYcCUEcbfI/bsNvt3Fgao/Oyi6S6RFV/0/OQBo8bKxgRTOezNTGQt23ROJVwpZoekW6eWSAl9krEXbr2BgXmQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywl79+yuGvyxG3cx6iS+/0bDqiWNI7XsRImrsN1n2oAnC2+7VTP eQbSHQJIiwb/n/I3CCXkqlHuX0z5rbr6jVN+8A1s8FQn9LrXbF0zB6g7KCTZeLI4Cx/pdlPxz5H RLOX1qFV8Eg== X-Received: from dycoh2.prod.google.com ([2002:a05:7301:da02:b0:2c5:f8b4:33a3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:3252:b0:2ba:964f:fa67 with SMTP id 5a478bee46e88-2cbfbe7d5ebmr1842255eec.24.1775248851905; Fri, 03 Apr 2026 13:40:51 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:04 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-13-irogers@google.com> Subject: [PATCH v5 12/25] perf db-export: Remove evsel from struct export_sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As the sample contains the evsel avoid the duplication. Remove the evsel from db_export__sample as it can also read from the sample. Signed-off-by: Ian Rogers --- tools/perf/util/db-export.c | 5 ++--- tools/perf/util/db-export.h | 3 +-- tools/perf/util/scripting-engines/trace-event-python.c | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index a1f578c3a8d5..fdfd825c7ef4 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -345,14 +345,13 @@ static int db_export__threads(struct db_export *dbe, = struct thread *thread, } =20 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 =3D al->thread; struct export_sample es =3D { .event =3D event, .sample =3D sample, - .evsel =3D evsel, .al =3D al, }; struct thread *main_thread; @@ -365,7 +364,7 @@ int db_export__sample(struct db_export *dbe, union perf= _event *event, if (!machine) return -1; =20 - err =3D db_export__evsel(dbe, evsel); + err =3D db_export__evsel(dbe, sample->evsel); if (err) return err; =20 diff --git a/tools/perf/util/db-export.h b/tools/perf/util/db-export.h index 23983cb35706..1abbfd398e3a 100644 --- a/tools/perf/util/db-export.h +++ b/tools/perf/util/db-export.h @@ -25,7 +25,6 @@ struct call_return; struct export_sample { union perf_event *event; struct perf_sample *sample; - struct evsel *evsel; struct addr_location *al; u64 db_id; u64 comm_db_id; @@ -96,7 +95,7 @@ int db_export__symbol(struct db_export *dbe, struct symbo= l *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); =20 int db_export__branch_types(struct db_export *dbe); diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index 08197cef44c8..8de08cebe240 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1312,7 +1312,7 @@ static void python_export_sample_table(struct db_expo= rt *dbe, t =3D tuple_new(28); =20 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 =3D tuple_new(3); =20 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); =20 call_object(tables->synth_handler, t, "synth_data"); @@ -1368,7 +1368,7 @@ static int python_export_sample(struct db_export *dbe, =20 python_export_sample_table(dbe, es); =20 - if (es->evsel->core.attr.type =3D=3D PERF_TYPE_SYNTH && tables->synth_han= dler) + if (es->sample->evsel->core.attr.type =3D=3D PERF_TYPE_SYNTH && tables->s= ynth_handler) python_export_synth(dbe, es); =20 return 0; @@ -1517,7 +1517,7 @@ static void python_process_event(union perf_event *ev= ent, /* 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); } --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7491E3D88E3 for ; Fri, 3 Apr 2026 20:40:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248858; cv=none; b=EPgqrZBhy2+3wV2WV6+GpPRM0gIAtR0fOFrwunQvuSvbGoi45WsBws0LASS9sfHXaQUSimW1Olcbm0ngMeVMOl63/edZjLuRZChdT8HU2/PuNcr0jFD/K2OMDdTqCGV5v0iexfcDHCdphFA2GoCRoJUHWsQjbw0Zo2R3knf7feU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248858; c=relaxed/simple; bh=jNIL33k87gtaSUPMibDJ6yPQJtDK0dHAdF1GtgBune4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qMqvjWXwUVG6AoEAPytTzeyXpo2cWgdPPDS65BimcUyCkQ4n5nC6h9qK8Rj2vthEi97itX9bq3JN0MWsxiak+rn3RdAHNbRVdXzmbXHS45iv1QWHDEk90I+nuUUwsP/SQQfzomI93plXgDaw9ZorCsW/mDrIohEUNFrna+lPw98= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KxMVnMT/; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KxMVnMT/" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12721cd1a2aso11297978c88.1 for ; Fri, 03 Apr 2026 13:40:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248855; x=1775853655; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ynwM+AEApMdqoZuvNbVdN+EnF0BWt1XhQbbnU8yhnto=; b=KxMVnMT/uCP+fa5uFu9nAoXgroYKJD72CmKyj2RY4ce+XjX4JWRhzAb+F8MlKNbP3F fUpSmCxDjet7sVve04ORXwJ3PRO3yncRRewALLRPXs+jcdlvhdq2NhQ/jNr/oCLUXeTL BbPaQx5mbvVN5gTL9tWDAQSK3aKhaTn1fRtCTmamnNTBNqm/bCw3mtKjp6lFBpWnx/bx szKDjwF6HqmmKS1zVy/QqICiZZAQKgsvxRBnyDRVLGCKEH91c8qaGzO2ku/jX2p+Mzfb Dw73/pdQcMI+EAL2JzoFvvtPemf0lyFHIP2E749T7QPZWlwiZqmEijzGr9I8U2edkjxO qiyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248855; x=1775853655; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ynwM+AEApMdqoZuvNbVdN+EnF0BWt1XhQbbnU8yhnto=; b=oRB1ByaLV/OSNSQhiuWpPGUXve1J+uZElahLh2LfOZ7OHunyX5mMsUJgGmFHDwyw6q a9Tv4Z7XD0RfEsdx/Ub66rybTvHMBHGr/e1fWetcy8AoN8ONrJiIZP2Og33zRgJYl0LF KU6rSSEfmhhNO/Xzx/QMl0G3OLGHRzdJCa6OXXHIxQ/pA3C6v1g1fenrJp8J5vagKf+q nO7B+Bgrx+a3yiAe83hzkctpTMUtBZVT8D9XciL96bQBfK3QQWuLMvkCv0VZtMnfAvTT AqLYDEkGJBCqoN9o8ro90mHTHTHQR6jtKArC/isKsnHnTRE/clZBz4iSuJP1zZ60Hbsz 6pug== X-Forwarded-Encrypted: i=1; AJvYcCWAJMQme0YY+jr6Rcawtgcb+D1L12pI+PMkztHYFBQDBhRrxevDd2uY/rCjyUQVqNf2vIAdEfm5HVRiszo=@vger.kernel.org X-Gm-Message-State: AOJu0YwnND6uFdDcJdAFJhlShtDoVMJB+G3R2SCOoVPv3WNTzh3d/8pN kDlX/A3hrS3p9EJYffWK+PMztM/pLjfIpW/YtCrQWBymgZisG4xTd84BPHSUy/oalC7L/YVJX1C QWw8SlBPNAg== X-Received: from dlbrh17.prod.google.com ([2002:a05:7022:f311:b0:12a:70c3:eda4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:ec17:b0:124:11af:7b75 with SMTP id a92af1059eb24-12bfb76f2a2mr2106655c88.34.1775248854355; Fri, 03 Apr 2026 13:40:54 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:05 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-14-irogers@google.com> Subject: [PATCH v5 13/25] perf hist: Remove evsel from struct hist_entry_iter From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" struct hist_entry_iter has the sample within it so the evsel is unnecessary. Remove the evsel and update uses. Also remove the evsel from hist__account_cycles and derive it from the sample too. Signed-off-by: Ian Rogers --- tools/perf/builtin-annotate.c | 10 ++++------ tools/perf/builtin-diff.c | 3 +-- tools/perf/builtin-report.c | 6 ++---- tools/perf/builtin-top.c | 9 +++------ tools/perf/tests/hists_cumulate.c | 1 - tools/perf/tests/hists_filter.c | 1 - tools/perf/tests/hists_output.c | 1 - tools/perf/util/hist.c | 24 ++++++++++++------------ tools/perf/util/hist.h | 3 +-- 9 files changed, 23 insertions(+), 35 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index c2d0599fe5f5..041f5dc92ea8 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -191,14 +191,12 @@ static int hist_iter__branch_callback(struct hist_ent= ry_iter *iter, return err; } =20 -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 =3D { - .evsel =3D evsel, .sample =3D sample, .add_entry_cb =3D hist_iter__branch_callback, .hide_unresolved =3D symbol_conf.hide_unresolved, @@ -221,8 +219,8 @@ static int process_branch_callback(struct evsel *evsel, if (a.map !=3D NULL) dso__set_hit(map__dso(a.map)); =20 - hist__account_cycles(sample->branch_stack, al, sample, false, - NULL, evsel); + hist__account_cycles(sample->branch_stack, al, sample, /*nonany_branch_mo= de=3D*/false, + /*total_cycles=3D*/NULL); =20 ret =3D hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann); out: @@ -269,7 +267,7 @@ static int evsel__add_sample(struct evsel *evsel, struc= t perf_sample *sample, process_branch_stack(sample->branch_stack, al, sample); =20 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); =20 he =3D hists__add_entry(hists, al, NULL, NULL, NULL, NULL, sample, true); if (he =3D=3D NULL) diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 096adc65451c..67cf5bbaab29 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -397,7 +397,6 @@ static int diff__process_sample_event(const struct perf= _tool *tool, struct evsel *evsel =3D sample->evsel; struct hists *hists =3D evsel__hists(evsel); struct hist_entry_iter iter =3D { - .evsel =3D evsel, .sample =3D sample, .ops =3D &hist_iter_normal, }; @@ -431,7 +430,7 @@ static int diff__process_sample_event(const struct perf= _tool *tool, } =20 hist__account_cycles(sample->branch_stack, &al, sample, - false, NULL, evsel); + /*nonany_branch_mode=3D*/false, /*total_cycles=3D*/NULL); break; =20 case COMPUTE_STREAM: diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 39968ae5cfb0..1051d7b75361 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -270,10 +270,8 @@ static int process_sample_event(const struct perf_tool= *tool, struct machine *machine) { struct report *rep =3D container_of(tool, struct report, tool); - struct evsel *evsel =3D sample->evsel; struct addr_location al; struct hist_entry_iter iter =3D { - .evsel =3D evsel, .sample =3D sample, .hide_unresolved =3D symbol_conf.hide_unresolved, .add_entry_cb =3D hist_iter__report_callback, @@ -285,7 +283,7 @@ static int process_sample_event(const struct perf_tool = *tool, return 0; } =20 - if (evswitch__discard(&rep->evswitch, evsel)) + if (evswitch__discard(&rep->evswitch, sample->evsel)) return 0; =20 addr_location__init(&al); @@ -329,7 +327,7 @@ static int process_sample_event(const struct perf_tool = *tool, if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) { hist__account_cycles(sample->branch_stack, &al, sample, rep->nonany_branch_mode, - &rep->total_cycles, evsel); + &rep->total_cycles); } =20 rep->total_samples++; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index b879592ae745..a66666e89f67 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -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 =3D arg; - struct evsel *evsel =3D iter->evsel; =20 if (perf_hpp_list.sym && single) perf_top__record_precise_ip(top, iter->he, iter->sample, al->addr); =20 hist__account_cycles(iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY), - NULL, evsel); + /*total_cycles=3D*/NULL); return 0; } =20 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 per= f_tool *tool, } =20 if (al.sym =3D=3D NULL || !al.sym->idle) { - struct hists *hists =3D evsel__hists(evsel); + struct hists *hists =3D evsel__hists(sample->evsel); struct hist_entry_iter iter =3D { - .evsel =3D evsel, .sample =3D sample, .add_entry_cb =3D hist_iter__top_callback, }; @@ -1211,7 +1208,7 @@ static int deliver_event(struct ordered_events *qe, } =20 if (event->header.type =3D=3D 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 =3D=3D PERF_RECORD_LOST) { perf_top__process_lost(top, event, evsel); diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cum= ulate.c index 606aa926a8fc..267cbc24691a 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -87,7 +87,6 @@ static int add_hist_entries(struct hists *hists, struct m= achine *machine) addr_location__init(&al); for (i =3D 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter =3D { - .evsel =3D evsel, .sample =3D &sample, .hide_unresolved =3D false, }; diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filte= r.c index cc6b26e373d1..002e3a4c1ca5 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -63,7 +63,6 @@ static int add_hist_entries(struct evlist *evlist, evlist__for_each_entry(evlist, evsel) { for (i =3D 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter =3D { - .evsel =3D evsel, .sample =3D &sample, .ops =3D &hist_iter_normal, .hide_unresolved =3D false, diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_outpu= t.c index 7818950d786e..fa683fd7b1e5 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -57,7 +57,6 @@ static int add_hist_entries(struct hists *hists, struct m= achine *machine) addr_location__init(&al); for (i =3D 0; i < ARRAY_SIZE(fake_samples); i++) { struct hist_entry_iter iter =3D { - .evsel =3D evsel, .sample =3D &sample, .ops =3D &hist_iter_normal, .hide_unresolved =3D false, diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index f51fd439d2dd..4e9a6e3b2a99 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -935,8 +935,8 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter,= struct addr_location *al { u64 cost; struct mem_info *mi =3D iter->mi; - struct hists *hists =3D evsel__hists(iter->evsel); struct perf_sample *sample =3D iter->sample; + struct hists *hists =3D evsel__hists(sample->evsel); struct hist_entry *he; =20 if (mi =3D=3D 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 =3D iter->evsel; + struct evsel *evsel =3D iter->sample->evsel; struct hists *hists =3D evsel__hists(evsel); struct hist_entry *he =3D iter->he; int err =3D -EINVAL; @@ -1036,9 +1036,9 @@ static int iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_locat= ion *al) { struct branch_info *bi; - struct evsel *evsel =3D iter->evsel; - struct hists *hists =3D evsel__hists(evsel); struct perf_sample *sample =3D iter->sample; + struct evsel *evsel =3D sample->evsel; + struct hists *hists =3D evsel__hists(evsel); struct hist_entry *he =3D NULL; int i =3D iter->curr; int err =3D 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 =3D iter->evsel; + struct evsel *evsel =3D iter->sample->evsel; struct hists *hists =3D evsel__hists(evsel); =20 for (int i =3D 0; i < iter->total; i++) @@ -1103,8 +1103,8 @@ iter_prepare_normal_entry(struct hist_entry_iter *ite= r __maybe_unused, static int iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_loc= ation *al) { - struct evsel *evsel =3D iter->evsel; struct perf_sample *sample =3D iter->sample; + struct evsel *evsel =3D sample->evsel; struct hist_entry *he; =20 he =3D 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 =3D iter->he; - struct evsel *evsel =3D iter->evsel; struct perf_sample *sample =3D iter->sample; + struct evsel *evsel =3D sample->evsel; =20 if (he =3D=3D 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 =3D iter->evsel; - struct hists *hists =3D evsel__hists(evsel); struct perf_sample *sample =3D iter->sample; + struct evsel *evsel =3D sample->evsel; + struct hists *hists =3D evsel__hists(evsel); struct hist_entry **he_cache =3D iter->he_cache; struct hist_entry *he; int err =3D 0; @@ -1224,8 +1224,8 @@ static int iter_add_next_cumulative_entry(struct hist_entry_iter *iter, struct addr_location *al) { - struct evsel *evsel =3D iter->evsel; struct perf_sample *sample =3D iter->sample; + struct evsel *evsel =3D sample->evsel; struct hist_entry **he_cache =3D iter->he_cache; struct hist_entry *he; struct hist_entry he_tmp =3D { @@ -2826,7 +2826,7 @@ int hists__unlink(struct hists *hists) =20 void hist__account_cycles(struct branch_stack *bs, struct addr_location *a= l, 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 =3D perf_sample__branch_entries(sample); @@ -2850,7 +2850,7 @@ void hist__account_cycles(struct branch_stack *bs, st= ruct addr_location *al, for (int i =3D bs->nr - 1; i >=3D 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 =3D &bi[i].to; =20 diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index d97a4efb9250..8fb89d81ef06 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -156,7 +156,6 @@ struct hist_entry_iter { int total; int curr; =20 - 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); =20 void hist__account_cycles(struct branch_stack *bs, struct addr_location *a= l, struct perf_sample *sample, bool nonany_branch_mode, - u64 *total_cycles, struct evsel *evsel); + u64 *total_cycles); =20 struct option; int parse_filter_percentage(const struct option *opt, const char *arg, int= unset); --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4BA33D9050 for ; Fri, 3 Apr 2026 20:40:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248860; cv=none; b=CoFtuRoS5v2uxz5fP7MBlSNTCwLu1niuJpggk8wJX5ag8Dx9vaEEJJpjAH3uk+R6SFRbWQ46rRh1oX9ya0HZQYnA1N4/hF8u5iGpcR77ntcPnnIYzULlFcS4J4aYmhfZ7+R+jtvw+s7wlHhBs6vc6mA70dURPIBiwMQwFRhBaKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248860; c=relaxed/simple; bh=JgM+52mZfp1KpJI7qRA2MZX5dCKkv3vx+FbrM+Xh2Vk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lqHYQhnOqH8+y4sBhUFl3zA5+Hyi8WH9d2D4yqS5wYfqrE/ONCSQLpv+a5jT32Mgkk542q43DFvxSQzmGPPeLRKLokCtMqktzF0swoFcxGD9n9x1cTq7Q/oJk2UXXdXnjyt3j0EvJyrEnXT+fqBAqDKqZVWnJSjgN3V+i7ZS2KI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=A8jm58Mn; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="A8jm58Mn" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2cc75e79b97so4880348eec.1 for ; Fri, 03 Apr 2026 13:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248857; x=1775853657; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1JpZYRI0yfE+caWiHFk758a3ExOIBuBQsAJlndyijH0=; b=A8jm58MnDeg0oeaZ5O+pQ94XVCuHYOKjQpvrw4MOXUWr1eIgNnFs9t3M3G0H9QtEIJ I6nqZ8VjOf8/lI9R+3A6nxl8cKAGr4hJAbE2MaxXQqU68XgFq3UfjPuWvTVQPQEZ3oD/ qrUFs2zxDwl+0OxnA9pRJ9ZErDiOYhn8bqoEQLmHFH0NHnxvH3c2gsBq4cvp0xGIxqW2 lEo6zk+iWYZZNqtuCtdf67Wmjg/8r6ONXeTnNtnBrp4Ytn79zKWx15yb+7rZzSj1RPDv 58h18Ahs9cEXJrtdv8amYozMqXONoPeszZganeYaQvvxOyjzymQPhRBci257WrKQlOgE 4MUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248857; x=1775853657; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1JpZYRI0yfE+caWiHFk758a3ExOIBuBQsAJlndyijH0=; b=n978eANAAVMkZaFW+YKqPJJOOSUAdXHBzTkKSDjMyK2Ix12gsSpABm97w8LlrVTrBw 3s0mkam4T3x+asVZjAXi2Ts4QAAQhgCYsc/aJbzg9ngL24hroZ3nYrCkjzVuvJoRMY2p 7lJssbI1JCVJPRvhdmFoI2fYMDXOjuOYU4IIwU5OWmVFRqHAlNrWeXWxwSxgsRcPNHHQ fpePlN3l+snLn0mxalUn9eNC2ckbdCDx3H5VKseK3AKYfTd4RE/D0zQmFZRsRHMqh0Dz i77gkkttSQwFnHE/W8tUd26cuvxZSgAi8taHIy0Y4LExsBKkMV27LnizUvX+8XO0z710 MjeA== X-Forwarded-Encrypted: i=1; AJvYcCXr2tJOQsdLfKmSkUQIIj0IEEGdTlj1EE/Gw6MpEsug2dUOzpBgdnX5n6kWR16+7uSSiObwk54HgvkKxRc=@vger.kernel.org X-Gm-Message-State: AOJu0YyfON6s+E4EytstQVvXubpmc0j42RXvjzxvO5LmPPVqto9yWEgn wUq8gcBgaGog/1HBFURvUat9GTO/mpXNPxXtwIgq9axKzHaJaj1bE+c85eVK1R/GmUu6cEx+MvL ygVDInHf8lQ== X-Received: from dybb26.prod.google.com ([2002:a05:693c:609a:b0:2c4:e587:8597]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:4090:b0:2c0:becb:7640 with SMTP id 5a478bee46e88-2cbfa9b364amr2115953eec.12.1775248856697; Fri, 03 Apr 2026 13:40:56 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:06 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-15-irogers@google.com> Subject: [PATCH v5 14/25] perf report: Directly use sample->evsel to avoid computing from sample->id From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In count_lost_samples_events try to avoid searching for the evsel for the sample, just use the variable within the sample. Signed-off-by: Ian Rogers --- tools/perf/builtin-report.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 1051d7b75361..d53aa7a94192 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -793,9 +793,11 @@ static int count_lost_samples_event(const struct perf_= tool *tool, struct machine *machine __maybe_unused) { struct report *rep =3D container_of(tool, struct report, tool); - struct evsel *evsel; + struct evsel *evsel =3D sample->evsel; + + if (!evsel) + evsel =3D evlist__id2evsel(rep->session->evlist, sample->id); =20 - evsel =3D evlist__id2evsel(rep->session->evlist, sample->id); if (evsel) { struct hists *hists =3D evsel__hists(evsel); u32 count =3D event->lost_samples.lost; --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDC023D9DA3 for ; Fri, 3 Apr 2026 20:40:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248863; cv=none; b=czDxs41VEkIAI04SgmkGrfDLKDEhq5frLSsJwjw+ss2L7icMvAWHbnHAwS4XZMZdJWRhqczLrizMh5fYL13vNu3rzffyjUca8DwC+R7tg7x01GIdNAjscgSg57U/3ow48uR2NnqXg3Y7se29byOFtAj//R+xOis3pd1hP9gl1hQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248863; c=relaxed/simple; bh=/7Otdj/WgbXIh6suCTdVqM2xyOka8p1nEa55b4snr9A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PFveEE7V8dridZG9dLMB3zQMzXSIWF2JCIqEfy4dkf5SqlePry5oldmI+lQKE0731DjWoYhD5vKC8jDM+T5jbBbhGSg+JSxzkbvE/fzaexzkLrI1eFsPdKqkMz/jNEt2SCpRSgMc+FlV+NyXLuY8d7o9gJtMJXRl7iFM5ABMnSE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=bLr0+9TX; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bLr0+9TX" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-82ce0a9e558so1545554b3a.1 for ; Fri, 03 Apr 2026 13:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248859; x=1775853659; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7q5/FlfPtZ6fBz0id1vXEKUDGTL26BmbGuI50JUYOeM=; b=bLr0+9TXzkQ+8CKouRo4b92QFruLsO5zKB1wgK1wQO+2GyVWNGFk8GPKJCuRSrhJh9 loj2qjB4mC4u1aI29te3wsQA3xITEQ8jKlKnr3MX3tsHjPmXrPsOk/TbhgVW8J6JTQVa Qx2Am681XoVerKfvZKDYdya18Kgvi6VtHsJzH54CQ60hcAurY5ToyedXXyMhZ++67jv7 qXmr6p7Y/gFkLcO9tu1DIxLfrXHP5ldIPxqCC7IACrc7yP6eiSVaL+hnJHt7BPUKcb5s RE69U/x6CeiP1YXokINCNkgkgX4MempYEoyrilcVE+6Tzy7QBTpjsndLpMkvUVng5bmW QVuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248859; x=1775853659; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7q5/FlfPtZ6fBz0id1vXEKUDGTL26BmbGuI50JUYOeM=; b=pJ+QgkVtcILA1HlrkggPOkFvK5nAvazbn8lB6txTxxZnblPpZKz9L397MRq2rOKtLT 72Iwwm6UI/aEHuFMBw89r2wg52lIbLa6rG3AD8GAGE3tvX8CpfAQ/9Sc++saBNDtUULY 3pH0Aule+3LV/06Zdb8/APQgOCX4QpsVmPLZ7qdzysjT85HhLH0FSzoypiy8XwZbdnd0 XskUbRfc8X8zM0Mia0hg14ufsJ977ymrid3WLpQ/tGlrFoutW89oQbinqpt0wuSOFN/x kJlNbzCuxGT9vK8MG0U4xa6vojeh+EIByFyCtJc4V8oSlcq9kWt66KhKoR3SmyJJ8kby GX4A== X-Forwarded-Encrypted: i=1; AJvYcCX+x074TvCY2ly3R0hDPxHHl2iwtwQ3CtFtsEuur4jTLDLe6dme6o00RI2xkK4q8bPDPcbE9pqKPwVBzYg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz69RVZV5QgeIr1pFmw9uWuJ+sI+ojWmWAh3tujUQhDbIL4RvQf PHx/yLdecIrymNKhbijS5wIb9VISD7HKWYXzvAzd7N5dB6tITEBXZKjX7tak4vZ2OQRxFTNmxXO RJtGrez3qCA== X-Received: from pfbef11.prod.google.com ([2002:a05:6a00:2c8b:b0:82c:e41e:8959]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3010:b0:82c:e76b:c68c with SMTP id d2e1a72fcca58-82d0d73f532mr3648419b3a.0.1775248858842; Fri, 03 Apr 2026 13:40:58 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:07 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-16-irogers@google.com> Subject: [PATCH v5 15/25] perf annotate: Don't pass evsel to add_sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sample contains the evsel so read it rather than pass it. Update call site. Signed-off-by: Ian Rogers --- tools/perf/builtin-annotate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 041f5dc92ea8..894e57aa50cd 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -233,11 +233,11 @@ static bool has_annotation(struct perf_annotate *ann) return ui__has_annotation() || ann->use_stdio2; } =20 -static int evsel__add_sample(struct evsel *evsel, struct perf_sample *samp= le, - 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 =3D evsel__hists(evsel); + struct hists *hists =3D evsel__hists(sample->evsel); struct hist_entry *he; int ret; =20 @@ -299,7 +299,7 @@ static int process_sample_event(const struct perf_tool = *tool, goto out_put; =20 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 =3D -1; --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 114543D9046 for ; Fri, 3 Apr 2026 20:41:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248864; cv=none; b=Ghpv6wVM45ryKfFXWXVIptLLXyb+EiM0+T3i0se6hndMLo03ul93KgE+Buv/M+6usBig07OnCzKFLqwpHb/G85kh8/kzLasFCozryPuGhDt3HWA9jJlZijy+lhJNsuAVrQbwHkIOte5Saa4Ep+z6uCUenpNfvKapICTjmVunFzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248864; c=relaxed/simple; bh=TGry0rol2phRV3nf/gGlXMg5O8aSIHeIVmtzCEk+VAw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=i5ZTlldo11dS/hTM6d7FBHEKcTwkUejNL7vy92MNL5FIqVzsl0/M2adUbgJJ9vpkoRlrIgsLdh+LMqugsvOJYm+yO7oHvoCUHhdY1qyRELgGJDyYW71nUVZtLoxBF8T4bXZ0tDvi35fdgz/6xo/UVaYJ3fDXyACMoRzf/DbQn8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XfMXiNRR; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XfMXiNRR" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-1276e71652fso4453087c88.0 for ; Fri, 03 Apr 2026 13:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248861; x=1775853661; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8aSAXkrfY52iMPy7jV0WTr7OXSfW79HOOKSw/IFS7Ow=; b=XfMXiNRRVQBws82OaKhOCHxj/wfpUM0XjHgo8AK5Fyh/2HqV+Kx0ul2jF1MdR0gtz6 SEXgJl0tSS5ftwfVye6HitRdDbyayDVSUNt3XvLBgGM7xbqTDyrW+cWj02u70CpW4rjb bweQQlLuuptfenoBt8e9fHBXdWKuvtMZ6ABHI7GaA51eJhzVPzr9A6CS3/XTesP2U+vl UiUtgKhE/w66qN1NdYurdGNmH2VqA1ApQC/7b1SNzibVdXDQM5Ah4ywhdJ6OtqbMdxNs OGi7Qv7iRP+mby1LHY4VdGSEeXfVgVQPNqvgo8MPrj1v+UhiH6EBijq+txUjcKejdlFo 8e0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248861; x=1775853661; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8aSAXkrfY52iMPy7jV0WTr7OXSfW79HOOKSw/IFS7Ow=; b=k8YntIi+XHDbuPw3rX7lgV6toNgfVRQmj1MZBIiiObAgsby/PCvkguVaf5e7dx+PwI +Qj6KvQVYP1SVDLVn4c5WcdB7UWXNWfezKY9ZhNA5jBVGHs7iupbstB9l9XsUcguhz6S EzpfevnX3gk9jPSJ550MRZ96fEvWt8td0k4Ng03ctJlhWlwZzZo7y1x8qndCrpLq5iYG 85LPlZXxgHQ4tbp2g/ALzDvA1jlhdnIA/2zB4aIJd9VP9/vag/kcKDUNzbNODBeTzxtH QBMgmt2qQbJ4gSom4GRKRRXZkuDPqvT6iiklv2A84KrQsvNb7rW6drsSY5uv7yBnICPD 497Q== X-Forwarded-Encrypted: i=1; AJvYcCVOSLShAhpCUx/rgqOUTKLQP2BsqT/PT+ezh+CFBaFYCA2tyUPl+TIjYEBFXss1/riiJt8kQkgWUAUk36o=@vger.kernel.org X-Gm-Message-State: AOJu0YyiH0wdEjJ/kZLDNHRF53kmV3uz35NjsT/Nu1HJYyOBujnlqSsj qpqEm45Q1T1T8b8xaWsOM7vWU2iEg46IXvab6yR999hp3DbUVwlHTIKqplix+6LD++ljQE+7WRs hQZTr7/RauQ== X-Received: from dlbuy21.prod.google.com ([2002:a05:7022:1e15:b0:128:d48f:6f7d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:e25:b0:12a:6e97:c21f with SMTP id a92af1059eb24-12bfb62b033mr2060481c88.0.1775248861093; Fri, 03 Apr 2026 13:41:01 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:08 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-17-irogers@google.com> Subject: [PATCH v5 16/25] perf inject: Don't pass evsel with sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sample contains the evsel and so it is unnecessary to pass the evsel as well. Clean up handling of sample and mmap_evsel when synthesizing build id events and mmap2 events with build ids. For callchain walking and things that expect the evsel to match sample, the sample->evsel shouldn't change. The mmap_evsel should be used when making mmap2 events. Add space for sample identifiers in perf_event__synthesize_mmap2_build_id to avoid Sashiko caught potential buffer overrun. Also add a NULL check to avoid an unlikely SEGV. Signed-off-by: Ian Rogers --- tools/perf/builtin-inject.c | 52 +++++++++-------- tools/perf/util/synthetic-events.c | 92 +++++++++++++++++++----------- tools/perf/util/synthetic-events.h | 2 - 3 files changed, 86 insertions(+), 60 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index ebcbe7a7202c..1989feedd6ff 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -146,14 +146,12 @@ struct event_entry { static int tool__inject_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, const char *filename, struct dso *dso, u32 flags); static int tool__inject_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -357,7 +355,6 @@ perf_inject__cut_auxtrace_sample(struct perf_inject *in= ject, typedef int (*inject_handler)(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct machine *machine); =20 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, =20 if (evsel && evsel->handler) { inject_handler f =3D evsel->handler; - return f(tool, event, sample, evsel, machine); + return f(tool, event, sample, machine); } =20 build_id__mark_dso_hit(tool, event, sample, machine); @@ -584,11 +581,12 @@ static int perf_event__repipe_common_mmap(const struc= t perf_tool *tool, } =20 if (dso && !dso__hit(dso)) { - struct evsel *evsel =3D evlist__event2evsel(inject->session->evlist, ev= ent); + if (!sample->evsel) + sample->evsel =3D evlist__event2evsel(inject->session->evlist, event); =20 - 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=3D*/sample->cpumode, filename, dso, flags); } @@ -615,23 +613,26 @@ static int perf_event__repipe_common_mmap(const struc= t perf_tool *tool, } if ((inject->build_id_style =3D=3D BID_RWS__MMAP2_BUILDID_ALL) && !(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) { - struct evsel *evsel =3D evlist__event2evsel(inject->session->evlist, eve= nt); + struct evsel *saved_evsel =3D sample->evsel; =20 - if (evsel && !dso_sought) { + sample->evsel =3D evlist__event2evsel(inject->session->evlist, event); + if (sample->evsel && !dso_sought) { dso =3D findnew_dso(pid, tid, filename, dso_id, machine); dso_sought =3D 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 =3D saved_evsel; dso__put(dso); return 0; } + sample->evsel =3D saved_evsel; } dso__put(dso); if (inject->build_id_style =3D=3D BID_RWS__MMAP2_BUILDID_LAZY) @@ -836,7 +837,6 @@ static bool perf_inject__lookup_known_build_id(struct p= erf_inject *inject, static int tool__inject_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, const char *filename, struct dso *dso, u32 flags) @@ -860,7 +860,7 @@ static int tool__inject_build_id(const struct perf_tool= *tool, =20 err =3D perf_event__synthesize_build_id(tool, sample, machine, perf_event__repipe, - evsel, misc, dso__bid(dso), + misc, dso__bid(dso), filename); if (err) { pr_err("Can't synthesize build_id event for %s\n", filename); @@ -873,7 +873,6 @@ static int tool__inject_build_id(const struct perf_tool= *tool, static int tool__inject_mmap2_build_id(const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *evsel, __u16 misc, __u32 pid, __u32 tid, __u64 start, __u64 len, __u64 pgoff, @@ -896,7 +895,6 @@ static int tool__inject_mmap2_build_id(const struct per= f_tool *tool, =20 err =3D perf_event__synthesize_mmap2_build_id(tool, sample, machine, perf_event__repipe, - evsel, misc, pid, tid, start, len, pgoff, dso__bid(dso), @@ -913,7 +911,7 @@ static int mark_dso_hit(const struct perf_inject *injec= t, const struct perf_tool *tool, struct perf_sample *sample, struct machine *machine, - const struct evsel *mmap_evsel, + struct evsel *mmap_evsel, struct map *map, bool sample_in_dso) { struct dso *dso; @@ -941,9 +939,13 @@ static int mark_dso_hit(const struct perf_inject *inje= ct, dso =3D map__dso(map); if (inject->build_id_style =3D=3D 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 =3D=3D BID_RWS__MMAP2_BUILDID_LAZY) { @@ -951,11 +953,13 @@ static int mark_dso_hit(const struct perf_inject *inj= ect, const struct build_id null_bid =3D { .size =3D 0 }; const struct build_id *bid =3D dso ? dso__bid(dso) : &null_bid; const char *filename =3D dso ? dso__long_name(dso) : ""; + struct evsel *saved_evsel =3D sample->evsel; =20 map__set_hit(map); + /* Creating a new mmap2 event which has an evsel for the mmap event. */ + sample->evsel =3D mmap_evsel; perf_event__synthesize_mmap2_build_id(tool, sample, machine, perf_event__repipe, - mmap_evsel, misc, sample->pid, sample->tid, map__start(map), @@ -965,6 +969,7 @@ static int mark_dso_hit(const struct perf_inject *injec= t, map__prot(map), map__flags(map), filename); + sample->evsel =3D saved_evsel; } } return 0; @@ -975,7 +980,7 @@ struct mark_dso_hit_args { const struct perf_tool *tool; struct perf_sample *sample; struct machine *machine; - const struct evsel *mmap_evsel; + struct evsel *mmap_evsel; }; =20 static int mark_dso_hit_callback(struct callchain_cursor_node *node, void = *data) @@ -1030,7 +1035,6 @@ static int perf_event__inject_buildid(const struct pe= rf_tool *tool, union perf_e static int perf_inject__sched_process_exit(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, struct machine *machine __maybe_unused) { struct perf_inject *inject =3D container_of(tool, struct perf_inject, too= l); @@ -1050,13 +1054,12 @@ static int perf_inject__sched_process_exit(const st= ruct 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 =3D container_of(tool, struct perf_inject, too= l); struct event_entry *ent; =20 - perf_inject__sched_process_exit(tool, event, sample, evsel, machine); + perf_inject__sched_process_exit(tool, event, sample, machine); =20 ent =3D malloc(event->header.size + sizeof(struct event_entry)); if (ent =3D=3D NULL) { @@ -1075,13 +1078,13 @@ static int perf_inject__sched_switch(const struct p= erf_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 =3D container_of(tool, struct perf_inject, too= l); + struct evsel *evsel =3D sample->evsel; u32 pid =3D perf_sample__intval(sample, "pid"); int ret; =20 @@ -1446,7 +1449,7 @@ static int synthesize_build_id(struct perf_inject *in= ject, struct dso *dso, pid_ dso__set_hit(dso); =20 return perf_event__synthesize_build_id(&inject->tool, &synth_sample, mach= ine, - process_build_id, inject__mmap_evsel(inject), + process_build_id, /*misc=3D*/synth_sample.cpumode, dso__bid(dso), dso__long_name(dso)); } @@ -2008,7 +2011,6 @@ static int evsel__check_stype(struct evsel *evsel, u6= 4 sample_type, const char * static int drop_sample(const struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct machine *machine __maybe_unused) { return 0; diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index ddf1cbda1902..e848129db996 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -1802,7 +1802,12 @@ int perf_event__synthesize_sample(union perf_event *= event, u64 type, u64 read_fo return 0; } =20 -int perf_event__synthesize_id_sample(__u64 *array, u64 type, const struct = perf_sample *sample) +static int __perf_event__synthesize_id_sample(__u64 *array, u64 type, + __u32 pid, __u32 tid, + __u64 sample_time, + __u64 sample_id, + __u64 stream_id, + __u32 cpu) { __u64 *start =3D array; =20 @@ -1813,42 +1818,52 @@ int perf_event__synthesize_id_sample(__u64 *array, = u64 type, const struct perf_s union u64_swap u; =20 if (type & PERF_SAMPLE_TID) { - u.val32[0] =3D sample->pid; - u.val32[1] =3D sample->tid; + u.val32[0] =3D pid; + u.val32[1] =3D tid; *array =3D u.val64; array++; } =20 if (type & PERF_SAMPLE_TIME) { - *array =3D sample->time; + *array =3D sample_time; array++; } =20 if (type & PERF_SAMPLE_ID) { - *array =3D sample->id; + *array =3D sample_id; array++; } =20 if (type & PERF_SAMPLE_STREAM_ID) { - *array =3D sample->stream_id; + *array =3D stream_id; array++; } =20 if (type & PERF_SAMPLE_CPU) { - u.val32[0] =3D sample->cpu; + u.val32[0] =3D cpu; u.val32[1] =3D 0; *array =3D u.val64; array++; } =20 if (type & PERF_SAMPLE_IDENTIFIER) { - *array =3D sample->id; + *array =3D sample_id; array++; } =20 return (void *)array - (void *)start; } =20 +int perf_event__synthesize_id_sample(__u64 *array, u64 type, const struct = perf_sample *sample) +{ + return __perf_event__synthesize_id_sample(array, type, + sample->pid, sample->tid, + sample->time, + sample->id, + sample->stream_id, + sample->cpu); +} + int __perf_event__synthesize_id_index(const struct perf_tool *tool, perf_e= vent__handler_t process, struct evlist *evlist, struct machine *machine, size_t from) { @@ -2252,7 +2267,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) @@ -2275,12 +2289,13 @@ int perf_event__synthesize_build_id(const struct pe= rf_tool *tool, ev.build_id.header.size =3D len; strcpy(ev.build_id.filename, filename); =20 - if (evsel) { + if (sample->evsel) { void *array =3D &ev; int ret; =20 array +=3D ev.header.size; - ret =3D perf_event__synthesize_id_sample(array, evsel->core.attr.sample_= type, sample); + ret =3D perf_event__synthesize_id_sample(array, sample->evsel->core.attr= .sample_type, + sample); if (ret < 0) return ret; =20 @@ -2299,7 +2314,6 @@ int perf_event__synthesize_mmap2_build_id(const struc= t 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, @@ -2307,39 +2321,51 @@ int perf_event__synthesize_mmap2_build_id(const str= uct perf_tool *tool, __u32 prot, __u32 flags, const char *filename) { - union perf_event ev; + struct { + union perf_event ev; + /* Esnure there is sufficient storage space for sample ids. */ + __u64 sample_ids[MAX_ID_HDR_ENTRIES]; + } ev; size_t ev_len; void *array; int ret; =20 - ev_len =3D sizeof(ev.mmap2) - sizeof(ev.mmap2.filename) + strlen(filename= ) + 1; + if (!sample->evsel) + return -EINVAL; /* Evsel is needed for sample_type data. */ + + ev_len =3D sizeof(ev.ev.mmap2) - sizeof(ev.ev.mmap2.filename) + strlen(fi= lename) + 1; ev_len =3D PERF_ALIGN(ev_len, sizeof(u64)); =20 memset(&ev, 0, ev_len); =20 - ev.mmap2.header.type =3D PERF_RECORD_MMAP2; - ev.mmap2.header.misc =3D misc | PERF_RECORD_MISC_MMAP_BUILD_ID; - ev.mmap2.header.size =3D ev_len; + ev.ev.mmap2.header.type =3D PERF_RECORD_MMAP2; + ev.ev.mmap2.header.misc =3D misc | PERF_RECORD_MISC_MMAP_BUILD_ID; + ev.ev.mmap2.header.size =3D ev_len; =20 - ev.mmap2.pid =3D pid; - ev.mmap2.tid =3D tid; - ev.mmap2.start =3D start; - ev.mmap2.len =3D len; - ev.mmap2.pgoff =3D pgoff; + ev.ev.mmap2.pid =3D pid; + ev.ev.mmap2.tid =3D tid; + ev.ev.mmap2.start =3D start; + ev.ev.mmap2.len =3D len; + ev.ev.mmap2.pgoff =3D pgoff; =20 - ev.mmap2.build_id_size =3D bid->size; - if (ev.mmap2.build_id_size > sizeof(ev.mmap2.build_id)) - ev.build_id.size =3D sizeof(ev.mmap2.build_id); - memcpy(ev.mmap2.build_id, bid->data, ev.mmap2.build_id_size); + ev.ev.mmap2.build_id_size =3D bid->size; + if (ev.ev.mmap2.build_id_size > sizeof(ev.ev.mmap2.build_id)) + ev.ev.build_id.size =3D sizeof(ev.ev.mmap2.build_id); + memcpy(ev.ev.mmap2.build_id, bid->data, ev.ev.mmap2.build_id_size); =20 - ev.mmap2.prot =3D prot; - ev.mmap2.flags =3D flags; + ev.ev.mmap2.prot =3D prot; + ev.ev.mmap2.flags =3D flags; =20 - memcpy(ev.mmap2.filename, filename, min(strlen(filename), sizeof(ev.mmap.= filename))); + memcpy(ev.ev.mmap2.filename, filename, min(strlen(filename), sizeof(ev.ev= .mmap.filename))); =20 array =3D &ev; - array +=3D ev.header.size; - ret =3D perf_event__synthesize_id_sample(array, evsel->core.attr.sample_t= ype, sample); + array +=3D ev.ev.header.size; + ret =3D __perf_event__synthesize_id_sample(array, sample->evsel->core.att= r.sample_type, + pid, tid, + sample->time, + sample->id, + sample->stream_id, + sample->cpu); if (ret < 0) return ret; =20 @@ -2348,9 +2374,9 @@ int perf_event__synthesize_mmap2_build_id(const struc= t perf_tool *tool, return -EINVAL; } =20 - ev.header.size +=3D ret; + ev.ev.header.size +=3D ret; =20 - return process(tool, &ev, sample, machine); + return process(tool, &ev.ev, sample, machine); } =20 int perf_event__synthesize_stat_events(struct perf_stat_config *config, co= nst struct perf_tool *tool, diff --git a/tools/perf/util/synthetic-events.h b/tools/perf/util/synthetic= -events.h index b0edad0c3100..473a43a78993 100644 --- a/tools/perf/util/synthetic-events.h +++ b/tools/perf/util/synthetic-events.h @@ -50,7 +50,6 @@ int perf_event__synthesize_build_id(const struct perf_too= l *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 pe= rf_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, --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 632593D813B for ; Fri, 3 Apr 2026 20:41:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248865; cv=none; b=WRwEwpjOn4E4XEURzcoeT9ztmUflanBQ0IndqiTRIqbmd2XOzuTsrIFTta9yRdIxXs1SlbgBS7yp2tnxgwUY+tJvUJmcbcc9arR4gRbLK4542cW4NkQUN1HIIX6PyIszmC9ZKU9uMadEDL+ZjDFZ7HD7Vzn02Lnb+h4ULPrd9C8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248865; c=relaxed/simple; bh=lta2fI5qXdYPdhIfm8zOThe6wXUgcAlnODSeXuma/Io=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GPYZ6bFeKbd+W3rmTuM83JCiavaI/HFkQBePUOTv5sLEI8aUQfTxVEmFJAFzJLzWLhsFBrQy/YEnGMQMHBFs9MMbzrliBAIyOE2JPnF0U7SMsWwBMPvRuOkik826Llrp0AZX3x89F+uB2VSQETgPsMsBCLuT9VsVF1AxOjDyrug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ulDUbRVy; arc=none smtp.client-ip=74.125.82.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ulDUbRVy" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-1276e71652fso4453143c88.0 for ; Fri, 03 Apr 2026 13:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248864; x=1775853664; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KaYE6VTNH1rn50K/H2pN6vOvFrscNqJ0UK5rxmsiNw8=; b=ulDUbRVyRxSf4ys6gxo7zqsTsM6HwYLURVTEqwFIi5AmYpOmaJd6/0YrlSTt1DT52O 414eWe1npzyj7PYTXVyTnwbQQJyqSkY4xvOqYl6hJ6YwmB2jG3BUEKL1Sw/9TygeZVpy //ZEQMHXEHg1Hau+ogPJevOVSjkYlWrgozfSmOdBa3jSv8yE+sek3qEnDx0XhFX/R7Qn mBWEaOksjJlvHv1zMcZOqJ0fxuOpt6Tm02RtXS2udSWZj/+cEyTkMBMSv0awqf0A7NaO 26ga4BPi/Z1lCNe2P1vI4+KD0HE4gopvr+nq4+ZHpiXcBuHhTgp26W6ZbbfIM1mps2pY X9fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248864; x=1775853664; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KaYE6VTNH1rn50K/H2pN6vOvFrscNqJ0UK5rxmsiNw8=; b=k4Ss7QUYDUrLdq3AdNmXz12fVqLE3cs2F5NQCy5WAAwRDd0MEuaEaJ3Ku6LGJHCNzI IjWIVoVxj/lrML2x7P7pqYqelhvOIHWtIjXtIRYnZsM21WstnX1MQJlC5PcY1fRifZ3T +IOTXJ6Syr7OekCrrYb/TAhxhA+1TEd5uEWWPHcdw5FU5RMjWrZV/yLH0oGnDaHfBy4b /JvmRvnwpO+W/PILm4bsJn5P+by0gM31kyR0Lg2DP2meaXpUIkh5wQPkll1mvFzIiFTS BeZ8gqDafGYG3SGbSyjmCPiDmMd7KtfZ+vmti001aIXu/mef/NEpPqHkAdh+/pvk+SgD vU5w== X-Forwarded-Encrypted: i=1; AJvYcCVOpQiYUNmFOPA5m9FZ0DZMnWWMvnN6En8APOeoSxIdWNFdvcx6nBpwru8b5a2f4SmGsDZX0bgxUZJGE5I=@vger.kernel.org X-Gm-Message-State: AOJu0YxvT9inoBIZqByMYGAQyruRycdwv8xH/x/cmgz0/11ADXdiNyxR KWo3J33kYPvaA4ow3ER4QWXmFahB2PKRuO12bd62yRRdb9nT2qyi09tNUwVuifAzctBkUG/O4Bl ai1fu8tQGXA== X-Received: from dlae5.prod.google.com ([2002:a05:701b:2305:b0:12b:fdc5:ed69]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7023:b0c:b0:12a:713b:8953 with SMTP id a92af1059eb24-12bfb6fbf94mr1891515c88.12.1775248863422; Fri, 03 Apr 2026 13:41:03 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:09 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-18-irogers@google.com> Subject: [PATCH v5 17/25] perf kmem: Don't pass evsel with sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sample contains the evsel and so it is unnecessary to pass the evsel as well. Fix memory leaks on error paths spotted during code review. Signed-off-by: Ian Rogers --- tools/perf/builtin-kmem.c | 44 ++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index b04f5d578e7a..cafa0eabfbc5 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -171,7 +171,7 @@ static int insert_caller_stat(unsigned long call_site, return 0; } =20 -static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sam= ple *sample) +static int evsel__process_alloc_event(struct perf_sample *sample) { unsigned long ptr =3D perf_sample__intval(sample, "ptr"), call_site =3D perf_sample__intval(sample, "call_site"); @@ -198,7 +198,7 @@ static int evsel__process_alloc_event(struct evsel *evs= el, 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; =20 node1 =3D cpu__get_node((struct perf_cpu){.cpu =3D sample->cpu}); @@ -243,7 +243,7 @@ static struct alloc_stat *search_alloc_stat(unsigned lo= ng ptr, return NULL; } =20 -static int evsel__process_free_event(struct evsel *evsel __maybe_unused, s= truct perf_sample *sample) +static int evsel__process_free_event(struct perf_sample *sample) { unsigned long ptr =3D 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; } =20 -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_fl= ags) { struct tep_record record =3D { .cpu =3D sample->cpu, @@ -773,7 +772,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct = perf_sample *sample, } =20 trace_seq_init(&seq); - tp_format =3D evsel__tp_format(evsel); + tp_format =3D evsel__tp_format(sample->evsel); if (tp_format) tep_print_event(tp_format->tep, &seq, &record, "%s", TEP_PRINT_INFO); =20 @@ -784,17 +783,21 @@ static int parse_gfp_flags(struct evsel *evsel, struc= t perf_sample *sample, =20 new =3D realloc(gfps, (nr_gfps + 1) * sizeof(*gfps)); if (new =3D=3D NULL) - return -ENOMEM; + goto err_out; =20 gfps =3D new; - new +=3D nr_gfps++; + new +=3D nr_gfps; =20 new->flags =3D gfp_flags; new->human_readable =3D strdup(str + 10); + if(!new->human_readable) + goto err_out; new->compact_str =3D 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); } =20 @@ -803,9 +806,12 @@ static int parse_gfp_flags(struct evsel *evsel, struct= perf_sample *sample, =20 trace_seq_destroy(&seq); return 0; +err_out: + trace_seq_destroy(&seq); + return -ENOMEM; } =20 -static int evsel__process_page_alloc_event(struct evsel *evsel, struct per= f_sample *sample) +static int evsel__process_page_alloc_event(struct perf_sample *sample) { u64 page; unsigned int order =3D perf_sample__intval(sample, "order"); @@ -845,7 +851,7 @@ static int evsel__process_page_alloc_event(struct evsel= *evsel, struct perf_samp return 0; } =20 - if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) + if (parse_gfp_flags(sample, gfp_flags) < 0) return -1; =20 callsite =3D find_callsite(sample); @@ -886,8 +892,7 @@ static int evsel__process_page_alloc_event(struct evsel= *evsel, struct perf_samp return 0; } =20 -static int evsel__process_page_free_event(struct evsel *evsel __maybe_unus= ed, - struct perf_sample *sample) +static int evsel__process_page_free_event(struct perf_sample *sample) { u64 page; unsigned int order =3D perf_sample__intval(sample, "order"); @@ -969,8 +974,7 @@ static bool perf_kmem__skip_sample(struct perf_sample *= sample) return false; } =20 -typedef int (*tracepoint_handler)(struct evsel *evsel, - struct perf_sample *sample); +typedef int (*tracepoint_handler)(struct perf_sample *sample); =20 static int process_sample_event(const struct perf_tool *tool __maybe_unuse= d, union perf_event *event, @@ -988,14 +992,16 @@ static int process_sample_event(const struct perf_too= l *tool __maybe_unused, return -1; } =20 - if (perf_kmem__skip_sample(sample)) + if (perf_kmem__skip_sample(sample)) { + thread__put(thread); return 0; + } =20 dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread__tid= (thread)); =20 if (evsel->handler !=3D NULL) { tracepoint_handler f =3D evsel->handler; - err =3D f(evsel, sample); + err =3D f(sample); } =20 thread__put(thread); --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09D1B3DB642 for ; Fri, 3 Apr 2026 20:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248869; cv=none; b=Y9lTfVe2zxJqqBOHme5KhfYIWWHJHTWvQgxCuKdhXGNmeN7amflStAbS7eli+OyWjSTs0A/YDfTLKX5CejWiGHYbopmJKWMqcerjh6R6dm97hlFGhu38WuGaDGwVW653db8Oy5ONf5YEI+1XRVNsJ5JLhG/y6gvOOi35R9qawcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248869; c=relaxed/simple; bh=lpM0C6lJcB996RrjMBNQGtbtoDVaUq3zMU+MBhdT7N0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mGMChiiYHY8GV/IUIr6/ekSGotbRHrpNMfyXJLWfto6dYXodtpVH1B9E8f3gdU9BieLNekQIyRiVojTPW6XRIkmJg7Zsc5ZbmXvBI0V5bLDs3Fr6WUztGhi01XqJaeXvwugcEI3e5LAWC6VRdsIfZYBowz0Iuo3Ag46ghoKAqsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fjZqONcI; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fjZqONcI" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2c895e7de52so7078070eec.0 for ; Fri, 03 Apr 2026 13:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248867; x=1775853667; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=eWQ1lOmIpYP7+WW9k0RFuajDdb9oYQGEBPEzhx3Ehpc=; b=fjZqONcISPcER4/aM+A6z+LidgsuOX/E11qEo2WZ2wEEYwWcz83eCirxz4597K0U2G QFFdhErkfvlBIw2DBjihdHzjMGuhheyemh0BZZjBHcTXv45jpiPSXKKt59/WAdm3BB+o Lui3xtryKbMR8czO7xxYwZO0iIzbr0LLGaX9BOlLYxW1KBgZgaZJ6IJ5QmB6QsFR3yD6 dGy4acVrPn2icDFhQVW1QDXfipyNWs9O5BeVN8pz56koW7eZqlI7MEUDUQHccLnoYKF8 aRC1jVm54VEFtKiInMbWRjIG0ZDKY7Ka0p3nDL6Slms8vb+eeHvEcCkqgLJ8y1NndTCG 8tAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248867; x=1775853667; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eWQ1lOmIpYP7+WW9k0RFuajDdb9oYQGEBPEzhx3Ehpc=; b=ONRi1AFsgkzMMq+uq8Ry8RB/31fT5ezp2EofhrLKhTY8YPA6emDtFOmJdEctKljKIb YzZTGWhL51CbM8IxLyv0Nwyh7QWJSqhoNwXwrbZKy1gp4flRaIq2LncTPMN/B/Z1TZND c8xYsn2o0tiHX6EVHuGrW8ue7Fo3QgZA+ZrEDvmLifTGW9xTprZ1EtdxVsDTyq1Xq+Q9 +fW2sRwVKy/FJlIgcEjyohxEiAerlVU63wG0dZL4f5daEYL4+zIM9GuwIrOyaoAQyMJu LyusWbzqPfNGAEWTKB8MLE27XGWyU/LwlanRouVS48tugZpz085AM1m+8WxnUFpcLuWq ZEWQ== X-Forwarded-Encrypted: i=1; AJvYcCW/r3t/nbmK/+bsOY17faSJ9GyT7YMWz6kntjtkZynGoRCpHto95apkHNG37dh1AzSiNS+PUrvPAcQ0X+c=@vger.kernel.org X-Gm-Message-State: AOJu0YzqgnduF69ZBrlDTBjTBS2x5irEnxOdTmdtaUqTxWkur1zzKT3M 6Oxl7QJSJ0QJwZmh2/lcvEnczIN9w1JzOOyw8vKVGxvc5/1z7DE44xfRP3wwKbdloulMkHSlEqy W2FhMIPmBSQ== X-Received: from dybfx3.prod.google.com ([2002:a05:7300:c383:b0:2c7:f617:6c6a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:dc88:b0:2c5:50fe:c782 with SMTP id 5a478bee46e88-2cbf9afd608mr2240608eec.3.1775248865804; Fri, 03 Apr 2026 13:41:05 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:10 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-19-irogers@google.com> Subject: [PATCH v5 18/25] perf kwork: Don't pass evsel with sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sample contains the evsel and so it is unnecessary to pass the evsel as well. Remove the evsel from struct kwork_class. Signed-off-by: Ian Rogers --- tools/perf/builtin-kwork.c | 74 +++++++++++++------------------------- tools/perf/util/kwork.h | 9 +++-- 2 files changed, 28 insertions(+), 55 deletions(-) diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 21cbeb233aac..fb6fe5115825 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -448,7 +448,6 @@ static int work_push_atom(struct perf_kwork *kwork, struct kwork_class *class, enum kwork_trace_type src_type, enum kwork_trace_type dst_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct kwork_work **ret_work, @@ -458,7 +457,7 @@ static int work_push_atom(struct perf_kwork *kwork, struct kwork_work *work, key; =20 BUG_ON(class->work_init =3D=3D NULL); - class->work_init(kwork, class, &key, src_type, evsel, sample, machine); + class->work_init(kwork, class, &key, src_type, sample, machine); =20 atom =3D atom_new(kwork, sample); if (atom =3D=3D NULL) @@ -507,7 +506,6 @@ static struct kwork_atom *work_pop_atom(struct perf_kwo= rk *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_kwo= rk *kwork, struct kwork_work *work, key; =20 BUG_ON(class->work_init =3D=3D NULL); - class->work_init(kwork, class, &key, src_type, evsel, sample, machine); + class->work_init(kwork, class, &key, src_type, sample, machine); =20 work =3D work_findnew(&class->work_root, &key, &kwork->cmp_id); if (ret_work !=3D NULL) @@ -599,18 +597,16 @@ static void report_update_exit_event(struct kwork_wor= k *work, =20 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); } =20 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 =3D NULL; =20 atom =3D work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (work =3D=3D NULL) return -1; @@ -654,18 +650,16 @@ static void latency_update_entry_event(struct kwork_w= ork *work, =20 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); } =20 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 =3D NULL; =20 atom =3D work_pop_atom(kwork, class, KWORK_TRACE_ENTRY, - KWORK_TRACE_RAISE, evsel, sample, + KWORK_TRACE_RAISE, sample, machine, &work); if (work =3D=3D NULL) return -1; @@ -812,18 +806,16 @@ static void timehist_print_event(struct perf_kwork *k= work, =20 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); } =20 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 *kwor= k, struct kwork_work *work =3D NULL; =20 ret =3D 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 *kwor= k, =20 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, } =20 atom =3D work_pop_atom(kwork, class, KWORK_TRACE_EXIT, - KWORK_TRACE_ENTRY, evsel, sample, + KWORK_TRACE_ENTRY, sample, machine, &work); if (work =3D=3D NULL) { ret =3D -1; @@ -895,18 +886,16 @@ static void top_update_runtime(struct kwork_work *wor= k, =20 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); } =20 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; =20 atom =3D 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, =20 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 *kw= ork, struct kwork_work *work; =20 atom =3D 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); } =20 - return top_entry_event(kwork, class, evsel, sample, machine); + return top_entry_event(kwork, class, sample, machine); } =20 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 stru= ct perf_tool *tool, =20 if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_irq, - evsel, sample, machine); + sample, machine); return 0; } =20 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, =20 if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_irq, - evsel, sample, machine); + sample, machine); return 0; } =20 @@ -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 =3D { =20 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, =20 if (kwork->tp_handler->raise_event) return kwork->tp_handler->raise_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); =20 return 0; } =20 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, =20 if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); =20 return 0; } =20 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 pe= rf_tool *tool, =20 if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_softirq, - evsel, sample, machine); + sample, machine); =20 return 0; } @@ -1133,7 +1115,6 @@ static void softirq_work_init(struct perf_kwork *kwor= k, 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 *kwor= k, } else { num =3D perf_sample__intval(sample, "vec"); work->id =3D num; - work->name =3D evsel__softirq_name(evsel, num); + work->name =3D evsel__softirq_name(sample->evsel, num); } } =20 @@ -1169,7 +1150,6 @@ static struct kwork_class kwork_softirq =3D { =20 static struct kwork_class kwork_workqueue; static int process_workqueue_activate_work_event(const struct perf_tool *t= ool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1177,13 +1157,12 @@ static int process_workqueue_activate_work_event(co= nst struct perf_tool *tool, =20 if (kwork->tp_handler->raise_event) return kwork->tp_handler->raise_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); =20 return 0; } =20 static int process_workqueue_execute_start_event(const struct perf_tool *t= ool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1191,13 +1170,12 @@ static int process_workqueue_execute_start_event(co= nst struct perf_tool *tool, =20 if (kwork->tp_handler->entry_event) return kwork->tp_handler->entry_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); =20 return 0; } =20 static int process_workqueue_execute_end_event(const struct perf_tool *too= l, - 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, =20 if (kwork->tp_handler->exit_event) return kwork->tp_handler->exit_event(kwork, &kwork_workqueue, - evsel, sample, machine); + sample, machine); =20 return 0; } @@ -1233,7 +1211,6 @@ static void workqueue_work_init(struct perf_kwork *kw= ork __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 =3D { =20 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 pe= rf_tool *tool, =20 if (kwork->tp_handler->sched_switch_event) return kwork->tp_handler->sched_switch_event(kwork, &kwork_sched, - evsel, sample, machine); + sample, machine); return 0; } =20 @@ -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 *kwor= k) } =20 typedef int (*tracepoint_handler)(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); =20 @@ -1961,7 +1935,7 @@ static int perf_kwork__process_tracepoint_sample(cons= t struct perf_tool *tool, if (evsel->handler !=3D NULL) { tracepoint_handler f =3D evsel->handler; =20 - err =3D f(tool, evsel, sample, machine); + err =3D f(tool, sample, machine); } =20 return err; diff --git a/tools/perf/util/kwork.h b/tools/perf/util/kwork.h index db00269b73f2..abf637d44794 100644 --- a/tools/perf/util/kwork.h +++ b/tools/perf/util/kwork.h @@ -157,7 +157,6 @@ struct kwork_class { struct kwork_class *class, struct kwork_work *work, enum kwork_trace_type src_type, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); =20 @@ -167,19 +166,19 @@ struct kwork_class { =20 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); =20 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); =20 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); =20 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); }; =20 --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04B3F3DBD4E for ; Fri, 3 Apr 2026 20:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248870; cv=none; b=u8Y0dyTSzBNal2kHJZWogt6FKjKn7hOMq1cTd4w87oB99P5d9qod6w7yJ+EcVMAKHkSBxSr9GZax1uuYn2GOzPBj+6WVb1FTaOI+s1E5dcFyb7Cu6g3JB1pw8cMbxjZFIYZcq4M//fXEUrNOD26ePqXdx+gD8/WcO+PfnGyNUFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248870; c=relaxed/simple; bh=R1eRO03wAt1dp60VJ664aBvcIUYq5ratVe3cYdnev7w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HqeTp5jPY2aGakXh9lik5IL2gHVF0VGN0Kqf8yj443mFimYhTincfeH/s+7fYBn5g7aKvRDMJnvtXGrw+c1WRIZtmhB1wv0Rie/lB2+U6Z5isA1flojRacWRZJxkaZ8dsObB3NlxJjCEpOdNVGOo6LFkkI0fhlB6maPp4iJORIA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pRGxyuBx; arc=none smtp.client-ip=74.125.82.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pRGxyuBx" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-126e8ee6227so3586809c88.0 for ; Fri, 03 Apr 2026 13:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248868; x=1775853668; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5k86aypFt67mnc4wsBRuul2tE1ESndRC/oJkXBZFkzg=; b=pRGxyuBxyFFu2iWepsKhp5auUyXOtthjJIZG72beEyx8jarkFd8pk6E40ZTFtKl6bZ fSGn2GEyNFuX9k6CbejmzFN0jTriCBa2As9NssKf6ttadydy1QWpg0rn+yWrk7GYsKsg 1d7B9Q2j6h22sfNuZFq0q7JgIkFXasQQOPJzZs86pxRM3q4iVnoalTN5S+XCOlNf2NZ2 CjVDvm6n5UTLtJ/rvWwruEFS5VpCqq9+r2ULY8f3nHGj048Fhq5TwapHxlTMTb6wGgz/ gCBRZ9G5ae5ZyLB0Ln224OGdT/ELh1x23NmKZs6MFkCTHGgJXjXfGPSMYy6J7W/BNc2k jEXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248868; x=1775853668; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5k86aypFt67mnc4wsBRuul2tE1ESndRC/oJkXBZFkzg=; b=sPBWpgYXr/jWPWRLC4bSdTNyHTl6TTbiHIWvOiBKhtz6VF7diYYOPi6Mm6avXz1fwm 9t6r29UwWlxwOEndnGJCh3crwVm6PjPoJQpTjd8A8GOxREeUCpZIKU8lB0s7yqTbH1GI jKhKUpViy/jcPwIVQ0SkXbxGOQQveGwGkdOCb7E7VnPLyTtSwK4Vwk6k3kHTd9WQGsIS RiupDM3RPWb+1z/klXnQANSH9VwBY8UY3xZjULx6jWkSTNeKcbG+u00nazqvNSOtNsRJ Vh+AoFwfo22JNg1LBDIkjwTMvHhibbbrp7lfnelQMUo1ECwWSOIcGDziu+qL642t4BBA IHnQ== X-Forwarded-Encrypted: i=1; AJvYcCXUXL7HLkoWZUyi/XvTNyhEsegkoaz9jUH+5e2NTCreeqMf2LvxaiZrBJIufjrYYLx7DM/k6VhXybFITpI=@vger.kernel.org X-Gm-Message-State: AOJu0Yyd82BXMVc0H9+EUrsR7GZ/WTmZZlkMlNi6rcNTbn8Pt74izCWx qtNAi7SfdJ68ERpV6tOcY8b8+B+PFEUHj9GmKJNypDMinET8tgcxfUffs8JG3aO1c6gPZhAMvFJ 5dSSUBjTLqw== X-Received: from dled6-n1.prod.google.com ([2002:a05:701b:42c6:10b0:12b:f977:8848]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:212:b0:123:3500:b688 with SMTP id a92af1059eb24-12bfb73ef52mr1685070c88.19.1775248867989; Fri, 03 Apr 2026 13:41:07 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:11 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-20-irogers@google.com> Subject: [PATCH v5 19/25] perf sched: Don't pass evsel with sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sample contains the evsel and so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers --- tools/perf/builtin-sched.c | 92 ++++++++++++++------------------------ 1 file changed, 34 insertions(+), 58 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index b6271a5ec8de..fdfa2fec0fe6 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -129,21 +129,20 @@ typedef int (*sort_fn_t)(struct work_atoms *, struct = work_atoms *); struct perf_sched; =20 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); =20 - 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); =20 - 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); =20 /* PERF_RECORD_FORK event, not sched_process_fork tracepoint */ int (*fork_event)(struct perf_sched *sched, union perf_event *event, struct machine *machine); =20 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) =20 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 =3D perf_sample__strval(sample, "comm"); @@ -834,7 +833,7 @@ replay_wakeup_event(struct perf_sched *sched, struct task_desc *waker, *wakee; =20 if (verbose > 0) { - printf("sched_wakeup event %p\n", evsel); + printf("sched_wakeup event %p\n", sample->evsel); =20 printf(" ... pid %d woke up %s/%d\n", sample->tid, comm, pid); } @@ -847,7 +846,6 @@ replay_wakeup_event(struct perf_sched *sched, } =20 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; =20 if (verbose > 0) - printf("sched_switch event %p\n", evsel); + printf("sched_switch event %p\n", sample->evsel); =20 if (cpu >=3D MAX_CPUS || cpu < 0) return 0; @@ -1134,7 +1132,6 @@ static void free_work_atoms(struct work_atoms *atoms) } =20 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 *sc= hed, } =20 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 *s= ched, } =20 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 *sc= hed, } =20 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) } =20 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 =3D container_of(tool, struct perf_sched, tool); =20 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); =20 return 0; } =20 static int process_sched_wakeup_ignore(const struct perf_tool *tool __mayb= e_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, } } =20 -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 =3D perf_sample__intval(sample, "next_pid"); const u32 prev_pid =3D perf_sample__intval(sample, "prev_pid"); @@ -1791,7 +1783,6 @@ static int map_switch_event(struct perf_sched *sched,= struct evsel *evsel __mayb } =20 static int process_sched_switch_event(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -1815,21 +1806,20 @@ static int process_sched_switch_event(const struct = perf_tool *tool, } =20 if (sched->tp_handler->switch_event) - err =3D sched->tp_handler->switch_event(sched, evsel, sample, machine); + err =3D sched->tp_handler->switch_event(sched, sample, machine); =20 sched->curr_pid[this_cpu] =3D next_pid; return err; } =20 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 =3D container_of(tool, struct perf_sched, tool); =20 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); =20 return 0; } @@ -1852,20 +1842,18 @@ static int perf_sched__process_fork_event(const str= uct perf_tool *tool, } =20 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 =3D container_of(tool, struct perf_sched, tool); =20 if (sched->tp_handler->migrate_task_event) - return sched->tp_handler->migrate_task_event(sched, evsel, sample, machi= ne); + return sched->tp_handler->migrate_task_event(sched, sample, machine); =20 return 0; } =20 typedef int (*tracepoint_handler)(const struct perf_tool *tool, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); =20 @@ -1879,7 +1867,7 @@ static int perf_sched__process_tracepoint_sample(cons= t struct perf_tool *tool __ =20 if (evsel->handler !=3D NULL) { tracepoint_handler f =3D evsel->handler; - err =3D f(tool, evsel, sample, machine); + err =3D f(tool, sample, machine); } =20 return err; @@ -2318,11 +2306,10 @@ static void timehist_update_runtime_stats(struct th= read_runtime *r, r->total_pre_mig_time +=3D r->dt_pre_mig; } =20 -static bool is_idle_sample(struct perf_sample *sample, - struct evsel *evsel) +static bool is_idle_sample(struct perf_sample *sample) { /* pid 0 =3D=3D swapper =3D=3D 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") =3D=3D 0; =20 return sample->pid =3D=3D 0; @@ -2504,12 +2491,11 @@ static void save_idle_callchain(struct perf_sched *= sched, =20 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; =20 - if (is_idle_sample(sample, evsel)) { + if (is_idle_sample(sample)) { thread =3D get_idle_thread(sample->cpu); if (thread =3D=3D NULL) pr_err("Failed to get idle thread for cpu %d.\n", sample->cpu); @@ -2552,7 +2538,6 @@ static struct thread *timehist_get_thread(struct perf= _sched *sched, =20 static bool timehist_skip_sample(struct perf_sched *sched, struct thread *thread, - struct evsel *evsel, struct perf_sample *sample) { bool rc =3D false; @@ -2574,7 +2559,7 @@ static bool timehist_skip_sample(struct perf_sched *s= ched, tr =3D thread__get_runtime(thread); if (tr && tr->prio !=3D -1) prio =3D tr->prio; - else if (evsel__name_is(evsel, "sched:sched_switch")) + else if (evsel__name_is(sample->evsel, "sched:sched_switch")) prio =3D perf_sample__intval(sample, "prev_prio"); =20 if (prio !=3D -1 && !test_bit(prio, sched->prio_bitmap)) { @@ -2584,7 +2569,7 @@ static bool timehist_skip_sample(struct perf_sched *s= ched, } =20 if (sched->idle_hist) { - if (!evsel__name_is(evsel, "sched:sched_switch")) + if (!evsel__name_is(sample->evsel, "sched:sched_switch")) rc =3D true; else if (perf_sample__intval(sample, "prev_pid") !=3D 0 && perf_sample__intval(sample, "next_pid") !=3D 0) @@ -2595,7 +2580,6 @@ static bool timehist_skip_sample(struct perf_sched *s= ched, } =20 static void timehist_print_wakeup_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct thread *awakened) @@ -2608,8 +2592,8 @@ static void timehist_print_wakeup_event(struct perf_s= ched *sched, return; =20 /* show wakeup unless both awakee and awaker are filtered */ - if (timehist_skip_sample(sched, thread, evsel, sample) && - timehist_skip_sample(sched, awakened, evsel, sample)) { + if (timehist_skip_sample(sched, thread, sample) && + timehist_skip_sample(sched, awakened, sample)) { thread__put(thread); return; } @@ -2633,7 +2617,6 @@ static void timehist_print_wakeup_event(struct perf_s= ched *sched, =20 static int timehist_sched_wakeup_ignore(const struct perf_tool *tool __may= be_unused, union perf_event *event __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused) { @@ -2642,7 +2625,6 @@ static int timehist_sched_wakeup_ignore(const struct = perf_tool *tool __maybe_unu =20 static int timehist_sched_wakeup_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2668,14 +2650,13 @@ static int timehist_sched_wakeup_event(const struct= perf_tool *tool, /* show wakeups if requested */ if (sched->show_wakeups && !perf_time__skip_sample(&sched->ptime, sample->time)) - timehist_print_wakeup_event(sched, evsel, sample, machine, thread); + timehist_print_wakeup_event(sched, sample, machine, thread); =20 thread__put(thread); return 0; } =20 static void timehist_print_migration_event(struct perf_sched *sched, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine, struct thread *migrated) @@ -2696,8 +2677,8 @@ static void timehist_print_migration_event(struct per= f_sched *sched, if (thread =3D=3D NULL) return; =20 - if (timehist_skip_sample(sched, thread, evsel, sample) && - timehist_skip_sample(sched, migrated, evsel, sample)) { + if (timehist_skip_sample(sched, thread, sample) && + timehist_skip_sample(sched, migrated, sample)) { thread__put(thread); return; } @@ -2731,7 +2712,6 @@ static void timehist_print_migration_event(struct per= f_sched *sched, =20 static int timehist_migrate_task_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2756,8 +2736,7 @@ static int timehist_migrate_task_event(const struct p= erf_tool *tool, =20 /* 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); =20 @@ -2789,7 +2768,6 @@ static void timehist_update_task_prio(struct perf_sam= ple *sample, =20 static int timehist_sched_change_event(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine) { @@ -2813,13 +2791,13 @@ static int timehist_sched_change_event(const struct= perf_tool *tool, if (sched->show_prio || sched->prio_str) timehist_update_task_prio(sample, machine); =20 - thread =3D timehist_get_thread(sched, sample, machine, evsel); + thread =3D timehist_get_thread(sched, sample, machine); if (thread =3D=3D NULL) { rc =3D -1; goto out; } =20 - if (timehist_skip_sample(sched, thread, evsel, sample)) + if (timehist_skip_sample(sched, thread, sample)) goto out; =20 tr =3D thread__get_runtime(thread); @@ -2828,7 +2806,7 @@ static int timehist_sched_change_event(const struct p= erf_tool *tool, goto out; } =20 - tprev =3D evsel__get_time(evsel, sample->cpu); + tprev =3D evsel__get_time(sample->evsel, sample->cpu); =20 /* * If start time given: @@ -2918,7 +2896,7 @@ static int timehist_sched_change_event(const struct p= erf_tool *tool, tr->migrated =3D 0; } =20 - evsel__save_time(evsel, sample->time, sample->cpu); + evsel__save_time(sample->evsel, sample->time, sample->cpu); =20 thread__put(thread); addr_location__exit(&al); @@ -2927,11 +2905,10 @@ static int timehist_sched_change_event(const struct= perf_tool *tool, =20 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); } =20 static int process_lost(const struct perf_tool *tool __maybe_unused, @@ -3179,7 +3156,6 @@ static void timehist_print_summary(struct perf_sched = *sched, =20 typedef int (*sched_handler)(const struct perf_tool *tool, union perf_event *event, - struct evsel *evsel, struct perf_sample *sample, struct machine *machine); =20 @@ -3201,7 +3177,7 @@ static int perf_timehist__process_sample(const struct= perf_tool *tool, if (evsel->handler !=3D NULL) { sched_handler f =3D evsel->handler; =20 - err =3D f(tool, event, evsel, sample, machine); + err =3D f(tool, event, sample, machine); } =20 return err; --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CECC23DBD66 for ; Fri, 3 Apr 2026 20:41:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248874; cv=none; b=alY0WpA503f5k37HTF2umAnXaKgorGfIqAPtURTZRCgCzLk8z8QE4X5BiDDKzj4cy4eVPu48mcvRxXvDs0GGdykf/6yvqpfzREaNPYcvXTONW9NbqdelEJCkaTaya1TRHvI3t4S5Vgl8Wwi+0fQANK3/2ADKB/pyLfgi79B8XdY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248874; c=relaxed/simple; bh=gaaj7mqTj9irdR4S7xoXLu9VEiPSaerqzbyXPHicpOk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=k5jXNnyO/xDRkT/iksX90UP+ND1O53SIbemgeYwrL6AE7qcsnhdEeSuxz83WPxV+mEpxq6Q86552AvS1qtbuKN1+cNW9Ly41NAmQU5bJl7DW4cPMvE6JyUkRCoOxSO7LCSLu2Ggr7wn8R8YOyrZJ8VhkBZ4gJkdS/kURPD3a3ic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=v68Flh7n; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="v68Flh7n" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2bdf6fe90a9so3086944eec.1 for ; Fri, 03 Apr 2026 13:41:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248872; x=1775853672; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Q/+euWmx5IbaoRi1V0BAsO1Eoicg/byu+jgqEgqtKYw=; b=v68Flh7nOLvmEwoelDM13kT72npdO+eW/fhywk0OHMXMQkL4d7lt+6MeV3zglOOXLC DX4ScHMnltCi8fIboAvC7IcgQkMzpicovtzGhySwukDnJRVoj3zpcDkfrXroYC0djTAQ 2dUHL7f9I4Vd0T1AwuV5ZO1IF6WCIE+4161C+P4VxKu0zZTUGsMI79PYy0fIH4E4ghz8 XUtmA0iT3TRHvRO+11daNOGWy0FCLXpelYUTyR9ur0yPr847uG7d8AiJsXSvjrfQJ978 sQztj8SRLRf9mKoiz2f+397RttDvrFG3+liNPUwb5dgYRBirLRAMDU8zuNXw/THkVe0T cL1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248872; x=1775853672; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Q/+euWmx5IbaoRi1V0BAsO1Eoicg/byu+jgqEgqtKYw=; b=lhn1yQZhNEbxP3Elnklepq19rwgIDCNt6tV9rCOSbCIAMff6GQLSoFd0K7ElOQA0Fl jpR/dHBvNhbEaZdJ0DaHoPGhaNR+10p1V+qqD8SkQoGrPbnKDR3P8Boha/B4WYbD3b+x G5EANm+2bkKXHunLnaTXgHrSLdxDWso4rT/3Ax62RmBmUjrXPGRd8AEx8VBU6f5VtwXf XwGMUqyvMFit8aRTauAYVaKEcwlRz2wPMNClhWDgL2Crzdlj2t4VJa7P4UDhkmO+huAV O8K7FB41MIjaoJTa4a0tJfx7t7CYLKGONzpZxvVHbnKB28y0mqTTSiOtFcu8q4ojfwB6 7JzA== X-Forwarded-Encrypted: i=1; AJvYcCX+LC3Oa51YMjWp5By8Nz8832yxJvvrUx9DKb4d34/x97fcMEAX1zSsll2+JVFbC2mv25hNNB77YHIS69I=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/fpfg/WOyxNVV+D9yOyqkF3EPLbdtO4aHklJnr7ThQ57eZOSJ eoH5ygIbTX5GNyYZ/J6RJVGOPHU6yrd05WJtCr+DiNN3AcI+CF75BaqTYXhEd2amrxbxjBFjzX1 IFA4YEp85Ng== X-Received: from dyw23.prod.google.com ([2002:a05:7300:8817:b0:2c8:fc92:6e72]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:2315:b0:2c8:1d56:340c with SMTP id 5a478bee46e88-2cbfba8d9femr1972599eec.23.1775248871533; Fri, 03 Apr 2026 13:41:11 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:12 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-21-irogers@google.com> Subject: [PATCH v5 20/25] perf timechart: Don't pass evsel with sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sample contains the evsel and so it is unnecessary to pass the evsel as well. Add missing backtrace argument to tracepoint_handler functions and mark them unused. Fix missing free from cat_backtrace, which requires copies of the backtrace being made in functions that save it. Signed-off-by: Ian Rogers --- tools/perf/builtin-timechart.c | 81 ++++++++++++++++------------------ 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 782ede4258a2..0db2a9bd5b91 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -299,7 +299,7 @@ static void pid_put_sample(struct timechart *tchart, in= t pid, int type, sample->type =3D type; sample->next =3D c->samples; sample->cpu =3D cpu; - sample->backtrace =3D backtrace; + sample->backtrace =3D backtrace ? strdup(backtrace) : NULL; c->samples =3D sample; =20 if (sample->type =3D=3D TYPE_RUNNING && end > start && start > 0) { @@ -433,7 +433,7 @@ static void sched_wakeup(struct timechart *tchart, int = cpu, u64 timestamp, =20 we->time =3D timestamp; we->waker =3D waker; - we->backtrace =3D backtrace; + we->backtrace =3D backtrace ? strdup(backtrace) : NULL; =20 if ((flags & TRACE_FLAG_HARDIRQ) || (flags & TRACE_FLAG_SOFTIRQ)) we->waker =3D -1; @@ -489,9 +489,9 @@ static void sched_switch(struct timechart *tchart, int = cpu, u64 timestamp, } } =20 -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; @@ -544,8 +544,10 @@ static const char *cat_backtrace(union perf_event *eve= nt, * It seems the callchain is corrupted. * Discard all. */ - zfree(&p); - goto exit; + addr_location__exit(&al); + fclose(f); + free(p); + return NULL; } continue; } @@ -567,7 +569,6 @@ static const char *cat_backtrace(union perf_event *even= t, } =20 typedef int (*tracepoint_handler)(struct timechart *tchart, - struct evsel *evsel, struct perf_sample *sample, const char *backtrace); =20 @@ -578,6 +579,7 @@ static int process_sample_event(const struct perf_tool = *tool, { struct timechart *tchart =3D container_of(tool, struct timechart, tool); struct evsel *evsel =3D sample->evsel; + int ret =3D 0; =20 if (evsel->core.attr.sample_type & PERF_SAMPLE_TIME) { if (!tchart->first_time || tchart->first_time > sample->time) @@ -588,16 +590,17 @@ static int process_sample_event(const struct perf_too= l *tool, =20 if (evsel->handler !=3D NULL) { tracepoint_handler f =3D evsel->handler; - return f(tchart, evsel, sample, - cat_backtrace(event, sample, machine)); + char *backtrace =3D cat_backtrace(event, sample, machine); + + ret =3D f(tchart, sample, backtrace); + free(backtrace); } =20 - return 0; + return ret; } =20 static int process_sample_cpu_idle(struct timechart *tchart __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -617,7 +620,6 @@ process_sample_cpu_idle(struct timechart *tchart __mayb= e_unused, =20 static int process_sample_cpu_frequency(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -634,7 +636,6 @@ process_sample_cpu_frequency(struct timechart *tchart, =20 static int process_sample_sched_wakeup(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { @@ -648,7 +649,6 @@ process_sample_sched_wakeup(struct timechart *tchart, =20 static int process_sample_sched_switch(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace) { @@ -664,7 +664,6 @@ process_sample_sched_switch(struct timechart *tchart, #ifdef SUPPORT_OLD_POWER_EVENTS static int process_sample_power_start(struct timechart *tchart __maybe_unused, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -681,7 +680,6 @@ process_sample_power_start(struct timechart *tchart __m= aybe_unused, =20 static int process_sample_power_end(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -691,7 +689,6 @@ process_sample_power_end(struct timechart *tchart, =20 static int process_sample_power_frequency(struct timechart *tchart, - struct evsel *evsel __maybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { @@ -865,8 +862,8 @@ static int pid_end_io_sample(struct timechart *tchart, = int pid, int type, =20 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 =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ, @@ -875,8 +872,8 @@ process_enter_read(struct timechart *tchart, =20 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 =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_READ, @@ -885,8 +882,8 @@ process_exit_read(struct timechart *tchart, =20 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 =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE, @@ -895,8 +892,8 @@ process_enter_write(struct timechart *tchart, =20 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 =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_WRITE, @@ -905,8 +902,8 @@ process_exit_write(struct timechart *tchart, =20 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 =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC, @@ -915,8 +912,8 @@ process_enter_sync(struct timechart *tchart, =20 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 =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_SYNC, @@ -925,8 +922,8 @@ process_exit_sync(struct timechart *tchart, =20 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 =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX, @@ -935,8 +932,8 @@ process_enter_tx(struct timechart *tchart, =20 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 =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_TX, @@ -945,8 +942,8 @@ process_exit_tx(struct timechart *tchart, =20 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 =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX, @@ -955,8 +952,8 @@ process_enter_rx(struct timechart *tchart, =20 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 =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_RX, @@ -965,8 +962,8 @@ process_exit_rx(struct timechart *tchart, =20 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 =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL, @@ -975,8 +972,8 @@ process_enter_poll(struct timechart *tchart, =20 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 =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_POLL, --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECA093D813D for ; Fri, 3 Apr 2026 20:41:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248876; cv=none; b=jI/8SEXECvpcspwEYvyYVq43iBEQ5YUX2yqAvFarJKlQrXYJicq9ns6TAu0kWJNn7zJm62PNu/XKK++7/EiI4+wQ7tv3S6AT29myGx5zC0uYlM4dO4XbFkSrY4OrjK0fCOYGI6sm3mvUIsXxvZQNTCJm2s9nmc/4iuL/60hzj78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248876; c=relaxed/simple; bh=DMva335Co4SJ5T4aexBmgvFAwe5lZa5RgB/TZ0G1IzE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rI/q8Z+Snd+Fxctd8PULiN8RNGMuE3raBvx8N3qtuzXDp6jXoQqCLrS6jv38eHzaiiNWqc5q8ylBZkYMlh4pKi44jm8SrLxOOq6TaThmakpwwK35VgXAHRK2wZ3W1xTqsHexTiZE2XirB1lrf3AunUD0s6247VX0q/F9ksoU5Ic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TcnZpSG9; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TcnZpSG9" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2bdd327d970so1609087eec.1 for ; Fri, 03 Apr 2026 13:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248874; x=1775853674; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LWh26oU1nkbVHiu8Aju0MEDFTjaq7PVSE7AultiAh+U=; b=TcnZpSG9/3yePh52mWy4ERbDKjUHRMtVq0OJwsrskPTzXz7KHCxK4R67ILBq+UQJ+i wjHg5cvrj25QkXSIwBhMclOg8xyirEUzJlP7N0kuPf0GX7JDK0Jc/orJdJSfb6D/Q2e2 0NU7mvQNPgM94LEtOoVuRej4YfnI6PxkEAqj2GlrkXTr+BuDdrW0t9dQaMh5PcKfyR0j psP/ymleY9me7PIwQGTKA9YLRIuU87jULXajz12mbkpJJkh+gFeht+uXLqXXoSYvMeSP wzQ2Mys9ljfyuDX9FORIDb9u0N7yzVHu9FYuVfJKfMAV17gcZg0xTUW9RbA+F/TLKMf7 7w3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248874; x=1775853674; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LWh26oU1nkbVHiu8Aju0MEDFTjaq7PVSE7AultiAh+U=; b=UgasoJ+ZKi2VdOwUB4z2rZj926qMmXz9JPR+fE9SRcZtmd+jKxupl3cHpKIryThOpm c8d2AzDInpeZDMsxTlG5Q8clO5orOoPc+XdgZFUY+9kgV7wUTIau13uSIZlo3ucwCg+h l6c4yJFrviwgUw6bDpuFo53Wtypp4L9V9EHjiPu8WIWRvMus1htEPBIvuh2zehUwntA1 tp0O5U5bZ2s+uPjmqulqzHVYvCalzznNe4Whm0/hQAZUJ7NPO1+S2oT7tB+zV7c5XC2J bXbsW9kHWhkcjEby96IDYMxSx3J32XYe2NKH7rYw+pig6KI56mUY9A2q7ZvqW+1cWXqT Y54A== X-Forwarded-Encrypted: i=1; AJvYcCVklBrA+xRyKPz1vlp1OkZ8vyqFtaz7WA83eI9nsWz9m4uPE7zmggTSQ065JtnvkWj51Qww25LCagYKAuc=@vger.kernel.org X-Gm-Message-State: AOJu0YwzyG2FCp/v5I+k4WGaWjjpYjxffPcSQNAN1fADhytnE9mvrEkj G0Jp/+KBQgwMiELDxUo1jlQV99gZxACxLclTVfY+yo7WJO1KgHjzNZt9WUGj3xOSUM5cnwQEE81 fHGFQBzD3eQ== X-Received: from dlah11.prod.google.com ([2002:a05:701b:260b:b0:127:82fc:dd48]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:1609:b0:123:3301:a718 with SMTP id a92af1059eb24-12bfac01230mr1754668c88.1.1775248873796; Fri, 03 Apr 2026 13:41:13 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:13 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-22-irogers@google.com> Subject: [PATCH v5 21/25] perf trace: Don't pass evsel with sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sample contains the evsel and so it is unnecessary to pass the evsel as well. In trace__handle_event try to use the evsel from the sample to avoid recomputation. Signed-off-by: Ian Rogers --- tools/perf/builtin-trace.c | 51 ++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 161e2e62bf1e..d97d0b1b3762 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2580,7 +2580,7 @@ static struct syscall *trace__find_syscall(struct tra= ce *trace, int e_machine, i return sc; } =20 -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); =20 @@ -2775,10 +2775,11 @@ static void *syscall__augmented_args(struct syscall= *sc, struct perf_sample *sam return NULL; } =20 -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 =3D sample->evsel; char *msg; void *args; int printed =3D 0; @@ -2921,10 +2922,11 @@ static int trace__fprintf_callchain(struct trace *t= race, struct perf_sample *sam return sample__fprintf_callchain(sample, 38, print_opts, get_tls_callchai= n_cursor(), symbol_conf.bt_stop_list, trace->output); } =20 -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 =3D sample->evsel; long ret; u64 duration =3D 0; bool duration_calculated =3D false; @@ -3059,7 +3061,7 @@ errno_print: { return err; } =20 -static int trace__vfs_getname(struct trace *trace, struct evsel *evsel __m= aybe_unused, +static int trace__vfs_getname(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3120,7 +3122,7 @@ static int trace__vfs_getname(struct trace *trace, st= ruct evsel *evsel __maybe_u return 0; } =20 -static int trace__sched_stat_runtime(struct trace *trace, struct evsel *ev= sel, +static int trace__sched_stat_runtime(struct trace *trace, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3142,7 +3144,7 @@ static int trace__sched_stat_runtime(struct trace *tr= ace, struct evsel *evsel, =20 out_dump: fprintf(trace->output, "%s: comm=3D%s,pid=3D%u,runtime=3D%" PRIu64 ",vrun= time=3D%" PRIu64 ")\n", - evsel->name, + sample->evsel->name, perf_sample__strval(sample, "comm"), (pid_t)perf_sample__intval(sample, "pid"), runtime, @@ -3253,10 +3255,11 @@ static size_t trace__fprintf_tp_fields(struct trace= *trace, struct perf_sample * return fprintf(trace->output, "%.*s", (int)printed, bf); } =20 -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 =3D sample->evsel; struct thread *thread; int callchain_ret =3D 0; =20 @@ -3362,7 +3365,6 @@ static void print_location(FILE *f, struct perf_sampl= e *sample, } =20 static int trace__pgfault(struct trace *trace, - struct evsel *evsel, union perf_event *event __maybe_unused, struct perf_sample *sample) { @@ -3391,7 +3393,7 @@ static int trace__pgfault(struct trace *trace, if (ttrace =3D=3D NULL) goto out_put; =20 - if (evsel->core.attr.config =3D=3D PERF_COUNT_SW_PAGE_FAULTS_MAJ) { + if (sample->evsel->core.attr.config =3D=3D PERF_COUNT_SW_PAGE_FAULTS_MAJ)= { ttrace->pfmaj++; trace->pfmaj++; } else { @@ -3407,7 +3409,7 @@ static int trace__pgfault(struct trace *trace, trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->ou= tput); =20 fprintf(trace->output, "%sfault [", - evsel->core.attr.config =3D=3D PERF_COUNT_SW_PAGE_FAULTS_MAJ ? + sample->evsel->core.attr.config =3D=3D PERF_COUNT_SW_PAGE_FAULTS_MAJ ? "maj" : "min"); =20 print_location(trace->output, sample, &al, false, true); @@ -3432,7 +3434,8 @@ static int trace__pgfault(struct trace *trace, if (callchain_ret > 0) trace__fprintf_callchain(trace, sample); else if (callchain_ret < 0) - pr_err("Problem processing %s callchain, skipping...\n", evsel__name(evs= el)); + pr_err("Problem processing %s callchain, skipping...\n", + evsel__name(sample->evsel)); =20 ++trace->nr_events_printed; out: @@ -3444,7 +3447,6 @@ static int trace__pgfault(struct trace *trace, } =20 static void trace__set_base_time(struct trace *trace, - struct evsel *evsel, struct perf_sample *sample) { /* @@ -3456,7 +3458,7 @@ static void trace__set_base_time(struct trace *trace, * appears in our event stream (vfs_getname comes to mind). */ if (trace->base_time =3D=3D 0 && !trace->full_time && - (evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) + (sample->evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) trace->base_time =3D sample->time; } =20 @@ -3476,11 +3478,11 @@ static int trace__process_sample(const struct perf_= tool *tool, if (thread && thread__is_filtered(thread)) goto out; =20 - trace__set_base_time(trace, evsel, sample); + trace__set_base_time(trace, sample); =20 if (handler) { ++trace->nr_events; - handler(trace, evsel, event, sample); + handler(trace, event, sample); } out: thread__put(thread); @@ -3622,32 +3624,33 @@ static void evlist__free_syscall_tp_fields(struct e= vlist *evlist) static void trace__handle_event(struct trace *trace, union perf_event *eve= nt, struct perf_sample *sample) { const u32 type =3D event->header.type; - struct evsel *evsel; =20 if (type !=3D PERF_RECORD_SAMPLE) { trace__process_event(trace, trace->host, event, sample); return; } =20 - evsel =3D evlist__id2evsel(trace->evlist, sample->id); - if (evsel =3D=3D NULL) { + if (sample->evsel =3D=3D NULL) + sample->evsel =3D evlist__id2evsel(trace->evlist, sample->id); + + if (sample->evsel =3D=3D NULL) { fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sampl= e->id); return; } =20 - if (evswitch__discard(&trace->evswitch, evsel)) + if (evswitch__discard(&trace->evswitch, sample->evsel)) return; =20 - trace__set_base_time(trace, evsel, sample); + trace__set_base_time(trace, sample); =20 - if (evsel->core.attr.type =3D=3D PERF_TYPE_TRACEPOINT && + if (sample->evsel->core.attr.type =3D=3D PERF_TYPE_TRACEPOINT && sample->raw_data =3D=3D NULL) { fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, r= aw_size=3D%d, skipping...\n", - evsel__name(evsel), sample->tid, + evsel__name(sample->evsel), sample->tid, sample->cpu, sample->raw_size); } else { - tracepoint_handler handler =3D evsel->handler; - handler(trace, evsel, event, sample); + tracepoint_handler handler =3D sample->evsel->handler; + handler(trace, event, sample); } =20 if (trace->nr_events_printed >=3D trace->max_events && trace->max_events = !=3D ULONG_MAX) --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D50D03DC4AA for ; Fri, 3 Apr 2026 20:41:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248878; cv=none; b=UOwujyPSCJ6iqCmVmmtZtoS+fK1yyUZg2DAdIHp9CbzUkUUdL8eLcSPuL/M7W/Y3WEUjwaWhQqv+3dxDUecCy+dy+j2QxVZpuHKHbue/zJmV5XXRudq45LTCCBfftzXWepEa8MkY6szOjgiAjtRfJGUmLYMft3aycw4dAY28roI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248878; c=relaxed/simple; bh=0Keft5t7OBXgX7YaxEhWnWuQSKMAek/Moq2pD9h81W8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kjOr/9FzhTlNm6THfaq18n5Afk9UQZ9ENc5qj3Ste2Uy2aNYNM51JOFnZJn7ObIvNnOeECtxgV59BrXdbUzrokyqqMI8PYPLUGg6TELHsCDRX6APVOryzwTx9Ac9q6iCSP+iL1+Gb41aKryhNypzRBg/nN+mNY5vQCs/NmL16vk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CZyep7Zu; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CZyep7Zu" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-1279caef718so3684385c88.1 for ; Fri, 03 Apr 2026 13:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248876; x=1775853676; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DD9DzZmqkeGtfBm/333ve8pZcjoUvLLGIPaFR8uqSWs=; b=CZyep7ZuoiyRsz9hroi7nbo6pv9x9ArKLhMADVMseqOemggOs5YtCmEu24xYmoTGZp +o8cECOoizce6MVutEl5/rVQc40zzIpUMG3JidUV/8pCE2tvYyy/LxHZv4/CjjukVya7 Co/hFFdzvfRe7HSfjGxYQp82nTtRkEXaMvCeVLS6aQfigof8732xHFE7WdLuZqpohl56 67UPbFwIbsHSX0qysuhLOkTjqtK5EvahlBQ0u9Kc17x7tW4iamkHnDhArmM3kxF4JSll bf/gLxBUGPrfAqx3RhOZYNa2CdGSWe6iz93aH+PPTAgXBB4BsQTH+IoEW9l0U3Jbd5xN PO0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248876; x=1775853676; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DD9DzZmqkeGtfBm/333ve8pZcjoUvLLGIPaFR8uqSWs=; b=klgs2tDAfqikUWVn6KmYDARs4pIKr03y/c/sDZBPNvSqCeNMSiWIU9Iq+RIVoMh8bK rfne3EJt9/ZVM9Br2Km4MUd64lxzcKi/huRinfqqVAVAa6zV+VgjeOsvPnTd0CAIHnbr 8zDBPM3/vlnDGNuXc/jnL6fylkfF6yxPMzCnehNiC3g58u3PrCzKCDE/KLdcKUvWKHF0 TZ8dRU+iRYM58WjM/j7lVpcqTKrP3lRzjpdtLnDEqS/I2MdwmpcPtlEg2jIzjWzDu0ca vbNebazpGhCTcnnKOzZ9PbPYYkNCjdyIEzaqE18FMjB6PBvZQoPYMu8603mnFmbb8mAY Amcw== X-Forwarded-Encrypted: i=1; AJvYcCUa9hrz7R5sh3Zo+9K+WZay8rfIOmXSGEfj+SnHKPDtn76N6bgzD2CEQbZ32C+ZS884CLK3mXojXBb7Ez0=@vger.kernel.org X-Gm-Message-State: AOJu0Ywj0eAnpEcPyFBzGtYkLw+Hlj3QfT1BBxYA/HrQvbdapM6xB2na bz2IVObMg4Ksa2NPZvPWFbqwBLf2CXJTvtthRMziC+3yLrpvkT/XvXWQ+Uar9H+LZmVOUKW+2c2 GkYjejkosdg== X-Received: from dycpq3.prod.google.com ([2002:a05:7301:fd03:b0:2c7:1a46:6250]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6629:b0:12a:6b99:1ad4 with SMTP id a92af1059eb24-12bfb6fb392mr2091620c88.11.1775248875900; Fri, 03 Apr 2026 13:41:15 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:14 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-23-irogers@google.com> Subject: [PATCH v5 22/25] perf evlist: Try to avoid computing evsel from sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If the sample has an evsel, don't recompute using the sample.id. Signed-off-by: Ian Rogers --- tools/perf/builtin-top.c | 4 +++- tools/perf/tests/mmap-basic.c | 4 +++- tools/perf/tests/switch-tracking.c | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index a66666e89f67..f8bca1cb5769 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1164,7 +1164,9 @@ static int deliver_event(struct ordered_events *qe, goto next_event; } =20 - evsel =3D evlist__id2evsel(session->evlist, sample.id); + evsel =3D sample.evsel; + if (!evsel) + evsel =3D evlist__id2evsel(session->evlist, sample.id); assert(evsel !=3D NULL); =20 if (event->header.type =3D=3D PERF_RECORD_SAMPLE) { diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 3313c236104e..a18d84d858aa 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -142,7 +142,9 @@ static int test__basic_mmap(struct test_suite *test __m= aybe_unused, int subtest } =20 err =3D -1; - evsel =3D evlist__id2evsel(evlist, sample.id); + evsel =3D sample.evsel; + if (!evsel) + evsel =3D evlist__id2evsel(evlist, sample.id); perf_sample__exit(&sample); if (evsel =3D=3D NULL) { pr_debug("event with id %" PRIu64 diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-t= racking.c index 22b0302252db..e32331fee277 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -138,7 +138,10 @@ static int process_sample_event(struct evlist *evlist, goto out; } =20 - evsel =3D evlist__id2evsel(evlist, sample.id); + evsel =3D sample.evsel; + if (!evsel) + evsel =3D evlist__id2evsel(evlist, sample.id); + if (evsel =3D=3D switch_tracking->switch_evsel) { next_tid =3D perf_sample__intval(&sample, "next_pid"); prev_tid =3D perf_sample__intval(&sample, "prev_pid"); --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F29B13DD530 for ; Fri, 3 Apr 2026 20:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248881; cv=none; b=ZhEsTANIQmwRrsIfA6p8GdQW0gBXGj/q60pbQt90ySFfLhijgH1wnTMr9D/2E9pdHtZZdSj3TYqUhAzMI2qf5jaCxyqBn/Xf81dDu1jNnkXJRL7gNg1ciNDwL/jByDP8Wa5zDw9YHgoORgIUPQhns9jtNfsV9zf1YBxVUGvEtOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248881; c=relaxed/simple; bh=y/G4gpKx0P2HPmDFix5CNzGkh4WQuw8zLMsSBqQ7Ecw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KLhol0d9uoFuEySNushhQl/n1M2v1e5avb20r7QeSv+qeB/qg8VwDQeC1X5MaIQzkadRVdJ9j4kPYvhDHw+2zLY0/TBJy/Rl/LXCtlLoSfOqx2luFAWSYgN4HSOtOnp2Dv1nW9CDS4pz2HeFpP0uJb2VpNQ+R1VRhlATY1WMUK8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mPLV11qf; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mPLV11qf" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2c7130f88e3so8693915eec.0 for ; Fri, 03 Apr 2026 13:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248878; x=1775853678; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fTlzkB4n9jPQ8oVXunJ8R99YcUod4tiDX9fMKJRXITM=; b=mPLV11qfJ9xzhN/gpKQbs0MtEH5CcFn5uR4bdX13l52JdoyHnvWJZfJWvS+9Wx92qd eziMRSs8OWyOl2SWZLUlVVb9lvx7jIEqBfmzJYkP9txvRcMrVBfU80gJ2C402Q75Kr/U 6bqeRP/71amZAikuo/GiUF0XkXJ/ZHKlbo6vwZsFwnH0dP0gUNW1ltkuyfjc4LzsY+1p 7C6hEMqxbDqYL74h58r9ybjmP+tATIZxNRoXCzZvAoWarmDDV8IUxLtk3IaJ+bPwDo4Z oDfXnDdEbhLBJTRCEfIKaciCFBzKmOx4ra1hHoBvVajMcS1NkJG4+241NVzCyMdEx21Y mFnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248878; x=1775853678; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fTlzkB4n9jPQ8oVXunJ8R99YcUod4tiDX9fMKJRXITM=; b=B06ykfVpsQf1MwM5HeLx2IIrR8M/EOw51JhnV1elqRS4WmNkxrcG8iREnuSSgJ2WZT q8DKEPtmWNfv2kztCTbwvu7PzVrwnczZhBuC12AMxQ2Qlaytj36Ev039th8baQsXKXSF /8cXGfDTg33WHaWUSS4LUqabLLjzYh/aV1aA6Rxh88M1FMJoRLFIDoo9A0ci9gUr2u8J 1raYmlkI5PelVVPAuyXTfjNjle/PECXOqd8Z7x4WBXixFvbmZcDJrWi4VOgtd8G8PaeR 6lnv5UgdUdaWPJ5dWpv31iqr4qWc9ZyOfw4W2EKPKv5P8CwX7y0sz0EcZNQDOOjEzJRR pFTg== X-Forwarded-Encrypted: i=1; AJvYcCUsD5PpV5ogTGY56oOhTYhhMTlP/1z/NEFqOrNDuokiaoy62OKs0z0hQYaX9lv4n/HcOCWvNcVJLHS9OBQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yxj4tlWOY4Gv1mnXTBQDhNL3BsaZSqls3Cz65mYxtNJ9VcoJ+tz bevrIkaNHBM8e6QQttBKbPyh7Znk7LohQU2EZrKcoytYo3HFyt0NTyVyMlqpLKEDbMNoKse8nQI jiBa2AFmCyw== X-Received: from dycmg10.prod.google.com ([2002:a05:693c:250a:b0:2c6:55cf:de3a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:3118:b0:2c5:a76c:71a with SMTP id 5a478bee46e88-2cbf69941c1mr2399688eec.0.1775248877859; Fri, 03 Apr 2026 13:41:17 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:15 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-24-irogers@google.com> Subject: [PATCH v5 23/25] perf script: Don't pass evsel with sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sample contains the evsel and so it is unnecessary to pass the evsel as well. Remove the evsel from the struct scripting_context so that the sample version is always accessed. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 12 ++++-- .../util/scripting-engines/trace-event-perl.c | 21 +++++------ .../scripting-engines/trace-event-python.c | 37 ++++++++----------- tools/perf/util/trace-event-scripting.c | 5 +-- tools/perf/util/trace-event.h | 3 -- 5 files changed, 33 insertions(+), 45 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8022801721e2..53da706d959f 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2418,12 +2418,13 @@ static bool show_event(struct perf_sample *sample, } =20 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 =3D al->thread; + struct evsel *evsel =3D sample->evsel; struct perf_event_attr *attr =3D &evsel->core.attr; unsigned int type =3D evsel__output_type(evsel); struct evsel_script *es =3D evsel->priv; @@ -2714,9 +2715,9 @@ static int process_sample_event(const struct perf_too= l *tool, thread__resolve(al.thread, &addr_al, sample); addr_al_ptr =3D &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); } =20 out_put: @@ -2892,9 +2893,12 @@ static int print_event_with_time(const struct perf_t= ool *tool, { struct perf_script *script =3D container_of(tool, struct perf_script, too= l); struct perf_session *session =3D script->session; - struct evsel *evsel =3D evlist__id2evsel(session->evlist, sample->id); + struct evsel *evsel =3D sample->evsel; struct thread *thread =3D NULL; =20 + if (!evsel) + evsel =3D evlist__id2evsel(session->evlist, sample->id); + if (evsel && !evsel->core.attr.sample_id_all) { sample->cpu =3D 0; sample->time =3D timestamp; diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/p= erf/util/scripting-engines/trace-event-perl.c index af0d514b2397..7a18ea4b7d50 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -257,7 +257,6 @@ static void define_event_symbols(struct tep_event *even= t, } =20 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 *s= ample, } =20 static void perl_process_tracepoint(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al) { struct thread *thread =3D al->thread; @@ -355,6 +353,7 @@ static void perl_process_tracepoint(struct perf_sample = *sample, unsigned long long nsecs =3D sample->time; const char *comm =3D thread__comm_str(thread); DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX); + struct evsel *evsel =3D sample->evsel; =20 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))); =20 /* common fields other than pid can be accessed via xsub fns */ =20 @@ -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; } =20 -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 per= f_sample *sample) { dSP; =20 @@ -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_si= ze))); PUTBACK; @@ -461,13 +459,12 @@ static void perl_process_event_generic(union perf_eve= nt *event, =20 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, ad= dr_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); } =20 static void run_start_sub(void) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index 8de08cebe240..63d04b051846 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -390,7 +390,6 @@ static unsigned long get_offset(struct symbol *sym, str= uct addr_location *al) } =20 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 samp= le_read_value *value, return t; } =20 -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_sam= ple *sample) { - u64 read_format =3D evsel->core.attr.read_format; + u64 read_format =3D sample->evsel->core.attr.read_format; PyObject *values; unsigned int i; =20 @@ -741,11 +738,10 @@ static void regs_map(struct regs_dump *regs, uint64_t= mask, uint16_t e_machine, =20 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 =3D &evsel->core.attr; + struct perf_event_attr *attr =3D &sample->evsel->core.attr; =20 int size =3D (__sw_hweight64(attr->sample_regs_intr) * MAX_REG_SIZE) + 1; char *bf =3D NULL; @@ -831,7 +827,6 @@ static void python_process_sample_flags(struct perf_sam= ple *sample, PyObject *di } =20 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_sampl= e *sample, PyObject *dict, *dict_sample, *brstack, *brstacksym; uint16_t e_machine =3D EM_HOST; uint32_t e_flags =3D EF_HOST; + struct evsel *evsel =3D sample->evsel; =20 dict =3D PyDict_New(); if (!dict) @@ -871,7 +867,7 @@ static PyObject *get_perf_sample_dict(struct perf_sampl= e *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_sampl= e *sample, if (al->thread) e_machine =3D thread__e_machine(al->thread, /*machine=3D*/NULL, &e_flags= ); =20 - 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"); =20 return dict; @@ -936,7 +932,6 @@ static PyObject *get_perf_sample_dict(struct perf_sampl= e *sample, =20 #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_sampl= e *sample, const char *comm =3D thread__comm_str(al->thread); const char *default_handler_name =3D "trace_unhandled"; DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX); + struct evsel *evsel =3D sample->evsel; =20 bitmap_zero(events_defined, TRACE_EVENT_TYPE_MAX); =20 @@ -995,7 +991,7 @@ static void python_process_tracepoint(struct perf_sampl= e *sample, PyTuple_SetItem(t, n++, context); =20 /* ip unwinding */ - callchain =3D python_process_callchain(sample, evsel, al); + callchain =3D python_process_callchain(sample, al); /* Need an additional reference for the perf_sample dict */ Py_INCREF(callchain); =20 @@ -1051,7 +1047,7 @@ static void python_process_tracepoint(struct perf_sam= ple *sample, PyTuple_SetItem(t, n++, dict); =20 if (get_argument_count(handler) =3D=3D (int) n + 1) { - all_entries_dict =3D get_perf_sample_dict(sample, evsel, al, addr_al, + all_entries_dict =3D 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_sam= ple *sample, } #else static void python_process_tracepoint(struct perf_sample *sample __maybe_u= nused, - 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_ret= urn *cr, u64 *parent_db_id, } =20 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"); =20 /* ip unwinding */ - callchain =3D python_process_callchain(sample, evsel, al); - dict =3D get_perf_sample_dict(sample, evsel, al, addr_al, callchain); + callchain =3D python_process_callchain(sample, al); + dict =3D get_perf_sample_dict(sample, al, addr_al, callchain); =20 PyTuple_SetItem(t, n++, dict); if (_PyTuple_Resize(&t, n) =3D=3D -1) @@ -1502,24 +1496,23 @@ static void python_process_general_event(struct per= f_sample *sample, =20 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 =3D &tables_global; =20 - scripting_context__update(scripting_context, event, sample, evsel, al, ad= dr_al); + scripting_context__update(scripting_context, event, sample, al, addr_al); =20 - 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); } } =20 diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index fa850e44cb46..dc584ac316a3 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -103,12 +103,11 @@ int script_spec__for_each(int (*cb)(struct scripting_= ops *ops, const char *spec) void scripting_context__update(struct scripting_context *c, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { #ifdef HAVE_LIBTRACEEVENT - const struct tep_event *tp_format =3D evsel__tp_format(evsel); + const struct tep_event *tp_format =3D evsel__tp_format(sample->evsel); =20 c->pevent =3D tp_format ? tp_format->tep : NULL; #else @@ -117,7 +116,6 @@ void scripting_context__update(struct scripting_context= *c, c->event_data =3D sample->raw_data; c->event =3D event; c->sample =3D sample; - c->evsel =3D evsel; c->al =3D al; c->addr_al =3D addr_al; } @@ -134,7 +132,6 @@ static int stop_script_unsupported(void) =20 static void process_event_unsupported(union perf_event *event __maybe_unus= ed, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct addr_location *al __maybe_unused, struct addr_location *addr_al __maybe_unused) { diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 914d9b69ed62..720121c74f1d 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -94,7 +94,6 @@ struct scripting_ops { int (*stop_script) (void); void (*process_event) (union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al); void (*process_switch)(union perf_event *event, @@ -124,7 +123,6 @@ struct scripting_context { void *event_data; union perf_event *event; struct perf_sample *sample; - struct evsel *evsel; struct addr_location *al; struct addr_location *addr_al; struct perf_session *session; @@ -133,7 +131,6 @@ struct scripting_context { void scripting_context__update(struct scripting_context *scripting_context, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al); =20 --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 129D03DDDCB for ; Fri, 3 Apr 2026 20:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248883; cv=none; b=HSpzYlssr/S2XZKG0T+S/KD2RDYaGyv7/KS1rbiXPJoH9iE+TzBSOZG0+HhQ2BlGh+ytsO82mRZFg/CoXFh/DpcFf53Vw6HjSKCaxZgWZnBr7hXnuzxVyN7wTAOVN7boBH5aU4Sbak2YS8iNZSSxtYXRbZveIYQhqFr2a7TgEHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248883; c=relaxed/simple; bh=p3zEoq/bmQlpgAQt3/UAgTTaA4JyI4UO/QfGKpe/qI0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=I14oez7qRsR5drdPYxC+Asfwi4+bLz2v4PhKYxlKY9PZ8OM9ii55b9bWc24ZAJAK3JJeG5MWz+GM2hOjYoO5FvnsXbgs0JXZLR+z9MuLoWR8AYBjTtzRZ4drD8fXXS9Rh6uVI3stF1whs5FPtD6Ozhljj8BNV/IVLApOaR7YlOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NA0/q/7A; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NA0/q/7A" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2bdf75bc88fso2793399eec.0 for ; Fri, 03 Apr 2026 13:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248880; x=1775853680; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=f8QqzSuQNDbhCu1T3qPBkA3LFLyljNgjUWQeDCGZhEI=; b=NA0/q/7A2IxETvY0hKSHtUkbv0BUlN0IQzqUU7SQ001kqb8bsjESMsRdftxOAqRyhi DU0G9FyhTRv0OZc47a//YzYAmzZ6uIFwdxmwOMsPkDKbUQl5Y99B3/lF0QHIT9LDJ91e 1rSLcs1PfBs+5NC/GNsqGw6RElmrP5fGiELk3rJxldgBFQS/AfcZ/nAKhtNKV5oo614b A7tNzNpp7NEhopapZubnfdFb/8Lft/Vt2gTcRTcssYSlank9H1HGgG3B0nL3h+hRiH2+ s2XKFk+2btVYpGf9Vlg0FGB94czj+3vW5acEz6NVd0dVR8CObV14YWoHFzAwSOFGSPnC uRBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248880; x=1775853680; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=f8QqzSuQNDbhCu1T3qPBkA3LFLyljNgjUWQeDCGZhEI=; b=PpuKFRrGz95az/XvFeocXTWR3SRUUYeY2PTdllqZ2zXhufX67+qgt2CfsKRevk049Z en/41x6Ae8ERR7QMEHRejT5t1KX2SiIerTqdFxuCWaLSpwiJKsZ+GPg6XKNuwOoMY+Cw 4HHv0WQF13P0HH0Vg/y4mZaOKsNZXblOcAwow8MWEoDOPvqFi+c7aNJRxsAiXQt3Bfp9 9LyUJCK9ZZSr9USVsb8Pl5hSax723/OBj6i9qhzQgEkNyLwcMF4lS192QjNXD5KHsdCf PuUMMDik5N4TTPTrvgvanzlNK9cnxBFl34s922Rh8FeE9KYhNTeakUDaOsWYWHYn0Vhe h+Ug== X-Forwarded-Encrypted: i=1; AJvYcCWdQW0pWSxzgz1wUOtnyKxlwlAc0dcXYjRIh25Of0vbSkFh+SXD5C5MtwN7Xenax7CFZoRw5tO9X6EdsUM=@vger.kernel.org X-Gm-Message-State: AOJu0YwGKiDXYSntd/fKCNwIyjpElAFHBlGNUGKYY6NzvDhqzM1Gx/vm iaSB6RkLcFtF3+EVbITDqO0Pu8To/+kJdeW5lgJgzpndnFzT6TRnBWfynB66K1Ix9+uunBFp09g A1cjQK6HWhA== X-Received: from dybmd47.prod.google.com ([2002:a05:7301:182f:b0:2cc:9943:d1b2]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:a14b:b0:2c1:6676:5ed6 with SMTP id 5a478bee46e88-2cbfbf7a279mr2007764eec.25.1775248879950; Fri, 03 Apr 2026 13:41:19 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:16 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-25-irogers@google.com> Subject: [PATCH v5 24/25] perf s390-sample-raw: Don't pass evsel or its PMU with sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sample contains the evsel and its PMU so it is unnecessary to pass the evsel as well. Signed-off-by: Ian Rogers --- tools/perf/util/s390-sample-raw.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sampl= e-raw.c index c6ae0ae8d86a..52bbca5c56c8 100644 --- a/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -222,8 +222,9 @@ static char *get_counter_name(int set, int nr, struct p= erf_pmu *pmu) return result; } =20 -static void s390_cpumcfdg_dump(struct perf_pmu *pmu, struct perf_sample *s= ample) +static void s390_cpumcfdg_dump(struct perf_sample *sample) { + struct perf_pmu *pmu =3D sample->evsel->pmu; size_t i, len =3D sample->raw_size, offset =3D 0; unsigned char *buf =3D sample->raw_data; const char *color =3D PERF_COLOR_BLUE; @@ -284,8 +285,9 @@ static bool s390_pai_all_test(struct perf_sample *sampl= e) return true; } =20 -static void s390_pai_all_dump(struct evsel *evsel, struct perf_sample *sam= ple) +static void s390_pai_all_dump(struct perf_sample *sample) { + struct evsel *evsel =3D sample->evsel; size_t len =3D sample->raw_size, offset =3D 0; unsigned char *p =3D sample->raw_data; const char *color =3D PERF_COLOR_BLUE; @@ -332,31 +334,32 @@ void evlist__s390_sample_raw(struct evlist *evlist, u= nion perf_event *event, struct perf_sample *sample) { const char *pai_name; - struct evsel *evsel; =20 if (event->header.type !=3D PERF_RECORD_SAMPLE) return; =20 - evsel =3D evlist__event2evsel(evlist, event); - if (!evsel) - return; + if (!sample->evsel) { + sample->evsel =3D evlist__event2evsel(evlist, event); + if (!sample->evsel) + return; + } =20 /* Check for raw data in sample */ if (!sample->raw_size || !sample->raw_data) return; =20 /* Display raw data on screen */ - if (evsel->core.attr.config =3D=3D PERF_EVENT_CPUM_CF_DIAG) { - if (!evsel->pmu) - evsel->pmu =3D perf_pmus__find("cpum_cf"); + if (sample->evsel->core.attr.config =3D=3D PERF_EVENT_CPUM_CF_DIAG) { + if (!sample->evsel->pmu) + sample->evsel->pmu =3D 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; } =20 - switch (evsel->core.attr.config) { + switch (sample->evsel->core.attr.config) { case PERF_EVENT_PAI_NNPA_ALL: pai_name =3D "NNPA_ALL"; break; @@ -370,8 +373,8 @@ void evlist__s390_sample_raw(struct evlist *evlist, uni= on 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 =3D perf_pmus__find_by_type(evsel->core.attr.type); - s390_pai_all_dump(evsel, sample); + if (!sample->evsel->pmu) + sample->evsel->pmu =3D perf_pmus__find_by_type(sample->evsel->core.attr= .type); + s390_pai_all_dump(sample); } } --=20 2.53.0.1213.gd9a14994de-goog From nobody Sat Apr 4 03:19:46 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6129B3DA5BC for ; Fri, 3 Apr 2026 20:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248884; cv=none; b=Y0IaGs+fUTya+wKdYyqD7T3j7L7sNrRw5+suTFiCdpb+kbNGL/Bn7elz6eHymfczzG3BtGkFDeGtjs1ghKVDiuebNf4Gvdrpy1ujYaFKHinSZ79I+pbtw1yjJ1RB7KB9POu/6US00f2sG/VR4I+t+iRYh33JpVgm30wT1h2TqJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775248884; c=relaxed/simple; bh=16je8wZ9rqScgL6yvcnuQStJyi53pIb8IMjgAO7kLG0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WuiHrlwWjC/X5yRoaSGZ8mfsZtwK4DM7YMWWddwz5ddTO+Dc0Y0yHb+sfAXePJEwMedYyJXnOKOLul/DS7xolHgGNckjoULZNncVD5EtbVomztAcbZU3TSfMA3f2L/qE2hBb2bWjBRTsJEckf/GVU9hkqr8hhFskBxO29kv6huo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aHm15rlg; arc=none smtp.client-ip=74.125.82.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aHm15rlg" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-1279caef718so3684457c88.1 for ; Fri, 03 Apr 2026 13:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775248883; x=1775853683; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BhGwcxOOVNWLaxv+kx7m7Po7gy72tR+Ml143+1jEuZI=; b=aHm15rlgAdzKh1X/HEfOuKLc2dEP97T0DWbfHHRFyFB6Ms5h74+hBAJAWQByQfGc0T DSRQ8obg2npCM285KzQ3/R1hkh16Q/XE5C8LuUt4Abhx++9LmDirrJPQJobyT3lnjZW8 nsI2OYz2CaZtEAd8L2JPibk6rh2NIn+TRx7PSmaAnTONUzlPswrpSNouh9jDrz6UfwyB E18rh9I3zTrlndI1LsLHiLRsL+z1wdhbfgdWWAaU/cjhhX/JwCo3Uo3SrbFPkZfkRCWF CB/nfOHnmLIj9j3bp96rUn5LDDjbtO2XJLZ3SKkOjs72kgmLxsBrmYh5b71Ey6AV6TWD JTDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775248883; x=1775853683; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BhGwcxOOVNWLaxv+kx7m7Po7gy72tR+Ml143+1jEuZI=; b=jjdUE90iWpByQ8TN0sqzGsS1b/mVsYh0nvgYK2mT2bVzVK0wWBRg3BA1V7miDqx4xl 5LWfbPZq67K0O/uv6bDyG2Yo1yK9SUY9YvbKxENAHmB8yTVvIyPuacciNMkoovQOWv5S Y3/IFX1vcLmg9nd8KjXSLRVuQFD61N0hn2uwA78QI6uzt/iN3KVaMS10nGdm0CmE9aEr ws4wfgY7D4uwStdpSR4Gnhch5iaath3zxF0xFMaoIN/jjKxcZXV5DsSHQip4ViLLRPmw itLljoUemR1Py7DCgjKTcfuhZ60mBe5lGF3z1WNB8RduQX3C4e2lr8SD3NVHF5kkPlGZ 8GNA== X-Forwarded-Encrypted: i=1; AJvYcCUXIIyIBppHXdpxdCLEGmNFwBsg8gdeZ+j11hRO6wjPApMRddv1wiki9KJAxAca4xfUQ+goZ29ZmAHa+Jo=@vger.kernel.org X-Gm-Message-State: AOJu0YzcbvGAW1r+1TKMUHkQC2yRkm1YX0bDBFPYgGA6AWGNocsg2OCn BvYsj0svmueqH93sjdexUtMqtlNwsnqfuKTUVYKv+YhZleNs9frh9oN4GsfLcCbo/B6v3Dn3QxO FAQEy3PCYWw== X-Received: from dlaf28.prod.google.com ([2002:a05:701b:241c:b0:128:ee69:eb75]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:112:b0:128:e6d0:d7c3 with SMTP id a92af1059eb24-12bfb73eec9mr1976455c88.20.1775248882399; Fri, 03 Apr 2026 13:41:22 -0700 (PDT) Date: Fri, 3 Apr 2026 13:40:17 -0700 In-Reply-To: <20260403204017.2919994-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260403204017.2919994-26-irogers@google.com> Subject: [PATCH v5 25/25] perf evsel: Don't pass evsel with sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Arrange for the sample to contain the evsel and so it is unnecessary to pass the evsel as well. This is done for uniformity, although parsing of the sample is arguably a special case. Add missing bound check in perf_evsel__parse_id_sample. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 53 ++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 3ff4e466ced9..9df30f83b764 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3002,24 +3002,39 @@ int evsel__open_per_thread(struct evsel *evsel, str= uct perf_thread_map *threads) return ret; } =20 -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 =3D sample->evsel; u64 type =3D evsel->core.attr.sample_type; - const __u64 *array =3D event->sample.array; + const __u64 *array, *array_begin =3D event->sample.array; bool swapped =3D evsel->needs_swap; union u64_swap u; =20 - array +=3D ((event->header.size - - sizeof(event->header)) / sizeof(u64)) - 1; + if ((type & (PERF_SAMPLE_IDENTIFIER | + PERF_SAMPLE_CPU | + PERF_SAMPLE_STREAM_ID | + PERF_SAMPLE_ID | + PERF_SAMPLE_TIME | + PERF_SAMPLE_TID)) =3D=3D 0) + return 0; + + if (event->header.size < sizeof(event->header) + sizeof(u64)) + return -EFAULT; =20 + array =3D array_begin + ((event->header.size - sizeof(event->header)) / s= izeof(u64)) - 1; if (type & PERF_SAMPLE_IDENTIFIER) { + if (array < array_begin) + return -EFAULT; + sample->id =3D *array; array--; } =20 if (type & PERF_SAMPLE_CPU) { + if (array < array_begin) + return -EFAULT; + u.val64 =3D *array; if (swapped) { /* undo swap of u64, then swap on individual u32s */ @@ -3032,21 +3047,33 @@ static int perf_evsel__parse_id_sample(const struct= evsel *evsel, } =20 if (type & PERF_SAMPLE_STREAM_ID) { + if (array < array_begin) + return -EFAULT; + sample->stream_id =3D *array; array--; } =20 if (type & PERF_SAMPLE_ID) { + if (array < array_begin) + return -EFAULT; + sample->id =3D *array; array--; } =20 if (type & PERF_SAMPLE_TIME) { + if (array < array_begin) + return -EFAULT; + sample->time =3D *array; array--; } =20 if (type & PERF_SAMPLE_TID) { + if (array < array_begin) + return -EFAULT; + u.val64 =3D *array; if (swapped) { /* undo swap of u64, then swap on individual u32s */ @@ -3243,15 +3270,18 @@ int evsel__parse_sample(struct evsel *evsel, union = perf_event *event, =20 data->deferred_cookie =3D event->callchain_deferred.cookie; =20 - 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; } =20 if (event->header.type !=3D 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; } =20 @@ -3613,12 +3643,13 @@ int evsel__parse_sample_timestamp(struct evsel *evs= el, union perf_event *event, =20 if (event->header.type !=3D PERF_RECORD_SAMPLE) { struct perf_sample data =3D { + .evsel =3D evsel, .time =3D -1ULL, }; =20 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; =20 *timestamp =3D data.time; --=20 2.53.0.1213.gd9a14994de-goog