Re: [RFC PATCH] cpufreq: userspace: Add fast-switch support for userspace

From: Christian Loehle
Date: Tue Dec 10 2024 - 05:21:08 EST


On 12/10/24 03:27, Xuewen Yan wrote:
> On Mon, Dec 9, 2024 at 6:36 PM Christian Loehle
> <christian.loehle@xxxxxxx> 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.

Fair enough.
There seems to be handling for that case in cpufreq anyway.

>
>>> 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@xxxxxxxxxx>
>>> Signed-off-by: Guohua Yan <guohua.yan@xxxxxxxxxx>
>>> Signed-off-by: Xuewen Yan <xuewen.yan@xxxxxxxxxx>
>>> ---
>>> 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.

Sorry for not being clear enough, I suggested rewriting it
like this, although personal preference.

---
static int cpufreq_userspace_target_freq(struct cpufreq_policy *policy,
unsigned int target_freq, unsigned int relation)
{
unsigned int idx;

if (!policy->fast_switch_enabled)
return __cpufreq_driver_target(policy, target_freq, relation);

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;
return !cpufreq_driver_fast_switch(policy, policy->freq_table[idx].frequency);
}