Skip to contentSkip to conversation

cpufreq / intel_pstate: Optimize intel_pstate_set_policy

PATCH In review Srinivas Pandruvada 3 participants 3 messages Apr 9, 2013 – Apr 10, 2013

Subsystems (2)
lore
Share & tools
lore

Srinivas Pandruvada

author maintainer
#0 lore raw

PATCH 1/1 cpufreq / intel_pstate: Optimize intel_pstate_set_policy

This function is called quite often from other subsystems. Removed unused call to intel_pstate_get_min_max(). Also when "policy->policy == CPUFREQ_POLICY_PERFORMANCE", then no need to do calculations as the limits will be forced anyway. Also corrected filename in the header.

---
 drivers/cpufreq/intel_pstate.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/cpufreq/intel_pstate.c +9 -12
index f6dd1e7..f3729d4 100644
@@ -1,5 +1,5 @@
 /*
- * cpufreq_snb.c: Native P state management for Intel processors
+ * intel_pstate.c: Native P state management for Intel processors
  *
  * (C) Copyright 2012 Intel Corporation
  * Author: Dirk Brandewie <[email protected]>
@@ -658,30 +658,27 @@ static unsigned int intel_pstate_get(unsigned int cpu_num)
 static int intel_pstate_set_policy(struct cpufreq_policy *policy)
 {
 	struct cpudata *cpu;
-	int min, max;
 
 	cpu = all_cpu_data[policy->cpu];
 
 	if (!policy->cpuinfo.max_freq)
 		return -ENODEV;
 
-	intel_pstate_get_min_max(cpu, &min, &max);
-
-	limits.min_perf_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
-	limits.min_perf_pct = clamp_t(int, limits.min_perf_pct, 0 , 100);
-	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
-
-	limits.max_perf_pct = policy->max * 100 / policy->cpuinfo.max_freq;
-	limits.max_perf_pct = clamp_t(int, limits.max_perf_pct, 0 , 100);
-	limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
-
 	if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) {
 		limits.min_perf_pct = 100;
 		limits.min_perf = int_tofp(1);
 		limits.max_perf_pct = 100;
 		limits.max_perf = int_tofp(1);
 		limits.no_turbo = 0;
+		return 0;
 	}
+	limits.min_perf_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
+	limits.min_perf_pct = clamp_t(int, limits.min_perf_pct, 0 , 100);
+	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
+
+	limits.max_perf_pct = policy->max * 100 / policy->cpuinfo.max_freq;
+	limits.max_perf_pct = clamp_t(int, limits.max_perf_pct, 0 , 100);
+	limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
 
 	return 0;
 }
Signature · 1 line
1.7.11.7
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Srinivas Pandruvada

This function is called quite often from other subsystems. Removed unused call to intel_pstate_get_min_max(). Also when "policy->policy == CPUFREQ_POLICY_PERFORMANCE", then no need to do calculations as the limits will be forced anyway.

Also corrected filename in the header.

Probably separate this out in a different patch.

Quoted 42 lines
---
 drivers/cpufreq/intel_pstate.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/cpufreq/intel_pstate.c +1 -12
index f6dd1e7..f3729d4 100644
@@ -1,5 +1,5 @@
 /*
- * cpufreq_snb.c: Native P state management for Intel processors
+ * intel_pstate.c: Native P state management for Intel processors
  *
  * (C) Copyright 2012 Intel Corporation
  * Author: Dirk Brandewie <[email protected]>
@@ -658,30 +658,27 @@ static unsigned int intel_pstate_get(unsigned int cpu_num)
 static int intel_pstate_set_policy(struct cpufreq_policy *policy)
 {
        struct cpudata *cpu;
-       int min, max;
 
        cpu = all_cpu_data[policy->cpu];
 
        if (!policy->cpuinfo.max_freq)
                return -ENODEV;
 
-       intel_pstate_get_min_max(cpu, &min, &max);
-
-       limits.min_perf_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
-       limits.min_perf_pct = clamp_t(int, limits.min_perf_pct, 0 , 100);
-       limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
-
-       limits.max_perf_pct = policy->max * 100 / policy->cpuinfo.max_freq;
-       limits.max_perf_pct = clamp_t(int, limits.max_perf_pct, 0 , 100);
-       limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
-
        if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) {
                limits.min_perf_pct = 100;
                limits.min_perf = int_tofp(1);
                limits.max_perf_pct = 100;
                limits.max_perf = int_tofp(1);

drivers/cpufreq/intel_pstate.c static unsigned int intel_pstate_get(unsigned int cpu_num) · line 681

Quoted 10 lines
drivers/cpufreq/intel_pstate.c +8 -0
                limits.no_turbo = 0;
+               return 0;
        }
+       limits.min_perf_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
+       limits.min_perf_pct = clamp_t(int, limits.min_perf_pct, 0 , 100);
+       limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
+
+       limits.max_perf_pct = policy->max * 100 / policy->cpuinfo.max_freq;
+       limits.max_perf_pct = clamp_t(int, limits.max_perf_pct, 0 , 100);
+       limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));

Otherwise it looks fine:

#2 lore raw
Quoted 66 lines · Viresh Kumar
Quoted 6 lines · Srinivas Pandruvada

This function is called quite often from other subsystems. Removed unused call to intel_pstate_get_min_max(). Also when "policy->policy == CPUFREQ_POLICY_PERFORMANCE", then no need to do calculations as the limits will be forced anyway.

Also corrected filename in the header.

Probably separate this out in a different patch.

Quoted 42 lines
---
 drivers/cpufreq/intel_pstate.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/cpufreq/intel_pstate.c +1 -12
index f6dd1e7..f3729d4 100644
@@ -1,5 +1,5 @@
 /*
- * cpufreq_snb.c: Native P state management for Intel processors
+ * intel_pstate.c: Native P state management for Intel processors
  *
  * (C) Copyright 2012 Intel Corporation
  * Author: Dirk Brandewie <[email protected]>
@@ -658,30 +658,27 @@ static unsigned int intel_pstate_get(unsigned int cpu_num)
 static int intel_pstate_set_policy(struct cpufreq_policy *policy)
 {
        struct cpudata *cpu;
-       int min, max;
 
        cpu = all_cpu_data[policy->cpu];
 
        if (!policy->cpuinfo.max_freq)
                return -ENODEV;
 
-       intel_pstate_get_min_max(cpu, &min, &max);
-
-       limits.min_perf_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
-       limits.min_perf_pct = clamp_t(int, limits.min_perf_pct, 0 , 100);
-       limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
-
-       limits.max_perf_pct = policy->max * 100 / policy->cpuinfo.max_freq;
-       limits.max_perf_pct = clamp_t(int, limits.max_perf_pct, 0 , 100);
-       limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
-
        if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) {
                limits.min_perf_pct = 100;
                limits.min_perf = int_tofp(1);
                limits.max_perf_pct = 100;
                limits.max_perf = int_tofp(1);

drivers/cpufreq/intel_pstate.c static unsigned int intel_pstate_get(unsigned int cpu_num) · line 681

Quoted 10 lines
drivers/cpufreq/intel_pstate.c +8 -0
                limits.no_turbo = 0;
+               return 0;
        }
+       limits.min_perf_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
+       limits.min_perf_pct = clamp_t(int, limits.min_perf_pct, 0 , 100);
+       limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
+
+       limits.max_perf_pct = policy->max * 100 / policy->cpuinfo.max_freq;
+       limits.max_perf_pct = clamp_t(int, limits.max_perf_pct, 0 , 100);
+       limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));

Otherwise it looks fine:

Quoted 1 line

Thanks!

Applied to my bleeding-edge branch and will go to linux-next after build testing.

Thanks,
Rafael

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.