Hi Everyone.
I am a little confused about something. Let's Suppose I'm running some concurrent tasks in RL-RTX. and let's say one of those tasks is calling a chain of functions ( a function that calls a function that calls another function).
I have 2 questions: 1. Where are the return addresses stored before jumping to the function instruction? Is it stored on the task's stack?
2. if it is stored on the task's stack, then is this (size of the return addresses) taken into account when the linker calculates "Maximum stack depth" and "Stack usage" stored in the html file in the output directory? or is that only the automatic variables?
Thank you very much in advance.
The answer to both questions is yes. However, the output if the compiler is only an estimate based on actual calls; it will not, as far as I know, indicate recursion which could have a much higher price in terms of stack usage. Another relation that cannot generally be resolved is the stack usage of function pointer. I am sure there are more - remember: it is only an estimate.
As far as i have seen, the linker adds the following: "+ Unknown(Functions without stacksize, Cycles, Untraceable Function Pointers)" to the static call-graph html file whenever recursion occurs.
And I am also aware of the function pointer problem. the linker can, however, see the function being pointed to. and it calculates the stack usage for that function independently.
My current approach for estimating stack usage is by manually finding the function pointers in the project and then looking at the "function-being-pointed-to"'s maximum stack depth. while making sure that it itself is not using a function pointer down the line. and then finding what the "actual" worst-case usage is. and then adding 64 bytes to that for a context switch.
Thank you very much. Your reply was very useful to me.
I guess, theoretically, we should take the nested interrupts into account too. When the worst case of nested interrupts happens, it would be very stack consuming.
Stack and stack size configuration are always a mystery to me.
View all questions in Keil forum