From nobody Tue Feb 10 15:43:24 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 15122387363 for ; Mon, 9 Feb 2026 17:40:49 +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=1770658850; cv=none; b=PxeK9Y+akQvVBHwprMkEPgpIvX1nFt7GN9SHCaqIDJjPoeRFrj5r3aUuMIYOmAOVt2FQa1cJ2xHVsyPT1x37/m+vURlFl6B//YQVMrVQzLKzXmmzrOjP8NMPUaNr5YZRuKD5Vskq4zyNOztNtP5Svyjjm3gu/OR4rHjLdRnMEgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770658850; c=relaxed/simple; bh=d9EhKkG6ze3jzDr0E895630a5304jf8nSoqGsqCsfzo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=RBwYyOI2+4WmLdPw1LmLbA/pWZMHjSHDNDAYuYNenhf3WqGDHCjy8bunhvP6DgnNo3sKqTq/szAqCOB60s1SqzD6qNfRMUCgj3UCxb0cFU/R/1r2dljWSp1U2B6U7iIwNa664oc0AZlqboYpxs91BxNnnpdnUUL8nLaHOCxMLPA= 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=LzFnsOaL; 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="LzFnsOaL" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-12721cd1a2aso3219991c88.1 for ; Mon, 09 Feb 2026 09:40:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770658849; x=1771263649; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=0/jCV8OZGOh/GHl8+nOnmAz38qBf1dX7oFSvxJQYI9M=; b=LzFnsOaLlATvdN69YZb2fyxoC8R4cSljtGGVVcKl+JMAcmaPdmEREWsy+HOHjetvFH XtOq9yPjes2Ckn7V3YJtcKcN5/jh7cAuqqLOWpikOiq1hUA/0ca85uhBUyLvP0dlpaQf LvMkw2Mp7/fAxMx4omUfYcr5r67XoRaGg2FmJWgJ/f6q3Mm05QDbWwclH2gDrSSJ/9j2 3UJLxL9NkHCo/1KWPkOnd/QVqxsZUuXsu4FfXqPh2GSg1cZKRKZjdKVBpvt4aIq/SUSe AeqbUA6+5Lba5CtPQ1AjimxnzrvKkGzwn37JFBu+m1TObdtr7A2PgoY7ylxXSvy4ps9b dpeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770658849; x=1771263649; h=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=0/jCV8OZGOh/GHl8+nOnmAz38qBf1dX7oFSvxJQYI9M=; b=q1o+iDXCxxlIEn8UfncpK+Ms+kQAzeO2zwEA19JCjAHkbTEAfZc/OAdi4iMj2DD2PJ lbBj3nB9FIZpDuU/MTrnHykFJAUINqOGJvSF5iEEQJsrLCkpu9kx4EGrhe6nzrZWd/Ia NlxHH72mhSl3C/lIBkk85xxH3ht7XN9+dgshNXz6V5x3K3HIcwO5LxBEWUmFxMNj0SgR LuQJYMl7nmnPCvDMCkg6anQfOK7iv82+SZqysQ2PRmvhCuFxUNnsqPOHqzgrWjik5uUP Dt3mlqPQeWNNUdBjVjRDUnRsT1rQD+uHfm1Vz2Nh87G+etBxuwtMB9B+4C+quLGnyoGF dGZg== X-Forwarded-Encrypted: i=1; AJvYcCWTMATpIW0aX+wSzZ3C3lK2CJXB3wimqvXpB6uYPMi6hwiw3Z0twX/d3Xj9lQZ5qINkMp1zl37H6SslKAk=@vger.kernel.org X-Gm-Message-State: AOJu0YyrXyfC5P8dzdNl+ocW6fqWDABNys0t78WAz3ewSqiat0MkZRB3 EO0kC9py6KpFPdlQE0U0fPewV/oOFBztZOCV5x3mWlHBRSxLcAuCxWpTfDQmiaMyuYFb+XMVQu8 inZhI5TAJlQ== X-Received: from dlj11.prod.google.com ([2002:a05:7022:50b:b0:127:fa:7498]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6894:b0:122:153:d161 with SMTP id a92af1059eb24-12704001972mr6324312c88.17.1770658849171; Mon, 09 Feb 2026 09:40:49 -0800 (PST) Date: Mon, 9 Feb 2026 09:40:10 -0800 In-Reply-To: <20260209174032.4142096-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: <20260209174032.4142096-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.239.g8d8fc8a987-goog Message-ID: <20260209174032.4142096-4-irogers@google.com> Subject: [PATCH v1 03/25] perf sample: Add evsel to struct perf_sample From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Leo Yan , Tianyou Li , Athira Rajeev , Derek Foreman , Thomas Falcon , Howard Chu , Dmitry Vyukov , Andi Kleen , tanze , Hrishikesh Suresh , Quan Zhou , Andrew Jones , Anup Patel , Dapeng Mi , "Dr. David Alan Gilbert" , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , Chun-Tse Shao , Ravi Bangoria , Swapnil Sapkal , Chen Ni , Blake Jones , Yujie Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 | 10 ++++++--- tools/perf/builtin-script.c | 4 ++++ tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 1 + tools/perf/tests/hists_output.c | 2 +- tools/perf/util/evsel.c | 1 + tools/perf/util/sample.h | 3 +++ tools/perf/util/session.c | 35 +++++++++++++++++++------------ 8 files changed, 40 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 3d2556213599..8ae76bf5253e 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -133,7 +133,7 @@ struct perf_inject { struct perf_file_section secs[HEADER_FEAT_BITS]; struct guest_session guest_session; struct strlist *known_build_ids; - const struct evsel *mmap_evsel; + struct evsel *mmap_evsel; struct ip_callchain *raw_callchain; }; =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 @@ -1007,6 +1007,7 @@ int perf_event__inject_buildid(const struct perf_tool= *tool, union perf_event *e .machine =3D machine, .mmap_evsel =3D inject__mmap_evsel(inject), }; + struct evsel *saved_evsel =3D sample->evsel; =20 addr_location__init(&al); thread =3D machine__findnew_thread(machine, sample->pid, sample->tid); @@ -1021,9 +1022,10 @@ int perf_event__inject_buildid(const struct perf_too= l *tool, union perf_event *e /*sample_in_dso=3D*/true); } =20 + sample->evsel =3D inject__mmap_evsel(inject); sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEP= TH, /*symbols=3D*/false, mark_dso_hit_callback, &args); - + sample->evsel =3D saved_evsel; thread__put(thread); repipe: perf_event__repipe(tool, event, sample, machine); @@ -1100,6 +1102,7 @@ static int perf_inject__sched_stat(const struct perf_= tool *tool, evsel__parse_sample(evsel, event_sw, &sample_sw); =20 perf_sample__init(&sample_sw, /*all=3D*/false); + sample_sw.evsel =3D evsel; sample_sw.period =3D sample->period; sample_sw.time =3D sample->time; perf_event__synthesize_sample(event_sw, evsel->core.attr.sample_type, @@ -1433,6 +1436,7 @@ static int synthesize_build_id(struct perf_inject *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 14c6f6c3c4f2..c28897186341 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2905,8 +2905,12 @@ static int print_event_with_time(const struct perf_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 34ae388750db..a7da54d365a9 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3220,6 +3220,7 @@ int evsel__parse_sample(struct evsel *evsel, union 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.h b/tools/perf/util/sample.h index 3fd2a5e01308..51ea4af452ea 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -5,6 +5,7 @@ #include #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.239.g8d8fc8a987-goog