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

Commit 2c9f5fa9 authored by Tri Vo's avatar Tri Vo Committed by Tri Vo
Browse files

UPSTREAM: PM / wakeup: Show wakeup sources stats in sysfs



Add an ID and a device pointer to 'struct wakeup_source'. Use them to to
expose wakeup sources statistics in sysfs under
/sys/class/wakeup/wakeup<ID>/*.

Co-developed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Co-developed-by: default avatarStephen Boyd <swboyd@chromium.org>
Signed-off-by: default avatarStephen Boyd <swboyd@chromium.org>
Signed-off-by: default avatarTri Vo <trong@android.com>
Tested-by: default avatarKalesh Singh <kaleshsingh@google.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
(cherry picked from commit c8377adfa78103be5380200eb9dab764d7ca890e)
Bug: 129087298
Signed-off-by: default avatarTri Vo <trong@google.com>
Change-Id: Iecd3412423f9d499981f44d3b69507eaa62a2cd9
parent 5bc2bdfb
Loading
Loading
Loading
Loading
+76 −0
Original line number Diff line number Diff line
What:		/sys/class/wakeup/
Date:		June 2019
Contact:	Tri Vo <trong@android.com>
Description:
		The /sys/class/wakeup/ directory contains pointers to all
		wakeup sources in the kernel at that moment in time.

What:		/sys/class/wakeup/.../name
Date:		June 2019
Contact:	Tri Vo <trong@android.com>
Description:
		This file contains the name of the wakeup source.

What:		/sys/class/wakeup/.../active_count
Date:		June 2019
Contact:	Tri Vo <trong@android.com>
Description:
		This file contains the number of times the wakeup source was
		activated.

What:		/sys/class/wakeup/.../event_count
Date:		June 2019
Contact:	Tri Vo <trong@android.com>
Description:
		This file contains the number of signaled wakeup events
		associated with the wakeup source.

What:		/sys/class/wakeup/.../wakeup_count
Date:		June 2019
Contact:	Tri Vo <trong@android.com>
Description:
		This file contains the number of times the wakeup source might
		abort suspend.

What:		/sys/class/wakeup/.../expire_count
Date:		June 2019
Contact:	Tri Vo <trong@android.com>
Description:
		This file contains the number of times the wakeup source's
		timeout has expired.

What:		/sys/class/wakeup/.../active_time_ms
Date:		June 2019
Contact:	Tri Vo <trong@android.com>
Description:
		This file contains the amount of time the wakeup source has
		been continuously active, in milliseconds.  If the wakeup
		source is not active, this file contains '0'.

What:		/sys/class/wakeup/.../total_time_ms
Date:		June 2019
Contact:	Tri Vo <trong@android.com>
Description:
		This file contains the total amount of time this wakeup source
		has been active, in milliseconds.

What:		/sys/class/wakeup/.../max_time_ms
Date:		June 2019
Contact:	Tri Vo <trong@android.com>
Description:
		This file contains the maximum amount of time this wakeup
		source has been continuously active, in milliseconds.

What:		/sys/class/wakeup/.../last_change_ms
Date:		June 2019
Contact:	Tri Vo <trong@android.com>
Description:
		This file contains the monotonic clock time when the wakeup
		source was touched last time, in milliseconds.

What:		/sys/class/wakeup/.../prevent_suspend_time_ms
Date:		June 2019
Contact:	Tri Vo <trong@android.com>
Description:
		The file contains the total amount of time this wakeup source
		has been preventing autosleep, in milliseconds.
+2 −1
Original line number Diff line number Diff line
@@ -455,7 +455,8 @@ acpi_status acpi_add_pm_notifier(struct acpi_device *adev, struct device *dev,
		goto out;

	mutex_lock(&acpi_pm_notifier_lock);
	adev->wakeup.ws = wakeup_source_register(dev_name(&adev->dev));
	adev->wakeup.ws = wakeup_source_register(&adev->dev,
						 dev_name(&adev->dev));
	adev->wakeup.context.dev = dev;
	adev->wakeup.context.func = func;
	adev->wakeup.flags.notifier_present = true;
+1 −1
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_PM)	+= sysfs.o generic_ops.o common.o qos.o runtime.o wakeirq.o
obj-$(CONFIG_PM_SLEEP)	+= main.o wakeup.o
obj-$(CONFIG_PM_SLEEP)	+= main.o wakeup.o wakeup_stats.o
obj-$(CONFIG_PM_TRACE_RTC)	+= trace.o
obj-$(CONFIG_PM_GENERIC_DOMAINS)	+=  domain.o domain_governor.o
obj-$(CONFIG_HAVE_CLK)	+= clock_ops.o
+9 −0
Original line number Diff line number Diff line
@@ -148,3 +148,12 @@ static inline void device_pm_init(struct device *dev)
	device_pm_sleep_init(dev);
	pm_runtime_init(dev);
}

#ifdef CONFIG_PM_SLEEP

/* drivers/base/power/wakeup_stats.c */
extern int wakeup_source_sysfs_add(struct device *parent,
				   struct wakeup_source *ws);
extern void wakeup_source_sysfs_remove(struct wakeup_source *ws);

#endif /* CONFIG_PM_SLEEP */
+24 −4
Original line number Diff line number Diff line
@@ -73,6 +73,8 @@ static struct wakeup_source deleted_ws = {
	.lock =  __SPIN_LOCK_UNLOCKED(deleted_ws.lock),
};

static DEFINE_IDA(wakeup_ida);

/**
 * wakeup_source_create - Create a struct wakeup_source object.
 * @name: Name of the new wakeup source.
@@ -81,6 +83,7 @@ struct wakeup_source *wakeup_source_create(const char *name)
{
	struct wakeup_source *ws;
	const char *ws_name;
	int id;

	ws = kzalloc(sizeof(*ws), GFP_KERNEL);
	if (!ws)
@@ -91,8 +94,15 @@ struct wakeup_source *wakeup_source_create(const char *name)
		goto err_name;
	ws->name = ws_name;

	id = ida_alloc(&wakeup_ida, GFP_KERNEL);
	if (id < 0)
		goto err_id;
	ws->id = id;

	return ws;

err_id:
	kfree_const(ws->name);
err_name:
	kfree(ws);
err_ws:
@@ -141,6 +151,7 @@ void wakeup_source_destroy(struct wakeup_source *ws)

	__pm_relax(ws);
	wakeup_source_record(ws);
	ida_free(&wakeup_ida, ws->id);
	kfree_const(ws->name);
	kfree(ws);
}
@@ -194,16 +205,24 @@ EXPORT_SYMBOL_GPL(wakeup_source_remove);

/**
 * wakeup_source_register - Create wakeup source and add it to the list.
 * @dev: Device this wakeup source is associated with (or NULL if virtual).
 * @name: Name of the wakeup source to register.
 */
struct wakeup_source *wakeup_source_register(const char *name)
struct wakeup_source *wakeup_source_register(struct device *dev,
					     const char *name)
{
	struct wakeup_source *ws;
	int ret;

	ws = wakeup_source_create(name);
	if (ws)
	if (ws) {
		ret = wakeup_source_sysfs_add(dev, ws);
		if (ret) {
			wakeup_source_destroy(ws);
			return NULL;
		}
		wakeup_source_add(ws);

	}
	return ws;
}
EXPORT_SYMBOL_GPL(wakeup_source_register);
@@ -216,6 +235,7 @@ void wakeup_source_unregister(struct wakeup_source *ws)
{
	if (ws) {
		wakeup_source_remove(ws);
		wakeup_source_sysfs_remove(ws);
		wakeup_source_destroy(ws);
	}
}
@@ -259,7 +279,7 @@ int device_wakeup_enable(struct device *dev)
	if (pm_suspend_target_state != PM_SUSPEND_ON)
		dev_dbg(dev, "Suspicious %s() during system transition!\n", __func__);

	ws = wakeup_source_register(dev_name(dev));
	ws = wakeup_source_register(dev, dev_name(dev));
	if (!ws)
		return -ENOMEM;

Loading