Hi,
I would like to understand what exactly fits into the THD_WORKING_AREA_SIZE.
Trying to optimize a project and can't find enough documentation to help on this.
How can one know (or estimate) the proper size for this?
Thanks!
Questions about THD_WORKING_AREA_SIZE
-
- Posts: 91
- Joined: Sat Feb 18, 2017 11:50 am
- Has thanked: 43 times
- Been thanked: 23 times
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Re: Questions about THD_WORKING_AREA_SIZE
Hi,
The parameter is the stack size reserved for the thread. The system then adds:
- Space for a thread_t structure.
- Space for port_intctx and port_extctx structures.
- Space for IRQ servicing, architecture dependent.
- Space for stack alignment enforcing, architecture dependent.
Note that he space for IRQ servicing is modifiable with a PORT option, it is set very conservatively by default, you may trim that down but consider that the required space may change depending on compiler version/settings.
Giovanni
The parameter is the stack size reserved for the thread. The system then adds:
- Space for a thread_t structure.
- Space for port_intctx and port_extctx structures.
- Space for IRQ servicing, architecture dependent.
- Space for stack alignment enforcing, architecture dependent.
Note that he space for IRQ servicing is modifiable with a PORT option, it is set very conservatively by default, you may trim that down but consider that the required space may change depending on compiler version/settings.
Code: Select all
/**
* @brief Per-thread stack overhead for interrupts servicing.
* @details This constant is used in the calculation of the correct working
* area size.
* @note In this port this value is conservatively set to 64 because the
* function @p chSchDoReschedule() can have a stack frame, especially
* with compiler optimizations disabled. The value can be reduced
* when compiler optimizations are enabled.
*/
#if !defined(PORT_INT_REQUIRED_STACK) || defined(__DOXYGEN__)
#define PORT_INT_REQUIRED_STACK 64
#endif
Giovanni
-
- Posts: 91
- Joined: Sat Feb 18, 2017 11:50 am
- Has thanked: 43 times
- Been thanked: 23 times
Re: Questions about THD_WORKING_AREA_SIZE
OK got you! I'll look into that piece of code closelly.
What goes into that "thread stack"?
Are there any hints on how to estimate the proper size for it?
Or perhaps a better question would be: how do I know that a var goes into the thread stack and not onto the "regular" stack?
What goes into that "thread stack"?
Are there any hints on how to estimate the proper size for it?
Or perhaps a better question would be: how do I know that a var goes into the thread stack and not onto the "regular" stack?
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Re: Questions about THD_WORKING_AREA_SIZE
Hi,
Each thread has a separate stack, there is no "regular stack", that is the stack of the main thread.
The stack must be large enough to contain all stack frames of functions called by the thread, the worst case depth. If in doubt make it very large, run your program making sure in uses all code paths then measure stack usage using the debug plugin.
Giovanni
Each thread has a separate stack, there is no "regular stack", that is the stack of the main thread.
The stack must be large enough to contain all stack frames of functions called by the thread, the worst case depth. If in doubt make it very large, run your program making sure in uses all code paths then measure stack usage using the debug plugin.
Giovanni
-
- Posts: 91
- Joined: Sat Feb 18, 2017 11:50 am
- Has thanked: 43 times
- Been thanked: 23 times
Who is online
Users browsing this forum: No registered users and 11 guests