FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [March 2017 Threads] Reducing Stack sizePosted by paulgigliotti on March 5, 2017 I am aware of tools for seeing how much stack is used by task. I am looking for some general guidelines on methods to reduce stack requirements. I am less concerned with the stack size, than by the time it takes to push data on to the stack upon a context switch. I have several tasks that wake up on a QueueRecieve. In these tasks, I have declared a buffer, into which the QueueReceive copies the data. The task processes the data, at at the end of the loop, returns to the QueueReceive, where it will become blocked, and wait for the next packet. What I am wondering is will the contents of the buffer (just processed) be pushed on to the stack. I no longer need this data, and moving it to the stack would be a waste of processor band width.
If the data does not get stored, then fine. If not, would it be more advantages to create the buffer outside the process, and pass the address of the buffer into the task as a paramater. Would this then prevent the contents of the buffer from being pushed onto the stack?
Reducing Stack sizePosted by richarddamon on March 5, 2017 The time to do a context switch is NOT dependent on the amount of data that is on the stack. Each task has its own stack space, that remains were it is, and the context switch basically saves the register set, saves the value of the Stack Pointer into the tasls TCB, and then loads the stack pointer for the new task, and restores the registar set and resumes execution.
Reducing Stack sizePosted by paulgigliotti on May 11, 2017 Thanks for that. Ok, independant of context switch, what are things to consider to reduce stack size. We are seeing some stack overflow issues that we are chasing down and looking for ways to reduce the amount of stack space required.
Reducing Stack sizePosted by rtel on May 12, 2017 The stack usage is really nothing to do with the RTOS.
If you take a non-RTOS program and execute it then the amount of stack
it uses is dependent on the function call depth, the compiler used, the
compiler optimisation, and the local variables you declare. If you then
take the same program and run it under the RTOS the stack usage will be
very approximately 70 words larger. The small number of additional
words are used to hold the task's context when the task is not running.
If you are using GCC then, with the right command line option (which I
forget but are easy to look up), you will get a file that tells you the
stack usage of every function as part of the build output.
You can also use uxTaskGetStackHighWaterMark() to query stack usage.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|