mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: mingo@kernel.org, ravi.bangoria@amd.com, lucas.demarchi@intel.com
Cc: linux-kernel@vger.kernel.org, acme@kernel.org,
	namhyung@kernel.org, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, jolsa@kernel.org,
	irogers@google.com, adrian.hunter@intel.com,
	kan.liang@linux.intel.com
Subject: [PATCH v3a 6/7] perf: Rename perf_event_exit_task(.child)
Date: Mon, 10 Mar 2025 16:37:42 +0100	[thread overview]
Message-ID: <20250310153742.GE19344@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20250307193723.417881572@infradead.org>


The task passed to perf_event_exit_task() is not a child, it is
current. Fix this confusing naming, since much of the rest of the code
also relies on it being current.

Specifically, both exec() and exit() callers use it with current as
the argument.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/events/core.c |   54 ++++++++++++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 26 deletions(-)

--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -13551,8 +13551,8 @@ static void perf_event_exit_task_context
 	struct perf_event_context *child_ctx, *clone_ctx = NULL;
 	struct perf_event *child_event, *next;
 
-	child_ctx = perf_pin_task_context(child);
-	if (!child_ctx)
+	ctx = perf_pin_task_context(task);
+	if (!ctx)
 		return;
 
 	/*
@@ -13565,27 +13565,27 @@ static void perf_event_exit_task_context
 	 * without ctx::mutex (it cannot because of the move_group double mutex
 	 * lock thing). See the comments in perf_install_in_context().
 	 */
-	mutex_lock(&child_ctx->mutex);
+	mutex_lock(&ctx->mutex);
 
 	/*
 	 * 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
 	 * in.
 	 */
-	raw_spin_lock_irq(&child_ctx->lock);
-	task_ctx_sched_out(child_ctx, NULL, EVENT_ALL);
+	raw_spin_lock_irq(&ctx->lock);
+	task_ctx_sched_out(ctx, NULL, EVENT_ALL);
 
 	/*
 	 * Now that the context is inactive, destroy the task <-> ctx relation
 	 * and mark the context dead.
 	 */
-	RCU_INIT_POINTER(child->perf_event_ctxp, NULL);
-	put_ctx(child_ctx); /* cannot be last */
-	WRITE_ONCE(child_ctx->task, TASK_TOMBSTONE);
+	RCU_INIT_POINTER(task->perf_event_ctxp, NULL);
+	put_ctx(ctx); /* cannot be last */
+	WRITE_ONCE(ctx->task, TASK_TOMBSTONE);
 	put_task_struct(current); /* cannot be last */
 
-	clone_ctx = unclone_ctx(child_ctx);
-	raw_spin_unlock_irq(&child_ctx->lock);
+	clone_ctx = unclone_ctx(ctx);
+	raw_spin_unlock_irq(&ctx->lock);
 
 	if (clone_ctx)
 		put_ctx(clone_ctx);
@@ -13596,12 +13596,12 @@ static void perf_event_exit_task_context
 	 * get a few PERF_RECORD_READ events.
 	 */
 	if (exit)
-		perf_event_task(child, child_ctx, 0);
+		perf_event_task(task, ctx, 0);
 
-	list_for_each_entry_safe(child_event, next, &child_ctx->event_list, event_entry)
-		perf_event_exit_event(child_event, child_ctx);
+	list_for_each_entry_safe(child_event, next, &ctx->event_list, event_entry)
+		perf_event_exit_event(child_event, ctx);
 
-	mutex_unlock(&child_ctx->mutex);
+	mutex_unlock(&ctx->mutex);
 
 	if (!exit) {
 		/*
@@ -13617,24 +13617,26 @@ static void perf_event_exit_task_context
 		 *
 		 * Wait for all events to drop their context reference.
 		 */
-		wait_var_event(&child_ctx->refcount,
-			       refcount_read(&child_ctx->refcount) == 1);
+		wait_var_event(&ctx->refcount,
+			       refcount_read(&ctx->refcount) == 1);
 	}
-	put_ctx(child_ctx);
+	put_ctx(ctx);
 }
 
 /*
- * When a child task exits, feed back event values to parent events.
+ * When a task exits, feed back event values to parent events.
  *
  * Can be called with exec_update_lock held when called from
  * setup_new_exec().
  */
-void perf_event_exit_task(struct task_struct *child)
+void perf_event_exit_task(struct task_struct *task)
 {
 	struct perf_event *event, *tmp;
 
-	mutex_lock(&child->perf_event_mutex);
-	list_for_each_entry_safe(event, tmp, &child->perf_event_list,
+	WARN_ON_ONCE(task != current);
+
+	mutex_lock(&task->perf_event_mutex);
+	list_for_each_entry_safe(event, tmp, &task->perf_event_list,
 				 owner_entry) {
 		list_del_init(&event->owner_entry);
 
@@ -13645,17 +13647,17 @@ void perf_event_exit_task(struct task_st
 		 */
 		smp_store_release(&event->owner, NULL);
 	}
-	mutex_unlock(&child->perf_event_mutex);
+	mutex_unlock(&task->perf_event_mutex);
 
-	perf_event_exit_task_context(child, true);
+	perf_event_exit_task_context(task, true);
 
 	/*
 	 * The perf_event_exit_task_context calls perf_event_task
-	 * with child's task_ctx, which generates EXIT events for
-	 * child contexts and sets child->perf_event_ctxp[] to NULL.
+	 * with task's task_ctx, which generates EXIT events for
+	 * task contexts and sets task->perf_event_ctxp[] to NULL.
 	 * At this point we need to send EXIT events to cpu contexts.
 	 */
-	perf_event_task(child, NULL, 0);
+	perf_event_task(task, NULL, 0);
 }
 
 /*

  parent reply	other threads:[~2025-03-10 15:37 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-07 19:33 [PATCH v3 0/7] perf: Make perf_pmu_unregister() usable Peter Zijlstra
2025-03-07 19:33 ` [PATCH v3 1/7] perf: Ensure bpf_perf_link path is properly serialized Peter Zijlstra
2025-03-07 19:33 ` [PATCH v3 2/7] perf: Simplify child event tear-down Peter Zijlstra
2025-03-07 19:33 ` [PATCH v3 3/7] perf: Simplify perf_event_free_task() wait Peter Zijlstra
2025-03-17  6:49   ` Ravi Bangoria
2025-04-02  9:15     ` Peter Zijlstra
2025-04-08 19:05   ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-04-09 13:01     ` Frederic Weisbecker
2025-04-10  9:34       ` Peter Zijlstra
2025-04-10  9:45         ` Frederic Weisbecker
2025-04-17 12:03       ` Ingo Molnar
2025-04-17 13:01       ` [tip: perf/core] perf/core: Fix put_ctx() ordering tip-bot2 for Frederic Weisbecker
2025-03-07 19:33 ` [PATCH v3 4/7] perf: Simplify perf_event_release_kernel() Peter Zijlstra
2025-04-08 19:05   ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-03-07 19:33 ` [PATCH v3 5/7] perf: Unify perf_event_free_task() / perf_event_exit_task_context() Peter Zijlstra
2025-03-10 15:35   ` [PATCH v3a " Peter Zijlstra
2025-04-08 19:05   ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-03-07 19:33 ` [PATCH v3 6/7] perf: Rename perf_event_exit_task(.child) Peter Zijlstra
2025-03-10 11:08   ` Ravi Bangoria
2025-03-10 14:47     ` Peter Zijlstra
2025-03-10 15:20       ` Ravi Bangoria
2025-03-10 15:27         ` Peter Zijlstra
2025-03-10 15:37   ` Peter Zijlstra [this message]
2025-03-12  6:31     ` [PATCH v3a " Ravi Bangoria
2025-03-12 10:16       ` Peter Zijlstra
2025-03-07 19:33 ` [PATCH v3 7/7] perf: Make perf_pmu_unregister() useable Peter Zijlstra
2025-03-10 15:35   ` Ravi Bangoria
2025-03-10 16:14     ` Peter Zijlstra
2025-03-10 16:46   ` Ravi Bangoria
2025-03-12 12:57     ` Peter Zijlstra
2025-03-12 13:57       ` Ravi Bangoria
2025-04-08 19:05   ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-04-17  8:08     ` Peter Zijlstra
2025-04-17 13:01       ` [tip: perf/core] perf/core: Fix event timekeeping merge tip-bot2 for Peter Zijlstra
2025-04-14  0:37   ` [PATCH v3 7/7] perf: Make perf_pmu_unregister() useable Mi, Dapeng
2025-04-17  8:07     ` Peter Zijlstra
2025-04-17  8:24       ` Mi, Dapeng
2025-04-17 11:30       ` [tip: perf/core] perf/core: Fix perf-stat / read() tip-bot2 for Peter Zijlstra
2025-04-17 13:01       ` tip-bot2 for Peter Zijlstra
2025-03-17  6:54 ` [PATCH v3 0/7] perf: Make perf_pmu_unregister() usable Ravi Bangoria
2025-04-08 19:05 ` [tip: perf/core] perf: Rename perf_event_exit_task(.child) tip-bot2 for Peter Zijlstra
2025-04-08 19:05 ` [tip: perf/core] perf: Simplify child event tear-down tip-bot2 for Peter Zijlstra
2025-04-08 19:05 ` [tip: perf/core] perf: Ensure bpf_perf_link path is properly serialized tip-bot2 for Peter Zijlstra

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=20250310153742.GE19344@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=lucas.demarchi@intel.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=ravi.bangoria@amd.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®