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

Get a better estimation for the required stack size #23

Open
jeromehue opened this issue Dec 22, 2022 · 3 comments
Open

Get a better estimation for the required stack size #23

jeromehue opened this issue Dec 22, 2022 · 3 comments

Comments

@jeromehue
Copy link
Contributor

jeromehue commented Dec 22, 2022

Description
Current stack size estimations are very crude guesses. We only have 128 kB of RAM.

Files
All threads files.

@PatrickKa
Copy link
Contributor

We should either try out static analysis tools like StackAnalyzer (unfortunately only 30-day free trial), or measure it, e.g., by filling the stack with magic numbers and then at the "end of the program" check how many magic numbers survived.

@PatrickKa
Copy link
Contributor

PatrickKa commented Dec 14, 2023

According to a discussion with @danielschloms on Slack, Rodos provides Thread::getMaxStackUsage(). This uses the approach where the stack is initially "painted" with magic numbers and you can later check how much "paint" is left.

Now, all that is left to do is use this function an estimate the max. stack size for all our threads.

@PatrickKa
Copy link
Contributor

As it turns out, it is even easier than that. I recently ran some tests where Rodos printed an error message telling me that there is a stack overflow in a thread and therefore terminated it. This worked on both Linux and the COBC and allowed me to binary search for the minimum required stack size. I only tested this with debug builds, though. Also, note that sometimes the error message was not printed. Instead, the output on HTerm just stopped at random locations. Knowing this should allow us to easily determine if a stack overflow occurred by just running the code in debug mode and checking the printed output, which is very nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants