linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] PM-runtime: Documentation: add runtime_status ABI document
@ 2019-09-01 14:08 Akinobu Mita
  2019-09-01 14:08 ` [PATCH 2/2] PM-runtime: allow userspace to monitor runtime_status changes Akinobu Mita
  2019-09-01 14:23 ` [PATCH 1/2] PM-runtime: Documentation: add runtime_status ABI document Dominik Brodowski
  0 siblings, 2 replies; 7+ messages in thread
From: Akinobu Mita @ 2019-09-01 14:08 UTC (permalink / raw)
  To: linux-leds, linux-pm
  Cc: Akinobu Mita, Alan Stern, Dominik Brodowski, Rafael J. Wysocki

/sys/devices/.../power/runtime_status is introduced by commit c92445fadb91
("PM / Runtime: Add sysfs debug files").  Then commit 0fcb4eef8294 ("PM /
Runtime: Make runtime_status attribute not debug-only (v. 2)") made the
runtime_status attribute available without CONFIG_PM_ADVANCED_DEBUG.

This adds missing runtime_status ABI document.

Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 Documentation/ABI/testing/sysfs-devices-power | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-devices-power b/Documentation/ABI/testing/sysfs-devices-power
index 80a00f7..3e50536 100644
--- a/Documentation/ABI/testing/sysfs-devices-power
+++ b/Documentation/ABI/testing/sysfs-devices-power
@@ -260,3 +260,12 @@ Description:
 
 		This attribute has no effect on system-wide suspend/resume and
 		hibernation.
+
+What:		/sys/devices/.../power/runtime_status
+Date:		April 2010
+Contact:	Dominik Brodowski <linux@dominikbrodowski.net>
+Description:
+		The /sys/devices/.../power/runtime_status attribute contains
+		the current runtime PM status of the device, which may be
+		"suspended", "suspending", "resuming", "active", "error" (fatal
+		error), or "unsupported" (runtime PM is disabled).
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] PM-runtime: allow userspace to monitor runtime_status changes
  2019-09-01 14:08 [PATCH 1/2] PM-runtime: Documentation: add runtime_status ABI document Akinobu Mita
@ 2019-09-01 14:08 ` Akinobu Mita
  2019-09-02 21:47   ` Rafael J. Wysocki
  2019-09-01 14:23 ` [PATCH 1/2] PM-runtime: Documentation: add runtime_status ABI document Dominik Brodowski
  1 sibling, 1 reply; 7+ messages in thread
From: Akinobu Mita @ 2019-09-01 14:08 UTC (permalink / raw)
  To: linux-leds, linux-pm
  Cc: Akinobu Mita, Alan Stern, Dominik Brodowski, Rafael J. Wysocki

This enables the /sys/devices/.../power/runtime_status attribute to
allow the user space to get notifications via poll/select when the device
runtime PM status is changed.

An example use case is to avoid unnecessary accesses for device statistics
(e.g. diskstats for block devices) while the device is in runtime suspend
by user space LED device actitity trigger.

Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 Documentation/ABI/testing/sysfs-devices-power | 2 ++
 drivers/base/power/power.h                    | 1 +
 drivers/base/power/runtime.c                  | 1 +
 drivers/base/power/sysfs.c                    | 5 +++++
 4 files changed, 9 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-devices-power b/Documentation/ABI/testing/sysfs-devices-power
index 3e50536..47dc357 100644
--- a/Documentation/ABI/testing/sysfs-devices-power
+++ b/Documentation/ABI/testing/sysfs-devices-power
@@ -269,3 +269,5 @@ Description:
 		the current runtime PM status of the device, which may be
 		"suspended", "suspending", "resuming", "active", "error" (fatal
 		error), or "unsupported" (runtime PM is disabled).
+		This attribute allows the user space to get notifications via
+		poll/select when the device runtime PM status is changed.
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index ec33fbdb..8891bf4 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -74,6 +74,7 @@ extern int pm_qos_sysfs_add_flags(struct device *dev);
 extern void pm_qos_sysfs_remove_flags(struct device *dev);
 extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev);
 extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev);
+extern void sysfs_notify_runtime_status(struct device *dev);
 
 #else /* CONFIG_PM */
 
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index b753355..3a3e413 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -94,6 +94,7 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
 {
 	update_pm_runtime_accounting(dev);
 	dev->power.runtime_status = status;
+	sysfs_notify_runtime_status(dev);
 }
 
 static u64 rpm_get_accounted_time(struct device *dev, bool suspended)
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 1b9c281c..e86d8cb 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -734,3 +734,8 @@ void dpm_sysfs_remove(struct device *dev)
 	sysfs_unmerge_group(&dev->kobj, &pm_wakeup_attr_group);
 	sysfs_remove_group(&dev->kobj, &pm_attr_group);
 }
+
+void sysfs_notify_runtime_status(struct device *dev)
+{
+	sysfs_notify(&dev->kobj, "power", "runtime_status");
+}
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] PM-runtime: Documentation: add runtime_status ABI document
  2019-09-01 14:08 [PATCH 1/2] PM-runtime: Documentation: add runtime_status ABI document Akinobu Mita
  2019-09-01 14:08 ` [PATCH 2/2] PM-runtime: allow userspace to monitor runtime_status changes Akinobu Mita
@ 2019-09-01 14:23 ` Dominik Brodowski
  2019-09-02 21:39   ` Rafael J. Wysocki
  1 sibling, 1 reply; 7+ messages in thread
From: Dominik Brodowski @ 2019-09-01 14:23 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: linux-leds, linux-pm, Alan Stern, Rafael J. Wysocki

Hi!

On Sun, Sep 01, 2019 at 11:08:51PM +0900, Akinobu Mita wrote:
> +What:		/sys/devices/.../power/runtime_status
> +Date:		April 2010
> +Contact:	Dominik Brodowski <linux@dominikbrodowski.net>

Thanks for the patch! I am not sure, however, whether I am the right contact
person here -- maybe Rafael J. Wysocki as PM maintainer?

Thanks,
	Dominik

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] PM-runtime: Documentation: add runtime_status ABI document
  2019-09-01 14:23 ` [PATCH 1/2] PM-runtime: Documentation: add runtime_status ABI document Dominik Brodowski
@ 2019-09-02 21:39   ` Rafael J. Wysocki
  0 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2019-09-02 21:39 UTC (permalink / raw)
  To: Dominik Brodowski, Akinobu Mita
  Cc: linux-leds, Linux PM, Alan Stern, Rafael J. Wysocki

On Sun, Sep 1, 2019 at 4:30 PM Dominik Brodowski
<linux@dominikbrodowski.net> wrote:
>
> Hi!
>
> On Sun, Sep 01, 2019 at 11:08:51PM +0900, Akinobu Mita wrote:
> > +What:                /sys/devices/.../power/runtime_status
> > +Date:                April 2010
> > +Contact:     Dominik Brodowski <linux@dominikbrodowski.net>
>
> Thanks for the patch! I am not sure, however, whether I am the right contact
> person here -- maybe Rafael J. Wysocki as PM maintainer?

Right, please follow the convention used for the other attributes
documented in this file.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] PM-runtime: allow userspace to monitor runtime_status changes
  2019-09-01 14:08 ` [PATCH 2/2] PM-runtime: allow userspace to monitor runtime_status changes Akinobu Mita
@ 2019-09-02 21:47   ` Rafael J. Wysocki
  2019-09-03 13:13     ` Akinobu Mita
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2019-09-02 21:47 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: linux-leds, Linux PM, Alan Stern, Dominik Brodowski, Rafael J. Wysocki

On Sun, Sep 1, 2019 at 4:09 PM Akinobu Mita <akinobu.mita@gmail.com> wrote:
>
> This enables the /sys/devices/.../power/runtime_status attribute to
> allow the user space to get notifications via poll/select when the device
> runtime PM status is changed.
>
> An example use case is to avoid unnecessary accesses for device statistics
> (e.g. diskstats for block devices) while the device is in runtime suspend
> by user space LED device actitity trigger.
>
> Cc: Alan Stern <stern@rowland.harvard.edu>
> Cc: Dominik Brodowski <linux@dominikbrodowski.net>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> ---
>  Documentation/ABI/testing/sysfs-devices-power | 2 ++
>  drivers/base/power/power.h                    | 1 +
>  drivers/base/power/runtime.c                  | 1 +
>  drivers/base/power/sysfs.c                    | 5 +++++
>  4 files changed, 9 insertions(+)
>
> diff --git a/Documentation/ABI/testing/sysfs-devices-power b/Documentation/ABI/testing/sysfs-devices-power
> index 3e50536..47dc357 100644
> --- a/Documentation/ABI/testing/sysfs-devices-power
> +++ b/Documentation/ABI/testing/sysfs-devices-power
> @@ -269,3 +269,5 @@ Description:
>                 the current runtime PM status of the device, which may be
>                 "suspended", "suspending", "resuming", "active", "error" (fatal
>                 error), or "unsupported" (runtime PM is disabled).
> +               This attribute allows the user space to get notifications via
> +               poll/select when the device runtime PM status is changed.
> diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
> index ec33fbdb..8891bf4 100644
> --- a/drivers/base/power/power.h
> +++ b/drivers/base/power/power.h
> @@ -74,6 +74,7 @@ extern int pm_qos_sysfs_add_flags(struct device *dev);
>  extern void pm_qos_sysfs_remove_flags(struct device *dev);
>  extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev);
>  extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev);
> +extern void sysfs_notify_runtime_status(struct device *dev);
>
>  #else /* CONFIG_PM */
>
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index b753355..3a3e413 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -94,6 +94,7 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
>  {
>         update_pm_runtime_accounting(dev);
>         dev->power.runtime_status = status;
> +       sysfs_notify_runtime_status(dev);

There are concerns about this.

First off, it adds overhead for devices that change the PM-runtime
status relatively often.  I'm not sure if that's sufficiently
justified.

Second, it is called for status changes from "active" to "suspending"
and from "suspending" to "suspended" (and analogously for resume)
which may not be particularly useful.  At least, user space may not
have enough time to act on such notifications.

Finally, it is racy, because at the time user space does something on
a device PM-runtime status change, it very well may have changed the
other way around already.

>  }
>
>  static u64 rpm_get_accounted_time(struct device *dev, bool suspended)
> diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
> index 1b9c281c..e86d8cb 100644
> --- a/drivers/base/power/sysfs.c
> +++ b/drivers/base/power/sysfs.c
> @@ -734,3 +734,8 @@ void dpm_sysfs_remove(struct device *dev)
>         sysfs_unmerge_group(&dev->kobj, &pm_wakeup_attr_group);
>         sysfs_remove_group(&dev->kobj, &pm_attr_group);
>  }
> +
> +void sysfs_notify_runtime_status(struct device *dev)
> +{
> +       sysfs_notify(&dev->kobj, "power", "runtime_status");
> +}
> --
> 2.7.4
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] PM-runtime: allow userspace to monitor runtime_status changes
  2019-09-02 21:47   ` Rafael J. Wysocki
@ 2019-09-03 13:13     ` Akinobu Mita
  2019-09-03 14:31       ` Alan Stern
  0 siblings, 1 reply; 7+ messages in thread
From: Akinobu Mita @ 2019-09-03 13:13 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: linux-leds, Linux PM, Alan Stern, Dominik Brodowski, Rafael J. Wysocki

2019年9月3日(火) 6:47 Rafael J. Wysocki <rafael@kernel.org>:
>
> On Sun, Sep 1, 2019 at 4:09 PM Akinobu Mita <akinobu.mita@gmail.com> wrote:
> >
> > This enables the /sys/devices/.../power/runtime_status attribute to
> > allow the user space to get notifications via poll/select when the device
> > runtime PM status is changed.
> >
> > An example use case is to avoid unnecessary accesses for device statistics
> > (e.g. diskstats for block devices) while the device is in runtime suspend
> > by user space LED device actitity trigger.
> >
> > Cc: Alan Stern <stern@rowland.harvard.edu>
> > Cc: Dominik Brodowski <linux@dominikbrodowski.net>
> > Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> > Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> > ---
> >  Documentation/ABI/testing/sysfs-devices-power | 2 ++
> >  drivers/base/power/power.h                    | 1 +
> >  drivers/base/power/runtime.c                  | 1 +
> >  drivers/base/power/sysfs.c                    | 5 +++++
> >  4 files changed, 9 insertions(+)
> >
> > diff --git a/Documentation/ABI/testing/sysfs-devices-power b/Documentation/ABI/testing/sysfs-devices-power
> > index 3e50536..47dc357 100644
> > --- a/Documentation/ABI/testing/sysfs-devices-power
> > +++ b/Documentation/ABI/testing/sysfs-devices-power
> > @@ -269,3 +269,5 @@ Description:
> >                 the current runtime PM status of the device, which may be
> >                 "suspended", "suspending", "resuming", "active", "error" (fatal
> >                 error), or "unsupported" (runtime PM is disabled).
> > +               This attribute allows the user space to get notifications via
> > +               poll/select when the device runtime PM status is changed.
> > diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
> > index ec33fbdb..8891bf4 100644
> > --- a/drivers/base/power/power.h
> > +++ b/drivers/base/power/power.h
> > @@ -74,6 +74,7 @@ extern int pm_qos_sysfs_add_flags(struct device *dev);
> >  extern void pm_qos_sysfs_remove_flags(struct device *dev);
> >  extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev);
> >  extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev);
> > +extern void sysfs_notify_runtime_status(struct device *dev);
> >
> >  #else /* CONFIG_PM */
> >
> > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> > index b753355..3a3e413 100644
> > --- a/drivers/base/power/runtime.c
> > +++ b/drivers/base/power/runtime.c
> > @@ -94,6 +94,7 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
> >  {
> >         update_pm_runtime_accounting(dev);
> >         dev->power.runtime_status = status;
> > +       sysfs_notify_runtime_status(dev);
>
> There are concerns about this.
>
> First off, it adds overhead for devices that change the PM-runtime
> status relatively often.  I'm not sure if that's sufficiently
> justified.
>
> Second, it is called for status changes from "active" to "suspending"
> and from "suspending" to "suspended" (and analogously for resume)
> which may not be particularly useful.  At least, user space may not
> have enough time to act on such notifications.
>
> Finally, it is racy, because at the time user space does something on
> a device PM-runtime status change, it very well may have changed the
> other way around already.

I withdraw this patch now.  I hope I'll retry with a real use case example
program.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] PM-runtime: allow userspace to monitor runtime_status changes
  2019-09-03 13:13     ` Akinobu Mita
@ 2019-09-03 14:31       ` Alan Stern
  0 siblings, 0 replies; 7+ messages in thread
From: Alan Stern @ 2019-09-03 14:31 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: Rafael J. Wysocki, linux-leds, Linux PM, Dominik Brodowski,
	Rafael J. Wysocki

On Tue, 3 Sep 2019, Akinobu Mita wrote:

> 2019年9月3日(火) 6:47 Rafael J. Wysocki <rafael@kernel.org>:
> >
> > On Sun, Sep 1, 2019 at 4:09 PM Akinobu Mita <akinobu.mita@gmail.com> wrote:
> > >
> > > This enables the /sys/devices/.../power/runtime_status attribute to
> > > allow the user space to get notifications via poll/select when the device
> > > runtime PM status is changed.
> > >
> > > An example use case is to avoid unnecessary accesses for device statistics
> > > (e.g. diskstats for block devices) while the device is in runtime suspend
> > > by user space LED device actitity trigger.
> > >
> > > Cc: Alan Stern <stern@rowland.harvard.edu>
> > > Cc: Dominik Brodowski <linux@dominikbrodowski.net>
> > > Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> > > Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

> > There are concerns about this.
> >
> > First off, it adds overhead for devices that change the PM-runtime
> > status relatively often.  I'm not sure if that's sufficiently
> > justified.
> >
> > Second, it is called for status changes from "active" to "suspending"
> > and from "suspending" to "suspended" (and analogously for resume)
> > which may not be particularly useful.  At least, user space may not
> > have enough time to act on such notifications.
> >
> > Finally, it is racy, because at the time user space does something on
> > a device PM-runtime status change, it very well may have changed the
> > other way around already.
> 
> I withdraw this patch now.  I hope I'll retry with a real use case example
> program.

You might want to take a look at commit 7794f486ed0b ("usbfs: Add
ioctls for runtime power management") in the usb-next branch of Greg
KH's usb.git tree.  It adds a mechanism for user programs to wait until
a device has done a runtime resume, without races.

But it is not general purpose (it applies only to USB devices), it
doesn't use poll(), and it doesn't check for other kinds of runtime PM
status changes.

Alan Stern


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-09-03 14:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-01 14:08 [PATCH 1/2] PM-runtime: Documentation: add runtime_status ABI document Akinobu Mita
2019-09-01 14:08 ` [PATCH 2/2] PM-runtime: allow userspace to monitor runtime_status changes Akinobu Mita
2019-09-02 21:47   ` Rafael J. Wysocki
2019-09-03 13:13     ` Akinobu Mita
2019-09-03 14:31       ` Alan Stern
2019-09-01 14:23 ` [PATCH 1/2] PM-runtime: Documentation: add runtime_status ABI document Dominik Brodowski
2019-09-02 21:39   ` Rafael J. Wysocki

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).