-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Ring buffer code cleanups #84060
base: main
Are you sure you want to change the base?
Ring buffer code cleanups #84060
Conversation
npitre
commented
Jan 15, 2025
•
edited
Loading
edited
- ring_buffer: delete redundant code
- ring_buffer: optimize the partial buffer loop
- ring_buffer: factorize almost identical code
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.
Looks clean. Another advantage to new work being encouraged to reuse existing tools is that the existing tools get a round of review and audit too.
do { | ||
partial_size = ring_buf_get_claim(buf, &src, size); | ||
if (partial_size == 0) { |
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.
Style, since the test is now at the top of the loop, you could refactor this into a while via e.g.:
while((partial_size = ring_buf_get_claim(buf, &src, size)) != 0) {
...
}
IIRC someone (MISRA?) doesn't want us using assignment in while expressions though, so it might need a wrapper that takes the size by reference and returns a boolean? Or not, I don't remember what the rules are supposed to be anymore.
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'm sure MISRA is against assignments within condition tests. And the loop has 2 exit conditions: one at the top and one at the bottom.
The CI failure baffles me. Ideas anyone? |
Regarding the CI failure ...
|
I reduced the CI failure to the following patch applied to the otherwise
Makes no sense to me. Assembly output is different with and without the |
kernel/include/kswap.h
Outdated
@@ -235,30 +235,6 @@ static inline void z_swap_unlocked(void) | |||
* | |||
* The memory of the dummy thread can be completely uninitialized. | |||
*/ | |||
static inline void z_dummy_thread_init(struct k_thread *dummy_thread) |
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.
Would it make sense to factor this change out to a separate PR?
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.
WTF? This was supposed to be part of PR #83871 which shows as being merged. Yet the main branch does not have it.
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.
Uh-oh
No need to clamp requested size as ring_buf_get_claim() does it already. Signed-off-by: Nicolas Pitre <[email protected]>
It is more efficient to break early when size of claimed area becomes zero. Signed-off-by: Nicolas Pitre <[email protected]>
Factorize almost identical code. May even improve performance due to CPU cache locality. Signed-off-by: Nicolas Pitre <[email protected]>
I am presently suspecting that the CI failure is due to a problem with the test itself. In a previous comment I noted that the same debug string still shows up when the test passes (without the proposed changes). This is making me suspect that there is something amiss not with the ring buffer code but with the test, and that the proposed changes have altered the timing just enough such that the test will detect a failure before it completes. FWIW, the tracing buffer has a default size of 2048 (CONFIG_TRACING_BUFFER_SIZE). Increase this value and the test will pass. |