Commit 938cfed18bec2c7361f37efc954712a7cc42c353

Authored by Jean Pihet
Committed by Ingo Molnar
1 parent eccdfe2d24

perf: Add calls to suspend trace point

Uses the machine_suspend trace point, called from the
generic kernel suspend_devices_and_enter function.

Signed-off-by: Jean Pihet <j-pihet@ti.com>
Acked-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Arjan van de Ven <arjan@linux.intel.com>
CC: Thomas Renninger <trenn@suse.de>
Cc: Len Brown <len.brown@intel.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: linux-pm@lists.linux-foundation.org
LKML-Reference: <1294253342-29056-2-git-send-email-j-pihet@ti.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Showing 1 changed file with 3 additions and 0 deletions Inline Diff

kernel/power/suspend.c
1 /* 1 /*
2 * kernel/power/suspend.c - Suspend to RAM and standby functionality. 2 * kernel/power/suspend.c - Suspend to RAM and standby functionality.
3 * 3 *
4 * Copyright (c) 2003 Patrick Mochel 4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab 5 * Copyright (c) 2003 Open Source Development Lab
6 * Copyright (c) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. 6 * Copyright (c) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
7 * 7 *
8 * This file is released under the GPLv2. 8 * This file is released under the GPLv2.
9 */ 9 */
10 10
11 #include <linux/string.h> 11 #include <linux/string.h>
12 #include <linux/delay.h> 12 #include <linux/delay.h>
13 #include <linux/errno.h> 13 #include <linux/errno.h>
14 #include <linux/init.h> 14 #include <linux/init.h>
15 #include <linux/console.h> 15 #include <linux/console.h>
16 #include <linux/cpu.h> 16 #include <linux/cpu.h>
17 #include <linux/syscalls.h> 17 #include <linux/syscalls.h>
18 #include <linux/gfp.h> 18 #include <linux/gfp.h>
19 #include <linux/io.h> 19 #include <linux/io.h>
20 #include <linux/kernel.h> 20 #include <linux/kernel.h>
21 #include <linux/list.h> 21 #include <linux/list.h>
22 #include <linux/mm.h> 22 #include <linux/mm.h>
23 #include <linux/slab.h> 23 #include <linux/slab.h>
24 #include <linux/suspend.h> 24 #include <linux/suspend.h>
25 #include <trace/events/power.h>
25 26
26 #include "power.h" 27 #include "power.h"
27 28
28 const char *const pm_states[PM_SUSPEND_MAX] = { 29 const char *const pm_states[PM_SUSPEND_MAX] = {
29 [PM_SUSPEND_STANDBY] = "standby", 30 [PM_SUSPEND_STANDBY] = "standby",
30 [PM_SUSPEND_MEM] = "mem", 31 [PM_SUSPEND_MEM] = "mem",
31 }; 32 };
32 33
33 static struct platform_suspend_ops *suspend_ops; 34 static struct platform_suspend_ops *suspend_ops;
34 35
35 /** 36 /**
36 * suspend_set_ops - Set the global suspend method table. 37 * suspend_set_ops - Set the global suspend method table.
37 * @ops: Pointer to ops structure. 38 * @ops: Pointer to ops structure.
38 */ 39 */
39 void suspend_set_ops(struct platform_suspend_ops *ops) 40 void suspend_set_ops(struct platform_suspend_ops *ops)
40 { 41 {
41 mutex_lock(&pm_mutex); 42 mutex_lock(&pm_mutex);
42 suspend_ops = ops; 43 suspend_ops = ops;
43 mutex_unlock(&pm_mutex); 44 mutex_unlock(&pm_mutex);
44 } 45 }
45 46
46 bool valid_state(suspend_state_t state) 47 bool valid_state(suspend_state_t state)
47 { 48 {
48 /* 49 /*
49 * All states need lowlevel support and need to be valid to the lowlevel 50 * All states need lowlevel support and need to be valid to the lowlevel
50 * implementation, no valid callback implies that none are valid. 51 * implementation, no valid callback implies that none are valid.
51 */ 52 */
52 return suspend_ops && suspend_ops->valid && suspend_ops->valid(state); 53 return suspend_ops && suspend_ops->valid && suspend_ops->valid(state);
53 } 54 }
54 55
55 /** 56 /**
56 * suspend_valid_only_mem - generic memory-only valid callback 57 * suspend_valid_only_mem - generic memory-only valid callback
57 * 58 *
58 * Platform drivers that implement mem suspend only and only need 59 * Platform drivers that implement mem suspend only and only need
59 * to check for that in their .valid callback can use this instead 60 * to check for that in their .valid callback can use this instead
60 * of rolling their own .valid callback. 61 * of rolling their own .valid callback.
61 */ 62 */
62 int suspend_valid_only_mem(suspend_state_t state) 63 int suspend_valid_only_mem(suspend_state_t state)
63 { 64 {
64 return state == PM_SUSPEND_MEM; 65 return state == PM_SUSPEND_MEM;
65 } 66 }
66 67
67 static int suspend_test(int level) 68 static int suspend_test(int level)
68 { 69 {
69 #ifdef CONFIG_PM_DEBUG 70 #ifdef CONFIG_PM_DEBUG
70 if (pm_test_level == level) { 71 if (pm_test_level == level) {
71 printk(KERN_INFO "suspend debug: Waiting for 5 seconds.\n"); 72 printk(KERN_INFO "suspend debug: Waiting for 5 seconds.\n");
72 mdelay(5000); 73 mdelay(5000);
73 return 1; 74 return 1;
74 } 75 }
75 #endif /* !CONFIG_PM_DEBUG */ 76 #endif /* !CONFIG_PM_DEBUG */
76 return 0; 77 return 0;
77 } 78 }
78 79
79 /** 80 /**
80 * suspend_prepare - Do prep work before entering low-power state. 81 * suspend_prepare - Do prep work before entering low-power state.
81 * 82 *
82 * This is common code that is called for each state that we're entering. 83 * This is common code that is called for each state that we're entering.
83 * Run suspend notifiers, allocate a console and stop all processes. 84 * Run suspend notifiers, allocate a console and stop all processes.
84 */ 85 */
85 static int suspend_prepare(void) 86 static int suspend_prepare(void)
86 { 87 {
87 int error; 88 int error;
88 89
89 if (!suspend_ops || !suspend_ops->enter) 90 if (!suspend_ops || !suspend_ops->enter)
90 return -EPERM; 91 return -EPERM;
91 92
92 pm_prepare_console(); 93 pm_prepare_console();
93 94
94 error = pm_notifier_call_chain(PM_SUSPEND_PREPARE); 95 error = pm_notifier_call_chain(PM_SUSPEND_PREPARE);
95 if (error) 96 if (error)
96 goto Finish; 97 goto Finish;
97 98
98 error = usermodehelper_disable(); 99 error = usermodehelper_disable();
99 if (error) 100 if (error)
100 goto Finish; 101 goto Finish;
101 102
102 error = suspend_freeze_processes(); 103 error = suspend_freeze_processes();
103 if (!error) 104 if (!error)
104 return 0; 105 return 0;
105 106
106 suspend_thaw_processes(); 107 suspend_thaw_processes();
107 usermodehelper_enable(); 108 usermodehelper_enable();
108 Finish: 109 Finish:
109 pm_notifier_call_chain(PM_POST_SUSPEND); 110 pm_notifier_call_chain(PM_POST_SUSPEND);
110 pm_restore_console(); 111 pm_restore_console();
111 return error; 112 return error;
112 } 113 }
113 114
114 /* default implementation */ 115 /* default implementation */
115 void __attribute__ ((weak)) arch_suspend_disable_irqs(void) 116 void __attribute__ ((weak)) arch_suspend_disable_irqs(void)
116 { 117 {
117 local_irq_disable(); 118 local_irq_disable();
118 } 119 }
119 120
120 /* default implementation */ 121 /* default implementation */
121 void __attribute__ ((weak)) arch_suspend_enable_irqs(void) 122 void __attribute__ ((weak)) arch_suspend_enable_irqs(void)
122 { 123 {
123 local_irq_enable(); 124 local_irq_enable();
124 } 125 }
125 126
126 /** 127 /**
127 * suspend_enter - enter the desired system sleep state. 128 * suspend_enter - enter the desired system sleep state.
128 * @state: state to enter 129 * @state: state to enter
129 * 130 *
130 * This function should be called after devices have been suspended. 131 * This function should be called after devices have been suspended.
131 */ 132 */
132 static int suspend_enter(suspend_state_t state) 133 static int suspend_enter(suspend_state_t state)
133 { 134 {
134 int error; 135 int error;
135 136
136 if (suspend_ops->prepare) { 137 if (suspend_ops->prepare) {
137 error = suspend_ops->prepare(); 138 error = suspend_ops->prepare();
138 if (error) 139 if (error)
139 goto Platform_finish; 140 goto Platform_finish;
140 } 141 }
141 142
142 error = dpm_suspend_noirq(PMSG_SUSPEND); 143 error = dpm_suspend_noirq(PMSG_SUSPEND);
143 if (error) { 144 if (error) {
144 printk(KERN_ERR "PM: Some devices failed to power down\n"); 145 printk(KERN_ERR "PM: Some devices failed to power down\n");
145 goto Platform_finish; 146 goto Platform_finish;
146 } 147 }
147 148
148 if (suspend_ops->prepare_late) { 149 if (suspend_ops->prepare_late) {
149 error = suspend_ops->prepare_late(); 150 error = suspend_ops->prepare_late();
150 if (error) 151 if (error)
151 goto Platform_wake; 152 goto Platform_wake;
152 } 153 }
153 154
154 if (suspend_test(TEST_PLATFORM)) 155 if (suspend_test(TEST_PLATFORM))
155 goto Platform_wake; 156 goto Platform_wake;
156 157
157 error = disable_nonboot_cpus(); 158 error = disable_nonboot_cpus();
158 if (error || suspend_test(TEST_CPUS)) 159 if (error || suspend_test(TEST_CPUS))
159 goto Enable_cpus; 160 goto Enable_cpus;
160 161
161 arch_suspend_disable_irqs(); 162 arch_suspend_disable_irqs();
162 BUG_ON(!irqs_disabled()); 163 BUG_ON(!irqs_disabled());
163 164
164 error = sysdev_suspend(PMSG_SUSPEND); 165 error = sysdev_suspend(PMSG_SUSPEND);
165 if (!error) { 166 if (!error) {
166 if (!suspend_test(TEST_CORE) && pm_check_wakeup_events()) { 167 if (!suspend_test(TEST_CORE) && pm_check_wakeup_events()) {
167 error = suspend_ops->enter(state); 168 error = suspend_ops->enter(state);
168 events_check_enabled = false; 169 events_check_enabled = false;
169 } 170 }
170 sysdev_resume(); 171 sysdev_resume();
171 } 172 }
172 173
173 arch_suspend_enable_irqs(); 174 arch_suspend_enable_irqs();
174 BUG_ON(irqs_disabled()); 175 BUG_ON(irqs_disabled());
175 176
176 Enable_cpus: 177 Enable_cpus:
177 enable_nonboot_cpus(); 178 enable_nonboot_cpus();
178 179
179 Platform_wake: 180 Platform_wake:
180 if (suspend_ops->wake) 181 if (suspend_ops->wake)
181 suspend_ops->wake(); 182 suspend_ops->wake();
182 183
183 dpm_resume_noirq(PMSG_RESUME); 184 dpm_resume_noirq(PMSG_RESUME);
184 185
185 Platform_finish: 186 Platform_finish:
186 if (suspend_ops->finish) 187 if (suspend_ops->finish)
187 suspend_ops->finish(); 188 suspend_ops->finish();
188 189
189 return error; 190 return error;
190 } 191 }
191 192
192 /** 193 /**
193 * suspend_devices_and_enter - suspend devices and enter the desired system 194 * suspend_devices_and_enter - suspend devices and enter the desired system
194 * sleep state. 195 * sleep state.
195 * @state: state to enter 196 * @state: state to enter
196 */ 197 */
197 int suspend_devices_and_enter(suspend_state_t state) 198 int suspend_devices_and_enter(suspend_state_t state)
198 { 199 {
199 int error; 200 int error;
200 201
201 if (!suspend_ops) 202 if (!suspend_ops)
202 return -ENOSYS; 203 return -ENOSYS;
203 204
205 trace_machine_suspend(state);
204 if (suspend_ops->begin) { 206 if (suspend_ops->begin) {
205 error = suspend_ops->begin(state); 207 error = suspend_ops->begin(state);
206 if (error) 208 if (error)
207 goto Close; 209 goto Close;
208 } 210 }
209 suspend_console(); 211 suspend_console();
210 pm_restrict_gfp_mask(); 212 pm_restrict_gfp_mask();
211 suspend_test_start(); 213 suspend_test_start();
212 error = dpm_suspend_start(PMSG_SUSPEND); 214 error = dpm_suspend_start(PMSG_SUSPEND);
213 if (error) { 215 if (error) {
214 printk(KERN_ERR "PM: Some devices failed to suspend\n"); 216 printk(KERN_ERR "PM: Some devices failed to suspend\n");
215 goto Recover_platform; 217 goto Recover_platform;
216 } 218 }
217 suspend_test_finish("suspend devices"); 219 suspend_test_finish("suspend devices");
218 if (suspend_test(TEST_DEVICES)) 220 if (suspend_test(TEST_DEVICES))
219 goto Recover_platform; 221 goto Recover_platform;
220 222
221 suspend_enter(state); 223 suspend_enter(state);
222 224
223 Resume_devices: 225 Resume_devices:
224 suspend_test_start(); 226 suspend_test_start();
225 dpm_resume_end(PMSG_RESUME); 227 dpm_resume_end(PMSG_RESUME);
226 suspend_test_finish("resume devices"); 228 suspend_test_finish("resume devices");
227 pm_restore_gfp_mask(); 229 pm_restore_gfp_mask();
228 resume_console(); 230 resume_console();
229 Close: 231 Close:
230 if (suspend_ops->end) 232 if (suspend_ops->end)
231 suspend_ops->end(); 233 suspend_ops->end();
234 trace_machine_suspend(PWR_EVENT_EXIT);
232 return error; 235 return error;
233 236
234 Recover_platform: 237 Recover_platform:
235 if (suspend_ops->recover) 238 if (suspend_ops->recover)
236 suspend_ops->recover(); 239 suspend_ops->recover();
237 goto Resume_devices; 240 goto Resume_devices;
238 } 241 }
239 242
240 /** 243 /**
241 * suspend_finish - Do final work before exiting suspend sequence. 244 * suspend_finish - Do final work before exiting suspend sequence.
242 * 245 *
243 * Call platform code to clean up, restart processes, and free the 246 * Call platform code to clean up, restart processes, and free the
244 * console that we've allocated. This is not called for suspend-to-disk. 247 * console that we've allocated. This is not called for suspend-to-disk.
245 */ 248 */
246 static void suspend_finish(void) 249 static void suspend_finish(void)
247 { 250 {
248 suspend_thaw_processes(); 251 suspend_thaw_processes();
249 usermodehelper_enable(); 252 usermodehelper_enable();
250 pm_notifier_call_chain(PM_POST_SUSPEND); 253 pm_notifier_call_chain(PM_POST_SUSPEND);
251 pm_restore_console(); 254 pm_restore_console();
252 } 255 }
253 256
254 /** 257 /**
255 * enter_state - Do common work of entering low-power state. 258 * enter_state - Do common work of entering low-power state.
256 * @state: pm_state structure for state we're entering. 259 * @state: pm_state structure for state we're entering.
257 * 260 *
258 * Make sure we're the only ones trying to enter a sleep state. Fail 261 * Make sure we're the only ones trying to enter a sleep state. Fail
259 * if someone has beat us to it, since we don't want anything weird to 262 * if someone has beat us to it, since we don't want anything weird to
260 * happen when we wake up. 263 * happen when we wake up.
261 * Then, do the setup for suspend, enter the state, and cleaup (after 264 * Then, do the setup for suspend, enter the state, and cleaup (after
262 * we've woken up). 265 * we've woken up).
263 */ 266 */
264 int enter_state(suspend_state_t state) 267 int enter_state(suspend_state_t state)
265 { 268 {
266 int error; 269 int error;
267 270
268 if (!valid_state(state)) 271 if (!valid_state(state))
269 return -ENODEV; 272 return -ENODEV;
270 273
271 if (!mutex_trylock(&pm_mutex)) 274 if (!mutex_trylock(&pm_mutex))
272 return -EBUSY; 275 return -EBUSY;
273 276
274 printk(KERN_INFO "PM: Syncing filesystems ... "); 277 printk(KERN_INFO "PM: Syncing filesystems ... ");
275 sys_sync(); 278 sys_sync();
276 printk("done.\n"); 279 printk("done.\n");
277 280
278 pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]); 281 pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]);
279 error = suspend_prepare(); 282 error = suspend_prepare();
280 if (error) 283 if (error)
281 goto Unlock; 284 goto Unlock;
282 285
283 if (suspend_test(TEST_FREEZER)) 286 if (suspend_test(TEST_FREEZER))
284 goto Finish; 287 goto Finish;
285 288
286 pr_debug("PM: Entering %s sleep\n", pm_states[state]); 289 pr_debug("PM: Entering %s sleep\n", pm_states[state]);
287 error = suspend_devices_and_enter(state); 290 error = suspend_devices_and_enter(state);
288 291
289 Finish: 292 Finish:
290 pr_debug("PM: Finishing wakeup.\n"); 293 pr_debug("PM: Finishing wakeup.\n");
291 suspend_finish(); 294 suspend_finish();
292 Unlock: 295 Unlock:
293 mutex_unlock(&pm_mutex); 296 mutex_unlock(&pm_mutex);
294 return error; 297 return error;
295 } 298 }
296 299
297 /** 300 /**
298 * pm_suspend - Externally visible function for suspending system. 301 * pm_suspend - Externally visible function for suspending system.
299 * @state: Enumerated value of state to enter. 302 * @state: Enumerated value of state to enter.
300 * 303 *
301 * Determine whether or not value is within range, get state 304 * Determine whether or not value is within range, get state
302 * structure, and enter (above). 305 * structure, and enter (above).
303 */ 306 */
304 int pm_suspend(suspend_state_t state) 307 int pm_suspend(suspend_state_t state)
305 { 308 {
306 if (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX) 309 if (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX)
307 return enter_state(state); 310 return enter_state(state);
308 return -EINVAL; 311 return -EINVAL;
309 } 312 }
310 EXPORT_SYMBOL(pm_suspend); 313 EXPORT_SYMBOL(pm_suspend);
311 314