Changeset c0bff5e in rtems


Ignore:
Timestamp:
05/15/14 08:31:22 (10 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
b532bb2c
Parents:
b4bdbcf
git-author:
Sebastian Huber <sebastian.huber@…> (05/15/14 08:31:22)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/15/14 10:18:49)
Message:

score: Split SMP scheduler enqueue function

Extract code from _Scheduler_SMP_Enqueue_ordered() and move it to the
new function _Scheduler_SMP_Enqueue_scheduled_ordered() to avoid
untestable execution paths.

Add and use function _Scheduler_SMP_Unblock().

Files:
4 added
5 edited

Legend:

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

    rb4bdbcf rc0bff5e  
    4242 *
    4343 * State transitions are triggered via basic operations
    44  * - _Scheduler_SMP_Enqueue_ordered(), and
     44 * - _Scheduler_SMP_Enqueue_ordered(),
     45 * - _Scheduler_SMP_Enqueue_scheduled_ordered(), and
    4546 * - _Scheduler_SMP_Block().
    4647 *
     
    296297typedef void ( *Scheduler_SMP_Enqueue )(
    297298  Scheduler_Context *context,
    298   Thread_Control *thread_to_enqueue,
    299   bool has_processor_allocated
     299  Thread_Control *thread_to_enqueue
    300300);
    301301
     
    433433 * @brief Enqueues a thread according to the specified order function.
    434434 *
     435 * The thread must not be in the scheduled state.
     436 *
    435437 * @param[in] context The scheduler instance context.
    436438 * @param[in] thread The thread to enqueue.
    437  * @param[in] has_processor_allocated The thread has a processor allocated.
     439 * @param[in] order The order function.
     440 * @param[in] insert_ready Function to insert a node into the set of ready
     441 * nodes.
     442 * @param[in] insert_scheduled Function to insert a node into the set of
     443 * scheduled nodes.
     444 * @param[in] move_from_scheduled_to_ready Function to move a node from the set
     445 * of scheduled nodes to the set of ready nodes.
     446 */
     447static inline void _Scheduler_SMP_Enqueue_ordered(
     448  Scheduler_Context *context,
     449  Thread_Control *thread,
     450  Chain_Node_order order,
     451  Scheduler_SMP_Insert insert_ready,
     452  Scheduler_SMP_Insert insert_scheduled,
     453  Scheduler_SMP_Move move_from_scheduled_to_ready
     454)
     455{
     456  Scheduler_SMP_Context *self = _Scheduler_SMP_Get_self( context );
     457  Thread_Control *lowest_scheduled =
     458    _Scheduler_SMP_Get_lowest_scheduled( self );
     459
     460  _Assert( lowest_scheduled != NULL);
     461
     462  /*
     463   * NOTE: Do not exchange parameters to do the negation of the order check.
     464   */
     465  if ( ( *order )( &thread->Object.Node, &lowest_scheduled->Object.Node ) ) {
     466    Scheduler_SMP_Node *lowest_scheduled_node =
     467      _Scheduler_SMP_Node_get( lowest_scheduled );
     468
     469    _Scheduler_SMP_Node_change_state(
     470      lowest_scheduled_node,
     471      SCHEDULER_SMP_NODE_READY
     472    );
     473    _Scheduler_SMP_Allocate_processor( self, thread, lowest_scheduled );
     474    ( *insert_scheduled )( &self->Base, thread );
     475    ( *move_from_scheduled_to_ready )( &self->Base, lowest_scheduled );
     476  } else {
     477    ( *insert_ready )( &self->Base, thread );
     478  }
     479}
     480
     481/**
     482 * @brief Enqueues a scheduled thread according to the specified order
     483 * function.
     484 *
     485 * @param[in] context The scheduler instance context.
     486 * @param[in] thread The thread to enqueue.
    438487 * @param[in] order The order function.
    439488 * @param[in] get_highest_ready Function to get the highest ready node.
     
    444493 * @param[in] move_from_ready_to_scheduled Function to move a node from the set
    445494 * of ready nodes to the set of scheduled nodes.
    446  * @param[in] move_from_scheduled_to_ready Function to move a node from the set
    447  * of scheduled nodes to the set of ready nodes.
    448495 */
    449 static inline void _Scheduler_SMP_Enqueue_ordered(
     496static inline void _Scheduler_SMP_Enqueue_scheduled_ordered(
    450497  Scheduler_Context *context,
    451498  Thread_Control *thread,
    452   bool has_processor_allocated,
    453499  Chain_Node_order order,
    454500  Scheduler_SMP_Get_highest_ready get_highest_ready,
    455501  Scheduler_SMP_Insert insert_ready,
    456502  Scheduler_SMP_Insert insert_scheduled,
    457   Scheduler_SMP_Move move_from_ready_to_scheduled,
    458   Scheduler_SMP_Move move_from_scheduled_to_ready
     503  Scheduler_SMP_Move move_from_ready_to_scheduled
    459504)
    460505{
    461506  Scheduler_SMP_Context *self = _Scheduler_SMP_Get_self( context );
    462507  Scheduler_SMP_Node *node = _Scheduler_SMP_Node_get( thread );
    463 
    464   if ( has_processor_allocated) {
    465     Thread_Control *highest_ready = ( *get_highest_ready )( &self->Base );
    466 
    467     _Assert( highest_ready != NULL);
    468 
    469     /*
    470      * The thread has been extracted from the scheduled chain.  We have to
    471      * place it now on the scheduled or ready chain.
    472      *
    473      * NOTE: Do not exchange parameters to do the negation of the order check.
    474      */
    475     if ( !( *order )( &thread->Object.Node, &highest_ready->Object.Node ) ) {
    476       _Scheduler_SMP_Node_change_state( node, SCHEDULER_SMP_NODE_READY );
    477       _Scheduler_SMP_Allocate_processor( self, highest_ready, thread );
    478       ( *insert_ready )( &self->Base, thread );
    479       ( *move_from_ready_to_scheduled )( &self->Base, highest_ready );
    480     } else {
    481       _Scheduler_SMP_Node_change_state( node, SCHEDULER_SMP_NODE_SCHEDULED );
    482       ( *insert_scheduled )( &self->Base, thread );
    483     }
     508  Thread_Control *highest_ready = ( *get_highest_ready )( &self->Base );
     509
     510  _Assert( highest_ready != NULL);
     511
     512  /*
     513   * The thread has been extracted from the scheduled chain.  We have to place
     514   * it now on the scheduled or ready set.
     515   *
     516   * NOTE: Do not exchange parameters to do the negation of the order check.
     517   */
     518  if ( !( *order )( &thread->Object.Node, &highest_ready->Object.Node ) ) {
     519    _Scheduler_SMP_Node_change_state( node, SCHEDULER_SMP_NODE_READY );
     520    _Scheduler_SMP_Allocate_processor( self, highest_ready, thread );
     521    ( *insert_ready )( &self->Base, thread );
     522    ( *move_from_ready_to_scheduled )( &self->Base, highest_ready );
    484523  } else {
    485     Thread_Control *lowest_scheduled =
    486       _Scheduler_SMP_Get_lowest_scheduled( self );
    487 
    488     _Assert( lowest_scheduled != NULL);
    489 
    490     if ( ( *order )( &thread->Object.Node, &lowest_scheduled->Object.Node ) ) {
    491       Scheduler_SMP_Node *lowest_scheduled_node =
    492         _Scheduler_SMP_Node_get( lowest_scheduled );
    493 
    494       _Scheduler_SMP_Node_change_state(
    495         lowest_scheduled_node,
    496         SCHEDULER_SMP_NODE_READY
    497       );
    498       _Scheduler_SMP_Allocate_processor( self, thread, lowest_scheduled );
    499       ( *insert_scheduled )( &self->Base, thread );
    500       ( *move_from_scheduled_to_ready )( &self->Base, lowest_scheduled );
    501     } else {
    502       _Scheduler_SMP_Node_change_state( node, SCHEDULER_SMP_NODE_READY );
    503       ( *insert_ready )( &self->Base, thread );
    504     }
    505   }
    506 }
    507 
    508 static inline void _Scheduler_SMP_Extract_from_scheduled( Thread_Control *thread )
     524    ( *insert_scheduled )( &self->Base, thread );
     525  }
     526}
     527
     528static inline void _Scheduler_SMP_Extract_from_scheduled(
     529  Thread_Control *thread
     530)
    509531{
    510532  _Chain_Extract_unprotected( &thread->Object.Node );
     
    564586}
    565587
     588static inline void _Scheduler_SMP_Unblock(
     589  Scheduler_Context *context,
     590  Thread_Control *thread,
     591  Scheduler_SMP_Enqueue enqueue_fifo
     592)
     593{
     594  Scheduler_SMP_Node *node = _Scheduler_SMP_Node_get( thread );
     595
     596  _Scheduler_SMP_Node_change_state( node, SCHEDULER_SMP_NODE_READY );
     597
     598  ( *enqueue_fifo )( context, thread );
     599}
     600
    566601static inline void _Scheduler_SMP_Change_priority(
    567602  Scheduler_Context *context,
     
    572607  Scheduler_SMP_Update update,
    573608  Scheduler_SMP_Enqueue enqueue_fifo,
    574   Scheduler_SMP_Enqueue enqueue_lifo
     609  Scheduler_SMP_Enqueue enqueue_lifo,
     610  Scheduler_SMP_Enqueue enqueue_scheduled_fifo,
     611  Scheduler_SMP_Enqueue enqueue_scheduled_lifo
    575612)
    576613{
    577614  Scheduler_SMP_Node *node = _Scheduler_SMP_Node_get( thread );
    578   bool has_processor_allocated = node->state == SCHEDULER_SMP_NODE_SCHEDULED;
    579 
    580   if ( has_processor_allocated ) {
     615
     616  if ( node->state == SCHEDULER_SMP_NODE_SCHEDULED ) {
    581617    _Scheduler_SMP_Extract_from_scheduled( thread );
     618
     619    ( *update )( context, &node->Base, new_priority );
     620
     621    if ( prepend_it ) {
     622      ( *enqueue_scheduled_lifo )( context, thread );
     623    } else {
     624      ( *enqueue_scheduled_fifo )( context, thread );
     625    }
    582626  } else {
    583627    ( *extract_from_ready )( context, thread );
    584   }
    585 
    586   ( *update )( context, &node->Base, new_priority );
    587 
    588   if ( prepend_it ) {
    589     ( *enqueue_lifo )( context, thread, has_processor_allocated );
    590   } else {
    591     ( *enqueue_fifo )( context, thread, has_processor_allocated );
     628
     629    ( *update )( context, &node->Base, new_priority );
     630
     631    if ( prepend_it ) {
     632      ( *enqueue_lifo )( context, thread );
     633    } else {
     634      ( *enqueue_fifo )( context, thread );
     635    }
    592636  }
    593637}
  • cpukit/score/src/schedulerprioritysmp.c

    rb4bdbcf rc0bff5e  
    229229  Scheduler_Context *context,
    230230  Thread_Control *thread,
    231   bool has_processor_allocated,
    232231  Chain_Node_order order,
    233232  Scheduler_SMP_Insert insert_ready,
     
    238237    context,
    239238    thread,
    240     has_processor_allocated,
     239    order,
     240    insert_ready,
     241    insert_scheduled,
     242    _Scheduler_priority_SMP_Move_from_scheduled_to_ready
     243  );
     244}
     245
     246static void _Scheduler_priority_SMP_Enqueue_lifo(
     247  Scheduler_Context *context,
     248  Thread_Control *thread
     249)
     250{
     251  _Scheduler_priority_SMP_Enqueue_ordered(
     252    context,
     253    thread,
     254    _Scheduler_simple_Insert_priority_lifo_order,
     255    _Scheduler_priority_SMP_Insert_ready_lifo,
     256    _Scheduler_SMP_Insert_scheduled_lifo
     257  );
     258}
     259
     260static void _Scheduler_priority_SMP_Enqueue_fifo(
     261  Scheduler_Context *context,
     262  Thread_Control *thread
     263)
     264{
     265  _Scheduler_priority_SMP_Enqueue_ordered(
     266    context,
     267    thread,
     268    _Scheduler_simple_Insert_priority_fifo_order,
     269    _Scheduler_priority_SMP_Insert_ready_fifo,
     270    _Scheduler_SMP_Insert_scheduled_fifo
     271  );
     272}
     273
     274static void _Scheduler_priority_SMP_Enqueue_scheduled_ordered(
     275  Scheduler_Context *context,
     276  Thread_Control *thread,
     277  Chain_Node_order order,
     278  Scheduler_SMP_Insert insert_ready,
     279  Scheduler_SMP_Insert insert_scheduled
     280)
     281{
     282  _Scheduler_SMP_Enqueue_scheduled_ordered(
     283    context,
     284    thread,
    241285    order,
    242286    _Scheduler_priority_SMP_Get_highest_ready,
    243287    insert_ready,
    244288    insert_scheduled,
    245     _Scheduler_priority_SMP_Move_from_ready_to_scheduled,
    246     _Scheduler_priority_SMP_Move_from_scheduled_to_ready
    247   );
    248 }
    249 
    250 static void _Scheduler_priority_SMP_Enqueue_lifo(
    251   Scheduler_Context *context,
    252   Thread_Control *thread,
    253   bool has_processor_allocated
    254 )
    255 {
    256   _Scheduler_priority_SMP_Enqueue_ordered(
    257     context,
    258     thread,
    259     has_processor_allocated,
     289    _Scheduler_priority_SMP_Move_from_ready_to_scheduled
     290  );
     291}
     292
     293static void _Scheduler_priority_SMP_Enqueue_scheduled_lifo(
     294  Scheduler_Context *context,
     295  Thread_Control *thread
     296)
     297{
     298  _Scheduler_priority_SMP_Enqueue_scheduled_ordered(
     299    context,
     300    thread,
    260301    _Scheduler_simple_Insert_priority_lifo_order,
    261302    _Scheduler_priority_SMP_Insert_ready_lifo,
     
    264305}
    265306
    266 static void _Scheduler_priority_SMP_Enqueue_fifo(
    267   Scheduler_Context *context,
    268   Thread_Control *thread,
    269   bool has_processor_allocated
    270 )
    271 {
    272   _Scheduler_priority_SMP_Enqueue_ordered(
    273     context,
    274     thread,
    275     has_processor_allocated,
     307static void _Scheduler_priority_SMP_Enqueue_scheduled_fifo(
     308  Scheduler_Context *context,
     309  Thread_Control *thread
     310)
     311{
     312  _Scheduler_priority_SMP_Enqueue_scheduled_ordered(
     313    context,
     314    thread,
    276315    _Scheduler_simple_Insert_priority_fifo_order,
    277316    _Scheduler_priority_SMP_Insert_ready_fifo,
     
    287326  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
    288327
    289   _Scheduler_priority_SMP_Enqueue_fifo( context, thread, false );
     328  _Scheduler_SMP_Unblock(
     329    context,
     330    thread,
     331    _Scheduler_priority_SMP_Enqueue_fifo
     332  );
    290333}
    291334
     
    307350    _Scheduler_priority_SMP_Do_update,
    308351    _Scheduler_priority_SMP_Enqueue_fifo,
    309     _Scheduler_priority_SMP_Enqueue_lifo
     352    _Scheduler_priority_SMP_Enqueue_lifo,
     353    _Scheduler_priority_SMP_Enqueue_scheduled_fifo,
     354    _Scheduler_priority_SMP_Enqueue_scheduled_lifo
    310355  );
    311356}
     
    322367
    323368  _Scheduler_SMP_Extract_from_scheduled( thread );
    324   _Scheduler_priority_SMP_Enqueue_fifo( context, thread, true );
     369  _Scheduler_priority_SMP_Enqueue_scheduled_fifo( context, thread );
    325370
    326371  _ISR_Enable( level );
  • cpukit/score/src/schedulersimplesmp.c

    rb4bdbcf rc0bff5e  
    165165  Scheduler_Context *context,
    166166  Thread_Control *thread,
    167   bool has_processor_allocated,
    168167  Chain_Node_order order,
    169168  Scheduler_SMP_Insert insert_ready,
     
    174173    context,
    175174    thread,
    176     has_processor_allocated,
     175    order,
     176    insert_ready,
     177    insert_scheduled,
     178    _Scheduler_simple_SMP_Move_from_scheduled_to_ready
     179  );
     180}
     181
     182static void _Scheduler_simple_SMP_Enqueue_lifo(
     183  Scheduler_Context *context,
     184  Thread_Control *thread
     185)
     186{
     187  _Scheduler_simple_SMP_Enqueue_ordered(
     188    context,
     189    thread,
     190    _Scheduler_simple_Insert_priority_lifo_order,
     191    _Scheduler_simple_SMP_Insert_ready_lifo,
     192    _Scheduler_SMP_Insert_scheduled_lifo
     193  );
     194}
     195
     196static void _Scheduler_simple_SMP_Enqueue_fifo(
     197  Scheduler_Context *context,
     198  Thread_Control *thread
     199)
     200{
     201  _Scheduler_simple_SMP_Enqueue_ordered(
     202    context,
     203    thread,
     204    _Scheduler_simple_Insert_priority_fifo_order,
     205    _Scheduler_simple_SMP_Insert_ready_fifo,
     206    _Scheduler_SMP_Insert_scheduled_fifo
     207  );
     208}
     209
     210static void _Scheduler_simple_SMP_Enqueue_scheduled_ordered(
     211  Scheduler_Context *context,
     212  Thread_Control *thread,
     213  Chain_Node_order order,
     214  Scheduler_SMP_Insert insert_ready,
     215  Scheduler_SMP_Insert insert_scheduled
     216)
     217{
     218  _Scheduler_SMP_Enqueue_scheduled_ordered(
     219    context,
     220    thread,
    177221    order,
    178222    _Scheduler_simple_SMP_Get_highest_ready,
    179223    insert_ready,
    180224    insert_scheduled,
    181     _Scheduler_simple_SMP_Move_from_ready_to_scheduled,
    182     _Scheduler_simple_SMP_Move_from_scheduled_to_ready
    183   );
    184 }
    185 
    186 static void _Scheduler_simple_SMP_Enqueue_lifo(
    187   Scheduler_Context *context,
    188   Thread_Control *thread,
    189   bool has_processor_allocated
    190 )
    191 {
    192   _Scheduler_simple_SMP_Enqueue_ordered(
    193     context,
    194     thread,
    195     has_processor_allocated,
     225    _Scheduler_simple_SMP_Move_from_ready_to_scheduled
     226  );
     227}
     228
     229static void _Scheduler_simple_SMP_Enqueue_scheduled_lifo(
     230  Scheduler_Context *context,
     231  Thread_Control *thread
     232)
     233{
     234  _Scheduler_simple_SMP_Enqueue_scheduled_ordered(
     235    context,
     236    thread,
    196237    _Scheduler_simple_Insert_priority_lifo_order,
    197238    _Scheduler_simple_SMP_Insert_ready_lifo,
     
    200241}
    201242
    202 static void _Scheduler_simple_SMP_Enqueue_fifo(
    203   Scheduler_Context *context,
    204   Thread_Control *thread,
    205   bool has_processor_allocated
    206 )
    207 {
    208   _Scheduler_simple_SMP_Enqueue_ordered(
    209     context,
    210     thread,
    211     has_processor_allocated,
     243static void _Scheduler_simple_SMP_Enqueue_scheduled_fifo(
     244  Scheduler_Context *context,
     245  Thread_Control *thread
     246)
     247{
     248  _Scheduler_simple_SMP_Enqueue_scheduled_ordered(
     249    context,
     250    thread,
    212251    _Scheduler_simple_Insert_priority_fifo_order,
    213252    _Scheduler_simple_SMP_Insert_ready_fifo,
     
    223262  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
    224263
    225   _Scheduler_simple_SMP_Enqueue_fifo( context, thread, false );
     264  _Scheduler_SMP_Unblock(
     265    context,
     266    thread,
     267    _Scheduler_simple_SMP_Enqueue_fifo
     268  );
    226269}
    227270
     
    243286    _Scheduler_simple_SMP_Do_update,
    244287    _Scheduler_simple_SMP_Enqueue_fifo,
    245     _Scheduler_simple_SMP_Enqueue_lifo
     288    _Scheduler_simple_SMP_Enqueue_lifo,
     289    _Scheduler_simple_SMP_Enqueue_scheduled_fifo,
     290    _Scheduler_simple_SMP_Enqueue_scheduled_lifo
    246291  );
    247292}
     
    258303
    259304  _Scheduler_SMP_Extract_from_scheduled( thread );
    260   _Scheduler_simple_SMP_Enqueue_fifo( context, thread, true );
     305  _Scheduler_simple_SMP_Enqueue_scheduled_fifo( context, thread );
    261306
    262307  _ISR_Enable( level );
  • testsuites/smptests/Makefile.am

    rb4bdbcf rc0bff5e  
    2626SUBDIRS += smpscheduler01
    2727SUBDIRS += smpscheduler02
     28SUBDIRS += smpscheduler03
    2829SUBDIRS += smpsignal01
    2930SUBDIRS += smpswitchextension01
  • testsuites/smptests/configure.ac

    rb4bdbcf rc0bff5e  
    8484smpscheduler01/Makefile
    8585smpscheduler02/Makefile
     86smpscheduler03/Makefile
    8687smpsignal01/Makefile
    8788smpswitchextension01/Makefile
Note: See TracChangeset for help on using the changeset viewer.