summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-27 11:44:48 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-28 11:23:53 +0100
commit01557b0c6e723627427195bb33bdfe0b125c70b1 (patch)
treeecd3bdb408cecd25bf24c25adb51dafdddedbc3a /cpukit/libcsupport
parentbdbuf: Fix race condition with sync active flag (diff)
downloadrtems-01557b0c6e723627427195bb33bdfe0b125c70b1.tar.bz2
libcsupport: Delete malloc statistics
Use the heap handler statistics instead. Add heap walk option to MALLOC shell command. close #1367
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r--cpukit/libcsupport/Makefile.am7
-rw-r--r--cpukit/libcsupport/include/rtems/malloc.h63
-rw-r--r--cpukit/libcsupport/src/calloc.c5
-rw-r--r--cpukit/libcsupport/src/free.c10
-rw-r--r--cpukit/libcsupport/src/malloc.c8
-rw-r--r--cpukit/libcsupport/src/malloc_get_statistics.c36
-rw-r--r--cpukit/libcsupport/src/malloc_initialize.c11
-rw-r--r--cpukit/libcsupport/src/malloc_p.h7
-rw-r--r--cpukit/libcsupport/src/malloc_report_statistics.c29
-rw-r--r--cpukit/libcsupport/src/malloc_report_statistics_plugin.c59
-rw-r--r--cpukit/libcsupport/src/malloc_statistics_helpers.c77
-rw-r--r--cpukit/libcsupport/src/posix_memalign.c6
-rw-r--r--cpukit/libcsupport/src/realloc.c4
-rw-r--r--cpukit/libcsupport/src/rtems_heap_extend_via_sbrk.c2
-rw-r--r--cpukit/libcsupport/src/rtems_memalign.c6
15 files changed, 5 insertions, 325 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am
index dfa8736ee0..1486194aa7 100644
--- a/cpukit/libcsupport/Makefile.am
+++ b/cpukit/libcsupport/Makefile.am
@@ -98,10 +98,9 @@ MALLOC_C_FILES = src/malloc_initialize.c src/calloc.c src/malloc.c \
src/realloc.c src/_calloc_r.c src/_malloc_r.c \
src/free.c src/_free_r.c \
src/_realloc_r.c src/mallocfreespace.c \
- src/mallocgetheapptr.c src/mallocsetheapptr.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/posix_memalign.c \
+ src/mallocgetheapptr.c src/mallocsetheapptr.c \
+ src/mallocinfo.c src/malloc_walk.c \
+ src/posix_memalign.c \
src/rtems_memalign.c src/malloc_deferred.c \
src/malloc_dirtier.c src/malloc_p.h src/rtems_malloc.c \
src/rtems_heap_extend_via_sbrk.c \
diff --git a/cpukit/libcsupport/include/rtems/malloc.h b/cpukit/libcsupport/include/rtems/malloc.h
index 25c2ead6de..7c00f21e77 100644
--- a/cpukit/libcsupport/include/rtems/malloc.h
+++ b/cpukit/libcsupport/include/rtems/malloc.h
@@ -48,34 +48,6 @@ void RTEMS_Malloc_Initialize(
Heap_Initialization_or_extend_handler extend
);
-/*
- * Malloc Statistics Structure
- */
-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;
- uint32_t max_depth; /* most ever malloc'd at 1 time */
- uintmax_t lifetime_allocated;
- uintmax_t lifetime_freed;
-} rtems_malloc_statistics_t;
-
-/*
- * Malloc statistics plugin
- */
-typedef struct {
- void (*initialize)(void);
- void (*at_malloc)(void *);
- void (*at_free)(void *);
-} rtems_malloc_statistics_functions_t;
-
-extern rtems_malloc_statistics_functions_t
- rtems_malloc_statistics_helpers_table;
-extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers;
-
extern ptrdiff_t RTEMS_Malloc_Sbrk_amount;
static inline void rtems_heap_set_sbrk_amount( ptrdiff_t sbrk_amount )
@@ -122,41 +94,6 @@ void rtems_malloc_dirty_memory(
);
/**
- * @brief Print Malloc Statistic Usage Report
- *
- * This method fills in the called provided malloc statistics area.
- *
- * @return This method returns 0 if successful and -1 on error.
- */
-int malloc_get_statistics(
- rtems_malloc_statistics_t *stats
-);
-
-/**
- * @brief Print Malloc Statistic Usage Report
- *
- * This method prints a malloc statistics report.
- *
- * @note It uses printk to print the report.
- */
-void malloc_report_statistics(void);
-
-/**
- * @brief Print Malloc Statistic Usage Report
- *
- * This method prints a malloc statistics report.
- *
- * @param[in] context is the context to pass to the print handler
- * @param[in] print is the print handler
- *
- * @note It uses the CALLER's routine to print the report.
- */
-void malloc_report_statistics_with_plugin(
- void *context,
- rtems_printk_plugin_t print
-);
-
-/**
* @brief RTEMS Variation on Aligned Memory Allocation
*
* This method is a help memalign implementation which does all
diff --git a/cpukit/libcsupport/src/calloc.c b/cpukit/libcsupport/src/calloc.c
index 095b467025..915ece3e17 100644
--- a/cpukit/libcsupport/src/calloc.c
+++ b/cpukit/libcsupport/src/calloc.c
@@ -19,7 +19,6 @@
#endif
#if defined(RTEMS_NEWLIB) && !defined(HAVE_CALLOC)
-#include "malloc_p.h"
#include <stdlib.h>
#include <string.h>
@@ -31,15 +30,11 @@ void *calloc(
char *cptr;
size_t length;
- MSBUMP(calloc_calls, 1);
-
length = nelem * elsize;
cptr = malloc( length );
if ( cptr )
memset( cptr, '\0', length );
- MSBUMP(malloc_calls, (uint32_t) -1); /* subtract off the malloc */
-
return cptr;
}
#endif
diff --git a/cpukit/libcsupport/src/free.c b/cpukit/libcsupport/src/free.c
index 2a7e3d931d..63eb7b8037 100644
--- a/cpukit/libcsupport/src/free.c
+++ b/cpukit/libcsupport/src/free.c
@@ -24,12 +24,12 @@
#include <rtems/score/sysstate.h>
+#include "malloc_p.h"
+
void free(
void *ptr
)
{
- MSBUMP(free_calls, 1);
-
if ( !ptr )
return;
@@ -41,12 +41,6 @@ void free(
return;
}
- /*
- * If configured, update the statistics
- */
- if ( rtems_malloc_statistics_helpers )
- (*rtems_malloc_statistics_helpers->at_free)(ptr);
-
if ( !_Protected_heap_Free( RTEMS_Malloc_Heap, ptr ) ) {
printk( "Program heap: free of bad pointer %p -- range %p - %p \n",
ptr,
diff --git a/cpukit/libcsupport/src/malloc.c b/cpukit/libcsupport/src/malloc.c
index 4645fdbbcb..73203e5b1c 100644
--- a/cpukit/libcsupport/src/malloc.c
+++ b/cpukit/libcsupport/src/malloc.c
@@ -30,8 +30,6 @@ void *malloc(
{
void *return_this;
- MSBUMP(malloc_calls, 1);
-
/*
* If some free's have been deferred, then do them now.
*/
@@ -71,12 +69,6 @@ void *malloc(
if ( rtems_malloc_dirty_helper )
(*rtems_malloc_dirty_helper)( return_this, size );
- /*
- * If configured, update the statistics
- */
- if ( rtems_malloc_statistics_helpers )
- (*rtems_malloc_statistics_helpers->at_malloc)(return_this);
-
return return_this;
}
diff --git a/cpukit/libcsupport/src/malloc_get_statistics.c b/cpukit/libcsupport/src/malloc_get_statistics.c
deleted file mode 100644
index a54a4c132a..0000000000
--- a/cpukit/libcsupport/src/malloc_get_statistics.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * @file
- *
- * @brief Print Malloc Statistic Usage Report
- * @ingroup MallocSupport
- */
-
-/*
- * 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.org/license/LICENSE.
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#ifdef RTEMS_NEWLIB
-#include "malloc_p.h"
-
-int malloc_get_statistics(
- rtems_malloc_statistics_t *stats
-)
-{
- if ( !stats )
- return -1;
- _RTEMS_Lock_allocator();
- *stats = rtems_malloc_statistics;
- _RTEMS_Unlock_allocator();
- return 0;
-}
-
-#endif
diff --git a/cpukit/libcsupport/src/malloc_initialize.c b/cpukit/libcsupport/src/malloc_initialize.c
index 75dc574b28..60fe2d94e6 100644
--- a/cpukit/libcsupport/src/malloc_initialize.c
+++ b/cpukit/libcsupport/src/malloc_initialize.c
@@ -22,8 +22,6 @@
#include "malloc_p.h"
#ifdef RTEMS_NEWLIB
-rtems_malloc_statistics_t rtems_malloc_statistics;
-
void RTEMS_Malloc_Initialize(
const Heap_Area *areas,
size_t area_count,
@@ -59,15 +57,6 @@ void RTEMS_Malloc_Initialize(
);
}
}
-
- /*
- * If configured, initialize the statistics support
- */
- if ( rtems_malloc_statistics_helpers != NULL ) {
- (*rtems_malloc_statistics_helpers->initialize)();
- }
-
- MSBUMP( space_available, _Protected_heap_Get_size( heap ) );
}
#else
void RTEMS_Malloc_Initialize(
diff --git a/cpukit/libcsupport/src/malloc_p.h b/cpukit/libcsupport/src/malloc_p.h
index 4295aebfda..89adc5fdfe 100644
--- a/cpukit/libcsupport/src/malloc_p.h
+++ b/cpukit/libcsupport/src/malloc_p.h
@@ -22,13 +22,6 @@
#include <rtems/chain.h>
/*
- * Malloc Statistics Structure
- */
-extern rtems_malloc_statistics_t rtems_malloc_statistics;
-
-#define MSBUMP(_f,_n) rtems_malloc_statistics._f += (_n)
-
-/*
* Process deferred free operations
*/
bool malloc_is_system_state_OK(void);
diff --git a/cpukit/libcsupport/src/malloc_report_statistics.c b/cpukit/libcsupport/src/malloc_report_statistics.c
deleted file mode 100644
index d726b72ed2..0000000000
--- a/cpukit/libcsupport/src/malloc_report_statistics.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * @file
- *
- * @brief Print Malloc Statistic Usage Report
- * @ingroup MallocSupport
- */
-
-/*
- * 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.org/license/LICENSE.
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#ifdef RTEMS_NEWLIB
-#include "malloc_p.h"
-
-void malloc_report_statistics(void)
-{
- malloc_report_statistics_with_plugin( NULL, printk_plugin );
-}
-
-#endif
diff --git a/cpukit/libcsupport/src/malloc_report_statistics_plugin.c b/cpukit/libcsupport/src/malloc_report_statistics_plugin.c
deleted file mode 100644
index 1113944fe4..0000000000
--- a/cpukit/libcsupport/src/malloc_report_statistics_plugin.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * malloc_report_statistics with plugin Implementation
- *
- * 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.org/license/LICENSE.
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#ifdef RTEMS_NEWLIB
-#include "malloc_p.h"
-#include "inttypes.h"
-
-void malloc_report_statistics_with_plugin(
- void *context,
- rtems_printk_plugin_t print
-)
-{
- rtems_malloc_statistics_t *s = &rtems_malloc_statistics;
- uint32_t space_available = s->space_available;
- uint32_t allocated = (uint32_t) (s->lifetime_allocated - s->lifetime_freed);
- uint32_t max_depth = s->max_depth;
- /* avoid float! */
- uint32_t allocated_per_cent = (allocated * 100) / space_available;
- uint32_t max_depth_per_cent = (max_depth * 100) / space_available;
-
- (*print)(
- context,
- "Malloc statistics\n"
- " avail:%"PRIu32"k allocated:%"PRIu32"k (%"PRIu32"%%) "
- "max:%"PRIu32"k (%"PRIu32"%%)"
- " lifetime:%"PRIuMAX"k freed:%"PRIuMAX"k\n",
- space_available / 1024,
- allocated / 1024,
- allocated_per_cent,
- max_depth / 1024,
- max_depth_per_cent,
- s->lifetime_allocated / 1024,
- s->lifetime_freed / 1024
- );
- (*print)(
- context,
- " Call counts: malloc:%"PRIu32" memalign:%"PRIu32" free:%"PRIu32
- " realloc:%"PRIu32" calloc:%"PRIu32"\n",
- s->malloc_calls,
- s->memalign_calls,
- s->free_calls,
- s->realloc_calls,
- s->calloc_calls
- );
-}
-
-#endif
diff --git a/cpukit/libcsupport/src/malloc_statistics_helpers.c b/cpukit/libcsupport/src/malloc_statistics_helpers.c
deleted file mode 100644
index 1ac128f1e0..0000000000
--- a/cpukit/libcsupport/src/malloc_statistics_helpers.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * @file
- *
- * @brief Malloc Statistics Support
- * @ingroup MallocSupport
- */
-
-/*
- * 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.org/license/LICENSE.
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#ifdef RTEMS_NEWLIB
-#include "malloc_p.h"
-
-#include <sys/reent.h>
-#include <stdlib.h>
-#include <string.h>
-
-static void rtems_malloc_statistics_initialize( void )
-{
- /*
- * Zero all the statistics
- */
- (void) memset(&rtems_malloc_statistics, 0, sizeof(rtems_malloc_statistics));
-}
-
-static void rtems_malloc_statistics_at_malloc(
- void *pointer
-)
-{
- uintptr_t actual_size = 0;
- uint32_t current_depth;
- rtems_malloc_statistics_t *s = &rtems_malloc_statistics;
-
- if ( !pointer )
- return;
-
- _Protected_heap_Get_block_size(RTEMS_Malloc_Heap, pointer, &actual_size);
-
- MSBUMP(lifetime_allocated, actual_size);
-
- current_depth = (uint32_t) (s->lifetime_allocated - s->lifetime_freed);
- if (current_depth > s->max_depth)
- s->max_depth = current_depth;
-}
-
-/**
- * If the pointer is not in the heap, then we won't be able to get its
- * size and thus we skip updating the statistics.
- */
-static void rtems_malloc_statistics_at_free(
- void *pointer
-)
-{
- uintptr_t size;
-
- if (_Protected_heap_Get_block_size(RTEMS_Malloc_Heap, pointer, &size) ) {
- MSBUMP(lifetime_freed, size);
- }
-}
-
-rtems_malloc_statistics_functions_t rtems_malloc_statistics_helpers_table = {
- rtems_malloc_statistics_initialize,
- rtems_malloc_statistics_at_malloc,
- rtems_malloc_statistics_at_free,
-};
-
-#endif
diff --git a/cpukit/libcsupport/src/posix_memalign.c b/cpukit/libcsupport/src/posix_memalign.c
index 97e3080965..80865cdc10 100644
--- a/cpukit/libcsupport/src/posix_memalign.c
+++ b/cpukit/libcsupport/src/posix_memalign.c
@@ -1,7 +1,6 @@
/**
* @file
*
- * @brief Update call statistics
* @ingroup libcsupport
*/
@@ -30,11 +29,6 @@ int posix_memalign(
size_t size
)
{
- /*
- * Update call statistics
- */
- MSBUMP(memalign_calls, 1);
-
if (((alignment - 1) & alignment) != 0 || (alignment < sizeof(void *)))
return EINVAL;
diff --git a/cpukit/libcsupport/src/realloc.c b/cpukit/libcsupport/src/realloc.c
index 2ca239d464..6efdfdfdb8 100644
--- a/cpukit/libcsupport/src/realloc.c
+++ b/cpukit/libcsupport/src/realloc.c
@@ -35,8 +35,6 @@ void *realloc(
uintptr_t old_size;
char *new_area;
- MSBUMP(realloc_calls, 1);
-
/*
* Do not attempt to allocate memory if in a critical section or ISR.
*/
@@ -77,8 +75,6 @@ void *realloc(
new_area = malloc( size );
- MSBUMP(malloc_calls, (uint32_t) -1); /* subtract off the malloc */
-
if ( !new_area ) {
return (void *) 0;
}
diff --git a/cpukit/libcsupport/src/rtems_heap_extend_via_sbrk.c b/cpukit/libcsupport/src/rtems_heap_extend_via_sbrk.c
index e895dc5cb8..61bc1cfd3f 100644
--- a/cpukit/libcsupport/src/rtems_heap_extend_via_sbrk.c
+++ b/cpukit/libcsupport/src/rtems_heap_extend_via_sbrk.c
@@ -52,8 +52,6 @@ void *rtems_heap_extend_via_sbrk(
bool ok = _Protected_heap_Extend( heap, area_begin, sbrk_size );
if ( ok ) {
- MSBUMP( space_available, sbrk_size );
-
return_this = _Protected_heap_Allocate( heap, alloc_size );
} else {
sbrk( -sbrk_size );
diff --git a/cpukit/libcsupport/src/rtems_memalign.c b/cpukit/libcsupport/src/rtems_memalign.c
index 1b9c6bc4b3..5755fa0b3c 100644
--- a/cpukit/libcsupport/src/rtems_memalign.c
+++ b/cpukit/libcsupport/src/rtems_memalign.c
@@ -62,12 +62,6 @@ int rtems_memalign(
if ( !return_this )
return ENOMEM;
- /*
- * If configured, update the more involved statistics
- */
- if ( rtems_malloc_statistics_helpers )
- (*rtems_malloc_statistics_helpers->at_malloc)(pointer);
-
*pointer = return_this;
return 0;
}