Changeset cfc4231d in rtems


Ignore:
Timestamp:
Aug 27, 2018, 8:36:35 AM (9 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
d8bc0730
Parents:
77d374f5
git-author:
Sebastian Huber <sebastian.huber@…> (08/27/18 08:36:35)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/10/18 08:38:45)
Message:

score: Add flexible per-CPU data

Update #3507.

Files:
6 added
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/headers.am

    r77d374f5 rcfc4231d  
    376376include_rtems_score_HEADERS += include/rtems/score/onceimpl.h
    377377include_rtems_score_HEADERS += include/rtems/score/percpu.h
     378include_rtems_score_HEADERS += include/rtems/score/percpudata.h
    378379include_rtems_score_HEADERS += include/rtems/score/priority.h
    379380include_rtems_score_HEADERS += include/rtems/score/prioritybitmap.h
  • cpukit/include/rtems/score/percpu.h

    r77d374f5 rcfc4231d  
    1010 *  On-Line Applications Research Corporation (OAR).
    1111 *
    12  *  Copyright (c) 2012, 2016 embedded brains GmbH
     12 *  Copyright (c) 2012, 2018 embedded brains GmbH
    1313 *
    1414 *  The license and distribution terms for this file may be
     
    478478
    479479    /**
     480     * @brief Begin of the per-CPU data area.
     481     *
     482     * Contains items defined via PER_CPU_DATA_ITEM().
     483     */
     484    char *data;
     485
     486    /**
    480487     * @brief Indicates the current state of the CPU.
    481488     *
  • cpukit/score/src/wkspace.c

    r77d374f5 rcfc4231d  
    2020
    2121#include <rtems/score/wkspace.h>
     22#include <rtems/score/assert.h>
    2223#include <rtems/score/heapimpl.h>
    2324#include <rtems/score/interr.h>
     25#include <rtems/score/percpudata.h>
    2426#include <rtems/score/threadimpl.h>
    2527#include <rtems/score/tls.h>
    2628#include <rtems/config.h>
    2729
    28 #include <string.h>  /* for memset */
     30#include <string.h>
    2931
    3032/* #define DEBUG_WORKSPACE */
     
    3335#endif
    3436
     37RTEMS_LINKER_RWSET(
     38  _Per_CPU_Data,
     39  RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES ) char
     40);
     41
    3542Heap_Control _Workspace_Area;
    3643
    37 static uint32_t _Get_maximum_thread_count(void)
    38 {
    39   uint32_t thread_count = 0;
    40 
     44static uint32_t _Workspace_Get_maximum_thread_count( void )
     45{
     46  uint32_t thread_count;
     47
     48  thread_count = 0;
    4149  thread_count += _Thread_Get_maximum_internal_threads();
    4250
     
    5462}
    5563
    56 void _Workspace_Handler_initialization(
    57   Heap_Area *areas,
    58   size_t area_count,
    59   Heap_Initialization_or_extend_handler extend
    60 )
    61 {
    62   Heap_Initialization_or_extend_handler init_or_extend = _Heap_Initialize;
    63   uintptr_t remaining = rtems_configuration_get_work_space_size();
    64   bool do_zero = rtems_configuration_get_do_zero_of_workspace();
    65   bool unified = rtems_configuration_get_unified_work_area();
    66   uintptr_t page_size = CPU_HEAP_ALIGNMENT;
    67   uintptr_t overhead = _Heap_Area_overhead( page_size );
    68   uintptr_t tls_size = _TLS_Get_size();
    69   size_t i;
     64static uintptr_t _Workspace_Space_for_TLS( uintptr_t page_size )
     65{
     66  uintptr_t tls_size;
     67  uintptr_t space;
     68
     69  tls_size = _TLS_Get_size();
    7070
    7171  /*
     
    8686     * size.
    8787     */
    88     remaining += _Heap_Min_block_size( page_size );
    89 
    90     remaining += _Get_maximum_thread_count()
     88    space = _Heap_Min_block_size( page_size );
     89
     90    space += _Workspace_Get_maximum_thread_count()
    9191      * _Heap_Size_with_overhead( page_size, tls_alloc, tls_align );
    92   }
    93 
    94   for (i = 0; i < area_count; ++i) {
    95     Heap_Area *area = &areas [i];
     92  } else {
     93    space = 0;
     94  }
     95
     96  return space;
     97}
     98
     99static uintptr_t _Workspace_Space_for_per_CPU_data( uintptr_t page_size )
     100{
     101  uintptr_t space;
     102
     103#ifdef RTEMS_SMP
     104  uintptr_t size;
     105
     106  size = RTEMS_LINKER_SET_SIZE( _Per_CPU_Data );
     107  _Assert( size % CPU_CACHE_LINE_BYTES == 0 );
     108
     109  if ( size > 0 ) {
     110    /*
     111     * Memory allocated with an alignment constraint is allocated from the end of
     112     * a free block.  The last allocation may need one free block of minimum
     113     * size.
     114     */
     115    space = _Heap_Min_block_size( page_size );
     116
     117    space += ( rtems_configuration_get_maximum_processors() - 1 )
     118      * _Heap_Size_with_overhead( page_size, size, CPU_CACHE_LINE_BYTES );
     119  } else {
     120    space = 0;
     121  }
     122#else
     123  space = 0;
     124#endif
     125
     126  return space;
     127}
     128
     129static void _Workspace_Allocate_per_CPU_data( void )
     130{
     131#ifdef RTEMS_SMP
     132  Per_CPU_Control *cpu;
     133  uintptr_t        size;
     134  uint32_t         cpu_index;
     135  uint32_t         cpu_max;
     136
     137  cpu = _Per_CPU_Get_by_index( 0 );
     138  cpu->data = RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data );
     139
     140  size = RTEMS_LINKER_SET_SIZE( _Per_CPU_Data );
     141  cpu_max = rtems_configuration_get_maximum_processors();
     142
     143  for ( cpu_index = 1 ; cpu_index < cpu_max ; ++cpu_index ) {
     144    cpu = _Per_CPU_Get_by_index( cpu_index );
     145    cpu->data = _Workspace_Allocate_aligned( size, CPU_CACHE_LINE_BYTES );
     146    _Assert( cpu->data != NULL );
     147    memcpy( cpu->data, RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ), size);
     148  }
     149#endif
     150}
     151
     152void _Workspace_Handler_initialization(
     153  Heap_Area *areas,
     154  size_t area_count,
     155  Heap_Initialization_or_extend_handler extend
     156)
     157{
     158  Heap_Initialization_or_extend_handler init_or_extend;
     159  uintptr_t                             remaining;
     160  bool                                  do_zero;
     161  bool                                  unified;
     162  uintptr_t                             page_size;
     163  uintptr_t                             overhead;
     164  size_t                                i;
     165
     166  page_size = CPU_HEAP_ALIGNMENT;
     167
     168  remaining = rtems_configuration_get_work_space_size();
     169  remaining += _Workspace_Space_for_TLS( page_size );
     170  remaining += _Workspace_Space_for_per_CPU_data( page_size );
     171
     172  init_or_extend = _Heap_Initialize;
     173  do_zero = rtems_configuration_get_do_zero_of_workspace();
     174  unified = rtems_configuration_get_unified_work_area();
     175  overhead = _Heap_Area_overhead( page_size );
     176
     177  for ( i = 0; i < area_count; ++i ) {
     178    Heap_Area *area;
     179
     180    area = &areas[ i ];
    96181
    97182    if ( do_zero ) {
     
    114199      }
    115200
    116       space_available = (*init_or_extend)(
     201      space_available = ( *init_or_extend )(
    117202        &_Workspace_Area,
    118203        area->begin,
     
    139224
    140225  _Heap_Protection_set_delayed_free_fraction( &_Workspace_Area, 1 );
     226  _Workspace_Allocate_per_CPU_data();
    141227}
    142228
  • testsuites/sptests/Makefile.am

    r77d374f5 rcfc4231d  
    15951595endif
    15961596
     1597if TEST_sppercpudata01
     1598sp_tests += sppercpudata01
     1599sp_screens += sppercpudata01/sppercpudata01.scn
     1600sp_docs += sppercpudata01/sppercpudata01.doc
     1601sppercpudata01_SOURCES = sppercpudata01/init.c sppercpudata01/item.c
     1602sppercpudata01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_sppercpudata01) \
     1603        $(support_includes)
     1604endif
     1605
    15971606if TEST_spport_err01
    15981607sp_tests += spport_err01
  • testsuites/sptests/configure.ac

    r77d374f5 rcfc4231d  
    206206RTEMS_TEST_CHECK([sppagesize])
    207207RTEMS_TEST_CHECK([sppartition_err01])
     208RTEMS_TEST_CHECK([sppercpudata01])
    208209RTEMS_TEST_CHECK([spport_err01])
    209210RTEMS_TEST_CHECK([spprintk])
Note: See TracChangeset for help on using the changeset viewer.