From: Peter Zijlstra <peterz@infradead.org>
To: Yeoreum Yun <yeoreum.yun@arm.com>
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, 10 Jan 2025 17:36:43 +0100 [thread overview]
Message-ID: <20250110163643.GB4213@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <Z2WaC0CqSwU5Ux1B@e129823.arm.com>
On Fri, Dec 20, 2024 at 04:23:39PM +0000, Yeoreum Yun wrote:
> > > diff --git a/kernel/events/core.c b/kernel/events/core.c
> > > index 065f9188b44a..71ed8f847b04 100644
> > > --- a/kernel/events/core.c
> > > +++ b/kernel/events/core.c
> > > @@ -2432,6 +2432,7 @@ __perf_remove_from_context(struct perf_event *event,
> > > if (flags & DETACH_DEAD)
> > > event->pending_disable = 1;
> > > event_sched_out(event, ctx);
> > > + perf_event_update_time(event);
> > > if (flags & DETACH_GROUP)
> > > perf_group_detach(event);
> > > if (flags & DETACH_CHILD)
> >
>
> This patch doesn't work when the event is child event.
> In case of parent's event, when you see the list_del_event(),
> the total_enable_time is updated properly by changing state with
> PERF_EVENT_STATE_OFF.
>
> However, child event's total_enable_time is added before list_del_event.
> So, the missing total_enable_time isn't added to parents event and the
> error print happens.
>
> So, I think it wouldn't be possible to update time with set_state.
> instead I think it should update total_enable_time before
> child's total_enable_time is added to parents' child_total_enable_time
>
> like
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 065f9188b44a..d27717c44924 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -13337,6 +13337,7 @@ static void sync_child_event(struct perf_event *child_event)
> }
>
> child_val = perf_event_count(child_event, false);
> + perf_event_update_time(child_event);
>
> /*
> * Add back the child's count to the parent's count:
Well, that again violates the rule that we update time on state change.
AFAICT there is no issue with simply moving the perf_event_set_state()
up a few lines in __perf_remove_from_context().
Notably event_sched_out() will already put us in OFF state; and nothing
after that cares about further states AFAICT.
So isn't the below the simpler solution?
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2438,14 +2438,13 @@ __perf_remove_from_context(struct perf_e
state = PERF_EVENT_STATE_DEAD;
}
event_sched_out(event, ctx);
+ perf_event_set_state(event, min(event->state, state));
if (flags & DETACH_GROUP)
perf_group_detach(event);
if (flags & DETACH_CHILD)
perf_child_detach(event);
list_del_event(event, ctx);
- perf_event_set_state(event, min(event->state, state));
-
if (!pmu_ctx->nr_events) {
pmu_ctx->rotate_necessary = 0;
next prev parent reply other threads:[~2025-01-10 16:36 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 [this message]
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
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=20250110163643.GB4213@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=yeoreum.yun@arm.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