-
Notifications
You must be signed in to change notification settings - Fork 13.3k
UART write loop could lead to wdt with low bitrates or large buffers #7799
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
Conversation
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.
LGTM !
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.
Just worried about yield() in the UART code. Need to be very sure it's safe and not used by SYS to log/etc...
uart_do_write_char(uart_nr, pgm_read_byte(buf++)); | ||
optimistic_yield(10000UL); |
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.
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.
optimistic_yield() checks if it can yield (i. e. in CONT), and if enough time has elapsed since the start of the current loop. If true, it yield()s, otherwise does nothing.
So it shouldn't panic.
However: I seem to remember there was a change to its behavior so that yield actually only happens once every blah ms instead of after blah ms since loop start.
In any case:
- At a glance, I think the argument of 10000 is way too big, I would use something like 500, i. e. yield at most every 0.5s
- this yield won't help in the case of slow comms attempted from SYS, but you could argue that comms should be done from CONT
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.
The unit is µs
so 10k is 10ms.
It should be fine.
Maybe 1ms is better to sustain high throughput in case of a network transfer.
edit all functions taking time as parameter should have the unit in their names, starting with delay()
... ah it's arduino API, we can't change it :) Our polled time structure have it though. We also could change optimistic_yield()
as it is internal API.
uart_do_write_char(uart_nr, pgm_read_byte(buf++)); | ||
optimistic_yield(10000UL); |
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.
optimistic_yield() checks if it can yield (i. e. in CONT), and if enough time has elapsed since the start of the current loop. If true, it yield()s, otherwise does nothing.
So it shouldn't panic.
However: I seem to remember there was a change to its behavior so that yield actually only happens once every blah ms instead of after blah ms since loop start.
In any case:
- At a glance, I think the argument of 10000 is way too big, I would use something like 500, i. e. yield at most every 0.5s
- this yield won't help in the case of slow comms attempted from SYS, but you could argue that comms should be done from CONT
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.
Oops, when I took a look before I saw ms. You're right, it's us. Maybe I need glasses...
One yield every 10ms should be ok. It might be worth testing if there's a difference vs 1ms before merging, but I don't see that as a stopper.
Approving.
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.
Fair enough, thanks for the clarification. LGTM!
EspSoftwareSerial successfully uses optimistic_yield for the same purpose already.
Fixes #7746