Changeset 493e405 in rtems


Ignore:
Timestamp:
Sep 12, 2007, 8:11:33 PM (12 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
98e398cb
Parents:
8393f3a
Message:

2007-09-12 Sergei Organov <osv@…>

PR 1258/rtems

  • cpukit/score/src/heapallocatealigned.c (block_allocate): New routine.
  • cpukit/score/src/heapallocatealigned.c (_Heap_Allocate_aligned): Use block_allocate() instead of _Heap_Block_allocate(). Replace _Heap_Head(the_heap)->next with equivalent _Heap_First(the_heap).
  • cpukit/score/src/heap.c (_Heap_Allocate): fix comments according to changed block split strategy in _Heap_Allocate_aligned().
Location:
cpukit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r8393f3a r493e405  
     12007-09-12  Sergei Organov  <osv@javad.com>
     2
     3        PR 1258/rtems
     4        * cpukit/score/src/heapallocatealigned.c (block_allocate): New routine.
     5        * cpukit/score/src/heapallocatealigned.c (_Heap_Allocate_aligned):
     6        Use block_allocate() instead of _Heap_Block_allocate(). Replace
     7        _Heap_Head(the_heap)->next with equivalent _Heap_First(the_heap).
     8        * cpukit/score/src/heap.c (_Heap_Allocate): fix comments according
     9        to changed block split strategy in _Heap_Allocate_aligned().
     10
    1112007-09-10      Joel Sherrill <joel.sherrill@OARcorp.com>
    212
  • cpukit/score/src/heap.c

    r8393f3a r493e405  
    6666 *            +--------------------------------+ <- end = begin + size
    6767 *
    68  *  This is what a heap looks like after first allocation of SIZE bytes.
    69  *  BSIZE stands for SIZE + 4 aligned up on 'page_size' boundary if allocation
    70  *  has been performed by _Heap_Allocate(). If allocation has been performed
    71  *  by _Heap_Allocate_aligned(), the block size BSIZE is defined differently
    72  *  (see 'heapallocatealigned.c' for details).
     68 *  Below is what a heap looks like after first allocation of SIZE bytes using
     69 *  _Heap_allocate(). BSIZE stands for SIZE + 4 aligned up on 'page_size'
     70 *  boundary.
     71 *  [NOTE: If allocation were performed by _Heap_Allocate_aligned(), the
     72 *  block size BSIZE is defined differently, and previously free block will
     73 *  be split so that upper part of it will become used block (see
     74 *  'heapallocatealigned.c' for details).]
    7375 *
    7476 *            +--------------------------------+ <- begin = starting_address
  • cpukit/score/src/heapallocatealigned.c

    r8393f3a r493e405  
    5757#endif /* !defined(RTEMS_HEAP_DEBUG) */
    5858
     59/*
     60 * Allocate block of size 'alloc_size' from 'the_block' belonging to
     61 * 'the_heap'. Split 'the_block' if possible, otherwise allocate it entirely.
     62 * When split, make the upper part used, and leave the lower part free.
     63 * Return the block allocated.
     64 *
     65 * NOTE: this is similar to _Heap_Block_allocate(), except it makes different
     66 * part of the split block used, and returns address of the block instead of its
     67 * size. We do need such variant for _Heap_Allocate_aligned() as we can't allow
     68 * user pointer to be too far from the beginning of the block, so that we can
     69 * recover start-of-block address from the user pointer without additional
     70 * information stored in the heap.
     71 */
     72static
     73Heap_Block *block_allocate(
     74  Heap_Control  *the_heap,
     75  Heap_Block    *the_block,
     76  uint32_t      alloc_size)
     77{
     78  Heap_Statistics *const stats = &the_heap->stats;
     79  uint32_t const block_size = _Heap_Block_size(the_block);
     80  uint32_t const the_rest = block_size - alloc_size;
     81
     82  _HAssert(_Heap_Is_aligned(block_size, the_heap->page_size));
     83  _HAssert(_Heap_Is_aligned(alloc_size, the_heap->page_size));
     84  _HAssert(alloc_size <= block_size);
     85  _HAssert(_Heap_Is_prev_used(the_block));
     86
     87  if(the_rest >= the_heap->min_block_size) {
     88    /* Split the block so that lower part is still free, and upper part
     89       becomes used. */
     90    the_block->size = the_rest | HEAP_PREV_USED;
     91    the_block = _Heap_Block_at(the_block, the_rest);
     92    the_block->prev_size = the_rest;
     93    the_block->size = alloc_size;
     94  }
     95  else {
     96    /* Don't split the block as remainder is either zero or too small to be
     97       used as a separate free block. Change 'alloc_size' to the size of the
     98       block and remove the block from the list of free blocks. */
     99    _Heap_Block_remove(the_block);
     100    alloc_size = block_size;
     101    stats->free_blocks -= 1;
     102  }
     103  /* Mark the block as used (in the next block). */
     104  _Heap_Block_at(the_block, alloc_size)->size |= HEAP_PREV_USED;
     105  /* Update statistics */
     106  stats->free_size -= alloc_size;
     107  if(stats->min_free_size > stats->free_size)
     108    stats->min_free_size = stats->free_size;
     109  stats->used_blocks += 1;
     110  return the_block;
     111}
     112
     113
    59114/*PAGE
    60115 *
     
    102157  /* Find large enough free block that satisfies the alignment requirements. */
    103158
    104   for(the_block = _Heap_Head(the_heap)->next, search_count = 0;
     159  for(the_block = _Heap_First(the_heap), search_count = 0;
    105160      the_block != tail;
    106161      the_block = the_block->next, ++search_count)
     
    132187      _Heap_Align_down_uptr(&user_addr, page_size);
    133188
    134       /* Make sure 'user_addr' calculated didn't run out of 'the_block. */
     189      /* Make sure 'user_addr' calculated didn't run out of 'the_block'. */
    135190      if(user_addr >= user_area) {
    136191
     
    173228          _HAssert(_Heap_Is_aligned_ptr((void*)aligned_user_addr, alignment));
    174229
    175           (void)_Heap_Block_allocate(the_heap, the_block, alloc_size);
     230          the_block = block_allocate(the_heap, the_block, alloc_size);
    176231
    177232          stats->searches += search_count + 1;
Note: See TracChangeset for help on using the changeset viewer.