aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-12-22 17:22:05 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-22 17:22:05 -0500
commit2218a4fcf3cddd076aaf8855f675ce77f74a500b (patch)
tree3cd0656eed0d9fbacd71048159ec1ba8a11dd53f /drivers/base
parentfe35d4a0289a8d6efcacb57e9a377b845686df10 (diff)
parentf1212ae1332b95fe3bafa7b5c063dd8e473247cf (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/suspend-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/suspend-2.6: PM: Runtime PM documentation update PM / Runtime: Use device type and device class callbacks PM: Use pm_runtime_put_sync in system resume PM: Measure device suspend and resume times PM: Make the initcall_debug style timing for suspend/resume complete
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/power/main.c128
-rw-r--r--drivers/base/power/runtime.c45
2 files changed, 151 insertions, 22 deletions
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 1a216c114a0f..48adf80926a0 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -161,6 +161,32 @@ void device_pm_move_last(struct device *dev)
161 list_move_tail(&dev->power.entry, &dpm_list); 161 list_move_tail(&dev->power.entry, &dpm_list);
162} 162}
163 163
164static ktime_t initcall_debug_start(struct device *dev)
165{
166 ktime_t calltime = ktime_set(0, 0);
167
168 if (initcall_debug) {
169 pr_info("calling %s+ @ %i\n",
170 dev_name(dev), task_pid_nr(current));
171 calltime = ktime_get();
172 }
173
174 return calltime;
175}
176
177static void initcall_debug_report(struct device *dev, ktime_t calltime,
178 int error)
179{
180 ktime_t delta, rettime;
181
182 if (initcall_debug) {
183 rettime = ktime_get();
184 delta = ktime_sub(rettime, calltime);
185 pr_info("call %s+ returned %d after %Ld usecs\n", dev_name(dev),
186 error, (unsigned long long)ktime_to_ns(delta) >> 10);
187 }
188}
189
164/** 190/**
165 * pm_op - Execute the PM operation appropriate for given PM event. 191 * pm_op - Execute the PM operation appropriate for given PM event.
166 * @dev: Device to handle. 192 * @dev: Device to handle.
@@ -172,13 +198,9 @@ static int pm_op(struct device *dev,
172 pm_message_t state) 198 pm_message_t state)
173{ 199{
174 int error = 0; 200 int error = 0;
175 ktime_t calltime, delta, rettime; 201 ktime_t calltime;
176 202
177 if (initcall_debug) { 203 calltime = initcall_debug_start(dev);
178 pr_info("calling %s+ @ %i\n",
179 dev_name(dev), task_pid_nr(current));
180 calltime = ktime_get();
181 }
182 204
183 switch (state.event) { 205 switch (state.event) {
184#ifdef CONFIG_SUSPEND 206#ifdef CONFIG_SUSPEND
@@ -227,12 +249,7 @@ static int pm_op(struct device *dev,
227 error = -EINVAL; 249 error = -EINVAL;
228 } 250 }
229 251
230 if (initcall_debug) { 252 initcall_debug_report(dev, calltime, error);
231 rettime = ktime_get();
232 delta = ktime_sub(rettime, calltime);
233 pr_info("call %s+ returned %d after %Ld usecs\n", dev_name(dev),
234 error, (unsigned long long)ktime_to_ns(delta) >> 10);
235 }
236 253
237 return error; 254 return error;
238} 255}
@@ -309,8 +326,9 @@ static int pm_noirq_op(struct device *dev,
309 if (initcall_debug) { 326 if (initcall_debug) {
310 rettime = ktime_get(); 327 rettime = ktime_get();
311 delta = ktime_sub(rettime, calltime); 328 delta = ktime_sub(rettime, calltime);
312 printk("initcall %s_i+ returned %d after %Ld usecs\n", dev_name(dev), 329 printk("initcall %s_i+ returned %d after %Ld usecs\n",
313 error, (unsigned long long)ktime_to_ns(delta) >> 10); 330 dev_name(dev), error,
331 (unsigned long long)ktime_to_ns(delta) >> 10);
314 } 332 }
315 333
316 return error; 334 return error;
@@ -354,6 +372,23 @@ static void pm_dev_err(struct device *dev, pm_message_t state, char *info,
354 kobject_name(&dev->kobj), pm_verb(state.event), info, error); 372 kobject_name(&dev->kobj), pm_verb(state.event), info, error);
355} 373}
356 374
375static void dpm_show_time(ktime_t starttime, pm_message_t state, char *info)
376{
377 ktime_t calltime;
378 s64 usecs64;
379 int usecs;
380
381 calltime = ktime_get();
382 usecs64 = ktime_to_ns(ktime_sub(calltime, starttime));
383 do_div(usecs64, NSEC_PER_USEC);
384 usecs = usecs64;
385 if (usecs == 0)
386 usecs = 1;
387 pr_info("PM: %s%s%s of devices complete after %ld.%03ld msecs\n",
388 info ?: "", info ? " " : "", pm_verb(state.event),
389 usecs / USEC_PER_MSEC, usecs % USEC_PER_MSEC);
390}
391
357/*------------------------- Resume routines -------------------------*/ 392/*------------------------- Resume routines -------------------------*/
358 393
359/** 394/**
@@ -390,6 +425,7 @@ static int device_resume_noirq(struct device *dev, pm_message_t state)
390void dpm_resume_noirq(pm_message_t state) 425void dpm_resume_noirq(pm_message_t state)
391{ 426{
392 struct device *dev; 427 struct device *dev;
428 ktime_t starttime = ktime_get();
393 429
394 mutex_lock(&dpm_list_mtx); 430 mutex_lock(&dpm_list_mtx);
395 transition_started = false; 431 transition_started = false;
@@ -403,11 +439,32 @@ void dpm_resume_noirq(pm_message_t state)
403 pm_dev_err(dev, state, " early", error); 439 pm_dev_err(dev, state, " early", error);
404 } 440 }
405 mutex_unlock(&dpm_list_mtx); 441 mutex_unlock(&dpm_list_mtx);
442 dpm_show_time(starttime, state, "early");
406 resume_device_irqs(); 443 resume_device_irqs();
407} 444}
408EXPORT_SYMBOL_GPL(dpm_resume_noirq); 445EXPORT_SYMBOL_GPL(dpm_resume_noirq);
409 446
410/** 447/**
448 * legacy_resume - Execute a legacy (bus or class) resume callback for device.
449 * dev: Device to resume.
450 * cb: Resume callback to execute.
451 */
452static int legacy_resume(struct device *dev, int (*cb)(struct device *dev))
453{
454 int error;
455 ktime_t calltime;
456
457 calltime = initcall_debug_start(dev);
458
459 error = cb(dev);
460 suspend_report_result(cb, error);
461
462 initcall_debug_report(dev, calltime, error);
463
464 return error;
465}
466
467/**
411 * device_resume - Execute "resume" callbacks for given device. 468 * device_resume - Execute "resume" callbacks for given device.
412 * @dev: Device to handle. 469 * @dev: Device to handle.
413 * @state: PM transition of the system being carried out. 470 * @state: PM transition of the system being carried out.
@@ -427,7 +484,7 @@ static int device_resume(struct device *dev, pm_message_t state)
427 error = pm_op(dev, dev->bus->pm, state); 484 error = pm_op(dev, dev->bus->pm, state);
428 } else if (dev->bus->resume) { 485 } else if (dev->bus->resume) {
429 pm_dev_dbg(dev, state, "legacy "); 486 pm_dev_dbg(dev, state, "legacy ");
430 error = dev->bus->resume(dev); 487 error = legacy_resume(dev, dev->bus->resume);
431 } 488 }
432 if (error) 489 if (error)
433 goto End; 490 goto End;
@@ -448,7 +505,7 @@ static int device_resume(struct device *dev, pm_message_t state)
448 error = pm_op(dev, dev->class->pm, state); 505 error = pm_op(dev, dev->class->pm, state);
449 } else if (dev->class->resume) { 506 } else if (dev->class->resume) {
450 pm_dev_dbg(dev, state, "legacy class "); 507 pm_dev_dbg(dev, state, "legacy class ");
451 error = dev->class->resume(dev); 508 error = legacy_resume(dev, dev->class->resume);
452 } 509 }
453 } 510 }
454 End: 511 End:
@@ -468,6 +525,7 @@ static int device_resume(struct device *dev, pm_message_t state)
468static void dpm_resume(pm_message_t state) 525static void dpm_resume(pm_message_t state)
469{ 526{
470 struct list_head list; 527 struct list_head list;
528 ktime_t starttime = ktime_get();
471 529
472 INIT_LIST_HEAD(&list); 530 INIT_LIST_HEAD(&list);
473 mutex_lock(&dpm_list_mtx); 531 mutex_lock(&dpm_list_mtx);
@@ -496,6 +554,7 @@ static void dpm_resume(pm_message_t state)
496 } 554 }
497 list_splice(&list, &dpm_list); 555 list_splice(&list, &dpm_list);
498 mutex_unlock(&dpm_list_mtx); 556 mutex_unlock(&dpm_list_mtx);
557 dpm_show_time(starttime, state, NULL);
499} 558}
500 559
501/** 560/**
@@ -548,7 +607,7 @@ static void dpm_complete(pm_message_t state)
548 mutex_unlock(&dpm_list_mtx); 607 mutex_unlock(&dpm_list_mtx);
549 608
550 device_complete(dev, state); 609 device_complete(dev, state);
551 pm_runtime_put_noidle(dev); 610 pm_runtime_put_sync(dev);
552 611
553 mutex_lock(&dpm_list_mtx); 612 mutex_lock(&dpm_list_mtx);
554 } 613 }
@@ -628,6 +687,7 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state)
628int dpm_suspend_noirq(pm_message_t state) 687int dpm_suspend_noirq(pm_message_t state)
629{ 688{
630 struct device *dev; 689 struct device *dev;
690 ktime_t starttime = ktime_get();
631 int error = 0; 691 int error = 0;
632 692
633 suspend_device_irqs(); 693 suspend_device_irqs();
@@ -643,11 +703,34 @@ int dpm_suspend_noirq(pm_message_t state)
643 mutex_unlock(&dpm_list_mtx); 703 mutex_unlock(&dpm_list_mtx);
644 if (error) 704 if (error)
645 dpm_resume_noirq(resume_event(state)); 705 dpm_resume_noirq(resume_event(state));
706 else
707 dpm_show_time(starttime, state, "late");
646 return error; 708 return error;
647} 709}
648EXPORT_SYMBOL_GPL(dpm_suspend_noirq); 710EXPORT_SYMBOL_GPL(dpm_suspend_noirq);
649 711
650/** 712/**
713 * legacy_suspend - Execute a legacy (bus or class) suspend callback for device.
714 * dev: Device to suspend.
715 * cb: Suspend callback to execute.
716 */
717static int legacy_suspend(struct device *dev, pm_message_t state,
718 int (*cb)(struct device *dev, pm_message_t state))
719{
720 int error;
721 ktime_t calltime;
722
723 calltime = initcall_debug_start(dev);
724
725 error = cb(dev, state);
726 suspend_report_result(cb, error);
727
728 initcall_debug_report(dev, calltime, error);
729
730 return error;
731}
732
733/**
651 * device_suspend - Execute "suspend" callbacks for given device. 734 * device_suspend - Execute "suspend" callbacks for given device.
652 * @dev: Device to handle. 735 * @dev: Device to handle.
653 * @state: PM transition of the system being carried out. 736 * @state: PM transition of the system being carried out.
@@ -664,8 +747,7 @@ static int device_suspend(struct device *dev, pm_message_t state)
664 error = pm_op(dev, dev->class->pm, state); 747 error = pm_op(dev, dev->class->pm, state);
665 } else if (dev->class->suspend) { 748 } else if (dev->class->suspend) {
666 pm_dev_dbg(dev, state, "legacy class "); 749 pm_dev_dbg(dev, state, "legacy class ");
667 error = dev->class->suspend(dev, state); 750 error = legacy_suspend(dev, state, dev->class->suspend);
668 suspend_report_result(dev->class->suspend, error);
669 } 751 }
670 if (error) 752 if (error)
671 goto End; 753 goto End;
@@ -686,8 +768,7 @@ static int device_suspend(struct device *dev, pm_message_t state)
686 error = pm_op(dev, dev->bus->pm, state); 768 error = pm_op(dev, dev->bus->pm, state);
687 } else if (dev->bus->suspend) { 769 } else if (dev->bus->suspend) {
688 pm_dev_dbg(dev, state, "legacy "); 770 pm_dev_dbg(dev, state, "legacy ");
689 error = dev->bus->suspend(dev, state); 771 error = legacy_suspend(dev, state, dev->bus->suspend);
690 suspend_report_result(dev->bus->suspend, error);
691 } 772 }
692 } 773 }
693 End: 774 End:
@@ -703,6 +784,7 @@ static int device_suspend(struct device *dev, pm_message_t state)
703static int dpm_suspend(pm_message_t state) 784static int dpm_suspend(pm_message_t state)
704{ 785{
705 struct list_head list; 786 struct list_head list;
787 ktime_t starttime = ktime_get();
706 int error = 0; 788 int error = 0;
707 789
708 INIT_LIST_HEAD(&list); 790 INIT_LIST_HEAD(&list);
@@ -728,6 +810,8 @@ static int dpm_suspend(pm_message_t state)
728 } 810 }
729 list_splice(&list, dpm_list.prev); 811 list_splice(&list, dpm_list.prev);
730 mutex_unlock(&dpm_list_mtx); 812 mutex_unlock(&dpm_list_mtx);
813 if (!error)
814 dpm_show_time(starttime, state, NULL);
731 return error; 815 return error;
732} 816}
733 817
@@ -796,7 +880,7 @@ static int dpm_prepare(pm_message_t state)
796 pm_runtime_get_noresume(dev); 880 pm_runtime_get_noresume(dev);
797 if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) { 881 if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) {
798 /* Wake-up requested during system sleep transition. */ 882 /* Wake-up requested during system sleep transition. */
799 pm_runtime_put_noidle(dev); 883 pm_runtime_put_sync(dev);
800 error = -EBUSY; 884 error = -EBUSY;
801 } else { 885 } else {
802 error = device_prepare(dev, state); 886 error = device_prepare(dev, state);
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 40d7720a4b21..f8b044e8aef7 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -85,6 +85,19 @@ static int __pm_runtime_idle(struct device *dev)
85 dev->bus->pm->runtime_idle(dev); 85 dev->bus->pm->runtime_idle(dev);
86 86
87 spin_lock_irq(&dev->power.lock); 87 spin_lock_irq(&dev->power.lock);
88 } else if (dev->type && dev->type->pm && dev->type->pm->runtime_idle) {
89 spin_unlock_irq(&dev->power.lock);
90
91 dev->type->pm->runtime_idle(dev);
92
93 spin_lock_irq(&dev->power.lock);
94 } else if (dev->class && dev->class->pm
95 && dev->class->pm->runtime_idle) {
96 spin_unlock_irq(&dev->power.lock);
97
98 dev->class->pm->runtime_idle(dev);
99
100 spin_lock_irq(&dev->power.lock);
88 } 101 }
89 102
90 dev->power.idle_notification = false; 103 dev->power.idle_notification = false;
@@ -194,6 +207,22 @@ int __pm_runtime_suspend(struct device *dev, bool from_wq)
194 207
195 spin_lock_irq(&dev->power.lock); 208 spin_lock_irq(&dev->power.lock);
196 dev->power.runtime_error = retval; 209 dev->power.runtime_error = retval;
210 } else if (dev->type && dev->type->pm
211 && dev->type->pm->runtime_suspend) {
212 spin_unlock_irq(&dev->power.lock);
213
214 retval = dev->type->pm->runtime_suspend(dev);
215
216 spin_lock_irq(&dev->power.lock);
217 dev->power.runtime_error = retval;
218 } else if (dev->class && dev->class->pm
219 && dev->class->pm->runtime_suspend) {
220 spin_unlock_irq(&dev->power.lock);
221
222 retval = dev->class->pm->runtime_suspend(dev);
223
224 spin_lock_irq(&dev->power.lock);
225 dev->power.runtime_error = retval;
197 } else { 226 } else {
198 retval = -ENOSYS; 227 retval = -ENOSYS;
199 } 228 }
@@ -359,6 +388,22 @@ int __pm_runtime_resume(struct device *dev, bool from_wq)
359 388
360 spin_lock_irq(&dev->power.lock); 389 spin_lock_irq(&dev->power.lock);
361 dev->power.runtime_error = retval; 390 dev->power.runtime_error = retval;
391 } else if (dev->type && dev->type->pm
392 && dev->type->pm->runtime_resume) {
393 spin_unlock_irq(&dev->power.lock);
394
395 retval = dev->type->pm->runtime_resume(dev);
396
397 spin_lock_irq(&dev->power.lock);
398 dev->power.runtime_error = retval;
399 } else if (dev->class && dev->class->pm
400 && dev->class->pm->runtime_resume) {
401 spin_unlock_irq(&dev->power.lock);
402
403 retval = dev->class->pm->runtime_resume(dev);
404
405 spin_lock_irq(&dev->power.lock);
406 dev->power.runtime_error = retval;
362 } else { 407 } else {
363 retval = -ENOSYS; 408 retval = -ENOSYS;
364 } 409 }