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

SMP: Simplify SMP multicast actions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.