Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a USB message queue to USB to CANbus bridge code #6354

Merged
merged 3 commits into from
Oct 4, 2023

Conversation

KevinOConnor
Copy link
Collaborator

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

Rename the internal variable names.  This is in preparation for
support of a USB message queue.

Signed-off-by: Kevin O'Connor <[email protected]>
Read USB messages arriving from the host into a queue.  This makes it
less likely that USB "bulk out" packets will be NAK'ed on the USB bus,
which improves USB bus utilization.

Signed-off-by: Kevin O'Connor <[email protected]>
Prioritize sending responses back to the host over transmitting new
messages from the host.  Otherwise, the gs_usb host usb
acknowledgments could saturate the usb bandwidth for extended periods.

Signed-off-by: Kevin O'Connor <[email protected]>
@KevinOConnor KevinOConnor merged commit 6adff39 into master Oct 4, 2023
@KevinOConnor KevinOConnor deleted the work-usbcan-20230925 branch October 4, 2023 03:32
@github-actions github-actions bot locked and limited conversation to collaborators Oct 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant