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/cpu.h>
12 #include <linux/cpuidle.h>
13 #include <linux/mutex.h>
14 #include <linux/pm_qos.h>
18 LIST_HEAD(cpuidle_governors);
19 struct cpuidle_governor *cpuidle_curr_governor;
22 * __cpuidle_find_governor - finds a governor of the specified name
25 * Must be called with cpuidle_lock acquired.
27 static struct cpuidle_governor * __cpuidle_find_governor(const char *str)
29 struct cpuidle_governor *gov;
31 list_for_each_entry(gov, &cpuidle_governors, governor_list)
32 if (!strncasecmp(str, gov->name, CPUIDLE_NAME_LEN))
39 * cpuidle_switch_governor - changes the governor
40 * @gov: the new target governor
41 * Must be called with cpuidle_lock acquired.
43 int cpuidle_switch_governor(struct cpuidle_governor *gov)
45 struct cpuidle_device *dev;
50 if (gov == cpuidle_curr_governor)
53 cpuidle_uninstall_idle_handler();
55 if (cpuidle_curr_governor) {
56 list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
57 cpuidle_disable_device(dev);
60 cpuidle_curr_governor = gov;
63 list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
64 cpuidle_enable_device(dev);
65 cpuidle_install_idle_handler();
66 printk(KERN_INFO "cpuidle: using governor %s\n", gov->name);
73 * cpuidle_register_governor - registers a governor
76 int cpuidle_register_governor(struct cpuidle_governor *gov)
80 if (!gov || !gov->select)
83 if (cpuidle_disabled())
86 mutex_lock(&cpuidle_lock);
87 if (__cpuidle_find_governor(gov->name) == NULL) {
89 list_add_tail(&gov->governor_list, &cpuidle_governors);
90 if (!cpuidle_curr_governor ||
91 cpuidle_curr_governor->rating < gov->rating)
92 cpuidle_switch_governor(gov);
94 mutex_unlock(&cpuidle_lock);
100 * cpuidle_governor_latency_req - Compute a latency constraint for CPU
103 int cpuidle_governor_latency_req(unsigned int cpu)
105 int global_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
106 struct device *device = get_cpu_device(cpu);
107 int device_req = dev_pm_qos_raw_read_value(device);
109 return device_req < global_req ? device_req : global_req;