mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "lihuisong (C)" <lihuisong@huawei.com>
To: Viresh Kumar <viresh.kumar@linaro.org>,
	Pengjie Zhang <zhangpengjie2@huawei.com>
Cc: <rafael@kernel.org>, <linux-pm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <zhanjie9@hisilicon.com>,
	<zhenglifeng1@huawei.com>, <yubowen8@huawei.com>,
	<linhongye@h-partners.com>, <linuxarm@huawei.com>,
	<jonathan.cameron@huawei.com>, <wangzhi12@huawei.com>
Subject: Re: [RFC PATCH] cpufreq: userspace: make scaling_setspeed return the actual requested frequency
Date: Tue, 20 Jan 2026 09:09:34 +0800	[thread overview]
Message-ID: <7ee9b7a2-db18-48f1-804a-8a4c8a8d05a3@huawei.com> (raw)
In-Reply-To: <ny7npyivbpk3zaf3dm6h3ves4azp75hzmrqmpiex3nauuzrzmt@zf3rto3vrjbq>


On 1/19/2026 4:28 PM, Viresh Kumar wrote:
> On 16-01-26, 17:46, Pengjie Zhang wrote:
>> According to the Linux kernel ABI documentation for 'scaling_setspeed':
>>    "It returns the last frequency requested by the governor (in kHz) or
>>     can be written to in order to set a new frequency for the policy."
>>
>> However, the current implementation of show_speed() returns 'policy->cur'.
>> 'policy->cur' represents the frequency after the driver has
>> resolved the request against the hardware frequency table and applied
>> policy limits (min/max).
>>
>> This creates a discrepancy between the documentation/user expectation and
>> the actual code behavior. For instance:
>>
>> 1. User writes a value to 'scaling_setspeed' that is not in the OPP table
>>     (e.g., user asks for A, driver rounds it to B).
>> 2. User reads 'scaling_setspeed'.
>> 3. Code returns B ('policy->cur').
>> 4. User expects A (the "frequency requested"), but gets B.
>>
>> This patch changes show_speed() to return 'userspace->setspeed', which
>> stores the actual value last requested by the user. This restores the
>> read/write symmetry of the attribute and aligns the code with the ABI
>> description.
>>
>> The effective frequency can still be observed via 'scaling_cur_freq' or
>> 'cpuinfo_cur_freq', preserving the distinction between "what was
>> requested" (setspeed) and "what is effective" (cur_freq).
>>
>> Signed-off-by: Pengjie Zhang <zhangpengjie2@huawei.com>
>> ---
>>   drivers/cpufreq/cpufreq_userspace.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c
>> index 77d62152cd38..4bd62e6c5c51 100644
>> --- a/drivers/cpufreq/cpufreq_userspace.c
>> +++ b/drivers/cpufreq/cpufreq_userspace.c
>> @@ -49,7 +49,9 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
>>   
>>   static ssize_t show_speed(struct cpufreq_policy *policy, char *buf)
>>   {
>> -	return sprintf(buf, "%u\n", policy->cur);
>> +	struct userspace_policy *userspace = policy->governor_data;
>> +
>> +	return sprintf(buf, "%u\n", userspace->setspeed);
>>   }
>>   
>>   static int cpufreq_userspace_policy_init(struct cpufreq_policy *policy)
> Looks okay to me.
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
This fix is more reasonable. Each interface has its own responsibility 
and no repeat.
Acked-by: lihuisong@huawei.com

  reply	other threads:[~2026-01-20  1:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16  9:46 Pengjie Zhang
2026-01-19  8:28 ` Viresh Kumar
2026-01-20  1:09   ` lihuisong (C) [this message]
2026-01-28 21:27   ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7ee9b7a2-db18-48f1-804a-8a4c8a8d05a3@huawei.com \
    --to=lihuisong@huawei.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linhongye@h-partners.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=rafael@kernel.org \
    --cc=viresh.kumar@linaro.org \
    --cc=wangzhi12@huawei.com \
    --cc=yubowen8@huawei.com \
    --cc=zhangpengjie2@huawei.com \
    --cc=zhanjie9@hisilicon.com \
    --cc=zhenglifeng1@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®