Thanks to visit codestin.com
Credit goes to github.com

Skip to content

esp32: Use configured stack-limit-margin when creating threads. #15583

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

Closed

Conversation

dpgeorge
Copy link
Member

@dpgeorge dpgeorge commented Aug 2, 2024

Summary

This gives more stack margin for threads on ESP32C3 (it should have been done this way from the beginning). That's important for IDF v5.2, see #15523 (comment)

Testing

Ran the main test suite on an ESP32C3 using IDF v5.0.5. All tests pass (sans known failure math_domain_special.py).

This gives more stack margin for threads on ESP32C3.

Signed-off-by: Damien George <[email protected]>
@@ -161,7 +161,7 @@ mp_uint_t mp_thread_create_ex(void *(*entry)(void *), void *arg, size_t *stack_s
thread = th;

// adjust the stack_size to provide room to recover from hitting the limit
*stack_size -= 1024;
*stack_size -= MP_TASK_STACK_LIMIT_MARGIN;
Copy link
Contributor

@projectgus projectgus Aug 6, 2024

Choose a reason for hiding this comment

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

This code has a pre-existing race condition, because stack_size points to inside the thread 'arg' structure (and the thread is already created). If a context switch happens before here then it will set the limit to the full task stack size.

It still failed for me on IDF V5.2.2 until I moved the adjustment before creating the RTOS thread. However I think I found a simpler way to handle it, will submit PR after lunch.

(As an aside, I thought I saw the stress_recurse test failing intermittently on esp32 - maybe this is why.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Great find! I'll wait for your fix then.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Alternative now at #15605 )

@dpgeorge
Copy link
Member Author

dpgeorge commented Aug 7, 2024

Closing in favour of #15605.

@dpgeorge dpgeorge closed this Aug 7, 2024
@dpgeorge dpgeorge deleted the esp32-fix-stack-limit-margin-c3 branch August 7, 2024 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants