2 * governor.c - governor support
8 * This code is licenced under the GPL.
11 #include <linux/cpu.h>
12 #include <linux/cpuidle.h>
13 #include <linux/mutex.h>
14 #include <linux/module.h>
15 #include <linux/pm_qos.h>
19 char param_governor[CPUIDLE_NAME_LEN];
21 LIST_HEAD(cpuidle_governors);
22 struct cpuidle_governor *cpuidle_curr_governor;
25 * __cpuidle_find_governor - finds a governor of the specified name
28 * Must be called with cpuidle_lock acquired.
30 static struct cpuidle_governor * __cpuidle_find_governor(const char *str)
32 struct cpuidle_governor *gov;
34 list_for_each_entry(gov, &cpuidle_governors, governor_list)
35 if (!strncasecmp(str, gov->name, CPUIDLE_NAME_LEN))
42 * cpuidle_switch_governor - changes the governor
43 * @gov: the new target governor
44 * Must be called with cpuidle_lock acquired.
46 int cpuidle_switch_governor(struct cpuidle_governor *gov)
48 struct cpuidle_device *dev;
53 if (gov == cpuidle_curr_governor)
56 cpuidle_uninstall_idle_handler();
58 if (cpuidle_curr_governor) {
59 list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
60 cpuidle_disable_device(dev);
63 cpuidle_curr_governor = gov;
66 list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
67 cpuidle_enable_device(dev);
68 cpuidle_install_idle_handler();
69 printk(KERN_INFO "cpuidle: using governor %s\n", gov->name);
76 * cpuidle_register_governor - registers a governor
79 int cpuidle_register_governor(struct cpuidle_governor *gov)
83 if (!gov || !gov->select)
86 if (cpuidle_disabled())
89 mutex_lock(&cpuidle_lock);
90 if (__cpuidle_find_governor(gov->name) == NULL) {
92 list_add_tail(&gov->governor_list, &cpuidle_governors);
93 if (!cpuidle_curr_governor ||
94 !strncasecmp(param_governor, gov->name, CPUIDLE_NAME_LEN) ||
95 (cpuidle_curr_governor->rating < gov->rating &&
96 strncasecmp(param_governor, cpuidle_curr_governor->name,
98 cpuidle_switch_governor(gov);
100 mutex_unlock(&cpuidle_lock);
106 * cpuidle_governor_latency_req - Compute a latency constraint for CPU
109 int cpuidle_governor_latency_req(unsigned int cpu)
111 int global_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
112 struct device *device = get_cpu_device(cpu);
113 int device_req = dev_pm_qos_raw_read_value(device);
115 return device_req < global_req ? device_req : global_req;