diff options
author | Sarah Sharp <saharabeara@gmail.com> | 2007-12-21 19:54:15 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-02-01 17:35:00 -0500 |
commit | 1512300689426cb98bfd7e567ee9fdfaaf61b7c7 (patch) | |
tree | a275493675fe7bc6b666d1c6a8179e103c7a199c /drivers/usb/core/hub.c | |
parent | 228426edac844a2c9270528e9cd7ab6260ef7628 (diff) |
USB: Export suspend statistics
This patch exports two statistics to userspace:
/sys/bus/usb/device/.../power/connected_duration
/sys/bus/usb/device/.../power/active_duration
connected_duration is the total time (in msec) that the device has
been connected. active_duration is the total time the device has not
been suspended. With these two statistics, tools like PowerTOP can
calculate the percentage time that a device is active, i.e. not
suspended or auto-suspended.
Users can also use the active_duration to check if a device is actually
autosuspended. Currently, they can set power/level to auto and
power/autosuspend to a positive timeout, but there's no way to know from
userspace if a device was actually autosuspended without looking at the
dmesg output. These statistics will be useful in creating an automated
userspace script to test autosuspend for USB devices.
Signed-off-by: Sarah Sharp <sarah.a.sharp@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/core/hub.c')
-rw-r--r-- | drivers/usb/core/hub.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index cc93aa9336fe..53fe049b40f5 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -1034,8 +1034,10 @@ static void recursively_mark_NOTATTACHED(struct usb_device *udev) | |||
1034 | if (udev->children[i]) | 1034 | if (udev->children[i]) |
1035 | recursively_mark_NOTATTACHED(udev->children[i]); | 1035 | recursively_mark_NOTATTACHED(udev->children[i]); |
1036 | } | 1036 | } |
1037 | if (udev->state == USB_STATE_SUSPENDED) | 1037 | if (udev->state == USB_STATE_SUSPENDED) { |
1038 | udev->discon_suspended = 1; | 1038 | udev->discon_suspended = 1; |
1039 | udev->active_duration -= jiffies; | ||
1040 | } | ||
1039 | udev->state = USB_STATE_NOTATTACHED; | 1041 | udev->state = USB_STATE_NOTATTACHED; |
1040 | } | 1042 | } |
1041 | 1043 | ||
@@ -1084,6 +1086,12 @@ void usb_set_device_state(struct usb_device *udev, | |||
1084 | else | 1086 | else |
1085 | device_init_wakeup(&udev->dev, 0); | 1087 | device_init_wakeup(&udev->dev, 0); |
1086 | } | 1088 | } |
1089 | if (udev->state == USB_STATE_SUSPENDED && | ||
1090 | new_state != USB_STATE_SUSPENDED) | ||
1091 | udev->active_duration -= jiffies; | ||
1092 | else if (new_state == USB_STATE_SUSPENDED && | ||
1093 | udev->state != USB_STATE_SUSPENDED) | ||
1094 | udev->active_duration += jiffies; | ||
1087 | udev->state = new_state; | 1095 | udev->state = new_state; |
1088 | } else | 1096 | } else |
1089 | recursively_mark_NOTATTACHED(udev); | 1097 | recursively_mark_NOTATTACHED(udev); |