Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Stack depth

Posted by Grigore-Mihai Dobra on February 25, 2009
Are there any metrics to know the maximum stack depth of freeRTOS, provided that all the parameters are passed on the stack and not in registers?

I mean, which is the maximum stack usage of the longest call chain of the freeRTOS functions?

RE: Stack depth

Posted by MEdwards on February 25, 2009
The configMINIMAL_STACK_SIZE setting is a good indication. This is the stack size allocated to the idle task (which does not use much stack at all) but also most of the demo tasks. The demo tasks exercise all the FreeRTOS functions.

RE: Stack depth

Posted by Grigore-Mihai Dobra on February 26, 2009
Ok, but the idle task does not use much of the freeRTOS services, so it is unlikely that it will use the maximum stack size needed by the most task consuming kernel service.

So, if all the parameters to the freeRTOS service functions are passed on the stack, and further, all the parameters from the service to internal functions are again passed on the stack, which, in turn, allocate local variables on the stack... Is there any way to know which is the longest or the most stack-consuming call chain given these hypotheses?

My compiler is capable of passing some of the parameters in registers(up to 8 bytes), but due to the need of interfacing user-mode application with the system-mode kernel through a trap I cannot use register calling convention, but instead I need to use the stack.

So, for example, I call xTaskCreate, passing its parameters on the stack. This function stores local variables on the stack but it also calls other functions, which will further load the stack.

Of course, the size of the return addresses are architecture dependent, so there is practically no way to include them in the stack usage estimation. All I'm interested in is the size taken by the parameters and local variables.

RE: Stack depth

Posted by Dave on February 26, 2009
> Ok, but the idle task does not use much of the freeRTOS
> services, so it is unlikely that it will use the maximum
> stack size needed by the most task consuming kernel service.


Agreed, but I think the main point of edwards3 post is that the demo app tasks also use this as the stack size and these use all the FreeRTOS services.

RE: Stack depth

Posted by Grigore-Mihai Dobra on February 26, 2009
Ok, so I'll just have to look for the configMINIMAL_STACK_SIZE of an architecture similar to mine(NXP 51XA) and then do some probabilistic/statistic/estimatory math.

RE: Stack depth

Posted by incrediball on February 26, 2009
Alternatively you could create stack sizes that are easily large enough, run the program with the stack highwater function enabled, throw everything imaginable at your program and after you're satisfied that the program has run long enough, look at how much stack has been used. Using these results you can then fine tune the stack sizes.

I know this approach is not 100% sure but there are problems with calculating it out on a theoretical basis:

1. Mistakes are easily made and certain factors (e.g. interrupts) can be overlooked. I wouldn't trust a calculation unless I can perform such a test run and get comparable results.

2. You cannot make any changes to your program, or ever upgrade to a new version of FreeRTOS, without having to recalculate everything.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists