Skip to contentSkip to conversation

cpufreq_set_policy removed

DISCUSSION Tony Breeds 6 participants 8 messages Jun 6, 2007 – Jun 23, 2007

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

Hi All,

	The git commit  632786ce9ff6206951ee4c84fe5c0d5c1d12f4cc reomved

the "deprecated and buggy" cpufreq_set_policy(). In the linux powerpc tree we have a driver that's using it.

Offending function:
---
static void cbe_cpufreq_handle_pmi(struct of_device *dev, pmi_message_t pmi_msg)

{
	struct cpufreq_policy policy;
	u8 cpu;
	u8 cbe_pmode_new;

	BUG_ON(pmi_msg.type != PMI_TYPE_FREQ_CHANGE);

	cpu = cbe_node_to_cpu(pmi_msg.data1);
	cbe_pmode_new = pmi_msg.data2;

	cpufreq_get_policy(&policy, cpu);

	policy.max = min(policy.max, cbe_freqs[cbe_pmode_new].frequency);
	policy.min = min(policy.min, policy.max);

	pr_debug("cbe_handle_pmi: new policy.min=%d policy.max=%d\n", policy.min, policy.max);
	cpufreq_set_policy(&policy);
}

---

What is the correct API to use now?

Yours Tony

linux.conf.au http://linux.conf.au/ || http://lca2008.linux.org.au/
Jan 28 - Feb 02 2008 The Australian Linux Technical Conference!

#1 lore raw
Quoted 4 lines · Tony Breeds

Hi All,

	The git commit  632786ce9ff6206951ee4c84fe5c0d5c1d12f4cc reomved

the "deprecated and buggy" cpufreq_set_policy(). In the linux powerpc tree we have a driver that's using it.

Ugh... we still use it ? I though we had fixed that ...

CC'ing Christian who maintains the CBE cpufreq driver.

Ben.

#2 lore raw
Quoted 9 lines · Ben Herrenschmidt
Quoted 4 lines · Tony Breeds

Hi All,

	The git commit  632786ce9ff6206951ee4c84fe5c0d5c1d12f4cc reomved

the "deprecated and buggy" cpufreq_set_policy(). In the linux powerpc tree we have a driver that's using it.

Ugh... we still use it ? I though we had fixed that ...

CC'ing Christian who maintains the CBE cpufreq driver.

Thomas mailed the following patch a few weeks ago..

Dave

Subject: Re: removal of cpufreq_set_policy()
From: Thomas Renninger <[email protected]>
Reply-To: [email protected]
To: Benjamin Herrenschmidt <[email protected]>
Cc: [email protected], Arnd Bergmann <[email protected]>,
Christian Krafft <[email protected]>, [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>

	 <[email protected]>
	 <[email protected]>

Content-Type: multipart/mixed; boundary="=-Hzx+Pg+lBncYZX+nEfyQ"
Date: Mon, 21 May 2007 06:54:13 -0500
Message-Id: <[email protected]>

--=-Hzx+Pg+lBncYZX+nEfyQ
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Quoted 11 lines · Benjamin Herrenschmidt
Quoted 9 lines · Thomas Renninger

set_policy is buggy:
It calls verify_within_limits (where max_freq might get reduced) then sets
data->user_policy.max = data->max;
which is used to restore to highest freq with update_policy, but an already lowered freq might get assigned (e.g. if initialized on battery with limited freq, you will never ever reach higher freqs again).

Quoted 5 lines
Quoted 2 lines

I grepped the whole kernel and couldn't find cpufreq_set_policy to be used anywhere else.

Looks like cbe_cpufreq driver was merged at the same time as you were removing set_polcy :-)

Yes.

Quoted 11 lines
Quoted 5 lines

The cell cpufreq driver also does not match?:
linux-2.6.21_tests/arch/powerpc/platforms/cell/cbe_cpufreq.c

Can you give me a pointer to the code, is this an external project?

It should be in that cbe_cpufreq.c file in current -git. I'm not the author of the driver though, I'm just reporting the build failure :-)

Arnd and Christian, can you check what's up ?

Quoted 7 lines

I think that driver uses set_policy to enforce new limits upon request from the system management.

I know I did something similar, though slightly different, for powermac, in drivers/macintosh/windfarm_cpufreq_clamp.c which is a module in my thermal control infrastructure that clamps down the cpufreq when an overtemp condition is detected.

I can reproduce this with -rc2.
cpufreq_set_policy came in with this one:
2007-04-23 Christian Krafft [POWERPC] cell: use pmi in cpufreq driver

Attached patch is setting the limit like it's done for x86 in driver/acpi/processor_perflib.c
IMO the interface is more complicated as it needs to be (maybe I am wrong),
but it seems that this is the way it's intended to work.

Please review, ehh, I don't have HW to test and don't even know what pmi is,
can someone give this patch a test and try whether freq is limited and increased again correctly if "pmi" kicks in (compile tested...).

Thomas

Limit frequency for cell powerpc via cpufreq notifier chain

and get rid of cpufreq_set_policy call that caused a build failure due interfering commits

---
 arch/powerpc/platforms/cell/cbe_cpufreq.c |   28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
arch/powerpc/platforms/cell/cbe_cpufreq.c +22 -6
Index: linux-2.6.22-rc2/arch/powerpc/platforms/cell/cbe_cpufreq.c
===================================================================
@@ -67,6 +67,7 @@ static u64 MIC_Slow_Next_Timer_table[] =
 	0x00003FC000000000ull,
 };
 
+static unsigned int pmi_frequency_limit = 0;
 /*
  * hardware specific functions
  */
@@ -164,7 +165,6 @@ static int set_pmode(int cpu, unsigned i
 
 static void cbe_cpufreq_handle_pmi(struct of_device *dev, pmi_message_t pmi_msg)
 {
-	struct cpufreq_policy policy;
 	u8 cpu;
 	u8 cbe_pmode_new;
 
@@ -173,15 +173,27 @@ static void cbe_cpufreq_handle_pmi(struc
 	cpu = cbe_node_to_cpu(pmi_msg.data1);
 	cbe_pmode_new = pmi_msg.data2;
 
-	cpufreq_get_policy(&policy, cpu);
+	pmi_frequency_limit = cbe_freqs[cbe_pmode_new].frequency;
 
-	policy.max = min(policy.max, cbe_freqs[cbe_pmode_new].frequency);
-	policy.min = min(policy.min, policy.max);
+	pr_debug("cbe_handle_pmi: max freq=%d\n", pmi_frequency_limit);
+}
+
+static int pmi_notifier(struct notifier_block *nb,
+				       unsigned long event, void *data)
+{
+	struct cpufreq_policy *policy = data;
+
+	if (event != CPUFREQ_INCOMPATIBLE)
+		return 0;
 
-	pr_debug("cbe_handle_pmi: new policy.min=%d policy.max=%d\n", policy.min, policy.max);
-	cpufreq_set_policy(&policy);
+	cpufreq_verify_within_limits(policy, 0, pmi_frequency_limit);
+	return 0;
 }
 
+static struct notifier_block pmi_notifier_block = {
+	.notifier_call = pmi_notifier,
+};
+
 static struct pmi_handler cbe_pmi_handler = {
 	.type			= PMI_TYPE_FREQ_CHANGE,
 	.handle_pmi_message	= cbe_cpufreq_handle_pmi,
@@ -238,6 +250,10 @@ static int cbe_cpufreq_cpu_init(struct c
 
 	cpufreq_frequency_table_get_attr(cbe_freqs, policy->cpu);
 
+	/* frequency might get limited later, initialize limit with max_freq */
+	pmi_frequency_limit = max_freq;
+	cpufreq_register_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER);
+
 	/* this ensures that policy->cpuinfo_min and policy->cpuinfo_max are set correctly */
 	return cpufreq_frequency_table_cpuinfo(policy, cbe_freqs);
 }

--=-Hzx+Pg+lBncYZX+nEfyQ
Content-Disposition: attachment; filename=ppc_cpufreq_pmi_notifier.patch
Content-Type: text/x-patch; name=ppc_cpufreq_pmi_notifier.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

Limit frequency for cell powerpc via cpufreq notifier chain

and get rid of cpufreq_set_policy call that caused a build failure due interfering commits

---
 arch/powerpc/platforms/cell/cbe_cpufreq.c |   28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
arch/powerpc/platforms/cell/cbe_cpufreq.c +22 -6
Index: linux-2.6.22-rc2/arch/powerpc/platforms/cell/cbe_cpufreq.c
===================================================================
@@ -67,6 +67,7 @@ static u64 MIC_Slow_Next_Timer_table[] =
 	0x00003FC000000000ull,
 };
 
+static unsigned int pmi_frequency_limit = 0;
 /*
  * hardware specific functions
  */
@@ -164,7 +165,6 @@ static int set_pmode(int cpu, unsigned i
 
 static void cbe_cpufreq_handle_pmi(struct of_device *dev, pmi_message_t pmi_msg)
 {
-	struct cpufreq_policy policy;
 	u8 cpu;
 	u8 cbe_pmode_new;
 
@@ -173,15 +173,27 @@ static void cbe_cpufreq_handle_pmi(struc
 	cpu = cbe_node_to_cpu(pmi_msg.data1);
 	cbe_pmode_new = pmi_msg.data2;
 
-	cpufreq_get_policy(&policy, cpu);
+	pmi_frequency_limit = cbe_freqs[cbe_pmode_new].frequency;
 
-	policy.max = min(policy.max, cbe_freqs[cbe_pmode_new].frequency);
-	policy.min = min(policy.min, policy.max);
+	pr_debug("cbe_handle_pmi: max freq=%d\n", pmi_frequency_limit);
+}
+
+static int pmi_notifier(struct notifier_block *nb,
+				       unsigned long event, void *data)
+{
+	struct cpufreq_policy *policy = data;
+
+	if (event != CPUFREQ_INCOMPATIBLE)
+		return 0;
 
-	pr_debug("cbe_handle_pmi: new policy.min=%d policy.max=%d\n", policy.min, policy.max);
-	cpufreq_set_policy(&policy);
+	cpufreq_verify_within_limits(policy, 0, pmi_frequency_limit);
+	return 0;
 }
 
+static struct notifier_block pmi_notifier_block = {
+	.notifier_call = pmi_notifier,
+};
+
 static struct pmi_handler cbe_pmi_handler = {
 	.type			= PMI_TYPE_FREQ_CHANGE,
 	.handle_pmi_message	= cbe_cpufreq_handle_pmi,
@@ -238,6 +250,10 @@ static int cbe_cpufreq_cpu_init(struct c
 
 	cpufreq_frequency_table_get_attr(cbe_freqs, policy->cpu);
 
+	/* frequency might get limited later, initialize limit with max_freq */
+	pmi_frequency_limit = max_freq;
+	cpufreq_register_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER);
+
 	/* this ensures that policy->cpuinfo_min and policy->cpuinfo_max are set correctly */
 	return cpufreq_frequency_table_cpuinfo(policy, cbe_freqs);
 }

--=-Hzx+Pg+lBncYZX+nEfyQ--

Signature · 1 line
http://www.codemonkey.org.uk
#3 lore raw
Quoted 7 lines · Dave Jones
Quoted 6 lines · Ben Herrenschmidt
Quoted 4 lines · Tony Breeds

Hi All,

	The git commit  632786ce9ff6206951ee4c84fe5c0d5c1d12f4cc reomved

the "deprecated and buggy" cpufreq_set_policy(). In the linux powerpc tree we have a driver that's using it.

Quoted 5 lines
Quoted 3 lines

Ugh... we still use it ? I though we had fixed that ...

CC'ing Christian who maintains the CBE cpufreq driver.

Thomas mailed the following patch a few weeks ago..

Thanks Dave and Thomas.

We'll see what we can do about getting this tested and pushed.

Yours Tony

linux.conf.au http://linux.conf.au/ || http://lca2008.linux.org.au/
Jan 28 - Feb 02 2008 The Australian Linux Technical Conference!

#4 lore raw
In reply to Dave Jones

I currently use set_policy() to get around some peculiar features of OMAP2420, so at first I was a little scared. But now after fixing my code - I agree that it is much better to only rely on the CPUFREQ_POLICY_NOTIFIER chain.

I have some comments to patch in-line:

On Thu, 2007-06-07 at 00:14 +0000, an unknown sender wrote:
...

Quoted 1 line · Benjamin Herrenschmidt

...

Quoted 4 lines

Index: linux-2.6.22-rc2/arch/powerpc/platforms/cell/cbe_cpufreq.c
===================================================================

arch/powerpc/platforms/cell/cbe_cpufreq.c +0 -0

...

arch/powerpc/platforms/cell/cbe_cpufreq.c static void cbe_cpufreq_handle_pmi(struc · line 179

Quoted 11 lines
arch/powerpc/platforms/cell/cbe_cpufreq.c +3 -3
@@ -173,15 +173,27 @@ static void cbe_cpufreq_handle_pmi(struc
 	cpu = cbe_node_to_cpu(pmi_msg.data1);
 	cbe_pmode_new = pmi_msg.data2;
 
-	cpufreq_get_policy(&policy, cpu);
+	pmi_frequency_limit = cbe_freqs[cbe_pmode_new].frequency;
 
-	policy.max = min(policy.max, cbe_freqs[cbe_pmode_new].frequency);
-	policy.min = min(policy.min, policy.max);
+	pr_debug("cbe_handle_pmi: max freq=%d\n", pmi_frequency_limit);
+}

Shouldn't cpufreq_update_policy() be called from this function?

Quoted 3 lines
arch/powerpc/platforms/cell/cbe_cpufreq.c +3 -0
+
+static int pmi_notifier(struct notifier_block *nb,
+				       unsigned long event, void *data)

...

arch/powerpc/platforms/cell/cbe_cpufreq.c static void cbe_cpufreq_handle_pmi(struc · line 191

Quoted 3 lines
arch/powerpc/platforms/cell/cbe_cpufreq.c +2 -0
+	cpufreq_verify_within_limits(policy, 0, pmi_frequency_limit);
+	return 0;
 }

... because pmi_notifier() is updating the policy...

...

arch/powerpc/platforms/cell/cbe_cpufreq.c static int cbe_cpufreq_cpu_init(struct c · line 255

Quoted 7 lines
arch/powerpc/platforms/cell/cbe_cpufreq.c +3 -0
@@ -238,6 +250,10 @@ static int cbe_cpufreq_cpu_init(struct c
 
 	cpufreq_frequency_table_get_attr(cbe_freqs, policy->cpu);
 
+	/* frequency might get limited later, initialize limit with max_freq */
+	pmi_frequency_limit = max_freq;
+	cpufreq_register_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER);

... and pmi_notifier() is registered on the CPUFREQ_POLICY_NOTIFIER chain.

So, how is the CPUFREQ_POLICY_NOTIFIER chain executed with no calls to cpufreq_update_policy() (or __cpufreq_set_policy())?

And if pmi_notifier() is not called, how is the policy updated?

BR, Klaus Pedersen

#5 lore raw
Quoted 23 lines · Klaus.K Pedersen (Nokia-M/Helsinki)

I currently use set_policy() to get around some peculiar features of OMAP2420, so at first I was a little scared. But now after fixing my code - I agree that it is much better to only rely on the CPUFREQ_POLICY_NOTIFIER chain.

I have some comments to patch in-line:

On Thu, 2007-06-07 at 00:14 +0000, an unknown sender wrote:
...

Quoted 1 line · Benjamin Herrenschmidt

...

Quoted 4 lines

Index: linux-2.6.22-rc2/arch/powerpc/platforms/cell/cbe_cpufreq.c
===================================================================

arch/powerpc/platforms/cell/cbe_cpufreq.c +0 -0

...

Quoted 7 lines
arch/powerpc/platforms/cell/cbe_cpufreq.c +1 -1
@@ -173,15 +173,27 @@ static void cbe_cpufreq_handle_pmi(struc
 	cpu = cbe_node_to_cpu(pmi_msg.data1);
 	cbe_pmode_new = pmi_msg.data2;
 
-	cpufreq_get_policy(&policy, cpu);
+	pmi_frequency_limit = cbe_freqs[cbe_pmode_new].frequency;
 
Quoted 6 lines

arch/powerpc/platforms/cell/cbe_cpufreq.c static void cbe_cpufreq_handle_pmi(struc · line 179

Quoted 4 lines
arch/powerpc/platforms/cell/cbe_cpufreq.c +2 -2
-	policy.max = min(policy.max, cbe_freqs[cbe_pmode_new].frequency);
-	policy.min = min(policy.min, policy.max);
+	pr_debug("cbe_handle_pmi: max freq=%d\n", pmi_frequency_limit);
+}

Shouldn't cpufreq_update_policy() be called from this function?

Yes, I think you are right, is that better?
Still a real-life test whether all that pmi things are working as expected would be great...

Thanks for the detailed info and review,

Thomas

Update the policy on pmi frequency changes

Also fixes a compile dependency, PPC_PMI is needed for cell cpufreq.

---
 arch/powerpc/platforms/cell/Kconfig       |    2 +-
 arch/powerpc/platforms/cell/cbe_cpufreq.c |    2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/platforms/cell/cbe_cpufreq.c +2 -0
Index: linux-2.6.22-rc5/arch/powerpc/platforms/cell/cbe_cpufreq.c
===================================================================
@@ -175,6 +175,8 @@ static void cbe_cpufreq_handle_pmi(struc
 
 	pmi_frequency_limit = cbe_freqs[cbe_pmode_new].frequency;
 
+	cpufreq_update_policy(cpu);
+
 	pr_debug("cbe_handle_pmi: max freq=%d\n", pmi_frequency_limit);
 }
 
arch/powerpc/platforms/cell/Kconfig +1 -1
Index: linux-2.6.22-rc5/arch/powerpc/platforms/cell/Kconfig
===================================================================
@@ -66,7 +66,7 @@ config CBE_THERM
 
 config CBE_CPUFREQ
 	tristate "CBE frequency scaling"
-	depends on CBE_RAS && CPU_FREQ
+	depends on PPC_PMI && CBE_RAS && CPU_FREQ
 	default m
 	help
 	  This adds the cpufreq driver for Cell BE processors.

Update the policy on pmi frequency changes

Also fixes a compile dependency, PPC_PMI is needed for cell cpufreq.

---
 arch/powerpc/platforms/cell/Kconfig       |    2 +-
 arch/powerpc/platforms/cell/cbe_cpufreq.c |    2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/platforms/cell/cbe_cpufreq.c +2 -0
Index: linux-2.6.22-rc5/arch/powerpc/platforms/cell/cbe_cpufreq.c
===================================================================
@@ -175,6 +175,8 @@ static void cbe_cpufreq_handle_pmi(struc
 
 	pmi_frequency_limit = cbe_freqs[cbe_pmode_new].frequency;
 
+	cpufreq_update_policy(cpu);
+
 	pr_debug("cbe_handle_pmi: max freq=%d\n", pmi_frequency_limit);
 }
 
arch/powerpc/platforms/cell/Kconfig +1 -1
Index: linux-2.6.22-rc5/arch/powerpc/platforms/cell/Kconfig
===================================================================
@@ -66,7 +66,7 @@ config CBE_THERM
 
 config CBE_CPUFREQ
 	tristate "CBE frequency scaling"
-	depends on CBE_RAS && CPU_FREQ
+	depends on PPC_PMI && CBE_RAS && CPU_FREQ
 	default m
 	help
 	  This adds the cpufreq driver for Cell BE processors.

_______________________________________________
Cpufreq mailing list
[email protected]
http://lists.linux.org.uk/mailman/listinfo/cpufreq

#6 lore raw

Thomas, Dave:

Do either of you have a problem with the existence of cpufreq_set_policy() or was it only removed because there were no remaining callers in the tree and it had bugs?

The reason why I ask is that I have been working on a module that changes cpufreq governors and I don't see any other way for a module to be able to change governors without this interface.

If there is another way please let me know. Otherwise I would like to fix the cpufreq_set_policy() related bugs and make it available for modules to use.

Myron

Signature · 1 line
Myron Stowe                             HP Open Source & Linux Org
#7 lore raw
Quoted 5 lines · Myron Stowe

Thomas, Dave:

Do either of you have a problem with the existence of cpufreq_set_policy() or was it only removed because there were no remaining callers in the tree and it had bugs?

Both.

In cpufreq_set_policy:

	/* this one invokes verify and data->max could get lowered
           because of temperature or BIOS limitations
	*/
        ret = __cpufreq_set_policy(data, policy);
        data->user_policy.min = data->min;
        data->user_policy.max = data->max;
        /* here user_policy.max is getting overridden with a possible
	limited value. But it is used in update_policy to restore the
	unlimited values again */
        data->user_policy.policy = data->policy;
        data->user_policy.governor = data->governor;

I think in update_policy:
policy->cpuinfo.min_freq
policy->cpuinfo.max_freq
should get used anyway...

If really needed it could get exported again, but just use cpu_get/cpu_put, set/unset a lock and invoke __cpufreq_set_policy in between?

Quoted 4 lines

The reason why I ask is that I have been working on a module that changes cpufreq governors and I don't see any other way for a module to be able to change governors without this interface.

But governor changing is userspace job?
IMO this is not the best argument, why do you need switching governors inside the kernel?

Thomas