[ECOS] Stack usage measurement
Mon Apr 20 10:09:00 GMT 2009
Gary Thomas Ãrta:
> Szentirmai Gergely wrote:
>> I had a bad feeling about stack usage (perhaps measurement), and I have
>> written a small testcode, to see what's really happening. It came with
>> an interesting result. It seems to me, that cyg_thread_info.stack_used
>> gives the max used stack size, not the actual. Is that right? According
>> to the docs, it should give the current usage.
>> The test code is attached, I use arm-elf-gcc, ecos with default packages.
>> The result is also attached. I think that even the last stack usage
>> should be equal with 144 Bytes.
>> Maybe I am wrong... maybe not.
> No, you are correct, the value is the maximum used. Why is this
> less useful than the 'current' used? Stacks aren't reused or
> dynamic (they don't grow or shrink), so [IMO] the most useful
> measurement is the max size you'll ever need, which is the
> measured value [at the time of the measurement, of course]
I agree with you, but I was interrested about the current usage in this
case. I thought that the difference between cyg_thread_info.stack_used
(CYGFUN_KERNEL_THREADS_STACK_MEASUREMENT enabled) is exactly this
(current vs max usage). If both measure the max usage, than what is the
difference? cyg_thread_measure_stack_usage is just a shortcut to the same?
> In addition, every call your code makes to 'diag_printf()'
> perturbs the measurement, as it can use a lot of stack itself!
> If you want to be very pure about the measurements, save the
> stack information in some variables and only print the results
> when done, that way 'diag_printf()'s use won't get in the way.
This is one of the things why I would like to measure the current usage.
I have tried to minimize this effect by avoid any %d and use
diag_write_dec(info.stack_used); So diag_printf only have to push the
My initialization thread now use 3k+ stack, which is way to much (I
have 32k of SRAM) from a simple initialization thread. I think
"printf-s" has a big part in it (trace, log etc.).
Does anybody has a estimation about the stack usage of pintf stuff? I
think it should use about the length of the printed text, and some more
because of the calling parameters. I know that it is depending on the
As a summary, I would have to avoid the usage of any printf if I'm short
In this case I would implement a stack usage optimalized printf
(statically allocated (or malloc) working buffer) for debugging purpose.
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
More information about the Ecos-discuss