]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/cpuidle/governor.c
2 * governor.c - governor support
4 * (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
5 * Shaohua Li <shaohua.li@intel.com>
6 * Adam Belay <abelay@novell.com>
8 * This code is licenced under the GPL.
11 #include <linux/mutex.h>
12 #include <linux/module.h>
13 #include <linux/cpuidle.h>
17 LIST_HEAD(cpuidle_governors
);
18 struct cpuidle_governor
*cpuidle_curr_governor
;
21 * __cpuidle_find_governor - finds a governor of the specified name
24 * Must be called with cpuidle_lock acquired.
26 static struct cpuidle_governor
* __cpuidle_find_governor(const char *str
)
28 struct cpuidle_governor
*gov
;
30 list_for_each_entry(gov
, &cpuidle_governors
, governor_list
)
31 if (!strnicmp(str
, gov
->name
, CPUIDLE_NAME_LEN
))
38 * cpuidle_switch_governor - changes the governor
39 * @gov: the new target governor
41 * NOTE: "gov" can be NULL to specify disabled
42 * Must be called with cpuidle_lock acquired.
44 int cpuidle_switch_governor(struct cpuidle_governor
*gov
)
46 struct cpuidle_device
*dev
;
48 if (gov
== cpuidle_curr_governor
)
51 cpuidle_uninstall_idle_handler();
53 if (cpuidle_curr_governor
) {
54 list_for_each_entry(dev
, &cpuidle_detected_devices
, device_list
)
55 cpuidle_disable_device(dev
);
56 module_put(cpuidle_curr_governor
->owner
);
59 cpuidle_curr_governor
= gov
;
62 if (!try_module_get(cpuidle_curr_governor
->owner
))
64 list_for_each_entry(dev
, &cpuidle_detected_devices
, device_list
)
65 cpuidle_enable_device(dev
);
66 cpuidle_install_idle_handler();
67 printk(KERN_INFO
"cpuidle: using governor %s\n", gov
->name
);
74 * cpuidle_register_governor - registers a governor
77 int cpuidle_register_governor(struct cpuidle_governor
*gov
)
81 if (!gov
|| !gov
->select
)
84 if (cpuidle_disabled())
87 mutex_lock(&cpuidle_lock
);
88 if (__cpuidle_find_governor(gov
->name
) == NULL
) {
90 list_add_tail(&gov
->governor_list
, &cpuidle_governors
);
91 if (!cpuidle_curr_governor
||
92 cpuidle_curr_governor
->rating
< gov
->rating
)
93 cpuidle_switch_governor(gov
);
95 mutex_unlock(&cpuidle_lock
);
101 * cpuidle_replace_governor - find a replacement governor
102 * @exclude_rating: the rating that will be skipped while looking for
105 static struct cpuidle_governor
*cpuidle_replace_governor(int exclude_rating
)
107 struct cpuidle_governor
*gov
;
108 struct cpuidle_governor
*ret_gov
= NULL
;
109 unsigned int max_rating
= 0;
111 list_for_each_entry(gov
, &cpuidle_governors
, governor_list
) {
112 if (gov
->rating
== exclude_rating
)
114 if (gov
->rating
> max_rating
) {
115 max_rating
= gov
->rating
;
124 * cpuidle_unregister_governor - unregisters a governor
127 void cpuidle_unregister_governor(struct cpuidle_governor
*gov
)
132 mutex_lock(&cpuidle_lock
);
133 if (gov
== cpuidle_curr_governor
) {
134 struct cpuidle_governor
*new_gov
;
135 new_gov
= cpuidle_replace_governor(gov
->rating
);
136 cpuidle_switch_governor(new_gov
);
138 list_del(&gov
->governor_list
);
139 mutex_unlock(&cpuidle_lock
);