net/mlx5e: Make function mlx5e_change_rep_mtu() static
[linux-2.6/btrfs-unstable.git] / drivers / cpuidle / governor.c
blob5d359aff3cc538005f6ebeb3b32a2ded2dd5605b
1 /*
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.
9 */
11 #include <linux/mutex.h>
12 #include <linux/cpuidle.h>
14 #include "cpuidle.h"
16 LIST_HEAD(cpuidle_governors);
17 struct cpuidle_governor *cpuidle_curr_governor;
19 /**
20 * __cpuidle_find_governor - finds a governor of the specified name
21 * @str: the name
23 * Must be called with cpuidle_lock acquired.
25 static struct cpuidle_governor * __cpuidle_find_governor(const char *str)
27 struct cpuidle_governor *gov;
29 list_for_each_entry(gov, &cpuidle_governors, governor_list)
30 if (!strncasecmp(str, gov->name, CPUIDLE_NAME_LEN))
31 return gov;
33 return NULL;
36 /**
37 * cpuidle_switch_governor - changes the governor
38 * @gov: the new target governor
39 * Must be called with cpuidle_lock acquired.
41 int cpuidle_switch_governor(struct cpuidle_governor *gov)
43 struct cpuidle_device *dev;
45 if (!gov)
46 return -EINVAL;
48 if (gov == cpuidle_curr_governor)
49 return 0;
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);
58 cpuidle_curr_governor = gov;
60 if (gov) {
61 list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
62 cpuidle_enable_device(dev);
63 cpuidle_install_idle_handler();
64 printk(KERN_INFO "cpuidle: using governor %s\n", gov->name);
67 return 0;
70 /**
71 * cpuidle_register_governor - registers a governor
72 * @gov: the governor
74 int cpuidle_register_governor(struct cpuidle_governor *gov)
76 int ret = -EEXIST;
78 if (!gov || !gov->select)
79 return -EINVAL;
81 if (cpuidle_disabled())
82 return -ENODEV;
84 mutex_lock(&cpuidle_lock);
85 if (__cpuidle_find_governor(gov->name) == NULL) {
86 ret = 0;
87 list_add_tail(&gov->governor_list, &cpuidle_governors);
88 if (!cpuidle_curr_governor ||
89 cpuidle_curr_governor->rating < gov->rating)
90 cpuidle_switch_governor(gov);
92 mutex_unlock(&cpuidle_lock);
94 return ret;