Re: [PATCH v3 1/3] cpufreq: mediatek: using global lock avoid race condition

From: Chun-Jen Tseng (曾俊仁)
Date: Sun Mar 23 2025 - 23:21:33 EST


Hi viresh,

I think the best configuration sequence is as follows:
cpufreq policy -> set frequency -> CCI governor get
CPUFREQ_POSTCHANGE NB -> choose CCI frequency -> set CCI frequency

However, in drivers/devfreq/governor_passive.c#L77,
get_target_freq_with_cpufreq() retrieves the current frequency of each
policy,
and it determines the CCI frequency based on the frequency of each
policy.

But if policy-0 and policy-6 enter simultaneously, the CCI governor
might get an incorrect frequency.

cpufreq policy-0 -> set frequency -> CCI governor get
CPUFREQ_POSTCHANGE NB -> choose CCI frequency -> set CCI frequency
=> during this time, the CCI governor gets policy-0 and policy-6, BUT
policy-6 may change frequency by cpufreq driver at the same time.

Therefore, I want to change it so that only one policy can perform the
set frequency action at a time to avoid CCI running at the wrong
frequency.

BRs,

Mark Tseng

On Fri, 2025-03-21 at 11:31 +0530, Viresh Kumar wrote:
>
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>
>
> On 21-03-25, 05:32, Chun-Jen Tseng (曾俊仁) wrote:
> > I add a global lock related to the CCI driver.
> >
> > This is because the CCI needs to obtain the frequencies of policy-0
> > and
> > policy-6 to determine its own frequency.
> >
> > If policy-0 and policy-6 are set simultaneously, it may cause the
> > CCI
> > to select the wrong frequency.
> >
> > Therefore, I hope to change the setting flow to the following:
> >    policy-0 or policy-6 -> set frequency -> CCI receives
> > notification -
> > set CCI frequency
>
> Can you please point to the code where this race exists ? I am not
> sure I fully understand it as of now. If the race is present in
> another driver, CCI ?, then shouldn't it be fixed there instead ?
>
> --
> viresh