mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Saravana Kannan <saravanak@google.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <len.brown@intel.com>,  Pavel Machek <pavel@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Danilo Krummrich <dakr@kernel.org>
Cc: Saravana Kannan <saravanak@google.com>,
	kernel-team@android.com, linux-pm@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: [RFC PATCH v1] PM: wakeup: Provide interface for userspace to abort suspend
Date: Fri, 18 Jul 2025 00:18:37 -0700	[thread overview]
Message-ID: <20250718071842.2483378-1-saravanak@google.com> (raw)

Once suspend starts, it can take a while before file system sync
finishes and all the userspace threads are frozen. During this time,
there can be events that originate in userspace that would require the
suspend to be aborted.

The only way to abort suspend from userspace as of today is to grab
and release a kernel wakelock using the /sys/power/wake_lock and
/sys/power/wake_unlock files. This has the disadvantage of:

* Doing the useless work of creating and destroying wakelocks.
* If the userspace entity crashes after the wake lock is created, we
  get a wake lock/memory leak.

To avoid all this and simplify the interface, this patch allows
canceling a suspend by writing UINT_MAX value to the
/sys/power/wakeup_count that is meant for tracking wakeup events.

Signed-off-by: Saravana Kannan <saravanak@google.com>
---

Rafael,

If the idea looks good to you, I can also update Documentation and sent
it as a non-RFC patch. I'm not too tied on what file we use to trigger
an abort from userspace as long as it's possible.

Thanks,
Saravana

 drivers/base/power/wakeup.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index d1283ff1080b..9316de561bcc 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -1008,6 +1008,8 @@ bool pm_save_wakeup_count(unsigned int count)
 	if (cnt == count && inpr == 0) {
 		saved_count = count;
 		events_check_enabled = true;
+	} else if (cnt == UINT_MAX) {
+		pm_system_wakeup();
 	}
 	raw_spin_unlock_irqrestore(&events_lock, flags);
 	return events_check_enabled;
-- 
2.50.0.727.gbf7dc18ff4-goog


             reply	other threads:[~2025-07-18  7:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-18  7:18 Saravana Kannan [this message]
2025-07-18 22:11 ` Saravana Kannan
2025-07-21 19:51 ` Rafael J. Wysocki
2025-07-21 21:47   ` Saravana Kannan

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=20250718071842.2483378-1-saravanak@google.com \
    --to=saravanak@google.com \
    --cc=dakr@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-team@android.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=rafael@kernel.org \
    /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

all inboxes | Powered by JetHome®