Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 97f0960e authored by Ruchi Kandoi's avatar Ruchi Kandoi Committed by Alistair Strachan
Browse files

ANDROID: power: wakeup_reason: add an API to log wakeup reasons



Add API log_wakeup_reason() and expose it to userspace via sysfs path
/sys/kernel/wakeup_reasons/last_resume_reason

Bug: 120445600
Signed-off-by: default avatarRuchi Kandoi <kandoiruchi@google.com>
[AmitP: Folded following android-4.9 commit changes into this patch
        1135122a192a ("ANDROID: POWER: fix compile warnings in log_wakeup_reason")
        b4e6247778b0 ("ANDROID: Power: Changes the permission to read only for sysfs file /sys/kernel/wakeup_reasons/last_resume_reason")
        e13dbc7c69cd ("ANDROID: power: wakeup_reason: rename irq_count to irqcount")]
Signed-off-by: default avatarAmit Pundir <amit.pundir@linaro.org>
[astrachan: Folded the following changes into this patch:
            39d7c7fe91c0 ("ANDROID: power: wakeup_reason: Add guard condition for maximum wakeup reasons")
            0730434bdf49 ("ANDROID: power: wakeup_reason: Avoids bogus error messages for the suspend aborts.")
            4e42dceae54e ("ANDROID: power: wakeup_reason: Adds functionality to log the last suspend abort reason.")
            f21313b70ac7 ("ANDROID: power: wakeup_reason: Report suspend times from last_suspend_time")
            f97ec34442ac ("ANDROID: power: wakeup_reason: fix suspend time reporting")
            cd92df73e504 ("ANDROID: power: wakeup: Add last wake up source logging for suspend abort reason.")
            546b6ae3c087 ("ANDROID: power: wakeup: Add the guard condition for len in pm_get_active_wakeup_sources")
            1453d9ffcdbe ("ANDROID: power: wakeup_reason: make logging work in an interrupt context.")]
Change-Id: I81addaf420f1338255c5d0638b0d244a99d777d1
Signed-off-by: default avatarAlistair Strachan <astrachan@google.com>
parent 7a38c5ff
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
What:		/sys/kernel/wakeup_reasons/last_resume_reason
Date:		February 2014
Contact:	Ruchi Kandoi <kandoiruchi@google.com>
Description:
		The /sys/kernel/wakeup_reasons/last_resume_reason is
		used to report wakeup reasons after system exited suspend.

What:		/sys/kernel/wakeup_reasons/last_suspend_time
Date:		March 2015
Contact:	jinqian <jinqian@google.com>
Description:
		The /sys/kernel/wakeup_reasons/last_suspend_time is
		used to report time spent in last suspend cycle. It contains
		two numbers (in seconds) separated by space. First number is
		the time spent in suspend and resume processes. Second number
		is the time spent in sleep state.
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <linux/cpufreq.h>
#include <linux/cpuidle.h>
#include <linux/timer.h>
#include <linux/wakeup_reason.h>

#include "../base.h"
#include "power.h"
@@ -1706,6 +1707,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
	pm_callback_t callback = NULL;
	const char *info = NULL;
	int error = 0;
	char suspend_abort[MAX_SUSPEND_ABORT_LEN];
	DECLARE_DPM_WATCHDOG_ON_STACK(wd);

	TRACE_DEVICE(dev);
@@ -1729,6 +1731,9 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)

	if (pm_wakeup_pending()) {
		dev->power.direct_complete = false;
		pm_get_active_wakeup_sources(suspend_abort,
			MAX_SUSPEND_ABORT_LEN);
		log_suspend_abort_reason(suspend_abort);
		async_error = -EBUSY;
		goto Complete;
	}
+32 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include <linux/seq_file.h>
#include <linux/debugfs.h>
#include <linux/pm_wakeirq.h>
#include <linux/types.h>
#include <trace/events/power.h>

#include "power.h"
@@ -803,6 +804,37 @@ void pm_wakeup_dev_event(struct device *dev, unsigned int msec, bool hard)
}
EXPORT_SYMBOL_GPL(pm_wakeup_dev_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;

	rcu_read_lock();
	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);
	}
	rcu_read_unlock();
}
EXPORT_SYMBOL_GPL(pm_get_active_wakeup_sources);

void pm_print_active_wakeup_sources(void)
{
	struct wakeup_source *ws;
+3 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#include <linux/module.h>
#include <linux/suspend.h>
#include <trace/events/power.h>
#include <linux/wakeup_reason.h>

static LIST_HEAD(syscore_ops_list);
static DEFINE_MUTEX(syscore_ops_lock);
@@ -74,6 +75,8 @@ int syscore_suspend(void)
	return 0;

 err_out:
	log_suspend_abort_reason("System core suspend callback %pF failed",
		ops->suspend);
	pr_err("PM: System core suspend callback %pF failed.\n", ops->suspend);

	list_for_each_entry_continue(ops, &syscore_ops_list, node)
+1 −0
Original line number Diff line number Diff line
@@ -446,6 +446,7 @@ 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);
extern void pm_print_active_wakeup_sources(void);
extern void pm_get_active_wakeup_sources(char *pending_sources, size_t max);

extern void lock_system_sleep(void);
extern void unlock_system_sleep(void);
Loading