diff options
author | Deepthi Dharwar <deepthi@linux.vnet.ibm.com> | 2011-11-29 21:46:42 -0500 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2011-12-07 21:56:31 -0500 |
commit | 707827f3387d9b260d50fa697885a4042cea3bf4 (patch) | |
tree | ad6b616d17cab85bf39fd42405dd2ae84123811c /arch/powerpc | |
parent | 771dae81896855d25f7f8746aaf56c0238deafb6 (diff) |
powerpc/cpuidle: cpuidle driver for pSeries
This patch implements a back-end cpuidle driver for pSeries
based on pseries_dedicated_idle_loop and pseries_shared_idle_loop
routines. The driver is built only if CONFIG_CPU_IDLE is set. This
cpuidle driver uses global registration of idle states and
not per-cpu.
Signed-off-by: Deepthi Dharwar <deepthi@linux.vnet.ibm.com>
Signed-off-by: Trinabh Gupta <g.trinabh@gmail.com>
Signed-off-by: Arun R Bharadwaj <arun.r.bharadwaj@gmail.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r-- | arch/powerpc/include/asm/system.h | 8 | ||||
-rw-r--r-- | arch/powerpc/kernel/sysfs.c | 2 | ||||
-rw-r--r-- | arch/powerpc/platforms/pseries/Kconfig | 9 | ||||
-rw-r--r-- | arch/powerpc/platforms/pseries/Makefile | 1 | ||||
-rw-r--r-- | arch/powerpc/platforms/pseries/processor_idle.c | 326 | ||||
-rw-r--r-- | arch/powerpc/platforms/pseries/pseries.h | 3 | ||||
-rw-r--r-- | arch/powerpc/platforms/pseries/setup.c | 3 | ||||
-rw-r--r-- | arch/powerpc/platforms/pseries/smp.c | 1 |
8 files changed, 350 insertions, 3 deletions
diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h index ff6668038799..f56a0a75d989 100644 --- a/arch/powerpc/include/asm/system.h +++ b/arch/powerpc/include/asm/system.h | |||
@@ -223,6 +223,14 @@ extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask); | |||
223 | extern int powersave_nap; /* set if nap mode can be used in idle loop */ | 223 | extern int powersave_nap; /* set if nap mode can be used in idle loop */ |
224 | void cpu_idle_wait(void); | 224 | void cpu_idle_wait(void); |
225 | 225 | ||
226 | #ifdef CONFIG_PSERIES_IDLE | ||
227 | extern void update_smt_snooze_delay(int snooze); | ||
228 | extern int pseries_notify_cpuidle_add_cpu(int cpu); | ||
229 | #else | ||
230 | static inline void update_smt_snooze_delay(int snooze) {} | ||
231 | static inline int pseries_notify_cpuidle_add_cpu(int cpu) { return 0; } | ||
232 | #endif | ||
233 | |||
226 | /* | 234 | /* |
227 | * Atomic exchange | 235 | * Atomic exchange |
228 | * | 236 | * |
diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c index f579be552094..6fdf5ffe8c44 100644 --- a/arch/powerpc/kernel/sysfs.c +++ b/arch/powerpc/kernel/sysfs.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <asm/machdep.h> | 18 | #include <asm/machdep.h> |
19 | #include <asm/smp.h> | 19 | #include <asm/smp.h> |
20 | #include <asm/pmc.h> | 20 | #include <asm/pmc.h> |
21 | #include <asm/system.h> | ||
21 | 22 | ||
22 | #include "cacheinfo.h" | 23 | #include "cacheinfo.h" |
23 | 24 | ||
@@ -51,6 +52,7 @@ static ssize_t store_smt_snooze_delay(struct sys_device *dev, | |||
51 | return -EINVAL; | 52 | return -EINVAL; |
52 | 53 | ||
53 | per_cpu(smt_snooze_delay, cpu->sysdev.id) = snooze; | 54 | per_cpu(smt_snooze_delay, cpu->sysdev.id) = snooze; |
55 | update_smt_snooze_delay(snooze); | ||
54 | 56 | ||
55 | return count; | 57 | return count; |
56 | } | 58 | } |
diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig index c81f6bb9c10f..ae7b6d41fed3 100644 --- a/arch/powerpc/platforms/pseries/Kconfig +++ b/arch/powerpc/platforms/pseries/Kconfig | |||
@@ -120,3 +120,12 @@ config DTL | |||
120 | which are accessible through a debugfs file. | 120 | which are accessible through a debugfs file. |
121 | 121 | ||
122 | Say N if you are unsure. | 122 | Say N if you are unsure. |
123 | |||
124 | config PSERIES_IDLE | ||
125 | tristate "Cpuidle driver for pSeries platforms" | ||
126 | depends on CPU_IDLE | ||
127 | depends on PPC_PSERIES | ||
128 | default y | ||
129 | help | ||
130 | Select this option to enable processor idle state management | ||
131 | through cpuidle subsystem. | ||
diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile index 3556e402cbf5..236db46b4078 100644 --- a/arch/powerpc/platforms/pseries/Makefile +++ b/arch/powerpc/platforms/pseries/Makefile | |||
@@ -22,6 +22,7 @@ obj-$(CONFIG_PHYP_DUMP) += phyp_dump.o | |||
22 | obj-$(CONFIG_CMM) += cmm.o | 22 | obj-$(CONFIG_CMM) += cmm.o |
23 | obj-$(CONFIG_DTL) += dtl.o | 23 | obj-$(CONFIG_DTL) += dtl.o |
24 | obj-$(CONFIG_IO_EVENT_IRQ) += io_event_irq.o | 24 | obj-$(CONFIG_IO_EVENT_IRQ) += io_event_irq.o |
25 | obj-$(CONFIG_PSERIES_IDLE) += processor_idle.o | ||
25 | 26 | ||
26 | ifeq ($(CONFIG_PPC_PSERIES),y) | 27 | ifeq ($(CONFIG_PPC_PSERIES),y) |
27 | obj-$(CONFIG_SUSPEND) += suspend.o | 28 | obj-$(CONFIG_SUSPEND) += suspend.o |
diff --git a/arch/powerpc/platforms/pseries/processor_idle.c b/arch/powerpc/platforms/pseries/processor_idle.c new file mode 100644 index 000000000000..f7e3e877cb69 --- /dev/null +++ b/arch/powerpc/platforms/pseries/processor_idle.c | |||
@@ -0,0 +1,326 @@ | |||
1 | /* | ||
2 | * processor_idle - idle state cpuidle driver. | ||
3 | * Adapted from drivers/idle/intel_idle.c and | ||
4 | * drivers/acpi/processor_idle.c | ||
5 | * | ||
6 | */ | ||
7 | |||
8 | #include <linux/kernel.h> | ||
9 | #include <linux/module.h> | ||
10 | #include <linux/init.h> | ||
11 | #include <linux/moduleparam.h> | ||
12 | #include <linux/cpuidle.h> | ||
13 | #include <linux/cpu.h> | ||
14 | |||
15 | #include <asm/paca.h> | ||
16 | #include <asm/reg.h> | ||
17 | #include <asm/system.h> | ||
18 | #include <asm/machdep.h> | ||
19 | #include <asm/firmware.h> | ||
20 | |||
21 | #include "plpar_wrappers.h" | ||
22 | #include "pseries.h" | ||
23 | |||
24 | struct cpuidle_driver pseries_idle_driver = { | ||
25 | .name = "pseries_idle", | ||
26 | .owner = THIS_MODULE, | ||
27 | }; | ||
28 | |||
29 | #define MAX_IDLE_STATE_COUNT 2 | ||
30 | |||
31 | static int max_idle_state = MAX_IDLE_STATE_COUNT - 1; | ||
32 | static struct cpuidle_device __percpu *pseries_cpuidle_devices; | ||
33 | static struct cpuidle_state *cpuidle_state_table; | ||
34 | |||
35 | void update_smt_snooze_delay(int snooze) | ||
36 | { | ||
37 | struct cpuidle_driver *drv = cpuidle_get_driver(); | ||
38 | if (drv) | ||
39 | drv->states[0].target_residency = snooze; | ||
40 | } | ||
41 | |||
42 | static inline void idle_loop_prolog(unsigned long *in_purr, ktime_t *kt_before) | ||
43 | { | ||
44 | |||
45 | *kt_before = ktime_get_real(); | ||
46 | *in_purr = mfspr(SPRN_PURR); | ||
47 | /* | ||
48 | * Indicate to the HV that we are idle. Now would be | ||
49 | * a good time to find other work to dispatch. | ||
50 | */ | ||
51 | get_lppaca()->idle = 1; | ||
52 | } | ||
53 | |||
54 | static inline s64 idle_loop_epilog(unsigned long in_purr, ktime_t kt_before) | ||
55 | { | ||
56 | get_lppaca()->wait_state_cycles += mfspr(SPRN_PURR) - in_purr; | ||
57 | get_lppaca()->idle = 0; | ||
58 | |||
59 | return ktime_to_us(ktime_sub(ktime_get_real(), kt_before)); | ||
60 | } | ||
61 | |||
62 | static int snooze_loop(struct cpuidle_device *dev, | ||
63 | struct cpuidle_driver *drv, | ||
64 | int index) | ||
65 | { | ||
66 | unsigned long in_purr; | ||
67 | ktime_t kt_before; | ||
68 | unsigned long start_snooze; | ||
69 | long snooze = drv->states[0].target_residency; | ||
70 | |||
71 | idle_loop_prolog(&in_purr, &kt_before); | ||
72 | |||
73 | if (snooze) { | ||
74 | start_snooze = get_tb() + snooze * tb_ticks_per_usec; | ||
75 | local_irq_enable(); | ||
76 | set_thread_flag(TIF_POLLING_NRFLAG); | ||
77 | |||
78 | while ((snooze < 0) || (get_tb() < start_snooze)) { | ||
79 | if (need_resched() || cpu_is_offline(dev->cpu)) | ||
80 | goto out; | ||
81 | ppc64_runlatch_off(); | ||
82 | HMT_low(); | ||
83 | HMT_very_low(); | ||
84 | } | ||
85 | |||
86 | HMT_medium(); | ||
87 | clear_thread_flag(TIF_POLLING_NRFLAG); | ||
88 | smp_mb(); | ||
89 | local_irq_disable(); | ||
90 | } | ||
91 | |||
92 | out: | ||
93 | HMT_medium(); | ||
94 | dev->last_residency = | ||
95 | (int)idle_loop_epilog(in_purr, kt_before); | ||
96 | return index; | ||
97 | } | ||
98 | |||
99 | static int dedicated_cede_loop(struct cpuidle_device *dev, | ||
100 | struct cpuidle_driver *drv, | ||
101 | int index) | ||
102 | { | ||
103 | unsigned long in_purr; | ||
104 | ktime_t kt_before; | ||
105 | |||
106 | idle_loop_prolog(&in_purr, &kt_before); | ||
107 | get_lppaca()->donate_dedicated_cpu = 1; | ||
108 | |||
109 | ppc64_runlatch_off(); | ||
110 | HMT_medium(); | ||
111 | cede_processor(); | ||
112 | |||
113 | get_lppaca()->donate_dedicated_cpu = 0; | ||
114 | dev->last_residency = | ||
115 | (int)idle_loop_epilog(in_purr, kt_before); | ||
116 | return index; | ||
117 | } | ||
118 | |||
119 | static int shared_cede_loop(struct cpuidle_device *dev, | ||
120 | struct cpuidle_driver *drv, | ||
121 | int index) | ||
122 | { | ||
123 | unsigned long in_purr; | ||
124 | ktime_t kt_before; | ||
125 | |||
126 | idle_loop_prolog(&in_purr, &kt_before); | ||
127 | |||
128 | /* | ||
129 | * Yield the processor to the hypervisor. We return if | ||
130 | * an external interrupt occurs (which are driven prior | ||
131 | * to returning here) or if a prod occurs from another | ||
132 | * processor. When returning here, external interrupts | ||
133 | * are enabled. | ||
134 | */ | ||
135 | cede_processor(); | ||
136 | |||
137 | dev->last_residency = | ||
138 | (int)idle_loop_epilog(in_purr, kt_before); | ||
139 | return index; | ||
140 | } | ||
141 | |||
142 | /* | ||
143 | * States for dedicated partition case. | ||
144 | */ | ||
145 | static struct cpuidle_state dedicated_states[MAX_IDLE_STATE_COUNT] = { | ||
146 | { /* Snooze */ | ||
147 | .name = "snooze", | ||
148 | .desc = "snooze", | ||
149 | .flags = CPUIDLE_FLAG_TIME_VALID, | ||
150 | .exit_latency = 0, | ||
151 | .target_residency = 0, | ||
152 | .enter = &snooze_loop }, | ||
153 | { /* CEDE */ | ||
154 | .name = "CEDE", | ||
155 | .desc = "CEDE", | ||
156 | .flags = CPUIDLE_FLAG_TIME_VALID, | ||
157 | .exit_latency = 1, | ||
158 | .target_residency = 10, | ||
159 | .enter = &dedicated_cede_loop }, | ||
160 | }; | ||
161 | |||
162 | /* | ||
163 | * States for shared partition case. | ||
164 | */ | ||
165 | static struct cpuidle_state shared_states[MAX_IDLE_STATE_COUNT] = { | ||
166 | { /* Shared Cede */ | ||
167 | .name = "Shared Cede", | ||
168 | .desc = "Shared Cede", | ||
169 | .flags = CPUIDLE_FLAG_TIME_VALID, | ||
170 | .exit_latency = 0, | ||
171 | .target_residency = 0, | ||
172 | .enter = &shared_cede_loop }, | ||
173 | }; | ||
174 | |||
175 | int pseries_notify_cpuidle_add_cpu(int cpu) | ||
176 | { | ||
177 | struct cpuidle_device *dev = | ||
178 | per_cpu_ptr(pseries_cpuidle_devices, cpu); | ||
179 | if (dev && cpuidle_get_driver()) { | ||
180 | cpuidle_disable_device(dev); | ||
181 | cpuidle_enable_device(dev); | ||
182 | } | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | /* | ||
187 | * pseries_cpuidle_driver_init() | ||
188 | */ | ||
189 | static int pseries_cpuidle_driver_init(void) | ||
190 | { | ||
191 | int idle_state; | ||
192 | struct cpuidle_driver *drv = &pseries_idle_driver; | ||
193 | |||
194 | drv->state_count = 0; | ||
195 | |||
196 | for (idle_state = 0; idle_state < MAX_IDLE_STATE_COUNT; ++idle_state) { | ||
197 | |||
198 | if (idle_state > max_idle_state) | ||
199 | break; | ||
200 | |||
201 | /* is the state not enabled? */ | ||
202 | if (cpuidle_state_table[idle_state].enter == NULL) | ||
203 | continue; | ||
204 | |||
205 | drv->states[drv->state_count] = /* structure copy */ | ||
206 | cpuidle_state_table[idle_state]; | ||
207 | |||
208 | if (cpuidle_state_table == dedicated_states) | ||
209 | drv->states[drv->state_count].target_residency = | ||
210 | __get_cpu_var(smt_snooze_delay); | ||
211 | |||
212 | drv->state_count += 1; | ||
213 | } | ||
214 | |||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | /* pseries_idle_devices_uninit(void) | ||
219 | * unregister cpuidle devices and de-allocate memory | ||
220 | */ | ||
221 | static void pseries_idle_devices_uninit(void) | ||
222 | { | ||
223 | int i; | ||
224 | struct cpuidle_device *dev; | ||
225 | |||
226 | for_each_possible_cpu(i) { | ||
227 | dev = per_cpu_ptr(pseries_cpuidle_devices, i); | ||
228 | cpuidle_unregister_device(dev); | ||
229 | } | ||
230 | |||
231 | free_percpu(pseries_cpuidle_devices); | ||
232 | return; | ||
233 | } | ||
234 | |||
235 | /* pseries_idle_devices_init() | ||
236 | * allocate, initialize and register cpuidle device | ||
237 | */ | ||
238 | static int pseries_idle_devices_init(void) | ||
239 | { | ||
240 | int i; | ||
241 | struct cpuidle_driver *drv = &pseries_idle_driver; | ||
242 | struct cpuidle_device *dev; | ||
243 | |||
244 | pseries_cpuidle_devices = alloc_percpu(struct cpuidle_device); | ||
245 | if (pseries_cpuidle_devices == NULL) | ||
246 | return -ENOMEM; | ||
247 | |||
248 | for_each_possible_cpu(i) { | ||
249 | dev = per_cpu_ptr(pseries_cpuidle_devices, i); | ||
250 | dev->state_count = drv->state_count; | ||
251 | dev->cpu = i; | ||
252 | if (cpuidle_register_device(dev)) { | ||
253 | printk(KERN_DEBUG \ | ||
254 | "cpuidle_register_device %d failed!\n", i); | ||
255 | return -EIO; | ||
256 | } | ||
257 | } | ||
258 | |||
259 | return 0; | ||
260 | } | ||
261 | |||
262 | /* | ||
263 | * pseries_idle_probe() | ||
264 | * Choose state table for shared versus dedicated partition | ||
265 | */ | ||
266 | static int pseries_idle_probe(void) | ||
267 | { | ||
268 | |||
269 | if (!firmware_has_feature(FW_FEATURE_SPLPAR)) | ||
270 | return -ENODEV; | ||
271 | |||
272 | if (max_idle_state == 0) { | ||
273 | printk(KERN_DEBUG "pseries processor idle disabled.\n"); | ||
274 | return -EPERM; | ||
275 | } | ||
276 | |||
277 | if (get_lppaca()->shared_proc) | ||
278 | cpuidle_state_table = shared_states; | ||
279 | else | ||
280 | cpuidle_state_table = dedicated_states; | ||
281 | |||
282 | return 0; | ||
283 | } | ||
284 | |||
285 | static int __init pseries_processor_idle_init(void) | ||
286 | { | ||
287 | int retval; | ||
288 | |||
289 | retval = pseries_idle_probe(); | ||
290 | if (retval) | ||
291 | return retval; | ||
292 | |||
293 | pseries_cpuidle_driver_init(); | ||
294 | retval = cpuidle_register_driver(&pseries_idle_driver); | ||
295 | if (retval) { | ||
296 | printk(KERN_DEBUG "Registration of pseries driver failed.\n"); | ||
297 | return retval; | ||
298 | } | ||
299 | |||
300 | retval = pseries_idle_devices_init(); | ||
301 | if (retval) { | ||
302 | pseries_idle_devices_uninit(); | ||
303 | cpuidle_unregister_driver(&pseries_idle_driver); | ||
304 | return retval; | ||
305 | } | ||
306 | |||
307 | printk(KERN_DEBUG "pseries_idle_driver registered\n"); | ||
308 | |||
309 | return 0; | ||
310 | } | ||
311 | |||
312 | static void __exit pseries_processor_idle_exit(void) | ||
313 | { | ||
314 | |||
315 | pseries_idle_devices_uninit(); | ||
316 | cpuidle_unregister_driver(&pseries_idle_driver); | ||
317 | |||
318 | return; | ||
319 | } | ||
320 | |||
321 | module_init(pseries_processor_idle_init); | ||
322 | module_exit(pseries_processor_idle_exit); | ||
323 | |||
324 | MODULE_AUTHOR("Deepthi Dharwar <deepthi@linux.vnet.ibm.com>"); | ||
325 | MODULE_DESCRIPTION("Cpuidle driver for POWER"); | ||
326 | MODULE_LICENSE("GPL"); | ||
diff --git a/arch/powerpc/platforms/pseries/pseries.h b/arch/powerpc/platforms/pseries/pseries.h index 24c7162f11d9..9a3dda07566f 100644 --- a/arch/powerpc/platforms/pseries/pseries.h +++ b/arch/powerpc/platforms/pseries/pseries.h | |||
@@ -57,4 +57,7 @@ extern struct device_node *dlpar_configure_connector(u32); | |||
57 | extern int dlpar_attach_node(struct device_node *); | 57 | extern int dlpar_attach_node(struct device_node *); |
58 | extern int dlpar_detach_node(struct device_node *); | 58 | extern int dlpar_detach_node(struct device_node *); |
59 | 59 | ||
60 | /* Snooze Delay, pseries_idle */ | ||
61 | DECLARE_PER_CPU(long, smt_snooze_delay); | ||
62 | |||
60 | #endif /* _PSERIES_PSERIES_H */ | 63 | #endif /* _PSERIES_PSERIES_H */ |
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c index 01df08dbc43c..f2446da7f2d5 100644 --- a/arch/powerpc/platforms/pseries/setup.c +++ b/arch/powerpc/platforms/pseries/setup.c | |||
@@ -585,9 +585,6 @@ static int __init pSeries_probe(void) | |||
585 | return 1; | 585 | return 1; |
586 | } | 586 | } |
587 | 587 | ||
588 | |||
589 | DECLARE_PER_CPU(long, smt_snooze_delay); | ||
590 | |||
591 | static void pseries_dedicated_idle_sleep(void) | 588 | static void pseries_dedicated_idle_sleep(void) |
592 | { | 589 | { |
593 | unsigned int cpu = smp_processor_id(); | 590 | unsigned int cpu = smp_processor_id(); |
diff --git a/arch/powerpc/platforms/pseries/smp.c b/arch/powerpc/platforms/pseries/smp.c index 26e93fd4c62b..bbc3c42f6730 100644 --- a/arch/powerpc/platforms/pseries/smp.c +++ b/arch/powerpc/platforms/pseries/smp.c | |||
@@ -148,6 +148,7 @@ static void __devinit smp_xics_setup_cpu(int cpu) | |||
148 | set_cpu_current_state(cpu, CPU_STATE_ONLINE); | 148 | set_cpu_current_state(cpu, CPU_STATE_ONLINE); |
149 | set_default_offline_state(cpu); | 149 | set_default_offline_state(cpu); |
150 | #endif | 150 | #endif |
151 | pseries_notify_cpuidle_add_cpu(cpu); | ||
151 | } | 152 | } |
152 | 153 | ||
153 | static int __devinit smp_pSeries_kick_cpu(int nr) | 154 | static int __devinit smp_pSeries_kick_cpu(int nr) |