Skip to contentSkip to conversation

runtime pm: add sysfs debug files

PATCH Superseded Dominik Brodowski 3 participants 8 messages Apr 11, 2010 – Apr 23, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 runtime pm: add sysfs debug files

Add a few sysfs files relating to runtime power management for advanced debug purposes:

runtime_status: what state is the device in currently? E.g., it
reports "disabled" if runtime power management is disabled for a device, "suspended" for runtime-suspended devices, and "active" for active devices.

runtime_usage: the runtime PM usage count of a device

runtime_children: the runtime PM children usage count of a device, or
0 if the ignore_children flag is set.

Also, CONFIG_PM_SLEEP_ADVANCED_DEBUG is not defined in any Kconfig file, so replace it with CONFIG_PM_ADVANCED_DEBUG.

drivers/base/power/sysfs.c +51 -3
index 86fd937..6ba0f06 100644
@@ -5,6 +5,7 @@
 #include <linux/device.h>
 #include <linux/string.h>
 #include <linux/pm_runtime.h>
+#include <asm/atomic.h>
 #include "power.h"
 
 /*
@@ -143,7 +144,49 @@ wake_store(struct device * dev, struct device_attribute *attr,
 
 static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
 
-#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
+#ifdef CONFIG_PM_ADVANCED_DEBUG
+#ifdef CONFIG_PM_RUNTIME
+
+static ssize_t usagecount_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", atomic_read(&dev->power.usage_count));
+}
+
+static ssize_t children_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", dev->power.ignore_children ?
+		0 : atomic_read(&dev->power.child_count));
+}
+
+static ssize_t rtpm_show(struct device *dev,
+			 struct device_attribute *attr, char *buf)
+{
+	int status = dev->power.runtime_status;
+	if (dev->power.disable_depth)
+		return sprintf(buf, "disabled\n");
+	if (dev->power.runtime_auto == false)
+		return sprintf(buf, "forbidden\n");
+	switch (status) {
+	case RPM_SUSPENDED:
+		return sprintf(buf, "suspended\n");
+	case RPM_SUSPENDING:
+		return sprintf(buf, "to be suspended\n");
+	case RPM_RESUMING:
+		return sprintf(buf, "to be resumed\n");
+	case RPM_ACTIVE:
+		return sprintf(buf, "active\n");
+	}
+	return -EIO;
+}
+
+static DEVICE_ATTR(runtime_usage, 0444, usagecount_show, NULL);
+static DEVICE_ATTR(runtime_children, 0444, children_show, NULL);
+static DEVICE_ATTR(runtime_status, 0444, rtpm_show, NULL);
+
+#endif
+
 static ssize_t async_show(struct device *dev, struct device_attribute *attr,
 			  char *buf)
 {
@@ -170,15 +213,20 @@ static ssize_t async_store(struct device *dev, struct device_attribute *attr,
 }
 
 static DEVICE_ATTR(async, 0644, async_show, async_store);
-#endif /* CONFIG_PM_SLEEP_ADVANCED_DEBUG */
+#endif /* CONFIG_PM_ADVANCED_DEBUG */
 
 static struct attribute * power_attrs[] = {
 #ifdef CONFIG_PM_RUNTIME
 	&dev_attr_control.attr,
 #endif
 	&dev_attr_wakeup.attr,
-#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
+#ifdef CONFIG_PM_ADVANCED_DEBUG
 	&dev_attr_async.attr,
+#ifdef CONFIG_PM_RUNTIME
+	&dev_attr_runtime_usage.attr,
+	&dev_attr_runtime_children.attr,
+	&dev_attr_runtime_status.attr,
+#endif
 #endif
 	NULL,
 };
#1 lore raw
Quoted 10 lines · Dominik Brodowski

Add a few sysfs files relating to runtime power management for advanced debug purposes:

runtime_status: what state is the device in currently? E.g., it
reports "disabled" if runtime power management is disabled for a device, "suspended" for runtime-suspended devices, and "active" for active devices.

runtime_usage: the runtime PM usage count of a device

Quoted 7 lines

runtime_children: the runtime PM children usage count of a device, or
0 if the ignore_children flag is set.

Also, CONFIG_PM_SLEEP_ADVANCED_DEBUG is not defined in any Kconfig file, so replace it with CONFIG_PM_ADVANCED_DEBUG.

Just a couple of minor comments...

Quoted 15 lines
drivers/base/power/sysfs.c +10 -1
@@ -143,7 +144,49 @@ wake_store(struct device * dev, struct device_attribute *attr,
 
 static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
 
-#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
+#ifdef CONFIG_PM_ADVANCED_DEBUG
+#ifdef CONFIG_PM_RUNTIME
+
+static ssize_t usagecount_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", atomic_read(&dev->power.usage_count));
+}
+
+static ssize_t children_show(struct device *dev,

drivers/base/power/sysfs.c wake_store(struct device * dev, struct device_attribute *attr, · line 166

Quoted 10 lines
drivers/base/power/sysfs.c +10 -0
+			     struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", dev->power.ignore_children ?
+		0 : atomic_read(&dev->power.child_count));
+}
+
+static ssize_t rtpm_show(struct device *dev,
+			 struct device_attribute *attr, char *buf)
+{
+	int status = dev->power.runtime_status;

You don't need this variable. Use dev->power.runtime_status directly in the switch statement.

drivers/base/power/sysfs.c wake_store(struct device * dev, struct device_attribute *attr, · line 170

Quoted 4 lines
drivers/base/power/sysfs.c +4 -0
+	if (dev->power.disable_depth)
+		return sprintf(buf, "disabled\n");
+	if (dev->power.runtime_auto == false)
+		return sprintf(buf, "forbidden\n");

The logic here isn't right. A "disabled" device can be either suspended or active. The same holds for a "forbidden" device (although the suspended-and-forbidden combination would be rather unusual). And a device can be both "disabled" and "forbidden".

In addition, you need to check for the runtime error state. In this state, a device is neither active nor suspended.

drivers/base/power/sysfs.c wake_store(struct device * dev, struct device_attribute *attr, · line 175

Quoted 5 lines
drivers/base/power/sysfs.c +5 -0
+	switch (status) {
+	case RPM_SUSPENDED:
+		return sprintf(buf, "suspended\n");
+	case RPM_SUSPENDING:
+		return sprintf(buf, "to be suspended\n");

Use "suspending", not "to be suspended".

drivers/base/power/sysfs.c wake_store(struct device * dev, struct device_attribute *attr, · line 177

Quoted 2 lines
drivers/base/power/sysfs.c +2 -0
+	case RPM_RESUMING:
+		return sprintf(buf, "to be resumed\n");

Use "resuming", not "to be resumed".

drivers/base/power/sysfs.c wake_store(struct device * dev, struct device_attribute *attr, · line 185

Quoted 8 lines
drivers/base/power/sysfs.c +8 -0
+	case RPM_ACTIVE:
+		return sprintf(buf, "active\n");
+	}
+	return -EIO;
+}
+
+static DEVICE_ATTR(runtime_usage, 0444, usagecount_show, NULL);
+static DEVICE_ATTR(runtime_children, 0444, children_show, NULL);

"runtime_children" seems like a slightly odd name. It isn't the number of children; it's the number of _active_ children. But I don't have any suggestions for a better name.

Alan Stern

#2 lore raw

PATCH v2 1/1 runtime pm: add sysfs debug files

Alan,

many thanks for your comments!

Quoted 9 lines · Alan Stern

Review

Quoted 4 lines
(quoted diff) +4 -0
+	if (dev->power.disable_depth)
+		return sprintf(buf, "disabled\n");
+	if (dev->power.runtime_auto == false)
+		return sprintf(buf, "forbidden\n");

The logic here isn't right. A "disabled" device can be either suspended or active. The same holds for a "forbidden" device (although the suspended-and-forbidden combination would be rather unusual). And a device can be both "disabled" and "forbidden".

Might it be better to move this to a different file, then?

Quoted 2 lines

In addition, you need to check for the runtime error state. In this state, a device is neither active nor suspended.

Okay. Is the check I added sufficient?

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+static DEVICE_ATTR(runtime_usage, 0444, usagecount_show, NULL);
+static DEVICE_ATTR(runtime_children, 0444, children_show, NULL);

"runtime_children" seems like a slightly odd name. It isn't the number of children; it's the number of _active_ children. But I don't have any suggestions for a better name.

What about "runtime_active_kids"?

From: Dominik Brodowski <[email protected]>
Date: Sun, 11 Apr 2010 15:56:49 +0200
Subject: [PATCH] runtime pm: add sysfs debug files

Add a few sysfs files relating to runtime power management for advanced debug purposes:

runtime_enabled: is runtime PM enabled for this device? States
are "enabled", "disabled", "forbidden" or a combination of the latter two.

runtime_status: what state is the device in currently? E.g., it
reports "suspended" for runtime-suspended devices, and "active" for active devices. NOTE: if runtime_enabled returns "disabled", the value of this file may not reflect its physical state.

runtime_usage: the runtime PM usage count of a device

runtime_active_kids: the runtime PM children usage count of a device, or
0 if the ignore_children flag is set.

Also, CONFIG_PM_SLEEP_ADVANCED_DEBUG is not defined in any Kconfig file, so replace it with CONFIG_PM_ADVANCED_DEBUG.

drivers/base/power/sysfs.c +62 -3
index 86fd937..a4c33bc 100644
@@ -5,6 +5,7 @@
 #include <linux/device.h>
 #include <linux/string.h>
 #include <linux/pm_runtime.h>
+#include <asm/atomic.h>
 #include "power.h"
 
 /*
@@ -143,7 +144,59 @@ wake_store(struct device * dev, struct device_attribute *attr,
 
 static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
 
-#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
+#ifdef CONFIG_PM_ADVANCED_DEBUG
+#ifdef CONFIG_PM_RUNTIME
+
+static ssize_t rtpm_usagecount_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", atomic_read(&dev->power.usage_count));
+}
+
+static ssize_t rtpm_children_show(struct device *dev,
+				  struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", dev->power.ignore_children ?
+		0 : atomic_read(&dev->power.child_count));
+}
+
+static ssize_t rtpm_enabled_show(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	if ((dev->power.disable_depth) && (dev->power.runtime_auto == false))
+		return sprintf(buf, "disabled & forbidden\n");
+	else if (dev->power.disable_depth)
+		return sprintf(buf, "disabled\n");
+	else if (dev->power.runtime_auto == false)
+		return sprintf(buf, "forbidden\n");
+	return sprintf(buf, "enabled\n");
+}
+
+static ssize_t rtpm_status_show(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	if (dev->power.runtime_error)
+		return sprintf(buf, "error\n");
+	switch (dev->power.runtime_status) {
+	case RPM_SUSPENDED:
+		return sprintf(buf, "suspended\n");
+	case RPM_SUSPENDING:
+		return sprintf(buf, "suspending\n");
+	case RPM_RESUMING:
+		return sprintf(buf, "resuming\n");
+	case RPM_ACTIVE:
+		return sprintf(buf, "active\n");
+	}
+	return -EIO;
+}
+
+static DEVICE_ATTR(runtime_usage, 0444, rtpm_usagecount_show, NULL);
+static DEVICE_ATTR(runtime_active_kids, 0444, rtpm_children_show, NULL);
+static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
+static DEVICE_ATTR(runtime_enabled, 0444, rtpm_enabled_show, NULL);
+
+#endif
+
 static ssize_t async_show(struct device *dev, struct device_attribute *attr,
 			  char *buf)
 {
@@ -170,15 +223,21 @@ static ssize_t async_store(struct device *dev, struct device_attribute *attr,
 }
 
 static DEVICE_ATTR(async, 0644, async_show, async_store);
-#endif /* CONFIG_PM_SLEEP_ADVANCED_DEBUG */
+#endif /* CONFIG_PM_ADVANCED_DEBUG */
 
 static struct attribute * power_attrs[] = {
 #ifdef CONFIG_PM_RUNTIME
 	&dev_attr_control.attr,
 #endif
 	&dev_attr_wakeup.attr,
-#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
+#ifdef CONFIG_PM_ADVANCED_DEBUG
 	&dev_attr_async.attr,
+#ifdef CONFIG_PM_RUNTIME
+	&dev_attr_runtime_usage.attr,
+	&dev_attr_runtime_active_kids.attr,
+	&dev_attr_runtime_status.attr,
+	&dev_attr_runtime_enabled.attr,
+#endif
 #endif
 	NULL,
 };
Acked-by on v2 1/1
#3 lore raw
Quoted 15 lines · Dominik Brodowski

Alan,

many thanks for your comments!

Quoted 9 lines · Alan Stern

drivers/base/power/sysfs.c wake_store(struct device * dev, struct device_attribute *attr, · line 171

Quoted 4 lines
drivers/base/power/sysfs.c +4 -0
+	if (dev->power.disable_depth)
+		return sprintf(buf, "disabled\n");
+	if (dev->power.runtime_auto == false)
+		return sprintf(buf, "forbidden\n");

The logic here isn't right. A "disabled" device can be either suspended or active. The same holds for a "forbidden" device (although the suspended-and-forbidden combination would be rather unusual). And a device can be both "disabled" and "forbidden".

Quoted 1 line

Might it be better to move this to a different file, then?

Yes. The revised patch is better.

Quoted 4 lines
Quoted 2 lines

In addition, you need to check for the runtime error state. In this state, a device is neither active nor suspended.

Okay. Is the check I added sufficient?

Yes.

Quoted 8 lines
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+static DEVICE_ATTR(runtime_usage, 0444, usagecount_show, NULL);
+static DEVICE_ATTR(runtime_children, 0444, children_show, NULL);

"runtime_children" seems like a slightly odd name. It isn't the number of children; it's the number of _active_ children. But I don't have any suggestions for a better name.

What about "runtime_active_kids"?

Okay. The name doesn't have to be superb since it's only for debugging.

Quoted 19 lines

From: Dominik Brodowski <[email protected]>
Date: Sun, 11 Apr 2010 15:56:49 +0200
Subject: [PATCH] runtime pm: add sysfs debug files

Add a few sysfs files relating to runtime power management for advanced debug purposes:

runtime_enabled: is runtime PM enabled for this device? States
are "enabled", "disabled", "forbidden" or a combination of the latter two.

runtime_status: what state is the device in currently? E.g., it
reports "suspended" for runtime-suspended devices, and "active" for active devices. NOTE: if runtime_enabled returns "disabled", the value of this file may not reflect its physical state.

runtime_usage: the runtime PM usage count of a device

Quoted 7 lines

runtime_active_kids: the runtime PM children usage count of a device, or
0 if the ignore_children flag is set.

Also, CONFIG_PM_SLEEP_ADVANCED_DEBUG is not defined in any Kconfig file, so replace it with CONFIG_PM_ADVANCED_DEBUG.

#4 lore raw
Quoted 22 lines · Alan Stern
Quoted 22 lines

From: Dominik Brodowski <[email protected]>
Date: Sun, 11 Apr 2010 15:56:49 +0200
Subject: [PATCH] runtime pm: add sysfs debug files

Add a few sysfs files relating to runtime power management for advanced debug purposes:

runtime_enabled: is runtime PM enabled for this device? States
are "enabled", "disabled", "forbidden" or a combination of the latter two.

runtime_status: what state is the device in currently? E.g., it
reports "suspended" for runtime-suspended devices, and "active" for active devices. NOTE: if runtime_enabled returns "disabled", the value of this file may not reflect its physical state.

runtime_usage: the runtime PM usage count of a device

runtime_active_kids: the runtime PM children usage count of a device, or
0 if the ignore_children flag is set.

Quoted 6 lines
Quoted 4 lines

Also, CONFIG_PM_SLEEP_ADVANCED_DEBUG is not defined in any Kconfig file, so replace it with CONFIG_PM_ADVANCED_DEBUG.

Who shall carry it upstream? Or shall I take it directly to Linus?

Best,
Dominik

#7 lore raw
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Alan Stern
Quoted 2 lines · Dominik Brodowski
Quoted 2 lines
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Who shall carry it upstream? Or shall I take it directly to Linus?

Rafael should merge it.

Yup, I'll do that when I get back home from the LF Collab Summit.

Applied to suspend-2.6/linux-next .

Thanks,
Rafael