Changeset 2612a0b in rtems


Ignore:
Timestamp:
Nov 2, 2016, 5:36:13 AM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
f20dfa8
Parents:
16b14cfd
git-author:
Sebastian Huber <sebastian.huber@…> (11/02/16 05:36:13)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/09/16 14:27:29)
Message:

score: Simplify _Scheduler_Get_by_id()

Avoid dead code in non-SMP configurations. Return scheduler identifier
independent of the current processor count of the scheduler via
rtems_scheduler_ident(), since this value may change during run-time.
Check the processor count in _Scheduler_Set() under scheduler lock
protection.

Update #2797.

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/rtems/include/rtems/rtems/tasks.h

    r16b14cfd r2612a0b  
    556556 * @retval RTEMS_INVALID_ADDRESS The @a id parameter is @c NULL.
    557557 * @retval RTEMS_INVALID_NAME Invalid scheduler name.
    558  * @retval RTEMS_UNSATISFIED A scheduler with this name exists, but the
    559  * processor set of this scheduler is empty.
    560558 */
    561559rtems_status_code rtems_scheduler_ident(
  • cpukit/rtems/src/schedulergetprocessorset.c

    r16b14cfd r2612a0b  
    3535  }
    3636
    37   if ( !_Scheduler_Get_by_id( scheduler_id, &scheduler ) ) {
     37  scheduler = _Scheduler_Get_by_id( scheduler_id );
     38  if ( scheduler == NULL ) {
    3839    return RTEMS_INVALID_ID;
    3940  }
  • cpukit/rtems/src/schedulerident.c

    r16b14cfd r2612a0b  
    3737
    3838      if ( scheduler->name == name ) {
    39         if ( _Scheduler_Get_processor_count( scheduler ) > 0 ) {
    40           *id = _Scheduler_Build_id( i );
    41           sc = RTEMS_SUCCESSFUL;
    42         } else {
    43           sc = RTEMS_UNSATISFIED;
    44         }
     39        *id = _Scheduler_Build_id( i );
     40        sc = RTEMS_SUCCESSFUL;
    4541      }
    4642    }
  • cpukit/rtems/src/semsetpriority.c

    r16b14cfd r2612a0b  
    139139  }
    140140
    141   if ( !_Scheduler_Get_by_id( scheduler_id, &scheduler ) ) {
     141  scheduler = _Scheduler_Get_by_id( scheduler_id );
     142  if ( scheduler == NULL ) {
    142143    return RTEMS_INVALID_ID;
    143144  }
  • cpukit/rtems/src/taskgetpriority.c

    r16b14cfd r2612a0b  
    3737  }
    3838
    39   if ( !_Scheduler_Get_by_id( scheduler_id, &scheduler ) ) {
     39  scheduler = _Scheduler_Get_by_id( scheduler_id );
     40  if ( scheduler == NULL ) {
    4041    return RTEMS_INVALID_ID;
    4142  }
  • cpukit/rtems/src/tasksetscheduler.c

    r16b14cfd r2612a0b  
    3636  Status_Control           status;
    3737
    38   if ( !_Scheduler_Get_by_id( scheduler_id, &scheduler ) ) {
     38  scheduler = _Scheduler_Get_by_id( scheduler_id );
     39  if ( scheduler == NULL ) {
    3940    return RTEMS_INVALID_ID;
    4041  }
  • cpukit/score/include/rtems/score/schedulerimpl.h

    r16b14cfd r2612a0b  
    829829}
    830830
    831 RTEMS_INLINE_ROUTINE bool _Scheduler_Get_by_id(
    832   Objects_Id                id,
    833   const Scheduler_Control **scheduler_p
    834 )
    835 {
    836   uint32_t index = _Scheduler_Get_index_by_id( id );
    837   const Scheduler_Control *scheduler = &_Scheduler_Table[ index ];
    838 
    839   *scheduler_p = scheduler;
    840 
    841   return index < _Scheduler_Count
    842     && _Scheduler_Get_processor_count( scheduler ) > 0;
     831RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Get_by_id(
     832  Objects_Id id
     833)
     834{
     835  uint32_t index;
     836
     837  index = _Scheduler_Get_index_by_id( id );
     838
     839  if ( index >= _Scheduler_Count ) {
     840    return NULL;
     841  }
     842
     843  return &_Scheduler_Table[ index ];
    843844}
    844845
     
    12061207)
    12071208{
    1208   Scheduler_Node *new_scheduler_node;
    1209   Scheduler_Node *old_scheduler_node;
     1209  Scheduler_Node          *new_scheduler_node;
     1210  Scheduler_Node          *old_scheduler_node;
     1211#if defined(RTEMS_SMP)
     1212  ISR_lock_Context         lock_context;
     1213  const Scheduler_Control *old_scheduler;
     1214
     1215#endif
    12101216
    12111217  if ( the_thread->Wait.queue != NULL ) {
     
    12301236#if defined(RTEMS_SMP)
    12311237  if ( !_Chain_Has_only_one_node( &the_thread->Scheduler.Wait_nodes ) ) {
     1238    _Priority_Plain_insert(
     1239      &old_scheduler_node->Wait.Priority,
     1240      &the_thread->Real_priority,
     1241      the_thread->Real_priority.priority
     1242    );
    12321243    return STATUS_RESOURCE_IN_USE;
    12331244  }
     1245
     1246  old_scheduler = _Thread_Scheduler_get_home( the_thread );
     1247
     1248  _Scheduler_Acquire_critical( new_scheduler, &lock_context );
     1249
     1250  if ( _Scheduler_Get_processor_count( new_scheduler ) == 0 ) {
     1251    _Scheduler_Release_critical( new_scheduler, &lock_context );
     1252    _Priority_Plain_insert(
     1253      &old_scheduler_node->Wait.Priority,
     1254      &the_thread->Real_priority,
     1255      the_thread->Real_priority.priority
     1256    );
     1257    return STATUS_UNSATISFIED;
     1258  }
     1259
     1260  the_thread->Scheduler.home = new_scheduler;
     1261
     1262  _Scheduler_Release_critical( new_scheduler, &lock_context );
    12341263
    12351264  _Thread_Scheduler_process_requests( the_thread );
     
    12501279
    12511280#if defined(RTEMS_SMP)
    1252   {
    1253     const Scheduler_Control *old_scheduler;
    1254 
    1255     old_scheduler = _Thread_Scheduler_get_home( the_thread );
    1256 
    1257     if ( old_scheduler != new_scheduler ) {
    1258       States_Control current_state;
    1259 
    1260       current_state = the_thread->current_state;
    1261 
    1262       if ( _States_Is_ready( current_state ) ) {
    1263         _Scheduler_Block( the_thread );
    1264       }
    1265 
    1266       _Assert( old_scheduler_node->sticky_level == 0 );
    1267       _Assert( new_scheduler_node->sticky_level == 0 );
    1268 
    1269       _Chain_Extract_unprotected( &old_scheduler_node->Thread.Wait_node );
    1270       _Assert( _Chain_Is_empty( &the_thread->Scheduler.Wait_nodes ) );
    1271       _Chain_Initialize_one(
    1272         &the_thread->Scheduler.Wait_nodes,
    1273         &new_scheduler_node->Thread.Wait_node
    1274       );
    1275       _Chain_Extract_unprotected(
    1276         &old_scheduler_node->Thread.Scheduler_node.Chain
    1277       );
    1278       _Assert( _Chain_Is_empty( &the_thread->Scheduler.Scheduler_nodes ) );
    1279       _Chain_Initialize_one(
    1280         &the_thread->Scheduler.Scheduler_nodes,
    1281         &new_scheduler_node->Thread.Scheduler_node.Chain
    1282       );
    1283 
    1284       the_thread->Scheduler.home = new_scheduler;
    1285       _Scheduler_Node_set_priority( new_scheduler_node, priority, false );
    1286 
    1287       if ( _States_Is_ready( current_state ) ) {
    1288         _Scheduler_Unblock( the_thread );
    1289       }
    1290 
    1291       return STATUS_SUCCESSFUL;
     1281  if ( old_scheduler != new_scheduler ) {
     1282    States_Control current_state;
     1283
     1284    current_state = the_thread->current_state;
     1285
     1286    if ( _States_Is_ready( current_state ) ) {
     1287      _Scheduler_Block( the_thread );
    12921288    }
     1289
     1290    _Assert( old_scheduler_node->sticky_level == 0 );
     1291    _Assert( new_scheduler_node->sticky_level == 0 );
     1292
     1293    _Chain_Extract_unprotected( &old_scheduler_node->Thread.Wait_node );
     1294    _Assert( _Chain_Is_empty( &the_thread->Scheduler.Wait_nodes ) );
     1295    _Chain_Initialize_one(
     1296      &the_thread->Scheduler.Wait_nodes,
     1297      &new_scheduler_node->Thread.Wait_node
     1298    );
     1299    _Chain_Extract_unprotected(
     1300      &old_scheduler_node->Thread.Scheduler_node.Chain
     1301    );
     1302    _Assert( _Chain_Is_empty( &the_thread->Scheduler.Scheduler_nodes ) );
     1303    _Chain_Initialize_one(
     1304      &the_thread->Scheduler.Scheduler_nodes,
     1305      &new_scheduler_node->Thread.Scheduler_node.Chain
     1306    );
     1307
     1308    _Scheduler_Node_set_priority( new_scheduler_node, priority, false );
     1309
     1310    if ( _States_Is_ready( current_state ) ) {
     1311      _Scheduler_Unblock( the_thread );
     1312    }
     1313
     1314    return STATUS_SUCCESSFUL;
    12931315  }
    12941316#endif
  • testsuites/smptests/smpscheduler02/init.c

    r16b14cfd r2612a0b  
    109109
    110110  sc = rtems_scheduler_ident(SCHED_C, &scheduler_c_id);
    111   rtems_test_assert(sc == RTEMS_UNSATISFIED);
     111  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    112112
    113113  sc = rtems_semaphore_create(
     
    183183  rtems_test_assert(sched_get_priority_max(SCHED_RR) == 254);
    184184
     185  sc = rtems_task_set_scheduler(task_id, scheduler_c_id, 1);
     186  rtems_test_assert(sc == RTEMS_UNSATISFIED);
     187
     188  sc = rtems_task_set_scheduler(task_id, scheduler_c_id + 1, 1);
     189  rtems_test_assert(sc == RTEMS_INVALID_ID);
     190
    185191  if (cpu_count > 1) {
    186192    sc = rtems_task_set_scheduler(task_id, scheduler_b_id, 1);
    187193    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    188 
    189     sc = rtems_task_set_scheduler(task_id, scheduler_b_id + 1, 1);
    190     rtems_test_assert(sc == RTEMS_INVALID_ID);
    191194
    192195    sc = rtems_task_get_scheduler(task_id, &scheduler_id);
Note: See TracChangeset for help on using the changeset viewer.