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

[rtl872x] hal: make USB CDC a bit quicker by scheduling TX from timer callback delayed by 1ms #2672

Merged
merged 1 commit into from Aug 2, 2023

Conversation

avtolstoy
Copy link
Member

Problem

USB stack on RTL872x platforms is pretty slow due to processing of interrupts in a task thread and weird scheduling. As a consequence this makes USB CDC (Serial) pretty slow especially on Device->Host path.

Solution

Trigger Device->Host transfers from a high-priority timer thread and delay them by 1ms (RTOS tick), which helps with task scheduling and allows to put more data into TX buffer before the transfer is scheduled. Previously writing 1 character (which is what the wiring APIs do) into an empty TX buffer was immediately triggering TX transaction and due to weird scheduling most of the transfers were just 1 byte.

Steps to Test

  • wiring/usbserial

Example App

N/A

References

N/A


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

Copy link
Member

@scott-brust scott-brust left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested serial logging in a tight loop and can see this PR speeds things up considerably.

Without PR, about 21 ms between lines:

[2023-07-20 15:09:16.717] 0000014181 [app] INFO: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
[2023-07-20 15:09:16.738] 0000014202 [app] INFO: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
[2023-07-20 15:09:16.759] 0000014223 [app] INFO: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
[2023-07-20 15:09:16.781] 0000014244 [app] INFO: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
[2023-07-20 15:09:16.802] 0000014266 [app] INFO: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
[2023-07-20 15:09:16.823] 0000014287 [app] INFO: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890

With PR, about 8ms between lines

[2023-07-20 15:04:24.525] 0000004632 [app] INFO: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
[2023-07-20 15:04:24.533] 0000004640 [app] INFO: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
[2023-07-20 15:04:24.542] 0000004649 [app] INFO: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
[2023-07-20 15:04:24.550] 0000004657 [app] INFO: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
[2023-07-20 15:04:24.559] 0000004665 [app] INFO: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
[2023-07-20 15:04:24.567] 0000004673 [app] INFO: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890

@@ -415,29 +422,34 @@ int CdcClassDriver::startTx() {
return 0;
}

if (holdoff) {
stopTxTimer();
return startTxTimer();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case for holdoff = true? This just delays the start of transmission by 1ms?

@scott-brust scott-brust modified the milestones: 5.4.1, 5.5.0-rc.1 Jul 28, 2023
@avtolstoy avtolstoy merged commit 7754e14 into develop Aug 2, 2023
1 check passed
@avtolstoy avtolstoy deleted the fix/rlt872x-usb-cdc branch August 2, 2023 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants