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

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 ]    [ 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