public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yeoreum Yun <yeoreum.yun@arm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: mingo@redhat.com, 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, linux-perf-users@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] events/core: fix acoount failure for event's total_enable_time
Date: Fri, 20 Dec 2024 15:43:40 +0000	[thread overview]
Message-ID: <Z2WQrO+kjJ+w2Sur@e129823.arm.com> (raw)
In-Reply-To: <20241220152810.GK12500@noisy.programming.kicks-ass.net>

On Fri, Dec 20, 2024 at 04:28:10PM +0100, Peter Zijlstra wrote:
> On Fri, Dec 20, 2024 at 04:14:14PM +0100, Peter Zijlstra wrote:
> > On Fri, Dec 20, 2024 at 02:05:39PM +0000, Yeoreum Yun wrote:
>
> > > the answer is in the perf_event_exit_event()'s
> > > perf_remove_from_context(). in here
> > > event_sched_out() is called via __perf_remove_from_context()
> > > So above case, the enable time is fixed in here.
> >
> > OK, how's this then?
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 065f9188b44a..96a00034b26f 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -2406,7 +2406,8 @@ ctx_time_update_event(struct perf_event_context *ctx, struct perf_event *event)
>
>  #define DETACH_GROUP	0x01UL
>  #define DETACH_CHILD	0x02UL
> -#define DETACH_DEAD	0x04UL
> +#define DETACH_EXIT	0x04UL
> +#define DETACH_DEAD	0x048L
>
>  /*
>   * Cross CPU call to remove a performance event
> @@ -2421,6 +2422,7 @@ __perf_remove_from_context(struct perf_event *event,
>  			   void *info)
>  {
>  	struct perf_event_pmu_context *pmu_ctx = event->pmu_ctx;
> +	enum perf_event_state state = PERF_EVENT_STATE_OFF;
>  	unsigned long flags = (unsigned long)info;
>
>  	ctx_time_update(cpuctx, ctx);
> @@ -2429,16 +2431,20 @@ __perf_remove_from_context(struct perf_event *event,
>  	 * Ensure event_sched_out() switches to OFF, at the very least
>  	 * this avoids raising perf_pending_task() at this time.
>  	 */
> -	if (flags & DETACH_DEAD)
> +	if (flags & DETACH_EXIT)
> +		state = PERF_EVENT_STATE_EXIT;
> +	if (flags & DETACH_DEAD) {
>  		event->pending_disable = 1;
> +		state = PERF_EVENT_STATE_DEAD;
> +	}
>  	event_sched_out(event, ctx);
>  	if (flags & DETACH_GROUP)
>  		perf_group_detach(event);
>  	if (flags & DETACH_CHILD)
>  		perf_child_detach(event);
>  	list_del_event(event, ctx);
> -	if (flags & DETACH_DEAD)
> -		event->state = PERF_EVENT_STATE_DEAD;
> +
> +	perf_event_set_state(event, min(event->state, state));
>
>  	if (!pmu_ctx->nr_events) {
>  		pmu_ctx->rotate_necessary = 0;
> @@ -13371,12 +13377,7 @@ perf_event_exit_event(struct perf_event *event, struct perf_event_context *ctx)
>  		mutex_lock(&parent_event->child_mutex);
>  	}
>
> -	perf_remove_from_context(event, detach_flags);
> -
> -	raw_spin_lock_irq(&ctx->lock);
> -	if (event->state > PERF_EVENT_STATE_EXIT)
> -		perf_event_set_state(event, PERF_EVENT_STATE_EXIT);
> -	raw_spin_unlock_irq(&ctx->lock);
> +	perf_remove_from_context(event, detach_flags | DETACH_EXIT);
>
>  	/*
>  	 * Child events can be freed.

Yes. I think this looks good to me to solve this error prints :)


      reply	other threads:[~2024-12-20 15:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-20 10:02 [PATCH v2] events/core: fix acoount failure for event's total_enable_time Yeoreum Yun
2024-12-20 13:33 ` Peter Zijlstra
2024-12-20 14:05   ` Yeoreum Yun
2024-12-20 15:14     ` Peter Zijlstra
2024-12-20 15:26       ` Yeoreum Yun
2024-12-20 15:30         ` Peter Zijlstra
2024-12-20 15:45           ` Yeoreum Yun
2024-12-20 16:23           ` Yeoreum Yun
2025-01-10 16:36             ` Peter Zijlstra
2025-01-28 18:57               ` Yeo Reum Yun
2025-02-25 20:36                 ` Ingo Molnar
2025-03-06 13:43                   ` Yeoreum Yun
2024-12-20 15:28       ` Peter Zijlstra
2024-12-20 15:43         ` Yeoreum Yun [this message]

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=Z2WQrO+kjJ+w2Sur@e129823.arm.com \
    --to=yeoreum.yun@arm.com \
    --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=peterz@infradead.org \
    /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