Message ID | 20191203101552.199339-1-ikjn@chromium.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | usb: override hub device bInterval with device | expand |
On Tue, 3 Dec 2019, Ikjoon Jang wrote: > This patch enables hub device to override its own endpoint descriptor's > bInterval when the hub has a device node with "hub,interval" property. > > When we know reducing autosuspend delay for built-in HIDs is better for > power saving, we can reduce it to the optimal value. But if a parent hub > has a long bInterval, mouse lags a lot from more frequent autosuspend. > So this enables overriding bInterval for a hard wired hub device only > when we know that reduces the power consumption. > > Signed-off-by: Ikjoon Jang <ikjn@chromium.org> > Acked-by: Alan Stern <stern@rowland.harvard.edu> > --- > drivers/usb/core/config.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c > index 5f40117e68e7..95ec5af42a1c 100644 > --- a/drivers/usb/core/config.c > +++ b/drivers/usb/core/config.c > @@ -6,6 +6,7 @@ > #include <linux/usb.h> > #include <linux/usb/ch9.h> > #include <linux/usb/hcd.h> > +#include <linux/usb/of.h> > #include <linux/usb/quirks.h> > #include <linux/module.h> > #include <linux/slab.h> > @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, > memcpy(&endpoint->desc, d, n); > INIT_LIST_HEAD(&endpoint->urb_list); > > + /* device node property overrides bInterval */ > + if (usb_of_has_combined_node(to_usb_device(ddev))) { > + u32 interval = 0; Coding style: there should be a blank line here. Also, you don't need the "= 0" initializer. Otherwise okay. Alan Stern > + if (!of_property_read_u32(ddev->of_node, "hub,interval", > + &interval)) > + d->bInterval = min_t(u8, interval, 255); > + } > + > /* > * Fix up bInterval values outside the legal range. > * Use 10 or 8 ms if no proper value can be guessed.
On Tue, Dec 03, 2019 at 06:15:52PM +0800, Ikjoon Jang wrote: > This patch enables hub device to override its own endpoint descriptor's > bInterval when the hub has a device node with "hub,interval" property. > > When we know reducing autosuspend delay for built-in HIDs is better for > power saving, we can reduce it to the optimal value. But if a parent hub > has a long bInterval, mouse lags a lot from more frequent autosuspend. > So this enables overriding bInterval for a hard wired hub device only > when we know that reduces the power consumption. I think I saw you argue about why this shouldn't simply be configured at runtime. Please include that here too, I can't seem to remember why... > Signed-off-by: Ikjoon Jang <ikjn@chromium.org> > Acked-by: Alan Stern <stern@rowland.harvard.edu> > --- > drivers/usb/core/config.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c > index 5f40117e68e7..95ec5af42a1c 100644 > --- a/drivers/usb/core/config.c > +++ b/drivers/usb/core/config.c > @@ -6,6 +6,7 @@ > #include <linux/usb.h> > #include <linux/usb/ch9.h> > #include <linux/usb/hcd.h> > +#include <linux/usb/of.h> > #include <linux/usb/quirks.h> > #include <linux/module.h> > #include <linux/slab.h> > @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, > memcpy(&endpoint->desc, d, n); > INIT_LIST_HEAD(&endpoint->urb_list); > > + /* device node property overrides bInterval */ > + if (usb_of_has_combined_node(to_usb_device(ddev))) { Not only hubs have combined nodes so you probably need to check bDeviceClass here instead. > + u32 interval = 0; > + if (!of_property_read_u32(ddev->of_node, "hub,interval", > + &interval)) > + d->bInterval = min_t(u8, interval, 255); You want min_t(u32, ...) here to avoid surprises when someone specifies a value > 255. > + } > + > /* > * Fix up bInterval values outside the legal range. > * Use 10 or 8 ms if no proper value can be guessed. Johan
On Wed, Dec 4, 2019 at 12:52 AM Johan Hovold <johan@kernel.org> wrote: > > On Tue, Dec 03, 2019 at 06:15:52PM +0800, Ikjoon Jang wrote: > > This patch enables hub device to override its own endpoint descriptor's > > bInterval when the hub has a device node with "hub,interval" property. > > > > When we know reducing autosuspend delay for built-in HIDs is better for > > power saving, we can reduce it to the optimal value. But if a parent hub > > has a long bInterval, mouse lags a lot from more frequent autosuspend. > > So this enables overriding bInterval for a hard wired hub device only > > when we know that reduces the power consumption. > > I think I saw you argue about why this shouldn't simply be configured at > runtime. Please include that here too, I can't seem to remember why... Okay. > > > Signed-off-by: Ikjoon Jang <ikjn@chromium.org> > > Acked-by: Alan Stern <stern@rowland.harvard.edu> > > --- > > drivers/usb/core/config.c | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c > > index 5f40117e68e7..95ec5af42a1c 100644 > > --- a/drivers/usb/core/config.c > > +++ b/drivers/usb/core/config.c > > @@ -6,6 +6,7 @@ > > #include <linux/usb.h> > > #include <linux/usb/ch9.h> > > #include <linux/usb/hcd.h> > > +#include <linux/usb/of.h> > > #include <linux/usb/quirks.h> > > #include <linux/module.h> > > #include <linux/slab.h> > > @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, > > memcpy(&endpoint->desc, d, n); > > INIT_LIST_HEAD(&endpoint->urb_list); > > > > + /* device node property overrides bInterval */ > > + if (usb_of_has_combined_node(to_usb_device(ddev))) { > > Not only hubs have combined nodes so you probably need to check > bDeviceClass here instead. yes, you're right, I didn't think of that case: if (to_usb_device(ddev)->descriptor.bDeviceClass == USB_CLASS_HUB && ddev->of_node && !of_property_read_u32(...)) Or is it better to check bInterfaceClass, for composite devices with a hub interface inside? if (ifp->desc.bInterfaceClass == USB_CLASS_HUB && ddev->of_node && !of_property_read_u32(...)) I think checking bInterfaceClass is better. > > > + u32 interval = 0; > > + if (!of_property_read_u32(ddev->of_node, "hub,interval", > > + &interval)) > > + d->bInterval = min_t(u8, interval, 255); > > You want min_t(u32, ...) here to avoid surprises when someone specifies > a value > 255. yes, thanks. > > > + } > > + > > /* > > * Fix up bInterval values outside the legal range. > > * Use 10 or 8 ms if no proper value can be guessed. > > Johan I will send v5 soon, thank you.
On Tue, Dec 3, 2019 at 11:23 PM Alan Stern <stern@rowland.harvard.edu> wrote: > > On Tue, 3 Dec 2019, Ikjoon Jang wrote: > > > This patch enables hub device to override its own endpoint descriptor's > > bInterval when the hub has a device node with "hub,interval" property. > > > > When we know reducing autosuspend delay for built-in HIDs is better for > > power saving, we can reduce it to the optimal value. But if a parent hub > > has a long bInterval, mouse lags a lot from more frequent autosuspend. > > So this enables overriding bInterval for a hard wired hub device only > > when we know that reduces the power consumption. > > > > Signed-off-by: Ikjoon Jang <ikjn@chromium.org> > > Acked-by: Alan Stern <stern@rowland.harvard.edu> > > --- > > drivers/usb/core/config.c | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c > > index 5f40117e68e7..95ec5af42a1c 100644 > > --- a/drivers/usb/core/config.c > > +++ b/drivers/usb/core/config.c > > @@ -6,6 +6,7 @@ > > #include <linux/usb.h> > > #include <linux/usb/ch9.h> > > #include <linux/usb/hcd.h> > > +#include <linux/usb/of.h> > > #include <linux/usb/quirks.h> > > #include <linux/module.h> > > #include <linux/slab.h> > > @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, > > memcpy(&endpoint->desc, d, n); > > INIT_LIST_HEAD(&endpoint->urb_list); > > > > + /* device node property overrides bInterval */ > > + if (usb_of_has_combined_node(to_usb_device(ddev))) { > > + u32 interval = 0; > > Coding style: there should be a blank line here. Also, you don't need > the "= 0" initializer. > > Otherwise okay. Okay, I will fix that. Thank you! > > Alan Stern > > > + if (!of_property_read_u32(ddev->of_node, "hub,interval", > > + &interval)) > > + d->bInterval = min_t(u8, interval, 255); > > + } > > + > > /* > > * Fix up bInterval values outside the legal range. > > * Use 10 or 8 ms if no proper value can be guessed. >
On Wed, Dec 04, 2019 at 03:04:53PM +0800, Ikjoon Jang wrote: > On Wed, Dec 4, 2019 at 12:52 AM Johan Hovold <johan@kernel.org> wrote: > > > > On Tue, Dec 03, 2019 at 06:15:52PM +0800, Ikjoon Jang wrote: > > > This patch enables hub device to override its own endpoint descriptor's > > > bInterval when the hub has a device node with "hub,interval" property. > > > > > > When we know reducing autosuspend delay for built-in HIDs is better for > > > power saving, we can reduce it to the optimal value. But if a parent hub > > > has a long bInterval, mouse lags a lot from more frequent autosuspend. > > > So this enables overriding bInterval for a hard wired hub device only > > > when we know that reduces the power consumption. > > > > I think I saw you argue about why this shouldn't simply be configured at > > runtime. Please include that here too, I can't seem to remember why... > > Okay. > > > > > > Signed-off-by: Ikjoon Jang <ikjn@chromium.org> > > > Acked-by: Alan Stern <stern@rowland.harvard.edu> > > > --- > > > drivers/usb/core/config.c | 9 +++++++++ > > > 1 file changed, 9 insertions(+) > > > > > > diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c > > > index 5f40117e68e7..95ec5af42a1c 100644 > > > --- a/drivers/usb/core/config.c > > > +++ b/drivers/usb/core/config.c > > > @@ -6,6 +6,7 @@ > > > #include <linux/usb.h> > > > #include <linux/usb/ch9.h> > > > #include <linux/usb/hcd.h> > > > +#include <linux/usb/of.h> > > > #include <linux/usb/quirks.h> > > > #include <linux/module.h> > > > #include <linux/slab.h> > > > @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, > > > memcpy(&endpoint->desc, d, n); > > > INIT_LIST_HEAD(&endpoint->urb_list); > > > > > > + /* device node property overrides bInterval */ > > > + if (usb_of_has_combined_node(to_usb_device(ddev))) { > > > > Not only hubs have combined nodes so you probably need to check > > bDeviceClass here instead. > > yes, you're right, I didn't think of that case: > if (to_usb_device(ddev)->descriptor.bDeviceClass == USB_CLASS_HUB && > ddev->of_node && !of_property_read_u32(...)) > > Or is it better to check bInterfaceClass, for composite devices with a > hub interface inside? > if (ifp->desc.bInterfaceClass == USB_CLASS_HUB && ddev->of_node && > !of_property_read_u32(...)) > > I think checking bInterfaceClass is better. Yep, that seems better (but please use two conditionals for readability). But related to my question above, why do you need to do this during enumeration? Why not just set the lower interval value in the hub driver? > > > + u32 interval = 0; > > > + if (!of_property_read_u32(ddev->of_node, "hub,interval", > > > + &interval)) > > > + d->bInterval = min_t(u8, interval, 255); > > > > You want min_t(u32, ...) here to avoid surprises when someone specifies > > a value > 255. > > yes, thanks. And I guess you should really be honouring bInterval as a maximum value, right? > > > + } > > > + > > > /* > > > * Fix up bInterval values outside the legal range. > > > * Use 10 or 8 ms if no proper value can be guessed. Johan
On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote: > > > > @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, > > > > memcpy(&endpoint->desc, d, n); > > > > INIT_LIST_HEAD(&endpoint->urb_list); > > > > > > > > + /* device node property overrides bInterval */ > > > > + if (usb_of_has_combined_node(to_usb_device(ddev))) { > > > > > > Not only hubs have combined nodes so you probably need to check > > > bDeviceClass here instead. > > > > yes, you're right, I didn't think of that case: > > if (to_usb_device(ddev)->descriptor.bDeviceClass == USB_CLASS_HUB && > > ddev->of_node && !of_property_read_u32(...)) > > > > Or is it better to check bInterfaceClass, for composite devices with a > > hub interface inside? > > if (ifp->desc.bInterfaceClass == USB_CLASS_HUB && ddev->of_node && > > !of_property_read_u32(...)) > > > > I think checking bInterfaceClass is better. > > Yep, that seems better (but please use two conditionals for > readability). > > But related to my question above, why do you need to do this during > enumeration? Why not just set the lower interval value in the hub > driver? > Because I want device tree's bInterval to be checked against the same rules defined in usb_parse_endpoint(). e.g. although hardware says its maximum is 255, but the practical limit is still 0 to 16, so the code can print warnings when bInterval from device node is too weird. > > > > + u32 interval = 0; > > > > + if (!of_property_read_u32(ddev->of_node, "hub,interval", > > > > + &interval)) > > > > + d->bInterval = min_t(u8, interval, 255); > > > > > > You want min_t(u32, ...) here to avoid surprises when someone specifies > > > a value > 255. > > > > yes, thanks. > > And I guess you should really be honouring bInterval as a maximum value, > right? Yes, right, not masking. > > > > > + } > > > > + > > > > /* > > > > * Fix up bInterval values outside the legal range. > > > > * Use 10 or 8 ms if no proper value can be guessed. > > Johan
On Thu, Dec 05, 2019 at 03:32:38PM +0800, Ikjoon Jang wrote: > On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote: > > But related to my question above, why do you need to do this during > > enumeration? Why not just set the lower interval value in the hub > > driver? > > Because I want device tree's bInterval to be checked against the same rules > defined in usb_parse_endpoint(). e.g. although hardware says its maximum > is 255, but the practical limit is still 0 to 16, so the code can > print warnings when bInterval from device node is too weird. But that could be handled refactoring the code in question or similar. The fundamental problem here is that you're using devicetree, which is supposed to only describe the hardware, to encode policy which should be deferred to user space. So I think you need to figure out an interface that allows user space to set the polling interval for any hub at runtime instead. Johan
On Thu, Dec 5, 2019 at 10:26 PM Johan Hovold <johan@kernel.org> wrote: > > On Thu, Dec 05, 2019 at 03:32:38PM +0800, Ikjoon Jang wrote: > > On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote: > > > > But related to my question above, why do you need to do this during > > > enumeration? Why not just set the lower interval value in the hub > > > driver? > > > > Because I want device tree's bInterval to be checked against the same rules > > defined in usb_parse_endpoint(). e.g. although hardware says its maximum > > is 255, but the practical limit is still 0 to 16, so the code can > > print warnings when bInterval from device node is too weird. > > But that could be handled refactoring the code in question or similar. > Yes, that should be worked. I can't exactly figure out how to refactor the code for now, but maybe parsed endpoint descriptors are being checked with default hard wired bInterval value and after that an overridden value should be checked again. Actually I don't care about the details of software policies. I just want all devices to be handled in the same manner without any further special treatments. > The fundamental problem here is that you're using devicetree, which is > supposed to only describe the hardware, to encode policy which should be > deferred to user space. The hub hardware has a default bInterval inside which is actually adjustable. So I can think setting bInterval is to describe the hardware rather than policy. > > So I think you need to figure out an interface that allows user space to > set the polling interval for any hub at runtime instead. Changing the interval at runtime is an another way to solve the power consumption problem, but it's not so easy. At least xhci needs to restart an endpoint and no devices are changing the interval after enumeration stage. Thanks! > > Johan
On Fri, 6 Dec 2019, Ikjoon Jang wrote: > On Thu, Dec 5, 2019 at 10:26 PM Johan Hovold <johan@kernel.org> wrote: > > > > On Thu, Dec 05, 2019 at 03:32:38PM +0800, Ikjoon Jang wrote: > > > On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote: > > > > > > But related to my question above, why do you need to do this during > > > > enumeration? Why not just set the lower interval value in the hub > > > > driver? > > > > > > Because I want device tree's bInterval to be checked against the same rules > > > defined in usb_parse_endpoint(). e.g. although hardware says its maximum > > > is 255, but the practical limit is still 0 to 16, so the code can > > > print warnings when bInterval from device node is too weird. > > > > But that could be handled refactoring the code in question or similar. > > > > Yes, that should be worked. I can't exactly figure out how to refactor > the code for now, but maybe parsed endpoint descriptors are being > checked with default hard wired bInterval value and after that > an overridden value should be checked again. > > Actually I don't care about the details of software policies. I just want > all devices to be handled in the same manner without any further > special treatments. > > > The fundamental problem here is that you're using devicetree, which is > > supposed to only describe the hardware, to encode policy which should be > > deferred to user space. > > The hub hardware has a default bInterval inside which is actually > adjustable. So I can think setting bInterval is to describe the hardware > rather than policy. If the hardware is adjustable, why don't you adjust the hardware instead of changing the software? > > So I think you need to figure out an interface that allows user space to > > set the polling interval for any hub at runtime instead. > > Changing the interval at runtime is an another way to solve the > power consumption problem, but it's not so easy. At least xhci needs > to restart an endpoint and no devices are changing the interval after > enumeration stage. Restarting endpoints is easy; just call usb_set_interface(). Alan Stern
On Fri, Dec 06, 2019 at 11:57:30AM +0800, Ikjoon Jang wrote: > On Thu, Dec 5, 2019 at 10:26 PM Johan Hovold <johan@kernel.org> wrote: > > > > On Thu, Dec 05, 2019 at 03:32:38PM +0800, Ikjoon Jang wrote: > > > On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote: > > > > > > But related to my question above, why do you need to do this during > > > > enumeration? Why not just set the lower interval value in the hub > > > > driver? > > > > > > Because I want device tree's bInterval to be checked against the same rules > > > defined in usb_parse_endpoint(). e.g. although hardware says its maximum > > > is 255, but the practical limit is still 0 to 16, so the code can > > > print warnings when bInterval from device node is too weird. > > > > But that could be handled refactoring the code in question or similar. > > Yes, that should be worked. I can't exactly figure out how to refactor > the code for now, but maybe parsed endpoint descriptors are being > checked with default hard wired bInterval value and after that > an overridden value should be checked again. > > Actually I don't care about the details of software policies. I just want > all devices to be handled in the same manner without any further > special treatments. I'd say you're indeed trying to give a specific device special treatment. ;) > > The fundamental problem here is that you're using devicetree, which is > > supposed to only describe the hardware, to encode policy which should be > > deferred to user space. > > The hub hardware has a default bInterval inside which is actually > adjustable. So I can think setting bInterval is to describe the hardware > rather than policy. No, the USB spec says bInterval is a maximum requested value and that the host is free to poll more often. And that's policy. > > So I think you need to figure out an interface that allows user space to > > set the polling interval for any hub at runtime instead. > > Changing the interval at runtime is an another way to solve the > power consumption problem, but it's not so easy. At least xhci needs > to restart an endpoint and no devices are changing the interval after > enumeration stage. The usb-hid driver actually supports configuring the polling rate for devices like mice and keyboards after enumeration (through a module parameter, but still). Unfortunately, the xhci driver does not yet support this and always uses the device maximum bInterval. A bug report for this was filed many years ago, perhaps it's time to address that (adding Mathias on CC): https://bugzilla.kernel.org/show_bug.cgi?id=82571 Johan
On Fri, Dec 6, 2019 at 11:00 PM Alan Stern <stern@rowland.harvard.edu> wrote: > > On Fri, 6 Dec 2019, Ikjoon Jang wrote: > > > On Thu, Dec 5, 2019 at 10:26 PM Johan Hovold <johan@kernel.org> wrote: > > > > > > On Thu, Dec 05, 2019 at 03:32:38PM +0800, Ikjoon Jang wrote: > > > > On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote: > > > > > > > > But related to my question above, why do you need to do this during > > > > > enumeration? Why not just set the lower interval value in the hub > > > > > driver? > > > > > > > > Because I want device tree's bInterval to be checked against the same rules > > > > defined in usb_parse_endpoint(). e.g. although hardware says its maximum > > > > is 255, but the practical limit is still 0 to 16, so the code can > > > > print warnings when bInterval from device node is too weird. > > > > > > But that could be handled refactoring the code in question or similar. > > > > > > > Yes, that should be worked. I can't exactly figure out how to refactor > > the code for now, but maybe parsed endpoint descriptors are being > > checked with default hard wired bInterval value and after that > > an overridden value should be checked again. > > > > Actually I don't care about the details of software policies. I just want > > all devices to be handled in the same manner without any further > > special treatments. > > > > > The fundamental problem here is that you're using devicetree, which is > > > supposed to only describe the hardware, to encode policy which should be > > > deferred to user space. > > > > The hub hardware has a default bInterval inside which is actually > > adjustable. So I can think setting bInterval is to describe the hardware > > rather than policy. > > If the hardware is adjustable, why don't you adjust the hardware > instead of changing the software? sorry, I meant "hardware has a default value but it's actually adjustable (by software)". Adjusting hardware is the best option but our hub doesn't allow to do that, so the current approach is patching a hardware descriptor on enumeration stage. > > > > So I think you need to figure out an interface that allows user space to > > > set the polling interval for any hub at runtime instead. > > > > Changing the interval at runtime is an another way to solve the > > power consumption problem, but it's not so easy. At least xhci needs > > to restart an endpoint and no devices are changing the interval after > > enumeration stage. > > Restarting endpoints is easy; just call usb_set_interface(). I thought just changing urb->interval at runtime will be more acceptable. Maybe I'll need an another approach if this patch is unacceptable. Thank you! > > Alan Stern >
On Fri, Dec 6, 2019 at 11:25 PM Johan Hovold <johan@kernel.org> wrote: > > On Fri, Dec 06, 2019 at 11:57:30AM +0800, Ikjoon Jang wrote: > > On Thu, Dec 5, 2019 at 10:26 PM Johan Hovold <johan@kernel.org> wrote: > > > > > > On Thu, Dec 05, 2019 at 03:32:38PM +0800, Ikjoon Jang wrote: > > > > On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote: > > > > > > > > But related to my question above, why do you need to do this during > > > > > enumeration? Why not just set the lower interval value in the hub > > > > > driver? > > > > > > > > Because I want device tree's bInterval to be checked against the same rules > > > > defined in usb_parse_endpoint(). e.g. although hardware says its maximum > > > > is 255, but the practical limit is still 0 to 16, so the code can > > > > print warnings when bInterval from device node is too weird. > > > > > > But that could be handled refactoring the code in question or similar. > > > > Yes, that should be worked. I can't exactly figure out how to refactor > > the code for now, but maybe parsed endpoint descriptors are being > > checked with default hard wired bInterval value and after that > > an overridden value should be checked again. > > > > Actually I don't care about the details of software policies. I just want > > all devices to be handled in the same manner without any further > > special treatments. > > I'd say you're indeed trying to give a specific device special > treatment. ;) yeah right, I'm giving one treatment but I mean not any further. > > > > The fundamental problem here is that you're using devicetree, which is > > > supposed to only describe the hardware, to encode policy which should be > > > deferred to user space. > > > > The hub hardware has a default bInterval inside which is actually > > adjustable. So I can think setting bInterval is to describe the hardware > > rather than policy. > > No, the USB spec says bInterval is a maximum requested value and that > the host is free to poll more often. And that's policy. Honestly I'm a bit confused on the border line between hardware and software definition. That's quite reasonable it's policy that software can poll more often than hardware specified, but can we think it's just overriding hardware property specifying maximum value from beginning? Is it still policy? or 'overriding hardware property' part is already not a hardware description? :-S > > > > So I think you need to figure out an interface that allows user space to > > > set the polling interval for any hub at runtime instead. > > > > Changing the interval at runtime is an another way to solve the > > power consumption problem, but it's not so easy. At least xhci needs > > to restart an endpoint and no devices are changing the interval after > > enumeration stage. > > The usb-hid driver actually supports configuring the polling rate > for devices like mice and keyboards after enumeration (through a module > parameter, but still). > > Unfortunately, the xhci driver does not yet support this and always uses > the device maximum bInterval. A bug report for this was filed many years > ago, perhaps it's time to address that (adding Mathias on CC): > > https://bugzilla.kernel.org/show_bug.cgi?id=82571 Thanks! > > Johan
On Mon, Dec 09, 2019 at 12:05:53PM +0800, Ikjoon Jang wrote: > On Fri, Dec 6, 2019 at 11:25 PM Johan Hovold <johan@kernel.org> wrote: > > > > On Fri, Dec 06, 2019 at 11:57:30AM +0800, Ikjoon Jang wrote: > > > On Thu, Dec 5, 2019 at 10:26 PM Johan Hovold <johan@kernel.org> wrote: > > > > The fundamental problem here is that you're using devicetree, which is > > > > supposed to only describe the hardware, to encode policy which should be > > > > deferred to user space. > > > > > > The hub hardware has a default bInterval inside which is actually > > > adjustable. So I can think setting bInterval is to describe the hardware > > > rather than policy. > > > > No, the USB spec says bInterval is a maximum requested value and that > > the host is free to poll more often. And that's policy. > > Honestly I'm a bit confused on the border line between hardware > and software definition. That's quite reasonable it's policy that software > can poll more often than hardware specified, but can we think it's just > overriding hardware property specifying maximum value from beginning? > Is it still policy? or 'overriding hardware property' part is already not > a hardware description? :-S The hardware is supposed to give you the upper limit, and then software is allowed to poll more often if it wants to and is able to do so. In this case that decision depends partly on what is connected to the hub but also on how that device in turn has been configured, specifically, whether runtime PM has been enabled or not. Someone who doesn't use the downstream device, or who prefers to never suspend it, may not be willing to pay the price for polling the hub more frequently, for example. So this ends up being very much a policy decision which should be left for user space. But if you can come up with a generic interface for this, it could be useful in other setups as well (non-DT, hot-pluggable, etc). Johan
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c index 5f40117e68e7..95ec5af42a1c 100644 --- a/drivers/usb/core/config.c +++ b/drivers/usb/core/config.c @@ -6,6 +6,7 @@ #include <linux/usb.h> #include <linux/usb/ch9.h> #include <linux/usb/hcd.h> +#include <linux/usb/of.h> #include <linux/usb/quirks.h> #include <linux/module.h> #include <linux/slab.h> @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, memcpy(&endpoint->desc, d, n); INIT_LIST_HEAD(&endpoint->urb_list); + /* device node property overrides bInterval */ + if (usb_of_has_combined_node(to_usb_device(ddev))) { + u32 interval = 0; + if (!of_property_read_u32(ddev->of_node, "hub,interval", + &interval)) + d->bInterval = min_t(u8, interval, 255); + } + /* * Fix up bInterval values outside the legal range. * Use 10 or 8 ms if no proper value can be guessed.