[Arm-dev] [PATCH v2 01/11] Add cpufreq CPPC fixes

Fri Nov 11 19:02:30 UTC 2016
Duc Dang <dhdang at apm.com>

Integrate 2 upstream fixes to correct the desired
performance calculation in cppc_cpufreq driver.

Signed-off-by: Duc Dang <dhdang at apm.com>
---
 ...C-Avoid-overflow-when-calculating-desired.patch | 31 +++++++++++++++
 ...req-CPPC-Correct-desired_perf-calculation.patch | 46 ++++++++++++++++++++++
 SPECS/kernel-aarch64.spec                          | 13 +++++-
 3 files changed, 89 insertions(+), 1 deletion(-)
 create mode 100644 SOURCES/1001-cpufreq-CPPC-Avoid-overflow-when-calculating-desired.patch
 create mode 100644 SOURCES/1002-cpufreq-CPPC-Correct-desired_perf-calculation.patch

diff --git a/SOURCES/1001-cpufreq-CPPC-Avoid-overflow-when-calculating-desired.patch b/SOURCES/1001-cpufreq-CPPC-Avoid-overflow-when-calculating-desired.patch
new file mode 100644
index 0000000..486f175
--- /dev/null
+++ b/SOURCES/1001-cpufreq-CPPC-Avoid-overflow-when-calculating-desired.patch
@@ -0,0 +1,31 @@
+From 8b5a7d03a65c86a4473bd10b582fc9b6fe434c31 Mon Sep 17 00:00:00 2001
+From: Hoan Tran <hotran at apm.com>
+Date: Wed, 14 Sep 2016 16:08:28 -0700
+Subject: [PATCH 1001/1018] cpufreq: CPPC: Avoid overflow when calculating
+ desired_perf
+
+This patch fixes overflow issue when calculating the desired_perf.
+
+Fixes: ad38677df44b (cpufreq: CPPC: Force reporting values in KHz to fix user space interface)
+Signed-off-by: Hoan Tran <hotran at apm.com>
+Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki at intel.com>
+---
+ 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 6fe8415..61d2ac6 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 = target_freq * policy->max / cppc_dmi_max_khz;
++	cpu->perf_ctrls.desired_perf = (u64)target_freq * policy->max / cppc_dmi_max_khz;
+ 	freqs.old = policy->cur;
+ 	freqs.new = target_freq;
+ 
+-- 
+1.8.3.1
+
diff --git a/SOURCES/1002-cpufreq-CPPC-Correct-desired_perf-calculation.patch b/SOURCES/1002-cpufreq-CPPC-Correct-desired_perf-calculation.patch
new file mode 100644
index 0000000..ec16cc1
--- /dev/null
+++ b/SOURCES/1002-cpufreq-CPPC-Correct-desired_perf-calculation.patch
@@ -0,0 +1,46 @@
+From 3ed005a638f6790c6c80fd8ea99b1b054a55a500 Mon Sep 17 00:00:00 2001
+From: Hoan Tran <hotran at apm.com>
+Date: Thu, 13 Oct 2016 10:33:35 -0700
+Subject: [PATCH 1002/1018] 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
+
+And cppc_cpufreq_set_target() returns if desired_perf is exactly
+the same with the old perf.
+
+Signed-off-by: Hoan Tran <hotran at apm.com>
+Reviewed-by: Prashanth Prakash <pprakash at codeaurora.org>
+Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki at intel.com>
+---
+ drivers/cpufreq/cppc_cpufreq.c | 8 +++++++-
+ 1 file changed, 7 insertions(+), 1 deletion(-)
+
+diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
+index 61d2ac6..c87f655 100644
+--- a/drivers/cpufreq/cppc_cpufreq.c
++++ b/drivers/cpufreq/cppc_cpufreq.c
+@@ -80,11 +80,17 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
+ {
+ 	struct cpudata *cpu;
+ 	struct cpufreq_freqs freqs;
++	u32 desired_perf;
+ 	int ret = 0;
+ 
+ 	cpu = all_cpu_data[policy->cpu];
+ 
+-	cpu->perf_ctrls.desired_perf = (u64)target_freq * policy->max / cppc_dmi_max_khz;
++	desired_perf = (u64)target_freq * cpu->perf_caps.highest_perf / cppc_dmi_max_khz;
++	/* Return if it is exactly the same perf */
++	if (desired_perf == cpu->perf_ctrls.desired_perf)
++		return ret;
++
++	cpu->perf_ctrls.desired_perf = desired_perf;
+ 	freqs.old = policy->cur;
+ 	freqs.new = target_freq;
+ 
+-- 
+1.8.3.1
+
diff --git a/SPECS/kernel-aarch64.spec b/SPECS/kernel-aarch64.spec
index ffaafe7..2aff470 100644
--- a/SPECS/kernel-aarch64.spec
+++ b/SPECS/kernel-aarch64.spec
@@ -12,7 +12,7 @@ Summary: The Linux kernel
 
 %define rpmversion 4.5.0
 %define pkgrelease 15.el7
-%define centupdate 16.el7
+%define centupdate 17.el7
 
 # allow pkg_release to have configurable %{?dist} tag
 %define specrelease %%SPECRELEASE%%
@@ -324,6 +324,10 @@ Source58: config-generic
 Source59: config-debug
 Source60: config-centos-sig
 
+#APM Patches
+Patch1001: 1001-cpufreq-CPPC-Avoid-overflow-when-calculating-desired.patch
+Patch1002: 1002-cpufreq-CPPC-Correct-desired_perf-calculation.patch
+
 # QDF2400 Patches
 Patch4000: 4000-arm64-Define-Qualcomm-Technologies-ARMv8-CPU.patch
 Patch4001: 4001-arm64-Workaround-Falkor-E1003.patch
@@ -657,6 +661,10 @@ if [ ! -d .git ]; then
   git commit -a -q -m "baseline"
 fi
 
+# Aplly APM patches
+git am %{PATCH1001}
+git am %{PATCH1002}
+
 # Apply QDF2400 patches
 git am %{PATCH4000}
 git am %{PATCH4001}
@@ -1434,6 +1442,9 @@ fi
 %kernel_variant_files %{with_debug} kernel-debug debug
 
 %changelog
+* Thu Nov 10 2016 Duc Dang <dhdang at apm.com> [4.5.0-17.el7]
+- Add cpufreq CPPC bug fixes
+
 * Mon Nov 07 2016 Christopher Covington <cov at codeaurora.org> [4.5.0-16.el7]
 - Add git machinery (Jim Perrin)
 
-- 
1.8.3.1