Stack usage. STMicroelectronics ST200-TOOLSET
விளம்பரம்
விளம்பரம்
Tasks OS21
A common problem when developing applications is not allocating enough stack for a task, or the need to tune stack allocation to minimize memory wastage. OS21 provides a couple of techniques which can be used to address this.
The first technique is to enable stack checking in the compiler. This adds an additional function call at the start of each of the user’s functions, just before any additional stack is allocated. The called stack check function can then determine whether there is sufficient space available for the function which is about to execute.
OS21 does not support GCC stack checking.
Although stack checking has the advantage that a stack overflow is reported immediately it occurs, it has several problems:
● there is a run time cost incurred every function call to perform the check
● it cannot report on functions which are not recompiled with stack checking enabled
An alternative technique is to determine experimentally, how much stack a task uses by giving the task a large stack initially, running the code, and then seeing how much stack has been used. To support this, OS21 normally fills a task’s stack with a known value. As the task runs it writes its own data into the stack, altering this value, and later the stack can be inspected to determine the highest address which has not been altered.
To support this, OS21 provides the function: int task_status(
task_t* task,
task_status_t* status,
task_status_flags_t flags);
This function can be used to determine information about the task’s status, for example the base and size of the stack specified when the task was created.
Stack filling is enabled by default, however, in some cases the user may want to control it, so two functions are provided: int task_stack_fill(task_stack_fill_t* fill); returns details about the current stack fill settings, and: int task_stack_fill_set(task_stack_fill_t* fill); allows them to be altered. Stack filling can be enabled or disabled, or the fill value can be changed. By default it is enabled, and the fill value set to 0x12345678.
By placing a call to task_stack_fill_set() in a start-up function, before the OS21 kernel is initialized, it is possible to control the filling of the root task’s stack.
To determine how much stack has been used task_status() can be called, with the flags
parameter set to task_status_flags_stack_used. For this to work correctly, task stack filling must have been enabled when the task was created, and the fill value must have the same value as the one which was in effect when the task was created.
50/226 7358306
பதிவிறக்கு
விளம்பரம்