Skip to content

Commit 8a537ec

Browse files
committed
PM / wakeup: Integrate mechanism to abort transitions in progress
The system wakeup framework is not very consistent with respect to the way it handles suspend-to-idle and generally wakeup events occurring during transitions to system low-power states. First off, system transitions in progress are aborted by the event reporting helpers like pm_wakeup_event() only if the wakeup_count sysfs attribute is in use (as documented), but there are cases in which system-wide transitions should be aborted even if that is not the case. For example, a wakeup signal from a designated wakeup device during system-wide PM transition, it should cause the transition to be aborted right away. Moreover, there is a freeze_wake() call in wakeup_source_activate(), but that really is only effective after suspend_freeze_state has been set to FREEZE_STATE_ENTER by freeze_enter(). However, it is very unlikely that wakeup_source_activate() will ever be called at that time, as it could only be triggered by a IRQF_NO_SUSPEND interrupt handler, so wakeups from suspend-to-idle don't really occur in wakeup_source_activate(). At the same time there is a way to abort a system suspend in progress (or wake up the system from suspend-to-idle), which is by calling pm_system_wakeup(), but in turn that doesn't cause any wakeup source objects to be activated, so it will not be covered by wakeup source statistics and will not prevent the system from suspending again immediately (in case autosleep is used, for example). Consequently, if anyone wants to abort system transitions in progress and allow the wakeup_count mechanism to work, they need to use both pm_system_wakeup() and pm_wakeup_event(), say, at the same time which is awkward. For the above reasons, make it possible to trigger pm_system_wakeup() from within wakeup_source_activate() and provide a new pm_wakeup_hard_event() helper to do so within the wakeup framework. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent a351e9b commit 8a537ec

2 files changed

Lines changed: 39 additions & 22 deletions

File tree

‎drivers/base/power/wakeup.c‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -512,24 +512,22 @@ static bool wakeup_source_not_registered(struct wakeup_source *ws)
512512
/**
513513
* wakup_source_activate - Mark given wakeup source as active.
514514
* @ws: Wakeup source to handle.
515+
* @hard: If set, abort suspends in progress and wake up from suspend-to-idle.
515516
*
516517
* Update the @ws' statistics and, if @ws has just been activated, notify the PM
517518
* core of the event by incrementing the counter of of wakeup events being
518519
* processed.
519520
*/
520-
static void wakeup_source_activate(struct wakeup_source *ws)
521+
static void wakeup_source_activate(struct wakeup_source *ws, bool hard)
521522
{
522523
unsigned int cec;
523524

524525
if (WARN_ONCE(wakeup_source_not_registered(ws),
525526
"unregistered wakeup source\n"))
526527
return;
527528

528-
/*
529-
* active wakeup source should bring the system
530-
* out of PM_SUSPEND_FREEZE state
531-
*/
532-
freeze_wake();
529+
if (hard)
530+
pm_system_wakeup();
533531

534532
ws->active = true;
535533
ws->active_count++;
@@ -546,16 +544,17 @@ static void wakeup_source_activate(struct wakeup_source *ws)
546544
/**
547545
* wakeup_source_report_event - Report wakeup event using the given source.
548546
* @ws: Wakeup source to report the event for.
547+
* @hard: If set, abort suspends in progress and wake up from suspend-to-idle.
549548
*/
550-
static void wakeup_source_report_event(struct wakeup_source *ws)
549+
static void wakeup_source_report_event(struct wakeup_source *ws, bool hard)
551550
{
552551
ws->event_count++;
553552
/* This is racy, but the counter is approximate anyway. */
554553
if (events_check_enabled)
555554
ws->wakeup_count++;
556555

557556
if (!ws->active)
558-
wakeup_source_activate(ws);
557+
wakeup_source_activate(ws, hard);
559558
}
560559

561560
/**
@@ -573,7 +572,7 @@ void __pm_stay_awake(struct wakeup_source *ws)
573572

574573
spin_lock_irqsave(&ws->lock, flags);
575574

576-
wakeup_source_report_event(ws);
575+
wakeup_source_report_event(ws, false);
577576
del_timer(&ws->timer);
578577
ws->timer_expires = 0;
579578

@@ -739,9 +738,10 @@ static void pm_wakeup_timer_fn(unsigned long data)
739738
}
740739

741740
/**
742-
* __pm_wakeup_event - Notify the PM core of a wakeup event.
741+
* pm_wakeup_ws_event - Notify the PM core of a wakeup event.
743742
* @ws: Wakeup source object associated with the event source.
744743
* @msec: Anticipated event processing time (in milliseconds).
744+
* @hard: If set, abort suspends in progress and wake up from suspend-to-idle.
745745
*
746746
* Notify the PM core of a wakeup event whose source is @ws that will take
747747
* approximately @msec milliseconds to be processed by the kernel. If @ws is
@@ -750,7 +750,7 @@ static void pm_wakeup_timer_fn(unsigned long data)
750750
*
751751
* It is safe to call this function from interrupt context.
752752
*/
753-
void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
753+
void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard)
754754
{
755755
unsigned long flags;
756756
unsigned long expires;
@@ -760,7 +760,7 @@ void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
760760

761761
spin_lock_irqsave(&ws->lock, flags);
762762

763-
wakeup_source_report_event(ws);
763+
wakeup_source_report_event(ws, hard);
764764

765765
if (!msec) {
766766
wakeup_source_deactivate(ws);
@@ -779,28 +779,28 @@ void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
779779
unlock:
780780
spin_unlock_irqrestore(&ws->lock, flags);
781781
}
782-
EXPORT_SYMBOL_GPL(__pm_wakeup_event);
783-
782+
EXPORT_SYMBOL_GPL(pm_wakeup_ws_event);
784783

785784
/**
786785
* pm_wakeup_event - Notify the PM core of a wakeup event.
787786
* @dev: Device the wakeup event is related to.
788787
* @msec: Anticipated event processing time (in milliseconds).
788+
* @hard: If set, abort suspends in progress and wake up from suspend-to-idle.
789789
*
790-
* Call __pm_wakeup_event() for the @dev's wakeup source object.
790+
* Call pm_wakeup_ws_event() for the @dev's wakeup source object.
791791
*/
792-
void pm_wakeup_event(struct device *dev, unsigned int msec)
792+
void pm_wakeup_dev_event(struct device *dev, unsigned int msec, bool hard)
793793
{
794794
unsigned long flags;
795795

796796
if (!dev)
797797
return;
798798

799799
spin_lock_irqsave(&dev->power.lock, flags);
800-
__pm_wakeup_event(dev->power.wakeup, msec);
800+
pm_wakeup_ws_event(dev->power.wakeup, msec, hard);
801801
spin_unlock_irqrestore(&dev->power.lock, flags);
802802
}
803-
EXPORT_SYMBOL_GPL(pm_wakeup_event);
803+
EXPORT_SYMBOL_GPL(pm_wakeup_dev_event);
804804

805805
void pm_print_active_wakeup_sources(void)
806806
{

‎include/linux/pm_wakeup.h‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ extern void __pm_stay_awake(struct wakeup_source *ws);
106106
extern void pm_stay_awake(struct device *dev);
107107
extern void __pm_relax(struct wakeup_source *ws);
108108
extern void pm_relax(struct device *dev);
109-
extern void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec);
110-
extern void pm_wakeup_event(struct device *dev, unsigned int msec);
109+
extern void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard);
110+
extern void pm_wakeup_dev_event(struct device *dev, unsigned int msec, bool hard);
111111

112112
#else /* !CONFIG_PM_SLEEP */
113113

@@ -182,9 +182,11 @@ static inline void __pm_relax(struct wakeup_source *ws) {}
182182

183183
static inline void pm_relax(struct device *dev) {}
184184

185-
static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec) {}
185+
static inline void pm_wakeup_ws_event(struct wakeup_source *ws,
186+
unsigned int msec, bool hard) {}
186187

187-
static inline void pm_wakeup_event(struct device *dev, unsigned int msec) {}
188+
static inline void pm_wakeup_dev_event(struct device *dev, unsigned int msec,
189+
bool hard) {}
188190

189191
#endif /* !CONFIG_PM_SLEEP */
190192

@@ -201,4 +203,19 @@ static inline void wakeup_source_trash(struct wakeup_source *ws)
201203
wakeup_source_drop(ws);
202204
}
203205

206+
static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
207+
{
208+
return pm_wakeup_ws_event(ws, msec, false);
209+
}
210+
211+
static inline void pm_wakeup_event(struct device *dev, unsigned int msec)
212+
{
213+
return pm_wakeup_dev_event(dev, msec, false);
214+
}
215+
216+
static inline void pm_wakeup_hard_event(struct device *dev)
217+
{
218+
return pm_wakeup_dev_event(dev, 0, true);
219+
}
220+
204221
#endif /* _LINUX_PM_WAKEUP_H */

0 commit comments

Comments
 (0)