]>
Commit | Line | Data |
---|---|---|
4f86d3a8 LB |
1 | /* |
2 | * governor.c - governor support | |
3 | * | |
4 | * (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> | |
5 | * Shaohua Li <shaohua.li@intel.com> | |
6 | * Adam Belay <abelay@novell.com> | |
7 | * | |
8 | * This code is licenced under the GPL. | |
9 | */ | |
10 | ||
0fc784fb | 11 | #include <linux/cpu.h> |
4f86d3a8 | 12 | #include <linux/cpuidle.h> |
0fc784fb | 13 | #include <linux/mutex.h> |
61cb5758 | 14 | #include <linux/module.h> |
0fc784fb | 15 | #include <linux/pm_qos.h> |
4f86d3a8 LB |
16 | |
17 | #include "cpuidle.h" | |
18 | ||
61cb5758 RW |
19 | char param_governor[CPUIDLE_NAME_LEN]; |
20 | ||
4f86d3a8 LB |
21 | LIST_HEAD(cpuidle_governors); |
22 | struct cpuidle_governor *cpuidle_curr_governor; | |
cb5d8c45 | 23 | struct cpuidle_governor *cpuidle_prev_governor; |
4f86d3a8 LB |
24 | |
25 | /** | |
cb5d8c45 | 26 | * cpuidle_find_governor - finds a governor of the specified name |
4f86d3a8 LB |
27 | * @str: the name |
28 | * | |
21ae2956 | 29 | * Must be called with cpuidle_lock acquired. |
4f86d3a8 | 30 | */ |
cb5d8c45 | 31 | struct cpuidle_governor *cpuidle_find_governor(const char *str) |
4f86d3a8 LB |
32 | { |
33 | struct cpuidle_governor *gov; | |
34 | ||
35 | list_for_each_entry(gov, &cpuidle_governors, governor_list) | |
91336640 | 36 | if (!strncasecmp(str, gov->name, CPUIDLE_NAME_LEN)) |
4f86d3a8 LB |
37 | return gov; |
38 | ||
39 | return NULL; | |
40 | } | |
41 | ||
42 | /** | |
43 | * cpuidle_switch_governor - changes the governor | |
44 | * @gov: the new target governor | |
21ae2956 | 45 | * Must be called with cpuidle_lock acquired. |
4f86d3a8 LB |
46 | */ |
47 | int cpuidle_switch_governor(struct cpuidle_governor *gov) | |
48 | { | |
49 | struct cpuidle_device *dev; | |
50 | ||
3cfd68b5 | 51 | if (!gov) |
52 | return -EINVAL; | |
53 | ||
4f86d3a8 LB |
54 | if (gov == cpuidle_curr_governor) |
55 | return 0; | |
56 | ||
57 | cpuidle_uninstall_idle_handler(); | |
58 | ||
59 | if (cpuidle_curr_governor) { | |
60 | list_for_each_entry(dev, &cpuidle_detected_devices, device_list) | |
61 | cpuidle_disable_device(dev); | |
4f86d3a8 LB |
62 | } |
63 | ||
64 | cpuidle_curr_governor = gov; | |
65 | ||
66 | if (gov) { | |
4f86d3a8 LB |
67 | list_for_each_entry(dev, &cpuidle_detected_devices, device_list) |
68 | cpuidle_enable_device(dev); | |
69 | cpuidle_install_idle_handler(); | |
70 | printk(KERN_INFO "cpuidle: using governor %s\n", gov->name); | |
71 | } | |
72 | ||
73 | return 0; | |
74 | } | |
75 | ||
76 | /** | |
77 | * cpuidle_register_governor - registers a governor | |
78 | * @gov: the governor | |
79 | */ | |
80 | int cpuidle_register_governor(struct cpuidle_governor *gov) | |
81 | { | |
82 | int ret = -EEXIST; | |
83 | ||
84 | if (!gov || !gov->select) | |
85 | return -EINVAL; | |
86 | ||
62027aea LB |
87 | if (cpuidle_disabled()) |
88 | return -ENODEV; | |
89 | ||
4f86d3a8 | 90 | mutex_lock(&cpuidle_lock); |
cb5d8c45 | 91 | if (cpuidle_find_governor(gov->name) == NULL) { |
4f86d3a8 | 92 | ret = 0; |
22782b3f | 93 | list_add_tail(&gov->governor_list, &cpuidle_governors); |
4f86d3a8 | 94 | if (!cpuidle_curr_governor || |
61cb5758 RW |
95 | !strncasecmp(param_governor, gov->name, CPUIDLE_NAME_LEN) || |
96 | (cpuidle_curr_governor->rating < gov->rating && | |
97 | strncasecmp(param_governor, cpuidle_curr_governor->name, | |
98 | CPUIDLE_NAME_LEN))) | |
4f86d3a8 LB |
99 | cpuidle_switch_governor(gov); |
100 | } | |
101 | mutex_unlock(&cpuidle_lock); | |
102 | ||
103 | return ret; | |
104 | } | |
0fc784fb RW |
105 | |
106 | /** | |
107 | * cpuidle_governor_latency_req - Compute a latency constraint for CPU | |
108 | * @cpu: Target CPU | |
109 | */ | |
c1d51f68 | 110 | s64 cpuidle_governor_latency_req(unsigned int cpu) |
0fc784fb | 111 | { |
0fc784fb | 112 | struct device *device = get_cpu_device(cpu); |
8262331e | 113 | int device_req = dev_pm_qos_raw_resume_latency(device); |
f60ccc35 | 114 | int global_req = cpu_latency_qos_limit(); |
0fc784fb | 115 | |
c1d51f68 RW |
116 | if (device_req > global_req) |
117 | device_req = global_req; | |
118 | ||
119 | return (s64)device_req * NSEC_PER_USEC; | |
0fc784fb | 120 | } |