Skip to contentSkip to conversation

cpufreq: intel_pstate: Eliminate some code duplication

PATCH In review Rafael J. Wysocki 2 participants 2 messages Nov 14, 2025 – Nov 17, 2025

Subsystems (2)
lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH 1/1 cpufreq: intel_pstate: Eliminate some code duplication

From: Rafael J. Wysocki <[email protected]>

To eliminate some code duplication from the intel_pstate driver, move the core_get_val() function body to a new function called get_perf_ctl_val() and make both core_get_val() and atom_get_val() invoke it to carry out the same computation.

No intentional functional impact.

---
 drivers/cpufreq/intel_pstate.c |   28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/cpufreq/intel_pstate.c +14 -14
@@ -2119,6 +2119,18 @@ static void intel_pstate_hwp_enable(stru
 	intel_pstate_update_epp_defaults(cpudata);
 }
 
+static u64 get_perf_ctl_val(int pstate)
+{
+	u64 val;
+
+	val = (u64)pstate << 8;
+	if (READ_ONCE(global.no_turbo) && !READ_ONCE(global.turbo_disabled) &&
+	    cpu_feature_enabled(X86_FEATURE_IDA))
+		val |= (u64)1 << 32;
+
+	return val;
+}
+
 static int atom_get_min_pstate(int not_used)
 {
 	u64 value;
@@ -2145,15 +2157,10 @@ static int atom_get_turbo_pstate(int not
 
 static u64 atom_get_val(struct cpudata *cpudata, int pstate)
 {
-	u64 val;
+	u64 val = get_perf_ctl_val(pstate);
 	int32_t vid_fp;
 	u32 vid;
 
-	val = (u64)pstate << 8;
-	if (READ_ONCE(global.no_turbo) && !READ_ONCE(global.turbo_disabled) &&
-	    cpu_feature_enabled(X86_FEATURE_IDA))
-		val |= (u64)1 << 32;
-
 	vid_fp = cpudata->vid.min + mul_fp(
 		int_tofp(pstate - cpudata->pstate.min_pstate),
 		cpudata->vid.ratio);
@@ -2313,14 +2320,7 @@ static int core_get_turbo_pstate(int cpu
 
 static u64 core_get_val(struct cpudata *cpudata, int pstate)
 {
-	u64 val;
-
-	val = (u64)pstate << 8;
-	if (READ_ONCE(global.no_turbo) && !READ_ONCE(global.turbo_disabled) &&
-	    cpu_feature_enabled(X86_FEATURE_IDA))
-		val |= (u64)1 << 32;
-
-	return val;
+	return get_perf_ctl_val(pstate);
 }
 
 static int knl_get_aperf_mperf_shift(void)
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

To eliminate some code duplication from the intel_pstate driver, move the core_get_val() function body to a new function called get_perf_ctl_val() and make both core_get_val() and atom_get_val() invoke it to carry out the same computation.

No intentional functional impact.

Quoted 64 lines

---
 drivers/cpufreq/intel_pstate.c |   28 ++++++++++++++--------------

 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/cpufreq/intel_pstate.c +0 -0
@@ -2119,6 +2119,18 @@ static void intel_pstate_hwp_enable(stru
  	intel_pstate_update_epp_defaults(cpudata);
  }

drivers/cpufreq/intel_pstate.c +6 -0
+static u64 get_perf_ctl_val(int pstate)
+{
+	u64 val;
+
+	val = (u64)pstate << 8;
+	if (READ_ONCE(global.no_turbo) &&

!READ_ONCE(global.turbo_disabled) &&

drivers/cpufreq/intel_pstate.c +6 -0
+	    cpu_feature_enabled(X86_FEATURE_IDA))
+		val |= (u64)1 << 32;
+
+	return val;
+}
+

 static int atom_get_min_pstate(int not_used)
 {
  u64 value;

drivers/cpufreq/intel_pstate.c +0 -0
@@ -2145,15 +2157,10 @@ static int atom_get_turbo_pstate(int not


 static u64 atom_get_val(struct cpudata *cpudata, int pstate) {

drivers/cpufreq/intel_pstate.c +1 -1
-	u64 val;
+	u64 val = get_perf_ctl_val(pstate);

  int32_t vid_fp;
  u32 vid;

drivers/cpufreq/intel_pstate.c +0 -2
-	val = (u64)pstate << 8;
-	if (READ_ONCE(global.no_turbo) &&

!READ_ONCE(global.turbo_disabled) &&

drivers/cpufreq/intel_pstate.c +0 -3
-	    cpu_feature_enabled(X86_FEATURE_IDA))
-		val |= (u64)1 << 32;
-

  vid_fp = cpudata->vid.min + mul_fp( int_tofp(pstate - cpudata->pstate.min_pstate), cpudata->vid.ratio);

drivers/cpufreq/intel_pstate.c +0 -0
@@ -2313,14 +2320,7 @@ static int core_get_turbo_pstate(int cpu


 static u64 core_get_val(struct cpudata *cpudata, int pstate) {

drivers/cpufreq/intel_pstate.c +0 -4
-	u64 val;
-
-	val = (u64)pstate << 8;
-	if (READ_ONCE(global.no_turbo) &&

!READ_ONCE(global.turbo_disabled) &&

drivers/cpufreq/intel_pstate.c +1 -4
-	    cpu_feature_enabled(X86_FEATURE_IDA))
-		val |= (u64)1 << 32;
-
-	return val;
+	return get_perf_ctl_val(pstate);

 }

 static int knl_get_aperf_mperf_shift(void)