* [PATCH] cpufreq/cppc: fix perf_to_khz conversion exception
@ 2024-04-30 10:12 liwei
2024-05-03 7:42 ` Pierre Gondois
0 siblings, 1 reply; 3+ messages in thread
From: liwei @ 2024-04-30 10:12 UTC (permalink / raw)
To: rafael, lenb, Pierre.Gondois, viresh.kumar
Cc: linux-acpi, linux-kernel, liwei391, liwei728
When the nominal_freq recorded by the kernel is equal to lowest_freq and
the frequency reduction operation is triggered externally, there is a
conversion logic error in cppc_perf_to_khz(), causing the kernel to be
unable to feedback the true frequency.
Fix this by adding the branch processing logic when nominal_freq is equal
to lowest_freq.
Fixes: ec1c7ad47664 ("cpufreq: CPPC: Fix performance/frequency conversion")
Signed-off-by: liwei <liwei728@huawei.com>
---
drivers/acpi/cppc_acpi.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index a40b6f3946ef..92aac6974e0e 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -1869,9 +1869,15 @@ unsigned int cppc_perf_to_khz(struct cppc_perf_caps *caps, unsigned int perf)
u64 mul, div;
if (caps->lowest_freq && caps->nominal_freq) {
- mul = caps->nominal_freq - caps->lowest_freq;
+ /* Avoid the special case when nominal_freq is equal to lowest_freq */
+ if (caps->lowest_freq == caps->nominal_freq) {
+ mul = caps->nominal_freq;
+ div = caps->nominal_perf;
+ } else {
+ mul = caps->nominal_freq - caps->lowest_freq;
+ div = caps->nominal_perf - caps->lowest_perf;
+ }
mul *= KHZ_PER_MHZ;
- div = caps->nominal_perf - caps->lowest_perf;
offset = caps->nominal_freq * KHZ_PER_MHZ -
div64_u64(caps->nominal_perf * mul, div);
} else {
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cpufreq/cppc: fix perf_to_khz conversion exception
2024-04-30 10:12 [PATCH] cpufreq/cppc: fix perf_to_khz conversion exception liwei
@ 2024-05-03 7:42 ` Pierre Gondois
2024-05-06 2:55 ` liwei (JK)
0 siblings, 1 reply; 3+ messages in thread
From: Pierre Gondois @ 2024-05-03 7:42 UTC (permalink / raw)
To: liwei; +Cc: linux-acpi, rafael, linux-kernel, lenb, liwei391, viresh.kumar
Hello Liwei,
Thanks for the fix. I think there might be a similar issue
in cppc_khz_to_perf(),
Regards,
Pierre
On 4/30/24 12:12, liwei wrote:
> When the nominal_freq recorded by the kernel is equal to lowest_freq and
> the frequency reduction operation is triggered externally, there is a
> conversion logic error in cppc_perf_to_khz(), causing the kernel to be
> unable to feedback the true frequency.
>
> Fix this by adding the branch processing logic when nominal_freq is equal
> to lowest_freq.
>
> Fixes: ec1c7ad47664 ("cpufreq: CPPC: Fix performance/frequency conversion")
> Signed-off-by: liwei <liwei728@huawei.com>
> ---
> drivers/acpi/cppc_acpi.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
> index a40b6f3946ef..92aac6974e0e 100644
> --- a/drivers/acpi/cppc_acpi.c
> +++ b/drivers/acpi/cppc_acpi.c
> @@ -1869,9 +1869,15 @@ unsigned int cppc_perf_to_khz(struct cppc_perf_caps *caps, unsigned int perf)
> u64 mul, div;
>
> if (caps->lowest_freq && caps->nominal_freq) {
> - mul = caps->nominal_freq - caps->lowest_freq;
> + /* Avoid the special case when nominal_freq is equal to lowest_freq */
> + if (caps->lowest_freq == caps->nominal_freq) {
> + mul = caps->nominal_freq;
> + div = caps->nominal_perf;
> + } else {
> + mul = caps->nominal_freq - caps->lowest_freq;
> + div = caps->nominal_perf - caps->lowest_perf;
> + }
> mul *= KHZ_PER_MHZ;
> - div = caps->nominal_perf - caps->lowest_perf;
> offset = caps->nominal_freq * KHZ_PER_MHZ -
> div64_u64(caps->nominal_perf * mul, div);
> } else {
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cpufreq/cppc: fix perf_to_khz conversion exception
2024-05-03 7:42 ` Pierre Gondois
@ 2024-05-06 2:55 ` liwei (JK)
0 siblings, 0 replies; 3+ messages in thread
From: liwei (JK) @ 2024-05-06 2:55 UTC (permalink / raw)
To: Pierre Gondois
Cc: linux-acpi, rafael, linux-kernel, lenb, liwei391, viresh.kumar
Hello Pierre,
Thanks for your reminder.
在 2024/5/3 15:42, Pierre Gondois 写道:
> Hello Liwei,
>
> Thanks for the fix. I think there might be a similar issue
> in cppc_khz_to_perf(),
>
> Regards,
> Pierre
>
cppc_khz_to_perf() also has similar issue, I will modify the patch again.
Liwei
> On 4/30/24 12:12, liwei wrote:
>> When the nominal_freq recorded by the kernel is equal to lowest_freq and
>> the frequency reduction operation is triggered externally, there is a
>> conversion logic error in cppc_perf_to_khz(), causing the kernel to be
>> unable to feedback the true frequency.
>>
>> Fix this by adding the branch processing logic when nominal_freq is equal
>> to lowest_freq.
>>
>> Fixes: ec1c7ad47664 ("cpufreq: CPPC: Fix performance/frequency
>> conversion")
>> Signed-off-by: liwei <liwei728@huawei.com>
>> ---
>> drivers/acpi/cppc_acpi.c | 10 ++++++++--
>> 1 file changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
>> index a40b6f3946ef..92aac6974e0e 100644
>> --- a/drivers/acpi/cppc_acpi.c
>> +++ b/drivers/acpi/cppc_acpi.c
>> @@ -1869,9 +1869,15 @@ unsigned int cppc_perf_to_khz(struct
>> cppc_perf_caps *caps, unsigned int perf)
>> u64 mul, div;
>> if (caps->lowest_freq && caps->nominal_freq) {
>> - mul = caps->nominal_freq - caps->lowest_freq;
>> + /* Avoid the special case when nominal_freq is equal to
>> lowest_freq */
>> + if (caps->lowest_freq == caps->nominal_freq) {
>> + mul = caps->nominal_freq;
>> + div = caps->nominal_perf;
>> + } else {
>> + mul = caps->nominal_freq - caps->lowest_freq;
>> + div = caps->nominal_perf - caps->lowest_perf;
>> + }
>> mul *= KHZ_PER_MHZ;
>> - div = caps->nominal_perf - caps->lowest_perf;
>> offset = caps->nominal_freq * KHZ_PER_MHZ -
>> div64_u64(caps->nominal_perf * mul, div);
>> } else {
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-06 2:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-30 10:12 [PATCH] cpufreq/cppc: fix perf_to_khz conversion exception liwei
2024-05-03 7:42 ` Pierre Gondois
2024-05-06 2:55 ` liwei (JK)
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®