2 * drivers/base/power/wakeup.c - System wakeup events framework
4 * Copyright (c) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
6 * This file is released under the GPLv2.
9 #include <linux/device.h>
10 #include <linux/slab.h>
11 #include <linux/sched.h>
12 #include <linux/capability.h>
13 #include <linux/export.h>
14 #include <linux/suspend.h>
15 #include <linux/seq_file.h>
16 #include <linux/debugfs.h>
17 #include <linux/types.h>
18 #include <trace/events/power.h>
23 * If set, the suspend/hibernate code will abort transitions to a sleep state
24 * if wakeup events are registered during or immediately before the transition.
26 bool events_check_enabled __read_mostly;
29 * Combined counters of registered wakeup events and wakeup events in progress.
30 * They need to be modified together atomically, so it's better to use one
31 * atomic variable to hold them both.
33 static atomic_t combined_event_count = ATOMIC_INIT(0);
35 #define IN_PROGRESS_BITS (sizeof(int) * 4)
36 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
38 static void split_counters(unsigned int *cnt, unsigned int *inpr)
40 unsigned int comb = atomic_read(&combined_event_count);
42 *cnt = (comb >> IN_PROGRESS_BITS);
43 *inpr = comb & MAX_IN_PROGRESS;
46 /* A preserved old value of the events counter. */
47 static unsigned int saved_count;
49 static DEFINE_SPINLOCK(events_lock);
51 static void pm_wakeup_timer_fn(unsigned long data);
53 static LIST_HEAD(wakeup_sources);
55 static DECLARE_WAIT_QUEUE_HEAD(wakeup_count_wait_queue);
58 * wakeup_source_prepare - Prepare a new wakeup source for initialization.
59 * @ws: Wakeup source to prepare.
60 * @name: Pointer to the name of the new wakeup source.
62 * Callers must ensure that the @name string won't be freed when @ws is still in
65 void wakeup_source_prepare(struct wakeup_source *ws, const char *name)
68 memset(ws, 0, sizeof(*ws));
72 EXPORT_SYMBOL_GPL(wakeup_source_prepare);
75 * wakeup_source_create - Create a struct wakeup_source object.
76 * @name: Name of the new wakeup source.
78 struct wakeup_source *wakeup_source_create(const char *name)
80 struct wakeup_source *ws;
82 ws = kmalloc(sizeof(*ws), GFP_KERNEL);
86 wakeup_source_prepare(ws, name ? kstrdup(name, GFP_KERNEL) : NULL);
89 EXPORT_SYMBOL_GPL(wakeup_source_create);
92 * wakeup_source_drop - Prepare a struct wakeup_source object for destruction.
93 * @ws: Wakeup source to prepare for destruction.
95 * Callers must ensure that __pm_stay_awake() or __pm_wakeup_event() will never
96 * be run in parallel with this function for the same wakeup source object.
98 void wakeup_source_drop(struct wakeup_source *ws)
103 del_timer_sync(&ws->timer);
106 EXPORT_SYMBOL_GPL(wakeup_source_drop);
109 * wakeup_source_destroy - Destroy a struct wakeup_source object.
110 * @ws: Wakeup source to destroy.
112 * Use only for wakeup source objects created with wakeup_source_create().
114 void wakeup_source_destroy(struct wakeup_source *ws)
119 wakeup_source_drop(ws);
123 EXPORT_SYMBOL_GPL(wakeup_source_destroy);
126 * wakeup_source_add - Add given object to the list of wakeup sources.
127 * @ws: Wakeup source object to add to the list.
129 void wakeup_source_add(struct wakeup_source *ws)
136 spin_lock_init(&ws->lock);
137 setup_timer(&ws->timer, pm_wakeup_timer_fn, (unsigned long)ws);
139 ws->last_time = ktime_get();
141 spin_lock_irqsave(&events_lock, flags);
142 list_add_rcu(&ws->entry, &wakeup_sources);
143 spin_unlock_irqrestore(&events_lock, flags);
145 EXPORT_SYMBOL_GPL(wakeup_source_add);
148 * wakeup_source_remove - Remove given object from the wakeup sources list.
149 * @ws: Wakeup source object to remove from the list.
151 void wakeup_source_remove(struct wakeup_source *ws)
158 spin_lock_irqsave(&events_lock, flags);
159 list_del_rcu(&ws->entry);
160 spin_unlock_irqrestore(&events_lock, flags);
163 EXPORT_SYMBOL_GPL(wakeup_source_remove);
166 * wakeup_source_register - Create wakeup source and add it to the list.
167 * @name: Name of the wakeup source to register.
169 struct wakeup_source *wakeup_source_register(const char *name)
171 struct wakeup_source *ws;
173 ws = wakeup_source_create(name);
175 wakeup_source_add(ws);
179 EXPORT_SYMBOL_GPL(wakeup_source_register);
182 * wakeup_source_unregister - Remove wakeup source from the list and remove it.
183 * @ws: Wakeup source object to unregister.
185 void wakeup_source_unregister(struct wakeup_source *ws)
188 wakeup_source_remove(ws);
189 wakeup_source_destroy(ws);
192 EXPORT_SYMBOL_GPL(wakeup_source_unregister);
195 * device_wakeup_attach - Attach a wakeup source object to a device object.
196 * @dev: Device to handle.
197 * @ws: Wakeup source object to attach to @dev.
199 * This causes @dev to be treated as a wakeup device.
201 static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws)
203 spin_lock_irq(&dev->power.lock);
204 if (dev->power.wakeup) {
205 spin_unlock_irq(&dev->power.lock);
208 dev->power.wakeup = ws;
209 spin_unlock_irq(&dev->power.lock);
214 * device_wakeup_enable - Enable given device to be a wakeup source.
215 * @dev: Device to handle.
217 * Create a wakeup source object, register it and attach it to @dev.
219 int device_wakeup_enable(struct device *dev)
221 struct wakeup_source *ws;
224 if (!dev || !dev->power.can_wakeup)
227 ws = wakeup_source_register(dev_name(dev));
231 ret = device_wakeup_attach(dev, ws);
233 wakeup_source_unregister(ws);
237 EXPORT_SYMBOL_GPL(device_wakeup_enable);
240 * device_wakeup_detach - Detach a device's wakeup source object from it.
241 * @dev: Device to detach the wakeup source object from.
243 * After it returns, @dev will not be treated as a wakeup device any more.
245 static struct wakeup_source *device_wakeup_detach(struct device *dev)
247 struct wakeup_source *ws;
249 spin_lock_irq(&dev->power.lock);
250 ws = dev->power.wakeup;
251 dev->power.wakeup = NULL;
252 spin_unlock_irq(&dev->power.lock);
257 * device_wakeup_disable - Do not regard a device as a wakeup source any more.
258 * @dev: Device to handle.
260 * Detach the @dev's wakeup source object from it, unregister this wakeup source
261 * object and destroy it.
263 int device_wakeup_disable(struct device *dev)
265 struct wakeup_source *ws;
267 if (!dev || !dev->power.can_wakeup)
270 ws = device_wakeup_detach(dev);
272 wakeup_source_unregister(ws);
276 EXPORT_SYMBOL_GPL(device_wakeup_disable);
279 * device_set_wakeup_capable - Set/reset device wakeup capability flag.
280 * @dev: Device to handle.
281 * @capable: Whether or not @dev is capable of waking up the system from sleep.
283 * If @capable is set, set the @dev's power.can_wakeup flag and add its
284 * wakeup-related attributes to sysfs. Otherwise, unset the @dev's
285 * power.can_wakeup flag and remove its wakeup-related attributes from sysfs.
287 * This function may sleep and it can't be called from any context where
288 * sleeping is not allowed.
290 void device_set_wakeup_capable(struct device *dev, bool capable)
292 if (!!dev->power.can_wakeup == !!capable)
295 if (device_is_registered(dev) && !list_empty(&dev->power.entry)) {
297 if (wakeup_sysfs_add(dev))
300 wakeup_sysfs_remove(dev);
303 dev->power.can_wakeup = capable;
305 EXPORT_SYMBOL_GPL(device_set_wakeup_capable);
308 * device_init_wakeup - Device wakeup initialization.
309 * @dev: Device to handle.
310 * @enable: Whether or not to enable @dev as a wakeup device.
312 * By default, most devices should leave wakeup disabled. The exceptions are
313 * devices that everyone expects to be wakeup sources: keyboards, power buttons,
314 * possibly network interfaces, etc. Also, devices that don't generate their
315 * own wakeup requests but merely forward requests from one bus to another
316 * (like PCI bridges) should have wakeup enabled by default.
318 int device_init_wakeup(struct device *dev, bool enable)
323 device_set_wakeup_capable(dev, true);
324 ret = device_wakeup_enable(dev);
326 device_set_wakeup_capable(dev, false);
331 EXPORT_SYMBOL_GPL(device_init_wakeup);
334 * device_set_wakeup_enable - Enable or disable a device to wake up the system.
335 * @dev: Device to handle.
337 int device_set_wakeup_enable(struct device *dev, bool enable)
339 if (!dev || !dev->power.can_wakeup)
342 return enable ? device_wakeup_enable(dev) : device_wakeup_disable(dev);
344 EXPORT_SYMBOL_GPL(device_set_wakeup_enable);
347 * wakeup_source_not_registered - validate the given wakeup source.
348 * @ws: Wakeup source to be validated.
350 static bool wakeup_source_not_registered(struct wakeup_source *ws)
353 * Use timer struct to check if the given source is initialized
354 * by wakeup_source_add.
356 return ws->timer.function != pm_wakeup_timer_fn ||
357 ws->timer.data != (unsigned long)ws;
361 * The functions below use the observation that each wakeup event starts a
362 * period in which the system should not be suspended. The moment this period
363 * will end depends on how the wakeup event is going to be processed after being
364 * detected and all of the possible cases can be divided into two distinct
367 * First, a wakeup event may be detected by the same functional unit that will
368 * carry out the entire processing of it and possibly will pass it to user space
369 * for further processing. In that case the functional unit that has detected
370 * the event may later "close" the "no suspend" period associated with it
371 * directly as soon as it has been dealt with. The pair of pm_stay_awake() and
372 * pm_relax(), balanced with each other, is supposed to be used in such
375 * Second, a wakeup event may be detected by one functional unit and processed
376 * by another one. In that case the unit that has detected it cannot really
377 * "close" the "no suspend" period associated with it, unless it knows in
378 * advance what's going to happen to the event during processing. This
379 * knowledge, however, may not be available to it, so it can simply specify time
380 * to wait before the system can be suspended and pass it as the second
381 * argument of pm_wakeup_event().
383 * It is valid to call pm_relax() after pm_wakeup_event(), in which case the
384 * "no suspend" period will be ended either by the pm_relax(), or by the timer
385 * function executed when the timer expires, whichever comes first.
389 * wakup_source_activate - Mark given wakeup source as active.
390 * @ws: Wakeup source to handle.
392 * Update the @ws' statistics and, if @ws has just been activated, notify the PM
393 * core of the event by incrementing the counter of of wakeup events being
396 static void wakeup_source_activate(struct wakeup_source *ws)
400 if (WARN(wakeup_source_not_registered(ws),
401 "unregistered wakeup source\n"))
405 * active wakeup source should bring the system
406 * out of PM_SUSPEND_FREEZE state
412 ws->last_time = ktime_get();
413 if (ws->autosleep_enabled)
414 ws->start_prevent_time = ws->last_time;
416 /* Increment the counter of events in progress. */
417 cec = atomic_inc_return(&combined_event_count);
419 trace_wakeup_source_activate(ws->name, cec);
423 * wakeup_source_report_event - Report wakeup event using the given source.
424 * @ws: Wakeup source to report the event for.
426 static void wakeup_source_report_event(struct wakeup_source *ws)
429 /* This is racy, but the counter is approximate anyway. */
430 if (events_check_enabled)
434 wakeup_source_activate(ws);
438 * __pm_stay_awake - Notify the PM core of a wakeup event.
439 * @ws: Wakeup source object associated with the source of the event.
441 * It is safe to call this function from interrupt context.
443 void __pm_stay_awake(struct wakeup_source *ws)
450 spin_lock_irqsave(&ws->lock, flags);
452 wakeup_source_report_event(ws);
453 del_timer(&ws->timer);
454 ws->timer_expires = 0;
456 spin_unlock_irqrestore(&ws->lock, flags);
458 EXPORT_SYMBOL_GPL(__pm_stay_awake);
461 * pm_stay_awake - Notify the PM core that a wakeup event is being processed.
462 * @dev: Device the wakeup event is related to.
464 * Notify the PM core of a wakeup event (signaled by @dev) by calling
465 * __pm_stay_awake for the @dev's wakeup source object.
467 * Call this function after detecting of a wakeup event if pm_relax() is going
468 * to be called directly after processing the event (and possibly passing it to
469 * user space for further processing).
471 void pm_stay_awake(struct device *dev)
478 spin_lock_irqsave(&dev->power.lock, flags);
479 __pm_stay_awake(dev->power.wakeup);
480 spin_unlock_irqrestore(&dev->power.lock, flags);
482 EXPORT_SYMBOL_GPL(pm_stay_awake);
484 #ifdef CONFIG_PM_AUTOSLEEP
485 static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now)
487 ktime_t delta = ktime_sub(now, ws->start_prevent_time);
488 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta);
491 static inline void update_prevent_sleep_time(struct wakeup_source *ws,
496 * wakup_source_deactivate - Mark given wakeup source as inactive.
497 * @ws: Wakeup source to handle.
499 * Update the @ws' statistics and notify the PM core that the wakeup source has
500 * become inactive by decrementing the counter of wakeup events being processed
501 * and incrementing the counter of registered wakeup events.
503 static void wakeup_source_deactivate(struct wakeup_source *ws)
505 unsigned int cnt, inpr, cec;
511 * __pm_relax() may be called directly or from a timer function.
512 * If it is called directly right after the timer function has been
513 * started, but before the timer function calls __pm_relax(), it is
514 * possible that __pm_stay_awake() will be called in the meantime and
515 * will set ws->active. Then, ws->active may be cleared immediately
516 * by the __pm_relax() called from the timer function, but in such a
517 * case ws->relax_count will be different from ws->active_count.
519 if (ws->relax_count != ws->active_count) {
527 duration = ktime_sub(now, ws->last_time);
528 ws->total_time = ktime_add(ws->total_time, duration);
529 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time))
530 ws->max_time = duration;
533 del_timer(&ws->timer);
534 ws->timer_expires = 0;
536 if (ws->autosleep_enabled)
537 update_prevent_sleep_time(ws, now);
540 * Increment the counter of registered wakeup events and decrement the
541 * couter of wakeup events in progress simultaneously.
543 cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
544 trace_wakeup_source_deactivate(ws->name, cec);
546 split_counters(&cnt, &inpr);
547 if (!inpr && waitqueue_active(&wakeup_count_wait_queue))
548 wake_up(&wakeup_count_wait_queue);
552 * __pm_relax - Notify the PM core that processing of a wakeup event has ended.
553 * @ws: Wakeup source object associated with the source of the event.
555 * Call this function for wakeup events whose processing started with calling
558 * It is safe to call it from interrupt context.
560 void __pm_relax(struct wakeup_source *ws)
567 spin_lock_irqsave(&ws->lock, flags);
569 wakeup_source_deactivate(ws);
570 spin_unlock_irqrestore(&ws->lock, flags);
572 EXPORT_SYMBOL_GPL(__pm_relax);
575 * pm_relax - Notify the PM core that processing of a wakeup event has ended.
576 * @dev: Device that signaled the event.
578 * Execute __pm_relax() for the @dev's wakeup source object.
580 void pm_relax(struct device *dev)
587 spin_lock_irqsave(&dev->power.lock, flags);
588 __pm_relax(dev->power.wakeup);
589 spin_unlock_irqrestore(&dev->power.lock, flags);
591 EXPORT_SYMBOL_GPL(pm_relax);
594 * pm_wakeup_timer_fn - Delayed finalization of a wakeup event.
595 * @data: Address of the wakeup source object associated with the event source.
597 * Call wakeup_source_deactivate() for the wakeup source whose address is stored
598 * in @data if it is currently active and its timer has not been canceled and
599 * the expiration time of the timer is not in future.
601 static void pm_wakeup_timer_fn(unsigned long data)
603 struct wakeup_source *ws = (struct wakeup_source *)data;
606 spin_lock_irqsave(&ws->lock, flags);
608 if (ws->active && ws->timer_expires
609 && time_after_eq(jiffies, ws->timer_expires)) {
610 wakeup_source_deactivate(ws);
614 spin_unlock_irqrestore(&ws->lock, flags);
618 * __pm_wakeup_event - Notify the PM core of a wakeup event.
619 * @ws: Wakeup source object associated with the event source.
620 * @msec: Anticipated event processing time (in milliseconds).
622 * Notify the PM core of a wakeup event whose source is @ws that will take
623 * approximately @msec milliseconds to be processed by the kernel. If @ws is
624 * not active, activate it. If @msec is nonzero, set up the @ws' timer to
625 * execute pm_wakeup_timer_fn() in future.
627 * It is safe to call this function from interrupt context.
629 void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
632 unsigned long expires;
637 spin_lock_irqsave(&ws->lock, flags);
639 wakeup_source_report_event(ws);
642 wakeup_source_deactivate(ws);
646 expires = jiffies + msecs_to_jiffies(msec);
650 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) {
651 mod_timer(&ws->timer, expires);
652 ws->timer_expires = expires;
656 spin_unlock_irqrestore(&ws->lock, flags);
658 EXPORT_SYMBOL_GPL(__pm_wakeup_event);
662 * pm_wakeup_event - Notify the PM core of a wakeup event.
663 * @dev: Device the wakeup event is related to.
664 * @msec: Anticipated event processing time (in milliseconds).
666 * Call __pm_wakeup_event() for the @dev's wakeup source object.
668 void pm_wakeup_event(struct device *dev, unsigned int msec)
675 spin_lock_irqsave(&dev->power.lock, flags);
676 __pm_wakeup_event(dev->power.wakeup, msec);
677 spin_unlock_irqrestore(&dev->power.lock, flags);
679 EXPORT_SYMBOL_GPL(pm_wakeup_event);
681 void pm_get_active_wakeup_sources(char *pending_wakeup_source, size_t max)
683 struct wakeup_source *ws, *last_active_ws = NULL;
688 list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
691 len += scnprintf(pending_wakeup_source, max,
692 "Pending Wakeup Sources: ");
693 len += scnprintf(pending_wakeup_source + len, max - len,
696 } else if (!active &&
698 ktime_to_ns(ws->last_time) >
699 ktime_to_ns(last_active_ws->last_time))) {
703 if (!active && last_active_ws) {
704 scnprintf(pending_wakeup_source, max,
705 "Last active Wakeup Source: %s",
706 last_active_ws->name);
710 EXPORT_SYMBOL_GPL(pm_get_active_wakeup_sources);
712 static void print_active_wakeup_sources(void)
714 struct wakeup_source *ws;
716 struct wakeup_source *last_activity_ws = NULL;
719 list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
721 pr_info("active wakeup source: %s\n", ws->name);
723 } else if (!active &&
724 (!last_activity_ws ||
725 ktime_to_ns(ws->last_time) >
726 ktime_to_ns(last_activity_ws->last_time))) {
727 last_activity_ws = ws;
731 if (!active && last_activity_ws)
732 pr_info("last active wakeup source: %s\n",
733 last_activity_ws->name);
738 * pm_wakeup_pending - Check if power transition in progress should be aborted.
740 * Compare the current number of registered wakeup events with its preserved
741 * value from the past and return true if new wakeup events have been registered
742 * since the old value was stored. Also return true if the current number of
743 * wakeup events being processed is different from zero.
745 bool pm_wakeup_pending(void)
750 spin_lock_irqsave(&events_lock, flags);
751 if (events_check_enabled) {
752 unsigned int cnt, inpr;
754 split_counters(&cnt, &inpr);
755 ret = (cnt != saved_count || inpr > 0);
756 events_check_enabled = !ret;
758 spin_unlock_irqrestore(&events_lock, flags);
761 print_active_wakeup_sources();
767 * pm_get_wakeup_count - Read the number of registered wakeup events.
768 * @count: Address to store the value at.
769 * @block: Whether or not to block.
771 * Store the number of registered wakeup events at the address in @count. If
772 * @block is set, block until the current number of wakeup events being
775 * Return 'false' if the current number of wakeup events being processed is
776 * nonzero. Otherwise return 'true'.
778 bool pm_get_wakeup_count(unsigned int *count, bool block)
780 unsigned int cnt, inpr;
786 prepare_to_wait(&wakeup_count_wait_queue, &wait,
788 split_counters(&cnt, &inpr);
789 if (inpr == 0 || signal_pending(current))
794 finish_wait(&wakeup_count_wait_queue, &wait);
797 split_counters(&cnt, &inpr);
803 * pm_save_wakeup_count - Save the current number of registered wakeup events.
804 * @count: Value to compare with the current number of registered wakeup events.
806 * If @count is equal to the current number of registered wakeup events and the
807 * current number of wakeup events being processed is zero, store @count as the
808 * old number of registered wakeup events for pm_check_wakeup_events(), enable
809 * wakeup events detection and return 'true'. Otherwise disable wakeup events
810 * detection and return 'false'.
812 bool pm_save_wakeup_count(unsigned int count)
814 unsigned int cnt, inpr;
817 events_check_enabled = false;
818 spin_lock_irqsave(&events_lock, flags);
819 split_counters(&cnt, &inpr);
820 if (cnt == count && inpr == 0) {
822 events_check_enabled = true;
824 spin_unlock_irqrestore(&events_lock, flags);
825 return events_check_enabled;
828 #ifdef CONFIG_PM_AUTOSLEEP
830 * pm_wakep_autosleep_enabled - Modify autosleep_enabled for all wakeup sources.
831 * @enabled: Whether to set or to clear the autosleep_enabled flags.
833 void pm_wakep_autosleep_enabled(bool set)
835 struct wakeup_source *ws;
836 ktime_t now = ktime_get();
839 list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
840 spin_lock_irq(&ws->lock);
841 if (ws->autosleep_enabled != set) {
842 ws->autosleep_enabled = set;
845 ws->start_prevent_time = now;
847 update_prevent_sleep_time(ws, now);
850 spin_unlock_irq(&ws->lock);
854 #endif /* CONFIG_PM_AUTOSLEEP */
856 static struct dentry *wakeup_sources_stats_dentry;
859 * print_wakeup_source_stats - Print wakeup source statistics information.
860 * @m: seq_file to print the statistics into.
861 * @ws: Wakeup source object to print the statistics for.
863 static int print_wakeup_source_stats(struct seq_file *m,
864 struct wakeup_source *ws)
869 unsigned long active_count;
871 ktime_t prevent_sleep_time;
874 spin_lock_irqsave(&ws->lock, flags);
876 total_time = ws->total_time;
877 max_time = ws->max_time;
878 prevent_sleep_time = ws->prevent_sleep_time;
879 active_count = ws->active_count;
881 ktime_t now = ktime_get();
883 active_time = ktime_sub(now, ws->last_time);
884 total_time = ktime_add(total_time, active_time);
885 if (active_time.tv64 > max_time.tv64)
886 max_time = active_time;
888 if (ws->autosleep_enabled)
889 prevent_sleep_time = ktime_add(prevent_sleep_time,
890 ktime_sub(now, ws->start_prevent_time));
892 active_time = ktime_set(0, 0);
895 ret = seq_printf(m, "%-12s\t%lu\t\t%lu\t\t%lu\t\t%lu\t\t"
896 "%lld\t\t%lld\t\t%lld\t\t%lld\t\t%lld\n",
897 ws->name, active_count, ws->event_count,
898 ws->wakeup_count, ws->expire_count,
899 ktime_to_ms(active_time), ktime_to_ms(total_time),
900 ktime_to_ms(max_time), ktime_to_ms(ws->last_time),
901 ktime_to_ms(prevent_sleep_time));
903 spin_unlock_irqrestore(&ws->lock, flags);
909 * wakeup_sources_stats_show - Print wakeup sources statistics information.
910 * @m: seq_file to print the statistics into.
912 static int wakeup_sources_stats_show(struct seq_file *m, void *unused)
914 struct wakeup_source *ws;
916 seq_puts(m, "name\t\tactive_count\tevent_count\twakeup_count\t"
917 "expire_count\tactive_since\ttotal_time\tmax_time\t"
918 "last_change\tprevent_suspend_time\n");
921 list_for_each_entry_rcu(ws, &wakeup_sources, entry)
922 print_wakeup_source_stats(m, ws);
928 static int wakeup_sources_stats_open(struct inode *inode, struct file *file)
930 return single_open(file, wakeup_sources_stats_show, NULL);
933 static const struct file_operations wakeup_sources_stats_fops = {
934 .owner = THIS_MODULE,
935 .open = wakeup_sources_stats_open,
938 .release = single_release,
941 static int __init wakeup_sources_debugfs_init(void)
943 wakeup_sources_stats_dentry = debugfs_create_file("wakeup_sources",
944 S_IRUGO, NULL, NULL, &wakeup_sources_stats_fops);
948 postcore_initcall(wakeup_sources_debugfs_init);