Quality RTOS & Embedded Software

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


Loading

avoid double thread locking of malloc/free on IAR EW for MSP430 with heap_3.c

Posted by gmenhennitt on January 30, 2014

IAR Embedded Workbench for MSP430 (and, I would guess, other IAR products) has an option "Enable thread support in library". If this is ticked, the library puts locks around calls to malloc() and free() to give thread safety. The developer is responsible for implementing four functions to implement the locking (see http://supp.iar.com/FilesPublic/UPDINFO/005691/arm/doc/infocenter/DLIBThreadSupport.html). When using this with FreeRTOS, it seems to be sufficient that locking calls vTaskSuspendAll() and unlocking calls xTaskResumeAll() (similar to what heap_3.c does).

However, that means that FreeRTOS's pvPortMalloc() and vPortFree() in heap3.c do the lock and unlock twice - once in heap3.c and once in the IAR library. I'm not sure what the overhead of this is, or if there are any adverse effects (I doubt that there are). But it's fairly trivial to avoid.

I've modified FreeRTOS.h to add a new config option configLOCKMALLOCFREE which causes the duplicate calls to be omitted. I then set that in FreeRTOSConfig.h to 1. Then I wrapped the calls in heap_3.c in #if's so that they get omitted.

The attached files are diffs against FreeRTOS 7.6.0 to implement this, together with a sample file locking.c that can be added to the project to implement the locking.

Graham


avoid double thread locking of malloc/free on IAR EW for MSP430 with heap_3.c

Posted by gmenhennitt on January 30, 2014

attachments

Attachments

FreeRTOS.h_patch (477 bytes)
heap_3.c_patch (1081 bytes)

avoid double thread locking of malloc/free on IAR EW for MSP430 with heap_3.c

Posted by gmenhennitt on January 30, 2014

oops, missed one

Attachments

locking.c (450 bytes)

avoid double thread locking of malloc/free on IAR EW for MSP430 with heap_3.c

Posted by edwards3 on January 30, 2014

The vTaskSuspend/Resume functions are designed to nest, and have very little overhead when called with a nest bigger than 0.

What advantage does using the IAR locks have over just using heap_3?


avoid double thread locking of malloc/free on IAR EW for MSP430 with heap_3.c

Posted by gmenhennitt on January 30, 2014

If the developer calls directly to malloc()/free() as opposed to pvPortMalloc()/vPortFree(), they'll bypass the locks in heap_3.c. So they're needed for anything that doesn't know about FreeRTOS e.g. any third party libraries, or any calls from inside the IAR libraries. They're used for C++ new/delete too.


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


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

Xilinx Microblaze and Zynq partner