Homepage | FAQ

FreeRTOS FAQ - Memory Usage and Boot Times

How much RAM does FreeRTOS use?
Why do queues use that much RAM?

How much ROM does FreeRTOS use?
How can I reduce the amount of RAM used?
How is RAM allocated to tasks?
How is RAM allocated to queues?
How big should a task stack be?
How Long does FreeRTOS take to boot?

FAQ Top



How much RAM does FreeRTOS use?

This depends on your application. Below is a guide based on:

Item Bytes Used
Scheduler Itself 236 bytes (can easily be reduced by using smaller data types).
For each queue you create, add 76 bytes + queue storage area (see FAQ Why do queues use that much RAM?)
For each task you create, add 64 bytes (includes 4 characters for the task name) + the task stack size.

Note these figures are much lower for 8 and 16 bit architectures!



Why do queues use that much RAM?

Event management is built into the queue functionality. This means the queue data structures contain all the RAM that other RTOS systems sometimes allocate separately. There is no concept of an event control block within FreeRTOS.



How much ROM does FreeRTOS use?

This depends on your compiler and architecture.

The kernel itself required under 4KBytes of ROM space when using the same configuration as stated for the FAQ "How much RAM does FreeRTOS use?".



How can I reduce the amount of RAM used?



How is RAM allocated to tasks?

To create a task the kernel makes two calls to pvPortMalloc(). The first allocates the task control block, the second allocates the task stack.

Please read the memory configuration section of the API documentation for details of the allocation scheme.



How is RAM allocated to queues?

To create a queue the kernel makes two calls to pvPortMalloc(). The first allocates the queue structure, the second the queue storage area (the size of which is a parameter to xQueueCreate()).



How big should the stack be?

This is completely application dependent, and not always easy to calculate. It depends on the function call depth, number of local variables allocated, number of parameters in function calls made, interrupt stack requirements, etc. The stack must always be large enough to contain the execution context (all the processor registers).

The stack of each task is filled with 0xa5 bytes upon creation which allows the high water mark to be viewed using suitable debugging tools. Also see the function usPortCheckFreeStackSpace() implemented in the x86 port for an example of how the high watermark can be measured.



How long does FreeRTOS take to boot?

FreeRTOS, OpenRTOS and in most cases SafeRTOS are supplied as source code for static linking into the users application. The build process therefore results in a single executable binary image. Typically such an image will include a C start up routine to set up the C run time environment, before calling main() to execute the users application. The interrupt vector table will also be statically configured and included at a predetermined location within the same binary.

The table below provides an indication of the sequence of processing booting such a system will require, along with some guidance on the time required for this processing to complete. Note that any numbers provided are indicative only and realistic. Actual times achievable will depend on the architecture being used, the clock frequencies configured, and the configuration of the memory interface.

#
Description
Timing
1
Configure the CPU clocks for the performance level required.
Typically requires a few register writes, followed by a short delay for clocks to lock. This will take in the order of a few microseconds, depending on the architecture being used.

This is an optional step. It could be performed later from C code but can boost the boot time if it is performed prior to initializing memory.

2
Initialize static and global variables that contain only the value zero (bss).
Including FreeRTOS in an application would typically only add an extra couple of hundred write accesses to be performed within a very tight assembly loop. This will add in the region of a few microseconds to the time taken when compared to that taken were the kernel not included.
3
Initialize variables that contain a value other than zero.
Including FreeRTOS in an application would typically not add any extra time to this step.
4
Perform any other hardware set up required.
Often it is desirable to configure peripherals prior to starting the scheduler. How long this takes will depend on the complexity of the peripherals being used, but on the class of microcontroller targeted by FreeRTOS the total time would typically require a few milliseconds only.
5
Create application queues, semaphores and mutexes.
Typically the majority of queues, semaphores and mutexes will be created prior to the scheduler being started.

By way of example, on a Cortex-M3 device, using the ARM RVDS compiler with optimization set to 1 (low), creating a queue, semaphore or mutex will take approximately 500 CPU cycles.

6
Create application tasks.
Typically the majority of tasks will be created prior to the scheduler being started.

By way of example, on a Cortex-M3 device, using the ARM RVDS compiler with optimization set to 1 (low), creating each task will take approximately 1100 CPU cycles.

7
Start the scheduler.
The scheduler is started by calling vTaskStartScheduler(). The start up process includes configuring the tick interrupt, creating the idle task, and then restoring the context of the first task to run.

By way of example, on a Cortex-M3 device, using the ARM RVDS compiler with optimization set to 1 (low), starting the scheduler will take approximately 1200 CPU cycles.






Copyright (C) 2010 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOS 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..