[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAB8ipk92xYEkZ_+m+xKnn2Z0DNOkum+6cgHUhSd_gbdzjAbOXA@mail.gmail.com>
Date: Tue, 10 Dec 2024 11:27:52 +0800
From: Xuewen Yan <xuewen.yan94@...il.com>
To: Christian Loehle <christian.loehle@....com>
Cc: Xuewen Yan <xuewen.yan@...soc.com>, rafael@...nel.org, viresh.kumar@...aro.org,
linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org, guohua.yan@...soc.com,
ke.wang@...soc.com
Subject: Re: [RFC PATCH] cpufreq: userspace: Add fast-switch support for userspace
On Mon, Dec 9, 2024 at 6:36 PM Christian Loehle
<christian.loehle@....com> wrote:
>
> On 12/9/24 08:14, Xuewen Yan wrote:
> > Now, the userspace governor does not support userspace,
> > if the driver only use the fast-switch and not add target_index(),
>
> Which driver does that? Is that actually valid?
> No mainline driver from what I can see.
>
Yes, indeed no mainline driver, It's on our own driver.
> > it will cause uerspace not work.
>
> s/uerspace/userspace
> to not work?
>
> > So add fast-switch support for userspace governor.
> >
> > Co-developed-by: Guohua Yan <guohua.yan@...soc.com>
> > Signed-off-by: Guohua Yan <guohua.yan@...soc.com>
> > Signed-off-by: Xuewen Yan <xuewen.yan@...soc.com>
> > ---
> > drivers/cpufreq/cpufreq_userspace.c | 35 +++++++++++++++++++++++++----
> > 1 file changed, 31 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c
> > index 2c42fee76daa..3a99197246ed 100644
> > --- a/drivers/cpufreq/cpufreq_userspace.c
> > +++ b/drivers/cpufreq/cpufreq_userspace.c
> > @@ -21,6 +21,30 @@ struct userspace_policy {
> > struct mutex mutex;
> > };
> >
> > +static int cpufreq_userspace_target_freq(struct cpufreq_policy *policy,
> > + unsigned int target_freq, unsigned int relation)
> > +{
> > + int ret;
>
> not really necessary
In cpufreq_set(), we need the return value.
>
> > +
> > + if (policy->fast_switch_enabled) {
> > + unsigned int idx;
> > +
> > + target_freq = clamp_val(target_freq, policy->min, policy->max);
> > +
> > + if (!policy->freq_table)
> > + return target_freq;
> > +
> > + idx = cpufreq_frequency_table_target(policy, target_freq, relation);
> > + policy->cached_resolved_idx = idx;
> > + policy->cached_target_freq = target_freq;
> > + ret = !cpufreq_driver_fast_switch(policy, policy->freq_table[idx].frequency);
> > + } else {
> > + ret = __cpufreq_driver_target(policy, target_freq, relation);
>
> NIT: could save the indent if you reverse conditions and ret early on !fast_switch
Okay, thanks!
>
> > + }
> > +
> > + return ret;
> > +}
> > +
> > /**
> > * cpufreq_set - set the CPU frequency
> > * @policy: pointer to policy struct where freq is being set
> > @@ -41,7 +65,7 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
> >
> > userspace->setspeed = freq;
> >
> > - ret = __cpufreq_driver_target(policy, freq, CPUFREQ_RELATION_L);
> > + ret = cpufreq_userspace_target_freq(policy, freq, CPUFREQ_RELATION_L);
> > err:
> > mutex_unlock(&userspace->mutex);
> > return ret;
> > @@ -62,6 +86,8 @@ static int cpufreq_userspace_policy_init(struct cpufreq_policy *policy)
> >
> > mutex_init(&userspace->mutex);
> >
> > + cpufreq_enable_fast_switch(policy);
> > +
> > policy->governor_data = userspace;
> > return 0;
> > }
> > @@ -72,6 +98,7 @@ static int cpufreq_userspace_policy_init(struct cpufreq_policy *policy)
> > */
> > static void cpufreq_userspace_policy_exit(struct cpufreq_policy *policy)
> > {
> > + cpufreq_disable_fast_switch(policy);
> > kfree(policy->governor_data);
> > policy->governor_data = NULL;
> > }
> > @@ -112,13 +139,13 @@ static void cpufreq_userspace_policy_limits(struct cpufreq_policy *policy)
> > policy->cpu, policy->min, policy->max, policy->cur, userspace->setspeed);
> >
> > if (policy->max < userspace->setspeed)
> > - __cpufreq_driver_target(policy, policy->max,
> > + cpufreq_userspace_target_freq(policy, policy->max,
> > CPUFREQ_RELATION_H);
> > else if (policy->min > userspace->setspeed)
> > - __cpufreq_driver_target(policy, policy->min,
> > + cpufreq_userspace_target_freq(policy, policy->min,
> > CPUFREQ_RELATION_L);
> > else
> > - __cpufreq_driver_target(policy, userspace->setspeed,
> > + cpufreq_userspace_target_freq(policy, userspace->setspeed,
> > CPUFREQ_RELATION_L);
> >
> > mutex_unlock(&userspace->mutex);
>
BR
Powered by blists - more mailing lists