pm: Add runtime PM statistics to sysfs
Subsystems (4)
PATCH 1/1 pm: Add runtime PM statistics to sysfs
From: Arjan van de Ven <[email protected]>
Subject: pm: Add runtime PM statistics to sysfs
In order for PowerTOP to be able to report how well the new runtime PM is working for the various drivers, the kernel needs to export some basic statistics in sysfs.
This patch adds two sysfs files in the runtime PM domain that expose the total time a device has been active, and the time a device has been suspended.
With this PowerTOP can compute the activity percentage
Active %age = 100 * (delta active) / (delta active + delta suspended)
and present the information to the user.
I've written the PowerTOP code (slated for version 1.12) already, and the output looks like this:
Runtime Device Power Management statistics
Active Device name
10.0% 06:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8101E/RTL8102E
--
3 files changed, 58 insertions(+)
drivers/base/power/runtime.c +24 -0
@@ -123,6 +123,27 @@ int pm_runtime_idle(struct device *dev) }EXPORT_SYMBOL_GPL (pm_runtime_idle); +void update_pm_runtime_accounting (struct device *dev) +{ +unsigned long now = jiffies; +int delta; + + delta = now - dev->power.accounting_timestamp; + +if (delta <0 ) + delta =0 ; + + dev->power.accounting_timestamp = now; + +if (dev->power.disable_depth >0 ) +return ; + +if (dev->power.runtime_status ==RPM_SUSPENDED ) + dev->power.suspended_jiffies += delta; +else + dev->power.active_jiffies += delta; +} +/** * __pm_runtime_suspend - Carry out run-time suspend of given device. * @dev: Device to suspend.
@@ -237,6 +258,7 @@ int __pm_runtime_suspend(struct device *dev, bool from_wq)pm_runtime_cancel_pending (dev); } }else { +update_pm_runtime_accounting (dev); dev->power.runtime_status =RPM_SUSPENDED ;pm_runtime_deactivate_timer (dev);
@@ -411,6 +433,7 @@ int __pm_runtime_resume(struct device *dev, bool from_wq) }if (retval) { +update_pm_runtime_accounting (dev); dev->power.runtime_status =RPM_SUSPENDED ;pm_runtime_cancel_pending (dev); }else {
@@ -1077,6 +1100,7 @@ void pm_runtime_init(struct device *dev) dev->power.request_pending = false; dev->power.request =RPM_REQ_NONE ; dev->power.deferred_resume = false; + dev->power.accounting_timestamp = jiffies;INIT_WORK (&dev->power.work, pm_runtime_work); dev->power.timer_expires =0 ;
drivers/base/power/sysfs.c +28 -0
@@ -6,6 +6,7 @@#include <linux/string.h> #include <linux/pm_runtime.h> #include <asm/atomic.h> +#include <linux/jiffies.h> #include "power.h" /*
@@ -190,9 +191,34 @@ static ssize_t rtpm_status_show(struct device *dev,return -EIO ; } +static ssize_t rtpm_active_time_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +int ret; +spin_lock_irq (&dev->power.lock); +update_pm_runtime_accounting (dev); + ret =sprintf (buf,"%i\n" ,jiffies_to_msecs (dev->power.active_jiffies)); +spin_unlock_irq (&dev->power.lock); +return ret; +} + +static ssize_t rtpm_suspended_time_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +int ret; +spin_lock_irq (&dev->power.lock); +update_pm_runtime_accounting (dev); + ret =sprintf (buf,"%i\n" , +jiffies_to_msecs (dev->power.suspended_jiffies)); +spin_unlock_irq (&dev->power.lock); +return ret; +} + 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_active_time, 0444, rtpm_active_time_show, NULL); +static DEVICE_ATTR(runtime_suspended_time, 0444, rtpm_suspended_time_show, NULL); static DEVICE_ATTR(runtime_enabled, 0444, rtpm_enabled_show, NULL);#endif
@@ -234,6 +260,8 @@ static struct attribute * power_attrs[] = { &dev_attr_async.attr, #ifdef CONFIG_PM_RUNTIME &dev_attr_runtime_usage.attr, + &dev_attr_runtime_suspended_time.attr, + &dev_attr_runtime_active_time.attr, &dev_attr_runtime_active_kids.attr, &dev_attr_runtime_status.attr, &dev_attr_runtime_enabled.attr,
include/linux/pm.h +6 -0
@@ -476,9 +476,15 @@ struct dev_pm_info {enum rpm_request request;enum rpm_status runtime_status;int runtime_error; +unsigned long active_jiffies; +unsigned long suspended_jiffies; +unsigned long accounting_timestamp;#endif }; +extern void update_pm_runtime_accounting (struct device *dev); + +/* * The PM_EVENT_ messages are also used by drivers implementing the legacy * suspend framework, based on the ->suspend() and ->resume() callbacks common
Signature · 3 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org
2010/7/9 Arjan van de Ven <[email protected]>:
Quoted 6 lines
From: Arjan van de Ven <[email protected]>
include/linux/pm.h +0
-0
include/linux/pm.h struct dev_pm_info { · line 483
Quoted 8 lines
include/linux/pm.h +3
-0@@ -476,9 +476,15 @@ struct dev_pm_info { enum rpm_request request; enum rpm_status runtime_status; int runtime_error; + unsigned long active_jiffies; + unsigned long suspended_jiffies; + unsigned long accounting_timestamp; #endif };
USB subsystem has implemented the function already, and only two variables are enough to do the statistics. Suggest you to make a reference to usb implementation, maybe sizeof(unsigned long) bytes per device can be saved.
Signature · 1 line
Lei Ming
2010/7/9 Arjan van de Ven <[email protected]>:
Quoted 6 lines
From: Arjan van de Ven <[email protected]>
include/linux/pm.h +0
-0
include/linux/pm.h struct dev_pm_info { · line 483
Quoted 8 lines
include/linux/pm.h +3
-0@@ -476,9 +476,15 @@ struct dev_pm_info { enum rpm_request request; enum rpm_status runtime_status; int runtime_error; + unsigned long active_jiffies; + unsigned long suspended_jiffies; + unsigned long accounting_timestamp; #endif };
USB subsystem has implemented the function already, and only two variables are enough to do the statistics. Suggest you to make a reference to usb implementation, maybe sizeof(unsigned long) bytes per device can be saved.
Signature · 1 line
Lei Ming
Quoted 12 lines · On Fri, 9 Jul 2010 15:04:59 +0800 Ming Lei <[email protected]> wrote:
2010/7/9 Arjan van de Ven <[email protected]>:
Quoted 11 lines
From: Arjan van de Ven <[email protected]>
include/linux/pm.h +2
-0@@ -476,9 +476,15 @@ struct dev_pm_info { enum rpm_request request; enum rpm_status runtime_status; int runtime_error; + unsigned long active_jiffies; + unsigned long suspended_jiffies;
Quoted 9 lines
include/linux/pm.h struct dev_pm_info { · line 483
Quoted 3 lines
include/linux/pm.h +1
-0+ unsigned long accounting_timestamp; #endif };USB subsystem has implemented the function already, and only two variables are enough to do the statistics. Suggest you to make a reference to usb implementation, maybe sizeof(unsigned long) bytes per device can be saved.
I did look at the USB implementation, and it is very clever. But it's more complex at the same time, because you no longer can just read out the time stamps, you need to look at the current device state each time to either subtract jiffies or not.
by having the timestamp as a separate variable all the code gets a lot simpler..... sometimes simple over clever is the right thing to do.
Signature · 3 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org
Quoted 12 lines · On Fri, 9 Jul 2010 15:04:59 +0800 Ming Lei <[email protected]> wrote:
2010/7/9 Arjan van de Ven <[email protected]>:
Quoted 11 lines
From: Arjan van de Ven <[email protected]>
include/linux/pm.h +2
-0@@ -476,9 +476,15 @@ struct dev_pm_info { enum rpm_request request; enum rpm_status runtime_status; int runtime_error; + unsigned long active_jiffies; + unsigned long suspended_jiffies;
Quoted 9 lines
include/linux/pm.h struct dev_pm_info { · line 483
Quoted 3 lines
include/linux/pm.h +1
-0+ unsigned long accounting_timestamp; #endif };USB subsystem has implemented the function already, and only two variables are enough to do the statistics. Suggest you to make a reference to usb implementation, maybe sizeof(unsigned long) bytes per device can be saved.
I did look at the USB implementation, and it is very clever. But it's more complex at the same time, because you no longer can just read out the time stamps, you need to look at the current device state each time to either subtract jiffies or not.
by having the timestamp as a separate variable all the code gets a lot simpler..... sometimes simple over clever is the right thing to do.
Signature · 7 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Quoted 24 lines · Arjan van de Ven
From: Arjan van de Ven <[email protected]>
Subject: pm: Add runtime PM statistics to sysfsIn order for PowerTOP to be able to report how well the new runtime PM is working for the various drivers, the kernel needs to export some basic statistics in sysfs.
This patch adds two sysfs files in the runtime PM domain that expose the total time a device has been active, and the time a device has been suspended.
With this PowerTOP can compute the activity percentage
Active %age = 100 * (delta active) / (delta active + delta suspended)
and present the information to the user.
I've written the PowerTOP code (slated for version 1.12) already, and the output looks like this:
Runtime Device Power Management statistics
Active Device name
10.0% 06:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8101E/RTL8102E
drivers/base/power/runtime.c int __pm_runtime_resume(struct device *dev, bool from_wq) · line 439
Quoted 7 lines
drivers/base/power/runtime.c +1
-0@@ -411,6 +433,7 @@ int __pm_runtime_resume(struct device *dev, bool from_wq) }if (retval) { +update_pm_runtime_accounting (dev); dev->power.runtime_status =RPM_SUSPENDED ;pm_runtime_cancel_pending (dev); }else {
This line was added in the wrong place. It belongs either before the "if (retval) {" or after the "} else {".
Alan Stern
Quoted 24 lines · Arjan van de Ven
From: Arjan van de Ven <[email protected]>
Subject: pm: Add runtime PM statistics to sysfsIn order for PowerTOP to be able to report how well the new runtime PM is working for the various drivers, the kernel needs to export some basic statistics in sysfs.
This patch adds two sysfs files in the runtime PM domain that expose the total time a device has been active, and the time a device has been suspended.
With this PowerTOP can compute the activity percentage
Active %age = 100 * (delta active) / (delta active + delta suspended)
and present the information to the user.
I've written the PowerTOP code (slated for version 1.12) already, and the output looks like this:
Runtime Device Power Management statistics
Active Device name
10.0% 06:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8101E/RTL8102E
drivers/base/power/runtime.c int __pm_runtime_resume(struct device *dev, bool from_wq) · line 439
Quoted 7 lines
drivers/base/power/runtime.c +1
-0@@ -411,6 +433,7 @@ int __pm_runtime_resume(struct device *dev, bool from_wq) }if (retval) { +update_pm_runtime_accounting (dev); dev->power.runtime_status =RPM_SUSPENDED ;pm_runtime_cancel_pending (dev); }else {
This line was added in the wrong place. It belongs either before the "if (retval) {" or after the "} else {".
Alan Stern
Quoted 28 lines · Alan Stern
Quoted 26 lines · Arjan van de Ven
From: Arjan van de Ven <[email protected]>
Subject: pm: Add runtime PM statistics to sysfsIn order for PowerTOP to be able to report how well the new runtime PM is working for the various drivers, the kernel needs to export some basic statistics in sysfs.
This patch adds two sysfs files in the runtime PM domain that expose the total time a device has been active, and the time a device has been suspended.
With this PowerTOP can compute the activity percentage
Active %age = 100 * (delta active) / (delta active + delta suspended)
and present the information to the user.
I've written the PowerTOP code (slated for version 1.12) already, and the output looks like this:
Runtime Device Power Management statistics
Active Device name
10.0% 06:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8101E/RTL8102E(quoted diff) +0
-0@@ -411,6 +433,7 @@ int __pm_runtime_resume(struct device *dev, bool from_wq) }
Quoted 8 lines
drivers/base/power/runtime.c int __pm_runtime_resume(struct device *dev, bool from_wq) · line 439
Quoted 5 lines
drivers/base/power/runtime.c +1
-0if (retval) { +update_pm_runtime_accounting (dev); dev->power.runtime_status =RPM_SUSPENDED ;pm_runtime_cancel_pending (dev); }else {This line was added in the wrong place. It belongs either before the "if (retval) {" or after the "} else {".
Whoops, sorry, my mistake. It doesn't belong here at all. It belongs considerably earlier in the function, before the line:
dev->power.runtime_status = RPM_RESUMING;
This is because update_pm_runtime_accounting() doesn't take into account the existence of the RPM_RESUMING and RPM_SUSPENDING states; it treats them all the same as RPM_ACTIVE.
Also, it looks like you forgot to add a call in__pm_runtime_set_status().
Alan Stern
Quoted 28 lines · Alan Stern
Quoted 26 lines · Arjan van de Ven
From: Arjan van de Ven <[email protected]>
Subject: pm: Add runtime PM statistics to sysfsIn order for PowerTOP to be able to report how well the new runtime PM is working for the various drivers, the kernel needs to export some basic statistics in sysfs.
This patch adds two sysfs files in the runtime PM domain that expose the total time a device has been active, and the time a device has been suspended.
With this PowerTOP can compute the activity percentage
Active %age = 100 * (delta active) / (delta active + delta suspended)
and present the information to the user.
I've written the PowerTOP code (slated for version 1.12) already, and the output looks like this:
Runtime Device Power Management statistics
Active Device name
10.0% 06:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8101E/RTL8102E(quoted diff) +0
-0@@ -411,6 +433,7 @@ int __pm_runtime_resume(struct device *dev, bool from_wq) }
Quoted 8 lines
drivers/base/power/runtime.c int __pm_runtime_resume(struct device *dev, bool from_wq) · line 439
Quoted 5 lines
drivers/base/power/runtime.c +1
-0if (retval) { +update_pm_runtime_accounting (dev); dev->power.runtime_status =RPM_SUSPENDED ;pm_runtime_cancel_pending (dev); }else {This line was added in the wrong place. It belongs either before the "if (retval) {" or after the "} else {".
Whoops, sorry, my mistake. It doesn't belong here at all. It belongs considerably earlier in the function, before the line:
dev->power.runtime_status = RPM_RESUMING;
This is because update_pm_runtime_accounting() doesn't take into account the existence of the RPM_RESUMING and RPM_SUSPENDING states; it treats them all the same as RPM_ACTIVE.
Also, it looks like you forgot to add a call in__pm_runtime_set_status().
Alan Stern
Quoted 43 lines · On Fri, 9 Jul 2010 11:11:06 -0400 (EDT) Alan Stern <[email protected]>…
Quoted 32 lines · Alan Stern
Quoted 30 lines · Arjan van de Ven
From: Arjan van de Ven <[email protected]>
Subject: pm: Add runtime PM statistics to sysfsIn order for PowerTOP to be able to report how well the new runtime PM is working for the various drivers, the kernel needs to export some basic statistics in sysfs.
This patch adds two sysfs files in the runtime PM domain that expose the total time a device has been active, and the time a device has been suspended.
With this PowerTOP can compute the activity percentage
Active %age = 100 * (delta active) / (delta active + delta suspended)
and present the information to the user.
I've written the PowerTOP code (slated for version 1.12) already, and the output looks like this:
Runtime Device Power Management statistics
Active Device name
10.0% 06:00.0 Ethernet controller: Realtek Semiconductor
Co., Ltd. RTL8101E/RTL8102E(quoted diff) +0
-0@@ -411,6 +433,7 @@ int __pm_runtime_resume(struct device *dev, bool from_wq) }Quoted 8 lines
drivers/base/power/runtime.c int __pm_runtime_resume(struct device *dev, bool from_wq) · line 439
Quoted 5 lines
drivers/base/power/runtime.c +1
-0if (retval) { +update_pm_runtime_accounting (dev); dev->power.runtime_status =RPM_SUSPENDED ;pm_runtime_cancel_pending (dev); }else {This line was added in the wrong place. It belongs either before the "if (retval) {" or after the "} else {".
Quoted 2 lines
Whoops, sorry, my mistake. It doesn't belong here at all. It belongs considerably earlier in the function, before the line:
you are correct.
I'll fix it, I think I'll make a small helper that does the account and assignment in one place, so that we then can have a rule that nobody updates this field without calling the function
Signature · 3 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org
Quoted 43 lines · On Fri, 9 Jul 2010 11:11:06 -0400 (EDT) Alan Stern <[email protected]>…
Quoted 32 lines · Alan Stern
Quoted 30 lines · Arjan van de Ven
From: Arjan van de Ven <[email protected]>
Subject: pm: Add runtime PM statistics to sysfsIn order for PowerTOP to be able to report how well the new runtime PM is working for the various drivers, the kernel needs to export some basic statistics in sysfs.
This patch adds two sysfs files in the runtime PM domain that expose the total time a device has been active, and the time a device has been suspended.
With this PowerTOP can compute the activity percentage
Active %age = 100 * (delta active) / (delta active + delta suspended)
and present the information to the user.
I've written the PowerTOP code (slated for version 1.12) already, and the output looks like this:
Runtime Device Power Management statistics
Active Device name
10.0% 06:00.0 Ethernet controller: Realtek Semiconductor
Co., Ltd. RTL8101E/RTL8102E(quoted diff) +0
-0@@ -411,6 +433,7 @@ int __pm_runtime_resume(struct device *dev, bool from_wq) }Quoted 8 lines
drivers/base/power/runtime.c int __pm_runtime_resume(struct device *dev, bool from_wq) · line 439
Quoted 5 lines
drivers/base/power/runtime.c +1
-0if (retval) { +update_pm_runtime_accounting (dev); dev->power.runtime_status =RPM_SUSPENDED ;pm_runtime_cancel_pending (dev); }else {This line was added in the wrong place. It belongs either before the "if (retval) {" or after the "} else {".
Quoted 2 lines
Whoops, sorry, my mistake. It doesn't belong here at all. It belongs considerably earlier in the function, before the line:
you are correct.
I'll fix it, I think I'll make a small helper that does the account and assignment in one place, so that we then can have a rule that nobody updates this field without calling the function
Signature · 3 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org
Quoted 4 lines · On Fri, 9 Jul 2010 11:11:06 -0400 (EDT) Alan Stern <[email protected]>…
This is because
update_pm_runtime_accounting()doesn't take into account the existence of theRPM_RESUMINGandRPM_SUSPENDINGstates; it treats them all the same asRPM_ACTIVE.
this is by design fwiw; I'm considering the time spent going in and out of suspend as "active", it's a little on the conservative side, but the underlying assumption is that you're still burning power until you're really suspended. Better to be conservative and not count it as really suspended....
Signature · 3 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org
Quoted 4 lines · On Fri, 9 Jul 2010 11:11:06 -0400 (EDT) Alan Stern <[email protected]>…
This is because
update_pm_runtime_accounting()doesn't take into account the existence of theRPM_RESUMINGandRPM_SUSPENDINGstates; it treats them all the same asRPM_ACTIVE.
this is by design fwiw; I'm considering the time spent going in and out of suspend as "active", it's a little on the conservative side, but the underlying assumption is that you're still burning power until you're really suspended. Better to be conservative and not count it as really suspended....
Signature · 3 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org