Quality RTOS & Embedded Software

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




Loading

OS consuming more memory than it should

Posted by mishung on February 10, 2017

Hello, I am running in bit of a memory allocation problem here. I am using a FreeRTOS on xmega32d4, the compiler I am using is AVR-GCC, optimisation set to max (-O3). Even without any custom tasks created, 528 bytes from stack is being used. 185 bytes get allocated in task.c line 3134 ** pxStack=(StackTypet*)pvPortMallocAligned((((sizet)usStackDepth)*sizeof(StackType_t)),puxStackBuffer); **37 bytes get allocated in task.c line 3140 pxNewTCB=(TCBt*)pvPortMalloc(sizeof(TCBt)); 306 bytes get allocated in task.c line 1565 xReturn = xTimerCreateTimerTask();

The timer task is configured to allocate minimal stack size which is set to 185 bytes so why does it take 306 bytes?

Also, whenever I create a task, it takes more stack space from heap than it should. Every task takes exactly 37 bytes more than what I allocate for it.

Here are my OS settings: ~~~

ifndef FREERTOSCONFIGH
define FREERTOSCONFIGH
include
define configCALLSTACKSIZE 20

/----------------------------------------------------------- * Application specific definitions. * * These definitions should be adjusted for your particular hardware and * application requirements. * * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. * * See http://www.freertos.org/a00110.html. *----------------------------------------------------------/

/* define priority level names*/

define PRIORITYLOW (tskIDLEPRIORITY+1)
define PRIORITYMED (tskIDLEPRIORITY+2)
define PRIORITYHI (tskIDLEPRIORITY+3)
define configMAX_PRIORITIES 4

/* config */

define configUSE_PREEMPTION 0
define configUSEIDLEHOOK 0
define configUSETICKHOOK 0
define configCPUCLOCKHZ (F_CPU)
define configTICKRATEHZ ((TickType_t)1000)
define configMINIMALSTACKSIZE (185U)
define configTOTALHEAPSIZE ((size_t)(1400))
define configMAXTASKNAME_LEN 8
define configUSETRACEFACILITY 1
define configUSE16BIT_TICKS 1
define configIDLESHOULDYIELD 1
define configUSETASKNOTIFICATIONS 0
define configUSE_MUTEXES 1
define configUSERECURSIVEMUTEXES 0
define configUSECOUNTINGSEMAPHORES 0
define configQUEUEREGISTRYSIZE 1
define configUSEQUEUESETS 0
define configUSETIMESLICING 1
define configUSENEWLIBREENTRANT 0
define configENABLEBACKWARDCOMPATIBILITY 0
define configNUMTHREADLOCALSTORAGEPOINTERS 0
define configCHECKFORSTACK_OVERFLOW 2

/* Co-routine definitions. */

define configUSECOROUTINES 0
define configMAXCOROUTINE_PRIORITIES 2

/* XMEGA port specific configuration / / for info see ... */

define configPORTDISABLEALLINTERRUPTSDURINGCONTEXTSWITCH 0
define configPORTSAVERAMPZONCONTEXT_SWITCH 0 //is zero for small MCUs
define configPORTTICKTIMER D0 //tick timer
define configPORTTICKTIMERINTCTRLAADDRESS 0x0906 //tick timer INTCTRLA address

/* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */

define INCLUDE_vTaskPrioritySet 1
define INCLUDE_uxTaskPriorityGet 0
define INCLUDE_vTaskDelete 1
define INCLUDE_vTaskSuspend 1
define INCLUDE_xResumeFromISR 0
define INCLUDE_vTaskDelayUntil 0
define INCLUDE_vTaskDelay 1
define INCLUDE_xTaskGetSchedulerState 0
define INCLUDE_xTaskGetCurrentTaskHandle 0
define INCLUDE_uxTaskGetStackHighWaterMark 1
define INCLUDE_xTaskGetIdleTaskHandle 0
define INCLUDE_xTimerGetTimerDaemonTaskHandle 0
define INCLUDE_pcTaskGetTaskName 0
define INCLUDE_eTaskGetState 1
define INCLUDE_xEventGroupSetBitFromISR 0
define INCLUDE_xTimerPendFunctionCall 0
define configUSE_TIMERS 1
define configTIMERTASKPRIORITY 1
define configTIMERQUEUELENGTH 10
define configTIMERTASKSTACKDEPTH configMINIMALSTACK_SIZE
endif /* FREERTOSCONFIGH */

~~~


OS consuming more memory than it should

Posted by rtel on February 10, 2017

configMINIMALSTACKSIZE can be set much smaller on an AVR (85?) unless you are doing something stack heavy from the idle task hook function. In your case you are using the setting to dimension the stack for both the idle and timer task.

In all the cases you highlight you can step through the code and see exactly where every byte is going.

Lets take xTimerCreateTimerTask() as an example. I'm not stepping through the code, just viewing it:

The first thing xTimerCreateTimerTask() does is call prvCheckForValidListAndQueue(). That calls xQueueCreate(), which will allocate the queue data structure and the queue storage area. You have configTIMERQUEUELENGTH set to 10, so the storage area by itself will use 10 * sizof( DaemonTaskMessage_t ) bytes.

Next xTimerCreateTimerTask() calls xTaskCreate(), which will allocate the task's TCB (the size of which depends on other config options in FreeRTOSConfig.h - you can look at the data structure in tasks.c), and the task's stack, which you have set to probably about 100 bytes larger than it needs to be unless you are using the idle hook function.


OS consuming more memory than it should

Posted by mishung on February 12, 2017

Thank you, I'll try lowering the configMINIMALSTACKSIZE and see if it works out.


OS consuming more memory than it should

Posted by mishung on February 14, 2017

I was able to set the configMINIMALSTACKSIZE to 135 Bytes, that helped a bit.


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




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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

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

OpenRTOS and SafeRTOS