Skip to contentSkip to conversation

cpufreq: CPPC: Correct desired_perf calculation

PATCH Superseded Hoan Tran 4 participants 6 messages Oct 11, 2016 – Oct 12, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Hoan Tran

author
#0 lore raw

PATCH 1/1 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

---
 drivers/cpufreq/cppc_cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cppc_cpufreq.c +1 -1
index 1b2f28f..ab1d4b7 100644
@@ -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;
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 16 lines · Hoan Tran

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

---
 drivers/cpufreq/cppc_cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cppc_cpufreq.c +0 -0
index 1b2f28f..ab1d4b7 100644

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_target(struct cpufreq_policy *policy, · line 90

Quoted 8 lines
drivers/cpufreq/cppc_cpufreq.c +1 -1
@@ -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

author
#2 lore raw

Hi Rafael,

Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Hoan Tran

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

---
 drivers/cpufreq/cppc_cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cppc_cpufreq.c +0 -0
index 1b2f28f..ab1d4b7 100644
@@ -84,7 +84,7 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
 
      cpu = all_cpu_data[policy->cpu];
 
Quoted 9 lines

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_target(struct cpufreq_policy *policy, · line 90

Quoted 6 lines
drivers/cpufreq/cppc_cpufreq.c +1 -1
-     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

Quoted 3 lines

Thanks,
Rafael

maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Hoan Tran
Quoted 15 lines · Hoan Tran

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

---
 drivers/cpufreq/cppc_cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cppc_cpufreq.c +0 -0
index 1b2f28f..ab1d4b7 100644

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_target(struct cpufreq_policy *policy, · line 89

Quoted 7 lines
drivers/cpufreq/cppc_cpufreq.c +1 -1
@@ -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..

Signature · 1 line
viresh
#4 lore raw
In reply to Hoan Tran

Hi Hoan,

Quoted 15 lines · Hoan Tran

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

---
 drivers/cpufreq/cppc_cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cppc_cpufreq.c +0 -0
index 1b2f28f..ab1d4b7 100644

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_target(struct cpufreq_policy *policy, · line 87

Quoted 5 lines
drivers/cpufreq/cppc_cpufreq.c +1 -1
@@ -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

author
#5 lore raw

[Resend with plain text mode]

Hi Prashanth,

Quoted 19 lines · Prashanth

Hi Hoan,

Quoted 16 lines · Hoan Tran

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

---
 drivers/cpufreq/cppc_cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cppc_cpufreq.c +0 -0
index 1b2f28f..ab1d4b7 100644
@@ -84,7 +84,7 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
 
Quoted 7 lines

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_target(struct cpufreq_policy *policy, · line 87

Quoted 4 lines
drivers/cpufreq/cppc_cpufreq.c +1 -1
      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

Quoted 3 lines

Thanks,
Prashanth