Changeset 9555341 in rtems


Ignore:
Timestamp:
Apr 6, 2016, 2:26:22 PM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
d26b053
Parents:
44ed384
git-author:
Sebastian Huber <sebastian.huber@…> (04/06/16 14:26:22)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/12/16 05:36:14)
Message:

posix: Use a dedicated lock for scheduler changes

Update #2555.

Location:
cpukit/posix
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/include/rtems/posix/pthreadimpl.h

    r44ed384 r9555341  
    224224}
    225225
     226RTEMS_INLINE_ROUTINE void _POSIX_Threads_Scheduler_acquire(
     227  POSIX_API_Control *api,
     228  ISR_lock_Context  *lock_context
     229)
     230{
     231  _ISR_lock_ISR_disable_and_acquire( &api->Scheduler_lock, lock_context );
     232}
     233
     234RTEMS_INLINE_ROUTINE void _POSIX_Threads_Scheduler_release(
     235  POSIX_API_Control *api,
     236  ISR_lock_Context  *lock_context
     237)
     238{
     239  _ISR_lock_Release_and_ISR_enable( &api->Scheduler_lock, lock_context );
     240}
     241
     242
    226243/** @} */
    227244
  • cpukit/posix/include/rtems/posix/threadsup.h

    r44ed384 r9555341  
    2020
    2121#include <rtems/score/coresem.h>
     22#include <rtems/score/isrlock.h>
    2223#include <rtems/score/thread.h>
    2324#include <rtems/score/threadq.h>
     
    5152  /** This is the set of threads waiting for the thread to exit. */
    5253  Thread_queue_Control    Join_List;
     54  /** This is the thread's current scheduling policy. */
     55  ISR_LOCK_MEMBER(        Scheduler_lock )
    5356  /** This is the thread's current scheduling policy. */
    5457  int                     schedpolicy;
  • cpukit/posix/src/pthread.c

    r44ed384 r9555341  
    107107void _POSIX_Threads_Sporadic_budget_TSR( Watchdog_Control *watchdog )
    108108{
    109   uint32_t            ticks;
    110109  POSIX_API_Control  *api;
    111110  Thread_Control     *the_thread;
    112   ISR_Level           level;
     111  ISR_lock_Context    lock_context;
     112  Priority_Control    new_priority;
    113113
    114114  api = RTEMS_CONTAINER_OF( watchdog, POSIX_API_Control, Sporadic_timer );
    115115  the_thread = api->thread;
    116116
    117   /* ticks is guaranteed to be at least one */
    118   ticks = _Timespec_To_ticks( &api->schedparam.sched_ss_init_budget );
    119 
    120   the_thread->cpu_time_budget = ticks;
     117  _POSIX_Threads_Scheduler_acquire( api, &lock_context );
     118
     119  the_thread->cpu_time_budget =
     120    _Timespec_To_ticks( &api->schedparam.sched_ss_init_budget );
     121
     122  _Watchdog_Per_CPU_remove_relative( &api->Sporadic_timer );
     123  _Watchdog_Per_CPU_insert_relative(
     124    &api->Sporadic_timer,
     125    _Per_CPU_Get(),
     126    _Timespec_To_ticks( &api->schedparam.sched_ss_repl_period )
     127  );
     128
     129  new_priority = _POSIX_Priority_To_core( api->schedparam.sched_priority );
     130
     131  _POSIX_Threads_Scheduler_release( api, &lock_context );
    121132
    122133  _Thread_Change_priority(
    123134    the_thread,
    124     _POSIX_Priority_To_core( api->schedparam.sched_priority ),
     135    new_priority,
    125136    NULL,
    126137    _POSIX_Threads_Sporadic_budget_TSR_filter,
    127138    true
    128139  );
    129 
    130   /* ticks is guaranteed to be at least one */
    131   ticks = _Timespec_To_ticks( &api->schedparam.sched_ss_repl_period );
    132 
    133   _Thread_Disable_dispatch();
    134   _ISR_Disable( level );
    135   _Watchdog_Per_CPU_insert_relative(
    136     &api->Sporadic_timer,
    137     _Per_CPU_Get(),
    138     ticks
    139   );
    140   _ISR_Enable( level );
    141   _Thread_Unnest_dispatch();
    142140}
    143141
     
    202200
    203201  api = created->API_Extensions[ THREAD_API_POSIX ];
     202
     203  _ISR_lock_Initialize( &api->Scheduler_lock, "POSIX Threads Scheduler" );
    204204
    205205  /* XXX check all fields are touched */
     
    245245}
    246246
     247static void _POSIX_Threads_Delete_extension(
     248  Thread_Control *executing,
     249  Thread_Control *deleted
     250)
     251{
     252  POSIX_API_Control *api;
     253
     254  api = deleted->API_Extensions[ THREAD_API_POSIX ];
     255
     256  _ISR_lock_Destroy( &api->Scheduler_lock );
     257  _Thread_queue_Destroy( &api->Join_List );
     258}
     259
    247260static void _POSIX_Threads_Terminate_extension(
    248261  Thread_Control *executing
     
    251264  Thread_Control     *the_thread;
    252265  POSIX_API_Control  *api;
     266  ISR_lock_Context    lock_context;
    253267  void              **value_ptr;
    254268
     
    266280  }
    267281
    268   if ( api->schedpolicy == SCHED_SPORADIC )
     282  _Thread_Enable_dispatch();
     283
     284  _POSIX_Threads_Scheduler_acquire( api, &lock_context );
     285
     286  if ( api->schedpolicy == SCHED_SPORADIC ) {
    269287    _Watchdog_Per_CPU_remove_relative( &api->Sporadic_timer );
    270 
    271   _Thread_queue_Destroy( &api->Join_List );
    272 
    273   _Thread_Enable_dispatch();
     288  }
     289
     290  _POSIX_Threads_Scheduler_release( api, &lock_context );
    274291}
    275292
     
    297314    NULL,                                     /* start */
    298315    NULL,                                     /* restart */
    299     NULL,                                     /* delete */
     316    _POSIX_Threads_Delete_extension,          /* delete */
    300317    NULL,                                     /* switch */
    301318    NULL,                                     /* begin */
  • cpukit/posix/src/pthreadcreate.c

    r44ed384 r9555341  
    248248
    249249  if ( schedpolicy == SCHED_SPORADIC ) {
    250     _ISR_Disable( level );
     250    _ISR_Disable_without_giant( level );
    251251    _Watchdog_Per_CPU_insert_relative(
    252252      &api->Sporadic_timer,
     
    254254      _Timespec_To_ticks( &api->schedparam.sched_ss_repl_period )
    255255    );
    256     _ISR_Enable( level );
     256    _ISR_Enable_without_giant( level );
    257257  }
    258258
  • cpukit/posix/src/pthreadsetschedparam.c

    r44ed384 r9555341  
    4545  int                                  rc;
    4646  Priority_Control                     unused;
    47   ISR_Level                            level;
     47  ISR_lock_Context                     lock_context;
     48  Priority_Control                     new_priority;
    4849
    4950  /*
     
    7172      api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    7273
     74      _POSIX_Threads_Scheduler_acquire( api, &lock_context );
     75
    7376      if ( api->schedpolicy == SCHED_SPORADIC ) {
    74         _ISR_Disable( level );
    7577        _Watchdog_Per_CPU_remove_relative( &api->Sporadic_timer );
    76         _ISR_Enable( level );
    7778      }
    7879
     
    8586      the_thread->budget_callout   = budget_callout;
    8687
    87       switch ( api->schedpolicy ) {
     88      switch ( policy ) {
    8889        case SCHED_OTHER:
    8990        case SCHED_FIFO:
     
    9192          the_thread->cpu_time_budget =
    9293            rtems_configuration_get_ticks_per_timeslice();
    93 
    94           _Thread_Set_priority(
    95             the_thread,
    96             _POSIX_Priority_To_core( api->schedparam.sched_priority ),
    97             &unused,
    98             true
    99           );
     94          new_priority =
     95            _POSIX_Priority_To_core( api->schedparam.sched_priority );
    10096          break;
    10197
    10298        case SCHED_SPORADIC:
    10399          api->ss_high_priority = api->schedparam.sched_priority;
    104           _ISR_Disable( level );
    105           _Watchdog_Per_CPU_remove_relative( &api->Sporadic_timer );
    106           _ISR_Enable( level );
     100          break;
     101      }
     102
     103      _POSIX_Threads_Scheduler_release( api, &lock_context );
     104
     105      switch ( policy ) {
     106        case SCHED_OTHER:
     107        case SCHED_FIFO:
     108        case SCHED_RR:
     109          _Thread_Set_priority( the_thread, new_priority, &unused, true );
     110          break;
     111
     112        case SCHED_SPORADIC:
    107113          _POSIX_Threads_Sporadic_budget_TSR( &api->Sporadic_timer );
    108114          break;
Note: See TracChangeset for help on using the changeset viewer.