Changeset 11290355 in rtems for cpukit/libcsupport


Ignore:
Timestamp:
Sep 29, 1995, 5:19:16 PM (25 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
1ceface
Parents:
1039ae4
Message:

all targets compile .. tony's patches in place

Location:
cpukit/libcsupport/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/src/error.c

    r1039ae4 r11290355  
    4040 *        if ((fd = open(pathname, O_RDNLY)) < 0)
    4141 *        {
    42  *            rtems_error(FLOSS_ERROR_ERRNO, "open of '%s' failed", pathname);
     42 *            rtems_error(RTEMS_ERROR_ERRNO, "open of '%s' failed", pathname);
    4343 *            goto failed;
    4444 *        }
  • cpukit/libcsupport/src/malloc.c

    r1039ae4 r11290355  
    1515
    1616#include <rtems.h>
    17 #ifdef RTEMS_LIBC
    18 #include <memory.h>
    19 #endif
    2017#include "libcsupport.h"
    2118#ifdef RTEMS_NEWLIB
     
    3027#include <string.h>
    3128
    32 /*
    33  *  XXX: Do we really need to duplicate these? It appears that they
    34  *       only cause typing problems.
    35  */
    36 
    37 #if 0
    38 void *malloc(size_t);
    39 void *calloc(size_t, size_t);
    40 void *realloc(void *, size_t);
    41 void free(void *);
    42 void *sbrk(size_t);
    43 #endif
    44 
    4529rtems_id RTEMS_Malloc_Heap;
    4630size_t RTEMS_Malloc_Sbrk_amount;
     31
     32#ifdef RTEMS_DEBUG
     33#define MALLOC_STATS
     34#endif
     35
     36#ifdef MALLOC_STATS
     37#define MSBUMP(f,n)    malloc_stats.f += (n)
     38
     39struct {
     40    unsigned32  space_available;             /* current size of malloc area */
     41    unsigned32  malloc_calls;                /* # calls to malloc */
     42    unsigned32  free_calls;
     43    unsigned32  realloc_calls;
     44    unsigned32  calloc_calls;
     45    unsigned32  max_depth;                   /* most ever malloc'd at 1 time */
     46    unsigned64  lifetime_allocated;
     47    unsigned64  lifetime_freed;
     48} malloc_stats;
     49
     50#else                   /* No malloc_stats */
     51#define MSBUMP(f,n)
     52#endif
    4753
    4854void RTEMS_Malloc_Initialize(
     
    7884      u32_address = (u32_address + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
    7985
    80       /*
    81        *  Adjust the length by whatever we aligned by
    82        */
     86       /*
     87        * adjust the length by whatever we aligned by
     88        */
    8389
    8490      length -= u32_address - old_address;
     
    98104    starting_address,
    99105    length,
    100     8,                     /* XXX : use CPU dependent RTEMS constant */
     106    CPU_ALIGNMENT,
    101107    RTEMS_DEFAULT_ATTRIBUTES,
    102108    &RTEMS_Malloc_Heap
     
    104110  if ( status != RTEMS_SUCCESSFUL )
    105111    rtems_fatal_error_occurred( status );
     112
     113#ifdef MALLOC_STATS
     114  /* zero all the stats */
     115  (void) memset(&malloc_stats, 0, sizeof(malloc_stats));
     116#endif
     117 
     118  MSBUMP(space_available, length);
    106119}
    107120
     
    115128  rtems_unsigned32   sbrk_amount;
    116129  rtems_status_code  status;
     130
     131  MSBUMP(malloc_calls, 1);
    117132
    118133  if ( !size )
     
    150165      return (void *) 0;
    151166
    152     /*
    153     fprintf(stderr, "Extended the C heap starting at 0x%x for %d bytes\n",
    154         (unsigned32)starting_address, the_size);
    155      */
    156 
    157167    status = rtems_region_extend(
    158168      RTEMS_Malloc_Heap,
     
    162172    if ( status != RTEMS_SUCCESSFUL ) {
    163173      sbrk(-the_size);
    164       return(FALSE);
    165174      errno = ENOMEM;
    166175      return (void *) 0;
    167176    }
     177   
     178    MSBUMP(space_available, the_size);
     179
    168180    status = rtems_region_get_segment(
    169181      RTEMS_Malloc_Heap,
     
    179191  }
    180192
     193#ifdef MALLOC_STATS
     194  if (return_this)
     195  {
     196      unsigned32 current_depth;
     197      MSBUMP(lifetime_allocated, size);
     198      current_depth = malloc_stats.lifetime_allocated - malloc_stats.lifetime_freed;
     199      if (current_depth > malloc_stats.max_depth)
     200          malloc_stats.max_depth = current_depth;
     201  }
     202#endif
     203 
    181204  return return_this;
    182205}
     
    189212  register char *cptr;
    190213  int length;
     214
     215  MSBUMP(calloc_calls, 1);
    191216
    192217  length = nelem * elsize;
     
    207232  char *new_area;
    208233
     234  MSBUMP(realloc_calls, 1);
     235
    209236  if ( !ptr )
    210237    return malloc( size );
    211238
    212239  if ( !size ) {
     240    free( ptr );
     241    return (void *) 0;
     242  }
     243
     244  new_area = malloc( size );
     245  if ( !new_area ) {
    213246    free( ptr );
    214247    return (void *) 0;
     
    221254  }
    222255
    223   new_area = malloc( size );
    224   if ( !new_area ) {
    225     free( ptr );
    226     return (void *) 0;
    227   }
    228 
    229256  memcpy( new_area, ptr, (size < old_size) ? size : old_size );
    230257  free( ptr );
     
    240267  rtems_status_code status;
    241268
     269  MSBUMP(free_calls, 1);
     270
    242271  if ( !ptr )
    243272    return;
    244273
     274#ifdef MALLOC_STATS
     275  {
     276      unsigned32        size;
     277      status = rtems_region_get_segment_size( RTEMS_Malloc_Heap, ptr, &size );
     278      if ( status == RTEMS_SUCCESSFUL ) {
     279          MSBUMP(lifetime_freed, size);
     280      }
     281  }
     282#endif
     283 
    245284  status = rtems_region_return_segment( RTEMS_Malloc_Heap, ptr );
    246285  if ( status != RTEMS_SUCCESSFUL ) {
     
    250289}
    251290
     291#ifdef MALLOC_STATS
     292/*
     293 * Dump the malloc statistics
     294 * May be called via atexit()  (installable by our bsp) or
     295 * at any time by user
     296 */
     297
     298void malloc_dump(void)
     299{
     300    unsigned32 allocated = malloc_stats.lifetime_allocated - malloc_stats.lifetime_freed;
     301
     302    printf("Malloc stats\n");
     303    printf("  avail:%uk  allocated:%uk (%d%%) max:%uk (%d%%) lifetime:%Luk freed:%Luk\n",
     304           (unsigned int) malloc_stats.space_available / 1024,
     305           (unsigned int) allocated / 1024,
     306           /* avoid float! */
     307           (allocated * 100) / malloc_stats.space_available,
     308           (unsigned int) malloc_stats.max_depth / 1024,
     309           (malloc_stats.max_depth * 100) / malloc_stats.space_available,
     310           (unsigned long long) malloc_stats.lifetime_allocated / 1024,
     311           (unsigned long long) malloc_stats.lifetime_freed / 1024);
     312    printf("  Call counts:   malloc:%d   free:%d   realloc:%d   calloc:%d\n",
     313           malloc_stats.malloc_calls,
     314           malloc_stats.free_calls,
     315           malloc_stats.realloc_calls,
     316           malloc_stats.calloc_calls);
     317}       
     318#endif
     319
    252320/*
    253321 *  "Reentrant" versions of the above routines implemented above.
Note: See TracChangeset for help on using the changeset viewer.