cpuidle: Add cpuidle.governor= command line parameter

This change “cpuidle: Add cpuidle.governor= command line parameter” in Linux kernel is authored by Rafael J. Wysocki <rafael.j.wysocki [at] intel.com> on Wed Dec 5 23:45:34 2018 +0100.

cpuidle: Add cpuidle.governor= command line parameter

Add cpuidle.governor= command line parameter to allow the default
cpuidle governor to be replaced.

That is useful, for example, if someone running a tickful kernel
wants to use the menu governor on it.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

This Linux change may have been applied to various maintained Linux releases and you can find Linux releases including commit 61cb575.

There are 21 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 Documentation/admin-guide/kernel-parameters.txt | 3 +++
 Documentation/admin-guide/pm/cpuidle.rst        | 7 +++++++
 drivers/cpuidle/cpuidle.c                       | 1 +
 drivers/cpuidle/cpuidle.h                       | 1 +
 drivers/cpuidle/governor.c                      | 9 +++++++--
 5 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 19f4423..60fb991 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -674,6 +674,9 @@
 	cpuidle.off=1	[CPU_IDLE]
 			disable the cpuidle sub-system
+	cpuidle.governor=
+			[CPU_IDLE] Name of the cpuidle governor to use.
 	cpufreq.off=1	[CPU_FREQ]
 			disable the cpufreq sub-system
diff --git a/Documentation/admin-guide/pm/cpuidle.rst b/Documentation/admin-guide/pm/cpuidle.rst
index 80b4f26..9a34484 100644
--- a/Documentation/admin-guide/pm/cpuidle.rst
+++ b/Documentation/admin-guide/pm/cpuidle.rst
@@ -566,6 +566,13 @@ processors implementing the architecture (i.e. CPU instruction set) in question,
 however, so it is rather crude and not very energy-efficient.  For this reason,
 it is not recommended for production use.
+The ``cpuidle.governor=`` kernel command line switch allows the ``CPUIdle``
+governor to use to be specified.  It has to be appended with a string matching
+the name of an available governor (e.g. ``cpuidle.governor=menu``) and that
+governor will be used instead of the default one.  It is possible to force
+the ``menu`` governor to be used on the systems that use the ``ladder`` governor
+by default this way, for example.
 The other kernel command line parameters controlling CPU idle time management
 described below are only relevant for the *x86* architecture and some of
 them affect Intel processors only.
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 4a97446..f7c5804 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -702,4 +702,5 @@ static int __init cpuidle_init(void)
 module_param(off, int, 0444);
+module_param_string(governor, param_governor, CPUIDLE_NAME_LEN, 0444);
diff --git a/drivers/cpuidle/cpuidle.h b/drivers/cpuidle/cpuidle.h
index 2965ab3..d661310 100644
--- a/drivers/cpuidle/cpuidle.h
+++ b/drivers/cpuidle/cpuidle.h
@@ -7,6 +7,7 @@
 /* For internal use only */
+extern char param_governor[];
 extern struct cpuidle_governor *cpuidle_curr_governor;
 extern struct list_head cpuidle_governors;
 extern struct list_head cpuidle_detected_devices;
diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
index 9fed1b82..bb93e5c 100644
--- a/drivers/cpuidle/governor.c
+++ b/drivers/cpuidle/governor.c
@@ -11,10 +11,13 @@
 #include <linux/cpu.h>
 #include <linux/cpuidle.h>
 #include <linux/mutex.h>
+#include <linux/module.h>
 #include <linux/pm_qos.h>
 #include "cpuidle.h"
+char param_governor[CPUIDLE_NAME_LEN];
 struct cpuidle_governor *cpuidle_curr_governor;
@@ -86,9 +89,11 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
 	if (__cpuidle_find_governor(gov->name) == NULL) {
 		ret = 0;
-		list_add_tail(&gov->governor_list, &cpuidle_governors);
 		if (!cpuidle_curr_governor ||
-		    cpuidle_curr_governor->rating < gov->rating)
+		    !strncasecmp(param_governor, gov->name, CPUIDLE_NAME_LEN) ||
+		    (cpuidle_curr_governor->rating < gov->rating &&
+		     strncasecmp(param_governor, cpuidle_curr_governor->name,

The commit for this change in Linux stable tree is 61cb575 (patch).

Leave a Reply

Your email address will not be published. Required fields are marked *