Add a USB message queue to USB to CANbus bridge code #6354
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current Klipper USB to CANbus bridge code will stop reading messages from the USB bus if it becomes busy sending messages on the USB bus. This was implemented as a flow control system to prevent bandwidth generated from host messages swamping message traffic received from the physical canbus.
Unfortunately, this flow control system has a notable performance impact. The low-level USB hardware layer will keep sending messages until the device acknowledges them. So, if the CANbus bridge code does not read USB messages, the retransmits continue to consume bandwidth - bandwidth that would be better utilized in sending messages from the device to the host.
This PR adds a small USB message queue to the USB to CANbus bridge code. The Linux gs_usb driver will only send 10 pending packets before it pauses transmissions. So, a small queue that stores these messages can help avoid low-level USB message resends.
This PR can notably improve the performance of the Klipper USB to CANbus bridge code.
-Kevin