linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Tri Vo <trong@android.com>
Cc: rjw@rjwysocki.net, viresh.kumar@linaro.org, rafael@kernel.org,
	hridya@google.com, sspatil@google.com, kaleshsingh@google.com,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	kernel-team@android.com
Subject: Re: [PATCH v3] PM / wakeup: show wakeup sources stats in sysfs
Date: Mon, 15 Jul 2019 22:36:51 +0200	[thread overview]
Message-ID: <20190715203651.GA7513@kroah.com> (raw)
In-Reply-To: <20190715201116.221078-1-trong@android.com>

On Mon, Jul 15, 2019 at 01:11:16PM -0700, Tri Vo wrote:
> Userspace can use wakeup_sources debugfs node to plot history of suspend
> blocking wakeup sources over device's boot cycle. This information can
> then be used (1) for power-specific bug reporting and (2) towards
> attributing battery consumption to specific processes over a period of
> time.
> 
> However, debugfs doesn't have stable ABI. For this reason, create a
> 'struct device' to expose wakeup sources statistics in sysfs under
> /sys/class/wakeup/<name>/.
> 
> Introduce CONFIG_PM_SLEEP_STATS that enables/disables showing wakeup
> source statistics in sysfs.
> 
> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Tri Vo <trong@android.com>
> Tested-by: Tri Vo <trong@android.com>

Co-Developed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
perhaps given that I rewrote the whole file last time?  :)


> ---
>  Documentation/ABI/testing/sysfs-power |  73 ++++++++++++-
>  drivers/base/power/Makefile           |   1 +
>  drivers/base/power/wakeup.c           |  12 ++-
>  drivers/base/power/wakeup_stats.c     | 148 ++++++++++++++++++++++++++
>  include/linux/pm_wakeup.h             |  19 ++++
>  kernel/power/Kconfig                  |  10 ++
>  kernel/power/wakelock.c               |  10 ++
>  7 files changed, 270 insertions(+), 3 deletions(-)
>  create mode 100644 drivers/base/power/wakeup_stats.c

What changed from v2?  :)

> diff --git a/Documentation/ABI/testing/sysfs-power b/Documentation/ABI/testing/sysfs-power
> index 18b7dc929234..ef92628e6fc3 100644
> --- a/Documentation/ABI/testing/sysfs-power
> +++ b/Documentation/ABI/testing/sysfs-power
> @@ -300,4 +300,75 @@ Description:
>  		attempt.
>  
>  		Using this sysfs file will override any values that were
> -		set using the kernel command line for disk offset.
> \ No newline at end of file
> +		set using the kernel command line for disk offset.
> +
> +What:		/sys/class/wakeup/

My fault, this should be a new ABI/testing file, don't use sysfs-power
as it does not make any sense now, right?

> --- /dev/null
> +++ b/drivers/base/power/wakeup_stats.c
> @@ -0,0 +1,148 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Wakeup statistics in sysfs
> + *
> + * Copyright (c) 2019 Linux Foundation <gregkh@linuxfoundation.org>

My fault on the original here, this line should be 2 lines:

> + * Copyright (c) 2019 Linux Foundation
> + * Copyright (c) 2019 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

as those are two different entities that have copyright here on this
file.

> +config PM_SLEEP_STATS
> +	bool "Wakeup sources statistics"
> +	depends on PM_SLEEP
> +	help
> +	  Expose wakeup sources statistics to user space via sysfs. Collected
> +	  statistics are located under /sys/power/wakeup_sources. For more
> +	  information, read <file:Documentation/ABI/testing/sysfs-power>.

Filename should be changed.


> +
> +	  If in doubt, say N.
> +
>  config DPM_WATCHDOG
>  	bool "Device suspend/resume watchdog"
>  	depends on PM_DEBUG && PSTORE && EXPERT
> diff --git a/kernel/power/wakelock.c b/kernel/power/wakelock.c
> index 4210152e56f0..32726da3d6e6 100644
> --- a/kernel/power/wakelock.c
> +++ b/kernel/power/wakelock.c
> @@ -122,6 +122,7 @@ static void __wakelocks_gc(struct work_struct *work)
>  
>  		if (!active) {
>  			wakeup_source_remove(&wl->ws);
> +			wakeup_source_sysfs_remove(&wl->ws);
>  			rb_erase(&wl->node, &wakelocks_tree);
>  			list_del(&wl->lru);
>  			kfree(wl->name);
> @@ -153,6 +154,7 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len,
>  	struct rb_node **node = &wakelocks_tree.rb_node;
>  	struct rb_node *parent = *node;
>  	struct wakelock *wl;
> +	int ret;
>  
>  	while (*node) {
>  		int diff;
> @@ -189,6 +191,14 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len,
>  	}
>  	wl->ws.name = wl->name;
>  	wl->ws.last_time = ktime_get();
> +
> +	ret = wakeup_source_sysfs_add(&wl->ws);
> +	if (ret) {
> +		kfree(wl->name);
> +		kfree(wl);
> +		return ERR_PTR(ret);
> +	}
> +
>  	wakeup_source_add(&wl->ws);
>  	rb_link_node(&wl->node, parent, node);
>  	rb_insert_color(&wl->node, &wakelocks_tree);

Nice, you got rid of the extra change in this file, making this much
simpler.

Can you make these minor tweaks?  If so, I'll be glad to queue this up
after 5.3-rc1 is out.

And I am guessing that you actually tested this all out, and it works
for you?  Have you changed Android userspace to use the new api with no
problems?

thanks,

greg k-h

  reply	other threads:[~2019-07-15 20:37 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-26  0:54 [PATCH] PM / wakeup: show wakeup sources stats in sysfs Tri Vo
2019-06-26  0:59 ` Tri Vo
2019-06-26  1:12 ` Greg KH
2019-06-26  1:33   ` Tri Vo
2019-06-26  1:46     ` Greg KH
2019-06-26 22:26       ` Tri Vo
2019-06-26 22:48     ` Tri Vo
2019-06-27  0:04       ` Greg KH
2019-06-27 22:53         ` [PATCH v2] " Tri Vo
2019-06-28 15:10           ` Greg KH
2019-07-04 10:31             ` Rafael J. Wysocki
2019-07-08  3:33               ` Tri Vo
2019-07-15 20:11                 ` [PATCH v3] " Tri Vo
2019-07-15 20:36                   ` Greg KH [this message]
2019-07-15 21:43                     ` [PATCH v4] " Tri Vo
2019-07-15 21:48                       ` Rafael J. Wysocki
2019-07-16  2:11                         ` Greg Kroah-Hartman
2019-07-16  4:16                           ` Tri Vo
2019-07-16  8:30                           ` Rafael J. Wysocki
2019-07-16  8:39                             ` Greg Kroah-Hartman
2019-07-16  9:36                               ` Rafael J. Wysocki
2019-07-15 21:48                     ` [PATCH v3] " Tri Vo
2019-07-16  2:12                       ` Greg KH
2019-06-27 22:57         ` [PATCH] " Tri Vo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190715203651.GA7513@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=hridya@google.com \
    --cc=kaleshsingh@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=sspatil@google.com \
    --cc=trong@android.com \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).