Changeset 46f05b9 in rtems


Ignore:
Timestamp:
Apr 5, 2017, 9:28:46 AM (2 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
9b91c84
Parents:
75e71b2
Message:

SMP: Simplify SMP multicast actions

Location:
cpukit/score
Files:
4 edited

Legend:

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

    r75e71b2 r46f05b9  
    6363typedef uint32_t Processor_mask[ PROCESSOR_MASK_FIELD_COUNT ];
    6464
     65RTEMS_INLINE_ROUTINE void _Processor_mask_Zero( Processor_mask mask )
     66{
     67  size_t i;
     68
     69  for ( i = 0; i < PROCESSOR_MASK_FIELD_COUNT; ++i ) {
     70    mask[ i ] = 0;
     71  }
     72}
     73
     74RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_zero( const Processor_mask mask )
     75{
     76  size_t i;
     77
     78  for ( i = 0; i < PROCESSOR_MASK_FIELD_COUNT; ++i ) {
     79    if ( mask[ i ] != 0 ) {
     80      return false;
     81    }
     82  }
     83
     84  return true;
     85}
     86
     87RTEMS_INLINE_ROUTINE void _Processor_mask_Assign( Processor_mask dst, const Processor_mask src )
     88{
     89  size_t i;
     90
     91  for ( i = 0; i < PROCESSOR_MASK_FIELD_COUNT; ++i ) {
     92    dst[ i ] = src[ i ];
     93  }
     94}
     95
    6596RTEMS_INLINE_ROUTINE void _Processor_mask_Set( Processor_mask mask, uint32_t index )
    6697{
  • cpukit/score/include/rtems/score/smpimpl.h

    r75e71b2 r46f05b9  
    238238 *  The sending processor may be part of the set.
    239239 *
    240  *  @param[in] setsize The size of the set of target processors of the message.
    241  *  @param[in] cpus The set of target processors of the message.
     240 *  @param[in] targets The set of processors to send the message.
    242241 *  @param[in] message The message.
    243242 */
    244243void _SMP_Send_message_multicast(
    245   const size_t setsize,
    246   const cpu_set_t *cpus,
    247   unsigned long message
     244  const Processor_mask targets,
     245  unsigned long        message
    248246);
    249247
  • cpukit/score/src/smp.c

    r75e71b2 r46f05b9  
    226226
    227227void _SMP_Send_message_multicast(
    228     const size_t setsize,
    229     const cpu_set_t *cpus,
    230     unsigned long message
     228  const Processor_mask targets,
     229  unsigned long        message
    231230)
    232231{
     
    235234
    236235  for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) {
    237     if ( CPU_ISSET_S( cpu_index, setsize, cpus ) ) {
     236    if ( _Processor_mask_Is_set( targets, cpu_index ) ) {
    238237      _SMP_Send_message( cpu_index, message );
    239238    }
  • cpukit/score/src/smpmulticastaction.c

    r75e71b2 r46f05b9  
    1717
    1818typedef struct {
    19   Chain_Node Node;
    20   SMP_Action_handler handler;
    21   void *arg;
    22   cpu_set_t *recipients;
    23   size_t setsize;
    24   Atomic_Ulong done;
     19  Chain_Node          Node;
     20  SMP_Action_handler  handler;
     21  void               *arg;
     22  Processor_mask      targets;
     23  Atomic_Ulong        done;
    2524} SMP_Multicast_action;
    2625
    2726typedef struct {
    2827  SMP_lock_Control Lock;
    29   Chain_Control List;
    30 } SMP_Multicast_action_context;
     28  Chain_Control    Actions;
     29} SMP_Multicast_context;
    3130
    32 static SMP_Multicast_action_context _SMP_Multicast_action_context = {
    33   .Lock = SMP_LOCK_INITIALIZER("SMP Multicast Action"),
    34   .List = CHAIN_INITIALIZER_EMPTY(_SMP_Multicast_action_context.List)
     31static SMP_Multicast_context _SMP_Multicast = {
     32  .Lock = SMP_LOCK_INITIALIZER( "SMP Multicast Action" ),
     33  .Actions = CHAIN_INITIALIZER_EMPTY( _SMP_Multicast.Actions )
    3534};
    3635
    37 void
    38 _SMP_Multicast_actions_process(void)
     36void _SMP_Multicast_actions_process( void )
    3937{
    40   SMP_lock_Context lock_context;
     38  SMP_lock_Context      lock_context;
     39  uint32_t              cpu_self_index;
    4140  SMP_Multicast_action *node;
    4241  SMP_Multicast_action *next;
    43   uint32_t cpu_self_idx;
    4442
    45   _SMP_lock_ISR_disable_and_acquire( &_SMP_Multicast_action_context.Lock,
    46       &lock_context );
    47   cpu_self_idx = _SMP_Get_current_processor();
     43  _SMP_lock_ISR_disable_and_acquire( &_SMP_Multicast.Lock, &lock_context );
     44  cpu_self_index = _SMP_Get_current_processor();
     45  node = (SMP_Multicast_action *) _Chain_First( &_SMP_Multicast.Actions );
    4846
    49   node = (SMP_Multicast_action*)_Chain_First(
    50       &_SMP_Multicast_action_context.List );
    51   while ( !_Chain_Is_tail( &_SMP_Multicast_action_context.List, &node->Node ) ) {
    52     next = (SMP_Multicast_action*)_Chain_Next( &node->Node );
    53     if ( CPU_ISSET_S ( cpu_self_idx, node->setsize, node->recipients ) ) {
    54       CPU_CLR_S ( cpu_self_idx, node->setsize, node->recipients );
     47  while ( !_Chain_Is_tail( &_SMP_Multicast.Actions, &node->Node ) ) {
     48    next = (SMP_Multicast_action *) _Chain_Next( &node->Node );
    5549
    56       node->handler( node->arg );
     50    if ( _Processor_mask_Is_set( node->targets, cpu_self_index ) ) {
     51      _Processor_mask_Clear( node->targets, cpu_self_index );
    5752
    58       if ( CPU_COUNT_S( node->setsize, node->recipients ) == 0 ) {
     53      ( *node->handler )( node->arg );
     54
     55      if ( _Processor_mask_Is_zero( node->targets ) ) {
    5956        _Chain_Extract_unprotected( &node->Node );
    6057        _Atomic_Store_ulong( &node->done, 1, ATOMIC_ORDER_RELEASE );
    6158      }
    6259    }
     60
    6361    node = next;
    6462  }
    6563
    66   _SMP_lock_Release_and_ISR_enable( &_SMP_Multicast_action_context.Lock,
    67       &lock_context );
     64  _SMP_lock_Release_and_ISR_enable( &_SMP_Multicast.Lock, &lock_context );
    6865}
    6966
    7067static void
    71 _SMP_Multicast_actions_try_process( void )
     68_SMP_Multicasts_try_process( void )
    7269{
    7370  unsigned long message;
     
    9996)
    10097{
    101   uint32_t i;
    10298  SMP_Multicast_action node;
    103   size_t set_size = CPU_ALLOC_SIZE( _SMP_Get_processor_count() );
    104   char cpu_set_copy[set_size];
    105   SMP_lock_Context lock_context;
     99  Processor_mask       targets;
     100  SMP_lock_Context     lock_context;
     101  uint32_t             i;
    106102
    107103  if ( ! _System_state_Is_up( _System_state_Get() ) ) {
    108     handler( arg );
     104    ( *handler )( arg );
    109105    return;
    110106  }
    111107
    112   memset( cpu_set_copy, 0, set_size );
    113108  if( cpus == NULL ) {
    114     for( i=0; i<_SMP_Get_processor_count(); ++i )
    115       CPU_SET_S( i, set_size, (cpu_set_t *)cpu_set_copy );
     109    _Processor_mask_Assign( targets, _SMP_Online_processors );
    116110  } else {
    117     for( i=0; i<_SMP_Get_processor_count(); ++i )
    118       if( CPU_ISSET_S( i, set_size, cpus ) )
    119         CPU_SET_S( i, set_size, (cpu_set_t *)cpu_set_copy );
     111    _Processor_mask_Zero( targets );
     112
     113    for ( i = 0; i < _SMP_Get_processor_count(); ++i ) {
     114      if ( CPU_ISSET_S( i, setsize, cpus ) ) {
     115        _Processor_mask_Set( targets, i );
     116      }
     117    }
    120118  }
    121119
     120  _Chain_Initialize_node( &node.Node );
    122121  node.handler = handler;
    123122  node.arg = arg;
    124   node.setsize = set_size;
    125   node.recipients = (cpu_set_t *)cpu_set_copy;
     123  _Processor_mask_Assign( node.targets, targets );
    126124  _Atomic_Store_ulong( &node.done, 0, ATOMIC_ORDER_RELAXED );
    127125
     126  _SMP_lock_ISR_disable_and_acquire( &_SMP_Multicast.Lock, &lock_context );
     127  _Chain_Prepend_unprotected( &_SMP_Multicast.Actions, &node.Node );
     128  _SMP_lock_Release_and_ISR_enable( &_SMP_Multicast.Lock, &lock_context );
    128129
    129   _SMP_lock_ISR_disable_and_acquire( &_SMP_Multicast_action_context.Lock,
    130       &lock_context );
    131   _Chain_Initialize_node( &node.Node );
    132   _Chain_Prepend_unprotected( &_SMP_Multicast_action_context.List, &node.Node );
    133   _SMP_lock_Release_and_ISR_enable( &_SMP_Multicast_action_context.Lock,
    134       &lock_context );
     130  _SMP_Send_message_multicast( targets, SMP_MESSAGE_MULTICAST_ACTION );
     131  _SMP_Multicasts_try_process();
    135132
    136   _SMP_Send_message_multicast( set_size, node.recipients,
    137       SMP_MESSAGE_MULTICAST_ACTION );
    138 
    139   _SMP_Multicast_actions_try_process();
    140 
    141   while ( !_Atomic_Load_ulong( &node.done, ATOMIC_ORDER_ACQUIRE ) );
     133  while ( _Atomic_Load_ulong( &node.done, ATOMIC_ORDER_ACQUIRE ) == 0 ) {
     134    /* Wait */
     135  };
    142136}
Note: See TracChangeset for help on using the changeset viewer.