Changeset 7c19e50 in rtems


Ignore:
Timestamp:
Dec 18, 2018, 7:45:06 AM (4 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
cde5e8d
Parents:
e7b0a72
git-author:
Sebastian Huber <sebastian.huber@…> (12/18/18 07:45:06)
git-committer:
Sebastian Huber <sebastian.huber@…> (12/18/18 07:50:08)
Message:

score: Fix per-CPU data allocation

Allocate the per-CPU data for secondary processors directly from the
heap areas before heap initialization and not via
_Workspace_Allocate_aligned(). This avoids dependency on the workspace
allocator. It fixes also a problem on some platforms (e.g. QorIQ) where
at this early point in the system initialization the top of the RAM is
used by low-level startup code on secondary processors (boot pages).

Update #3507.

Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/score/interr.h

    re7b0a72 r7c19e50  
    194194  INTERNAL_ERROR_LIBIO_STDERR_FD_OPEN_FAILED = 37,
    195195  INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT = 38,
    196   INTERNAL_ERROR_ARC4RANDOM_GETENTROPY_FAIL = 39
     196  INTERNAL_ERROR_ARC4RANDOM_GETENTROPY_FAIL = 39,
     197  INTERNAL_ERROR_NO_MEMORY_FOR_PER_CPU_DATA = 40
    197198} Internal_errors_Core_list;
    198199
  • cpukit/sapi/src/interrtext.c

    re7b0a72 r7c19e50  
    88
    99/*
    10  * Copyright (c) 2012, 2017 embedded brains GmbH.  All rights reserved.
     10 * Copyright (c) 2012, 2018 embedded brains GmbH.  All rights reserved.
    1111 *
    1212 *  embedded brains GmbH
     
    6767  "INTERNAL_ERROR_LIBIO_STDERR_FD_OPEN_FAILED",
    6868  "INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT",
    69   "INTERNAL_ERROR_ARC4RANDOM_GETENTROPY_FAIL"
     69  "INTERNAL_ERROR_ARC4RANDOM_GETENTROPY_FAIL",
     70  "INTERNAL_ERROR_NO_MEMORY_FOR_PER_CPU_DATA"
    7071};
    7172
  • cpukit/score/src/wkspace.c

    re7b0a72 r7c19e50  
    7878}
    7979
    80 static uintptr_t _Workspace_Space_for_per_CPU_data( uintptr_t page_size )
    81 {
    82   uintptr_t space;
    83 
    8480#ifdef RTEMS_SMP
    85   uintptr_t size;
    86 
    87   size = RTEMS_LINKER_SET_SIZE( _Per_CPU_Data );
    88   _Assert( size % CPU_CACHE_LINE_BYTES == 0 );
    89 
    90   if ( size > 0 ) {
    91     /*
    92      * Memory allocated with an alignment constraint is allocated from the end of
    93      * a free block.  The last allocation may need one free block of minimum
    94      * size.
    95      */
    96     space = _Heap_Min_block_size( page_size );
    97 
    98     space += ( rtems_configuration_get_maximum_processors() - 1 )
    99       * _Heap_Size_with_overhead( page_size, size, CPU_CACHE_LINE_BYTES );
    100   } else {
    101     space = 0;
    102   }
    103 #else
    104   space = 0;
    105 #endif
    106 
    107   return space;
    108 }
    109 
    110 static void _Workspace_Allocate_per_CPU_data( void )
     81static void *_Workspace_Allocate_from_areas(
     82  Heap_Area *areas,
     83  size_t     area_count,
     84  uintptr_t  size,
     85  uintptr_t  alignment
     86)
     87{
     88  size_t i;
     89
     90  for ( i = 0; i < area_count; ++i ) {
     91    Heap_Area *area;
     92    uintptr_t  alloc_begin;
     93    uintptr_t  alloc_size;
     94
     95    area = &areas[ i ];
     96    alloc_begin = (uintptr_t) area->begin;
     97    alloc_begin = ( alloc_begin + alignment - 1 ) & ~( alignment - 1 );
     98    alloc_size = size;
     99    alloc_size += alloc_begin - (uintptr_t) area->begin;
     100
     101    if ( area->size >= alloc_size ) {
     102      area->begin = (void *) ( alloc_begin + size );
     103      area->size -= alloc_size;
     104
     105      return (void *) alloc_begin;
     106    }
     107  }
     108
     109  return NULL;
     110}
     111#endif
     112
     113static void _Workspace_Allocate_per_CPU_data(
     114  Heap_Area *areas,
     115  size_t area_count
     116)
    111117{
    112118#ifdef RTEMS_SMP
     
    127133    for ( cpu_index = 1 ; cpu_index < cpu_max ; ++cpu_index ) {
    128134      cpu = _Per_CPU_Get_by_index( cpu_index );
    129       cpu->data = _Workspace_Allocate_aligned( size, CPU_CACHE_LINE_BYTES );
    130       _Assert( cpu->data != NULL );
     135      cpu->data = _Workspace_Allocate_from_areas(
     136        areas,
     137        area_count,
     138        size,
     139        CPU_CACHE_LINE_BYTES
     140      );
     141
     142      if( cpu->data == NULL ) {
     143        _Internal_error( INTERNAL_ERROR_NO_MEMORY_FOR_PER_CPU_DATA );
     144      }
     145
    131146      memcpy( cpu->data, RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ), size);
    132147    }
    133148  }
     149#else
     150  (void) areas;
     151  (void) area_count;
    134152#endif
    135153}
     
    149167  size_t                                i;
    150168
     169  _Workspace_Allocate_per_CPU_data( areas, area_count );
     170
    151171  page_size = CPU_HEAP_ALIGNMENT;
    152172
    153173  remaining = rtems_configuration_get_work_space_size();
    154174  remaining += _Workspace_Space_for_TLS( page_size );
    155   remaining += _Workspace_Space_for_per_CPU_data( page_size );
    156175
    157176  init_or_extend = _Heap_Initialize;
     
    209228
    210229  _Heap_Protection_set_delayed_free_fraction( &_Workspace_Area, 1 );
    211   _Workspace_Allocate_per_CPU_data();
    212230}
    213231
  • testsuites/smptests/Makefile.am

    re7b0a72 r7c19e50  
    239239
    240240if HAS_SMP
     241if TEST_smpfatal09
     242smp_tests += smpfatal09
     243smp_screens += smpfatal09/smpfatal09.scn
     244smp_docs += smpfatal09/smpfatal09.doc
     245smpfatal09_SOURCES = smpfatal09/init.c
     246smpfatal09_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_smpfatal09) \
     247        $(support_includes)
     248endif
     249endif
     250
     251if HAS_SMP
    241252if TEST_smpipi01
    242253smp_tests += smpipi01
  • testsuites/smptests/configure.ac

    re7b0a72 r7c19e50  
    5454RTEMS_TEST_CHECK([smpfatal06])
    5555RTEMS_TEST_CHECK([smpfatal08])
     56RTEMS_TEST_CHECK([smpfatal09])
    5657RTEMS_TEST_CHECK([smpipi01])
    5758RTEMS_TEST_CHECK([smpload01])
  • testsuites/sptests/spinternalerror02/init.c

    re7b0a72 r7c19e50  
    3737
    3838  rtems_test_assert(
    39     error - 3 == INTERNAL_ERROR_ARC4RANDOM_GETENTROPY_FAIL
     39    error - 3 == INTERNAL_ERROR_NO_MEMORY_FOR_PER_CPU_DATA
    4040  );
    4141}
  • testsuites/sptests/spinternalerror02/spinternalerror02.scn

    re7b0a72 r7c19e50  
    11*** BEGIN OF TEST SPINTERNALERROR 2 ***
     2*** TEST VERSION: 5.0.0.cfa82b34b0c53ab4e3d84dd8ab5225793d48fcd0
     3*** TEST STATE: EXPECTED-PASS
     4*** TEST BUILD:
     5*** TEST TOOLS: 7.4.0 20181206 (RTEMS 5, RSB ddba5372522da341fa20b2c75dfe966231cb6790, Newlib df6915f029ac9acd2b479ea898388cbd7dda4974)
    26INTERNAL_ERROR_NO_CONFIGURATION_TABLE
    37INTERNAL_ERROR_NO_CPU_TABLE
     
    3236INTERNAL_ERROR_BAD_THREAD_DISPATCH_DISABLE_LEVEL
    3337INTERNAL_ERROR_BAD_THREAD_DISPATCH_ENVIRONMENT
     38INTERNAL_ERROR_RTEMS_INIT_TASK_CREATE_FAILED
     39INTERNAL_ERROR_POSIX_INIT_THREAD_CREATE_FAILED
     40INTERNAL_ERROR_LIBIO_USER_ENV_KEY_CREATE_FAILED
     41INTERNAL_ERROR_LIBIO_SEM_CREATE_FAILED
     42INTERNAL_ERROR_LIBIO_STDOUT_FD_OPEN_FAILED
     43INTERNAL_ERROR_LIBIO_STDERR_FD_OPEN_FAILED
     44INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
     45INTERNAL_ERROR_ARC4RANDOM_GETENTROPY_FAIL
     46INTERNAL_ERROR_NO_MEMORY_FOR_PER_CPU_DATA
    3447?
    3548?
     
    8093?
    8194?
     95
    8296*** END OF TEST SPINTERNALERROR 2 ***
Note: See TracChangeset for help on using the changeset viewer.