diff options
author | Rafael J. Wysocki <rjw@sisk.pl> | 2011-12-02 18:23:43 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2011-12-06 16:09:45 -0500 |
commit | 0c6aebe31861c470c8cfbfdfdfd72d1369a6440b (patch) | |
tree | 1d23085d79374baae2aa51730a1d49632f332c50 /drivers/base/power/main.c | |
parent | 5a50a7c32d630d6cdb13d69afabb0cc81b2f379c (diff) |
PM / Sleep: Unify diagnostic messages from device suspend/resume
Make pm_op() and pm_noirq_op() use the same helper function for
running callbacks, which will cause them to use the same format of
diagnostic messages. This also reduces the complexity and size of
the code quite a bit.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/power/main.c')
-rw-r--r-- | drivers/base/power/main.c | 128 |
1 files changed, 35 insertions, 93 deletions
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 406f82c344fa..b570189d4f2d 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c | |||
@@ -164,8 +164,9 @@ static ktime_t initcall_debug_start(struct device *dev) | |||
164 | ktime_t calltime = ktime_set(0, 0); | 164 | ktime_t calltime = ktime_set(0, 0); |
165 | 165 | ||
166 | if (initcall_debug) { | 166 | if (initcall_debug) { |
167 | pr_info("calling %s+ @ %i\n", | 167 | pr_info("calling %s+ @ %i, parent: %s\n", |
168 | dev_name(dev), task_pid_nr(current)); | 168 | dev_name(dev), task_pid_nr(current), |
169 | dev->parent ? dev_name(dev->parent) : "none"); | ||
169 | calltime = ktime_get(); | 170 | calltime = ktime_get(); |
170 | } | 171 | } |
171 | 172 | ||
@@ -210,6 +211,24 @@ static void dpm_wait_for_children(struct device *dev, bool async) | |||
210 | device_for_each_child(dev, &async, dpm_wait_fn); | 211 | device_for_each_child(dev, &async, dpm_wait_fn); |
211 | } | 212 | } |
212 | 213 | ||
214 | static int dpm_run_callback(struct device *dev, int (*cb)(struct device *)) | ||
215 | { | ||
216 | ktime_t calltime; | ||
217 | int error; | ||
218 | |||
219 | if (!cb) | ||
220 | return 0; | ||
221 | |||
222 | calltime = initcall_debug_start(dev); | ||
223 | |||
224 | error = cb(dev); | ||
225 | suspend_report_result(cb, error); | ||
226 | |||
227 | initcall_debug_report(dev, calltime, error); | ||
228 | |||
229 | return error; | ||
230 | } | ||
231 | |||
213 | /** | 232 | /** |
214 | * pm_op - Execute the PM operation appropriate for given PM event. | 233 | * pm_op - Execute the PM operation appropriate for given PM event. |
215 | * @dev: Device to handle. | 234 | * @dev: Device to handle. |
@@ -221,59 +240,36 @@ static int pm_op(struct device *dev, | |||
221 | pm_message_t state) | 240 | pm_message_t state) |
222 | { | 241 | { |
223 | int error = 0; | 242 | int error = 0; |
224 | ktime_t calltime; | ||
225 | |||
226 | calltime = initcall_debug_start(dev); | ||
227 | 243 | ||
228 | switch (state.event) { | 244 | switch (state.event) { |
229 | #ifdef CONFIG_SUSPEND | 245 | #ifdef CONFIG_SUSPEND |
230 | case PM_EVENT_SUSPEND: | 246 | case PM_EVENT_SUSPEND: |
231 | if (ops->suspend) { | 247 | error = dpm_run_callback(dev, ops->suspend); |
232 | error = ops->suspend(dev); | ||
233 | suspend_report_result(ops->suspend, error); | ||
234 | } | ||
235 | break; | 248 | break; |
236 | case PM_EVENT_RESUME: | 249 | case PM_EVENT_RESUME: |
237 | if (ops->resume) { | 250 | error = dpm_run_callback(dev, ops->resume); |
238 | error = ops->resume(dev); | ||
239 | suspend_report_result(ops->resume, error); | ||
240 | } | ||
241 | break; | 251 | break; |
242 | #endif /* CONFIG_SUSPEND */ | 252 | #endif /* CONFIG_SUSPEND */ |
243 | #ifdef CONFIG_HIBERNATE_CALLBACKS | 253 | #ifdef CONFIG_HIBERNATE_CALLBACKS |
244 | case PM_EVENT_FREEZE: | 254 | case PM_EVENT_FREEZE: |
245 | case PM_EVENT_QUIESCE: | 255 | case PM_EVENT_QUIESCE: |
246 | if (ops->freeze) { | 256 | error = dpm_run_callback(dev, ops->freeze); |
247 | error = ops->freeze(dev); | ||
248 | suspend_report_result(ops->freeze, error); | ||
249 | } | ||
250 | break; | 257 | break; |
251 | case PM_EVENT_HIBERNATE: | 258 | case PM_EVENT_HIBERNATE: |
252 | if (ops->poweroff) { | 259 | error = dpm_run_callback(dev, ops->poweroff); |
253 | error = ops->poweroff(dev); | ||
254 | suspend_report_result(ops->poweroff, error); | ||
255 | } | ||
256 | break; | 260 | break; |
257 | case PM_EVENT_THAW: | 261 | case PM_EVENT_THAW: |
258 | case PM_EVENT_RECOVER: | 262 | case PM_EVENT_RECOVER: |
259 | if (ops->thaw) { | 263 | error = dpm_run_callback(dev, ops->thaw); |
260 | error = ops->thaw(dev); | ||
261 | suspend_report_result(ops->thaw, error); | ||
262 | } | ||
263 | break; | 264 | break; |
264 | case PM_EVENT_RESTORE: | 265 | case PM_EVENT_RESTORE: |
265 | if (ops->restore) { | 266 | error = dpm_run_callback(dev, ops->restore); |
266 | error = ops->restore(dev); | ||
267 | suspend_report_result(ops->restore, error); | ||
268 | } | ||
269 | break; | 267 | break; |
270 | #endif /* CONFIG_HIBERNATE_CALLBACKS */ | 268 | #endif /* CONFIG_HIBERNATE_CALLBACKS */ |
271 | default: | 269 | default: |
272 | error = -EINVAL; | 270 | error = -EINVAL; |
273 | } | 271 | } |
274 | 272 | ||
275 | initcall_debug_report(dev, calltime, error); | ||
276 | |||
277 | return error; | 273 | return error; |
278 | } | 274 | } |
279 | 275 | ||
@@ -291,70 +287,36 @@ static int pm_noirq_op(struct device *dev, | |||
291 | pm_message_t state) | 287 | pm_message_t state) |
292 | { | 288 | { |
293 | int error = 0; | 289 | int error = 0; |
294 | ktime_t calltime = ktime_set(0, 0), delta, rettime; | ||
295 | |||
296 | if (initcall_debug) { | ||
297 | pr_info("calling %s+ @ %i, parent: %s\n", | ||
298 | dev_name(dev), task_pid_nr(current), | ||
299 | dev->parent ? dev_name(dev->parent) : "none"); | ||
300 | calltime = ktime_get(); | ||
301 | } | ||
302 | 290 | ||
303 | switch (state.event) { | 291 | switch (state.event) { |
304 | #ifdef CONFIG_SUSPEND | 292 | #ifdef CONFIG_SUSPEND |
305 | case PM_EVENT_SUSPEND: | 293 | case PM_EVENT_SUSPEND: |
306 | if (ops->suspend_noirq) { | 294 | error = dpm_run_callback(dev, ops->suspend_noirq); |
307 | error = ops->suspend_noirq(dev); | ||
308 | suspend_report_result(ops->suspend_noirq, error); | ||
309 | } | ||
310 | break; | 295 | break; |
311 | case PM_EVENT_RESUME: | 296 | case PM_EVENT_RESUME: |
312 | if (ops->resume_noirq) { | 297 | error = dpm_run_callback(dev, ops->resume_noirq); |
313 | error = ops->resume_noirq(dev); | ||
314 | suspend_report_result(ops->resume_noirq, error); | ||
315 | } | ||
316 | break; | 298 | break; |
317 | #endif /* CONFIG_SUSPEND */ | 299 | #endif /* CONFIG_SUSPEND */ |
318 | #ifdef CONFIG_HIBERNATE_CALLBACKS | 300 | #ifdef CONFIG_HIBERNATE_CALLBACKS |
319 | case PM_EVENT_FREEZE: | 301 | case PM_EVENT_FREEZE: |
320 | case PM_EVENT_QUIESCE: | 302 | case PM_EVENT_QUIESCE: |
321 | if (ops->freeze_noirq) { | 303 | error = dpm_run_callback(dev, ops->freeze_noirq); |
322 | error = ops->freeze_noirq(dev); | ||
323 | suspend_report_result(ops->freeze_noirq, error); | ||
324 | } | ||
325 | break; | 304 | break; |
326 | case PM_EVENT_HIBERNATE: | 305 | case PM_EVENT_HIBERNATE: |
327 | if (ops->poweroff_noirq) { | 306 | error = dpm_run_callback(dev, ops->poweroff_noirq); |
328 | error = ops->poweroff_noirq(dev); | ||
329 | suspend_report_result(ops->poweroff_noirq, error); | ||
330 | } | ||
331 | break; | 307 | break; |
332 | case PM_EVENT_THAW: | 308 | case PM_EVENT_THAW: |
333 | case PM_EVENT_RECOVER: | 309 | case PM_EVENT_RECOVER: |
334 | if (ops->thaw_noirq) { | 310 | error = dpm_run_callback(dev, ops->thaw_noirq); |
335 | error = ops->thaw_noirq(dev); | ||
336 | suspend_report_result(ops->thaw_noirq, error); | ||
337 | } | ||
338 | break; | 311 | break; |
339 | case PM_EVENT_RESTORE: | 312 | case PM_EVENT_RESTORE: |
340 | if (ops->restore_noirq) { | 313 | error = dpm_run_callback(dev, ops->restore_noirq); |
341 | error = ops->restore_noirq(dev); | ||
342 | suspend_report_result(ops->restore_noirq, error); | ||
343 | } | ||
344 | break; | 314 | break; |
345 | #endif /* CONFIG_HIBERNATE_CALLBACKS */ | 315 | #endif /* CONFIG_HIBERNATE_CALLBACKS */ |
346 | default: | 316 | default: |
347 | error = -EINVAL; | 317 | error = -EINVAL; |
348 | } | 318 | } |
349 | 319 | ||
350 | if (initcall_debug) { | ||
351 | rettime = ktime_get(); | ||
352 | delta = ktime_sub(rettime, calltime); | ||
353 | printk("initcall %s_i+ returned %d after %Ld usecs\n", | ||
354 | dev_name(dev), error, | ||
355 | (unsigned long long)ktime_to_ns(delta) >> 10); | ||
356 | } | ||
357 | |||
358 | return error; | 320 | return error; |
359 | } | 321 | } |
360 | 322 | ||
@@ -486,26 +448,6 @@ void dpm_resume_noirq(pm_message_t state) | |||
486 | EXPORT_SYMBOL_GPL(dpm_resume_noirq); | 448 | EXPORT_SYMBOL_GPL(dpm_resume_noirq); |
487 | 449 | ||
488 | /** | 450 | /** |
489 | * legacy_resume - Execute a legacy (bus or class) resume callback for device. | ||
490 | * @dev: Device to resume. | ||
491 | * @cb: Resume callback to execute. | ||
492 | */ | ||
493 | static int legacy_resume(struct device *dev, int (*cb)(struct device *dev)) | ||
494 | { | ||
495 | int error; | ||
496 | ktime_t calltime; | ||
497 | |||
498 | calltime = initcall_debug_start(dev); | ||
499 | |||
500 | error = cb(dev); | ||
501 | suspend_report_result(cb, error); | ||
502 | |||
503 | initcall_debug_report(dev, calltime, error); | ||
504 | |||
505 | return error; | ||
506 | } | ||
507 | |||
508 | /** | ||
509 | * device_resume - Execute "resume" callbacks for given device. | 451 | * device_resume - Execute "resume" callbacks for given device. |
510 | * @dev: Device to handle. | 452 | * @dev: Device to handle. |
511 | * @state: PM transition of the system being carried out. | 453 | * @state: PM transition of the system being carried out. |
@@ -553,7 +495,7 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
553 | goto End; | 495 | goto End; |
554 | } else if (dev->class->resume) { | 496 | } else if (dev->class->resume) { |
555 | pm_dev_dbg(dev, state, "legacy class "); | 497 | pm_dev_dbg(dev, state, "legacy class "); |
556 | error = legacy_resume(dev, dev->class->resume); | 498 | error = dpm_run_callback(dev, dev->class->resume); |
557 | goto End; | 499 | goto End; |
558 | } | 500 | } |
559 | } | 501 | } |
@@ -564,7 +506,7 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
564 | error = pm_op(dev, dev->bus->pm, state); | 506 | error = pm_op(dev, dev->bus->pm, state); |
565 | } else if (dev->bus->resume) { | 507 | } else if (dev->bus->resume) { |
566 | pm_dev_dbg(dev, state, "legacy "); | 508 | pm_dev_dbg(dev, state, "legacy "); |
567 | error = legacy_resume(dev, dev->bus->resume); | 509 | error = dpm_run_callback(dev, dev->bus->resume); |
568 | } | 510 | } |
569 | } | 511 | } |
570 | 512 | ||