Changeset e746a88 in rtems


Ignore:
Timestamp:
May 3, 2007, 9:33:39 PM (13 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
9f260c4
Parents:
40ff680
Message:

2007-05-03 Joel Sherrill <joel@…>

  • ChangeLog?, libcsupport/src/malloc.c, libcsupport/src/mallocfreespace.c, sapi/include/confdefs.h, score/Makefile.am, score/preinstall.am: malloc never blocks so the Region Manager is quite heavy for implementing this. This patch implements the C Program Heap directly in terms of the new Protected Heap handler. This handler is a direct use of a SuperCore? Heap in conjunction with the Allocator Mutex used internally by RTEMS. This saves 3184 bytes on most SPARC test executables.
  • score/include/rtems/score/protectedheap.h, score/src/pheapallocate.c, score/src/pheapallocatealigned.c, score/src/pheapextend.c, score/src/pheapfree.c, score/src/pheapgetblocksize.c, score/src/pheapgetfreeinfo.c, score/src/pheapgetinfo.c, score/src/pheapinit.c, score/src/pheapresizeblock.c, score/src/pheapwalk.c: New files.
Location:
cpukit
Files:
11 added
6 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r40ff680 re746a88  
     12007-05-03      Joel Sherrill <joel@OARcorp.com>
     2
     3        * ChangeLog, libcsupport/src/malloc.c,
     4        libcsupport/src/mallocfreespace.c, sapi/include/confdefs.h,
     5        score/Makefile.am, score/preinstall.am: malloc never blocks so the
     6        Region Manager is quite heavy for implementing this. This patch
     7        implements the C Program Heap directly in terms of the new Protected
     8        Heap handler. This handler is a direct use of a SuperCore Heap in
     9        conjunction with the Allocator Mutex used internally by RTEMS. This
     10        saves 3184 bytes on most SPARC test executables.
     11        * score/include/rtems/score/protectedheap.h, score/src/pheapallocate.c,
     12        score/src/pheapallocatealigned.c, score/src/pheapextend.c,
     13        score/src/pheapfree.c, score/src/pheapgetblocksize.c,
     14        score/src/pheapgetfreeinfo.c, score/src/pheapgetinfo.c,
     15        score/src/pheapinit.c, score/src/pheapresizeblock.c,
     16        score/src/pheapwalk.c: New files.
     17
     182007-05-03      Joel Sherrill <joel@OARcorp.com>
     19
     20        * libcsupport/src/rmdir.c: Fixed spacing.
     21        * libcsupport/Makefile.am, libcsupport/src/newlibc.c: Split _exit from
     22        newlibc.c. It is not required for minimum executing and drops 624
     23        from SPARC minimum executable.
     24        * libcsupport/src/newlibc_exit.c: New file.
     25
    1262007-04-17      Joel Sherrill <joel@OARcorp.com>
    227
  • cpukit/libcsupport/src/malloc.c

    r40ff680 re746a88  
    2020#include <rtems.h>
    2121#include <rtems/libcsupport.h>
    22 #include <rtems/score/apimutex.h>
     22#include <rtems/score/protectedheap.h>
    2323#ifdef RTEMS_NEWLIB
    2424#include <sys/reent.h>
     
    8686#endif
    8787
     88Heap_Control  RTEMS_Malloc_Heap;
    8889Chain_Control RTEMS_Malloc_GC_list;
    8990
    90 rtems_id RTEMS_Malloc_Heap;
     91/* rtems_id RTEMS_Malloc_Heap; */
    9192size_t RTEMS_Malloc_Sbrk_amount;
    9293
     
    120121)
    121122{
    122   rtems_status_code   status;
    123   void               *starting_address;
    124   uintptr_t           old_address;
    125   uintptr_t           uaddress;
     123  uint32_t      status;
     124  void         *starting_address;
     125  uintptr_t     old_address;
     126  uintptr_t     uaddress;
    126127
    127128  /*
     
    181182   */
    182183
    183   status = rtems_region_create(
    184     rtems_build_name( 'H', 'E', 'A', 'P' ),
     184  status = _Protected_heap_Initialize(
     185    &RTEMS_Malloc_Heap,
    185186    starting_address,
    186187    length,
    187     CPU_HEAP_ALIGNMENT,
    188     RTEMS_DEFAULT_ATTRIBUTES,
    189     &RTEMS_Malloc_Heap
     188    CPU_HEAP_ALIGNMENT
    190189  );
    191   if ( status != RTEMS_SUCCESSFUL )
     190  if ( !status )
    192191    rtems_fatal_error_occurred( status );
    193192
     
    205204)
    206205{
    207   void              *return_this;
    208   void              *starting_address;
     206  void        *return_this;
     207  void        *starting_address;
    209208  uint32_t     the_size;
    210209  uint32_t     sbrk_amount;
    211   rtems_status_code  status;
    212   Chain_Node        *to_be_freed;
     210  Chain_Node  *to_be_freed;
    213211
    214212  MSBUMP(malloc_calls, 1);
     
    236234
    237235  /*
    238    * Try to give a segment in the current region if there is not
    239    * enough space then try to grow the region using rtems_region_extend().
     236   * Try to give a segment in the current heap if there is not
     237   * enough space then try to grow the heap.
    240238   * If this fails then return a NULL pointer.
    241239   */
     
    244242  size += sizeof(struct mallocNode) + SENTINELSIZE;
    245243#endif
    246   status = rtems_region_get_segment(
    247     RTEMS_Malloc_Heap,
    248     size,
    249     RTEMS_NO_WAIT,
    250     RTEMS_NO_TIMEOUT,
    251     &return_this
    252   );
    253 
    254   if ( status != RTEMS_SUCCESSFUL ) {
     244  return_this = _Protected_heap_Allocate( &RTEMS_Malloc_Heap, size );
     245
     246  if ( !return_this ) {
    255247    /*
    256248     *  Round to the "requested sbrk amount" so hopefully we won't have
     
    270262      return (void *) 0;
    271263
    272     status = rtems_region_extend(
    273       RTEMS_Malloc_Heap,
    274       starting_address,
    275       the_size
    276     );
    277     if ( status != RTEMS_SUCCESSFUL ) {
     264    if ( !_Protected_heap_Extend(
     265            &RTEMS_Malloc_Heap, starting_address, the_size) ) {
    278266      sbrk(-the_size);
    279267      errno = ENOMEM;
     
    283271    MSBUMP(space_available, the_size);
    284272
    285     status = rtems_region_get_segment(
    286       RTEMS_Malloc_Heap,
    287        size,
    288        RTEMS_NO_WAIT,
    289        RTEMS_NO_TIMEOUT,
    290        &return_this
    291     );
    292     if ( status != RTEMS_SUCCESSFUL ) {
     273    return_this = _Protected_heap_Allocate( &RTEMS_Malloc_Heap, size );
     274    if ( !return_this ) {
    293275      errno = ENOMEM;
    294276      return (void *) 0;
     
    299281  if (return_this)
    300282  {
    301       size_t     actual_size;
     283      size_t     actual_size = 0;
    302284      uint32_t   current_depth;
    303       status = rtems_region_get_segment_size(
    304                    RTEMS_Malloc_Heap, return_this, &actual_size);
     285      Protected_heap_Get_block_size(&RTEMS_Malloc_Heap, ptr, &actual_size);
    305286      MSBUMP(lifetime_allocated, actual_size);
    306287      current_depth = rtems_malloc_stats.lifetime_allocated -
     
    370351{
    371352  size_t old_size;
    372   rtems_status_code status;
    373353  char *new_area;
    374354
     
    400380#ifdef MALLOC_ARENA_CHECK
    401381  {
    402   void *np;
    403   np = malloc(size);
    404   if (!np) return np;
    405   memcpy(np,ptr,size);
    406   free(ptr);
    407   return np;
    408   }
    409 #endif
    410   status =
    411     rtems_region_resize_segment( RTEMS_Malloc_Heap, ptr, size, &old_size );
    412 
    413   if( status == RTEMS_SUCCESSFUL ) {
     382    void *np;
     383    np = malloc(size);
     384    if (!np) return np;
     385    memcpy(np,ptr,size);
     386    free(ptr);
     387    return np;
     388  }
     389#endif
     390  if ( _Protected_heap_Resize_block( &RTEMS_Malloc_Heap, ptr, size ) ) {
    414391    return ptr;
    415   }
    416   else if ( status != RTEMS_UNSATISFIED ) {
    417     errno = EINVAL;
    418     return (void *) 0;
    419392  }
    420393
     
    433406  }
    434407
    435   status = rtems_region_get_segment_size( RTEMS_Malloc_Heap, ptr, &old_size );
    436   if ( status != RTEMS_SUCCESSFUL ) {
     408  if ( !_Protected_heap_Get_block_size(&RTEMS_Malloc_Heap, ptr, &old_size) ) {
    437409    errno = EINVAL;
    438410    return (void *) 0;
     
    450422)
    451423{
    452   rtems_status_code status;
    453 
    454424  MSBUMP(free_calls, 1);
    455425
     
    494464#ifdef MALLOC_STATS
    495465  {
    496       size_t size;
    497       status = rtems_region_get_segment_size( RTEMS_Malloc_Heap, ptr, &size );
    498       if ( status == RTEMS_SUCCESSFUL ) {
    499           MSBUMP(lifetime_freed, size);
    500       }
    501   }
    502 #endif
    503 
    504   status = rtems_region_return_segment( RTEMS_Malloc_Heap, ptr );
    505   if ( status != RTEMS_SUCCESSFUL ) {
     466    size_t size;
     467    if (Protected_heap_Get_block_size(&RTEMS_Malloc_Heap, ptr, &size) ) {
     468      MSBUMP(lifetime_freed, size);
     469    }
     470  }
     471#endif
     472
     473  if ( !_Protected_heap_Free( &RTEMS_Malloc_Heap, ptr ) ) {
    506474    errno = EINVAL;
    507475    assert( 0 );
     
    566534void malloc_walk(size_t source, size_t printf_enabled)
    567535{
    568    register Region_Control *the_region;
    569    Objects_Locations        location;
    570 
    571   _RTEMS_Lock_allocator();                      /* to prevent deletion */
    572    the_region = _Region_Get( RTEMS_Malloc_Heap, &location );
    573    if ( location == OBJECTS_LOCAL )
    574    {
    575       _Heap_Walk( &the_region->Memory, source, printf_enabled );
    576    }
    577   _RTEMS_Unlock_allocator();
     536  _Protected_heap_Walk( &RTEMS_Malloc_Heap, source, printf_enabled );
    578537}
    579538
  • cpukit/libcsupport/src/mallocfreespace.c

    r40ff680 re746a88  
    2020#include <rtems.h>
    2121#include <rtems/libcsupport.h>
     22#include <rtems/score/protectedheap.h>
    2223
    2324#include <stdio.h>
     
    2829#include <string.h>
    2930
    30 extern rtems_id RTEMS_Malloc_Heap;
     31extern Heap_Control RTEMS_Malloc_Heap;
    3132
    3233/*
     
    3637size_t malloc_free_space( void )
    3738{
    38   region_information_block   heap_info;
     39  Heap_Information info;
    3940
    40   if ( !rtems_region_get_free_information( RTEMS_Malloc_Heap, &heap_info ) ) {
    41     return (size_t) heap_info.Free.largest;
    42   }
    43   return (size_t) -1;
     41  _Protected_heap_Get_free_information( &RTEMS_Malloc_Heap, &info );
     42  return (size_t) info.largest;
    4443}
  • cpukit/sapi/include/confdefs.h

    r40ff680 re746a88  
    7171#endif
    7272
    73 #define CONFIGURE_MALLOC_REGION 1
    74 
    7573/*
    7674 *  File descriptors managed by libio
     
    10571055   CONFIGURE_MEMORY_FOR_MESSAGE_QUEUES(CONFIGURE_MAXIMUM_MESSAGE_QUEUES) + \
    10581056   CONFIGURE_MEMORY_FOR_PARTITIONS(CONFIGURE_MAXIMUM_PARTITIONS) + \
    1059    CONFIGURE_MEMORY_FOR_REGIONS( \
    1060       CONFIGURE_MAXIMUM_REGIONS + CONFIGURE_MALLOC_REGION ) + \
     1057   CONFIGURE_MEMORY_FOR_REGIONS( CONFIGURE_MAXIMUM_REGIONS ) + \
    10611058   CONFIGURE_MEMORY_FOR_PORTS(CONFIGURE_MAXIMUM_PORTS) + \
    10621059   CONFIGURE_MEMORY_FOR_PERIODS(CONFIGURE_MAXIMUM_PERIODS) + \
     
    11101107  CONFIGURE_MAXIMUM_MESSAGE_QUEUES,
    11111108  CONFIGURE_MAXIMUM_PARTITIONS,
    1112   CONFIGURE_MAXIMUM_REGIONS + CONFIGURE_MALLOC_REGION,
     1109  CONFIGURE_MAXIMUM_REGIONS,
    11131110  CONFIGURE_MAXIMUM_PORTS,
    11141111  CONFIGURE_MAXIMUM_PERIODS,
  • cpukit/score/Makefile.am

    r40ff680 re746a88  
    2424    include/rtems/score/coremutex.h include/rtems/score/corerwlock.h \
    2525    include/rtems/score/coresem.h include/rtems/score/corespinlock.h \
    26     include/rtems/score/heap.h \
     26    include/rtems/score/heap.h include/rtems/score/protectedheap.h \
    2727    include/rtems/score/interr.h include/rtems/score/isr.h \
    2828    include/rtems/score/object.h include/rtems/score/priority.h \
     
    101101
    102102## HEAP_C_FILES
    103 libscore_a_SOURCES += src/heap.c src/heapallocate.c src/heapextend.c src/heapfree.c \
    104     src/heapsizeofuserarea.c src/heapwalk.c src/heapgetinfo.c \
     103libscore_a_SOURCES += src/heap.c src/heapallocate.c src/heapextend.c \
     104    src/heapfree.c src/heapsizeofuserarea.c src/heapwalk.c src/heapgetinfo.c \
    105105    src/heapgetfreeinfo.c src/heapallocatealigned.c \
    106106    src/heapresizeblock.c
     
    116116    src/objectshrinkinformation.c src/objectgetnoprotection.c \
    117117    src/objectidtoname.c
     118
     119## PROTECTED_HEAP_C_FILES
     120libscore_a_SOURCES += src/pheapallocatealigned.c src/pheapallocate.c \
     121    src/pheapextend.c src/pheapfree.c src/pheapgetblocksize.c \
     122    src/pheapgetfreeinfo.c src/pheapgetinfo.c src/pheapinit.c \
     123    src/pheapresizeblock.c src/pheapwalk.c
    118124
    119125## THREAD_C_FILES
  • cpukit/score/preinstall.am

    r40ff680 re746a88  
    9191        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/heap.h
    9292PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/heap.h
     93
     94$(PROJECT_INCLUDE)/rtems/score/protectedheap.h: include/rtems/score/protectedheap.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
     95        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/protectedheap.h
     96PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/protectedheap.h
    9397
    9498$(PROJECT_INCLUDE)/rtems/score/interr.h: include/rtems/score/interr.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
Note: See TracChangeset for help on using the changeset viewer.