[RFC PATCH] usb/core: add current frame_number sysfs attr to hcd

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This allows user space to retrieve the current frame number on a USB
as returned by usb_get_current_frame_number(...) via sysfs.

Signed-off-by: Stefan Tauner <stefan.tauner@xxxxxxxxxxxxxxxxxxxx>
---
That's sadly not necessarily the raw value seen on the bus because
the individual driver functions called by usb_get_current_frame_number(...)
seem to limit the possible range to the "schedule horizon" of isochronous
packets. IMHO the function name is a misnomer and I would like to hear your
opinion on this, a possible new name for it and a better way to retrieve the
real/raw value.

The rationale for this patch can be found in the thread with the subject
"Correlating SOF with host system time" from last december
(201212042020.qB4KKt0N008541@xxxxxxxxxxxxxxxxxxxxxxxxxx).
My whole use case/idea was kinda frowned upon then, but there was little
discussion about how it should/could be implemented in the kernel code in
case one really wants to try it.

Adding the sysfs attribute was the easiest way for me to communicate
this to user space, but at least for my use case a non-polling approach
would have been better. Any suggestions on how this could be done by a
newbie like me are very welcome.

The patch is against version 3.8.0-6.13 of the Ubuntu 13.04 development
kernel, but I really hope it is simple enough to apply upstream, but
I don't expect it to get merged as is anyway, so please don't flame too
much if it does not cleanly. :)

I have tested it on my Ubuntu 12.04 system, lspci -nn | grep USB
00:1a.0 USB controller [0c03]: Intel Corporation 5 Series/3400 Series Chipset USB2 Enhanced Host Controller [8086:3b3c] (rev 06)
00:1d.0 USB controller [0c03]: Intel Corporation 5 Series/3400 Series Chipset USB2 Enhanced Host Controller [8086:3b34] (rev 06)

It creates two files:
/sys/devices/pci0000\:00/0000\:00\:1a.0/usb1/frame_number
and
/sys/devices/pci0000\:00/0000\:00\:1d.0/usb2/frame_number
which contain sane, distinct, looping values between 0 and about 2^10 - 1
---
 drivers/usb/core/hcd.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 8e64adf..9c8e9ab 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -862,10 +862,26 @@ static DEVICE_ATTR(authorized_default, 0644,
 	    usb_host_authorized_default_show,
 	    usb_host_authorized_default_store);
 
+/*
+ * Show the current frame number as returned by usb_get_current_frame_number()
+ * (or a negative value in the case of errors)
+ */
+static ssize_t usb_bus_frame_number_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)
+{
+	struct usb_device *rh_usb_dev = to_usb_device(dev);
+	int fn = usb_get_current_frame_number(rh_usb_dev);
+	return snprintf(buf, PAGE_SIZE, "%d\n", fn);
+}
+
+static DEVICE_ATTR(frame_number, S_IRUGO, usb_bus_frame_number_show, NULL);
+
 
 /* Group all the USB bus attributes */
 static struct attribute *usb_bus_attrs[] = {
 		&dev_attr_authorized_default.attr,
+		&dev_attr_frame_number.attr,
 		NULL,
 };
 
-- 
Kind regards, Stefan Tauner

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux