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

Non-deterministic stack usage #13

Open
jd-yolabs opened this issue Mar 9, 2023 · 0 comments
Open

Non-deterministic stack usage #13

jd-yolabs opened this issue Mar 9, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@jd-yolabs
Copy link
Collaborator

Standard Operation

Most tasks that receive and distribute events to callers have deterministic stack usage.

  1. The stack for a task waiting on the event queue is at its lowest point.
  2. The task receives an event and calls the handlers for that event one at a time.
  3. The maximum task use is the maximum of the stack use of each handler.

This behavior makes it easy to reason about stack overflows; if we see an overflow we can find the one handler at fault.

Problem

An optimization in ErReturnToSender() in the FreeRTOS implementation causes the eventrouter to behave differently in a specific case.

This optimization saves a roundtrip for an event if the last subscriber lives in the same task as the sender; when the last subscriber is done with the event, the eventrouter returns the event to the sender immediately instead of reposting the event to the sending module's task's queue.

This only becomes a problem when the last subscriber:

  1. Previously KEPT the event;
  2. Lives in the same task as the sender; and
  3. Calls ErReturnToSender() directly.

In this case we still have part of the subscriber's handler on the stack in addition to the sender's handler.

Conclusion

This shouldn't cause functional problems but may make stack overflows more difficult to diagnose and predict in some use cases.

@linkmonitor linkmonitor added the enhancement New feature or request label Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants