Skip to content

Commit 074037e

Browse files
committed
PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
Introduce struct wakeup_source for representing system wakeup sources within the kernel and for collecting statistics related to them. Make the recently introduced helper functions pm_wakeup_event(), pm_stay_awake() and pm_relax() use struct wakeup_source objects internally, so that wakeup statistics associated with wakeup devices can be collected and reported in a consistent way (the definition of pm_relax() is changed, which is harmless, because this function is not called directly by anyone yet). Introduce new wakeup-related sysfs device attributes in /sys/devices/.../power for reporting the device wakeup statistics. Change the global wakeup events counters event_count and events_in_progress into atomic variables, so that it is not necessary to acquire a global spinlock in pm_wakeup_event(), pm_stay_awake() and pm_relax(), which should allow us to avoid lock contention in these functions on SMP systems with many wakeup devices. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 0702d9e commit 074037e

10 files changed

Lines changed: 756 additions & 125 deletions

File tree

‎Documentation/ABI/testing/sysfs-devices-power‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,73 @@ Description:
7777
devices this attribute is set to "enabled" by bus type code or
7878
device drivers and in that cases it should be safe to leave the
7979
default value.
80+
81+
What: /sys/devices/.../power/wakeup_count
82+
Date: September 2010
83+
Contact: Rafael J. Wysocki <rjw@sisk.pl>
84+
Description:
85+
The /sys/devices/.../wakeup_count attribute contains the number
86+
of signaled wakeup events associated with the device. This
87+
attribute is read-only. If the device is not enabled to wake up
88+
the system from sleep states, this attribute is empty.
89+
90+
What: /sys/devices/.../power/wakeup_active_count
91+
Date: September 2010
92+
Contact: Rafael J. Wysocki <rjw@sisk.pl>
93+
Description:
94+
The /sys/devices/.../wakeup_active_count attribute contains the
95+
number of times the processing of wakeup events associated with
96+
the device was completed (at the kernel level). This attribute
97+
is read-only. If the device is not enabled to wake up the
98+
system from sleep states, this attribute is empty.
99+
100+
What: /sys/devices/.../power/wakeup_hit_count
101+
Date: September 2010
102+
Contact: Rafael J. Wysocki <rjw@sisk.pl>
103+
Description:
104+
The /sys/devices/.../wakeup_hit_count attribute contains the
105+
number of times the processing of a wakeup event associated with
106+
the device might prevent the system from entering a sleep state.
107+
This attribute is read-only. If the device is not enabled to
108+
wake up the system from sleep states, this attribute is empty.
109+
110+
What: /sys/devices/.../power/wakeup_active
111+
Date: September 2010
112+
Contact: Rafael J. Wysocki <rjw@sisk.pl>
113+
Description:
114+
The /sys/devices/.../wakeup_active attribute contains either 1,
115+
or 0, depending on whether or not a wakeup event associated with
116+
the device is being processed (1). This attribute is read-only.
117+
If the device is not enabled to wake up the system from sleep
118+
states, this attribute is empty.
119+
120+
What: /sys/devices/.../power/wakeup_total_time_ms
121+
Date: September 2010
122+
Contact: Rafael J. Wysocki <rjw@sisk.pl>
123+
Description:
124+
The /sys/devices/.../wakeup_total_time_ms attribute contains
125+
the total time of processing wakeup events associated with the
126+
device, in milliseconds. This attribute is read-only. If the
127+
device is not enabled to wake up the system from sleep states,
128+
this attribute is empty.
129+
130+
What: /sys/devices/.../power/wakeup_max_time_ms
131+
Date: September 2010
132+
Contact: Rafael J. Wysocki <rjw@sisk.pl>
133+
Description:
134+
The /sys/devices/.../wakeup_max_time_ms attribute contains
135+
the maximum time of processing a single wakeup event associated
136+
with the device, in milliseconds. This attribute is read-only.
137+
If the device is not enabled to wake up the system from sleep
138+
states, this attribute is empty.
139+
140+
What: /sys/devices/.../power/wakeup_last_time_ms
141+
Date: September 2010
142+
Contact: Rafael J. Wysocki <rjw@sisk.pl>
143+
Description:
144+
The /sys/devices/.../wakeup_last_time_ms attribute contains
145+
the value of the monotonic clock corresponding to the time of
146+
signaling the last wakeup event associated with the device, in
147+
milliseconds. This attribute is read-only. If the device is
148+
not enabled to wake up the system from sleep states, this
149+
attribute is empty.

‎drivers/base/power/main.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ void device_pm_init(struct device *dev)
6060
dev->power.status = DPM_ON;
6161
init_completion(&dev->power.completion);
6262
complete_all(&dev->power.completion);
63-
dev->power.wakeup_count = 0;
63+
dev->power.wakeup = NULL;
64+
spin_lock_init(&dev->power.lock);
6465
pm_runtime_init(dev);
6566
}
6667

@@ -120,6 +121,7 @@ void device_pm_remove(struct device *dev)
120121
mutex_lock(&dpm_list_mtx);
121122
list_del_init(&dev->power.entry);
122123
mutex_unlock(&dpm_list_mtx);
124+
device_wakeup_disable(dev);
123125
pm_runtime_remove(dev);
124126
}
125127

‎drivers/base/power/power.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extern void device_pm_move_last(struct device *);
3434

3535
static inline void device_pm_init(struct device *dev)
3636
{
37+
spin_lock_init(&dev->power.lock);
3738
pm_runtime_init(dev);
3839
}
3940

‎drivers/base/power/runtime.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,8 +1099,6 @@ EXPORT_SYMBOL_GPL(pm_runtime_allow);
10991099
*/
11001100
void pm_runtime_init(struct device *dev)
11011101
{
1102-
spin_lock_init(&dev->power.lock);
1103-
11041102
dev->power.runtime_status = RPM_SUSPENDED;
11051103
dev->power.idle_notification = false;
11061104

‎drivers/base/power/sysfs.c‎

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,122 @@ static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
210210
static ssize_t wakeup_count_show(struct device *dev,
211211
struct device_attribute *attr, char *buf)
212212
{
213-
return sprintf(buf, "%lu\n", dev->power.wakeup_count);
213+
unsigned long count = 0;
214+
bool enabled = false;
215+
216+
spin_lock_irq(&dev->power.lock);
217+
if (dev->power.wakeup) {
218+
count = dev->power.wakeup->event_count;
219+
enabled = true;
220+
}
221+
spin_unlock_irq(&dev->power.lock);
222+
return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
214223
}
215224

216225
static DEVICE_ATTR(wakeup_count, 0444, wakeup_count_show, NULL);
217-
#endif
226+
227+
static ssize_t wakeup_active_count_show(struct device *dev,
228+
struct device_attribute *attr, char *buf)
229+
{
230+
unsigned long count = 0;
231+
bool enabled = false;
232+
233+
spin_lock_irq(&dev->power.lock);
234+
if (dev->power.wakeup) {
235+
count = dev->power.wakeup->active_count;
236+
enabled = true;
237+
}
238+
spin_unlock_irq(&dev->power.lock);
239+
return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
240+
}
241+
242+
static DEVICE_ATTR(wakeup_active_count, 0444, wakeup_active_count_show, NULL);
243+
244+
static ssize_t wakeup_hit_count_show(struct device *dev,
245+
struct device_attribute *attr, char *buf)
246+
{
247+
unsigned long count = 0;
248+
bool enabled = false;
249+
250+
spin_lock_irq(&dev->power.lock);
251+
if (dev->power.wakeup) {
252+
count = dev->power.wakeup->hit_count;
253+
enabled = true;
254+
}
255+
spin_unlock_irq(&dev->power.lock);
256+
return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
257+
}
258+
259+
static DEVICE_ATTR(wakeup_hit_count, 0444, wakeup_hit_count_show, NULL);
260+
261+
static ssize_t wakeup_active_show(struct device *dev,
262+
struct device_attribute *attr, char *buf)
263+
{
264+
unsigned int active = 0;
265+
bool enabled = false;
266+
267+
spin_lock_irq(&dev->power.lock);
268+
if (dev->power.wakeup) {
269+
active = dev->power.wakeup->active;
270+
enabled = true;
271+
}
272+
spin_unlock_irq(&dev->power.lock);
273+
return enabled ? sprintf(buf, "%u\n", active) : sprintf(buf, "\n");
274+
}
275+
276+
static DEVICE_ATTR(wakeup_active, 0444, wakeup_active_show, NULL);
277+
278+
static ssize_t wakeup_total_time_show(struct device *dev,
279+
struct device_attribute *attr, char *buf)
280+
{
281+
s64 msec = 0;
282+
bool enabled = false;
283+
284+
spin_lock_irq(&dev->power.lock);
285+
if (dev->power.wakeup) {
286+
msec = ktime_to_ms(dev->power.wakeup->total_time);
287+
enabled = true;
288+
}
289+
spin_unlock_irq(&dev->power.lock);
290+
return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n");
291+
}
292+
293+
static DEVICE_ATTR(wakeup_total_time_ms, 0444, wakeup_total_time_show, NULL);
294+
295+
static ssize_t wakeup_max_time_show(struct device *dev,
296+
struct device_attribute *attr, char *buf)
297+
{
298+
s64 msec = 0;
299+
bool enabled = false;
300+
301+
spin_lock_irq(&dev->power.lock);
302+
if (dev->power.wakeup) {
303+
msec = ktime_to_ms(dev->power.wakeup->max_time);
304+
enabled = true;
305+
}
306+
spin_unlock_irq(&dev->power.lock);
307+
return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n");
308+
}
309+
310+
static DEVICE_ATTR(wakeup_max_time_ms, 0444, wakeup_max_time_show, NULL);
311+
312+
static ssize_t wakeup_last_time_show(struct device *dev,
313+
struct device_attribute *attr, char *buf)
314+
{
315+
s64 msec = 0;
316+
bool enabled = false;
317+
318+
spin_lock_irq(&dev->power.lock);
319+
if (dev->power.wakeup) {
320+
msec = ktime_to_ms(dev->power.wakeup->last_time);
321+
enabled = true;
322+
}
323+
spin_unlock_irq(&dev->power.lock);
324+
return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n");
325+
}
326+
327+
static DEVICE_ATTR(wakeup_last_time_ms, 0444, wakeup_last_time_show, NULL);
328+
#endif /* CONFIG_PM_SLEEP */
218329

219330
#ifdef CONFIG_PM_ADVANCED_DEBUG
220331
#ifdef CONFIG_PM_RUNTIME
@@ -288,6 +399,12 @@ static struct attribute * power_attrs[] = {
288399
&dev_attr_wakeup.attr,
289400
#ifdef CONFIG_PM_SLEEP
290401
&dev_attr_wakeup_count.attr,
402+
&dev_attr_wakeup_active_count.attr,
403+
&dev_attr_wakeup_hit_count.attr,
404+
&dev_attr_wakeup_active.attr,
405+
&dev_attr_wakeup_total_time_ms.attr,
406+
&dev_attr_wakeup_max_time_ms.attr,
407+
&dev_attr_wakeup_last_time_ms.attr,
291408
#endif
292409
#ifdef CONFIG_PM_ADVANCED_DEBUG
293410
&dev_attr_async.attr,

0 commit comments

Comments
 (0)