usb: dwc2: host: Rewrite the microframe scheduler
Subsystems (3)
PATCH v2 1/1 usb: dwc2: host: Rewrite the microframe scheduler
The old microframe scheduler was hard to follow and had some bugs in it. Specifically, I made some code to visualize what was happening and found:
Add W (280 us):
WWWWWWWWWW|WWWWWWWWWW|WWWWWWWW | | | | |
Add B (260 us):
WWWWWWWWWW|WWWWWWWWWW|WWWWWWWWBB|BBBBBBBBBB|BBBBBBBBBB|BBBB | |
Add C ( 80 us):
WWWWWWWWWW|WWWWWWWWWW|WWWWWWWWBB|BBBBBBBBBB|BBBBBBBBBB|BBBBCCCCCC|CC |
Add K ( 10 us):
WWWWWWWWWW|WWWWWWWWWW|WWWWWWWWBB|BBBBBBBBBB|BBBBBBBBBB|BBBBK | |
Add S (170 us):
SSSSSSSSSS|SSSSSSS | BB|BBBBBBBBBB|BBBBBBBBBB|BBBBK | |
Add L ( 60 us):
SSSSSSSSSS|SSSSSSSLLL|LLL BB|BBBBBBBBBB|BBBBBBBBBB|BBBBK | |
Add W ( 60 us):
SSSSSSSSSS|SSSSSSSLLL|LLLWWWWWBB|BBBBBBBBBB|BBBBBBBBBB|BBBBKW | |
As you can see, the "W" is broken up in a bogus way. It's in microframe 2 and microframe 5. It's easy to find more examples of bugs with more testing.
This new code uses the existing Linux bitmap code to avoid reinventing the wheel. You can see (ugly) test code for this up on pastebin:
http://pastebin.com/GwMuz5HT
Note: no known problems are fixed by this patch, and in fact I can see very little impact of the microframe scheduler overall.
---
Since no known bugs are fixed by this code and my current setup hardly stress the microframe scheduler at all, please give extra eyes and extra testing to this patch. Thanks!
Changes in v2:
- Totally rewrote again after writing test code.
- Now needs to be atop my recent series delaying bandwidth release
drivers/usb/dwc2/core.h | 9 +++- drivers/usb/dwc2/hcd.c | 3 -- drivers/usb/dwc2/hcd.h | 5 +- drivers/usb/dwc2/hcd_queue.c | 117 ++++++++++++++++--------------------------- 4 files changed, 52 insertions(+), 82 deletions(-)
drivers/usb/dwc2/core.h +7 -2
@@ -649,7 +649,7 @@ struct dwc2_hregs_backup {* This value is in microseconds per (micro)frame. The * assumption is that all periodic transfers may occur in * the same (micro)frame. -* @frame_usecs: Internal variable used by the microframe scheduler +* @periodic_bitmap: Bitmap used by the microframe scheduler * @frame_number: Frame number read from the core at SOF. The value ranges * from 0 to HFNUM_MAX_FRNUM. * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
@@ -744,6 +744,10 @@ struct dwc2_hsotg {#define DWC2_CORE_REV_3_00a 0x4f54300a #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) + +/* Total number of microseconds for scheduling */ +#define TOTAL_PERIODIC_USEC 630 + union dwc2_hcd_internal_flags { u32 d32; struct {
@@ -766,7 +770,8 @@ struct dwc2_hsotg {struct list_head periodic_sched_assigned;struct list_head periodic_sched_queued;u16 periodic_usecs; -u16 frame_usecs[8 ]; +unsigned long periodic_bitmap[DIV_ROUND_UP (TOTAL_PERIODIC_USEC , +BITS_PER_LONG )];u16 frame_number;u16 periodic_qh_count;bool bus_suspended;
drivers/usb/dwc2/hcd.c +0 -3
@@ -3089,9 +3089,6 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq) hsotg->hc_ptr_array[i] = channel; } -if (hsotg->core_params->uframe_sched >0 ) -dwc2_hcd_init_usecs (hsotg); -/* Initialize hsotg start work */ INIT_DELAYED_WORK (&hsotg->start_work, dwc2_hcd_start_func);
drivers/usb/dwc2/hcd.h +2 -3
@@ -236,7 +236,7 @@ enum dwc2_transaction_type {* @interval: Interval between transfers in (micro)frames * @sched_frame: (Micro)frame to initialize a periodic transfer. * The transfer executes in the following (micro)frame. -* @frame_usecs: Internal variable used by the microframe scheduler +* @start_usecs: Exact start microsecond value. * @start_split_frame: (Micro)frame at which last start split was initialized * @ntd: Actual number of transfer descriptors in a list * @qtd_list: List of QTDs for this QH
@@ -270,7 +270,7 @@ struct dwc2_qh {u16 usecs;u16 interval;u16 sched_frame; -u16 frame_usecs[8 ]; +u16 start_usecs;u16 start_split_frame;u16 ntd;struct list_head qtd_list;
@@ -458,7 +458,6 @@ extern void dwc2_hcd_queue_transactions(struct dwc2_hsotg *hsotg,/* Schedule Queue Functions */ /* Implemented in hcd_queue.c */ -extern void dwc2_hcd_init_usecs (struct dwc2_hsotg *hsotg);extern struct dwc2_qh *dwc2_hcd_qh_create (struct dwc2_hsotg *hsotg,struct dwc2_hcd_urb *urb,gfp_t mem_flags);
drivers/usb/dwc2/hcd_queue.c +43 -74
152 lines not on this page · raw message
Signature · 6 lines
2.6.0.rc2.230.g3dd15c0 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html