Re: [PATCH V2 01/15] perf: Fix the throttle logic for a group

From: Leo Yan
Date: Fri May 16 2025 - 08:52:05 EST


On Thu, May 15, 2025 at 08:55:05AM -0400, Liang, Kan wrote:

[...]

> >> +static void perf_event_unthrottle_group(struct perf_event *event, bool start)
> >> +{
> >> + struct perf_event *sibling, *leader = event->group_leader;
> >> +
> >> + perf_event_unthrottle(leader, leader != event || start);
> >> + for_each_sibling_event(sibling, leader)
> >> + perf_event_unthrottle(sibling, sibling != event || start);
> >
> > Seems to me that the condition "leader != event || start" is bit tricky
> > (similarly for the check "sibling != event || start").
> >
> > If a session sets the frequency (with option -F in perf tool), the
> > following flow is triggered:
> >
> > perf_adjust_freq_unthr_events()
> > `> perf_event_unthrottle_group(event, false);
> >
> > The argument "start" is false, so all sibling events will be enabled,
> > but the event pointed by the "event" argument remains disabled.
>
> Right. Because the following code will adjust the period of the event
> and start it.
> The PMU is disabled at the moment. There is no difference in starting
> the leader first or the member first.

Thanks for explaination. In the case above, as you said, all events will
be enabled either in perf_event_unthrottle_group() or in
perf_adjust_freq_unthr_events() with a recalculated period.

Just a minor suggestion. Seems to me, the parameter "start" actually
means "only_enable_sibling". For more readable, the function can be
refine as:

static void perf_event_unthrottle_group(struct perf_event *event,
bool only_enable_sibling)
{
struct perf_event *sibling, *leader = event->group_leader;

perf_event_unthrottle(leader,
only_enable_sibling ? leader != event : true);
...
}

Thanks,
Leo