Changeset 65a5c1b in rtems


Ignore:
Timestamp:
Jun 6, 1996, 3:32:49 PM (25 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
0207c55
Parents:
ebd40c0
Message:

completed pthread_setschedparam.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/posix/src/pthread.c

    rebd40c0 r65a5c1b  
    4343/*PAGE
    4444 *
     45 *  _POSIX_Threads_Sporadic_budget_TSR
     46 */
     47
     48void _POSIX_Threads_Sporadic_budget_TSR(
     49  Objects_Id      id,
     50  void           *argument
     51)
     52{
     53  Thread_Control     *the_thread;
     54  POSIX_API_Control  *api;
     55
     56  the_thread = argument;
     57
     58  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
     59
     60  the_thread->cpu_time_budget =
     61    _POSIX_Timespec_to_interval( &api->schedparam.ss_initial_budget );
     62
     63  _Thread_Change_priority(
     64    the_thread,
     65    _POSIX_Priority_To_core( api->schedparam.sched_priority )
     66  );
     67 
     68  _Watchdog_Insert_ticks(
     69    &api->Sporadic_timer,
     70    _POSIX_Timespec_to_interval( &api->schedparam.ss_replenish_period )
     71  );
     72}
     73
     74/*PAGE
     75 *
     76 *  _POSIX_Threads_Sporadic_budget_callout
     77 */
     78
     79void _POSIX_Threads_Sporadic_budget_callout(
     80  Thread_Control *the_thread
     81)
     82{
     83  POSIX_API_Control                  *api;
     84
     85  /* XXX really should be based on MAX_U32 */
     86
     87  api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
     88
     89  the_thread->cpu_time_budget = 0xFFFFFFFF;
     90
     91  _Thread_Change_priority(
     92    the_thread,
     93    _POSIX_Priority_To_core( api->schedparam.ss_low_priority )
     94  );
     95}
     96
     97/*PAGE
     98 *
    4599 *  _POSIX_Threads_Create_extension
    46100 *
     
    422476)
    423477{
    424   register Thread_Control *the_thread;
    425   POSIX_API_Control       *api;
    426   Objects_Locations        location;
    427  
     478  register Thread_Control             *the_thread;
     479  POSIX_API_Control                   *api;
     480  Thread_CPU_budget_algorithms         budget_algorithm;
     481  Thread_CPU_budget_algorithm_callout  budget_callout;
     482  Objects_Locations                    location;
     483 
     484  /*
     485   *  Check all the parameters
     486   */
     487
    428488  if ( !param )
    429489    return EINVAL;
    430490
    431   /* XXX need to reschedule after doing this to the thread */
    432   /* XXX need to have one routine called by create and here */
    433 #warning "pthread_setschedparam needs work"
     491  if ( !_POSIX_Priority_Is_valid( param->sched_priority ) )
     492    return EINVAL;
     493
     494  budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
     495  budget_callout = NULL;
     496
     497  switch ( policy ) {
     498    case SCHED_OTHER:
     499      budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
     500      break;
     501 
     502    case SCHED_FIFO:
     503      budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
     504      break;
     505 
     506    case SCHED_RR:
     507      budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
     508      break;
     509 
     510    case SCHED_SPORADIC:
     511      budget_algorithm  = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
     512      budget_callout = _POSIX_Threads_Sporadic_budget_callout;
     513 
     514      if ( _POSIX_Timespec_to_interval( &param->ss_replenish_period ) <
     515           _POSIX_Timespec_to_interval( &param->ss_initial_budget ) )
     516        return EINVAL;
     517 
     518      if ( !_POSIX_Priority_Is_valid( param->ss_low_priority ) )
     519        return EINVAL;
     520 
     521      break;
     522 
     523    default:
     524      return EINVAL;
     525  }
     526
     527  /*
     528   *  Actually change the scheduling policy and parameters
     529   */
    434530
    435531  the_thread = _POSIX_Threads_Get( thread, &location );
     
    439535      return ESRCH;
    440536    case OBJECTS_LOCAL:
    441       switch ( policy ) {
     537      api = the_thread->API_Extensions[ THREAD_API_POSIX ];
     538
     539      if ( api->schedpolicy == SCHED_SPORADIC )
     540        (void) _Watchdog_Remove( &api->Sporadic_timer );
     541
     542      api->schedpolicy = policy;
     543      api->schedparam  = *param;
     544      the_thread->budget_algorithm = budget_algorithm;
     545      the_thread->budget_callout   = budget_callout;
     546
     547      switch ( api->schedpolicy ) {
    442548        case SCHED_OTHER:
    443549        case SCHED_FIFO:
    444550        case SCHED_RR:
     551          the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
     552
     553          _Thread_Change_priority(
     554            the_thread,
     555            _POSIX_Priority_To_core( api->schedparam.sched_priority )
     556          );
     557          break;
     558 
    445559        case SCHED_SPORADIC:
    446           /* XXX this is where the interpretation work should go */
     560          _POSIX_Threads_Sporadic_budget_TSR( 0, the_thread );
    447561          break;
    448  
    449         default:
    450           _Thread_Enable_dispatch();
    451           return EINVAL;
    452562      }
    453563
    454       api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    455 
    456       api->schedpolicy = policy;
    457       api->schedparam  = *param;
    458564      _Thread_Enable_dispatch();
    459565      return 0;
     
    604710      return EINVAL;
    605711  }
    606 }
    607 
    608 /*PAGE
    609  *
    610  *  _POSIX_Threads_Sporadic_budget_TSR
    611  */
    612 
    613 void _POSIX_Threads_Sporadic_budget_TSR(
    614   Objects_Id      id,
    615   void           *argument
    616 )
    617 {
    618   Thread_Control     *the_thread;
    619   POSIX_API_Control  *api;
    620 
    621   the_thread = argument;
    622 
    623   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    624 
    625   the_thread->cpu_time_budget =
    626     _POSIX_Timespec_to_interval( &api->schedparam.ss_initial_budget );
    627 
    628   _Thread_Change_priority(
    629     the_thread,
    630     _POSIX_Priority_To_core( api->schedparam.sched_priority )
    631   );
    632  
    633   _Watchdog_Insert_ticks(
    634     &api->Sporadic_timer,
    635     _POSIX_Timespec_to_interval( &api->schedparam.ss_replenish_period )
    636   );
    637 }
    638 
    639 /*PAGE
    640  *
    641  *  _POSIX_Threads_Sporadic_budget_callout
    642  */
    643 
    644 void _POSIX_Threads_Sporadic_budget_callout(
    645   Thread_Control *the_thread
    646 )
    647 {
    648   POSIX_API_Control                  *api;
    649 
    650   /* XXX really should be based on MAX_U32 */
    651 
    652   api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
    653 
    654   the_thread->cpu_time_budget = 0xFFFFFFFF;
    655 
    656   _Thread_Change_priority(
    657     the_thread,
    658     _POSIX_Priority_To_core( api->schedparam.ss_low_priority )
    659   );
    660712}
    661713
     
    776828
    777829      break;
     830
     831    default:
     832      return EINVAL;
    778833  }
    779834
     
    9981053      *(void **)the_thread->Wait.return_argument = value_ptr;
    9991054
     1055  if ( api->schedpolicy == SCHED_SPORADIC )
     1056    (void) _Watchdog_Remove( &api->Sporadic_timer );
     1057
    10001058  /* XXX run _POSIX_Keys_Run_destructors here? */
    10011059
     
    10181076 *
    10191077 *  16.1.7 Compare Thread IDs, p1003.1c/Draft 10, p. 153
     1078 *
     1079 *  NOTE:  POSIX does not define the behavior when either thread id is invalid.
    10201080 */
    10211081
     
    10281088  Objects_Locations location;
    10291089
    1030  /* XXX may want to do a "get" to make sure both are valid. */
    1031  /* XXX behavior is undefined if not valid pthread_t's */
    1032  
    10331090  /*
    10341091   *  By default this is not a match.
  • cpukit/posix/src/pthread.c

    rebd40c0 r65a5c1b  
    4343/*PAGE
    4444 *
     45 *  _POSIX_Threads_Sporadic_budget_TSR
     46 */
     47
     48void _POSIX_Threads_Sporadic_budget_TSR(
     49  Objects_Id      id,
     50  void           *argument
     51)
     52{
     53  Thread_Control     *the_thread;
     54  POSIX_API_Control  *api;
     55
     56  the_thread = argument;
     57
     58  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
     59
     60  the_thread->cpu_time_budget =
     61    _POSIX_Timespec_to_interval( &api->schedparam.ss_initial_budget );
     62
     63  _Thread_Change_priority(
     64    the_thread,
     65    _POSIX_Priority_To_core( api->schedparam.sched_priority )
     66  );
     67 
     68  _Watchdog_Insert_ticks(
     69    &api->Sporadic_timer,
     70    _POSIX_Timespec_to_interval( &api->schedparam.ss_replenish_period )
     71  );
     72}
     73
     74/*PAGE
     75 *
     76 *  _POSIX_Threads_Sporadic_budget_callout
     77 */
     78
     79void _POSIX_Threads_Sporadic_budget_callout(
     80  Thread_Control *the_thread
     81)
     82{
     83  POSIX_API_Control                  *api;
     84
     85  /* XXX really should be based on MAX_U32 */
     86
     87  api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
     88
     89  the_thread->cpu_time_budget = 0xFFFFFFFF;
     90
     91  _Thread_Change_priority(
     92    the_thread,
     93    _POSIX_Priority_To_core( api->schedparam.ss_low_priority )
     94  );
     95}
     96
     97/*PAGE
     98 *
    4599 *  _POSIX_Threads_Create_extension
    46100 *
     
    422476)
    423477{
    424   register Thread_Control *the_thread;
    425   POSIX_API_Control       *api;
    426   Objects_Locations        location;
    427  
     478  register Thread_Control             *the_thread;
     479  POSIX_API_Control                   *api;
     480  Thread_CPU_budget_algorithms         budget_algorithm;
     481  Thread_CPU_budget_algorithm_callout  budget_callout;
     482  Objects_Locations                    location;
     483 
     484  /*
     485   *  Check all the parameters
     486   */
     487
    428488  if ( !param )
    429489    return EINVAL;
    430490
    431   /* XXX need to reschedule after doing this to the thread */
    432   /* XXX need to have one routine called by create and here */
    433 #warning "pthread_setschedparam needs work"
     491  if ( !_POSIX_Priority_Is_valid( param->sched_priority ) )
     492    return EINVAL;
     493
     494  budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
     495  budget_callout = NULL;
     496
     497  switch ( policy ) {
     498    case SCHED_OTHER:
     499      budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
     500      break;
     501 
     502    case SCHED_FIFO:
     503      budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
     504      break;
     505 
     506    case SCHED_RR:
     507      budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
     508      break;
     509 
     510    case SCHED_SPORADIC:
     511      budget_algorithm  = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
     512      budget_callout = _POSIX_Threads_Sporadic_budget_callout;
     513 
     514      if ( _POSIX_Timespec_to_interval( &param->ss_replenish_period ) <
     515           _POSIX_Timespec_to_interval( &param->ss_initial_budget ) )
     516        return EINVAL;
     517 
     518      if ( !_POSIX_Priority_Is_valid( param->ss_low_priority ) )
     519        return EINVAL;
     520 
     521      break;
     522 
     523    default:
     524      return EINVAL;
     525  }
     526
     527  /*
     528   *  Actually change the scheduling policy and parameters
     529   */
    434530
    435531  the_thread = _POSIX_Threads_Get( thread, &location );
     
    439535      return ESRCH;
    440536    case OBJECTS_LOCAL:
    441       switch ( policy ) {
     537      api = the_thread->API_Extensions[ THREAD_API_POSIX ];
     538
     539      if ( api->schedpolicy == SCHED_SPORADIC )
     540        (void) _Watchdog_Remove( &api->Sporadic_timer );
     541
     542      api->schedpolicy = policy;
     543      api->schedparam  = *param;
     544      the_thread->budget_algorithm = budget_algorithm;
     545      the_thread->budget_callout   = budget_callout;
     546
     547      switch ( api->schedpolicy ) {
    442548        case SCHED_OTHER:
    443549        case SCHED_FIFO:
    444550        case SCHED_RR:
     551          the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
     552
     553          _Thread_Change_priority(
     554            the_thread,
     555            _POSIX_Priority_To_core( api->schedparam.sched_priority )
     556          );
     557          break;
     558 
    445559        case SCHED_SPORADIC:
    446           /* XXX this is where the interpretation work should go */
     560          _POSIX_Threads_Sporadic_budget_TSR( 0, the_thread );
    447561          break;
    448  
    449         default:
    450           _Thread_Enable_dispatch();
    451           return EINVAL;
    452562      }
    453563
    454       api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    455 
    456       api->schedpolicy = policy;
    457       api->schedparam  = *param;
    458564      _Thread_Enable_dispatch();
    459565      return 0;
     
    604710      return EINVAL;
    605711  }
    606 }
    607 
    608 /*PAGE
    609  *
    610  *  _POSIX_Threads_Sporadic_budget_TSR
    611  */
    612 
    613 void _POSIX_Threads_Sporadic_budget_TSR(
    614   Objects_Id      id,
    615   void           *argument
    616 )
    617 {
    618   Thread_Control     *the_thread;
    619   POSIX_API_Control  *api;
    620 
    621   the_thread = argument;
    622 
    623   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    624 
    625   the_thread->cpu_time_budget =
    626     _POSIX_Timespec_to_interval( &api->schedparam.ss_initial_budget );
    627 
    628   _Thread_Change_priority(
    629     the_thread,
    630     _POSIX_Priority_To_core( api->schedparam.sched_priority )
    631   );
    632  
    633   _Watchdog_Insert_ticks(
    634     &api->Sporadic_timer,
    635     _POSIX_Timespec_to_interval( &api->schedparam.ss_replenish_period )
    636   );
    637 }
    638 
    639 /*PAGE
    640  *
    641  *  _POSIX_Threads_Sporadic_budget_callout
    642  */
    643 
    644 void _POSIX_Threads_Sporadic_budget_callout(
    645   Thread_Control *the_thread
    646 )
    647 {
    648   POSIX_API_Control                  *api;
    649 
    650   /* XXX really should be based on MAX_U32 */
    651 
    652   api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
    653 
    654   the_thread->cpu_time_budget = 0xFFFFFFFF;
    655 
    656   _Thread_Change_priority(
    657     the_thread,
    658     _POSIX_Priority_To_core( api->schedparam.ss_low_priority )
    659   );
    660712}
    661713
     
    776828
    777829      break;
     830
     831    default:
     832      return EINVAL;
    778833  }
    779834
     
    9981053      *(void **)the_thread->Wait.return_argument = value_ptr;
    9991054
     1055  if ( api->schedpolicy == SCHED_SPORADIC )
     1056    (void) _Watchdog_Remove( &api->Sporadic_timer );
     1057
    10001058  /* XXX run _POSIX_Keys_Run_destructors here? */
    10011059
     
    10181076 *
    10191077 *  16.1.7 Compare Thread IDs, p1003.1c/Draft 10, p. 153
     1078 *
     1079 *  NOTE:  POSIX does not define the behavior when either thread id is invalid.
    10201080 */
    10211081
     
    10281088  Objects_Locations location;
    10291089
    1030  /* XXX may want to do a "get" to make sure both are valid. */
    1031  /* XXX behavior is undefined if not valid pthread_t's */
    1032  
    10331090  /*
    10341091   *  By default this is not a match.
Note: See TracChangeset for help on using the changeset viewer.