Development discussion of WireGuard
 help / color / mirror / Atom feed
* [PATCH] pm/sleep: Add PM_USERSPACE_AUTOSLEEP Kconfig
@ 2022-06-30 19:12 Kalesh Singh
  2022-06-30 19:49 ` Jason A. Donenfeld
  0 siblings, 1 reply; 7+ messages in thread
From: Kalesh Singh @ 2022-06-30 19:12 UTC (permalink / raw)
  To: Jason, jstultz, paulmck, rostedt, rafael, hch
  Cc: saravanak, tjmercier, surenb, kernel-team, Kalesh Singh,
	Theodore Ts'o, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Len Brown, Pavel Machek, linux-kernel, wireguard,
	netdev, linux-pm

Systems that initiate frequent suspend/resume from userspace
can make the kernel aware by enabling PM_USERSPACE_AUTOSLEEP
config.

This allows for certain sleep-sensitive code (wireguard/rng) to
decide on what preparatory work should be performed (or not) in
their pm_notification callbacks.

This patch was prompted by the discussion at [1] which attempts
to remove CONFIG_ANDROID that currently guards these code paths.

[1] https://lore.kernel.org/r/20220629150102.1582425-1-hch@lst.de/

Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
 drivers/char/random.c          |  4 ++--
 drivers/net/wireguard/device.c |  3 ++-
 kernel/power/Kconfig           | 20 ++++++++++++++++++++
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index e3dd1dd3dd22..8c90f535d149 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -755,8 +755,8 @@ static int random_pm_notification(struct notifier_block *nb, unsigned long actio
 	spin_unlock_irqrestore(&input_pool.lock, flags);
 
 	if (crng_ready() && (action == PM_RESTORE_PREPARE ||
-	    (action == PM_POST_SUSPEND &&
-	     !IS_ENABLED(CONFIG_PM_AUTOSLEEP) && !IS_ENABLED(CONFIG_ANDROID)))) {
+	    (action == PM_POST_SUSPEND && !IS_ENABLED(CONFIG_PM_AUTOSLEEP) &&
+	     !IS_ENABLED(CONFIG_PM_USERSPACE_AUTOSLEEP)))) {
 		crng_reseed();
 		pr_notice("crng reseeded on system resumption\n");
 	}
diff --git a/drivers/net/wireguard/device.c b/drivers/net/wireguard/device.c
index aa9a7a5970fd..d58e9f818d3b 100644
--- a/drivers/net/wireguard/device.c
+++ b/drivers/net/wireguard/device.c
@@ -69,7 +69,8 @@ static int wg_pm_notification(struct notifier_block *nb, unsigned long action, v
 	 * its normal operation rather than as a somewhat rare event, then we
 	 * don't actually want to clear keys.
 	 */
-	if (IS_ENABLED(CONFIG_PM_AUTOSLEEP) || IS_ENABLED(CONFIG_ANDROID))
+	if (IS_ENABLED(CONFIG_PM_AUTOSLEEP) ||
+	    IS_ENABLED(CONFIG_PM_USERSPACE_AUTOSLEEP))
 		return 0;
 
 	if (action != PM_HIBERNATION_PREPARE && action != PM_SUSPEND_PREPARE)
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index a12779650f15..60a1d3051cc7 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -143,6 +143,26 @@ config PM_AUTOSLEEP
 	Allow the kernel to trigger a system transition into a global sleep
 	state automatically whenever there are no active wakeup sources.
 
+config PM_USERSPACE_AUTOSLEEP
+	bool "Userspace opportunistic sleep"
+	depends on PM_SLEEP
+	help
+	Notify kernel of aggressive userspace autosleep power management policy.
+
+	This option changes the behavior of various sleep-sensitive code to deal
+	with frequent userspace-initiated transitions into a global sleep state.
+
+	Saying Y here, disables code paths that most users really should keep
+	enabled. In particular, only enable this if it is very common to be
+	asleep/awake for very short periods of time (<= 2 seconds).
+
+	Only platforms, such as Android, that implement opportunistic sleep from
+	a userspace power manager service should enable this option; and not
+	other machines. Therefore, you should say N here, unless you are
+	extremely certain that this is what you want. The option otherwise has
+	bad, undesirable effects, and should not be enabled just for fun.
+
+
 config PM_WAKELOCKS
 	bool "User space wakeup sources interface"
 	depends on PM_SLEEP

base-commit: 03c765b0e3b4cb5063276b086c76f7a612856a9a
-- 
2.37.0.rc0.161.g10f37bed90-goog


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

* Re: [PATCH] pm/sleep: Add PM_USERSPACE_AUTOSLEEP Kconfig
  2022-06-30 19:12 [PATCH] pm/sleep: Add PM_USERSPACE_AUTOSLEEP Kconfig Kalesh Singh
@ 2022-06-30 19:49 ` Jason A. Donenfeld
  2022-06-30 20:41   ` Kalesh Singh
  2022-07-01  8:38   ` Greg KH
  0 siblings, 2 replies; 7+ messages in thread
From: Jason A. Donenfeld @ 2022-06-30 19:49 UTC (permalink / raw)
  To: Kalesh Singh
  Cc: jstultz, paulmck, rostedt, rafael, hch, saravanak, tjmercier,
	surenb, kernel-team, Theodore Ts'o, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Len Brown,
	Pavel Machek, linux-kernel, wireguard, netdev, linux-pm

Hi Kalesh,

On Thu, Jun 30, 2022 at 07:12:29PM +0000, Kalesh Singh wrote:
> Systems that initiate frequent suspend/resume from userspace
> can make the kernel aware by enabling PM_USERSPACE_AUTOSLEEP
> config.
> 
> This allows for certain sleep-sensitive code (wireguard/rng) to
> decide on what preparatory work should be performed (or not) in
> their pm_notification callbacks.
> 
> This patch was prompted by the discussion at [1] which attempts
> to remove CONFIG_ANDROID that currently guards these code paths.
> 
> [1] https://lore.kernel.org/r/20220629150102.1582425-1-hch@lst.de/
> 
> Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com>
> Signed-off-by: Kalesh Singh <kaleshsingh@google.com>

Thanks, looks good to me. Do you have a corresponding Gerrit link to the
change adding this to the base Android kernel config? If so, have my
Ack:

    Acked-by: Jason A. Donenfeld <Jason@zx2c4.com>

Jason

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

* Re: [PATCH] pm/sleep: Add PM_USERSPACE_AUTOSLEEP Kconfig
  2022-06-30 19:49 ` Jason A. Donenfeld
@ 2022-06-30 20:41   ` Kalesh Singh
  2022-06-30 21:14     ` Jason A. Donenfeld
  2022-07-01  8:38   ` Greg KH
  1 sibling, 1 reply; 7+ messages in thread
From: Kalesh Singh @ 2022-06-30 20:41 UTC (permalink / raw)
  To: Jason A. Donenfeld
  Cc: John Stultz, Paul E. McKenney, Steven Rostedt, Rafael J. Wysocki,
	Christoph Hellwig, Saravana Kannan, T.J. Mercier,
	Suren Baghdasaryan, Cc: Android Kernel, Theodore Ts'o,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Len Brown, Pavel Machek, LKML, wireguard, netdev, linux-pm

On Thu, Jun 30, 2022 at 12:49 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
>
> Hi Kalesh,
>
> On Thu, Jun 30, 2022 at 07:12:29PM +0000, Kalesh Singh wrote:
> > Systems that initiate frequent suspend/resume from userspace
> > can make the kernel aware by enabling PM_USERSPACE_AUTOSLEEP
> > config.
> >
> > This allows for certain sleep-sensitive code (wireguard/rng) to
> > decide on what preparatory work should be performed (or not) in
> > their pm_notification callbacks.
> >
> > This patch was prompted by the discussion at [1] which attempts
> > to remove CONFIG_ANDROID that currently guards these code paths.
> >
> > [1] https://lore.kernel.org/r/20220629150102.1582425-1-hch@lst.de/
> >
> > Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com>
> > Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
>
> Thanks, looks good to me. Do you have a corresponding Gerrit link to the
> change adding this to the base Android kernel config? If so, have my
> Ack:
>
>     Acked-by: Jason A. Donenfeld <Jason@zx2c4.com>

Hi Jason,

Our latest supported kernels in Android are based on 5.15 so the
config change isn't yet needed. Once there are newer versions with the
CONFIG_ANDROID removed I will add this to the defconfig.

Thanks,
Kalesh

>
> Jason
>
> --
> To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com.
>

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

* Re: [PATCH] pm/sleep: Add PM_USERSPACE_AUTOSLEEP Kconfig
  2022-06-30 20:41   ` Kalesh Singh
@ 2022-06-30 21:14     ` Jason A. Donenfeld
  2022-06-30 22:02       ` Kalesh Singh
  0 siblings, 1 reply; 7+ messages in thread
From: Jason A. Donenfeld @ 2022-06-30 21:14 UTC (permalink / raw)
  To: Kalesh Singh
  Cc: John Stultz, Paul E. McKenney, Steven Rostedt, Rafael J. Wysocki,
	Christoph Hellwig, Saravana Kannan, T.J. Mercier,
	Suren Baghdasaryan, Cc: Android Kernel, Theodore Ts'o,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Len Brown, Pavel Machek, LKML, wireguard, netdev, linux-pm

On Thu, Jun 30, 2022 at 01:41:40PM -0700, Kalesh Singh wrote:
> Our latest supported kernels in Android are based on 5.15 so the
> config change isn't yet needed. Once there are newer versions with the
> CONFIG_ANDROID removed I will add this to the defconfig.

Okay. It might be still worth getting something uploaded to gerrit so
that it's easy to remember and submit whenever the time comes.

Also, what about android running on mainline? Where does that base
config live?

Jason

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

* Re: [PATCH] pm/sleep: Add PM_USERSPACE_AUTOSLEEP Kconfig
  2022-06-30 21:14     ` Jason A. Donenfeld
@ 2022-06-30 22:02       ` Kalesh Singh
  2022-06-30 22:08         ` Jason A. Donenfeld
  0 siblings, 1 reply; 7+ messages in thread
From: Kalesh Singh @ 2022-06-30 22:02 UTC (permalink / raw)
  To: Jason A. Donenfeld
  Cc: John Stultz, Paul E. McKenney, Steven Rostedt, Rafael J. Wysocki,
	Christoph Hellwig, Saravana Kannan, T.J. Mercier,
	Suren Baghdasaryan, Cc: Android Kernel, Theodore Ts'o,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Len Brown, Pavel Machek, LKML, wireguard, netdev, linux-pm

On Thu, Jun 30, 2022 at 2:14 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
>
> On Thu, Jun 30, 2022 at 01:41:40PM -0700, Kalesh Singh wrote:
> > Our latest supported kernels in Android are based on 5.15 so the
> > config change isn't yet needed. Once there are newer versions with the
> > CONFIG_ANDROID removed I will add this to the defconfig.
>
> Okay. It might be still worth getting something uploaded to gerrit so
> that it's easy to remember and submit whenever the time comes.
>
> Also, what about android running on mainline? Where does that base
> config live?

I've uploaded the changes on android-mainline [1]. We'll submit there
once the upstream changes are finalized.

[1] https://android-review.googlesource.com/c/kernel/common/+/2142693/1

Thanks,
Kalesh
>
> Jason

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

* Re: [PATCH] pm/sleep: Add PM_USERSPACE_AUTOSLEEP Kconfig
  2022-06-30 22:02       ` Kalesh Singh
@ 2022-06-30 22:08         ` Jason A. Donenfeld
  0 siblings, 0 replies; 7+ messages in thread
From: Jason A. Donenfeld @ 2022-06-30 22:08 UTC (permalink / raw)
  To: Kalesh Singh
  Cc: John Stultz, Paul E. McKenney, Steven Rostedt, Rafael J. Wysocki,
	Christoph Hellwig, Saravana Kannan, T.J. Mercier,
	Suren Baghdasaryan, Cc: Android Kernel, Theodore Ts'o,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Len Brown, Pavel Machek, LKML, wireguard, netdev, linux-pm

Hi Kalesh,

On Thu, Jun 30, 2022 at 03:02:46PM -0700, Kalesh Singh wrote:
> I've uploaded the changes on android-mainline [1]. We'll submit there
> once the upstream changes are finalized.
> 
> [1] https://android-review.googlesource.com/c/kernel/common/+/2142693/1

Excellent. I think everything is all set then, at least from my
perspective. There's a viable replacement for this usage of
CONFIG_ANDROID, there are patches ready to go both in the kernel and on
Android's configs, and now all we do is wait for Rafael. Great!

Maybe people will have opinions on the naming
(CONFIG_PM_RAPID_USERSPACE_AUTOSLEEP vs
CONFIG_PM_ANDROID_USERAPCE_AUTO_SLEEP vs what you have vs something else
vs who knows), but whatever is chosen seems probably fine, as this is a
pretty low key change since it can always be tweaked further later (it's
not ABI).

Jason

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

* Re: [PATCH] pm/sleep: Add PM_USERSPACE_AUTOSLEEP Kconfig
  2022-06-30 19:49 ` Jason A. Donenfeld
  2022-06-30 20:41   ` Kalesh Singh
@ 2022-07-01  8:38   ` Greg KH
  1 sibling, 0 replies; 7+ messages in thread
From: Greg KH @ 2022-07-01  8:38 UTC (permalink / raw)
  To: Jason A. Donenfeld
  Cc: Kalesh Singh, jstultz, paulmck, rostedt, rafael, hch, saravanak,
	tjmercier, surenb, kernel-team, Theodore Ts'o,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Len Brown, Pavel Machek, linux-kernel, wireguard, netdev,
	linux-pm

On Thu, Jun 30, 2022 at 09:49:24PM +0200, Jason A. Donenfeld wrote:
> Hi Kalesh,
> 
> On Thu, Jun 30, 2022 at 07:12:29PM +0000, Kalesh Singh wrote:
> > Systems that initiate frequent suspend/resume from userspace
> > can make the kernel aware by enabling PM_USERSPACE_AUTOSLEEP
> > config.
> > 
> > This allows for certain sleep-sensitive code (wireguard/rng) to
> > decide on what preparatory work should be performed (or not) in
> > their pm_notification callbacks.
> > 
> > This patch was prompted by the discussion at [1] which attempts
> > to remove CONFIG_ANDROID that currently guards these code paths.
> > 
> > [1] https://lore.kernel.org/r/20220629150102.1582425-1-hch@lst.de/
> > 
> > Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com>
> > Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
> 
> Thanks, looks good to me. Do you have a corresponding Gerrit link to the
> change adding this to the base Android kernel config? If so, have my
> Ack:
> 
>     Acked-by: Jason A. Donenfeld <Jason@zx2c4.com>

Cool, I'll queue this up and also the CONFIG_ANDROID removal into my
tree now, thanks all for working it out!

greg k-h

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

end of thread, other threads:[~2022-07-01  8:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 19:12 [PATCH] pm/sleep: Add PM_USERSPACE_AUTOSLEEP Kconfig Kalesh Singh
2022-06-30 19:49 ` Jason A. Donenfeld
2022-06-30 20:41   ` Kalesh Singh
2022-06-30 21:14     ` Jason A. Donenfeld
2022-06-30 22:02       ` Kalesh Singh
2022-06-30 22:08         ` Jason A. Donenfeld
2022-07-01  8:38   ` Greg KH

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).