[PATCH] Export URB statistics for powertop.
Sarah Sharp <[email protected]>
| Newsgroups | gmane.linux.usb.devel |
|---|---|
| Message-ID | <20071003215603.GA6317@localdomain> |
powertop currently tracks interrupts generated by uhci and ehci, but it has no way of telling which USB device to blame interrupts on. This patch exports the number of URBs that complete for a given device. Cat the file 'urbnum' in /sys/bus/usb/devices/.../ Signed-off-by: Sarah Sharp <[email protected]> --- drivers/usb/core/driver.c | 1 + drivers/usb/core/hcd.c | 1 + drivers/usb/core/sysfs.c | 11 +++++++++++ include/linux/usb.h | 1 + 4 files changed, 14 insertions(+), 0 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 63b1243..125406a 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -170,6 +170,7 @@ static int usb_probe_device(struct device *dev) * unless the driver suports autosuspend. */ udev->pm_usage_cnt = !(udriver->supports_autosuspend); + atomic_set(&udev->urb_cnt, 0); error = udriver->probe(udev); return error; diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 42ef1d5..102c523 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -1174,6 +1174,7 @@ void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb) { urb_unlink(hcd, urb); usbmon_urb_complete (&hcd->self, urb); + atomic_inc(&urb->dev->urb_cnt); usb_unanchor_urb(urb); /* pass ownership to the completion handler */ diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 2ab222b..c4e4cdf 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c @@ -169,6 +169,16 @@ show_quirks(struct device *dev, struct device_attribute *attr, char *buf) } static DEVICE_ATTR(quirks, S_IRUGO, show_quirks, NULL); +static ssize_t +show_urbnum(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct usb_device *udev; + + udev = to_usb_device(dev); + return sprintf(buf, "%d\n", atomic_read(&udev->urb_cnt)); +} +static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL); + #if defined(CONFIG_USB_PERSIST) || defined(CONFIG_USB_SUSPEND) static const char power_group[] = "power"; @@ -420,6 +430,7 @@ static struct attribute *dev_attrs[] = { &dev_attr_bConfigurationValue.attr, &dev_attr_bmAttributes.attr, &dev_attr_bMaxPower.attr, + &dev_attr_urbnum.attr, /* device attributes */ &dev_attr_idVendor.attr, &dev_attr_idProduct.attr, diff --git a/include/linux/usb.h b/include/linux/usb.h index 4f33a58..3d88ff7 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -405,6 +405,7 @@ struct usb_device { int pm_usage_cnt; /* usage counter for autosuspend */ u32 quirks; /* quirks of the whole device */ + atomic_t urb_cnt; /* number of URBs completed for the whole device */ #ifdef CONFIG_PM struct delayed_work autosuspend; /* for delayed autosuspends */ -- 1.5.2.4 ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ [email protected] To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel