From d7205f0083f8fdd0408404ce99c6eab9b8d120c7 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 8 Apr 2020 17:14:41 +0200 Subject: libc: Optimize malloc() initialization The BSPs provide memory for the separate C Program Heap initialization via _Memory_Get(). Most BSPs provide exactly one memory area. Only two BSPs provide more than one memory area (arm/altera-cyclone-v and bsps/powerpc/mpc55xxevb). Only if more than one memory area is provided, there is a need to use _Heap_Extend(). Provide two implementations to initialize the separate C Program Heap and let the BSP select one of the implementations based on the number of provided memory areas. This gets rid of a dependency on _Heap_Extend(). It also avoids dead code sections for most BSPs. Change licence to BSD-2-Clause according to file history. Update #3053. --- testsuites/libtests/malloc04/init.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'testsuites') diff --git a/testsuites/libtests/malloc04/init.c b/testsuites/libtests/malloc04/init.c index 51d318850b..8f05c63a79 100644 --- a/testsuites/libtests/malloc04/init.c +++ b/testsuites/libtests/malloc04/init.c @@ -78,16 +78,23 @@ rtems_task Init( ) { Heap_Control *real_heap; - Memory_Area area; - Memory_Information mem = { - .count = 1, - .areas = &area - }; + const Memory_Information *mem; + Memory_Area *area; + size_t i; void *p; TEST_BEGIN(); + mem = _Memory_Get(); + + for ( i = 0; i < _Memory_Get_count( mem ); ++i ) { + area = _Memory_Get_area( mem, i ); + _Memory_Initialize( area, NULL, NULL ); + } + + area = _Memory_Get_area( mem, 0 ); + /* Safe information on real heap */ real_heap = malloc_get_heap_pointer(); malloc_set_heap_pointer( &TempHeap ); @@ -98,8 +105,8 @@ rtems_task Init( sbrk_count = 0; offset = 256; - _Memory_Initialize_by_size( &area, &Malloc_Heap[ 0 ], offset ); - RTEMS_Malloc_Initialize( &mem, NULL ); + _Memory_Initialize_by_size( area, &Malloc_Heap[ 0 ], offset ); + _Malloc_Initialize(); errno = 0; p = malloc( 256 ); @@ -113,8 +120,8 @@ rtems_task Init( sbrk_count = 0; offset = 256; - _Memory_Initialize_by_size( &area, &Malloc_Heap[ 0 ], offset ); - RTEMS_Malloc_Initialize( &mem, NULL ); + _Memory_Initialize_by_size( area, &Malloc_Heap[ 0 ], offset ); + _Malloc_Initialize(); p = malloc(1); rtems_test_assert( p != NULL ); @@ -128,8 +135,8 @@ rtems_task Init( sbrk_count = 0; offset = 256; - _Memory_Initialize_by_size( &area, &Malloc_Heap[ 0 ], offset ); - RTEMS_Malloc_Initialize( &mem, NULL ); + _Memory_Initialize_by_size( area, &Malloc_Heap[ 0 ], offset ); + _Malloc_Initialize(); errno = 0; p = malloc( sizeof( Malloc_Heap ) ); @@ -141,8 +148,8 @@ rtems_task Init( sbrk_count = 0; offset = 256; - _Memory_Initialize_by_size( &area, &Malloc_Heap[ 0 ], offset ); - RTEMS_Malloc_Initialize( &mem, NULL ); + _Memory_Initialize_by_size( area, &Malloc_Heap[ 0 ], offset ); + _Malloc_Initialize(); p = malloc( 128 ); rtems_test_assert( p != NULL ); @@ -156,8 +163,8 @@ rtems_task Init( sbrk_count = -1; offset = 256; - _Memory_Initialize_by_size( &area, &Malloc_Heap[ 0 ], offset ); - RTEMS_Malloc_Initialize( &mem, NULL ); + _Memory_Initialize_by_size( area, &Malloc_Heap[ 0 ], offset ); + _Malloc_Initialize(); errno = 0; p = malloc( 256 ); -- cgit v1.2.3