1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129 |
- #include <linux/device.h>
- #include <linux/slab.h>
- #include <linux/sched.h>
- #include <linux/capability.h>
- #include <linux/export.h>
- #include <linux/suspend.h>
- #include <linux/seq_file.h>
- #include <linux/debugfs.h>
- #include <linux/pm_wakeirq.h>
- #include <linux/types.h>
- #include <linux/wakeup_reason.h>
- #include <trace/events/power.h>
- #include <linux/irq.h>
- #include <linux/irqdesc.h>
- #include "power.h"
- bool events_check_enabled __read_mostly;
- unsigned int pm_wakeup_irq __read_mostly;
- static bool pm_abort_suspend __read_mostly;
- static atomic_t combined_event_count = ATOMIC_INIT(0);
- #define IN_PROGRESS_BITS (sizeof(int) * 4)
- #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
- static void split_counters(unsigned int *cnt, unsigned int *inpr)
- {
- unsigned int comb = atomic_read(&combined_event_count);
- *cnt = (comb >> IN_PROGRESS_BITS);
- *inpr = comb & MAX_IN_PROGRESS;
- }
- static unsigned int saved_count;
- static DEFINE_SPINLOCK(events_lock);
- static void pm_wakeup_timer_fn(unsigned long data);
- static LIST_HEAD(wakeup_sources);
- static DECLARE_WAIT_QUEUE_HEAD(wakeup_count_wait_queue);
- DEFINE_STATIC_SRCU(wakeup_srcu);
- static struct wakeup_source deleted_ws = {
- .name = "deleted",
- .lock = __SPIN_LOCK_UNLOCKED(deleted_ws.lock),
- };
- void wakeup_source_prepare(struct wakeup_source *ws, const char *name)
- {
- if (ws) {
- memset(ws, 0, sizeof(*ws));
- ws->name = name;
- }
- }
- EXPORT_SYMBOL_GPL(wakeup_source_prepare);
- struct wakeup_source *wakeup_source_create(const char *name)
- {
- struct wakeup_source *ws;
- ws = kmalloc(sizeof(*ws), GFP_KERNEL);
- if (!ws)
- return NULL;
- wakeup_source_prepare(ws, name ? kstrdup_const(name, GFP_KERNEL) : NULL);
- return ws;
- }
- EXPORT_SYMBOL_GPL(wakeup_source_create);
- void wakeup_source_drop(struct wakeup_source *ws)
- {
- if (!ws)
- return;
- __pm_relax(ws);
- }
- EXPORT_SYMBOL_GPL(wakeup_source_drop);
- static void wakeup_source_record(struct wakeup_source *ws)
- {
- unsigned long flags;
- spin_lock_irqsave(&deleted_ws.lock, flags);
- if (ws->event_count) {
- deleted_ws.total_time =
- ktime_add(deleted_ws.total_time, ws->total_time);
- deleted_ws.prevent_sleep_time =
- ktime_add(deleted_ws.prevent_sleep_time,
- ws->prevent_sleep_time);
- deleted_ws.max_time =
- ktime_compare(deleted_ws.max_time, ws->max_time) > 0 ?
- deleted_ws.max_time : ws->max_time;
- deleted_ws.event_count += ws->event_count;
- deleted_ws.active_count += ws->active_count;
- deleted_ws.relax_count += ws->relax_count;
- deleted_ws.expire_count += ws->expire_count;
- deleted_ws.wakeup_count += ws->wakeup_count;
- }
- spin_unlock_irqrestore(&deleted_ws.lock, flags);
- }
- void wakeup_source_destroy(struct wakeup_source *ws)
- {
- if (!ws)
- return;
- wakeup_source_drop(ws);
- wakeup_source_record(ws);
- kfree_const(ws->name);
- kfree(ws);
- }
- EXPORT_SYMBOL_GPL(wakeup_source_destroy);
- void wakeup_source_add(struct wakeup_source *ws)
- {
- unsigned long flags;
- if (WARN_ON(!ws))
- return;
- spin_lock_init(&ws->lock);
- setup_timer(&ws->timer, pm_wakeup_timer_fn, (unsigned long)ws);
- ws->active = false;
- ws->last_time = ktime_get();
- spin_lock_irqsave(&events_lock, flags);
- list_add_rcu(&ws->entry, &wakeup_sources);
- spin_unlock_irqrestore(&events_lock, flags);
- }
- EXPORT_SYMBOL_GPL(wakeup_source_add);
- void wakeup_source_remove(struct wakeup_source *ws)
- {
- unsigned long flags;
- if (WARN_ON(!ws))
- return;
- spin_lock_irqsave(&events_lock, flags);
- list_del_rcu(&ws->entry);
- spin_unlock_irqrestore(&events_lock, flags);
- synchronize_srcu(&wakeup_srcu);
- del_timer_sync(&ws->timer);
-
- ws->timer.function = NULL;
- }
- EXPORT_SYMBOL_GPL(wakeup_source_remove);
- struct wakeup_source *wakeup_source_register(const char *name)
- {
- struct wakeup_source *ws;
- ws = wakeup_source_create(name);
- if (ws)
- wakeup_source_add(ws);
- return ws;
- }
- EXPORT_SYMBOL_GPL(wakeup_source_register);
- void wakeup_source_unregister(struct wakeup_source *ws)
- {
- if (ws) {
- wakeup_source_remove(ws);
- wakeup_source_destroy(ws);
- }
- }
- EXPORT_SYMBOL_GPL(wakeup_source_unregister);
- static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws)
- {
- spin_lock_irq(&dev->power.lock);
- if (dev->power.wakeup) {
- spin_unlock_irq(&dev->power.lock);
- return -EEXIST;
- }
- dev->power.wakeup = ws;
- if (dev->power.wakeirq)
- device_wakeup_attach_irq(dev, dev->power.wakeirq);
- spin_unlock_irq(&dev->power.lock);
- return 0;
- }
- int device_wakeup_enable(struct device *dev)
- {
- struct wakeup_source *ws;
- int ret;
- if (!dev || !dev->power.can_wakeup)
- return -EINVAL;
- ws = wakeup_source_register(dev_name(dev));
- if (!ws)
- return -ENOMEM;
- ret = device_wakeup_attach(dev, ws);
- if (ret)
- wakeup_source_unregister(ws);
- return ret;
- }
- EXPORT_SYMBOL_GPL(device_wakeup_enable);
- int device_wakeup_attach_irq(struct device *dev,
- struct wake_irq *wakeirq)
- {
- struct wakeup_source *ws;
- ws = dev->power.wakeup;
- if (!ws) {
- dev_err(dev, "forgot to call call device_init_wakeup?\n");
- return -EINVAL;
- }
- if (ws->wakeirq)
- return -EEXIST;
- ws->wakeirq = wakeirq;
- return 0;
- }
- void device_wakeup_detach_irq(struct device *dev)
- {
- struct wakeup_source *ws;
- ws = dev->power.wakeup;
- if (ws)
- ws->wakeirq = NULL;
- }
- void device_wakeup_arm_wake_irqs(void)
- {
- struct wakeup_source *ws;
- int srcuidx;
- srcuidx = srcu_read_lock(&wakeup_srcu);
- list_for_each_entry_rcu(ws, &wakeup_sources, entry)
- dev_pm_arm_wake_irq(ws->wakeirq);
- srcu_read_unlock(&wakeup_srcu, srcuidx);
- }
- void device_wakeup_disarm_wake_irqs(void)
- {
- struct wakeup_source *ws;
- int srcuidx;
- srcuidx = srcu_read_lock(&wakeup_srcu);
- list_for_each_entry_rcu(ws, &wakeup_sources, entry)
- dev_pm_disarm_wake_irq(ws->wakeirq);
- srcu_read_unlock(&wakeup_srcu, srcuidx);
- }
- static struct wakeup_source *device_wakeup_detach(struct device *dev)
- {
- struct wakeup_source *ws;
- spin_lock_irq(&dev->power.lock);
- ws = dev->power.wakeup;
- dev->power.wakeup = NULL;
- spin_unlock_irq(&dev->power.lock);
- return ws;
- }
- int device_wakeup_disable(struct device *dev)
- {
- struct wakeup_source *ws;
- if (!dev || !dev->power.can_wakeup)
- return -EINVAL;
- ws = device_wakeup_detach(dev);
- wakeup_source_unregister(ws);
- return 0;
- }
- EXPORT_SYMBOL_GPL(device_wakeup_disable);
- void device_set_wakeup_capable(struct device *dev, bool capable)
- {
- if (!!dev->power.can_wakeup == !!capable)
- return;
- if (device_is_registered(dev) && !list_empty(&dev->power.entry)) {
- if (capable) {
- if (wakeup_sysfs_add(dev))
- return;
- } else {
- wakeup_sysfs_remove(dev);
- }
- }
- dev->power.can_wakeup = capable;
- }
- EXPORT_SYMBOL_GPL(device_set_wakeup_capable);
- int device_init_wakeup(struct device *dev, bool enable)
- {
- int ret = 0;
- if (!dev)
- return -EINVAL;
- if (enable) {
- device_set_wakeup_capable(dev, true);
- ret = device_wakeup_enable(dev);
- } else {
- if (dev->power.can_wakeup)
- device_wakeup_disable(dev);
- device_set_wakeup_capable(dev, false);
- }
- return ret;
- }
- EXPORT_SYMBOL_GPL(device_init_wakeup);
- int device_set_wakeup_enable(struct device *dev, bool enable)
- {
- if (!dev || !dev->power.can_wakeup)
- return -EINVAL;
- return enable ? device_wakeup_enable(dev) : device_wakeup_disable(dev);
- }
- EXPORT_SYMBOL_GPL(device_set_wakeup_enable);
- static bool wakeup_source_not_registered(struct wakeup_source *ws)
- {
-
- return ws->timer.function != pm_wakeup_timer_fn ||
- ws->timer.data != (unsigned long)ws;
- }
- static void wakeup_source_activate(struct wakeup_source *ws)
- {
- unsigned int cec;
- if (WARN_ONCE(wakeup_source_not_registered(ws),
- "unregistered wakeup source\n"))
- return;
-
- freeze_wake();
- ws->active = true;
- ws->active_count++;
- ws->last_time = ktime_get();
- if (ws->autosleep_enabled)
- ws->start_prevent_time = ws->last_time;
-
- cec = atomic_inc_return(&combined_event_count);
- trace_wakeup_source_activate(ws->name, cec);
- }
- static void wakeup_source_report_event(struct wakeup_source *ws)
- {
- ws->event_count++;
-
- if (events_check_enabled)
- ws->wakeup_count++;
- if (!ws->active)
- wakeup_source_activate(ws);
- }
- void __pm_stay_awake(struct wakeup_source *ws)
- {
- unsigned long flags;
- if (!ws)
- return;
- spin_lock_irqsave(&ws->lock, flags);
- wakeup_source_report_event(ws);
- del_timer(&ws->timer);
- ws->timer_expires = 0;
- spin_unlock_irqrestore(&ws->lock, flags);
- }
- EXPORT_SYMBOL_GPL(__pm_stay_awake);
- void pm_stay_awake(struct device *dev)
- {
- unsigned long flags;
- if (!dev)
- return;
- spin_lock_irqsave(&dev->power.lock, flags);
- __pm_stay_awake(dev->power.wakeup);
- spin_unlock_irqrestore(&dev->power.lock, flags);
- }
- 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
- static void wakeup_source_deactivate(struct wakeup_source *ws)
- {
- unsigned int cnt, inpr, cec;
- ktime_t duration;
- ktime_t now;
- ws->relax_count++;
-
- if (ws->relax_count != ws->active_count) {
- ws->relax_count--;
- return;
- }
- ws->active = false;
- now = ktime_get();
- duration = ktime_sub(now, ws->last_time);
- ws->total_time = ktime_add(ws->total_time, duration);
- if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time))
- ws->max_time = duration;
- ws->last_time = now;
- del_timer(&ws->timer);
- ws->timer_expires = 0;
- if (ws->autosleep_enabled)
- update_prevent_sleep_time(ws, now);
-
- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
- trace_wakeup_source_deactivate(ws->name, cec);
- split_counters(&cnt, &inpr);
- if (!inpr && waitqueue_active(&wakeup_count_wait_queue))
- wake_up(&wakeup_count_wait_queue);
- }
- void __pm_relax(struct wakeup_source *ws)
- {
- unsigned long flags;
- if (!ws)
- return;
- spin_lock_irqsave(&ws->lock, flags);
- if (ws->active)
- wakeup_source_deactivate(ws);
- spin_unlock_irqrestore(&ws->lock, flags);
- }
- EXPORT_SYMBOL_GPL(__pm_relax);
- void pm_relax(struct device *dev)
- {
- unsigned long flags;
- if (!dev)
- return;
- spin_lock_irqsave(&dev->power.lock, flags);
- __pm_relax(dev->power.wakeup);
- spin_unlock_irqrestore(&dev->power.lock, flags);
- }
- EXPORT_SYMBOL_GPL(pm_relax);
- static void pm_wakeup_timer_fn(unsigned long data)
- {
- struct wakeup_source *ws = (struct wakeup_source *)data;
- unsigned long flags;
- spin_lock_irqsave(&ws->lock, flags);
- if (ws->active && ws->timer_expires
- && time_after_eq(jiffies, ws->timer_expires)) {
- wakeup_source_deactivate(ws);
- ws->expire_count++;
- }
- spin_unlock_irqrestore(&ws->lock, flags);
- }
- void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
- {
- unsigned long flags;
- unsigned long expires;
- if (!ws)
- return;
- spin_lock_irqsave(&ws->lock, flags);
- wakeup_source_report_event(ws);
- if (!msec) {
- wakeup_source_deactivate(ws);
- goto unlock;
- }
- expires = jiffies + msecs_to_jiffies(msec);
- if (!expires)
- expires = 1;
- if (!ws->timer_expires || time_after(expires, ws->timer_expires)) {
- mod_timer(&ws->timer, expires);
- ws->timer_expires = expires;
- }
- unlock:
- spin_unlock_irqrestore(&ws->lock, flags);
- }
- EXPORT_SYMBOL_GPL(__pm_wakeup_event);
- void pm_wakeup_event(struct device *dev, unsigned int msec)
- {
- unsigned long flags;
- if (!dev)
- return;
- spin_lock_irqsave(&dev->power.lock, flags);
- __pm_wakeup_event(dev->power.wakeup, msec);
- spin_unlock_irqrestore(&dev->power.lock, flags);
- }
- EXPORT_SYMBOL_GPL(pm_wakeup_event);
- void pm_get_active_wakeup_sources(char *pending_wakeup_source, size_t max)
- {
- struct wakeup_source *ws, *last_active_ws = NULL;
- int len = 0;
- bool active = false;
- int srcuidx;
- srcuidx = srcu_read_lock(&wakeup_srcu);
- list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
- if (ws->active && len < max) {
- if (!active)
- len += scnprintf(pending_wakeup_source, max,
- "Pending Wakeup Sources: ");
- len += scnprintf(pending_wakeup_source + len, max - len,
- "%s ", ws->name);
- active = true;
- } else if (!active &&
- (!last_active_ws ||
- ktime_to_ns(ws->last_time) >
- ktime_to_ns(last_active_ws->last_time))) {
- last_active_ws = ws;
- }
- }
- if (!active && last_active_ws) {
- scnprintf(pending_wakeup_source, max,
- "Last active Wakeup Source: %s",
- last_active_ws->name);
- }
- srcu_read_unlock(&wakeup_srcu, srcuidx);
- }
- EXPORT_SYMBOL_GPL(pm_get_active_wakeup_sources);
- void pm_print_active_wakeup_sources(void)
- {
- struct wakeup_source *ws;
- int srcuidx, active = 0;
- struct wakeup_source *last_activity_ws = NULL;
- srcuidx = srcu_read_lock(&wakeup_srcu);
- list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
- if (ws->active) {
- pr_info("active wakeup source: %s\n", ws->name);
- active = 1;
- } else if (!active &&
- (!last_activity_ws ||
- ktime_to_ns(ws->last_time) >
- ktime_to_ns(last_activity_ws->last_time))) {
- last_activity_ws = ws;
- }
- }
- if (!active && last_activity_ws)
- pr_info("last active wakeup source: %s\n",
- last_activity_ws->name);
- srcu_read_unlock(&wakeup_srcu, srcuidx);
- }
- EXPORT_SYMBOL_GPL(pm_print_active_wakeup_sources);
- bool pm_wakeup_pending(void)
- {
- unsigned long flags;
- bool ret = false;
- char suspend_abort[MAX_SUSPEND_ABORT_LEN];
- spin_lock_irqsave(&events_lock, flags);
- if (events_check_enabled) {
- unsigned int cnt, inpr;
- split_counters(&cnt, &inpr);
- ret = (cnt != saved_count || inpr > 0);
- events_check_enabled = !ret;
- }
- spin_unlock_irqrestore(&events_lock, flags);
- if (ret) {
- pr_info("PM: Wakeup pending, aborting suspend\n");
- pm_get_active_wakeup_sources(suspend_abort,
- MAX_SUSPEND_ABORT_LEN);
- log_suspend_abort_reason(suspend_abort);
- pr_info("PM: %s\n", suspend_abort);
- }
- return ret || pm_abort_suspend;
- }
- void pm_system_wakeup(void)
- {
- pm_abort_suspend = true;
- freeze_wake();
- }
- EXPORT_SYMBOL_GPL(pm_system_wakeup);
- void pm_wakeup_clear(void)
- {
- pm_abort_suspend = false;
- pm_wakeup_irq = 0;
- }
- void pm_system_irq_wakeup(unsigned int irq_number)
- {
- struct irq_desc *desc;
- const char *name = "null";
- if (pm_wakeup_irq == 0) {
- if (msm_show_resume_irq_mask) {
- desc = irq_to_desc(irq_number);
- if (desc == NULL)
- name = "stray irq";
- else if (desc->action && desc->action->name)
- name = desc->action->name;
- log_base_wakeup_reason(irq_number);
- pr_warn("%s: %d triggered %s\n", __func__,
- irq_number, name);
- }
- pm_wakeup_irq = irq_number;
- pm_system_wakeup();
- }
- }
- bool pm_get_wakeup_count(unsigned int *count, bool block)
- {
- unsigned int cnt, inpr;
- if (block) {
- DEFINE_WAIT(wait);
- for (;;) {
- prepare_to_wait(&wakeup_count_wait_queue, &wait,
- TASK_INTERRUPTIBLE);
- split_counters(&cnt, &inpr);
- if (inpr == 0 || signal_pending(current))
- break;
- schedule();
- }
- finish_wait(&wakeup_count_wait_queue, &wait);
- }
- split_counters(&cnt, &inpr);
- *count = cnt;
- return !inpr;
- }
- bool pm_save_wakeup_count(unsigned int count)
- {
- unsigned int cnt, inpr;
- unsigned long flags;
- events_check_enabled = false;
- spin_lock_irqsave(&events_lock, flags);
- split_counters(&cnt, &inpr);
- if (cnt == count && inpr == 0) {
- saved_count = count;
- events_check_enabled = true;
- }
- spin_unlock_irqrestore(&events_lock, flags);
- return events_check_enabled;
- }
- #ifdef CONFIG_PM_AUTOSLEEP
- void pm_wakep_autosleep_enabled(bool set)
- {
- struct wakeup_source *ws;
- ktime_t now = ktime_get();
- int srcuidx;
- srcuidx = srcu_read_lock(&wakeup_srcu);
- 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);
- }
- srcu_read_unlock(&wakeup_srcu, srcuidx);
- }
- #endif
- static struct dentry *wakeup_sources_stats_dentry;
- static int print_wakeup_source_stats(struct seq_file *m,
- struct wakeup_source *ws)
- {
- unsigned long flags;
- ktime_t total_time;
- ktime_t max_time;
- unsigned long active_count;
- ktime_t active_time;
- ktime_t prevent_sleep_time;
- 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) {
- 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);
- }
- seq_printf(m, "%-32s\t%lu\t\t%lu\t\t%lu\t\t%lu\t\t%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(prevent_sleep_time));
- spin_unlock_irqrestore(&ws->lock, flags);
- return 0;
- }
- static int wakeup_sources_stats_show(struct seq_file *m, void *unused)
- {
- struct wakeup_source *ws;
- int srcuidx;
- seq_puts(m, "name\t\t\t\t\tactive_count\tevent_count\twakeup_count\t"
- "expire_count\tactive_since\ttotal_time\tmax_time\t"
- "last_change\tprevent_suspend_time\n");
- srcuidx = srcu_read_lock(&wakeup_srcu);
- list_for_each_entry_rcu(ws, &wakeup_sources, entry)
- print_wakeup_source_stats(m, ws);
- srcu_read_unlock(&wakeup_srcu, srcuidx);
- print_wakeup_source_stats(m, &deleted_ws);
- return 0;
- }
- static int wakeup_sources_stats_open(struct inode *inode, struct file *file)
- {
- return single_open(file, wakeup_sources_stats_show, NULL);
- }
- static const struct file_operations wakeup_sources_stats_fops = {
- .owner = THIS_MODULE,
- .open = wakeup_sources_stats_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
- };
- static int __init wakeup_sources_debugfs_init(void)
- {
- wakeup_sources_stats_dentry = debugfs_create_file("wakeup_sources",
- S_IRUGO, NULL, NULL, &wakeup_sources_stats_fops);
- return 0;
- }
- postcore_initcall(wakeup_sources_debugfs_init);
|