linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: mark gross <640e9920@gmail.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>,
	"Linux-pm mailing list" <linux-pm@lists.linux-foundation.org>,
	"Matthew Garrett" <mjg59@srcf.ucam.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Arve Hjønnevåg" <arve@android.com>, "Neil Brown" <neilb@suse.de>,
	"mark gross" <640e9920@gmail.com>
Subject: Re: [RFC][PATCH] PM: Avoid losing wakeup events during suspend
Date: Sun, 20 Jun 2010 23:13:45 -0700	[thread overview]
Message-ID: <20100621061345.GF9735@gvim.org> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1006202154260.29532-100000@netrider.rowland.org>

On Sun, Jun 20, 2010 at 10:23:38PM -0400, Alan Stern wrote:
> On Sun, 20 Jun 2010, Rafael J. Wysocki wrote:
> 
> > > > Generally, there are two problems in that area.  First, if a wakeup event
> > > > occurs exactly at the same time when /sys/power/state is being written to,
> > > > the even may be delivered to user space right before the freezing of it,
> > > > in which case the user space consumer of the event may not be able to process
> > > > it before the system is suspended.
> > > 
> > > Indeed, the same problem arises if the event isn't delivered to
> > > userspace until after userspace is frozen.
> > 
> > In that case the kernel should abort the suspend so that the event can be
> > delivered to the user space.
> 
> Yes.
> 
> > > Of course, the underlying issue here is that the kernel has no direct way
> > > to know when userspace has finished processing an event.  Userspace would
> > > have to tell it, which generally would mean rewriting some large number of user
> > > programs.
> > 
> > I'm not sure of that.  If the kernel doesn't initiate suspend, it doesn't
> > really need to know whether or not user space has already consumed the event.
> 
> That's true.  But it only shifts the onus: When a userspace program has 
> finished processing an event, it has to tell the power-manager process.  
> Clearly this sort of thing is unavoidable, one way or another.
> 
> > > > The following patch illustrates my idea of how these two problems may be
> > > > addressed.  It introduces a new global sysfs attribute,
> > > > /sys/power/wakeup_count, associated with a running counter of wakeup events
> > > > and a helper function, pm_wakeup_event(), that may be used by kernel subsystems
> > > > to increment the wakeup events counter.
> > > 
> > > In what way is this better than suspend blockers?
> > 
> > It doesn't add any new framework and it doesn't require the users of
> > pm_wakeup_event() to "unblock" suspend, so it is simpler.  It also doesn't add
> > the user space interface that caused so much opposition to appear.
> 
> Okay.  A quick comparison shows that in your proposal:
> 
> 	There's no need to register and unregister suspend blockers.
> 	But instead you create the equivalent of a suspend blocker
> 	inside every struct device.
> 
> 	Drivers (or subsystems) don't have to activate suspend 
> 	blockers.  But instead they have to call pm_wakeup_event().
> 
> 	Drivers don't have to deactivate suspend blockers.  You don't
> 	have anything equivalent, and as a result your scheme is 
> 	subject to the race described below.
> 
> 	There are no userspace suspend blockers and no opportunistic
> 	suspend.  Instead a power-manager process takes care of 
> 	initiating or preventing suspends as needed.
> 
> In short, you have eliminated the userspace part of the suspend blocker 
> approach just as in some of the proposals posted earlier, and you have 
> replaced the in-kernel suspend blockers with new data in struct device 
> and a new PM API.  On the whole, it doesn't seem very different from 
> the in-kernel part of suspend blockers.  The most notable difference is 
> the name: pm_wake_event() vs. suspend_blocker_activate(), or whatever 
> it ended up being called.
> 
> This is the race I was talking about:

Your confused about what problem this patch attempts to solve.  There is
a pm_qos patch in the works to address the suspend blocker
functionality.
http://lists.linux-foundation.org/pipermail/linux-pm/2010-June/026760.html

--mgross



> 
> > > What happens if an event arrives just before you read
> > > /sys/power/wakeup_count, but the userspace consumer doesn't realize
> > > there is a new unprocessed event until after the power manager checks
> > > it?
> 
> > I think this is not the kernel's problem.  In this approach the kernel makes it
> > possible for the user space to avoid the race.  Whether or not the user space
> > will use this opportunity is a different matter.
> 
> It is _not_ possible for userspace to avoid this race.  Help from the 
> kernel is needed.
> 
> > >  Your plan is missing a critical step: the "handoff" whereby 
> > > responsibility for handling an event passes from the kernel to 
> > > userspace.
> 
> > > With suspend blockers, this handoff occurs when an event queue is 
> > > emptied and its associate suspend blocker is deactivated.  Or with some 
> > > kinds of events for which the Android people have not written an 
> > > explicit handoff, it occurs when a timer expires (timed suspend 
> > > blockers).
> > 
> > Well, quite frankly, I don't see any difference here.  In either case there is
> > a possibility for user space to mess up things and the kernel can't really help
> > that.
> 
> With suspend blockers, there is also the possibility for userspace to 
> handle races correctly.  But with your scheme there isn't -- that's the 
> difference.
> 
> > > This shares with the other alternatives posted recently the need for a
> > > central power-manager process.  And like in-kernel suspend blockers, it
> > > requires changes to wakeup-capable drivers (the wakeup-events counter
> > > has to be incremented).
> > 
> > It doesn't really require changes to drivers, but to code that knows of wakeup
> > events, like the PCI runtime wakeup code.
> 
> Just like in-kernel suspend blockers.
> 
> >  Moreover, it doesn't require kernel
> > subsystems to know or even care when it is reasonable to allow suspend to
> > happen.  The only thing they need to do is to call pm_wakeup_event() whenever
> > they see a wakeup event.
> 
> That's just semantics.  Obviously a wakeup event should prevent suspend
> from happening, so if subsystems know or care about one then they know
> or care about the other.
> 
> >  I don't really think it is too much of a requirement
> > (and quite frnakly I can't imagine anything simpler than that).
> 
> This is because you have omitted the part about allowing suspends again
> (or if you prefer, about notifying the PM core that a wakeup event has
> been handed off to userspace).  As a result of leaving this out, you
> haven't eliminated all the races.
> 
> > Yes, it does, but I have an idea about how to implement such a power manager
> > and I'm going to actually try it.
> 
> A logical design would be to use dbus for disseminating PM-related 
> information.  Does your idea work that way?
> 
> > I don't think any of the approaches that don't use suspend blockers allows
> > one to avoid the race between the process that writes to /sys/power/state
> > and a wakeup event happening at the same time.  They attempt to address another
> > issue, which is how to prevent untrusted user space processes from keeping the
> > system out of idle, but that is a different story.
> 
> Well, there was one approach that didn't use suspend blockers and did 
> solve the race: the original wakelocks proposal.  Of course, that was 
> just suspend blockers under a different name.  One could make a very 
> good case that your scheme is also suspend blockers under a different 
> name (and with an important part missing).
> 
> Alan Stern
> 

  parent reply	other threads:[~2010-06-21  6:13 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-19 22:05 [RFC][PATCH] PM: Avoid losing wakeup events during suspend Rafael J. Wysocki
2010-06-20  5:52 ` mark gross
2010-06-20 12:49   ` Rafael J. Wysocki
2010-06-20 23:13     ` mark gross
2010-06-20 16:28 ` Alan Stern
2010-06-20 21:50   ` Rafael J. Wysocki
2010-06-21  2:23     ` Alan Stern
2010-06-21  5:32       ` Florian Mickler
2010-06-21 15:23         ` Alan Stern
2010-06-21 20:38           ` Florian Mickler
2010-06-21 22:18             ` Alan Stern
2010-06-21 22:40               ` Rafael J. Wysocki
2010-06-21 22:48                 ` Rafael J. Wysocki
2010-06-22  0:50                 ` Arve Hjønnevåg
2010-06-22 10:21                 ` Rafael J. Wysocki
2010-06-22 14:35                   ` Alan Stern
2010-06-22 15:35                     ` Rafael J. Wysocki
2010-06-22 19:55                       ` Alan Stern
2010-06-22 20:58                         ` Rafael J. Wysocki
2010-06-22 19:59                       ` [update] " Rafael J. Wysocki
2010-06-22 20:34                         ` Alan Stern
2010-06-22 21:41                           ` Rafael J. Wysocki
2010-06-23  2:12                             ` Alan Stern
2010-06-23 10:09                               ` Rafael J. Wysocki
2010-06-23 15:21                                 ` Alan Stern
2010-06-23 22:17                                   ` Rafael J. Wysocki
2010-06-24 13:13                                     ` [update 2] " Rafael J. Wysocki
2010-06-24 15:06                                       ` Rafael J. Wysocki
2010-06-24 15:35                                         ` Alan Stern
2010-06-24 23:00                                           ` [update 3] " Rafael J. Wysocki
2010-06-25 14:42                                             ` Alan Stern
2010-06-25 20:33                                               ` Rafael J. Wysocki
2010-06-24 15:44                                       ` [update 2] " Alan Stern
2010-06-24 16:19                                         ` Rafael J. Wysocki
2010-06-24 17:09                                           ` Alan Stern
2010-06-24 23:06                                             ` Rafael J. Wysocki
2010-06-25 15:09                                               ` Alan Stern
2010-06-25 20:37                                                 ` Rafael J. Wysocki
2010-06-25 20:57                                                   ` Alan Stern
2010-06-25  6:40                                             ` Florian Mickler
2010-06-25 13:28                                               ` Rafael J. Wysocki
     [not found]                       ` <201006222159.28081.rjw__37084.1419128284$1277237903$gmane$org@sisk.pl>
2010-06-24 14:16                         ` [update] " Andy Lutomirski
2010-06-24 14:45                           ` Alan Stern
2010-06-24 14:48                           ` Rafael J. Wysocki
2010-06-24 15:21                             ` Andy Lutomirski
2010-06-22 23:00                   ` mark gross
2010-06-21 16:54         ` Alan Stern
2010-06-21 20:40           ` Florian Mickler
2010-06-21 21:18           ` Rafael J. Wysocki
2010-06-21 22:27             ` Alan Stern
2010-06-21  6:13       ` mark gross [this message]
2010-06-21 12:10         ` tytso
2010-06-21 12:22           ` Alan Cox
2010-06-21 12:26             ` Florian Mickler
2010-06-21 13:42             ` tytso
2010-06-21 14:01               ` Alan Cox
2010-06-22  1:07           ` mark gross
2010-06-21 16:01         ` Alan Stern
2010-06-22  1:25           ` mark gross
2010-06-22  2:24             ` Alan Stern
2010-06-21 21:58       ` Rafael J. Wysocki
2010-06-20 22:58   ` mark gross
2010-06-21  2:33     ` Alan Stern
2010-06-21  4:04       ` [linux-pm] " David Brownell
2010-06-21  6:02         ` David Brownell
2010-06-21 15:06         ` Alan Stern
2010-06-21  5:55       ` mark gross
2010-06-21 12:39         ` Florian Mickler
2010-06-21 15:57         ` Alan Stern
2010-06-22  1:58           ` mark gross
2010-06-22  2:46             ` Alan Stern
2010-06-22  9:24               ` Rafael J. Wysocki
2010-06-22  6:18             ` Florian Mickler
2010-06-22 23:22               ` mark gross
2010-06-22  9:29             ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100621061345.GF9735@gvim.org \
    --to=640e9920@gmail.com \
    --cc=arve@android.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=markgross@thegnar.org \
    --cc=mjg59@srcf.ucam.org \
    --cc=neilb@suse.de \
    --cc=rjw@sisk.pl \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).