From 1512300689426cb98bfd7e567ee9fdfaaf61b7c7 Mon Sep 17 00:00:00 2001 From: Sarah Sharp Date: Fri, 21 Dec 2007 16:54:15 -0800 Subject: 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 Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hub.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'drivers/usb/core/hub.c') diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index cc93aa9336f..53fe049b40f 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) if (udev->children[i]) recursively_mark_NOTATTACHED(udev->children[i]); } - if (udev->state == USB_STATE_SUSPENDED) + if (udev->state == USB_STATE_SUSPENDED) { udev->discon_suspended = 1; + udev->active_duration -= jiffies; + } udev->state = USB_STATE_NOTATTACHED; } @@ -1084,6 +1086,12 @@ void usb_set_device_state(struct usb_device *udev, else device_init_wakeup(&udev->dev, 0); } + if (udev->state == USB_STATE_SUSPENDED && + new_state != USB_STATE_SUSPENDED) + udev->active_duration -= jiffies; + else if (new_state == USB_STATE_SUSPENDED && + udev->state != USB_STATE_SUSPENDED) + udev->active_duration += jiffies; udev->state = new_state; } else recursively_mark_NOTATTACHED(udev); -- cgit v1.2.3