From: "Arve Hjønnevåg" <arve@android.com>
To: linux-pm@lists.linux-foundation.org
Cc: ncunningham@crca.org.au, u.luckas@road.de, swetland@google.com
Subject: [PATCH 9/9] PM: suspend_block: Add timeout support to user-space suspend_blockers
Date: Tue, 5 May 2009 21:18:49 -0700 [thread overview]
Message-ID: <1241583529-5092-10-git-send-email-arve@android.com> (raw)
In-Reply-To: <1241583529-5092-9-git-send-email-arve@android.com>
This also allows a grace period to be set where suspend is blocked for a while
if a user-space suspend_blocker is destroyed while it was active.
Signed-off-by: Arve Hjønnevåg <arve@android.com>
---
Documentation/power/suspend-blockers.txt | 7 +++++++
include/linux/suspend_block_dev.h | 1 +
kernel/power/user_suspend_blocker.c | 23 +++++++++++++++++++++++
3 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/Documentation/power/suspend-blockers.txt b/Documentation/power/suspend-blockers.txt
index bc9d57a..3612794 100644
--- a/Documentation/power/suspend-blockers.txt
+++ b/Documentation/power/suspend-blockers.txt
@@ -112,6 +112,8 @@ then call:
To activate a suspend_blocker call:
ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK);
+or
+ ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK_TIMEOUT, ×pec_timeout);
To unblock call:
ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK);
@@ -119,3 +121,8 @@ To unblock call:
To destroy the suspend_blocker, close the device:
close(fd);
+A module parameter, unclean_exit_grace_period, can be set to allow servers
+some time to restart if they crash with an active suspend_blocker. If the
+process dies or the device is closed while the suspend_blocker is active, a
+suspend_blocker will be held for the number of seconds specified.
+
diff --git a/include/linux/suspend_block_dev.h b/include/linux/suspend_block_dev.h
index a7c0bf9..cff4943 100644
--- a/include/linux/suspend_block_dev.h
+++ b/include/linux/suspend_block_dev.h
@@ -20,6 +20,7 @@
#define SUSPEND_BLOCKER_IOCTL_INIT(len) _IOC(_IOC_WRITE, 's', 0, len)
#define SUSPEND_BLOCKER_IOCTL_BLOCK _IO('s', 1)
+#define SUSPEND_BLOCKER_IOCTL_BLOCK_TIMEOUT _IOW('s', 2, struct timespec)
#define SUSPEND_BLOCKER_IOCTL_UNBLOCK _IO('s', 3)
#endif
diff --git a/kernel/power/user_suspend_blocker.c b/kernel/power/user_suspend_blocker.c
index 69b3ddb..b853f66 100644
--- a/kernel/power/user_suspend_blocker.c
+++ b/kernel/power/user_suspend_blocker.c
@@ -26,7 +26,12 @@ enum {
static int debug_mask = DEBUG_FAILURE;
module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP);
+static int unclean_exit_grace_period;
+module_param_named(unclean_exit_grace_period, unclean_exit_grace_period, int,
+ S_IRUGO | S_IWUSR | S_IWGRP);
+
static DEFINE_MUTEX(ioctl_lock);
+static struct suspend_blocker unclean_exit_suspend_blocker;
struct user_suspend_blocker {
struct suspend_blocker blocker;
@@ -58,6 +63,8 @@ static long user_suspend_blocker_ioctl(struct file *file, unsigned int cmd,
{
void __user *arg = (void __user *)_arg;
struct user_suspend_blocker *bl;
+ struct timespec ts;
+ unsigned long timeout;
long ret;
mutex_lock(&ioctl_lock);
@@ -75,6 +82,15 @@ static long user_suspend_blocker_ioctl(struct file *file, unsigned int cmd,
suspend_block(&bl->blocker);
ret = 0;
break;
+ case SUSPEND_BLOCKER_IOCTL_BLOCK_TIMEOUT:
+ if (copy_from_user(&ts, arg, sizeof(ts))) {
+ ret = -EFAULT;
+ goto done;
+ }
+ timeout = timespec_to_jiffies(&ts);
+ suspend_block_timeout(&bl->blocker, timeout);
+ ret = 0;
+ break;
case SUSPEND_BLOCKER_IOCTL_UNBLOCK:
suspend_unblock(&bl->blocker);
ret = 0;
@@ -95,6 +111,10 @@ static int user_suspend_blocker_release(struct inode *inode, struct file *file)
struct user_suspend_blocker *bl = file->private_data;
if (!bl)
return 0;
+ if (suspend_blocker_is_active(&bl->blocker) &&
+ unclean_exit_grace_period)
+ suspend_block_timeout(&unclean_exit_suspend_blocker,
+ unclean_exit_grace_period * HZ);
suspend_blocker_destroy(&bl->blocker);
kfree(bl);
return 0;
@@ -113,12 +133,15 @@ struct miscdevice user_suspend_blocker_device = {
static int __init user_suspend_blocker_init(void)
{
+ suspend_blocker_init(&unclean_exit_suspend_blocker,
+ "user-unclean-exit");
return misc_register(&user_suspend_blocker_device);
}
static void __exit user_suspend_blocker_exit(void)
{
misc_deregister(&user_suspend_blocker_device);
+ suspend_blocker_destroy(&unclean_exit_suspend_blocker);
}
module_init(user_suspend_blocker_init);
--
1.6.1
_______________________________________________
linux-pm mailing list
linux-pm@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
next prev parent reply other threads:[~2009-05-06 4:18 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-06 4:18 [RFC][PATCH 0/9] Suspend block api (version 3) Arve Hjønnevåg
2009-05-06 4:18 ` [PATCH 1/9] PM: Add suspend block api Arve Hjønnevåg
2009-05-06 4:18 ` [PATCH 2/9] PM: suspend_block: Add driver to access suspend blockers from user-space Arve Hjønnevåg
2009-05-05 20:12 ` Pavel Machek
2009-05-07 1:42 ` Arve Hjønnevåg
2009-05-07 10:32 ` Pavel Machek
2009-05-08 0:43 ` Arve Hjønnevåg
2009-05-08 14:22 ` Rafael J. Wysocki
2009-05-09 0:38 ` Arve Hjønnevåg
2009-05-05 20:16 ` Pavel Machek
2009-05-07 1:31 ` Arve Hjønnevåg
2009-05-07 10:43 ` Pavel Machek
2009-05-06 4:18 ` [PATCH 3/9] PM: suspend_block: Abort task freezing if a suspend_blocker is active Arve Hjønnevåg
2009-05-05 19:57 ` Pavel Machek
2009-05-07 1:51 ` Arve Hjønnevåg
2009-05-07 10:41 ` Pavel Machek
2009-05-07 23:49 ` Arve Hjønnevåg
2009-05-08 1:06 ` Nigel Cunningham
2009-05-08 1:22 ` Arve Hjønnevåg
2009-05-08 1:35 ` Nigel Cunningham
2009-05-08 14:40 ` Rafael J. Wysocki
2009-05-08 22:27 ` Nigel Cunningham
2009-05-08 23:01 ` Rafael J. Wysocki
2009-05-09 0:12 ` Nigel Cunningham
2009-05-12 10:05 ` Pavel Machek
2009-05-12 16:55 ` Rafael J. Wysocki
2009-05-12 19:33 ` Pavel Machek
2009-05-12 10:04 ` Pavel Machek
2009-05-08 0:22 ` Rafael J. Wysocki
2009-05-06 4:18 ` [PATCH 4/9] Input: Block suspend while event queue is not empty Arve Hjønnevåg
2009-05-05 20:02 ` Pavel Machek
2009-05-07 1:57 ` Arve Hjønnevåg
2009-05-06 4:18 ` [PATCH 5/9] PM: suspend_block: Switch to list of active and inactive suspend blockers Arve Hjønnevåg
2009-05-06 4:18 ` [PATCH 6/9] PM: suspend_block: Add debugfs file Arve Hjønnevåg
2009-05-06 4:18 ` [PATCH 7/9] PM: suspend_block: Add suspend_blocker stats Arve Hjønnevåg
2009-05-06 4:18 ` [PATCH 8/9] PM: suspend_block: Add timeout support Arve Hjønnevåg
2009-05-06 4:18 ` Arve Hjønnevåg [this message]
2009-05-06 17:17 ` [RFC][PATCH 0/9] Suspend block api (version 3) Kevin Hilman
2009-05-07 22:42 ` Arve Hjønnevåg
2009-05-08 16:01 ` mark gross
2009-05-08 23:36 ` Kevin Hilman
2009-05-15 19:58 ` Pavel Machek
-- strict thread matches above, loose matches on Subject: below --
2009-04-30 3:09 [RFC][PATCH 0/9] Suspend block api (version 2) Arve Hjønnevåg
2009-04-30 3:10 ` [PATCH 1/9] PM: Add suspend block api Arve Hjønnevåg
2009-04-30 3:10 ` [PATCH 2/9] PM: suspend_block: Add driver to access suspend blockers from user-space Arve Hjønnevåg
2009-04-30 3:10 ` [PATCH 3/9] PM: suspend_block: Abort task freezing if a suspend_blocker is active Arve Hjønnevåg
2009-04-30 3:10 ` [PATCH 4/9] Input: Block suspend while event queue is not empty Arve Hjønnevåg
2009-04-30 3:10 ` [PATCH 5/9] PM: suspend_block: Switch to list of active and inactive suspend blockers Arve Hjønnevåg
2009-04-30 3:10 ` [PATCH 6/9] PM: suspend_block: Add debugfs file Arve Hjønnevåg
2009-04-30 3:10 ` [PATCH 7/9] PM: suspend_block: Add suspend_blocker stats Arve Hjønnevåg
2009-04-30 3:10 ` [PATCH 8/9] PM: suspend_block: Add timeout support Arve Hjønnevåg
2009-04-30 3:10 ` [PATCH 9/9] PM: suspend_block: Add timeout support to user-space suspend_blockers Arve Hjønnevåg
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=1241583529-5092-10-git-send-email-arve@android.com \
--to=arve@android.com \
--cc=linux-pm@lists.linux-foundation.org \
--cc=ncunningham@crca.org.au \
--cc=swetland@google.com \
--cc=u.luckas@road.de \
/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