From: mark gross <mgross@linux.intel.com>
To: "Arve Hjønnevåg" <arve@android.com>
Cc: swetland@google.com, linux-pm@lists.linux-foundation.org,
u.luckas@road.de, ncunningham@crca.org.au
Subject: Re: [PATCH 01/13] PM: Add wake lock api.
Date: Thu, 5 Feb 2009 14:51:58 -0800 [thread overview]
Message-ID: <20090205225158.GA19577@linux.intel.com> (raw)
In-Reply-To: <1233802226-23386-2-git-send-email-arve@android.com>
On Wed, Feb 04, 2009 at 06:50:14PM -0800, Arve Hjønnevåg wrote:
> Signed-off-by: Arve Hjønnevåg <arve@android.com>
> ---
> Documentation/power/wakelocks.txt | 91 ++++++++++++++++++++++++++++++++++++
> include/linux/wakelock.h | 92 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 183 insertions(+), 0 deletions(-)
> create mode 100644 Documentation/power/wakelocks.txt
> create mode 100755 include/linux/wakelock.h
>
> diff --git a/Documentation/power/wakelocks.txt b/Documentation/power/wakelocks.txt
> new file mode 100644
> index 0000000..219bb11
> --- /dev/null
> +++ b/Documentation/power/wakelocks.txt
> @@ -0,0 +1,91 @@
> +Wakelocks
> +=========
> +
> +A locked wakelock, depending on its type, prevents the system from entering
> +suspend or other low-power states. When creating a wakelock, you can select
> +if it prevents suspend or low-power idle states. If the type is set to
> +WAKE_LOCK_SUSPEND, the wakelock prevents a full system suspend. If the type
> +is WAKE_LOCK_IDLE, low-power states that cause large interrupt latencies, or
> +that disable a set of interrupts, will not be entered from idle until the
> +wakelocks are released. Unless the type is specified, this document refers
> +to wakelocks with the type set to WAKE_LOCK_SUSPEND.
How much of this can be implemented using a pm-qos approach?
> +
> +If the suspend operation has already started when locking a wakelock, it will
> +abort the suspend operation as long it has not already reached the suspend_late
> +stage. This means that locking a wakelock from an interrupt handler or a
> +freezeable thread always works, but if you lock a wakelock from a suspend_late
> +handler you must also return an error from that handler to abort suspend.
> +
> +Wakelocks can be used to allow user-space to decide which keys should wake the
> +full system up and turn the screen on. Use set_irq_wake or a platform specific
> +api to make sure the keypad interrupt wakes up the cpu. Once the keypad driver
> +has resumed, the sequence of events can look like this:
> +- The Keypad driver gets an interrupt. It then locks the keypad-scan wakelock
> + and starts scanning the keypad matrix.
> +- The keypad-scan code detects a key change and reports it to the input-event
> + driver.
> +- The input-event driver sees the key change, enqueues an event, and locks
> + the input-event-queue wakelock.
> +- The keypad-scan code detects that no keys are held and unlocks the
> + keypad-scan wakelock.
> +- The user-space input-event thread returns from select/poll, locks the
> + process-input-events wakelock and then calls read in the input-event device.
> +- The input-event driver dequeues the key-event and, since the queue is now
> + empty, it unlocks the input-event-queue wakelock.
> +- The user-space input-event thread returns from read. It determines that the
> + key should not wake up the full system, releases the process-input-events
> + wakelock and calls select or poll.
> +
> + Key pressed Key released
> + | |
> +keypad-scan ++++++++++++++++++
> +input-event-queue +++ +++
> +process-input-events +++ +++
> +
This feels a lot like operating points implemented as a collection of
product specific binary locks. How could this be generalized to be less
application specific?
> +
> +Driver API
> +==========
> +
> +A driver can use the wakelock api by adding a wakelock variable to its state
> +and calling wake_lock_init. For instance:
> +struct state {
> + struct wakelock wakelock;
> +}
> +
> +init() {
> + wake_lock_init(&state->wakelock, WAKE_LOCK_SUSPEND, "wakelockname");
> +}
> +
> +Before freeing the memory, wake_lock_destroy must be called:
> +
> +uninit() {
> + wake_lock_destroy(&state->wakelock);
> +}
> +
> +When the driver determines that it needs to run (usually in an interrupt
> +handler) it calls wake_lock:
> + wake_lock(&state->wakelock);
um, if a driver grabs the wakelock for another device that is sleeping
how will it know when that sleeping device is ready to be used? Is
wake_lock going to block until the dives its locking is in a good power
state? (I'm guessing yes) Is doing this in the context of and IRQ a
good idea?
> +
> +When it no longer needs to run it calls wake_unlock:
> + wake_unlock(&state->wakelock);
> +
> +It can also call wake_lock_timeout to release the wakelock after a delay:
> + wake_lock_timeout(&state->wakelock, HZ);
Timer?
> +
> +This works whether the wakelock is already held or not. It is useful if the
> +driver woke up other parts of the system that do not use wakelocks but
> +still need to run. Avoid this when possible, since it will waste power
> +if the timeout is long or may fail to finish needed work if the timeout is
> +short.
> +
> +
> +User-space API
> +==============
> +
> +Write "lockname" or "lockname timeout" to /sys/power/wake_lock lock and if
> +needed create a wakelock. The timeout here is specified nanoseconds.
> +Write "lockname" to /sys/power/wake_unlock to unlock a user wakelock.
> +
> +Do not use randomly generated wakelock names as there is no api to free
> +a user-space wakelock.
> +
> diff --git a/include/linux/wakelock.h b/include/linux/wakelock.h
> new file mode 100755
> index 0000000..b17e993
> --- /dev/null
> +++ b/include/linux/wakelock.h
> @@ -0,0 +1,92 @@
> +/* include/linux/wakelock.h
> + *
> + * Copyright (C) 2007-2008 Google, Inc.
> + *
> + * This software is licensed under the terms of the GNU General Public
> + * License version 2, as published by the Free Software Foundation, and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#ifndef _LINUX_WAKELOCK_H
> +#define _LINUX_WAKELOCK_H
> +
> +#include <linux/list.h>
> +#include <linux/ktime.h>
> +
> +/* A wake_lock prevents the system from entering suspend or other low power
> + * states when active. If the type is set to WAKE_LOCK_SUSPEND, the wake_lock
> + * prevents a full system suspend. If the type is WAKE_LOCK_IDLE, low power
> + * states that cause large interrupt latencies or that disable a set of
> + * interrupts will not entered from idle until the wake_locks are released.
> + */
> +
> +enum {
> + WAKE_LOCK_SUSPEND, /* Prevent suspend */
> + WAKE_LOCK_IDLE, /* Prevent low power idle */
> + WAKE_LOCK_TYPE_COUNT
> +};
> +
> +struct wake_lock {
> +#ifdef CONFIG_HAS_WAKELOCK
Shouldn't this #ifdef be in the files using wake_lock.h? If
!CONFIG_HAS_WAKELOCK then should all the definitions here not be parsed
at compile time?
> + struct list_head link;
> + int flags;
> + const char *name;
> + unsigned long expires;
> +#ifdef CONFIG_WAKELOCK_STAT
> + struct {
> + int count;
> + int expire_count;
> + int wakeup_count;
> + ktime_t total_time;
> + ktime_t prevent_suspend_time;
> + ktime_t max_time;
> + ktime_t last_time;
> + } stat;
> +#endif
> +#endif
> +};
> +
> +#ifdef CONFIG_HAS_WAKELOCK
> +
> +void wake_lock_init(struct wake_lock *lock, int type, const char *name);
> +void wake_lock_destroy(struct wake_lock *lock);
> +void wake_lock(struct wake_lock *lock);
> +void wake_lock_timeout(struct wake_lock *lock, long timeout);
> +void wake_unlock(struct wake_lock *lock);
> +
> +/* wake_lock_active returns a non-zero value if the wake_lock is currently
> + * locked. If the wake_lock has a timeout, it does not check the timeout,
> + * but if the timeout had already expired when it was checked elsewhere
> + * this function will return 0.
> + */
> +int wake_lock_active(struct wake_lock *lock);
> +
> +/* has_wake_lock returns 0 if no wake locks of the specified type are active,
> + * and non-zero if one or more wake locks are held. Specifically it returns
> + * -1 if one or more wake locks with no timeout are active or the
> + * number of jiffies until all active wake locks time out.
> + */
> +long has_wake_lock(int type);
Type? or class? What is this type concept? Should we have some strong
typing to the enum list above or at least a comment on what are the
types that are valid to call this API with?
> +
> +#else
> +
> +static inline void wake_lock_init(struct wake_lock *lock, int type,
> + const char *name) {}
> +static inline void wake_lock_destroy(struct wake_lock *lock) {}
> +static inline void wake_lock(struct wake_lock *lock) {}
> +static inline void wake_lock_timeout(struct wake_lock *lock, long timeout) {}
> +static inline void wake_unlock(struct wake_lock *lock) {}
> +
> +static inline int wake_lock_active(struct wake_lock *lock) { return 0; }
> +static inline long has_wake_lock(int type) { return 0; }
> +
> +#endif
I don't like these type of use of ifdef to no-op out API's do we really
need to do it this way?
> +
> +#endif
> +
> --
> 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-02-05 22:51 UTC|newest]
Thread overview: 192+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-05 2:50 [RFC][PATCH 00/11] Android PM extensions Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 01/13] PM: Add wake lock api Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 02/13] PM: Add early suspend api Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 03/13] PM: Implement wakelock api Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 04/13] PM: wakelock: Override wakelocks when using /sys/power/state Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 05/13] PM: Add option to disable /sys/power/state interface Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 06/13] PM: Implement early suspend api Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 07/13] PM: wakelock: Add /sys/power/request_state Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 08/13] PM: Add user-space wake lock api Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 09/13] PM: wakelock: Abort task freezing if a wake lock is held Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 10/13] PM: earlysuspend: Add console switch when user requested sleep state changes Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 11/13] PM: earlysuspend: Removing dependence on console Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 12/13] Input: Hold wake lock while event queue is not empty Arve Hjønnevåg
2009-02-05 2:50 ` [PATCH 13/13] ledtrig-sleep: Add led trigger for sleep debugging Arve Hjønnevåg
2009-02-05 9:08 ` [PATCH 12/13] Input: Hold wake lock while event queue is not empty Pavel Machek
2009-02-05 9:06 ` [PATCH 11/13] PM: earlysuspend: Removing dependence on console Pavel Machek
2009-02-05 9:42 ` Arve Hjønnevåg
2009-02-05 9:53 ` Pavel Machek
2009-02-05 9:03 ` [PATCH 10/13] PM: earlysuspend: Add console switch when user requested sleep state changes Pavel Machek
2009-02-05 9:37 ` Arve Hjønnevåg
2009-02-05 9:51 ` Pavel Machek
2009-02-05 10:54 ` Uli Luckas
2009-02-06 2:29 ` Arve Hjønnevåg
2009-02-08 22:02 ` Pavel Machek
2009-02-08 22:53 ` Arve Hjønnevåg
2009-02-08 22:58 ` Pavel Machek
2009-02-05 8:55 ` [PATCH 09/13] PM: wakelock: Abort task freezing if a wake lock is held Pavel Machek
2009-02-05 9:30 ` Arve Hjønnevåg
2009-02-05 9:49 ` Pavel Machek
2009-02-05 9:58 ` Arve Hjønnevåg
2009-02-05 10:02 ` Pavel Machek
2009-02-05 10:08 ` Arve Hjønnevåg
2009-02-06 3:42 ` Arve Hjønnevåg
2009-02-08 23:00 ` Pavel Machek
2009-02-06 0:35 ` mark gross
2009-02-05 8:53 ` [PATCH 08/13] PM: Add user-space wake lock api Pavel Machek
2009-02-05 8:52 ` [PATCH 07/13] PM: wakelock: Add /sys/power/request_state Pavel Machek
2009-02-05 9:25 ` Arve Hjønnevåg
2009-02-05 9:27 ` Pavel Machek
2009-02-07 22:54 ` Rafael J. Wysocki
2009-02-06 0:18 ` [PATCH 06/13] PM: Implement early suspend api mark gross
2009-02-07 22:47 ` Rafael J. Wysocki
2009-02-08 2:32 ` Benjamin Herrenschmidt
2009-02-08 13:33 ` Rafael J. Wysocki
2009-02-05 9:17 ` [PATCH 05/13] PM: Add option to disable /sys/power/state interface Pavel Machek
2009-02-07 22:37 ` Rafael J. Wysocki
2009-02-08 10:33 ` Pavel Machek
2009-02-08 13:50 ` Rafael J. Wysocki
2009-02-08 14:04 ` Brian Swetland
2009-02-08 21:06 ` Pavel Machek
2009-02-08 23:41 ` Rafael J. Wysocki
2009-02-09 1:58 ` Uli Luckas
2009-02-10 0:09 ` Rafael J. Wysocki
2009-02-08 23:40 ` Rafael J. Wysocki
2009-02-08 23:58 ` Arve Hjønnevåg
2009-02-09 0:26 ` Rafael J. Wysocki
2009-02-09 1:35 ` Arve Hjønnevåg
2009-02-09 1:53 ` Brian Swetland
2009-02-09 8:58 ` Pavel Machek
2009-02-09 13:31 ` Brian Swetland
2009-02-10 11:19 ` Pavel Machek
2009-02-09 9:15 ` Pavel Machek
2009-02-09 3:07 ` Alan Stern
2009-02-11 22:26 ` Rafael J. Wysocki
2009-02-09 9:09 ` Pavel Machek
2009-02-12 11:16 ` Matthew Garrett
2009-02-08 21:04 ` Pavel Machek
2009-02-08 21:40 ` Alan Stern
2009-02-08 23:00 ` Arve Hjønnevåg
2009-02-08 23:03 ` Pavel Machek
2009-02-09 0:31 ` Rafael J. Wysocki
2009-02-09 2:11 ` Uli Luckas
2009-02-09 2:24 ` Arve Hjønnevåg
2009-02-09 2:56 ` Uli Luckas
2009-02-09 9:01 ` Pavel Machek
2009-02-10 0:17 ` Rafael J. Wysocki
2009-02-10 9:13 ` Pavel Machek
2009-02-10 14:18 ` Rafael J. Wysocki
2009-02-08 23:41 ` Pavel Machek
2009-02-08 23:44 ` Rafael J. Wysocki
2009-02-08 23:44 ` Rafael J. Wysocki
2009-02-07 22:31 ` [PATCH 04/13] PM: wakelock: Override wakelocks when using /sys/power/state Rafael J. Wysocki
2009-02-05 9:16 ` [PATCH 03/13] PM: Implement wakelock api Pavel Machek
2009-02-05 15:24 ` Alan Stern
2009-02-06 0:10 ` mark gross
2009-02-06 0:38 ` Arve Hjønnevåg
2009-02-07 0:33 ` mark gross
2009-02-07 0:47 ` Arve Hjønnevåg
2009-02-09 18:00 ` mark gross
2009-02-10 20:24 ` Pavel Machek
2009-02-07 22:27 ` Rafael J. Wysocki
2009-02-11 2:52 ` Arve Hjønnevåg
2009-02-05 9:14 ` [PATCH 02/13] PM: Add early suspend api Pavel Machek
2009-02-05 23:26 ` mark gross
2009-02-06 9:33 ` Uli Luckas
2009-02-06 23:26 ` Arve Hjønnevåg
2009-02-07 20:53 ` Rafael J. Wysocki
2009-02-07 23:34 ` Arve Hjønnevåg
2009-02-08 20:59 ` Pavel Machek
2009-02-08 23:59 ` Rafael J. Wysocki
2009-02-05 9:11 ` [PATCH 01/13] PM: Add wake lock api Pavel Machek
2009-02-06 0:28 ` Arve Hjønnevåg
2009-02-06 9:45 ` Uli Luckas
2009-02-08 21:30 ` Pavel Machek
2009-02-08 23:11 ` Arve Hjønnevåg
2009-02-09 9:06 ` Pavel Machek
2009-02-08 22:17 ` non-racy examples, please (was Re: [PATCH 01/13] PM: Add wake lock api.) Pavel Machek
2009-02-08 22:40 ` Arve Hjønnevåg
2009-02-08 23:14 ` Pavel Machek
2009-02-08 23:35 ` Arve Hjønnevåg
2009-02-10 11:15 ` Pavel Machek
2009-02-11 3:12 ` Arve Hjønnevåg
2009-02-09 1:49 ` non-racy examples, please (was Re: [PATCH 01/13] PM: Add wake lock api. ) Uli Luckas
2009-02-10 11:17 ` non-racy examples, please (was Re: [PATCH 01/13] PM: Add wake lock?api.) Pavel Machek
2009-02-10 12:10 ` Woodruff, Richard
2009-02-10 13:14 ` Pavel Machek
2009-02-10 13:20 ` Woodruff, Richard
2009-02-10 13:42 ` Brian Swetland
2009-02-10 12:35 ` Uli Luckas
2009-02-06 1:32 ` [PATCH 01/13] PM: Add wake lock api mark gross
2009-02-05 22:51 ` mark gross [this message]
2009-02-06 0:13 ` Arve Hjønnevåg
2009-02-10 20:25 ` Pavel Machek
2009-02-11 2:11 ` Arve Hjønnevåg
2009-02-11 4:47 ` Brian Swetland
2009-02-11 8:40 ` Uli Luckas
2009-02-11 14:58 ` Alan Stern
2009-02-11 15:45 ` Rafael J. Wysocki
2009-02-08 22:57 ` Pavel Machek
2009-02-11 21:37 ` Pavel Machek
2009-02-11 22:05 ` Alan Stern
2009-02-11 23:55 ` Arve Hjønnevåg
2009-02-12 18:47 ` mark gross
2009-02-07 18:56 ` Rafael J. Wysocki
2009-02-07 22:51 ` Arve Hjønnevåg
2009-02-07 23:25 ` Rafael J. Wysocki
2009-02-08 0:20 ` Arve Hjønnevåg
2009-02-08 21:21 ` Pavel Machek
2009-02-09 0:03 ` Rafael J. Wysocki
2009-02-09 0:15 ` Rafael J. Wysocki
2009-02-09 2:03 ` Arve Hjønnevåg
2009-02-11 22:23 ` Rafael J. Wysocki
2009-02-11 23:42 ` Arve Hjønnevåg
2009-02-12 22:22 ` Rafael J. Wysocki
2009-02-12 23:42 ` Woodruff, Richard
2009-02-13 1:10 ` Matthew Garrett
2009-02-13 2:21 ` Arve Hjønnevåg
2009-02-13 2:40 ` Nigel Cunningham
2009-02-13 3:17 ` Woodruff, Richard
2009-02-13 10:55 ` Uli Luckas
2009-02-13 14:06 ` Matthew Garrett
2009-02-13 14:24 ` Brian Swetland
2009-02-13 14:37 ` Matthew Garrett
2009-02-13 14:46 ` Brian Swetland
2009-02-13 15:07 ` Matthew Garrett
2009-02-13 22:52 ` Rafael J. Wysocki
2009-02-13 16:46 ` Uli Luckas
2009-02-13 17:05 ` Matthew Garrett
2009-02-13 18:13 ` Uli Luckas
2009-02-13 19:14 ` Matthew Garrett
2009-02-13 19:35 ` Uli Luckas
2009-02-13 16:49 ` Uli Luckas
2009-02-13 17:09 ` Matthew Garrett
2009-02-13 18:18 ` Uli Luckas
2009-02-27 13:18 ` Pavel Machek
2009-02-27 14:07 ` Uli Luckas
2009-02-27 20:32 ` Pavel Machek
2009-03-02 13:53 ` Uli Luckas
2009-03-03 14:02 ` Pavel Machek
2009-03-04 13:41 ` Uli Luckas
2009-03-04 14:00 ` Uli Luckas
2009-03-04 14:13 ` Pavel Machek
2009-03-04 14:34 ` Uli Luckas
2009-03-04 17:10 ` Pavel Machek
2009-03-05 17:42 ` Uli Luckas
2009-03-08 8:32 ` Pavel Machek
2009-03-08 12:34 ` Alan Stern
2009-02-13 23:36 ` Arve Hjønnevåg
2009-02-14 0:05 ` Matthew Garrett
2009-02-14 0:50 ` Arve Hjønnevåg
2009-02-14 1:06 ` Matthew Garrett
2009-02-14 1:33 ` Arve Hjønnevåg
2009-02-14 1:49 ` Matthew Garrett
2009-02-14 5:51 ` Arve Hjønnevåg
2009-02-14 20:44 ` Matthew Garrett
2009-02-26 15:04 ` Pavel Machek
2009-02-26 21:11 ` Arve Hjønnevåg
2009-02-26 21:36 ` Pavel Machek
2009-02-27 0:16 ` Arve Hjønnevåg
2009-02-27 9:56 ` Pavel Machek
2009-02-28 3:20 ` Arve Hjønnevåg
2009-02-06 23:51 ` [RFC][PATCH 00/11] Android PM extensions 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=20090205225158.GA19577@linux.intel.com \
--to=mgross@linux.intel.com \
--cc=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