* [PATCH] power:sysfs: Expose device wakeup_event_count.
@ 2019-07-22 18:02 Ravi Chandra Sadineni
2019-07-22 18:22 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: Ravi Chandra Sadineni @ 2019-07-22 18:02 UTC (permalink / raw)
To: tglx, mingo, bp, hpa, x86, rjw, pavel, len.brown, gregkh,
ravisadineni, bhe, dyoung, linux-kernel, linux-pm, tbroch
Device level event_count can help user level daemon to track if a
praticular device has seen an wake interrupt during a suspend resume
cycle. Thus expose it via sysfs.
Signed-off-by: Ravi Chandra Sadineni <ravisadineni@chromium.org>
---
Documentation/ABI/testing/sysfs-devices-power | 11 ++++++++++
drivers/base/power/sysfs.c | 20 +++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-devices-power b/Documentation/ABI/testing/sysfs-devices-power
index 1ca04b4f0489..344549f4013f 100644
--- a/Documentation/ABI/testing/sysfs-devices-power
+++ b/Documentation/ABI/testing/sysfs-devices-power
@@ -89,6 +89,17 @@ Description:
attribute is not present. If the device is not enabled to wake
up the system from sleep states, this attribute is empty.
+What: /sys/devices/.../power/wakeup_event_count
+Date: July 2019
+Contact: Ravi Chandra sadineni <ravisadineni@chromium.org>
+Description:
+ The /sys/devices/.../wakeup_event_count attribute contains the
+ number of signaled wakeup events associated with the device.
+ This attribute is read-only. If the device is not capable to
+ wake up the system from sleep states, this attribute is not
+ present. If the device is not enabled to wake up the system
+ from sleep states, this attribute is empty.
+
What: /sys/devices/.../power/wakeup_active_count
Date: September 2010
Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index f42044d9711c..8dc1235b9784 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -357,6 +357,25 @@ static ssize_t wakeup_count_show(struct device *dev,
static DEVICE_ATTR_RO(wakeup_count);
+static ssize_t wakeup_event_count_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ unsigned long count = 0;
+ bool enabled = false;
+
+ spin_lock_irq(&dev->power.lock);
+ if (dev->power.wakeup) {
+ count = dev->power.wakeup->event_count;
+ enabled = true;
+ }
+ spin_unlock_irq(&dev->power.lock);
+ return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
+}
+
+static DEVICE_ATTR_RO(wakeup_event_count);
+
+
+
static ssize_t wakeup_active_count_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -561,6 +580,7 @@ static struct attribute *wakeup_attrs[] = {
#ifdef CONFIG_PM_SLEEP
&dev_attr_wakeup.attr,
&dev_attr_wakeup_count.attr,
+ &dev_attr_wakeup_event_count.attr,
&dev_attr_wakeup_active_count.attr,
&dev_attr_wakeup_expire_count.attr,
&dev_attr_wakeup_active.attr,
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] power:sysfs: Expose device wakeup_event_count.
2019-07-22 18:02 [PATCH] power:sysfs: Expose device wakeup_event_count Ravi Chandra Sadineni
@ 2019-07-22 18:22 ` Greg KH
2019-07-23 16:43 ` Ravi Chandra Sadineni
0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2019-07-22 18:22 UTC (permalink / raw)
To: Ravi Chandra Sadineni
Cc: tglx, mingo, bp, hpa, x86, rjw, pavel, len.brown, bhe, dyoung,
linux-kernel, linux-pm, tbroch
On Mon, Jul 22, 2019 at 11:02:58AM -0700, Ravi Chandra Sadineni wrote:
> Device level event_count can help user level daemon to track if a
> praticular device has seen an wake interrupt during a suspend resume
> cycle. Thus expose it via sysfs.
>
> Signed-off-by: Ravi Chandra Sadineni <ravisadineni@chromium.org>
> ---
> Documentation/ABI/testing/sysfs-devices-power | 11 ++++++++++
> drivers/base/power/sysfs.c | 20 +++++++++++++++++++
> 2 files changed, 31 insertions(+)
>
> diff --git a/Documentation/ABI/testing/sysfs-devices-power b/Documentation/ABI/testing/sysfs-devices-power
> index 1ca04b4f0489..344549f4013f 100644
> --- a/Documentation/ABI/testing/sysfs-devices-power
> +++ b/Documentation/ABI/testing/sysfs-devices-power
> @@ -89,6 +89,17 @@ Description:
> attribute is not present. If the device is not enabled to wake
> up the system from sleep states, this attribute is empty.
>
> +What: /sys/devices/.../power/wakeup_event_count
> +Date: July 2019
> +Contact: Ravi Chandra sadineni <ravisadineni@chromium.org>
> +Description:
> + The /sys/devices/.../wakeup_event_count attribute contains the
> + number of signaled wakeup events associated with the device.
> + This attribute is read-only. If the device is not capable to
> + wake up the system from sleep states, this attribute is not
> + present. If the device is not enabled to wake up the system
> + from sleep states, this attribute is empty.
The attribute is not "empty" it returns just an empty line.
Is that really a good thing if you are expecting a number?
> +
> What: /sys/devices/.../power/wakeup_active_count
> Date: September 2010
> Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
> diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
> index f42044d9711c..8dc1235b9784 100644
> --- a/drivers/base/power/sysfs.c
> +++ b/drivers/base/power/sysfs.c
> @@ -357,6 +357,25 @@ static ssize_t wakeup_count_show(struct device *dev,
>
> static DEVICE_ATTR_RO(wakeup_count);
>
> +static ssize_t wakeup_event_count_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + unsigned long count = 0;
> + bool enabled = false;
> +
> + spin_lock_irq(&dev->power.lock);
> + if (dev->power.wakeup) {
> + count = dev->power.wakeup->event_count;
> + enabled = true;
> + }
> + spin_unlock_irq(&dev->power.lock);
Why do you need to lock? The state and count can change right after the
lock, so what does this help with?
> + return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
Use a real if statement please.
> +}
> +
> +static DEVICE_ATTR_RO(wakeup_event_count);
> +
> +
> +
too many empty lines :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] power:sysfs: Expose device wakeup_event_count.
2019-07-22 18:22 ` Greg KH
@ 2019-07-23 16:43 ` Ravi Chandra Sadineni
0 siblings, 0 replies; 3+ messages in thread
From: Ravi Chandra Sadineni @ 2019-07-23 16:43 UTC (permalink / raw)
To: Greg KH
Cc: tglx, mingo, bp, hpa, x86, rjw, pavel, len.brown, bhe, dyoung,
linux-kernel, linux-pm, Todd Broch
Hi Greg,
On Mon, Jul 22, 2019 at 11:22 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Mon, Jul 22, 2019 at 11:02:58AM -0700, Ravi Chandra Sadineni wrote:
> > Device level event_count can help user level daemon to track if a
> > praticular device has seen an wake interrupt during a suspend resume
> > cycle. Thus expose it via sysfs.
> >
> > Signed-off-by: Ravi Chandra Sadineni <ravisadineni@chromium.org>
> > ---
> > Documentation/ABI/testing/sysfs-devices-power | 11 ++++++++++
> > drivers/base/power/sysfs.c | 20 +++++++++++++++++++
> > 2 files changed, 31 insertions(+)
> >
> > diff --git a/Documentation/ABI/testing/sysfs-devices-power b/Documentation/ABI/testing/sysfs-devices-power
> > index 1ca04b4f0489..344549f4013f 100644
> > --- a/Documentation/ABI/testing/sysfs-devices-power
> > +++ b/Documentation/ABI/testing/sysfs-devices-power
> > @@ -89,6 +89,17 @@ Description:
> > attribute is not present. If the device is not enabled to wake
> > up the system from sleep states, this attribute is empty.
> >
> > +What: /sys/devices/.../power/wakeup_event_count
> > +Date: July 2019
> > +Contact: Ravi Chandra sadineni <ravisadineni@chromium.org>
> > +Description:
> > + The /sys/devices/.../wakeup_event_count attribute contains the
> > + number of signaled wakeup events associated with the device.
> > + This attribute is read-only. If the device is not capable to
> > + wake up the system from sleep states, this attribute is not
> > + present. If the device is not enabled to wake up the system
> > + from sleep states, this attribute is empty.
>
> The attribute is not "empty" it returns just an empty line.
Corrected the description.
>
> Is that really a good thing if you are expecting a number?
This is to adhere to the convention as described in
base/power/sysfs.c. Hope this is o.k
>
> > +
> > What: /sys/devices/.../power/wakeup_active_count
> > Date: September 2010
> > Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
> > diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
> > index f42044d9711c..8dc1235b9784 100644
> > --- a/drivers/base/power/sysfs.c
> > +++ b/drivers/base/power/sysfs.c
> > @@ -357,6 +357,25 @@ static ssize_t wakeup_count_show(struct device *dev,
> >
> > static DEVICE_ATTR_RO(wakeup_count);
> >
> > +static ssize_t wakeup_event_count_show(struct device *dev,
> > + struct device_attribute *attr, char *buf)
> > +{
> > + unsigned long count = 0;
> > + bool enabled = false;
> > +
> > + spin_lock_irq(&dev->power.lock);
> > + if (dev->power.wakeup) {
> > + count = dev->power.wakeup->event_count;
> > + enabled = true;
> > + }
> > + spin_unlock_irq(&dev->power.lock);
>
> Why do you need to lock? The state and count can change right after the
> lock, so what does this help with?
power.wakeup can be NULL (device_wakeup_detach ()) if wakeup is
disabled for a particular device.
>
> > + return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
>
> Use a real if statement please.
>
> > +}
> > +
> > +static DEVICE_ATTR_RO(wakeup_event_count);
> > +
> > +
> > +
>
> too many empty lines :)
Removed the empty lines.
>
> thanks,
>
> greg k-h
Thanks,
Ravi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-23 16:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22 18:02 [PATCH] power:sysfs: Expose device wakeup_event_count Ravi Chandra Sadineni
2019-07-22 18:22 ` Greg KH
2019-07-23 16:43 ` Ravi Chandra Sadineni
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).