Skip to contentSkip to conversation

Reduce the intel_pstate timer overhead

PATCH Superseded Philippe Longepe 2 participants 11 messages Mar 8, 2016 – Mar 10, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v6 cover Reduce the intel_pstate timer overhead

V6: Minor fixes on commit message (Patch 1) + add intel_pstate:

This serie includes the following code optimizations:

Patch 1: Remove extra conversions in pid calculation
Patch 2: Optimize calculation for max/min_perf_adj
Patch 3: Move the intel_pstate_calc_busy into get_target_pstate_use_performance Patch 4: Remove the freq calculation from the intel_pstate_calc_busy function

Philippe Longepe (4):
Remove extra conversions in pid calculation
Optimize calculation for max/min_perf_adj
Move the intel_pstate_calc_busy into get_target_pstate_use_performance
intel_pstate: Remove the freq calculation from the
intel_pstate_calc_busy function

 drivers/cpufreq/intel_pstate.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

v6 cover Reduce the intel_pstate timer overhead

V6: Minor fixes on commit message (Patch 1) + add intel_pstate:

This serie includes the following code optimizations:

Patch 1: Remove extra conversions in pid calculation
Patch 2: Optimize calculation for max/min_perf_adj
Patch 3: Move the intel_pstate_calc_busy into get_target_pstate_use_performance Patch 4: Remove the freq calculation from the intel_pstate_calc_busy function

Philippe Longepe (4):
Remove extra conversions in pid calculation
Optimize calculation for max/min_perf_adj
Move the intel_pstate_calc_busy into get_target_pstate_use_performance
intel_pstate: Remove the freq calculation from the
intel_pstate_calc_busy function

 drivers/cpufreq/intel_pstate.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)
Signature · 1 line
1.9.1
#2 lore raw

PATCH v6 1/4 intel_pstate: Remove extra conversions in pid calculation

In reply to Philippe Longepe

pid->setpoint and pid->deadband can be initialized in fixed point, so we can avoid the int_tofp in pid_calc.

---
 drivers/cpufreq/intel_pstate.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/cpufreq/intel_pstate.c +4 -4
index eb0aef0..114e4e0 100644
@@ -198,8 +198,8 @@ static struct perf_limits *limits = &powersave_limits;
 
 static inline void pid_reset(struct _pid *pid, int setpoint, int busy,
 			     int deadband, int integral) {
-	pid->setpoint = setpoint;
-	pid->deadband  = deadband;
+	pid->setpoint = int_tofp(setpoint);
+	pid->deadband  = int_tofp(deadband);
 	pid->integral  = int_tofp(integral);
 	pid->last_err  = int_tofp(setpoint) - int_tofp(busy);
 }
@@ -225,9 +225,9 @@ static signed int pid_calc(struct _pid *pid, int32_t busy)
 	int32_t pterm, dterm, fp_error;
 	int32_t integral_limit;
 
-	fp_error = int_tofp(pid->setpoint) - busy;
+	fp_error = pid->setpoint - busy;
 
-	if (abs(fp_error) <= int_tofp(pid->deadband))
+	if (abs(fp_error) <= pid->deadband)
 		return 0;
 
 	pterm = mul_fp(pid->p_gain, fp_error);
Signature · 1 line
1.9.1
#3 lore raw

PATCH v6 1/4 intel_pstate: Remove extra conversions in pid calculation

In reply to Philippe Longepe

pid->setpoint and pid->deadband can be initialized in fixed point, so we can avoid the int_tofp in pid_calc.

---
 drivers/cpufreq/intel_pstate.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/cpufreq/intel_pstate.c +4 -4
index eb0aef0..114e4e0 100644
@@ -198,8 +198,8 @@ static struct perf_limits *limits = &powersave_limits;
 
 static inline void pid_reset(struct _pid *pid, int setpoint, int busy,
 			     int deadband, int integral) {
-	pid->setpoint = setpoint;
-	pid->deadband  = deadband;
+	pid->setpoint = int_tofp(setpoint);
+	pid->deadband  = int_tofp(deadband);
 	pid->integral  = int_tofp(integral);
 	pid->last_err  = int_tofp(setpoint) - int_tofp(busy);
 }
@@ -225,9 +225,9 @@ static signed int pid_calc(struct _pid *pid, int32_t busy)
 	int32_t pterm, dterm, fp_error;
 	int32_t integral_limit;
 
-	fp_error = int_tofp(pid->setpoint) - busy;
+	fp_error = pid->setpoint - busy;
 
-	if (abs(fp_error) <= int_tofp(pid->deadband))
+	if (abs(fp_error) <= pid->deadband)
 		return 0;
 
 	pterm = mul_fp(pid->p_gain, fp_error);
Signature · 1 line
1.9.1
#4 lore raw

PATCH v6 2/4 intel_pstate: Optimize calculation for max/min_perf_adj

In reply to Philippe Longepe

mul_fp(int_tofp(A), B) expands to:
((A << FRAC_BITS) * B) >> FRAC_BITS, so the same result can be obtained via simple multiplication A * B. Apply this observation to max_perf * limits->max_perf and max_perf * limits->min_perf in intel_pstate_get_min_max()."

---
 drivers/cpufreq/intel_pstate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpufreq/intel_pstate.c +2 -2
index 114e4e0..c46d23a 100644
@@ -828,11 +828,11 @@ static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
 	 * policy, or by cpu specific default values determined through
 	 * experimentation.
 	 */
-	max_perf_adj = fp_toint(mul_fp(int_tofp(max_perf), limits->max_perf));
+	max_perf_adj = fp_toint(max_perf * limits->max_perf);
 	*max = clamp_t(int, max_perf_adj,
 			cpu->pstate.min_pstate, cpu->pstate.turbo_pstate);
 
-	min_perf = fp_toint(mul_fp(int_tofp(max_perf), limits->min_perf));
+	min_perf = fp_toint(max_perf * limits->min_perf);
 	*min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf);
 }
 
Signature · 1 line
1.9.1
#5 lore raw

PATCH v6 2/4 intel_pstate: Optimize calculation for max/min_perf_adj

In reply to Philippe Longepe

mul_fp(int_tofp(A), B) expands to:
((A << FRAC_BITS) * B) >> FRAC_BITS, so the same result can be obtained via simple multiplication A * B. Apply this observation to max_perf * limits->max_perf and max_perf * limits->min_perf in intel_pstate_get_min_max()."

---
 drivers/cpufreq/intel_pstate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpufreq/intel_pstate.c +2 -2
index 114e4e0..c46d23a 100644
@@ -828,11 +828,11 @@ static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
 	 * policy, or by cpu specific default values determined through
 	 * experimentation.
 	 */
-	max_perf_adj = fp_toint(mul_fp(int_tofp(max_perf), limits->max_perf));
+	max_perf_adj = fp_toint(max_perf * limits->max_perf);
 	*max = clamp_t(int, max_perf_adj,
 			cpu->pstate.min_pstate, cpu->pstate.turbo_pstate);
 
-	min_perf = fp_toint(mul_fp(int_tofp(max_perf), limits->min_perf));
+	min_perf = fp_toint(max_perf * limits->min_perf);
 	*min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf);
 }
 
Signature · 1 line
1.9.1
#6 lore raw

PATCH v6 3/4 intel_pstate: Move the intel_pstate_calc_busy into get_target_pstate_use_performance

In reply to Philippe Longepe

The cpu_load algorithm doesn't need to invoke intel_pstate_calc_busy(), so move that call from intel_pstate_sample() to get_target_pstate_use_performance().

---
 drivers/cpufreq/intel_pstate.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/cpufreq/intel_pstate.c +2 -3
index c46d23a..903341f 100644
@@ -912,8 +912,6 @@ static inline void intel_pstate_sample(struct cpudata *cpu, u64 time)
 	cpu->sample.mperf -= cpu->prev_mperf;
 	cpu->sample.tsc -= cpu->prev_tsc;
 
-	intel_pstate_calc_busy(cpu);
-
 	cpu->prev_aperf = aperf;
 	cpu->prev_mperf = mperf;
 	cpu->prev_tsc = tsc;
@@ -942,7 +940,6 @@ static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu)
 	mperf = cpu->sample.mperf + delta_iowait_mperf;
 	cpu->prev_cummulative_iowait = cummulative_iowait;
 
-
 	/*
 	 * The load can be estimated as the ratio of the mperf counter
 	 * running at a constant frequency during active periods
@@ -960,6 +957,8 @@ static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu)
 	int32_t core_busy, max_pstate, current_pstate, sample_ratio;
 	u64 duration_ns;
 
+	intel_pstate_calc_busy(cpu);
+
 	/*
 	 * core_busy is the ratio of actual performance to max
 	 * max_pstate is the max non turbo pstate available
Signature · 1 line
1.9.1
#7 lore raw

PATCH v6 3/4 intel_pstate: Move the intel_pstate_calc_busy into get_target_pstate_use_performance

In reply to Philippe Longepe

The cpu_load algorithm doesn't need to invoke intel_pstate_calc_busy(), so move that call from intel_pstate_sample() to get_target_pstate_use_performance().

---
 drivers/cpufreq/intel_pstate.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/cpufreq/intel_pstate.c +2 -3
index c46d23a..903341f 100644
@@ -912,8 +912,6 @@ static inline void intel_pstate_sample(struct cpudata *cpu, u64 time)
 	cpu->sample.mperf -= cpu->prev_mperf;
 	cpu->sample.tsc -= cpu->prev_tsc;
 
-	intel_pstate_calc_busy(cpu);
-
 	cpu->prev_aperf = aperf;
 	cpu->prev_mperf = mperf;
 	cpu->prev_tsc = tsc;
@@ -942,7 +940,6 @@ static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu)
 	mperf = cpu->sample.mperf + delta_iowait_mperf;
 	cpu->prev_cummulative_iowait = cummulative_iowait;
 
-
 	/*
 	 * The load can be estimated as the ratio of the mperf counter
 	 * running at a constant frequency during active periods
@@ -960,6 +957,8 @@ static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu)
 	int32_t core_busy, max_pstate, current_pstate, sample_ratio;
 	u64 duration_ns;
 
+	intel_pstate_calc_busy(cpu);
+
 	/*
 	 * core_busy is the ratio of actual performance to max
 	 * max_pstate is the max non turbo pstate available
Signature · 1 line
1.9.1
#8 lore raw

PATCH v6 4/4 intel_pstate: Remove the freq calculation from the intel_pstate_calc_busy function

In reply to Philippe Longepe

Use a helper function to compute the average pstate and call it only where it is needed (only when tracing or in intel_pstate_get).

---
 drivers/cpufreq/intel_pstate.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/cpufreq/intel_pstate.c +8 -8
index 903341f..6e07366 100644
@@ -878,12 +878,6 @@ static inline void intel_pstate_calc_busy(struct cpudata *cpu)
 	core_pct = int_tofp(sample->aperf) * int_tofp(100);
 	core_pct = div64_u64(core_pct, int_tofp(sample->mperf));
 
-	sample->freq = fp_toint(
-		mul_fp(int_tofp(
-			cpu->pstate.max_pstate_physical *
-			cpu->pstate.scaling / 100),
-			core_pct));
-
 	sample->core_pct_busy = (int32_t)core_pct;
 }
 
@@ -917,6 +911,12 @@ static inline void intel_pstate_sample(struct cpudata *cpu, u64 time)
 	cpu->prev_tsc = tsc;
 }
 
+static inline int32_t get_avg_frequency(struct cpudata *cpu)
+{
+	return div64_u64(cpu->pstate.max_pstate_physical * cpu->sample.aperf *
+		cpu->pstate.scaling, cpu->sample.mperf);
+}
+
 static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu)
 {
 	struct sample *sample = &cpu->sample;
@@ -1012,7 +1012,7 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
 		sample->mperf,
 		sample->aperf,
 		sample->tsc,
-		sample->freq);
+		get_avg_frequency(cpu));
 }
 
 static void intel_pstate_update_util(struct update_util_data *data, u64 time,
@@ -1101,7 +1101,7 @@ static unsigned int intel_pstate_get(unsigned int cpu_num)
 	if (!cpu)
 		return 0;
 	sample = &cpu->sample;
-	return sample->freq;
+	return get_avg_frequency(cpu);
 }
 
 static int intel_pstate_set_policy(struct cpufreq_policy *policy)
Signature · 1 line
1.9.1
#9 lore raw

PATCH v6 4/4 intel_pstate: Remove the freq calculation from the intel_pstate_calc_busy function

In reply to Philippe Longepe

Use a helper function to compute the average pstate and call it only where it is needed (only when tracing or in intel_pstate_get).

---
 drivers/cpufreq/intel_pstate.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/cpufreq/intel_pstate.c +8 -8
index 903341f..6e07366 100644
@@ -878,12 +878,6 @@ static inline void intel_pstate_calc_busy(struct cpudata *cpu)
 	core_pct = int_tofp(sample->aperf) * int_tofp(100);
 	core_pct = div64_u64(core_pct, int_tofp(sample->mperf));
 
-	sample->freq = fp_toint(
-		mul_fp(int_tofp(
-			cpu->pstate.max_pstate_physical *
-			cpu->pstate.scaling / 100),
-			core_pct));
-
 	sample->core_pct_busy = (int32_t)core_pct;
 }
 
@@ -917,6 +911,12 @@ static inline void intel_pstate_sample(struct cpudata *cpu, u64 time)
 	cpu->prev_tsc = tsc;
 }
 
+static inline int32_t get_avg_frequency(struct cpudata *cpu)
+{
+	return div64_u64(cpu->pstate.max_pstate_physical * cpu->sample.aperf *
+		cpu->pstate.scaling, cpu->sample.mperf);
+}
+
 static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu)
 {
 	struct sample *sample = &cpu->sample;
@@ -1012,7 +1012,7 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
 		sample->mperf,
 		sample->aperf,
 		sample->tsc,
-		sample->freq);
+		get_avg_frequency(cpu));
 }
 
 static void intel_pstate_update_util(struct update_util_data *data, u64 time,
@@ -1101,7 +1101,7 @@ static unsigned int intel_pstate_get(unsigned int cpu_num)
 	if (!cpu)
 		return 0;
 	sample = &cpu->sample;
-	return sample->freq;
+	return get_avg_frequency(cpu);
 }
 
 static int intel_pstate_set_policy(struct cpufreq_policy *policy)
Signature · 1 line
1.9.1
#10 lore raw
In reply to Philippe Longepe
Quoted 16 lines · Philippe Longepe

V6: Minor fixes on commit message (Patch 1) + add intel_pstate:

This serie includes the following code optimizations:

Patch 1: Remove extra conversions in pid calculation
Patch 2: Optimize calculation for max/min_perf_adj
Patch 3: Move the intel_pstate_calc_busy into get_target_pstate_use_performance Patch 4: Remove the freq calculation from the intel_pstate_calc_busy function

Philippe Longepe (4):
Remove extra conversions in pid calculation
Optimize calculation for max/min_perf_adj
Move the intel_pstate_calc_busy into get_target_pstate_use_performance
intel_pstate: Remove the freq calculation from the
intel_pstate_calc_busy function

Quoted 2 lines
 drivers/cpufreq/intel_pstate.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

All applied, [2-4/4] with Srinivas' ACKs.

Thanks,
Rafael