[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250402091512.GV5880@noisy.programming.kicks-ass.net>
Date: Wed, 2 Apr 2025 11:15:12 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Ravi Bangoria <ravi.bangoria@....com>
Cc: mingo@...nel.org, lucas.demarchi@...el.com,
linux-kernel@...r.kernel.org, acme@...nel.org, namhyung@...nel.org,
mark.rutland@....com, alexander.shishkin@...ux.intel.com,
jolsa@...nel.org, irogers@...gle.com, adrian.hunter@...el.com,
kan.liang@...ux.intel.com
Subject: Re: [PATCH v3 3/7] perf: Simplify perf_event_free_task() wait
On Mon, Mar 17, 2025 at 12:19:07PM +0530, Ravi Bangoria wrote:
> Hi Peter,
>
> > @@ -1223,8 +1223,14 @@ static void put_ctx(struct perf_event_co
> > if (refcount_dec_and_test(&ctx->refcount)) {
> > if (ctx->parent_ctx)
> > put_ctx(ctx->parent_ctx);
> > - if (ctx->task && ctx->task != TASK_TOMBSTONE)
> > - put_task_struct(ctx->task);
> > + if (ctx->task) {
> > + if (ctx->task == TASK_TOMBSTONE) {
> > + smp_mb(); /* pairs with wait_var_event() */
> > + wake_up_var(&ctx->refcount);
>
> perf_event_free_task() waits on "ctx->refcount == 1". But moving
> wake_up_var() under refcount_dec_and_test() will cause
> perf_event_free_task() to wait indefinitely. Right? So, shouldn't
> wake_up_var() be outside? something like:
>
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -1281,15 +1281,14 @@ static void put_ctx(struct perf_event_context *ctx)
> if (refcount_dec_and_test(&ctx->refcount)) {
> if (ctx->parent_ctx)
> put_ctx(ctx->parent_ctx);
> - if (ctx->task) {
> - if (ctx->task == TASK_TOMBSTONE) {
> - smp_mb(); /* pairs with wait_var_event() */
> - wake_up_var(&ctx->refcount);
> - } else {
> - put_task_struct(ctx->task);
> - }
> - }
> + if (ctx->task && ctx->task != TASK_TOMBSTONE)
> + put_task_struct(ctx->task);
> call_rcu(&ctx->rcu_head, free_ctx);
> + } else {
> + if (ctx->task == TASK_TOMBSTONE) {
> + smp_mb(); /* pairs with wait_var_event() */
> + wake_up_var(&ctx->refcount);
> + }
> }
> }
Yes, you're quite right indeed. Thanks!
Powered by blists - more mailing lists