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

UART write loop could lead to wdt with low bitrates or large buffers #7799

Merged
merged 1 commit into from
Dec 31, 2020

Conversation

dok-net
Copy link
Contributor

@dok-net dok-net commented Dec 29, 2020

EspSoftwareSerial successfully uses optimistic_yield for the same purpose already.
Fixes #7746

Copy link
Collaborator

@d-a-v d-a-v left a comment

Choose a reason for hiding this comment

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

LGTM !

Copy link
Collaborator

@earlephilhower earlephilhower left a 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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

AIUI, optimistic_yield will panic() if not in the CONT context. This would make any SYS-callback printouts (TCP, others) potentially crash.

@devyte, @d-a-v, any comments/ideas? I like the idea, but the forced panic seems worse than a potential WDT...

Copy link
Collaborator

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

Copy link
Collaborator

@d-a-v d-a-v Dec 30, 2020

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);
Copy link
Collaborator

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

Copy link
Collaborator

@devyte devyte left a 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.

Copy link
Collaborator

@earlephilhower earlephilhower left a 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!

@earlephilhower earlephilhower merged commit 84260dc into esp8266:master Dec 31, 2020
@dok-net dok-net deleted the hwseryield branch January 7, 2021 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slow serial baudrates cause exceptions / WDT
4 participants