mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Thaumy Cheng <thaumy.love@gmail.com>
Cc: 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>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 RESEND] perf/core: Fix missing read event generation on task exit
Date: Mon, 13 Oct 2025 16:08:06 +0200	[thread overview]
Message-ID: <20251013140806.GL3245006@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20251008163530.810407-1-thaumy.love@gmail.com>

On Thu, Oct 09, 2025 at 12:35:30AM +0800, Thaumy Cheng wrote:

> @@ -13995,13 +13997,16 @@ static void sync_child_event(struct perf_event *child_event)
>  }
> 
>  static void
> -perf_event_exit_event(struct perf_event *event,
> -		      struct perf_event_context *ctx, bool revoke)
> +perf_event_detach_event(struct perf_event *event,
> +		      struct perf_event_context *ctx, bool revoke, bool exit)
>  {
>  	struct perf_event *parent_event = event->parent;
> -	unsigned long detach_flags = DETACH_EXIT;
> +	unsigned long detach_flags = 0;
>  	unsigned int attach_state;
> 
> +	if (exit)
> +		detach_flags |= DETACH_EXIT;
> +

Urgh, at that point just pass in the right DETACH_flag directly,
something like:

perf_event_detach_event(struct perf_event *event,
			struct perf_event_context *ctx,
			unsigned long detach_flags);

	perf_event_detach_event(event, ctx, DETACH_EXIT);

	perf_event_detach_event(event, ctx, DETACH_REVOKE);



>  	if (parent_event) {
>  		/*
>  		 * Do not destroy the 'original' grouping; because of the
> @@ -14077,6 +14082,17 @@ static void perf_event_exit_task_context(struct task_struct *task, bool exit)
>  	 */
>  	mutex_lock(&ctx->mutex);
> 
> +	/*
> +	 * Report the task dead after unscheduling the events so that we
> +	 * won't get any samples after PERF_RECORD_EXIT. We can however still
> +	 * get a few PERF_RECORD_READ events.
> +	 */
> +	if (exit)
> +		perf_event_task(task, ctx, 0);
> +
> +	list_for_each_entry_safe(child_event, next, &ctx->event_list, event_entry)
> +		perf_event_detach_event(child_event, ctx, false, exit);
> +
>  	/*
>  	 * In a single ctx::lock section, de-schedule the events and detach the
>  	 * context from the task such that we cannot ever get it scheduled back

This can't be right; read the comment you moved and then look where we
unschedule the event.

  reply	other threads:[~2025-10-13 14:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-08 16:35 Thaumy Cheng
2025-10-13 14:08 ` Peter Zijlstra [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-09-02 15:15 Thaumy Cheng

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=20251013140806.GL3245006@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --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®