This source file includes following definitions.
- cpuidle_find_governor
- cpuidle_switch_governor
- cpuidle_register_governor
- cpuidle_governor_latency_req
1
2
3
4
5
6
7
8
9
10
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>
16
17 #include "cpuidle.h"
18
19 char param_governor[CPUIDLE_NAME_LEN];
20
21 LIST_HEAD(cpuidle_governors);
22 struct cpuidle_governor *cpuidle_curr_governor;
23 struct cpuidle_governor *cpuidle_prev_governor;
24
25
26
27
28
29
30
31 struct cpuidle_governor *cpuidle_find_governor(const char *str)
32 {
33 struct cpuidle_governor *gov;
34
35 list_for_each_entry(gov, &cpuidle_governors, governor_list)
36 if (!strncasecmp(str, gov->name, CPUIDLE_NAME_LEN))
37 return gov;
38
39 return NULL;
40 }
41
42
43
44
45
46
47 int cpuidle_switch_governor(struct cpuidle_governor *gov)
48 {
49 struct cpuidle_device *dev;
50
51 if (!gov)
52 return -EINVAL;
53
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);
62 }
63
64 cpuidle_curr_governor = gov;
65
66 if (gov) {
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
78
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
87 if (cpuidle_disabled())
88 return -ENODEV;
89
90 mutex_lock(&cpuidle_lock);
91 if (cpuidle_find_governor(gov->name) == NULL) {
92 ret = 0;
93 list_add_tail(&gov->governor_list, &cpuidle_governors);
94 if (!cpuidle_curr_governor ||
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)))
99 cpuidle_switch_governor(gov);
100 }
101 mutex_unlock(&cpuidle_lock);
102
103 return ret;
104 }
105
106
107
108
109
110 int cpuidle_governor_latency_req(unsigned int cpu)
111 {
112 int global_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
113 struct device *device = get_cpu_device(cpu);
114 int device_req = dev_pm_qos_raw_resume_latency(device);
115
116 return device_req < global_req ? device_req : global_req;
117 }