mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [linux-pm] [PATCH] PM: Make it possible to avoid wakeup events from being lost
@ 2010-06-26 16:54 David Brownell
  2010-06-26 17:14 ` Alan Stern
  2010-06-26 18:20 ` Rafael J. Wysocki
  0 siblings, 2 replies; 9+ messages in thread
From: David Brownell @ 2010-06-26 16:54 UTC (permalink / raw)
  To: linux-pm, Rafael J. Wysocki
  Cc: mark gross, Neil Brown, linux-pci, Dmitry Torokhov,
	Linux Kernel Mailing List, Arve, Florian Mickler, Jesse Barnes

This is a repeat of an issue I posted before, but
which for some reason I never saw email back ...

basically, I think the notion of counting wakeup
events seems dubious on common hardware, so the
focus might perhaps better be placed on ensuring
userspace just receives events rather than
trying to track events which in one context ended
up being wakeup events.  (That's simpler, and the
system is by definition awake if it can handle any
events at all.)

Thing is, "wakeup" is, for e.g. most ARMs, just a hardware attribute of what's otherwise a routine
event, which happens in other contexts and needs
to be handled consistently .... nothing special
about having woken the system too, the result ought to
be the same regardless (from the user P.O.V.) ...  (Common Examples include SoC peripheral IRQs that can wake the system (including GPIO and other types
of external IRQ signal.)

BRIEFLY:  if that event doesn't arrive reliably,
it's an issue regardless of wakeup:  either TX from
kernel, or RX in userspace. Such bugs would need to
be fixed.  Having them fixed will help the wakeup scenarios too of course.

(The raciness issues might boil down to something as simple as not letting userspace know about transition events to/from suspend states, but that issue
ought to be cleanly separable; ISTR other messages on the suspend blocker threads have shown how to work with such clean factoring.)



So trying to track whether a given event is what
woke the system will often be implausible, since
several such events might each have fired (one
or more concurrent wakeup sources, even ... it
could be indeterminate which one[s] happened.)
And the event could fire without being a wakeup.

Yes, there are a few cases (like USB remote wakeup
signaling and some PCI mechanisms, plus a few BIOS
assisted situations) where certain events may be
identifiable as wakeup sources, perhaps runtime not
system-wide).  But the common case just includes
an event, not the ability to know that event had
the "woke whole system from low power state"
side effect too.




> +        The
> /sys/power/wakeup_count file allows user space to avoid
> +        losing wakeup events
> when transitioning the system into a sleep
> +        state.  Reading
> from it returns the current number of registered
> +        wakeup events and it
> blocks if some wakeup events are being
> +        processed at the
> time the file is read from. 



^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [PATCH] PM: Make it possible to avoid wakeup events from being lost
@ 2010-06-27 23:59 Rafael J. Wysocki
  2010-06-28 23:28 ` [linux-pm] " David Brownell
  0 siblings, 1 reply; 9+ messages in thread
From: Rafael J. Wysocki @ 2010-06-27 23:59 UTC (permalink / raw)
  To: Alan Stern
  Cc: linux-pm, Linux Kernel Mailing List, Neil Brown, Matthew Garrett,
	mark gross, Arve Hjønnevåg, Dmitry Torokhov,
	Florian Mickler, linux-pci, Jesse Barnes

On Sunday, June 27, 2010, Alan Stern wrote:
> On Sat, 26 Jun 2010, Rafael J. Wysocki wrote:
> 
> > +void pm_relax(void)
> > +{
> > +	unsigned long flags;
> > +
> > +	spin_lock_irqsave(&events_lock, flags);
> > +	if (events_in_progress) {
> > +		event_count++;
> > +		if (!--events_in_progress)
> > +			wake_up_all(&events_wait_queue);
> > +	}
> > +	spin_unlock_irqrestore(&events_lock, flags);
> > +}
> 
> > +bool pm_get_wakeup_count(unsigned long *count)
> > +{
> > +	bool ret;
> > +
> > +	spin_lock_irq(&events_lock);
> > +	if (capable(CAP_SYS_ADMIN))
> > +		events_check_enabled = false;
> > +
> > +	if (events_in_progress) {
> > +		DEFINE_WAIT(wait);
> > +
> > +		do {
> > +			prepare_to_wait(&events_wait_queue, &wait,
> > +					TASK_INTERRUPTIBLE);
> > +			if (!events_in_progress)
> > +				break;
> > +			spin_unlock_irq(&events_lock);
> > +
> > +			schedule();
> > +
> > +			spin_lock_irq(&events_lock);
> > +		} while (!signal_pending(current));
> > +		finish_wait(&events_wait_queue, &wait);
> > +	}
> > +	*count = event_count;
> > +	ret = !events_in_progress;
> > +	spin_unlock_irq(&events_lock);
> > +	return ret;
> > +}
> 
> Here's a thought.  Presumably pm_relax() will end up getting called a 
> lot more often than pm_get_wakeup_count().  Instead of using a wait 
> queue, you could make pm_get_wakeup_count() poll at 100-ms intervals.  
> The total overhead would be smaller.

For that I'd need a separate kernel thread or a work item that would reschedule
itself periodically, because pm_get_wakeup_count() is only called via
/sys/power/wakeup_count.  It would complicate things quite a bit which I'm not
sure is worth it at this point.

> Here's another thought.  If event_count and events_in_progress were 
> atomic_t then the new spinlock wouldn't be needed at all.  (But you 
> would need an appropriate pair of memory barriers, to guarantee that 
> when a writer decrements events_in_progress to 0 and increments 
> event_count, a reader won't see events_in_progress == 0 without also 
> seeing the incremented event_count.)  Overall, this may not be a
> significant improvement.

No, I don't think it would be significant.  Still, we can go back to this
if the spinlock turns out to be a problem in future.

Rafael

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-06-29 19:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-26 16:54 [linux-pm] [PATCH] PM: Make it possible to avoid wakeup events from being lost David Brownell
2010-06-26 17:14 ` Alan Stern
2010-06-26 18:21   ` Rafael J. Wysocki
2010-06-26 19:58     ` Alan Stern
2010-06-27  2:43   ` David Brownell
2010-06-27  3:06     ` Alan Stern
2010-06-26 18:20 ` Rafael J. Wysocki
2010-06-27 23:59 Rafael J. Wysocki
2010-06-28 23:28 ` [linux-pm] " David Brownell
2010-06-29 19:57   ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®