All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bastien Nocera <hadess@hadess.net>
To: Chirantan Ekbote <chirantan@chromium.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	John Stultz <john.stultz@linaro.org>,
	Olof Johansson <olof@lixom.net>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	snanda@chromium.org, Tomeu Vizoso <tomeu.vizoso@collabora.com>,
	Linux PM list <linux-pm@vger.kernel.org>
Subject: Re: A desktop environment[1] kernel wishlist
Date: Tue, 05 May 2015 12:46:40 +0200	[thread overview]
Message-ID: <1430822800.7954.5.camel@hadess.net> (raw)
In-Reply-To: <CAJFHJrrYhOtjQENR2-_v2XDeYUJCB1tw7MnZbWjC0d-Mz3Z15g@mail.gmail.com>

On Mon, 2015-05-04 at 16:30 -0700, Chirantan Ekbote wrote:
> 
<snip>
> In the interest of brevity, I didn't go into the design of suspend /
> resume in userspace in my last email but it seems like there's no way
> around it.
> 
> Ignoring lucid sleep for a moment, here is how a regular suspend 
> works
> in the power manager.  The power manager sees a suspend request 
> either
> because the user has been idle for X amount of time (usually 15
> minutes) or the user explicitly requested it by closing the lid.  The
> power manager reads the value of /sys/power/wakeup_count and then
> announces an imminent suspend to the rest of the system via DBus.
> Interested applications (like the network manager and Chrome) will
> have registered with the power manager to be informed about this when
> they started up.  For example, this is when Chrome would freeze its
> renderer processes.  The power manager will now wait for them to
> report back their readiness to suspend.  Once all applications have
> reported ready (or the maximum timeout occurs), the power manager
> performs some final preparations (like setting the resume brightness
> for the display).

logind in systemd also does this, using block or delay inhibitors over
D-Bus:
http://www.freedesktop.org/wiki/Software/systemd/inhibit/

>   The last thing the power manager does, right before
> writing "mem" to /sys/power/state, is write the wakeup_count that it
> read earlier to /sys/power/wakeup_count.  If the write fails, the
> power manager considers the suspend attempt failed, reads the new
> wakeup_count, and starts a timer (usually 10 seconds) to retry the
> suspend.  The same thing happens if the write to /sys/power/state
> fails.

Is this something that logind should do as well?

> It may be the case that the event that incremented the count happened
> because a user was trying to cancel the suspend.  The user could have
> pressed some keys on the keyboard, touched the trackpad, opened the
> lid, pressed the power button, etc, etc.  For the keyboard and
> trackpad these events make their way up to Chrome, which sends a user
> activity message to the power manager.  This is a message that Chrome
> sends to the power manager even during regular activity, up to five
> times a second, to prevent the idle timeout from occuring.  When the
> power manager sees this user activity message while waiting to retry
> the suspend, it cancels the retry and sends out a DBus signal
> informing the system that the suspend is now complete.  For events
> like opening the lid or pressing the power button, the power manager
> monitors those events in /dev/input and simulates a user activity
> message from chrome if any of them fire.
> 
> 
> Ok so now I can talk about how lucid sleep fits into all of this. 
>  The
> power manager only considers a suspend attempt successful if the 
> write
> to /sys/power/state was successful.  If the suspend was successful,
> the power manager then reads another sysfs file
> (/sys/power/wakeup_type in our kernel) to determine if the wakeup
> event was user-triggered.

This is where your lucid sleep implementation matches up with what I
had in mind for that wishlist.

>   If the event was user-triggered it sends
> out a DBus signal announcing the end of the suspend, Chrome thaws its
> renderer processes, the full UI comes back up, and the user can start
> working.  If the event was _not_ user-triggred (if it was the RTC or
> NIC), the power manager sends out a different DBus signal announcing
> that the system is in lucid sleep and will re-suspend soon.  It will
> then wait for all registered applications to report readiness to
> suspend or for the max timeout to expire.
> 
> If it so happens that a user interacts with the system while it is in
> this state, the power manager detects it via the user activity 
> message
> that Chrome sends.  This could be real (keyboard, trackpad) or
> simulated (lid, power button).  Either way, the power manager 
> responds
> the same way: it announces the end of the suspend, Chrome thaws its
> renderers, the full UI comes back up, and the user starts working. 
>  If
> there is no user activity and all applications report ready, the 
> power
> manager gets ready to suspend the system again.  Since the NIC is now
> a wakeup source, the power manager doesn't read the wakeup_count 
> until
> after all applications have reported ready because accessing the
> network could increment the wakeup_count and cause false positives.
> 
> If either the write to /sys/power/wakeup_count or /sys/power/state
> fails from lucid sleep, the power manager re-announces that the 
> system
> is in lucid sleep and will re-suspend soon.  It's actually a little
> smart about this: it will only re-announce lucid sleep if there was a
> wakeup_count mismatch or if the write to /sys/power/state returned
> EBUSY.  Other failures only trigger a simple retry and no DBus 
> signal.
> We do this because these wakeup events may legitimately trigger lucid
> sleep.  For example, more packets may arrive from the network or the
> RTC may go off and applications don't perform work until they hear
> from the power manager that the system is in lucid sleep.  At this
> point the power manager is back to waiting for applications to report
> ready (or for the retry timer to fire).  This process may repeat
> multiple times if we keep getting wakeup events right as the system
> tries to re-suspend.
> 
> 
> So that was a little long-winded but hopefully I've addressed all 
> your
> concerns about potential race conditions in this code.  I simplified 
> a
> few bits because would just complicate the discussion but for the 
> most
> part this is how the feature works now.  Having the kernel emit a
> uevent with the wakeup event type would take the place of the power
> manager reading from /sys/power/wakeup_type in this system but
> wouldn't really affect anything else.

Could you or Tomeu explain the driver changes that are necessary? Do
only drivers that we want to be usable as wakeup sources need to be
changed? Do you have examples of such a patch?

Cheers


  reply	other threads:[~2015-05-05 10:46 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-21  8:49 A desktop environment[1] kernel wishlist Bastien Nocera
2014-10-21 13:11 ` Sergey
2014-10-22  2:58   ` Minchan Kim
2014-10-22 16:52   ` Dan Streetman
2014-10-22 20:16   ` Heinrich Schuchardt
2014-10-27 16:11     ` Sergey "Shnatsel" Davidoff
2014-10-27  9:23   ` Pavel Machek
2014-10-27 16:02     ` Sergey "Shnatsel" Davidoff
2014-10-31  9:36       ` Jan Kara
2014-11-03 18:21         ` Heinrich Schuchardt
2014-11-04  9:28           ` Jan Kara
2014-11-04 19:55             ` Heinrich Schuchardt
2014-11-05 17:18               ` Jan Kara
2014-10-21 17:04 ` John Stultz
2014-10-21 17:14   ` Bastien Nocera
2014-10-21 18:00     ` John Stultz
2014-10-21 18:09       ` Bastien Nocera
2014-10-21 19:10         ` John Stultz
2014-10-27 14:19           ` Bastien Nocera
2014-10-27 16:56             ` John Stultz
2014-10-28 22:57               ` One Thousand Gnomes
2014-10-30 14:41                 ` Bastien Nocera
2014-10-30 23:39                   ` One Thousand Gnomes
2014-10-31 14:03                     ` Bastien Nocera
2014-11-03 14:17                       ` One Thousand Gnomes
2014-10-30 14:35               ` Bastien Nocera
2014-10-30 23:25                 ` One Thousand Gnomes
2014-10-31 14:01                   ` Bastien Nocera
2014-11-21 19:08             ` Pavel Machek
2014-10-21 19:23         ` Andy Lutomirski
2014-10-22 17:04         ` Zygo Blaxell
2014-10-27 14:28           ` Bastien Nocera
2014-10-27 20:59             ` Zygo Blaxell
2014-10-28 12:36               ` Bastien Nocera
2014-10-28 14:36                 ` John Stultz
2014-10-31 13:54                   ` Bastien Nocera
2014-10-31 17:38                     ` John Stultz
     [not found]                 ` <CANszf4gaozN9YHzxUToRP9CaA1VVEV9vcz_X6LDL1zW3fH4Fow@mail.gmail.com>
2014-10-28 16:41                   ` Fwd: " Rogelio Serrano
2014-10-27  9:28         ` Pavel Machek
2014-10-27 14:31           ` Bastien Nocera
2014-10-28 18:50             ` suspend to partition " Pavel Machek
2014-10-30 13:57               ` Bastien Nocera
2014-10-29 19:19             ` Andy Lutomirski
2014-10-29 20:26               ` Theodore Ts'o
2014-10-29 21:16                 ` Pavel Machek
2014-10-30 14:45                   ` Bastien Nocera
2014-10-30 14:53                     ` Andy Lutomirski
2014-10-30 15:07                       ` Bastien Nocera
2014-10-30 18:23                         ` Pavel Machek
2014-10-31 13:57                           ` Bastien Nocera
2014-10-30 15:05                     ` Theodore Ts'o
2014-10-30 15:15                       ` Bastien Nocera
2014-10-30 15:34                         ` Theodore Ts'o
2014-10-30 15:36                           ` Bastien Nocera
2014-10-30 17:41                         ` Pavel Machek
2014-10-31 13:59                           ` Bastien Nocera
2014-10-30 23:21                         ` One Thousand Gnomes
2014-10-30 23:19                       ` One Thousand Gnomes
2014-10-30 14:42                 ` Bastien Nocera
2014-10-28 22:42           ` One Thousand Gnomes
2014-10-21 18:24     ` Geert Uytterhoeven
2014-10-27 14:20       ` Bastien Nocera
2014-10-27 15:31         ` Geert Uytterhoeven
2014-10-27 15:44           ` Bastien Nocera
2015-04-30 16:25   ` Bastien Nocera
2015-04-30 17:10     ` John Stultz
2015-04-30 17:23       ` Olof Johansson
2015-04-30 18:54         ` Chirantan Ekbote
2015-05-01  9:02           ` Tomeu Vizoso
2015-05-04 22:19             ` Rafael J. Wysocki
2015-05-05  6:05               ` Tomeu Vizoso
2015-05-05 12:31                 ` Rafael J. Wysocki
2015-05-07 16:54                   ` One Thousand Gnomes
2015-05-07 21:03                     ` Rafael J. Wysocki
2015-05-08  7:09                       ` Tomeu Vizoso
2015-05-04 22:12           ` Rafael J. Wysocki
2015-05-04 23:30             ` Chirantan Ekbote
2015-05-05 10:46               ` Bastien Nocera [this message]
2015-05-05 19:22                 ` Chirantan Ekbote
2015-05-06 12:41                   ` Bastien Nocera
2015-05-05 14:39               ` Alan Stern
2015-05-05 14:39                 ` Alan Stern
2015-05-05 17:58                 ` Chirantan Ekbote
2015-05-05 19:35                   ` Alan Stern
2015-05-05 19:35                     ` Alan Stern
2015-05-05 20:58                     ` Chirantan Ekbote
2015-05-05 23:56                       ` Rafael J. Wysocki
2015-05-05 23:38                         ` David Lang
2015-05-05 23:51                           ` Rafael J. Wysocki
2015-05-07 17:03                       ` One Thousand Gnomes
2015-05-07 18:21                         ` Chirantan Ekbote
2015-05-05 23:47               ` Rafael J. Wysocki
2015-05-06 17:40                 ` Chirantan Ekbote
2015-05-07 23:19                   ` Rafael J. Wysocki
2015-05-11 22:12                 ` Pavel Machek
2015-05-12  0:45                   ` Rafael J. Wysocki
2014-10-21 19:28 ` Andy Lutomirski
2014-10-21 19:43   ` Al Viro
2014-10-21 19:47     ` Andy Lutomirski
2014-10-27 13:55   ` Bastien Nocera
2014-10-27 15:12     ` Andy Lutomirski
2014-10-27 15:45       ` Bastien Nocera
2014-10-27 16:08         ` Andy Lutomirski
2014-10-27 16:09           ` Bastien Nocera
2014-10-27 16:22             ` Al Viro

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=1430822800.7954.5.camel@hadess.net \
    --to=hadess@hadess.net \
    --cc=chirantan@chromium.org \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=olof@lixom.net \
    --cc=rjw@rjwysocki.net \
    --cc=snanda@chromium.org \
    --cc=tomeu.vizoso@collabora.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.