Re: [PATCH 1/2] cpufreq: schedutil: Fix superfluous updates caused by need_freq_update
From: Xuewen Yan
Date: Wed Apr 09 2025 - 22:13:38 EST
On Thu, Apr 10, 2025 at 10:09 AM Sultan Alsawaf <sultan@xxxxxxxxxxxxxxx> wrote:
>
> On Thu, Apr 10, 2025 at 10:06:41AM +0800, Xuewen Yan wrote:
> > On Thu, Apr 10, 2025 at 9:49 AM Sultan Alsawaf <sultan@xxxxxxxxxxxxxxx> wrote:
> > >
> > > On Wed, Apr 09, 2025 at 07:48:05PM +0800, Xuewen Yan wrote:
> > > > Or can we modify it as follows?
> > > >
> > > > -->8--
> > > >
> > > > diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
> > > > index 1a19d69b91ed..0e8d3b92ffe7 100644
> > > > --- a/kernel/sched/cpufreq_schedutil.c
> > > > +++ b/kernel/sched/cpufreq_schedutil.c
> > > > @@ -83,7 +83,7 @@ static bool sugov_should_update_freq(struct
> > > > sugov_policy *sg_policy, u64 time)
> > > >
> > > > if (unlikely(sg_policy->limits_changed)) {
> > > > sg_policy->limits_changed = false;
> > > > - sg_policy->need_freq_update =
> > > > cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS);
> > > > + sg_policy->need_freq_update = true;
> > > > return true;
> > > > }
> > > >
> > > > @@ -95,11 +95,15 @@ static bool sugov_should_update_freq(struct
> > > > sugov_policy *sg_policy, u64 time)
> > > > static bool sugov_update_next_freq(struct sugov_policy *sg_policy, u64 time,
> > > > unsigned int next_freq)
> > > > {
> > > > - if (sg_policy->need_freq_update)
> > > > + if (sg_policy->need_freq_update) {
> > > > sg_policy->need_freq_update = false;
> > > > - else if (sg_policy->next_freq == next_freq)
> > > > - return false;
> > > > + if (cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS))
> > > > + goto change;
> > > > + }
> > > >
> > > > + if (sg_policy->next_freq == next_freq)
> > > > + return false;
> > > > +change:
> > > > sg_policy->next_freq = next_freq;
> > > > sg_policy->last_freq_update_time = time;
> > >
> > > If CPUFREQ_NEED_UPDATE_LIMITS isn't specified, then there's no need to request a
> > > frequency switch from the driver when the current frequency is exactly the same
> > > as the next frequency.
> >
> > Yes, the following check would return false:
> >
> > + if (sg_policy->next_freq == next_freq)
> > + return false;
>
> But what does that change fix? In fact, that change causes a limits update to
> trigger a frequency switch request to the driver even when the new frequency is
> the same as the current one.
We set the sg_policy->need_freq_update = false instead of
sg_policy->need_freq_update =
cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS),
to fix the original issue, and then add the
+ if (cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS))
+ goto change;
to allow cpufreq to update when CPUFREQ_NEED_UPDATE_LIMITS is set.
>
> Sultan