-
Notifications
You must be signed in to change notification settings - Fork 2.1k
sys/usb/cdc_acm, sys/tsrb: speedup usb_cdc ringbuffer handling #21788
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
base: master
Are you sure you want to change the base?
Conversation
sys/tsrb/tsrb.c
Outdated
size_t tmp = n; | ||
int cnt = 0; | ||
unsigned irq_state = irq_disable(); | ||
while (tmp && !tsrb_empty(rb)) { | ||
while (n-- && !tsrb_empty(rb)) { | ||
*dst++ = _pop(rb); | ||
tmp--; | ||
cnt++; | ||
} | ||
irq_restore(irq_state); | ||
return (n - tmp); | ||
return (cnt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you renaming and retyping variables and restructure their use?
-- this question goes for other function you do the same thing to as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to ease readbility
retyping to fit return type
slightly change their use for readability for humans and compilers godbolt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: You could go the extra mile and rename n
to length
/size
/remaining_bytes
and cnt
to copied_bytes
😏
Do you have any benchmark numbers or so to show that it actually improves the speed? Also I'm not to keen on the |
i would not like to have them accessible through the same header ( could go for benchmarking the irq enable and disable -which this is mostly about- is very difficult we got the when i did |
/* | ||
* SPDX-FileCopyrightText: 2015 Kaspar Schleiser <[email protected]> | ||
* SPDX-FileCopyrightText: 2025 Karl Fessel <[email protected]> ML!PA Consulting GmbH | ||
* SPDX-License-Identifier: LGPL-2.1-only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am a bit unsure about that only
-- just a bit if its ok like this its fine for me
What is the motivation to have this in addition to https://doc.riot-os.org/cib_8h.html ? Wouldn't cib already solve all the non-thread-safe ringbuffer needs? |
cib seems to have a very strange usage pattern, does not do the buffer handling but just the index,
turb is created to provide access to tsrb without extra thread safety measures ( cause they are taken/ensured by the caller )
|
Contribution description
speedup usb_cdc_acm tsrb writing and reading by avoid jumps to tsrb and superfluous irq_disable calls.
Testing procedure
read
usb cdc acm still working
Issues/PRs references
#12402 fixed tsrb hadling for usb ( loss of chars for acm) by adding irq disable around tsrb access
#15218 added isr_guards thoughout tsrb