cpufreq Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [-mm patch] CPU_FREQ_GOV_PERFORMANCE must always be y
       [not found]   ` <46B12516.4090006@googlemail.com>
@ 2007-08-02 13:48     ` Adrian Bunk
  2007-08-02 14:38       ` [-mm patch] CPUfreq: Only check for transition latency on problematic governors Thomas Renninger
  0 siblings, 1 reply; 4+ messages in thread
From: Adrian Bunk @ 2007-08-02 13:48 UTC (permalink / raw)
  To: Gabriel C, davej
  Cc: Andrew Morton, Miles Lane, LKML, Thomas Renninger, cpufreq

On Thu, Aug 02, 2007 at 02:28:06AM +0200, Gabriel C wrote:
> Andrew Morton wrote:
> > On Wed, 1 Aug 2007 16:31:46 -0700
> > "Miles Lane" <miles.lane@gmail.com> wrote:
> > 
> >>   LD      .tmp_vmlinux1
> >> drivers/built-in.o: In function `__cpufreq_governor':
> >> cpufreq.c:(.text+0xaf178): undefined reference to `cpufreq_gov_performance'
> >> cpufreq.c:(.text+0xaf18a): undefined reference to `cpufreq_gov_performance'
> >> make: *** [.tmp_vmlinux1] Error 1
> > 
> > One for Thomas, I expect.
> 
> Is this patch :
> 
> cpufreq-allow-ondemand-and-conservative-cpufreq-governors-to-be-used-as-default.patch
> 
> Reverting it here fixes the error.

Possible fix below.

> Gabriel

cu
Adrian


<--  snip  -->


With the 'performance' governor always as a fallback it must always be 
compiled into the kernel.

Signed-off-by: Adrian Bunk <bunk@stusta.de>

---

 drivers/cpufreq/Kconfig |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

d7418849ec236338ec5ac74c0d66e5aaae466ffe 
diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig
index 721f86f..91f7cfd 100644
--- a/drivers/cpufreq/Kconfig
+++ b/drivers/cpufreq/Kconfig
@@ -84,7 +84,6 @@ config CPU_FREQ_DEFAULT_GOV_USERSPACE
 config CPU_FREQ_DEFAULT_GOV_ONDEMAND
 	bool "ondemand"
 	select CPU_FREQ_GOV_ONDEMAND
-	select CPU_FREQ_GOV_PERFORMANCE
 	help
 	  Use the CPUFreq governor 'ondemand' as default. This allows
 	  you to get a full dynamic frequency capable system by simply
@@ -96,7 +95,6 @@ config CPU_FREQ_DEFAULT_GOV_ONDEMAND
 config CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
 	bool "conservative"
 	select CPU_FREQ_GOV_CONSERVATIVE
-	select CPU_FREQ_GOV_PERFORMANCE
 	help
 	  Use the CPUFreq governor 'conservative' as default. This allows
 	  you to get a full dynamic frequency capable system by simply
@@ -107,7 +105,8 @@ config CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
 endchoice
 
 config CPU_FREQ_GOV_PERFORMANCE
-	tristate "'performance' governor"
+	tristate
+	default y
 	help
 	  This cpufreq governor sets the frequency statically to the
 	  highest available CPU frequency.

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [-mm patch] CPUfreq: Only check for transition latency on problematic governors
  2007-08-02 13:48     ` [-mm patch] CPU_FREQ_GOV_PERFORMANCE must always be y Adrian Bunk
@ 2007-08-02 14:38       ` Thomas Renninger
  2007-08-02 14:54         ` Adrian Bunk
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Renninger @ 2007-08-02 14:38 UTC (permalink / raw)
  To: Adrian Bunk
  Cc: Gabriel C, davej, Andrew Morton, Miles Lane, LKML, cpufreq,
	Pallipadi, Venkatesh

[-- Attachment #1: Type: text/plain, Size: 3489 bytes --]

On Thu, 2007-08-02 at 15:48 +0200, Adrian Bunk wrote:
> On Thu, Aug 02, 2007 at 02:28:06AM +0200, Gabriel C wrote:
> > Andrew Morton wrote:
> > > On Wed, 1 Aug 2007 16:31:46 -0700
> > > "Miles Lane" <miles.lane@gmail.com> wrote:
> > > 
> > >>   LD      .tmp_vmlinux1
> > >> drivers/built-in.o: In function `__cpufreq_governor':
> > >> cpufreq.c:(.text+0xaf178): undefined reference to `cpufreq_gov_performance'
> > >> cpufreq.c:(.text+0xaf18a): undefined reference to `cpufreq_gov_performance'
> > >> make: *** [.tmp_vmlinux1] Error 1
> > > 
> > > One for Thomas, I expect.
> > 
> > Is this patch :
> > 
> > cpufreq-allow-ondemand-and-conservative-cpufreq-governors-to-be-used-as-default.patch
> > 
> > Reverting it here fixes the error.
> 
> Possible fix below.
Or this one.
Advantage: You can still have cpufreq core without the performance 
           governor built.
Disadvantage: The logic whether transition latency checks are
              needed/done is moved to Kconfig.
              Means, if you write a governor that has transition
              latency values above 0, you must let it depend on
              the performance governor in Kconfig.

Hope I got all .config possibilities with that one now.
Attached is also a replacement patch for this one:
cpufreq-allow-ondemand-and-conservative-cpufreq-governors-to-be-used-as-default.patch


CPUfreq: Only check for transition latency on problematic governors

Signed-off-by: Thomas Renninger <trenn@suse.de>
--

--- linux-2.6.23-rc1-mm2/include/linux/cpufreq.h	2007-08-02 16:01:36.000000000 +0200
+++ linux-2.6.23-rc1-mm2_fixed/include/linux/cpufreq.h	2007-08-02 15:21:28.000000000 +0200
@@ -299,8 +299,10 @@ static inline unsigned int cpufreq_get(u
   Performance governor is fallback governor if any other gov failed to
   auto load due latency restrictions
 */
+#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
 extern struct cpufreq_governor cpufreq_gov_performance;
 #define CPUFREQ_PERFORMANCE_GOVERNOR	(&cpufreq_gov_performance)
+#endif
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
 #define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_performance)
 #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
--- linux-2.6.23-rc1-mm2/drivers/cpufreq/cpufreq.c	2007-08-02 16:01:35.000000000 +0200
+++ linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq.c	2007-08-02 16:23:09.000000000 +0200
@@ -1484,17 +1484,30 @@ static int __cpufreq_governor(struct cpu
 					unsigned int event)
 {
 	int ret;
+
+	/* Only must be defined when default governor is known to have latency
+	   restrictions, like e.g. conservative or ondemand.
+	   That this is the case is already ensured in Kconfig
+	*/
+#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
 	struct cpufreq_governor *gov = CPUFREQ_PERFORMANCE_GOVERNOR;
+#else
+	struct cpufreq_governor *gov = NULL;
+#endif
 
 	if (policy->governor->max_transition_latency &&
 	    policy->cpuinfo.transition_latency >
 	    policy->governor->max_transition_latency) {
-		printk(KERN_WARNING "%s governor failed, too long"
-		       " transition latency of HW, fallback"
-		       " to %s governor\n",
-		       policy->governor->name,
-		       gov->name);
-		       policy->governor = gov;
+		if (!gov)
+			return -EINVAL;
+		else {
+			printk(KERN_WARNING "%s governor failed, too long"
+			       " transition latency of HW, fallback"
+			       " to %s governor\n",
+			       policy->governor->name,
+			       gov->name);
+			policy->governor = gov;
+		}
 	}
 
 	if (!try_module_get(policy->governor->owner))


[-- Attachment #2: ondemand_default.patch --]
[-- Type: text/x-patch, Size: 10014 bytes --]

Allow ondemand and conservative cpufreq governors to be used as default

Depending on the transition latency of the HW for cpufreq switches, the
ondemand or conservative governor cannot be used with certain cpufreq drivers.
Still the ondemand should be the default governor on a wide range of systems.
This patch allows this and lets the governor fallback to the performance
governor at cpufreq driver load time, if the driver does not support fast
enough frequency switching.

Main benefit is that on e.g. installation or other systems without userspace
support a working dynamic cpufreq support can be achieved on most systems by
simply loading the cpufreq driver. This is especially essential for recent
x86(_64) laptop hardware which may rely on working dynamic cpufreq OS support.

Signed-off-by: Thomas Renninger <trenn@suse.de>

---
 drivers/cpufreq/Kconfig                |   27 +++++++++++++++++++++++----
 drivers/cpufreq/cpufreq.c              |   25 +++++++++++++++++++++++++
 drivers/cpufreq/cpufreq_conservative.c |   19 +++++++++----------
 drivers/cpufreq/cpufreq_ondemand.c     |   22 +++++++++-------------
 include/linux/cpufreq.h                |   22 +++++++++++++++++++---
 5 files changed, 85 insertions(+), 30 deletions(-)

Index: linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-2.6.23-rc1-mm2_fixed.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq_ondemand.c
@@ -47,7 +47,7 @@ static unsigned int def_sampling_rate;
 			(def_sampling_rate / MIN_SAMPLING_RATE_RATIO)
 #define MAX_SAMPLING_RATE			(500 * def_sampling_rate)
 #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER	(1000)
-#define TRANSITION_LATENCY_LIMIT		(10 * 1000)
+#define TRANSITION_LATENCY_LIMIT		(10 * 1000 * 1000)
 
 static void do_dbs_timer(struct work_struct *work);
 
@@ -508,12 +508,6 @@ static int cpufreq_governor_dbs(struct c
 		if ((!cpu_online(cpu)) || (!policy->cur))
 			return -EINVAL;
 
-		if (policy->cpuinfo.transition_latency >
-				(TRANSITION_LATENCY_LIMIT * 1000)) {
-			printk(KERN_WARNING "ondemand governor failed to load "
-			       "due to too long transition latency\n");
-			return -EINVAL;
-		}
 		if (this_dbs_info->enable) /* Already enabled */
 			break;
 
@@ -585,11 +579,13 @@ static int cpufreq_governor_dbs(struct c
 	return 0;
 }
 
-static struct cpufreq_governor cpufreq_gov_dbs = {
-	.name = "ondemand",
-	.governor = cpufreq_governor_dbs,
-	.owner = THIS_MODULE,
+struct cpufreq_governor cpufreq_gov_ondemand = {
+	.name			= "ondemand",
+	.governor		= cpufreq_governor_dbs,
+	.max_transition_latency = TRANSITION_LATENCY_LIMIT,
+	.owner			= THIS_MODULE,
 };
+EXPORT_SYMBOL(cpufreq_gov_ondemand);
 
 static int __init cpufreq_gov_dbs_init(void)
 {
@@ -598,12 +594,12 @@ static int __init cpufreq_gov_dbs_init(v
 		printk(KERN_ERR "Creation of kondemand failed\n");
 		return -EFAULT;
 	}
-	return cpufreq_register_governor(&cpufreq_gov_dbs);
+	return cpufreq_register_governor(&cpufreq_gov_ondemand);
 }
 
 static void __exit cpufreq_gov_dbs_exit(void)
 {
-	cpufreq_unregister_governor(&cpufreq_gov_dbs);
+	cpufreq_unregister_governor(&cpufreq_gov_ondemand);
 	destroy_workqueue(kondemand_wq);
 }
 
Index: linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-2.6.23-rc1-mm2_fixed.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq_conservative.c
@@ -58,7 +58,7 @@ static unsigned int 				def_sampling_rat
 #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER	(1000)
 #define DEF_SAMPLING_DOWN_FACTOR		(1)
 #define MAX_SAMPLING_DOWN_FACTOR		(10)
-#define TRANSITION_LATENCY_LIMIT		(10 * 1000)
+#define TRANSITION_LATENCY_LIMIT		(10 * 1000 * 1000)
 
 static void do_dbs_timer(struct work_struct *work);
 
@@ -466,9 +466,6 @@ static int cpufreq_governor_dbs(struct c
 		    (!policy->cur))
 			return -EINVAL;
 
-		if (policy->cpuinfo.transition_latency >
-				(TRANSITION_LATENCY_LIMIT * 1000))
-			return -EINVAL;
 		if (this_dbs_info->enable) /* Already enabled */
 			break;
 		 
@@ -551,15 +548,17 @@ static int cpufreq_governor_dbs(struct c
 	return 0;
 }
 
-static struct cpufreq_governor cpufreq_gov_dbs = {
-	.name		= "conservative",
-	.governor	= cpufreq_governor_dbs,
-	.owner		= THIS_MODULE,
+struct cpufreq_governor cpufreq_gov_conservative = {
+	.name			= "conservative",
+	.governor		= cpufreq_governor_dbs,
+	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
+	.owner			= THIS_MODULE,
 };
+EXPORT_SYMBOL(cpufreq_gov_conservative);
 
 static int __init cpufreq_gov_dbs_init(void)
 {
-	return cpufreq_register_governor(&cpufreq_gov_dbs);
+	return cpufreq_register_governor(&cpufreq_gov_conservative);
 }
 
 static void __exit cpufreq_gov_dbs_exit(void)
@@ -567,7 +566,7 @@ static void __exit cpufreq_gov_dbs_exit(
 	/* Make sure that the scheduled work is indeed not running */
 	flush_scheduled_work();
 
-	cpufreq_unregister_governor(&cpufreq_gov_dbs);
+	cpufreq_unregister_governor(&cpufreq_gov_conservative);
 }
 
 
Index: linux-2.6.23-rc1-mm2_fixed/include/linux/cpufreq.h
===================================================================
--- linux-2.6.23-rc1-mm2_fixed.orig/include/linux/cpufreq.h
+++ linux-2.6.23-rc1-mm2_fixed/include/linux/cpufreq.h
@@ -163,6 +163,9 @@ struct cpufreq_governor {
 	char	name[CPUFREQ_NAME_LEN];
 	int 	(*governor)	(struct cpufreq_policy *policy,
 				 unsigned int event);
+	unsigned int max_transition_latency; /* HW must be able to switch to
+			next freq faster than this value in nano secs or we
+			will fallback to performance governor */
 	struct list_head	governor_list;
 	struct module		*owner;
 };
@@ -292,12 +295,25 @@ static inline unsigned int cpufreq_get(u
  *********************************************************************/
 
 
-#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
+/*
+  Performance governor is fallback governor if any other gov failed to
+  auto load due latency restrictions
+*/
+#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
 extern struct cpufreq_governor cpufreq_gov_performance;
-#define CPUFREQ_DEFAULT_GOVERNOR	&cpufreq_gov_performance
+#define CPUFREQ_PERFORMANCE_GOVERNOR	(&cpufreq_gov_performance)
+#endif
+#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
+#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_performance)
 #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
 extern struct cpufreq_governor cpufreq_gov_userspace;
-#define CPUFREQ_DEFAULT_GOVERNOR	&cpufreq_gov_userspace
+#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_userspace)
+#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
+extern struct cpufreq_governor cpufreq_gov_ondemand;
+#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_ondemand)
+#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE)
+extern struct cpufreq_governor cpufreq_gov_conservative;
+#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_conservative)
 #endif
 
 
Index: linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/Kconfig
===================================================================
--- linux-2.6.23-rc1-mm2_fixed.orig/drivers/cpufreq/Kconfig
+++ linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/Kconfig
@@ -56,10 +56,6 @@ config CPU_FREQ_STAT_DETAILS
 
 	  If in doubt, say N.
 
-# Note that it is not currently possible to set the other governors (such as ondemand)
-# as the default, since if they fail to initialise, cpufreq will be
-# left in an undefined state.
-
 choice
 	prompt "Default CPUFreq governor"
 	default CPU_FREQ_DEFAULT_GOV_USERSPACE if CPU_FREQ_SA1100 || CPU_FREQ_SA1110
@@ -85,6 +81,29 @@ config CPU_FREQ_DEFAULT_GOV_USERSPACE
 	  program shall be able to set the CPU dynamically without having
 	  to enable the userspace governor manually.
 
+config CPU_FREQ_DEFAULT_GOV_ONDEMAND
+	bool "ondemand"
+	select CPU_FREQ_GOV_ONDEMAND
+	select CPU_FREQ_GOV_PERFORMANCE
+	help
+	  Use the CPUFreq governor 'ondemand' as default. This allows
+	  you to get a full dynamic frequency capable system by simply
+	  loading your cpufreq low-level hardware driver.
+	  Be aware that not all cpufreq drivers support the ondemand
+	  governor. If unsure have a look at the help section of the
+	  driver. Fallback governor will be the performance governor.
+
+config CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
+	bool "conservative"
+	select CPU_FREQ_GOV_CONSERVATIVE
+	select CPU_FREQ_GOV_PERFORMANCE
+	help
+	  Use the CPUFreq governor 'conservative' as default. This allows
+	  you to get a full dynamic frequency capable system by simply
+	  loading your cpufreq low-level hardware driver.
+	  Be aware that not all cpufreq drivers support the conservative
+	  governor. If unsure have a look at the help section of the
+	  driver. Fallback governor will be the performance governor.
 endchoice
 
 config CPU_FREQ_GOV_PERFORMANCE
Index: linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq.c
===================================================================
--- linux-2.6.23-rc1-mm2_fixed.orig/drivers/cpufreq/cpufreq.c
+++ linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq.c
@@ -1485,6 +1485,31 @@ static int __cpufreq_governor(struct cpu
 {
 	int ret;
 
+	/* Only must be defined when default governor is known to have latency
+	   restrictions, like e.g. conservative or ondemand.
+	   That this is the case is already ensured in Kconfig
+	*/
+#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
+	struct cpufreq_governor *gov = CPUFREQ_PERFORMANCE_GOVERNOR;
+#else
+	struct cpufreq_governor *gov = NULL;
+#endif
+
+	if (policy->governor->max_transition_latency &&
+	    policy->cpuinfo.transition_latency >
+	    policy->governor->max_transition_latency) {
+		if (!gov)
+			return -EINVAL;
+		else {
+			printk(KERN_WARNING "%s governor failed, too long"
+			       " transition latency of HW, fallback"
+			       " to %s governor\n",
+			       policy->governor->name,
+			       gov->name);
+			policy->governor = gov;
+		}
+	}
+
 	if (!try_module_get(policy->governor->owner))
 		return -EINVAL;
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [-mm patch] CPUfreq: Only check for transition latency on problematic governors
  2007-08-02 14:38       ` [-mm patch] CPUfreq: Only check for transition latency on problematic governors Thomas Renninger
@ 2007-08-02 14:54         ` Adrian Bunk
  2007-08-02 15:24           ` Thomas Renninger
  0 siblings, 1 reply; 4+ messages in thread
From: Adrian Bunk @ 2007-08-02 14:54 UTC (permalink / raw)
  To: Thomas Renninger
  Cc: Gabriel C, davej, Andrew Morton, Miles Lane, LKML, cpufreq,
	Pallipadi, Venkatesh

On Thu, Aug 02, 2007 at 04:38:06PM +0200, Thomas Renninger wrote:
> On Thu, 2007-08-02 at 15:48 +0200, Adrian Bunk wrote:
> > On Thu, Aug 02, 2007 at 02:28:06AM +0200, Gabriel C wrote:
> > > Andrew Morton wrote:
> > > > On Wed, 1 Aug 2007 16:31:46 -0700
> > > > "Miles Lane" <miles.lane@gmail.com> wrote:
> > > > 
> > > >>   LD      .tmp_vmlinux1
> > > >> drivers/built-in.o: In function `__cpufreq_governor':
> > > >> cpufreq.c:(.text+0xaf178): undefined reference to `cpufreq_gov_performance'
> > > >> cpufreq.c:(.text+0xaf18a): undefined reference to `cpufreq_gov_performance'
> > > >> make: *** [.tmp_vmlinux1] Error 1
> > > > 
> > > > One for Thomas, I expect.
> > > 
> > > Is this patch :
> > > 
> > > cpufreq-allow-ondemand-and-conservative-cpufreq-governors-to-be-used-as-default.patch
> > > 
> > > Reverting it here fixes the error.
> > 
> > Possible fix below.
> Or this one.
> Advantage: You can still have cpufreq core without the performance 
>            governor built.
> Disadvantage: The logic whether transition latency checks are
>               needed/done is moved to Kconfig.
>               Means, if you write a governor that has transition
>               latency values above 0, you must let it depend on
>               the performance governor in Kconfig.
> 
> Hope I got all .config possibilities with that one now.
> Attached is also a replacement patch for this one:
> cpufreq-allow-ondemand-and-conservative-cpufreq-governors-to-be-used-as-default.patch
> 
> 
> CPUfreq: Only check for transition latency on problematic governors
> 
> Signed-off-by: Thomas Renninger <trenn@suse.de>
> --
> 
> --- linux-2.6.23-rc1-mm2/include/linux/cpufreq.h	2007-08-02 16:01:36.000000000 +0200
> +++ linux-2.6.23-rc1-mm2_fixed/include/linux/cpufreq.h	2007-08-02 15:21:28.000000000 +0200
> @@ -299,8 +299,10 @@ static inline unsigned int cpufreq_get(u
>    Performance governor is fallback governor if any other gov failed to
>    auto load due latency restrictions
>  */
> +#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
>  extern struct cpufreq_governor cpufreq_gov_performance;
>  #define CPUFREQ_PERFORMANCE_GOVERNOR	(&cpufreq_gov_performance)
> +#endif
>  #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
>  #define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_performance)
>  #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
> --- linux-2.6.23-rc1-mm2/drivers/cpufreq/cpufreq.c	2007-08-02 16:01:35.000000000 +0200
> +++ linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq.c	2007-08-02 16:23:09.000000000 +0200
> @@ -1484,17 +1484,30 @@ static int __cpufreq_governor(struct cpu
>  					unsigned int event)
>  {
>  	int ret;
> +
> +	/* Only must be defined when default governor is known to have latency
> +	   restrictions, like e.g. conservative or ondemand.
> +	   That this is the case is already ensured in Kconfig
> +	*/
> +#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
>  	struct cpufreq_governor *gov = CPUFREQ_PERFORMANCE_GOVERNOR;
> +#else
> +	struct cpufreq_governor *gov = NULL;
> +#endif
>...

Looks good, but you could remove CPUFREQ_PERFORMANCE_GOVERNOR and 
directly use cpufreq_gov_performance.
  
cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [-mm patch] CPUfreq: Only check for transition latency on problematic governors
  2007-08-02 14:54         ` Adrian Bunk
@ 2007-08-02 15:24           ` Thomas Renninger
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Renninger @ 2007-08-02 15:24 UTC (permalink / raw)
  To: Adrian Bunk, akpm
  Cc: Gabriel C, davej, Miles Lane, LKML, cpufreq, Pallipadi, Venkatesh

On Thu, 2007-08-02 at 16:54 +0200, Adrian Bunk wrote:
> On Thu, Aug 02, 2007 at 04:38:06PM +0200, Thomas Renninger wrote:
--- CUT --- 
> > 
> > CPUfreq: Only check for transition latency on problematic governors
> > 
> > Signed-off-by: Thomas Renninger <trenn@suse.de>
> > --
> > 
> > --- linux-2.6.23-rc1-mm2/include/linux/cpufreq.h	2007-08-02 16:01:36.000000000 +0200
> > +++ linux-2.6.23-rc1-mm2_fixed/include/linux/cpufreq.h	2007-08-02 15:21:28.000000000 +0200
> > @@ -299,8 +299,10 @@ static inline unsigned int cpufreq_get(u
> >    Performance governor is fallback governor if any other gov failed to
> >    auto load due latency restrictions
> >  */
> > +#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
> >  extern struct cpufreq_governor cpufreq_gov_performance;
> >  #define CPUFREQ_PERFORMANCE_GOVERNOR	(&cpufreq_gov_performance)
> > +#endif
> >  #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
> >  #define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_performance)
> >  #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
> > --- linux-2.6.23-rc1-mm2/drivers/cpufreq/cpufreq.c	2007-08-02 16:01:35.000000000 +0200
> > +++ linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq.c	2007-08-02 16:23:09.000000000 +0200
> > @@ -1484,17 +1484,30 @@ static int __cpufreq_governor(struct cpu
> >  					unsigned int event)
> >  {
> >  	int ret;
> > +
> > +	/* Only must be defined when default governor is known to have latency
> > +	   restrictions, like e.g. conservative or ondemand.
> > +	   That this is the case is already ensured in Kconfig
> > +	*/
> > +#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
> >  	struct cpufreq_governor *gov = CPUFREQ_PERFORMANCE_GOVERNOR;
> > +#else
> > +	struct cpufreq_governor *gov = NULL;
> > +#endif
> >...
> 
> Looks good, but you could remove CPUFREQ_PERFORMANCE_GOVERNOR and 
> directly use.

Thanks.
I cut out the "#define CPUFREQ_PERFORMANCE_GOVERNOR	(&cpufreq_gov_performance)"
in include/linux/cpufreq.h
and replaced CPUFREQ_PERFORMANCE_GOVERNOR with &cpufreq_gov_performance.

The old patch should revert cleanly, so a replacement patch is more
useful? Tell me if you need a new on top patch.
The patch that should get replaced is this one:
cpufreq-allow-ondemand-and-conservative-cpufreq-governors-to-be-used-as-default.patch

Thanks,

    Thomas

--------

Allow ondemand and conservative cpufreq governors to be used as default

Depending on the transition latency of the HW for cpufreq switches, the
ondemand or conservative governor cannot be used with certain cpufreq drivers.
Still the ondemand should be the default governor on a wide range of systems.
This patch allows this and lets the governor fallback to the performance
governor at cpufreq driver load time, if the driver does not support fast
enough frequency switching.

Main benefit is that on e.g. installation or other systems without userspace
support a working dynamic cpufreq support can be achieved on most systems by
simply loading the cpufreq driver. This is especially essential for recent
x86(_64) laptop hardware which may rely on working dynamic cpufreq OS support.

Signed-off-by: Thomas Renninger <trenn@suse.de>

---
 drivers/cpufreq/Kconfig                |   27 +++++++++++++++++++++++----
 drivers/cpufreq/cpufreq.c              |   25 +++++++++++++++++++++++++
 drivers/cpufreq/cpufreq_conservative.c |   19 +++++++++----------
 drivers/cpufreq/cpufreq_ondemand.c     |   22 +++++++++-------------
 include/linux/cpufreq.h                |   21 ++++++++++++++++++---
 5 files changed, 84 insertions(+), 30 deletions(-)

Index: linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-2.6.23-rc1-mm2_fixed.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq_ondemand.c
@@ -47,7 +47,7 @@ static unsigned int def_sampling_rate;
 			(def_sampling_rate / MIN_SAMPLING_RATE_RATIO)
 #define MAX_SAMPLING_RATE			(500 * def_sampling_rate)
 #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER	(1000)
-#define TRANSITION_LATENCY_LIMIT		(10 * 1000)
+#define TRANSITION_LATENCY_LIMIT		(10 * 1000 * 1000)
 
 static void do_dbs_timer(struct work_struct *work);
 
@@ -508,12 +508,6 @@ static int cpufreq_governor_dbs(struct c
 		if ((!cpu_online(cpu)) || (!policy->cur))
 			return -EINVAL;
 
-		if (policy->cpuinfo.transition_latency >
-				(TRANSITION_LATENCY_LIMIT * 1000)) {
-			printk(KERN_WARNING "ondemand governor failed to load "
-			       "due to too long transition latency\n");
-			return -EINVAL;
-		}
 		if (this_dbs_info->enable) /* Already enabled */
 			break;
 
@@ -585,11 +579,13 @@ static int cpufreq_governor_dbs(struct c
 	return 0;
 }
 
-static struct cpufreq_governor cpufreq_gov_dbs = {
-	.name = "ondemand",
-	.governor = cpufreq_governor_dbs,
-	.owner = THIS_MODULE,
+struct cpufreq_governor cpufreq_gov_ondemand = {
+	.name			= "ondemand",
+	.governor		= cpufreq_governor_dbs,
+	.max_transition_latency = TRANSITION_LATENCY_LIMIT,
+	.owner			= THIS_MODULE,
 };
+EXPORT_SYMBOL(cpufreq_gov_ondemand);
 
 static int __init cpufreq_gov_dbs_init(void)
 {
@@ -598,12 +594,12 @@ static int __init cpufreq_gov_dbs_init(v
 		printk(KERN_ERR "Creation of kondemand failed\n");
 		return -EFAULT;
 	}
-	return cpufreq_register_governor(&cpufreq_gov_dbs);
+	return cpufreq_register_governor(&cpufreq_gov_ondemand);
 }
 
 static void __exit cpufreq_gov_dbs_exit(void)
 {
-	cpufreq_unregister_governor(&cpufreq_gov_dbs);
+	cpufreq_unregister_governor(&cpufreq_gov_ondemand);
 	destroy_workqueue(kondemand_wq);
 }
 
Index: linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-2.6.23-rc1-mm2_fixed.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq_conservative.c
@@ -58,7 +58,7 @@ static unsigned int 				def_sampling_rat
 #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER	(1000)
 #define DEF_SAMPLING_DOWN_FACTOR		(1)
 #define MAX_SAMPLING_DOWN_FACTOR		(10)
-#define TRANSITION_LATENCY_LIMIT		(10 * 1000)
+#define TRANSITION_LATENCY_LIMIT		(10 * 1000 * 1000)
 
 static void do_dbs_timer(struct work_struct *work);
 
@@ -466,9 +466,6 @@ static int cpufreq_governor_dbs(struct c
 		    (!policy->cur))
 			return -EINVAL;
 
-		if (policy->cpuinfo.transition_latency >
-				(TRANSITION_LATENCY_LIMIT * 1000))
-			return -EINVAL;
 		if (this_dbs_info->enable) /* Already enabled */
 			break;
 		 
@@ -551,15 +548,17 @@ static int cpufreq_governor_dbs(struct c
 	return 0;
 }
 
-static struct cpufreq_governor cpufreq_gov_dbs = {
-	.name		= "conservative",
-	.governor	= cpufreq_governor_dbs,
-	.owner		= THIS_MODULE,
+struct cpufreq_governor cpufreq_gov_conservative = {
+	.name			= "conservative",
+	.governor		= cpufreq_governor_dbs,
+	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
+	.owner			= THIS_MODULE,
 };
+EXPORT_SYMBOL(cpufreq_gov_conservative);
 
 static int __init cpufreq_gov_dbs_init(void)
 {
-	return cpufreq_register_governor(&cpufreq_gov_dbs);
+	return cpufreq_register_governor(&cpufreq_gov_conservative);
 }
 
 static void __exit cpufreq_gov_dbs_exit(void)
@@ -567,7 +566,7 @@ static void __exit cpufreq_gov_dbs_exit(
 	/* Make sure that the scheduled work is indeed not running */
 	flush_scheduled_work();
 
-	cpufreq_unregister_governor(&cpufreq_gov_dbs);
+	cpufreq_unregister_governor(&cpufreq_gov_conservative);
 }
 
 
Index: linux-2.6.23-rc1-mm2_fixed/include/linux/cpufreq.h
===================================================================
--- linux-2.6.23-rc1-mm2_fixed.orig/include/linux/cpufreq.h
+++ linux-2.6.23-rc1-mm2_fixed/include/linux/cpufreq.h
@@ -163,6 +163,9 @@ struct cpufreq_governor {
 	char	name[CPUFREQ_NAME_LEN];
 	int 	(*governor)	(struct cpufreq_policy *policy,
 				 unsigned int event);
+	unsigned int max_transition_latency; /* HW must be able to switch to
+			next freq faster than this value in nano secs or we
+			will fallback to performance governor */
 	struct list_head	governor_list;
 	struct module		*owner;
 };
@@ -292,12 +295,24 @@ static inline unsigned int cpufreq_get(u
  *********************************************************************/
 
 
-#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
+/*
+  Performance governor is fallback governor if any other gov failed to
+  auto load due latency restrictions
+*/
+#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
 extern struct cpufreq_governor cpufreq_gov_performance;
-#define CPUFREQ_DEFAULT_GOVERNOR	&cpufreq_gov_performance
+#endif
+#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
+#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_performance)
 #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
 extern struct cpufreq_governor cpufreq_gov_userspace;
-#define CPUFREQ_DEFAULT_GOVERNOR	&cpufreq_gov_userspace
+#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_userspace)
+#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
+extern struct cpufreq_governor cpufreq_gov_ondemand;
+#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_ondemand)
+#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE)
+extern struct cpufreq_governor cpufreq_gov_conservative;
+#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_conservative)
 #endif
 
 
Index: linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/Kconfig
===================================================================
--- linux-2.6.23-rc1-mm2_fixed.orig/drivers/cpufreq/Kconfig
+++ linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/Kconfig
@@ -56,10 +56,6 @@ config CPU_FREQ_STAT_DETAILS
 
 	  If in doubt, say N.
 
-# Note that it is not currently possible to set the other governors (such as ondemand)
-# as the default, since if they fail to initialise, cpufreq will be
-# left in an undefined state.
-
 choice
 	prompt "Default CPUFreq governor"
 	default CPU_FREQ_DEFAULT_GOV_USERSPACE if CPU_FREQ_SA1100 || CPU_FREQ_SA1110
@@ -85,6 +81,29 @@ config CPU_FREQ_DEFAULT_GOV_USERSPACE
 	  program shall be able to set the CPU dynamically without having
 	  to enable the userspace governor manually.
 
+config CPU_FREQ_DEFAULT_GOV_ONDEMAND
+	bool "ondemand"
+	select CPU_FREQ_GOV_ONDEMAND
+	select CPU_FREQ_GOV_PERFORMANCE
+	help
+	  Use the CPUFreq governor 'ondemand' as default. This allows
+	  you to get a full dynamic frequency capable system by simply
+	  loading your cpufreq low-level hardware driver.
+	  Be aware that not all cpufreq drivers support the ondemand
+	  governor. If unsure have a look at the help section of the
+	  driver. Fallback governor will be the performance governor.
+
+config CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
+	bool "conservative"
+	select CPU_FREQ_GOV_CONSERVATIVE
+	select CPU_FREQ_GOV_PERFORMANCE
+	help
+	  Use the CPUFreq governor 'conservative' as default. This allows
+	  you to get a full dynamic frequency capable system by simply
+	  loading your cpufreq low-level hardware driver.
+	  Be aware that not all cpufreq drivers support the conservative
+	  governor. If unsure have a look at the help section of the
+	  driver. Fallback governor will be the performance governor.
 endchoice
 
 config CPU_FREQ_GOV_PERFORMANCE
Index: linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq.c
===================================================================
--- linux-2.6.23-rc1-mm2_fixed.orig/drivers/cpufreq/cpufreq.c
+++ linux-2.6.23-rc1-mm2_fixed/drivers/cpufreq/cpufreq.c
@@ -1485,6 +1485,31 @@ static int __cpufreq_governor(struct cpu
 {
 	int ret;
 
+	/* Only must be defined when default governor is known to have latency
+	   restrictions, like e.g. conservative or ondemand.
+	   That this is the case is already ensured in Kconfig
+	*/
+#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
+	struct cpufreq_governor *gov = &cpufreq_gov_performance;
+#else
+	struct cpufreq_governor *gov = NULL;
+#endif
+
+	if (policy->governor->max_transition_latency &&
+	    policy->cpuinfo.transition_latency >
+	    policy->governor->max_transition_latency) {
+		if (!gov)
+			return -EINVAL;
+		else {
+			printk(KERN_WARNING "%s governor failed, too long"
+			       " transition latency of HW, fallback"
+			       " to %s governor\n",
+			       policy->governor->name,
+			       gov->name);
+			policy->governor = gov;
+		}
+	}
+
 	if (!try_module_get(policy->governor->owner))
 		return -EINVAL;
 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-08-02 15:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <a44ae5cd0708011631k7f476af2jcd01d2875f4b4b17@mail.gmail.com>
     [not found] ` <20070801165704.a26961b7.akpm@linux-foundation.org>
     [not found]   ` <46B12516.4090006@googlemail.com>
2007-08-02 13:48     ` [-mm patch] CPU_FREQ_GOV_PERFORMANCE must always be y Adrian Bunk
2007-08-02 14:38       ` [-mm patch] CPUfreq: Only check for transition latency on problematic governors Thomas Renninger
2007-08-02 14:54         ` Adrian Bunk
2007-08-02 15:24           ` Thomas Renninger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox