Cleanups for cpufreq
Subsystems (3)
v4 cover Cleanups for cpufreq
Rev 4 of cleanups for cpufreq to take care of the review comments on the remaining rev3 patches.
Applies on top of:git://git.kernel.org/pub/scm/linux/kernel/git/khilman/linux-omap-pm.git
branch: pm-wip/cpufreq
Tested on SDP4430 - with a TI internal loadgenerator controlled on each cpu while online/offline of cpu1 and using all governors. (Used a forked dvfs for testing purposes)
Patch 4 Depends on: http://marc.info/?t=130630947000002&r=1&w=2
v4: changes:
* we drop omap2 code for clk_init/exit and expect omap2 be supported once we get OPP/wrapper function to give us that function (http://marc.info/?l=linux-omap&m=130644155723048&w=2)
* Dropped the mutex infavor of atomic
(http://marc.info/?l=linux-omap&m=130643487913294&w=2)
v3: http://marc.info/?l=linux-omap&m=130636674200733&w=2
v2: http://marc.info/?l=linux-omap&m=130570427214357&w=2
V1: http://marc.info/?l=linux-omap&m=130532085617487&w=2
Nishanth Menon (4):
OMAP2+: cpufreq: dont support !freq_table
OMAP2+: cpufreq: use OPP library
OMAP2+: cpufreq: put clk if cpu_init failed
OMAP2+: cpufreq: fix freq_table leak
arch/arm/mach-omap2/Makefile | 4 +- arch/arm/mach-omap2/omap2plus-cpufreq.c | 103 ++++++++++++++++++------------ 2 files changed, 64 insertions(+), 43 deletions(-)
Regards,
Nishanth Menon
PATCH v4 1/4 OMAP2+: cpufreq: dont support !freq_table
OMAP2+ all have frequency tables, hence the hacks we had for older silicon do not need to be carried forward. As part of this change, use cpufreq_frequency_table_target to find the best match for frequency requested.
--- arch/arm/mach-omap2/omap2plus-cpufreq.c | 67 +++++++++++++++---------------- 1 files changed, 33 insertions(+), 34 deletions(-)
arch/arm/mach-omap2/omap2plus-cpufreq.c +33 -34
@@ -38,8 +38,6 @@#include <mach/hardware.h> -#define VERY_HI_RATE 900000000 -static struct cpufreq_frequency_table *freq_table;static struct clk *mpu_clk;static char *mpu_clk_name;
@@ -47,20 +45,9 @@ static struct device *mpu_dev;static int omap_verify_speed (struct cpufreq_policy *policy) { -if (freq_table) -return cpufreq_frequency_table_verify (policy, freq_table); - -if (policy->cpu) +if (!freq_table)return -EINVAL ; - -cpufreq_verify_within_limits (policy, policy->cpuinfo.min_freq, - policy->cpuinfo.max_freq); - - policy->min =clk_round_rate (mpu_clk, policy->min *1000 ) /1000 ; - policy->max =clk_round_rate (mpu_clk, policy->max *1000 ) /1000 ; -cpufreq_verify_within_limits (policy, policy->cpuinfo.min_freq, - policy->cpuinfo.max_freq); -return 0 ; +return cpufreq_frequency_table_verify (policy, freq_table); }static unsigned int omap_getspeed (unsigned int cpu)
@@ -78,22 +65,35 @@ 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) { +dev_err (mpu_dev,"%s: cpu%d: no freq table!\n" , __func__, + policy->cpu); +return -EINVAL ; + } + + ret =cpufreq_frequency_table_target (policy, freq_table, target_freq, + relation, &i); +if (ret) { +dev_dbg (mpu_dev,"%s: cpu%d: no freq match for %d(ret=%d)\n" , + __func__, policy->cpu, target_freq, ret); +return ret; + } + freqs.new = freq_table[i].frequency; +if (!freqs.new) { +dev_err (mpu_dev,"%s: cpu%d: no match for freq %d\n" , __func__, + policy->cpu, 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)
@@ -166,19 +166,18 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)return -EINVAL ; policy->cur = policy->min = policy->max =omap_getspeed (policy->cpu); -opp_init_cpufreq_table (mpu_dev, &freq_table); - -if (freq_table) { - result =cpufreq_frequency_table_cpuinfo (policy, freq_table); -if (!result) -cpufreq_frequency_table_get_attr (freq_table, - policy->cpu); - }else { - policy->cpuinfo.min_freq =clk_round_rate (mpu_clk,0 ) /1000 ; - policy->cpuinfo.max_freq =clk_round_rate (mpu_clk, -VERY_HI_RATE ) /1000 ; + result =opp_init_cpufreq_table (mpu_dev, &freq_table); + +if (result) { +dev_err (mpu_dev,"%s: cpu%d: failed creating freq table[%d]\n" , + __func__, policy->cpu, result); +return result; } + result =cpufreq_frequency_table_cpuinfo (policy, freq_table); +if (!result) +cpufreq_frequency_table_get_attr (freq_table, policy->cpu); + policy->min = policy->cpuinfo.min_freq; policy->max = policy->cpuinfo.max_freq; policy->cur =omap_getspeed (policy->cpu);
Signature · 1 line
1.7.1
PATCH v4 2/4 OMAP2+: cpufreq: use OPP library
In reply to Nishanth MenonOMAP2 is the only family using clk_[init|exit]_cpufreq_table, however, the cpufreq code has does not use clk_init_cpufreq_table. As a result, it is unusuable for OMAP2 and only usable only on platforms using OPP library.
So move the compilation for cpufreq only if OPP is available for the architecture and deny OMAP2 in multi-OMAP builds until OMAP2 is fixed.
--- arch/arm/mach-omap2/Makefile | 4 ++-- arch/arm/mach-omap2/omap2plus-cpufreq.c | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-)
arch/arm/mach-omap2/Makefile +2 -2
@@ -54,10 +54,10 @@ ifeq ($(CONFIG_PM_OPP),y) obj-y += opp.o obj-$(CONFIG_ARCH_OMAP3) += opp3xxx_data.o obj-$(CONFIG_ARCH_OMAP4) += opp4xxx_data.o -endif - # CPUFREQ driver obj-$(CONFIG_CPU_FREQ) += omap2plus-cpufreq.o +endif + # Power Management ifeq ($(CONFIG_PM),y)
arch/arm/mach-omap2/omap2plus-cpufreq.c +7 -5
@@ -1,7 +1,7 @@/* * OMAP2PLUS cpufreq driver * -* CPU frequency scaling for OMAP +* CPU frequency scaling for OMAP using OPP information * * Copyright (C) 2005 Nokia Corporation * Written by Tony Lindgren <[email protected]>
@@ -203,7 +203,6 @@ 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);clk_put (mpu_clk);return 0 ; }
@@ -226,12 +225,15 @@ static struct cpufreq_driver omap_driver = {static int __init omap_cpufreq_init (void ) { -if (cpu_is_omap24xx ()) +if (cpu_is_omap24xx ()) { mpu_clk_name ="virt_prcm_set" ; -else if (cpu_is_omap34xx ()) +pr_warning ("%s: omap2 cpufreq needs fixing\n" , __func__); +return -EINVAL ; + }else if (cpu_is_omap34xx ()) { mpu_clk_name ="dpll1_ck" ; -else if (cpu_is_omap44xx ()) + }else if (cpu_is_omap44xx ()) { mpu_clk_name ="dpll_mpu_ck" ; + }if (!mpu_clk_name) {pr_err ("%s: unsupported Silicon?\n" , __func__);
Signature · 1 line
1.7.1
PATCH v4 3/4 OMAP2+: cpufreq: put clk if cpu_init failed
In reply to Nishanth MenonRelease the mpu_clk in fail paths.
--- arch/arm/mach-omap2/omap2plus-cpufreq.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-)
arch/arm/mach-omap2/omap2plus-cpufreq.c +11 -3
@@ -162,8 +162,10 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)if (IS_ERR (mpu_clk))return PTR_ERR (mpu_clk); -if (policy->cpu >=NR_CPUS ) -return -EINVAL ; +if (policy->cpu >=NR_CPUS ) { + result = -EINVAL ; + goto fail_ck; + } policy->cur = policy->min = policy->max =omap_getspeed (policy->cpu); result =opp_init_cpufreq_table (mpu_dev, &freq_table);
@@ -171,12 +173,14 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)if (result) {dev_err (mpu_dev,"%s: cpu%d: failed creating freq table[%d]\n" , __func__, policy->cpu, result); -return result; + goto fail_ck; } result =cpufreq_frequency_table_cpuinfo (policy, freq_table);if (!result)cpufreq_frequency_table_get_attr (freq_table, policy->cpu); +else + goto fail_ck; policy->min = policy->cpuinfo.min_freq; policy->max = policy->cpuinfo.max_freq;
@@ -199,6 +203,10 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy) policy->cpuinfo.transition_latency =300 *1000 ;return 0 ; + +fail_ck: +clk_put (mpu_clk); +return result; }static int omap_cpu_exit (struct cpufreq_policy *policy)
Signature · 1 line
1.7.1
PATCH v4 4/4 OMAP2+: cpufreq: fix freq_table leak
In reply to Nishanth MenonWe use a single frequency table for multiple CPUs. But, with OMAP4, since we have multiple CPUs, the cpu_init call for CPU1 causes freq_table previously allocated for CPU0 to be overwritten. In addition, we dont free the table on exit path.
We solve this by maintaining an atomic type counter to ensure just a single table exists at a given time.
---
NOTE: Depends on: http://marc.info/?t=130630947000002&r=1&w=2
arch/arm/mach-omap2/omap2plus-cpufreq.c | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/omap2plus-cpufreq.c +14 -2
@@ -39,6 +39,7 @@#include <mach/hardware.h> static struct cpufreq_frequency_table *freq_table; +static atomic_t freq_table_users =ATOMIC_INIT (0 );static struct clk *mpu_clk;static char *mpu_clk_name;static struct device *mpu_dev;
@@ -153,6 +154,12 @@ skip_lpj:return ret; } +static inline void freq_table_free (void ) +{ +if (atomic_dec_and_test (&freq_table_users)) +opp_free_cpufreq_table (mpu_dev, &freq_table); +} +static int __cpuinit omap_cpu_init (struct cpufreq_policy *policy) {int result =0 ;
@@ -168,7 +175,9 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy) } policy->cur = policy->min = policy->max =omap_getspeed (policy->cpu); - result =opp_init_cpufreq_table (mpu_dev, &freq_table); + +if (atomic_inc_return (&freq_table_users) ==1 ) + result =opp_init_cpufreq_table (mpu_dev, &freq_table);if (result) { dev_err(mpu_dev, "%s: cpu%d: failed creating freq table[%d]\n",
@@ -180,7 +189,7 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)if (!result)cpufreq_frequency_table_get_attr (freq_table, policy->cpu);else - goto fail_ck; + goto fail_table; policy->min = policy->cpuinfo.min_freq; policy->max = policy->cpuinfo.max_freq;
@@ -204,6 +213,8 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)return 0 ; +fail_table: +freq_table_free (); fail_ck:clk_put (mpu_clk);return result;
@@ -211,6 +222,7 @@ fail_ck:static int omap_cpu_exit (struct cpufreq_policy *policy) { +freq_table_free ();clk_put (mpu_clk);return 0 ; }
Signature · 1 line
1.7.1
Re: [PM-WIP_CPUFREQ][PATCH v4 2/4] OMAP2+: cpufreq: use OPP library
In reply to Nishanth MenonQuoted 7 lines · Nishanth Menon
OMAP2 is the only family using clk_[init|exit]_cpufreq_table, however, the cpufreq code has does not use
clk_init_cpufreq_table. As a result, it is unusuable for OMAP2 and only usable only on platforms using OPP library.So move the compilation for cpufreq only if OPP is available for the architecture and deny OMAP2 in multi-OMAP builds until OMAP2 is fixed.
Let's not prevent the build, just print a failure warning when the freq_table is empty because there were no OPPs found. We need this also for any new platforms that are added but don't yet have OPPs available.
Quoted 45 lines
Signed-off-by Nishanth Menon <[email protected]>--- arch/arm/mach-omap2/Makefile | 4 ++-- arch/arm/mach-omap2/omap2plus-cpufreq.c | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-)arch/arm/mach-omap2/Makefile +2
-2@@ -54,10 +54,10 @@ ifeq ($(CONFIG_PM_OPP),y) obj-y += opp.o obj-$(CONFIG_ARCH_OMAP3) += opp3xxx_data.o obj-$(CONFIG_ARCH_OMAP4) += opp4xxx_data.o -endif - # CPUFREQ driver obj-$(CONFIG_CPU_FREQ) += omap2plus-cpufreq.o +endif + # Power Management ifeq ($(CONFIG_PM),y)arch/arm/mach-omap2/omap2plus-cpufreq.c +1
-2@@ -1,7 +1,7 @@/* * OMAP2PLUS cpufreq driver * -* CPU frequency scaling for OMAP +* CPU frequency scaling for OMAP using OPP information * * Copyright (C) 2005 Nokia Corporation * Written by Tony Lindgren <[email protected]> @@ -203,7 +203,6 @@ 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);clk_put (mpu_clk);return 0 ; }
arch/arm/mach-omap2/omap2plus-cpufreq.c static struct cpufreq_driver omap_driver = { · line 230
Quoted 8 lines
arch/arm/mach-omap2/omap2plus-cpufreq.c +2
-2@@ -226,12 +225,15 @@ static struct cpufreq_driver omap_driver = {static int __init omap_cpufreq_init (void ) { -if (cpu_is_omap24xx ()) +if (cpu_is_omap24xx ()) { mpu_clk_name ="virt_prcm_set" ; -else if (cpu_is_omap34xx ()) +pr_warning ("%s: omap2 cpufreq needs fixing\n" , __func__);
Rather than the warning here, just have it fail with a warning when/if the freq_table creation fails because of no OPPs.
Kevin
Quoted 10 lines
arch/arm/mach-omap2/omap2plus-cpufreq.c +4
-1+return -EINVAL ; + }else if (cpu_is_omap34xx ()) { mpu_clk_name ="dpll1_ck" ; - else if (cpu_is_omap44xx()) + }else if (cpu_is_omap44xx ()) { mpu_clk_name ="dpll_mpu_ck" ; + }if (!mpu_clk_name) {pr_err ("%s: unsupported Silicon?\n" , __func__);
Kevin Hilman
AppliedRe: [PM-WIP_CPUFREQ][PATCH v4 1/4] OMAP2+: cpufreq: dont support !freq_table
In reply to Nishanth MenonQuoted 6 lines · Nishanth Menon
OMAP2+ all have frequency tables, hence the hacks we had for older silicon do not need to be carried forward. As part of this change, use
cpufreq_frequency_table_targetto find the best match for frequency requested.Signed-off-by Nishanth Menon <[email protected]>
Thanks, applied.
Kevin
Kevin Hilman
AppliedRe: [PM-WIP_CPUFREQ][PATCH v4 3/4] OMAP2+: cpufreq: put clk if cpu_init failed
In reply to Nishanth MenonQuoted 4 lines · Nishanth Menon
Release the
mpu_clkin fail paths.Reported-by Todd Poynor <[email protected]>Signed-off-by Nishanth Menon <[email protected]>
Thanks, applied.
Kevin
Re: [PM-WIP_CPUFREQ][PATCH v4 2/4] OMAP2+: cpufreq: use OPP library
In reply to Nishanth MenonQuoted 9 lines · Nishanth Menon
OMAP2 is the only family using clk_[init|exit]_cpufreq_table, however, the cpufreq code has does not use
clk_init_cpufreq_table. As a result, it is unusuable for OMAP2 and only usable only on platforms using OPP library.So move the compilation for cpufreq only if OPP is available for the architecture and deny OMAP2 in multi-OMAP builds until OMAP2 is fixed.
Signed-off-by Nishanth Menon <[email protected]>
I updated this patch slightly, preferring a more generic failure mode, namely just failing with a warning on init when no OPPs are present.
I tested this on 3430/n900 by simply commenting out the omap_init_opp_table() for OMAP3. CPUfreq init fails predictably with
platform mpu.0: opp_init_cpufreq_table: Device OPP not found (-19) platform mpu.0: omap_cpu_init: cpu0: failed creating freq table[-19]
So CPUfreq driver never gets registered.
Updated patch below. If you're OK with this change, I'll apply it to pm-wip/cpufreq.
Kevin
Quoted 1 line
From
22f1704e2ec30816e34b3d46a4c61513441fce8dMon Sep 17 00:00:00 2001
From: Nishanth Menon <[email protected]>
Date: Thu, 26 May 2011 19:39:18 -0700
Subject: [PATCH 2/4] OMAP2+: cpufreq: only supports OPP library
OMAP2 is the only family using clk_[init|exit]_cpufreq_table, however, the cpufreq code does not currently use clk_init_cpufreq_table. As a result, it is unusuable for OMAP2 and only usable only on platforms using OPP library.
Remove the unbalanced clk_exit_cpufreq_table(). Any platforms where OPPs are not availble will fail on init because a freq table will not be properly initialized.
--- arch/arm/mach-omap2/omap2plus-cpufreq.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/omap2plus-cpufreq.c +1 -2
@@ -1,7 +1,7 @@/* * OMAP2PLUS cpufreq driver * -* CPU frequency scaling for OMAP +* CPU frequency scaling for OMAP using OPP information * * Copyright (C) 2005 Nokia Corporation * Written by Tony Lindgren <[email protected]>
@@ -203,7 +203,6 @@ 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);clk_put (mpu_clk);return 0 ; }
Signature · 1 line
1.7.4
Re: [PM-WIP_CPUFREQ][PATCH v4 2/4] OMAP2+: cpufreq: use OPP library
Quoted 72 lines · Kevin Hilman
Quoted 9 lines · Nishanth Menon
OMAP2 is the only family using clk_[init|exit]_cpufreq_table, however, the cpufreq code has does not use
clk_init_cpufreq_table. As a result, it is unusuable for OMAP2 and only usable only on platforms using OPP library.So move the compilation for cpufreq only if OPP is available for the architecture and deny OMAP2 in multi-OMAP builds until OMAP2 is fixed.
Signed-off-by Nishanth Menon <[email protected]>I updated this patch slightly, preferring a more generic failure mode, namely just failing with a warning on init when no OPPs are present.
I tested this on 3430/n900 by simply commenting out the
omap_init_opp_table()for OMAP3. CPUfreq init fails predictably withplatform mpu.0:
opp_init_cpufreq_table: Device OPP not found (-19) platform mpu.0:omap_cpu_init: cpu0: failed creating freq table[-19]So CPUfreq driver never gets registered.
Updated patch below. If you're OK with this change, I'll apply it to pm-wip/cpufreq.
Kevin
From
22f1704e2ec30816e34b3d46a4c61513441fce8dMon Sep 17 00:00:00 2001
From: Nishanth Menon <[email protected]>
Date: Thu, 26 May 2011 19:39:18 -0700
Subject: [PATCH 2/4] OMAP2+: cpufreq: only supports OPP libraryOMAP2 is the only family using clk_[init|exit]_cpufreq_table, however, the cpufreq code does not currently use
clk_init_cpufreq_table. As a result, it is unusuable for OMAP2 and only usable only on platforms using OPP library.Remove the unbalanced
clk_exit_cpufreq_table(). Any platforms where OPPs are not availble will fail on init because a freq table will not be properly initialized.Signed-off-by Nishanth Menon <[email protected]>[[email protected]: changelog edits, and graceful failure mode changes]Acked-by Kevin Hilman <[email protected]>---
arch/arm/mach-omap2/omap2plus-cpufreq.c | 3 +--1 files changed, 1 insertions(+), 2 deletions(-)arch/arm/mach-omap2/omap2plus-cpufreq.c +1
-3@@ -1,7 +1,7 @@ /** OMAP2PLUS cpufreq driver * -* CPU frequency scaling for OMAP +* CPU frequency scaling for OMAP using OPP information * * Copyright (C) 2005 Nokia Corporation * Written by Tony Lindgren <[email protected]> @@ -203,7 +203,6 @@ 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); clk_put(mpu_clk); return 0; } --
Quoted 3 lines
1.7.4
Fine with me. thanks for it. it achieves what I needed as well :)
Regards,
Nishanth Menon
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html