2016-10-11 21:36:21

by Hoan Tran

[permalink] [raw]
Subject: [PATCH] cpufreq: CPPC: Correct desired_perf calculation

The desired_perf is an abstract performance number. Its value should
be in the range of [lowest perf, highest perf] of CPPC.
The correct calculation is
desired_perf = freq * cppc_highest_perf / cppc_dmi_max_khz

Signed-off-by: Hoan Tran <[email protected]>
---
drivers/cpufreq/cppc_cpufreq.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index 1b2f28f..ab1d4b7 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -84,7 +84,7 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,

cpu = all_cpu_data[policy->cpu];

- cpu->perf_ctrls.desired_perf = (u64)target_freq * policy->max / cppc_dmi_max_khz;
+ cpu->perf_ctrls.desired_perf = (u64)target_freq * cpu->perf_caps.highest_perf / cppc_dmi_max_khz;
freqs.old = policy->cur;
freqs.new = target_freq;

--
1.9.1


2016-10-11 21:43:46

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: CPPC: Correct desired_perf calculation

On Tuesday, October 11, 2016 02:12:00 PM Hoan Tran wrote:
> The desired_perf is an abstract performance number. Its value should
> be in the range of [lowest perf, highest perf] of CPPC.
> The correct calculation is
> desired_perf = freq * cppc_highest_perf / cppc_dmi_max_khz
>
> Signed-off-by: Hoan Tran <[email protected]>
> ---
> drivers/cpufreq/cppc_cpufreq.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
> index 1b2f28f..ab1d4b7 100644
> --- a/drivers/cpufreq/cppc_cpufreq.c
> +++ b/drivers/cpufreq/cppc_cpufreq.c
> @@ -84,7 +84,7 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
>
> cpu = all_cpu_data[policy->cpu];
>
> - cpu->perf_ctrls.desired_perf = (u64)target_freq * policy->max / cppc_dmi_max_khz;
> + cpu->perf_ctrls.desired_perf = (u64)target_freq * cpu->perf_caps.highest_perf / cppc_dmi_max_khz;
> freqs.old = policy->cur;
> freqs.new = target_freq;
>
>

This patch has already been applied AFAICS.

Thanks,
Rafael

2016-10-11 22:38:48

by Hoan Tran

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: CPPC: Correct desired_perf calculation

Hi Rafael,

On Tue, Oct 11, 2016 at 2:50 PM, Rafael J. Wysocki <[email protected]> wrote:
> On Tuesday, October 11, 2016 02:12:00 PM Hoan Tran wrote:
>> The desired_perf is an abstract performance number. Its value should
>> be in the range of [lowest perf, highest perf] of CPPC.
>> The correct calculation is
>> desired_perf = freq * cppc_highest_perf / cppc_dmi_max_khz
>>
>> Signed-off-by: Hoan Tran <[email protected]>
>> ---
>> drivers/cpufreq/cppc_cpufreq.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
>> index 1b2f28f..ab1d4b7 100644
>> --- a/drivers/cpufreq/cppc_cpufreq.c
>> +++ b/drivers/cpufreq/cppc_cpufreq.c
>> @@ -84,7 +84,7 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
>>
>> cpu = all_cpu_data[policy->cpu];
>>
>> - cpu->perf_ctrls.desired_perf = (u64)target_freq * policy->max / cppc_dmi_max_khz;
>> + cpu->perf_ctrls.desired_perf = (u64)target_freq * cpu->perf_caps.highest_perf / cppc_dmi_max_khz;
>> freqs.old = policy->cur;
>> freqs.new = target_freq;
>>
>>
>
> This patch has already been applied AFAICS.
>

You mean this applied patch "cpufreq: CPPC: Avoid overflow when
calculating desired_perf"

This is another the bug, not the overflow bug.

Thanks
Hoan



> Thanks,
> Rafael
>

2016-10-12 03:29:10

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: CPPC: Correct desired_perf calculation

On 11-10-16, 14:12, Hoan Tran wrote:
> The desired_perf is an abstract performance number. Its value should
> be in the range of [lowest perf, highest perf] of CPPC.
> The correct calculation is
> desired_perf = freq * cppc_highest_perf / cppc_dmi_max_khz
>
> Signed-off-by: Hoan Tran <[email protected]>
> ---
> drivers/cpufreq/cppc_cpufreq.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
> index 1b2f28f..ab1d4b7 100644
> --- a/drivers/cpufreq/cppc_cpufreq.c
> +++ b/drivers/cpufreq/cppc_cpufreq.c
> @@ -84,7 +84,7 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
>
> cpu = all_cpu_data[policy->cpu];
>
> - cpu->perf_ctrls.desired_perf = (u64)target_freq * policy->max / cppc_dmi_max_khz;
> + cpu->perf_ctrls.desired_perf = (u64)target_freq * cpu->perf_caps.highest_perf / cppc_dmi_max_khz;
> freqs.old = policy->cur;
> freqs.new = target_freq;

I am not sure what the calculations should be like, but I don't have
any objections against applying this..

Acked-by: Viresh Kumar <[email protected]>

--
viresh

2016-10-12 15:36:46

by Prakash, Prashanth

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: CPPC: Correct desired_perf calculation

Hi Hoan,

On 10/11/2016 3:12 PM, Hoan Tran wrote:
> The desired_perf is an abstract performance number. Its value should
> be in the range of [lowest perf, highest perf] of CPPC.
> The correct calculation is
> desired_perf = freq * cppc_highest_perf / cppc_dmi_max_khz
>
> Signed-off-by: Hoan Tran <[email protected]>
> ---
> drivers/cpufreq/cppc_cpufreq.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
> index 1b2f28f..ab1d4b7 100644
> --- a/drivers/cpufreq/cppc_cpufreq.c
> +++ b/drivers/cpufreq/cppc_cpufreq.c
> @@ -84,7 +84,7 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
>
> cpu = all_cpu_data[policy->cpu];
>
> - cpu->perf_ctrls.desired_perf = (u64)target_freq * policy->max / cppc_dmi_max_khz;
> + cpu->perf_ctrls.desired_perf = (u64)target_freq * cpu->perf_caps.highest_perf / cppc_dmi_max_khz;
The patch looks good, I suppose we can add a small optimization. We can do a simple check
to see if the newly computed desired_perf is same as old one, If it is same we can just return
here instead of calling cppc_set_perf with same desired_perf value.

Thanks,
Prashanth

2016-10-12 17:35:30

by Hoan Tran

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: CPPC: Correct desired_perf calculation

[Resend with plain text mode]

Hi Prashanth,

On Wed, Oct 12, 2016 at 8:36 AM, Prakash, Prashanth
<[email protected]> wrote:
> Hi Hoan,
>
> On 10/11/2016 3:12 PM, Hoan Tran wrote:
>> The desired_perf is an abstract performance number. Its value should
>> be in the range of [lowest perf, highest perf] of CPPC.
>> The correct calculation is
>> desired_perf = freq * cppc_highest_perf / cppc_dmi_max_khz
>>
>> Signed-off-by: Hoan Tran <[email protected]>
>> ---
>> drivers/cpufreq/cppc_cpufreq.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
>> index 1b2f28f..ab1d4b7 100644
>> --- a/drivers/cpufreq/cppc_cpufreq.c
>> +++ b/drivers/cpufreq/cppc_cpufreq.c
>> @@ -84,7 +84,7 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
>>
>> cpu = all_cpu_data[policy->cpu];
>>
>> - cpu->perf_ctrls.desired_perf = (u64)target_freq * policy->max / cppc_dmi_max_khz;
>> + cpu->perf_ctrls.desired_perf = (u64)target_freq * cpu->perf_caps.highest_perf / cppc_dmi_max_khz;
> The patch looks good, I suppose we can add a small optimization. We can do a simple check
> to see if the newly computed desired_perf is same as old one, If it is same we can just return
> here instead of calling cppc_set_perf with same desired_perf value.

That's a good point. I can add a check into this patch.

Thanks
Hoan

>
> Thanks,
> Prashanth