Skip to contentSkip to conversation

Cleanups for cpufreq

PATCH Superseded Nishanth Menon 1 participant 6 messages May 13, 2011

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Cleanups for cpufreq

Hi,
a few cleanups for cpufreq to include a couple of bugfixes we found as part of dvfs testing and code review.

Testing done: OMAP4SDP4430 - I think the only major platform would be omap2 - but I doubt it was functional previously - if someone has a chance to give it a whirl, please do, as I dont have access to an OMAP2 platform atm :(.

Applies on top of:
git://git.kernel.org/pub/scm/linux/kernel/git/khilman/linux-omap-pm.git
branch: pm-wip/cpufreq

Nishanth Menon (5):
OMAP2+: cpufreq: free up table on exit
OMAP2+: cpufreq: handle invalid cpufreq table
OMAP2+: cpufreq: minor comment cleanup
OMAP2: cpufreq: use clk_init_cpufreq_table if OPPs not available OMAP2+: cpufreq: use cpufreq_frequency_table_target

 arch/arm/mach-omap2/omap2plus-cpufreq.c |   56 +++++++++++++++++++++++++------
 1 files changed, 45 insertions(+), 11 deletions(-)

Regards,
Nishanth Menon

#1 lore raw

PATCH 1/5 OMAP2+: cpufreq: free up table on exit

freq_table allocated by opp_init_cpufreq_table in omap_cpu_init needs to be freed in omap_cpu_exit.

---
 arch/arm/mach-omap2/omap2plus-cpufreq.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/omap2plus-cpufreq.c +3 -0
index d53ce23..e38ebb8 100644
@@ -26,6 +26,7 @@
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/opp.h>
+#include <linux/slab.h>
 #include <linux/cpu.h>
 
 #include <asm/system.h>
@@ -216,6 +217,8 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
 static int omap_cpu_exit(struct cpufreq_policy *policy)
 {
 	clk_exit_cpufreq_table(&freq_table);
+	kfree(freq_table);
+	freq_table = NULL;
 	clk_put(mpu_clk);
 	return 0;
 }
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/5 OMAP2+: cpufreq: handle invalid cpufreq table

In reply to Nishanth Menon

Handle the case when cpufreq_frequency_table_cpuinfo fails. freq_table that we passed failed the internal test of cpufreq generic driver, so we should'nt be using the freq_table as such. Instead, warn and fallback to clock functions for validation and operation.

---
 arch/arm/mach-omap2/omap2plus-cpufreq.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/omap2plus-cpufreq.c +10 -2
index e38ebb8..6e3666a 100644
@@ -182,10 +182,18 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
 
 	if (freq_table) {
 		result = cpufreq_frequency_table_cpuinfo(policy, freq_table);
-		if (!result)
+		if (!result) {
 			cpufreq_frequency_table_get_attr(freq_table,
 							policy->cpu);
-	} else {
+		} else {
+			WARN(true, "%s: fallback to clk_round(freq_table=%d)\n",
+					__func__, result);
+			kfree(freq_table);
+			freq_table = NULL;
+		}
+	}
+
+	if (!freq_table) {
 		policy->cpuinfo.min_freq = clk_round_rate(mpu_clk, 0) / 1000;
 		policy->cpuinfo.max_freq = clk_round_rate(mpu_clk,
 							VERY_HI_RATE) / 1000;
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/5 OMAP2+: cpufreq: minor comment cleanup

In reply to Nishanth Menon

this should probably get squashed in..

---
 arch/arm/mach-omap2/omap2plus-cpufreq.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/omap2plus-cpufreq.c +4 -2
index 6e3666a..45f1e9e 100644
@@ -84,8 +84,10 @@ static int omap_target(struct cpufreq_policy *policy,
 	if (is_smp() && (num_online_cpus() < NR_CPUS))
 		return ret;
 
-	/* Ensure desired rate is within allowed range.  Some govenors
-	 * (ondemand) will just pass target_freq=0 to get the minimum. */
+	/*
+	 * Ensure desired rate is within allowed range.  Some govenors
+	 * (ondemand) will just pass target_freq=0 to get the minimum.
+	 */
 	if (target_freq < policy->min)
 		target_freq = policy->min;
 	if (target_freq > policy->max)
Signature · 1 line
1.7.1
#4 lore raw

PATCH 4/5 OMAP2: cpufreq: use clk_init_cpufreq_table if OPPs not available

In reply to Nishanth Menon

OMAP2 does not use OPP tables at the moment for DVFS. Currently, we depend on opp table initialization to give us the freq_table, which makes sense for OMAP3+. for OMAP2, we should be using clk_init_cpufreq_table - so if the opp based frequency table initilization fails, fall back to clk_init_cpufreq_table to give us the table.

---
 arch/arm/mach-omap2/omap2plus-cpufreq.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/omap2plus-cpufreq.c +8 -1
index 45f1e9e..854f4b3 100644
@@ -180,7 +180,13 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
 		pr_warning("%s: unable to get the mpu device\n", __func__);
 		return -EINVAL;
 	}
-	opp_init_cpufreq_table(mpu_dev, &freq_table);
+
+	/*
+	 * if we dont get cpufreq table using opp, use traditional omap2 lookup
+	 * as a fallback
+	 */
+	if (opp_init_cpufreq_table(mpu_dev, &freq_table))
+		clk_init_cpufreq_table(&freq_table);
 
 	if (freq_table) {
 		result = cpufreq_frequency_table_cpuinfo(policy, freq_table);
@@ -188,6 +194,7 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
 			cpufreq_frequency_table_get_attr(freq_table,
 							policy->cpu);
 		} else {
+			clk_exit_cpufreq_table(&freq_table);
 			WARN(true, "%s: fallback to clk_round(freq_table=%d)\n",
 					__func__, result);
 			kfree(freq_table);
Signature · 1 line
1.7.1
#5 lore raw

PATCH 5/5 OMAP2+: cpufreq: use cpufreq_frequency_table_target

In reply to Nishanth Menon

Use cpufreq_frequency_table_target for finding the proper target instead of seeing if the frequency requested is divisible alone. if we have a frequency table, we should restrict ourselves to selecting the "approved" frequencies alone and only in the case where the frequency table is not available should we attempt at closest roundable clock frequency.

---
 arch/arm/mach-omap2/omap2plus-cpufreq.c |   34 +++++++++++++++++++++---------
 1 files changed, 24 insertions(+), 10 deletions(-)
arch/arm/mach-omap2/omap2plus-cpufreq.c +24 -10
index 854f4b3..688c5bc 100644
@@ -77,24 +77,38 @@ static int omap_target(struct cpufreq_policy *policy,
 		       unsigned int target_freq,
 		       unsigned int relation)
 {
-	int i, ret = 0;
+	unsigned int i;
+	int ret = 0;
 	struct cpufreq_freqs freqs;
 
 	/* Changes not allowed until all CPUs are online */
 	if (is_smp() && (num_online_cpus() < NR_CPUS))
 		return ret;
 
-	/*
-	 * Ensure desired rate is within allowed range.  Some govenors
-	 * (ondemand) will just pass target_freq=0 to get the minimum.
-	 */
-	if (target_freq < policy->min)
-		target_freq = policy->min;
-	if (target_freq > policy->max)
-		target_freq = policy->max;
+	if (freq_table) {
+		cpufreq_frequency_table_target(policy, freq_table, target_freq,
+			relation, &i);
+		freqs.new = freq_table[i].frequency;
+	} else {
+		/*
+		 * Ensure desired rate is within allowed range. Some govenors
+		 * (ondemand) will just pass target_freq=0 to get the minimum.
+		 */
+		if (target_freq < policy->min)
+			target_freq = policy->min;
+		if (target_freq > policy->max)
+			target_freq = policy->max;
+
+		freqs.new = clk_round_rate(mpu_clk, target_freq * 1000) / 1000;
+	}
+	if (!freqs.new) {
+		for_each_cpu(i, policy->cpus)
+			pr_err("%s:cpu%d no match for freq %d\n", __func__,
+				i, target_freq);
+		return -EINVAL;
+	}
 
 	freqs.old = omap_getspeed(policy->cpu);
-	freqs.new = clk_round_rate(mpu_clk, target_freq * 1000) / 1000;
 	freqs.cpu = policy->cpu;
 
 	if (freqs.old == freqs.new)
Signature · 1 line
1.7.1