From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Linux PM list <linux-pm@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
"Magnus Damm" <magnus.damm@gmail.com>,
markgross@thegnar.org, "Matthew Garrett" <mjg@redhat.com>,
"Greg KH" <gregkh@linuxfoundation.org>,
"Arve Hjønnevåg" <arve@android.com>,
"John Stultz" <john.stultz@linaro.org>,
"Brian Swetland" <swetland@google.com>,
"Neil Brown" <neilb@suse.de>,
"Alan Stern" <stern@rowland.harvard.edu>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>
Subject: [RFC][PATCH 7/8] PM / Sleep: Add "prevent autosleep time" statistics to wakeup sources
Date: Sun, 22 Apr 2012 23:24:04 +0200 [thread overview]
Message-ID: <201204222324.04848.rjw@sisk.pl> (raw)
In-Reply-To: <201204222319.02228.rjw@sisk.pl>
From: Rafael J. Wysocki <rjw@sisk.pl>
Android uses one wakelock statistics that is only necessary for
opportunistic sleep. Namely, the prevent_suspend_time field
accumulates the total time the given wakelock has been locked
while "automatic suspend" was enabled. Add an analogous field,
prevent_sleep_time, to wakeup sources and make it behave in a similar
way.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
Documentation/ABI/testing/sysfs-devices-power | 11 ++++
drivers/base/power/sysfs.c | 24 ++++++++++
drivers/base/power/wakeup.c | 61 ++++++++++++++++++++++++--
include/linux/pm_wakeup.h | 4 +
include/linux/suspend.h | 1
kernel/power/autosleep.c | 6 ++
6 files changed, 102 insertions(+), 5 deletions(-)
Index: linux/include/linux/pm_wakeup.h
===================================================================
--- linux.orig/include/linux/pm_wakeup.h
+++ linux/include/linux/pm_wakeup.h
@@ -34,6 +34,7 @@
* @total_time: Total time this wakeup source has been active.
* @max_time: Maximum time this wakeup source has been continuously active.
* @last_time: Monotonic clock when the wakeup source's was touched last time.
+ * @prevent_sleep_time: Total time this source has been preventing autosleep.
* @event_count: Number of signaled wakeup events.
* @active_count: Number of times the wakeup sorce was activated.
* @relax_count: Number of times the wakeup sorce was deactivated.
@@ -51,12 +52,15 @@ struct wakeup_source {
ktime_t total_time;
ktime_t max_time;
ktime_t last_time;
+ ktime_t start_prevent_time;
+ ktime_t prevent_sleep_time;
unsigned long event_count;
unsigned long active_count;
unsigned long relax_count;
unsigned long expire_count;
unsigned long wakeup_count;
bool active:1;
+ bool autosleep_enabled:1;
};
#ifdef CONFIG_PM_SLEEP
Index: linux/drivers/base/power/wakeup.c
===================================================================
--- linux.orig/drivers/base/power/wakeup.c
+++ linux/drivers/base/power/wakeup.c
@@ -380,6 +380,8 @@ static void wakeup_source_activate(struc
ws->active = true;
ws->active_count++;
ws->last_time = ktime_get();
+ if (ws->autosleep_enabled)
+ ws->start_prevent_time = ws->last_time;
/* Increment the counter of events in progress. */
cec = atomic_inc_return(&combined_event_count);
@@ -449,6 +451,17 @@ void pm_stay_awake(struct device *dev)
}
EXPORT_SYMBOL_GPL(pm_stay_awake);
+#ifdef CONFIG_PM_AUTOSLEEP
+static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now)
+{
+ ktime_t delta = ktime_sub(now, ws->start_prevent_time);
+ ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta);
+}
+#else
+static inline void update_prevent_sleep_time(struct wakeup_source *ws,
+ ktime_t now) {}
+#endif
+
/**
* wakup_source_deactivate - Mark given wakeup source as inactive.
* @ws: Wakeup source to handle.
@@ -490,6 +503,9 @@ static void wakeup_source_deactivate(str
del_timer(&ws->timer);
ws->timer_expires = 0;
+ if (ws->autosleep_enabled)
+ update_prevent_sleep_time(ws, now);
+
/*
* Increment the counter of registered wakeup events and decrement the
* couter of wakeup events in progress simultaneously.
@@ -720,6 +736,34 @@ bool pm_save_wakeup_count(unsigned int c
return events_check_enabled;
}
+#ifdef CONFIG_PM_AUTOSLEEP
+/**
+ * pm_wakep_autosleep_enabled - Modify autosleep_enabled for all wakeup sources.
+ * @enabled: Whether to set or to clear the autosleep_enabled flags.
+ */
+void pm_wakep_autosleep_enabled(bool set)
+{
+ struct wakeup_source *ws;
+ ktime_t now = ktime_get();
+
+ rcu_read_lock();
+ list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
+ spin_lock_irq(&ws->lock);
+ if (ws->autosleep_enabled != set) {
+ ws->autosleep_enabled = set;
+ if (ws->active) {
+ if (set)
+ ws->start_prevent_time = now;
+ else
+ update_prevent_sleep_time(ws, now);
+ }
+ }
+ spin_unlock_irq(&ws->lock);
+ }
+ rcu_read_unlock();
+}
+#endif /* CONFIG_PM_AUTOSLEEP */
+
static struct dentry *wakeup_sources_stats_dentry;
/**
@@ -735,28 +779,37 @@ static int print_wakeup_source_stats(str
ktime_t max_time;
unsigned long active_count;
ktime_t active_time;
+ ktime_t prevent_sleep_time;
int ret;
spin_lock_irqsave(&ws->lock, flags);
total_time = ws->total_time;
max_time = ws->max_time;
+ prevent_sleep_time = ws->prevent_sleep_time;
active_count = ws->active_count;
if (ws->active) {
- active_time = ktime_sub(ktime_get(), ws->last_time);
+ ktime_t now = ktime_get();
+
+ active_time = ktime_sub(now, ws->last_time);
total_time = ktime_add(total_time, active_time);
if (active_time.tv64 > max_time.tv64)
max_time = active_time;
+
+ if (ws->autosleep_enabled)
+ prevent_sleep_time = ktime_add(prevent_sleep_time,
+ ktime_sub(now, ws->start_prevent_time));
} else {
active_time = ktime_set(0, 0);
}
ret = seq_printf(m, "%-12s\t%lu\t\t%lu\t\t%lu\t\t%lu\t\t"
- "%lld\t\t%lld\t\t%lld\t\t%lld\n",
+ "%lld\t\t%lld\t\t%lld\t\t%lld\t\t%lld\n",
ws->name, active_count, ws->event_count,
ws->wakeup_count, ws->expire_count,
ktime_to_ms(active_time), ktime_to_ms(total_time),
- ktime_to_ms(max_time), ktime_to_ms(ws->last_time));
+ ktime_to_ms(max_time), ktime_to_ms(ws->last_time),
+ ktime_to_ms(prevent_sleep_time));
spin_unlock_irqrestore(&ws->lock, flags);
@@ -773,7 +826,7 @@ static int wakeup_sources_stats_show(str
seq_puts(m, "name\t\tactive_count\tevent_count\twakeup_count\t"
"expire_count\tactive_since\ttotal_time\tmax_time\t"
- "last_change\n");
+ "last_change\tprevent_suspend_time\n");
rcu_read_lock();
list_for_each_entry_rcu(ws, &wakeup_sources, entry)
Index: linux/include/linux/suspend.h
===================================================================
--- linux.orig/include/linux/suspend.h
+++ linux/include/linux/suspend.h
@@ -358,6 +358,7 @@ extern bool events_check_enabled;
extern bool pm_wakeup_pending(void);
extern bool pm_get_wakeup_count(unsigned int *count, bool block);
extern bool pm_save_wakeup_count(unsigned int count);
+extern void pm_wakep_autosleep_enabled(bool set);
static inline void lock_system_sleep(void)
{
Index: linux/drivers/base/power/sysfs.c
===================================================================
--- linux.orig/drivers/base/power/sysfs.c
+++ linux/drivers/base/power/sysfs.c
@@ -417,6 +417,27 @@ static ssize_t wakeup_last_time_show(str
}
static DEVICE_ATTR(wakeup_last_time_ms, 0444, wakeup_last_time_show, NULL);
+
+#ifdef CONFIG_PM_AUTOSLEEP
+static ssize_t wakeup_prevent_sleep_time_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ s64 msec = 0;
+ bool enabled = false;
+
+ spin_lock_irq(&dev->power.lock);
+ if (dev->power.wakeup) {
+ msec = ktime_to_ms(dev->power.wakeup->prevent_sleep_time);
+ enabled = true;
+ }
+ spin_unlock_irq(&dev->power.lock);
+ return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n");
+}
+
+static DEVICE_ATTR(wakeup_prevent_sleep_time_ms, 0444,
+ wakeup_prevent_sleep_time_show, NULL);
+#endif /* CONFIG_PM_AUTOSLEEP */
#endif /* CONFIG_PM_SLEEP */
#ifdef CONFIG_PM_ADVANCED_DEBUG
@@ -511,6 +532,9 @@ static struct attribute *wakeup_attrs[]
&dev_attr_wakeup_total_time_ms.attr,
&dev_attr_wakeup_max_time_ms.attr,
&dev_attr_wakeup_last_time_ms.attr,
+#ifdef CONFIG_PM_AUTOSLEEP
+ &dev_attr_wakeup_prevent_sleep_time_ms.attr,
+#endif
#endif
NULL,
};
Index: linux/Documentation/ABI/testing/sysfs-devices-power
===================================================================
--- linux.orig/Documentation/ABI/testing/sysfs-devices-power
+++ linux/Documentation/ABI/testing/sysfs-devices-power
@@ -158,6 +158,17 @@ Description:
not enabled to wake up the system from sleep states, this
attribute is not present.
+What: /sys/devices/.../power/wakeup_prevent_sleep_time_ms
+Date: February 2012
+Contact: Rafael J. Wysocki <rjw@sisk.pl>
+Description:
+ The /sys/devices/.../wakeup_prevent_sleep_time_ms attribute
+ contains the total time the device has been preventing
+ opportunistic transitions to sleep states from occuring.
+ This attribute is read-only. If the device is not enabled to
+ wake up the system from sleep states, this attribute is not
+ present.
+
What: /sys/devices/.../power/autosuspend_delay_ms
Date: September 2010
Contact: Alan Stern <stern@rowland.harvard.edu>
Index: linux/kernel/power/autosleep.c
===================================================================
--- linux.orig/kernel/power/autosleep.c
+++ linux/kernel/power/autosleep.c
@@ -91,8 +91,12 @@ int pm_autosleep_set_state(suspend_state
__pm_relax(autosleep_ws);
- if (state > PM_SUSPEND_ON)
+ if (state > PM_SUSPEND_ON) {
+ pm_wakep_autosleep_enabled(true);
queue_up_suspend_work();
+ } else {
+ pm_wakep_autosleep_enabled(false);
+ }
mutex_unlock(&autosleep_lock);
return 0;
next prev parent reply other threads:[~2012-04-22 21:21 UTC|newest]
Thread overview: 129+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-07 1:00 [RFC][PATCH 0/8] PM: Implement autosleep and "wake locks" Rafael J. Wysocki
2012-02-07 1:01 ` [PATCH 1/8] PM / Sleep: Initialize wakeup source locks in wakeup_source_add() Rafael J. Wysocki
2012-02-07 22:29 ` John Stultz
2012-02-07 22:41 ` Rafael J. Wysocki
2012-02-07 1:03 ` [PATCH 2/8] PM / Sleep: Do not check wakeup too often in try_to_freeze_tasks() Rafael J. Wysocki
2012-02-07 1:03 ` [PATCH 3/8] PM / Sleep: Look for wakeup events in later stages of device suspend Rafael J. Wysocki
2012-02-07 1:04 ` [PATCH 4/8] PM / Sleep: Use wait queue to signal "no wakeup events in progress" Rafael J. Wysocki
2012-02-08 23:10 ` NeilBrown
2012-02-09 0:05 ` Rafael J. Wysocki
2012-02-12 1:27 ` mark gross
2012-02-07 1:05 ` [RFC][PATCH 5/8] PM / Sleep: Change wakeup statistics Rafael J. Wysocki
2012-02-15 6:15 ` Arve Hjønnevåg
2012-02-15 22:37 ` Rafael J. Wysocki
2012-02-17 2:11 ` Arve Hjønnevåg
2012-02-07 1:06 ` [RFC][PATCH 6/8] PM / Sleep: Implement opportunistic sleep Rafael J. Wysocki
2012-02-07 22:49 ` [Update][RFC][PATCH " Rafael J. Wysocki
2012-02-07 1:06 ` [RFC][PATCH 7/8] PM / Sleep: Add "prevent autosleep time" statistics to wakeup sources Rafael J. Wysocki
2012-02-07 1:07 ` [RFC][PATCH 8/8] PM / Sleep: Add user space interface for manipulating " Rafael J. Wysocki
2012-02-07 1:13 ` [RFC][PATCH 0/8] PM: Implement autosleep and "wake locks" Rafael J. Wysocki
2012-02-08 23:57 ` NeilBrown
2012-02-10 0:44 ` Rafael J. Wysocki
2012-02-12 2:05 ` mark gross
2012-02-12 21:32 ` Rafael J. Wysocki
2012-02-14 0:11 ` Arve Hjønnevåg
2012-02-15 15:28 ` mark gross
2012-02-12 1:54 ` mark gross
2012-02-12 1:19 ` mark gross
2012-02-14 2:07 ` Arve Hjønnevåg
2012-02-14 23:22 ` Rafael J. Wysocki
2012-02-15 5:57 ` Arve Hjønnevåg
2012-02-15 23:07 ` Rafael J. Wysocki
2012-02-16 22:22 ` Rafael J. Wysocki
2012-02-17 3:56 ` Arve Hjønnevåg
2012-02-17 23:02 ` [PATCH] PM / Sleep: Add more wakeup source initialization routines Rafael J. Wysocki
2012-02-18 23:50 ` [Update][PATCH] " Rafael J. Wysocki
2012-02-20 23:04 ` [Update 2x][PATCH] " Rafael J. Wysocki
2012-02-17 3:55 ` [RFC][PATCH 0/8] PM: Implement autosleep and "wake locks" Arve Hjønnevåg
2012-02-17 20:57 ` Rafael J. Wysocki
2012-02-21 23:31 ` [RFC][PATCH 0/7] PM: Implement autosleep and "wake locks", take 2 Rafael J. Wysocki
2012-02-21 23:32 ` [RFC][PATCH 1/7] PM / Sleep: Look for wakeup events in later stages of device suspend Rafael J. Wysocki
2012-02-21 23:33 ` [RFC][PATCH 2/7] PM / Sleep: Use wait queue to signal "no wakeup events in progress" Rafael J. Wysocki
2012-02-21 23:34 ` [RFC][PATCH 3/7] PM / Sleep: Change wakeup source statistics to follow Android Rafael J. Wysocki
2012-02-21 23:34 ` [RFC][PATCH 4/7] Input / PM: Add ioctl to block suspend while event queue is not empty Rafael J. Wysocki
2012-02-24 5:16 ` Matt Helsley
2012-02-25 4:25 ` Arve Hjønnevåg
2012-02-25 23:33 ` Rafael J. Wysocki
2012-02-28 0:19 ` Matt Helsley
2012-02-26 20:57 ` Rafael J. Wysocki
2012-02-27 22:18 ` Matt Helsley
2012-02-28 1:17 ` Rafael J. Wysocki
2012-02-28 5:58 ` Arve Hjønnevåg
2012-03-04 22:56 ` Rafael J. Wysocki
2012-03-06 1:04 ` [PATCH 1/2] epoll: Add a flag, EPOLLWAKEUP, to prevent suspend while epoll events are ready Arve Hjønnevåg
2012-03-06 1:04 ` [PATCH 2/2] PM / Sleep: Add wakeup_source_activate and wakeup_source_deactivate tracepoints Arve Hjønnevåg
2012-02-21 23:35 ` [RFC][PATCH 5/7] PM / Sleep: Implement opportunistic sleep Rafael J. Wysocki
2012-02-22 8:45 ` Srivatsa S. Bhat
2012-02-22 22:10 ` Rafael J. Wysocki
2012-02-23 5:35 ` Srivatsa S. Bhat
2012-02-21 23:36 ` [RFC][PATCH 6/7] PM / Sleep: Add "prevent autosleep time" statistics to wakeup sources Rafael J. Wysocki
2012-02-21 23:37 ` [RFC][PATCH 7/7] PM / Sleep: Add user space interface for manipulating " Rafael J. Wysocki
2012-02-22 4:49 ` [RFC][PATCH 0/7] PM: Implement autosleep and "wake locks", take 2 John Stultz
2012-02-22 8:44 ` Srivatsa S. Bhat
2012-02-22 22:10 ` [RFC][PATCH 0/7] PM: Implement autosleep and "wake locks", take2 Rafael J. Wysocki
2012-02-23 6:25 ` Srivatsa S. Bhat
2012-02-23 21:26 ` Rafael J. Wysocki
2012-02-23 21:32 ` Rafael J. Wysocki
2012-02-24 4:44 ` Srivatsa S. Bhat
2012-02-24 23:21 ` Rafael J. Wysocki
2012-02-25 4:43 ` Arve Hjønnevåg
2012-02-25 20:43 ` Rafael J. Wysocki
2012-02-25 19:20 ` Srivatsa S. Bhat
2012-02-25 21:01 ` Rafael J. Wysocki
2012-02-28 10:24 ` Srivatsa S. Bhat
2012-04-22 21:19 ` [RFC][PATCH 0/8] PM: Implement autosleep and "wake locks", take 3 Rafael J. Wysocki
2012-04-22 21:19 ` [PATCH 1/8] PM / Sleep: Look for wakeup events in later stages of device suspend Rafael J. Wysocki
2012-04-22 21:20 ` [PATCH 2/8] PM / Sleep: Use wait queue to signal "no wakeup events in progress" Rafael J. Wysocki
2012-04-23 4:01 ` mark gross
2012-04-22 21:21 ` [PATCH 3/8] PM / Sleep: Change wakeup source statistics to follow Android Rafael J. Wysocki
2012-04-22 21:21 ` [PATCH 4/8] PM / Sleep: Add wakeup_source_activate and wakeup_source_deactivate tracepoints Rafael J. Wysocki
2012-04-22 21:22 ` [RFC][PATCH 5/8] epoll: Add a flag, EPOLLWAKEUP, to prevent suspend while epoll events are ready Rafael J. Wysocki
2012-04-26 4:03 ` NeilBrown
2012-04-26 20:40 ` Rafael J. Wysocki
2012-04-27 3:49 ` Arve Hjønnevåg
2012-04-27 21:18 ` Rafael J. Wysocki
2012-04-27 23:26 ` [PATCH] " Arve Hjønnevåg
2012-04-30 1:58 ` [RFC][PATCH 5/8] " NeilBrown
2012-05-01 0:52 ` Arve Hjønnevåg
2012-05-01 2:18 ` NeilBrown
2012-05-01 5:33 ` [PATCH] " Arve Hjønnevåg
2012-05-01 6:28 ` NeilBrown
2012-05-01 13:51 ` Rafael J. Wysocki
2012-07-16 6:38 ` Michael Kerrisk
2012-07-16 11:00 ` Rafael J. Wysocki
2012-07-16 22:04 ` Arve Hjønnevåg
2012-07-17 5:14 ` Michael Kerrisk
2012-07-17 19:22 ` Rafael J. Wysocki
2012-07-17 19:36 ` Greg KH
2012-07-17 19:55 ` Rafael J. Wysocki
2012-07-18 6:41 ` Michael Kerrisk (man-pages)
2012-04-22 21:23 ` [RFC][PATCH 6/8] PM / Sleep: Implement opportunistic sleep Rafael J. Wysocki
2012-04-26 3:05 ` NeilBrown
2012-04-26 21:52 ` Rafael J. Wysocki
2012-04-27 0:39 ` NeilBrown
2012-04-27 21:22 ` Rafael J. Wysocki
2012-05-03 0:23 ` Arve Hjønnevåg
2012-05-03 13:28 ` Rafael J. Wysocki
2012-05-03 21:27 ` Arve Hjønnevåg
2012-05-03 22:20 ` Rafael J. Wysocki
2012-05-03 22:16 ` Arve Hjønnevåg
2012-05-03 22:24 ` Rafael J. Wysocki
2012-04-22 21:24 ` Rafael J. Wysocki [this message]
2012-04-22 21:24 ` [RFC][PATCH 8/8] PM / Sleep: Add user space interface for manipulating wakeup sources Rafael J. Wysocki
2012-04-24 1:35 ` John Stultz
2012-04-24 21:27 ` Rafael J. Wysocki
2012-04-26 6:31 ` NeilBrown
2012-04-26 22:04 ` Rafael J. Wysocki
2012-04-27 0:07 ` NeilBrown
2012-04-27 21:15 ` Rafael J. Wysocki
2012-04-27 3:57 ` Arve Hjønnevåg
2012-04-27 21:14 ` Rafael J. Wysocki
2012-04-27 21:17 ` Arve Hjønnevåg
2012-04-27 21:34 ` Rafael J. Wysocki
2012-05-03 19:29 ` [PATCH 0/2]: Kconfig options for wakelocks limit and gc (was: Re: [RFC][PATCH 8/8] PM / Sleep: Add user space ...) Rafael J. Wysocki
2012-05-03 19:30 ` [PATCH 1/2] PM / Sleep: Make the limit of user space wakeup sources configurable Rafael J. Wysocki
2012-05-03 19:34 ` [PATCH 2/2] PM / Sleep: User space wakeup sources garbage collector Kconfig option Rafael J. Wysocki
2012-05-03 22:14 ` [PATCH 0/2]: Kconfig options for wakelocks limit and gc (was: Re: [RFC][PATCH 8/8] PM / Sleep: Add user space ...) Arve Hjønnevåg
2012-05-03 22:20 ` Rafael J. Wysocki
2012-04-23 16:49 ` [RFC][PATCH 0/8] PM: Implement autosleep and "wake locks", take 3 Greg KH
2012-04-23 19:51 ` 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=201204222324.04848.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=arve@android.com \
--cc=dmitry.torokhov@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=markgross@thegnar.org \
--cc=mjg@redhat.com \
--cc=neilb@suse.de \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
--cc=stern@rowland.harvard.edu \
--cc=swetland@google.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 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).