Stacksize optimization

Hi,

In order to optimize the statcksize of a thread, I would like to know when the thread uses the maximum of its stack (maximum can be 3/4 of the stack for instance) How can I find this "time"?

Cheers,


Baptiste

Hi,

Hi,

In order to optimize the statcksize of a thread, I would like to know when the thread uses the maximum of its stack (maximum can be 3/4 of the stack for instance) How can I find this "time"?

In my opinion:

Welcome to the embedded world problems...

I thought about to have some coverage compiler and check always the maximum stacksize... That's my idea to get such value... but then you need to reach 100% coverage of the thread -> good luck with that. :slight_smile:

It would maybe nice to have such feature in RIOT to coverage his "little tiny thread application" where you could reach your 100% coverage...

Maybe also possible on other stacks for testing in native application... and also check ISR stack size. It think it's a good research topic for somebody who looking for academic work. :slight_smile:

- Alex

Hi!

On Mon, Jan 09, 2017 at 02:01:04PM +0100, Baptiste Clenet wrote:

In order to optimize the statcksize of a thread, I would like to know when the thread uses the maximum of its stack (maximum can be 3/4 of the stack for instance) How can I find this “time”?

Sounds like a case for -finstrument-functions (man gcc).

Cheers,
Oleg


die_if_kernel("Kernel gets FloatingPenguinUnit disabled trap", regs);
        linux-2.2.16/arch/sparc/kernel/traps.c

Thanks for your replies. I leave this for the moment but stack optimisation will be a very nice feature :slight_smile:

Any update on this, I’m still interested and I think lot of people are interested :slight_smile:

I mean there is the thread stack high water mark that gets displayed in ps with DEVELHELP on, but that only tells you about the highest stack usage in the past.

If there is a branch not taken yet, that could cause higher stack usage, you would not know. Maybe the new coverage module can help there.

2023-02-17 08:22:56,455 # 	pid | name                 | state    Q | pri | stack  ( used) | base addr  | current     
2023-02-17 08:22:56,463 # 	  - | isr_stack            | -        - |   - |    512 (  132) | 0x20000000 | 0x200001c0
2023-02-17 08:22:56,472 # 	  1 | idle                 | pending  Q |  15 |    256 (  120) | 0x200003c4 | 0x2000044c 
2023-02-17 08:22:56,481 # 	  2 | main                 | bl mutex _ |   7 |   1536 (  396) | 0x200004c4 | 0x200009fc 
2023-02-17 08:22:56,490 # 	  3 | test_thread          | running  Q |   7 |    600 (  528) | 0x20000b68 | 0x20000d14 
2023-02-17 08:22:56,496 # 	    | SUM                  |            |     |   2904 ( 1176)

I don’t have the latest RIOT but I don’t see “the thread stack high water mark” I only see the stack size and stack used currently. Do I misinterpret something? Even in master code, I don’t see the highest stack usage in the past

Could you point out in code what you mean please?

Thanks

The used field shows the high watermark, not the current value.

Ok so

( used)

is not very explicit

But thanks, that helps me a lot to know that