summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-12-19 16:03:54 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-12-19 16:03:54 +0000
commit8e30a269a21cd61ca1387e666e458e52c0b153ab (patch)
tree4d1cc760d319a170b335b9e90ea9d26162ffc687
parent2007-12-18 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-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.
-rw-r--r--cpukit/ChangeLog11
-rw-r--r--cpukit/libcsupport/Makefile.am3
-rw-r--r--cpukit/libcsupport/include/rtems/malloc.h1
-rw-r--r--cpukit/libcsupport/src/free.c7
-rw-r--r--cpukit/libcsupport/src/malloc.c32
-rw-r--r--cpukit/libcsupport/src/malloc_deferred.c53
-rw-r--r--cpukit/libcsupport/src/malloc_p.h6
-rw-r--r--cpukit/libcsupport/src/malloc_report_statistics_plugin.c6
-rw-r--r--cpukit/libcsupport/src/posix_memalign.c102
-rw-r--r--cpukit/libmisc/shell/shell.c8
-rw-r--r--cpukit/libmisc/shell/shell.h14
-rw-r--r--cpukit/score/src/objectinitializeinformation.c9
12 files changed, 215 insertions, 37 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index d3e286a494..7d265ec545 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,14 @@
+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.
+
2007-12-18 Joel Sherrill <joel.sherrill@oarcorp.com>
* libcsupport/Makefile.am, libcsupport/preinstall.am,
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
diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index ea87edb145..4bbbec4033 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -342,17 +342,17 @@ void rtems_shell_print_env(
}
#endif
-rtems_task rtems_shell_shell(rtems_task_argument task_argument)
+rtems_task rtems_shell_task(rtems_task_argument task_argument)
{
rtems_shell_env_t * shell_env = (rtems_shell_env_t*) task_argument;
- rtems_shell_shell_loop( shell_env );
+ rtems_shell_main_loop( shell_env );
rtems_task_delete( RTEMS_SELF );
}
#define RTEMS_SHELL_MAXIMUM_ARGUMENTS 128
-rtems_boolean rtems_shell_shell_loop(
+rtems_boolean rtems_shell_main_loop(
rtems_shell_env_t *shell_env_arg
)
{
@@ -535,6 +535,6 @@ rtems_status_code rtems_shell_init (
shell_env->exit_shell = FALSE;
shell_env->forever = forever;
- return rtems_task_start(task_id,rtems_shell_shell,
+ return rtems_task_start(task_id, rtems_shell_task,
(rtems_task_argument) shell_env);
}
diff --git a/cpukit/libmisc/shell/shell.h b/cpukit/libmisc/shell/shell.h
index fbaf1165ac..d9a2a53fe7 100644
--- a/cpukit/libmisc/shell/shell.h
+++ b/cpukit/libmisc/shell/shell.h
@@ -119,7 +119,7 @@ typedef struct {
uintptr_t mdump_addr;
} rtems_shell_env_t;
-rtems_boolean rtems_shell_shell_loop(
+rtems_boolean rtems_shell_main_loop(
rtems_shell_env_t *rtems_shell_env
);
@@ -137,10 +137,14 @@ extern rtems_shell_env_t *rtems_current_shell_env;
*/
struct rtems_shell_filesystems_tt;
typedef struct rtems_shell_filesystems_tt rtems_shell_filesystems_t;
-typedef int (*rtems_shell_filesystems_mounter_t)(const char* driver,
- const char* path,
- rtems_shell_filesystems_t* fs,
- rtems_filesystem_options_t options);
+
+typedef int (*rtems_shell_filesystems_mounter_t)(
+ const char* driver,
+ const char* path,
+ rtems_shell_filesystems_t* fs,
+ rtems_filesystem_options_t options
+);
+
struct rtems_shell_filesystems_tt {
const char* name;
int driver_needed;
diff --git a/cpukit/score/src/objectinitializeinformation.c b/cpukit/score/src/objectinitializeinformation.c
index ee9129ecfe..cdad1fcd94 100644
--- a/cpukit/score/src/objectinitializeinformation.c
+++ b/cpukit/score/src/objectinitializeinformation.c
@@ -63,10 +63,10 @@ void _Objects_Initialize_information(
)
{
static Objects_Control *null_local_table = NULL;
- uint32_t minimum_index;
- uint32_t name_length;
+ uint32_t minimum_index;
+ uint32_t name_length;
#if defined(RTEMS_MULTIPROCESSING)
- uint32_t index;
+ uint32_t index;
#endif
information->the_api = the_api;
@@ -96,7 +96,8 @@ void _Objects_Initialize_information(
* Are we operating in unlimited, or auto-extend mode
*/
- information->auto_extend = (maximum & OBJECTS_UNLIMITED_OBJECTS) ? TRUE : FALSE;
+ information->auto_extend =
+ (maximum & OBJECTS_UNLIMITED_OBJECTS) ? TRUE : FALSE;
maximum &= ~OBJECTS_UNLIMITED_OBJECTS;
/*