Introduce a governor rating scheme to pick the right governor by default.
Signed-off-by: Venkatesh Pallipadi <[email protected]>
Index: linux-2.6.22-rc-mm/include/linux/cpuidle.h
===================================================================
--- linux-2.6.22-rc-mm.orig/include/linux/cpuidle.h 2007-06-05 17:00:09.000000000 -0700
+++ linux-2.6.22-rc-mm/include/linux/cpuidle.h 2007-06-05 17:01:08.000000000 -0700
@@ -159,6 +159,7 @@
struct cpuidle_governor {
char name[CPUIDLE_NAME_LEN];
struct list_head governor_list;
+ unsigned int rating;
int (*init) (struct cpuidle_device *dev);
void (*exit) (struct cpuidle_device *dev);
Index: linux-2.6.22-rc-mm/drivers/cpuidle/governors/menu.c
===================================================================
--- linux-2.6.22-rc-mm.orig/drivers/cpuidle/governors/menu.c 2007-06-05 15:46:34.000000000 -0700
+++ linux-2.6.22-rc-mm/drivers/cpuidle/governors/menu.c 2007-06-05 17:04:32.000000000 -0700
@@ -153,6 +153,7 @@
struct cpuidle_governor menu_governor = {
.name = "menu",
+ .rating = 20,
.scan = menu_scan_device,
.select = menu_select,
.reflect = menu_reflect,
Index: linux-2.6.22-rc-mm/drivers/cpuidle/governor.c
===================================================================
--- linux-2.6.22-rc-mm.orig/drivers/cpuidle/governor.c 2007-06-01 16:25:49.000000000 -0700
+++ linux-2.6.22-rc-mm/drivers/cpuidle/governor.c 2007-06-05 17:15:05.000000000 -0700
@@ -131,7 +131,8 @@
if (__cpuidle_find_governor(gov->name) == NULL) {
ret = 0;
list_add_tail(&gov->governor_list, &cpuidle_governors);
- if (!cpuidle_curr_governor)
+ if (!cpuidle_curr_governor ||
+ cpuidle_curr_governor->rating < gov->rating)
cpuidle_switch_governor(gov);
}
mutex_unlock(&cpuidle_lock);
@@ -142,6 +143,29 @@
EXPORT_SYMBOL_GPL(cpuidle_register_governor);
/**
+ * cpuidle_replace_governor - find a replacement governor
+ * @exclude_rating: the rating that will be skipped while looking for
+ * new governor.
+ */
+struct cpuidle_governor *cpuidle_replace_governor(int exclude_rating)
+{
+ struct cpuidle_governor *gov;
+ struct cpuidle_governor *ret_gov = NULL;
+ unsigned int max_rating = 0;
+
+ list_for_each_entry(gov, &cpuidle_governors, governor_list) {
+ if (gov->rating == exclude_rating)
+ continue;
+ if (gov->rating > max_rating) {
+ max_rating = gov->rating;
+ ret_gov = gov;
+ }
+ }
+
+ return ret_gov;
+}
+
+/**
* cpuidle_unregister_governor - unregisters a governor
* @gov: the governor
*/
@@ -151,8 +175,11 @@
return;
mutex_lock(&cpuidle_lock);
- if (gov == cpuidle_curr_governor)
- cpuidle_switch_governor(NULL);
+ if (gov == cpuidle_curr_governor) {
+ struct cpuidle_governor *new_gov;
+ new_gov = cpuidle_replace_governor(gov->rating);
+ cpuidle_switch_governor(new_gov);
+ }
list_del(&gov->governor_list);
mutex_unlock(&cpuidle_lock);
}
Index: linux-2.6.22-rc-mm/drivers/cpuidle/governors/ladder.c
===================================================================
--- linux-2.6.22-rc-mm.orig/drivers/cpuidle/governors/ladder.c 2007-06-01 16:25:49.000000000 -0700
+++ linux-2.6.22-rc-mm/drivers/cpuidle/governors/ladder.c 2007-06-05 17:03:37.000000000 -0700
@@ -199,6 +199,7 @@
static struct cpuidle_governor ladder_governor = {
.name = "ladder",
+ .rating = 10,
.init = ladder_init_device,
.exit = ladder_exit_device,
.scan = ladder_scan_device,
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]