From 19d39dcea7b6dabfba4e4e902f370c84316a79a2 Mon Sep 17 00:00:00 2001 From: haojl2 Date: Wed, 13 Nov 2019 14:27:49 +0800 Subject: [PATCH] power: Add function to show active wakelocks tlmm: Add a function to dump the active wakelocks Change-Id: I05f4d477ff9e096efe8e0fcdb3a8d5d76c7028ac Signed-off-by: haojl2 Reviewed-on: https://gerrit.mot.com/1453711 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Jianqi Yang Submit-Approved: Jira Key Reviewed-on: https://gerrit.mot.com/1509728 Reviewed-by: Wang Wang --- drivers/base/power/wakeup.c | 27 +++++++++++++++++++++++++++ include/linux/pm_wakeup.h | 1 + 2 files changed, 28 insertions(+) diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index f72608d1be4b..ad88d7a07d6e 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c @@ -1158,6 +1158,33 @@ static const struct seq_operations wakeup_sources_stats_seq_ops = { .show = wakeup_sources_stats_seq_show, }; +int wakelock_dump_active_info(char *buf, int size) +{ + struct wakeup_source *ws; + unsigned long flags; + char *p = buf; + + rcu_read_lock(); + list_for_each_entry_rcu(ws, &wakeup_sources, entry) { + spin_lock_irqsave(&ws->lock, flags); + if (ws->active) { + if (time_after(ws->timer_expires, jiffies)) { + long timeout = ws->timer_expires - jiffies; + + p += snprintf(p, size - (p - buf), + " (active)[%s], time left %d (msecs)\n", + ws->name, jiffies_to_msecs(timeout)); + } else /* active */ + p += snprintf(p, size - (p - buf), + " (active)[%s]\n", ws->name); + } + spin_unlock_irqrestore(&ws->lock, flags); + } + rcu_read_unlock(); + + return p - buf; +} + static int wakeup_sources_stats_open(struct inode *inode, struct file *file) { return seq_open_private(file, &wakeup_sources_stats_seq_ops, sizeof(int)); diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h index 6e6a25220c56..347100640b0a 100644 --- a/include/linux/pm_wakeup.h +++ b/include/linux/pm_wakeup.h @@ -118,6 +118,7 @@ extern void __pm_relax(struct wakeup_source *ws); extern void pm_relax(struct device *dev); extern void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard); extern void pm_wakeup_dev_event(struct device *dev, unsigned int msec, bool hard); +extern int wakelock_dump_active_info(char *buf, int size); #else /* !CONFIG_PM_SLEEP */