From: Peter Zijlstra <peterz@infradead.org>
To: James Clark <james.clark@linaro.org>
Cc: Thaumy Cheng <thaumy.love@gmail.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Suzuki K Poulose <Suzuki.Poulose@arm.com>,
Leo Yan <leo.yan@arm.com>, Mike Leach <mike.leach@linaro.org>
Subject: Re: [PATCH v3] perf/core: Fix missing read event generation on task exit
Date: Wed, 4 Mar 2026 16:23:16 +0100 [thread overview]
Message-ID: <20260304152316.GO1395266@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <f0a5192a-7b6a-4c51-87e9-fc1dbf4d37df@linaro.org>
On Wed, Mar 04, 2026 at 11:26:10AM +0000, James Clark wrote:
> > @@ -14564,11 +14556,21 @@ static void perf_event_exit_task_context(struct task_struct *task, bool exit)
> > * won't get any samples after PERF_RECORD_EXIT. We can however still
> > * get a few PERF_RECORD_READ events.
> > */
> > - if (exit)
> > + if (exit) {
> > perf_event_task(task, ctx, 0);
> > - list_for_each_entry_safe(child_event, next, &ctx->event_list, event_entry)
> > - perf_event_exit_event(child_event, ctx, exit ? task : NULL, false);
> > + guard(raw_spinlock_irq)(&ctx->lock);
> > + list_for_each_entry(event, &ctx->event_list, event_entry) {
> > + if (event->attr.inherit_stat) {
> > + if (task && task != TASK_TOMBSTONE &&
> > + event_filter_match(event))
> > + perf_event_read_event(event, task);
>
> Doesn't this only work if you happened to have an event opened on every CPU?
> Otherwise you could get rescheduled onto a core without an event and the
> event_filter_match() will fail and you'd drop the sample read for that exit.
Yes, absolutely. But that is more or less what you get.
So perf has per-task buffers and per-cpu buffers. For a simple per-task
profile, the per-task buffer works fine. However, if you want inherited
tasks, they can't all emit to the same buffer -- this would be a
scalability nightmake. So in that scenario you have to have
per-task-per-cpu events and make sure everybody emits to the local
buffer.
If you 'forget' to create an event/buffer for a particular CPU the
task(s) can run on, you loose events the moment they end up there.
There just isn't much you can do about that.
next prev parent reply other threads:[~2026-03-04 15:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-24 17:05 Thaumy Cheng
2026-02-06 11:21 ` James Clark
2026-02-06 15:29 ` Peter Zijlstra
2026-02-09 16:12 ` James Clark
2026-03-03 14:29 ` Peter Zijlstra
2026-03-04 11:26 ` James Clark
2026-03-04 15:23 ` Peter Zijlstra [this message]
2026-05-15 12:45 ` James Clark
2026-03-10 10:59 ` James Clark
2026-03-10 18:25 ` Ian Rogers
2026-03-11 10:16 ` James Clark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260304152316.GO1395266@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Suzuki.Poulose@arm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=leo.yan@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mike.leach@linaro.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=thaumy.love@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®