diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-12-19 16:03:54 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-12-19 16:03:54 +0000 |
commit | 8e30a269a21cd61ca1387e666e458e52c0b153ab (patch) | |
tree | 4d1cc760d319a170b335b9e90ea9d26162ffc687 /cpukit/libcsupport | |
parent | 2007-12-18 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-8e30a269a21cd61ca1387e666e458e52c0b153ab.tar.bz2 |
2007-12-19 Joel Sherrill <joel.sherrill@OARcorp.com>
* libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h,
libcsupport/src/free.c, libcsupport/src/malloc.c,
libcsupport/src/malloc_p.h,
libcsupport/src/malloc_report_statistics_plugin.c,
libmisc/shell/shell.c, libmisc/shell/shell.h,
score/src/objectinitializeinformation.c: Add posix_memalign. Split
out management of deferred frees to subroutines.
* libcsupport/src/malloc_deferred.c, libcsupport/src/posix_memalign.c: New files.
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r-- | cpukit/libcsupport/Makefile.am | 3 | ||||
-rw-r--r-- | cpukit/libcsupport/include/rtems/malloc.h | 1 | ||||
-rw-r--r-- | cpukit/libcsupport/src/free.c | 7 | ||||
-rw-r--r-- | cpukit/libcsupport/src/malloc.c | 32 | ||||
-rw-r--r-- | cpukit/libcsupport/src/malloc_deferred.c | 53 | ||||
-rw-r--r-- | cpukit/libcsupport/src/malloc_p.h | 6 | ||||
-rw-r--r-- | cpukit/libcsupport/src/malloc_report_statistics_plugin.c | 6 | ||||
-rw-r--r-- | cpukit/libcsupport/src/posix_memalign.c | 102 |
8 files changed, 186 insertions, 24 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am index 0f54c5c3f9..c32a88d5e0 100644 --- a/cpukit/libcsupport/Makefile.am +++ b/cpukit/libcsupport/Makefile.am @@ -83,7 +83,8 @@ MALLOC_C_FILES = src/malloc_initialize.c src/calloc.c src/malloc.c \ src/_realloc_r.c src/__brk.c src/__sbrk.c src/mallocfreespace.c \ src/mallocinfo.c src/malloc_walk.c src/malloc_get_statistics.c \ src/malloc_report_statistics.c src/malloc_report_statistics_plugin.c \ - src/malloc_statistics_helpers.c src/malloc_boundary.c + src/malloc_statistics_helpers.c src/malloc_boundary.c src/posix_memalign.c \ + src/malloc_deferred.c PASSWORD_GROUP_C_FILES = src/getpwent.c diff --git a/cpukit/libcsupport/include/rtems/malloc.h b/cpukit/libcsupport/include/rtems/malloc.h index abf31f8406..763830397a 100644 --- a/cpukit/libcsupport/include/rtems/malloc.h +++ b/cpukit/libcsupport/include/rtems/malloc.h @@ -29,6 +29,7 @@ typedef struct { uint32_t space_available; /* current size of malloc area */ uint32_t malloc_calls; /* # calls to malloc */ + uint32_t memalign_calls; /* # calls to memalign */ uint32_t free_calls; uint32_t realloc_calls; uint32_t calloc_calls; diff --git a/cpukit/libcsupport/src/free.c b/cpukit/libcsupport/src/free.c index 160e560bba..be23388888 100644 --- a/cpukit/libcsupport/src/free.c +++ b/cpukit/libcsupport/src/free.c @@ -36,11 +36,10 @@ void free( * Do not attempt to free memory if in a critical section or ISR. */ - if (_System_state_Is_up(_System_state_Get())) { - if ((_Thread_Dispatch_disable_level > 0) || (_ISR_Nest_level > 0)) { - Chain_Append(&RTEMS_Malloc_GC_list, (Chain_Node *)ptr); + if ( _System_state_Is_up(_System_state_Get()) && + !malloc_is_system_state_OK() ) { + malloc_defer_free(ptr); return; - } } #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS) diff --git a/cpukit/libcsupport/src/malloc.c b/cpukit/libcsupport/src/malloc.c index d1b3bb3504..a77444dc2c 100644 --- a/cpukit/libcsupport/src/malloc.c +++ b/cpukit/libcsupport/src/malloc.c @@ -34,30 +34,30 @@ void *malloc( MSBUMP(malloc_calls, 1); + /* + * If some free's have been deferred, then do them now. + */ + malloc_process_deferred_frees(); + + /* + * Validate the parameters + */ if ( !size ) return (void *) 0; - #if defined(RTEMS_HEAP_DEBUG) - _Protected_heap_Walk( &RTEMS_Malloc_Heap, 0, FALSE ); - #endif - /* - * Do not attempt to allocate memory if in a critical section or ISR. + * Do not attempt to allocate memory if not in correct system state. */ - - if (_System_state_Is_up(_System_state_Get())) { - if (_Thread_Dispatch_disable_level > 0) - return (void *) 0; - - if (_ISR_Nest_level > 0) - return (void *) 0; - } + if ( _System_state_Is_up(_System_state_Get()) && + !malloc_is_system_state_OK() ) + return NULL; /* - * If some free's have been deferred, then do them now. + * Walk the heap and verify its integrity */ - while ((to_be_freed = Chain_Get(&RTEMS_Malloc_GC_list)) != NULL) - free(to_be_freed); + #if defined(RTEMS_HEAP_DEBUG) + _Protected_heap_Walk( &RTEMS_Malloc_Heap, 0, FALSE ); + #endif #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS) /* diff --git a/cpukit/libcsupport/src/malloc_deferred.c b/cpukit/libcsupport/src/malloc_deferred.c new file mode 100644 index 0000000000..9e8a259deb --- /dev/null +++ b/cpukit/libcsupport/src/malloc_deferred.c @@ -0,0 +1,53 @@ +/* + * Process free requests deferred because they were from ISR + * or other critical section. + * + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef RTEMS_NEWLIB +#include <stdlib.h> +#include <errno.h> + +#include "malloc_p.h" + +boolean malloc_is_system_state_OK(void) +{ + if ( _Thread_Dispatch_disable_level > 0 ) + return FALSE; + + if ( _ISR_Nest_level > 0 ) + return FALSE; + + return TRUE; +} + +void malloc_process_deferred_frees(void) +{ + Chain_Node *to_be_freed; + + /* + * If some free's have been deferred, then do them now. + */ + while ((to_be_freed = Chain_Get(&RTEMS_Malloc_GC_list)) != NULL) + free(to_be_freed); +} + +void malloc_defer_free( + void *pointer +) +{ + Chain_Append(&RTEMS_Malloc_GC_list, (Chain_Node *)pointer); +} +#endif diff --git a/cpukit/libcsupport/src/malloc_p.h b/cpukit/libcsupport/src/malloc_p.h index 95f73d72b1..3c2cdddf87 100644 --- a/cpukit/libcsupport/src/malloc_p.h +++ b/cpukit/libcsupport/src/malloc_p.h @@ -53,3 +53,9 @@ extern rtems_malloc_statistics_t rtems_malloc_statistics; */ #define MALLOC_DIRTY +/* + * Process deferred free operations + */ +boolean malloc_is_system_state_OK(void); +void malloc_process_deferred_frees(void); +void malloc_defer_free(void *); diff --git a/cpukit/libcsupport/src/malloc_report_statistics_plugin.c b/cpukit/libcsupport/src/malloc_report_statistics_plugin.c index 2f00477d44..c89cc46da6 100644 --- a/cpukit/libcsupport/src/malloc_report_statistics_plugin.c +++ b/cpukit/libcsupport/src/malloc_report_statistics_plugin.c @@ -36,15 +36,15 @@ void malloc_report_statistics_with_plugin( "Malloc statistics\n" " avail:%"PRIu32"k allocated:%"PRIu32"k (%"PRId32"%%) " "max:%"PRIu32"k (%"PRIu32"%%)" - " lifetime:%"PRIuMAX"k freed:%"PRIuMAX"k\n", + " lifetime:%"PRIu32"k freed:%"PRIu32"k\n", s->space_available / 1024, allocated / 1024, /* avoid float! */ (allocated * 100) / s->space_available, s->max_depth / 1024, (s->max_depth * 100) / s->space_available, - s->lifetime_allocated / 1024, - s->lifetime_freed / 1024 + (uint32_t) (s->lifetime_allocated / 1024), + (uint32_t) (s->lifetime_freed / 1024) ); (*print)( context, diff --git a/cpukit/libcsupport/src/posix_memalign.c b/cpukit/libcsupport/src/posix_memalign.c new file mode 100644 index 0000000000..c3dae3449e --- /dev/null +++ b/cpukit/libcsupport/src/posix_memalign.c @@ -0,0 +1,102 @@ +/* + * posix_memalign() + * + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef RTEMS_NEWLIB +#include "malloc_p.h" + +#include <stdlib.h> +#include <errno.h> + +int posix_memalign( + void **pointer, + size_t alignment, + size_t size +) +{ + void *return_this; + + /* + * Update call statistics + */ + MSBUMP(memalign_calls, 1); + + /* + * Parameter error checks + */ + if ( !pointer ) + return EINVAL; + + *pointer = NULL; + + if (((alignment - 1) & alignment) != 0 || (alignment < sizeof(void *))) + return EINVAL; + + if ( !size ) + return EINVAL; + + /* + * Do not attempt to allocate memory if not in correct system state. + */ + if ( _System_state_Is_up(_System_state_Get()) && + !malloc_is_system_state_OK() ) + return EINVAL; + + /* + * + * If some free's have been deferred, then do them now. + */ + malloc_process_deferred_frees(); + + #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS) + /* + * If the support for a boundary area at the end of the heap + * block allocated is turned on, then adjust the size. + */ + if (rtems_malloc_boundary_helpers) + size += (*rtems_malloc_boundary_helpers->overhead)(); + #endif + + /* + * Perform the aligned allocation requested + */ + + return_this = _Protected_heap_Allocate_aligned( + &RTEMS_Malloc_Heap, + size, + alignment + ); + if ( !return_this ) + return ENOMEM; + + /* + * If configured, update the more involved statistics + */ + if ( rtems_malloc_statistics_helpers ) + (*rtems_malloc_statistics_helpers->at_malloc)(pointer); + + #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS) + /* + * If configured, set the boundary area + */ + if (rtems_malloc_boundary_helpers) + (*rtems_malloc_boundary_helpers->at_malloc)(return_this, size); + #endif + + *pointer = return_this; + return 0; +} +#endif |