Changeset cfcc4e20 in rtems


Ignore:
Timestamp:
Jan 8, 2008, 10:59:14 PM (12 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.9, master
Children:
b36dc03
Parents:
c8f8ffd
Message:

2008-01-08 Joel Sherrill <joel.sherrill@…>

  • libcsupport/Makefile.am: Add malloc_sbrk_helpers.c.
  • libcsupport/include/rtems/malloc.h, libcsupport/src/malloc.c, libcsupport/src/malloc_initialize.c, libcsupport/src/malloc_p.h, libcsupport/src/malloc_statistics_helpers.c: Make sbrk() support pluggable and optional. This eliminates the need for heap extend and sbrk in the minimum footprint which is ~2.5K on the SPARC.
  • sapi/include/confdefs.h: Add the following configuration points: + CONFIGURE_MALLOC_STATISTICS + CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
  • libcsupport/src/malloc_sbrk_helpers.c: New file.
Location:
cpukit
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rc8f8ffd rcfcc4e20  
     12008-01-08      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * libcsupport/Makefile.am: Add malloc_sbrk_helpers.c.
     4        * libcsupport/include/rtems/malloc.h,
     5        libcsupport/src/malloc.c, libcsupport/src/malloc_initialize.c,
     6        libcsupport/src/malloc_p.h,
     7        libcsupport/src/malloc_statistics_helpers.c: Make sbrk()
     8        support pluggable and optional.  This eliminates the need for
     9        heap extend and sbrk in the minimum footprint which is ~2.5K on
     10        the SPARC.
     11        * sapi/include/confdefs.h: Add the following configuration points:
     12          + CONFIGURE_MALLOC_STATISTICS
     13          + CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
     14        * libcsupport/src/malloc_sbrk_helpers.c: New file.
     15
    1162008-01-08      Joel Sherrill <joel.sherrill@OARcorp.com>
    217
  • cpukit/libcsupport/Makefile.am

    rc8f8ffd rcfcc4e20  
    8585   src/malloc_report_statistics.c src/malloc_report_statistics_plugin.c \
    8686   src/malloc_statistics_helpers.c src/malloc_boundary.c src/posix_memalign.c \
    87    src/malloc_deferred.c
     87   src/malloc_deferred.c src/malloc_sbrk_helpers.c
    8888
    8989PASSWORD_GROUP_C_FILES = src/getpwent.c
  • cpukit/libcsupport/include/rtems/malloc.h

    rc8f8ffd rcfcc4e20  
    66 *  RTEMS Malloc Extensions
    77 *
    8  *  COPYRIGHT (c) 1989-1997.
     8 *  COPYRIGHT (c) 1989-2007.
    99 *  On-Line Applications Research Corporation (OAR).
    1010 *
     
    1313 *  http://www.rtems.com/license/LICENSE.
    1414 *
    15  * $ld:
     15 * $Id$
    1616 */
    1717
     
    4646  void (*at_malloc)(void *);
    4747  void (*at_free)(void *);
    48 } rtems_malloc_statististics_functions_t;
     48} rtems_malloc_statistics_functions_t;
    4949
    50 extern rtems_malloc_statististics_functions_t
     50extern rtems_malloc_statistics_functions_t
    5151  rtems_malloc_statistics_helpers_table;
    52 extern rtems_malloc_statististics_functions_t *rtems_malloc_statistics_helpers;
     52extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers;
    5353
    5454/*
     
    6666extern rtems_malloc_boundary_functions_t *rtems_malloc_boundary_helpers;
    6767
     68/*
     69 *  Malloc Heap Extension (sbrk) plugin
     70 */
     71typedef struct {
     72  void *(*initialize)(void *, size_t);
     73  void *(*extend)(size_t);
     74} rtems_malloc_sbrk_functions_t;
    6875
     76extern rtems_malloc_sbrk_functions_t rtems_malloc_sbrk_helpers_table;
     77extern rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers;
    6978
    7079/** @brief Print Malloc Statistic Usage Report
  • cpukit/libcsupport/src/malloc.c

    rc8f8ffd rcfcc4e20  
    2828{
    2929  void        *return_this;
    30   void        *starting_address;
    31   uint32_t     the_size;
    32   uint32_t     sbrk_amount;
    3330  Chain_Node  *to_be_freed;
    3431
     
    7875
    7976  if ( !return_this ) {
    80     /*
    81      *  Round to the "requested sbrk amount" so hopefully we won't have
    82      *  to grow again for a while.  This effectively does sbrk() calls
    83      *  in "page" amounts.
    84      */
    85 
    86     sbrk_amount = RTEMS_Malloc_Sbrk_amount;
    87 
    88     if ( sbrk_amount == 0 )
    89       return (void *) 0;
    90 
    91     the_size = ((size + sbrk_amount) / sbrk_amount * sbrk_amount);
    92 
    93     if ((starting_address = (void *)sbrk(the_size))
    94             == (void*) -1)
    95       return (void *) 0;
    96 
    97     if ( !_Protected_heap_Extend(
    98             &RTEMS_Malloc_Heap, starting_address, the_size) ) {
    99       sbrk(-the_size);
    100       errno = ENOMEM;
    101       return (void *) 0;
    102     }
    103 
    104     MSBUMP(space_available, the_size);
    105 
    106     return_this = _Protected_heap_Allocate( &RTEMS_Malloc_Heap, size );
     77    if (rtems_malloc_sbrk_helpers)
     78      return_this = (*rtems_malloc_sbrk_helpers->extend)( size );
    10779    if ( !return_this ) {
    10880      errno = ENOMEM;
  • cpukit/libcsupport/src/malloc_initialize.c

    rc8f8ffd rcfcc4e20  
    2323Heap_Control              RTEMS_Malloc_Heap;
    2424Chain_Control             RTEMS_Malloc_GC_list;
    25 size_t                    RTEMS_Malloc_Sbrk_amount;
    2625rtems_malloc_statistics_t rtems_malloc_statistics;
    2726
     
    3433  uint32_t      status;
    3534  void         *starting_address;
    36   uintptr_t     old_address;
    37   uintptr_t     uaddress;
    3835
    3936  #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
     
    5653  Chain_Initialize_empty(&RTEMS_Malloc_GC_list);
    5754
     55  starting_address = start;
     56
    5857  /*
    59    * If the starting address is 0 then we are to attempt to
    60    * get length worth of memory using sbrk. Make sure we
    61    * align the address that we get back.
     58   *  Initialize the optional sbrk support for extending the heap
    6259   */
    63 
    64   starting_address = start;
    65   RTEMS_Malloc_Sbrk_amount = sbrk_amount;
    66 
    67   if (!starting_address) {
    68     uaddress = (uintptr_t)sbrk(length);
    69 
    70     if (uaddress == (uintptr_t) -1) {
    71       rtems_fatal_error_occurred( RTEMS_NO_MEMORY );
    72       /* DOES NOT RETURN!!! */
    73     }
    74 
    75     if (uaddress & (CPU_HEAP_ALIGNMENT-1)) {
    76       old_address = uaddress;
    77       uaddress = (uaddress + CPU_HEAP_ALIGNMENT) & ~(CPU_HEAP_ALIGNMENT-1);
    78 
    79       /*
    80        * adjust the length by whatever we aligned by
    81        */
    82       length -= uaddress - old_address;
    83     }
    84 
    85     starting_address = (void *)uaddress;
     60  if (rtems_malloc_sbrk_helpers) {
     61    starting_address = (*rtems_malloc_sbrk_helpers->initialize)(
     62      start,
     63      sbrk_amount
     64    );
    8665  }
    87 
     66   
    8867  /*
    8968   *  If the BSP is not clearing out the workspace, then it is most likely
  • cpukit/libcsupport/src/malloc_p.h

    rc8f8ffd rcfcc4e20  
    4040extern Heap_Control  RTEMS_Malloc_Heap;
    4141extern Chain_Control RTEMS_Malloc_GC_list;
    42 extern size_t        RTEMS_Malloc_Sbrk_amount;
    4342
    4443/*
  • cpukit/libcsupport/src/malloc_statistics_helpers.c

    rc8f8ffd rcfcc4e20  
    6767}
    6868
    69 rtems_malloc_statististics_functions_t rtems_malloc_statistics_helpers_table = {
     69rtems_malloc_statistics_functions_t rtems_malloc_statistics_helpers_table = {
    7070  rtems_malloc_statistics_initialize,
    7171  rtems_malloc_statistics_at_malloc,
     
    7373};
    7474
    75 rtems_malloc_statististics_functions_t *rtems_malloc_statistics_helpers =
    76   &rtems_malloc_statistics_helpers_table;
    77 
    7875#endif
    7976
  • cpukit/sapi/include/confdefs.h

    rc8f8ffd rcfcc4e20  
    241241    #define CONFIGURE_ZERO_WORKSPACE_AUTOMATICALLY FALSE
    242242  #endif
     243#endif
     244
     245/*
     246 *  RTEMS Malloc configuration
     247 */
     248
     249#include <rtems/malloc.h>
     250
     251#ifdef CONFIGURE_INIT
     252  rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers =
     253    #ifndef CONFIGURE_MALLOC_STATISTICS
     254      NULL;
     255    #else
     256      &rtems_malloc_statistics_helpers_table;
     257    #endif
     258#endif
     259
     260#ifdef CONFIGURE_INIT
     261  rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers =
     262    #ifndef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
     263      NULL;
     264    #else
     265      &rtems_malloc_sbrk_helpers_table;
     266    #endif
    243267#endif
    244268
Note: See TracChangeset for help on using the changeset viewer.