Changeset 5a32c48 in rtems


Ignore:
Timestamp:
Jun 14, 2016, 1:57:54 PM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
1a4eac5
Parents:
eec08ef
git-author:
Sebastian Huber <sebastian.huber@…> (06/14/16 13:57:54)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/22/16 12:00:28)
Message:

posix: Make POSIX API aware of scheduler instances

Location:
cpukit/posix
Files:
10 edited

Legend:

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

    reec08ef r5a32c48  
    3131 * @ingroup POSIXAPI
    3232 *
    33  * @brief Interface to the POSIX Priority Implementation
    34  *
     33 * @brief Interface to the POSIX Priority Implementation.
     34 *
     35 * @{
    3536 */
    36 /**@{**/
    37 
    38 /**
    39  * 1003.1b-1993,2.2.2.80 definition of priority, p. 19
    40  *
    41  * "Numerically higher values represent higher priorities."
    42  *
    43  * Thus, RTEMS Core has priorities run in the opposite sense of the POSIX API.
    44  *
    45  * There are only 254 posix priority levels since a task at priority level
    46  * 255 would never run because of the RTEMS idle task.  This is necessary
    47  * because GNAT maps the lowest Ada task priority to the lowest thread
    48  * priority.  The lowest priority Ada task should get to run, so there is
    49  * a fundamental conflict with having 255 priorities.
    50  *
    51  * But since RTEMS can be configured with fewer than 256 priorities,
    52  * we use the internal constant.
    53  */
    54 #define POSIX_SCHEDULER_MAXIMUM_PRIORITY (PRIORITY_MAXIMUM - 1)
    55 
    5637
    5738/**
     
    7354 * @brief Check if POSIX priority is valid.
    7455 *
    75  * 1003.1b-1993,2.2.2.80 definition of priority, p. 19
     56 * According to POSIX, numerically higher values represent higher priorities.
     57 * Thus, SuperCore has priorities run in the opposite sense of the POSIX API.
    7658 *
    77  * "Numerically higher values represent higher priorities."
     59 * Let N be the maximum priority of this scheduler instance.   The SuperCore
     60 * priority zero is system reserved (PRIORITY_PSEUDO_ISR).  There are only
     61 * N - 1 POSIX API priority levels since a thread at SuperCore priority N would
     62 * never run because of the idle threads.  This is necessary because GNAT maps
     63 * the lowest Ada task priority to the lowest thread priority.  The lowest
     64 * priority Ada task should get to run, so there is a fundamental conflict with
     65 * having N priorities.
    7866 *
    79  * Thus, RTEMS Core has priorities run in the opposite sense of the POSIX API.
     67 * @param[in] scheduler The scheduler instance.
     68 * @param[in] priority The POSIX API priority to test.
    8069 *
    81  * @param[in] priority is the priority to test
    82  *
    83  * @retval TRUE The priority is valid.
    84  * @retval FALSE The priority is invalid.
     70 * @retval true The priority is valid.
     71 * @retval false Otherwise.
    8572 */
    8673bool _POSIX_Priority_Is_valid(
    87   int priority
     74  const Scheduler_Control *scheduler,
     75  int                      priority
    8876);
    8977
    9078/**
    91  * @brief Convert POSIX priority to SuperCore priority.
     79 * @brief Converts the SuperCore priority to the corresponding POSIX API
     80 * priority.
    9281 *
    93  * This method converts a POSIX API priority into onto the corresponding
    94  * SuperCore value.
     82 * @param[in] scheduler The scheduler instance.
     83 * @param[in] priority The SuperCore priority to convert.
    9584 *
    96  * @param[in] priority is the POSIX API priority.
    97  *
    98  * @return This method returns the corresponding SuperCore priority.
     85 * @return The corresponding POSIX API priority.
    9986 */
    100 RTEMS_INLINE_ROUTINE Priority_Control _POSIX_Priority_To_core(
    101   int priority
     87RTEMS_INLINE_ROUTINE int _POSIX_Priority_From_core(
     88  const Scheduler_Control *scheduler,
     89  Priority_Control         priority
    10290)
    10391{
    104   return (Priority_Control) (POSIX_SCHEDULER_MAXIMUM_PRIORITY - priority + 1);
    105 }
    106 
    107 /**
    108  * @brief Convert SuperCore priority To POSIX priority.
    109  *
    110  * This method converts a SuperCore priority into onto the corresponding
    111  * POSIX API value.
    112  *
    113  * @param[in] priority is the POSIX API priority.
    114  *
    115  * @return This method returns the corresponding POSIX priority.
    116  */
    117 RTEMS_INLINE_ROUTINE int _POSIX_Priority_From_core(
    118   Priority_Control priority
    119 )
    120 {
    121   return (POSIX_SCHEDULER_MAXIMUM_PRIORITY - priority + 1);
     92  return (int) ( scheduler->maximum_priority - priority );
    12293}
    12394
  • cpukit/posix/src/mutexgetprioceiling.c

    reec08ef r5a32c48  
    4747
    4848  *prioceiling = _POSIX_Priority_From_core(
     49    &_Scheduler_Table[ 0 ],
    4950    the_mutex->Mutex.priority_ceiling
    5051  );
  • cpukit/posix/src/mutexinit.c

    reec08ef r5a32c48  
    2121#include <rtems/posix/muteximpl.h>
    2222#include <rtems/posix/priorityimpl.h>
     23#include <rtems/score/schedulerimpl.h>
    2324
    2425/**
     
    116117    }
    117118
    118     if ( !_POSIX_Priority_Is_valid( prio_ceiling ) ) {
     119    if ( !_POSIX_Priority_Is_valid( scheduler, prio_ceiling ) ) {
    119120      return EINVAL;
    120121    }
    121122
    122     priority = _POSIX_Priority_To_core( prio_ceiling );
     123    priority = _POSIX_Priority_To_core( scheduler, prio_ceiling );
    123124  }
    124125
  • cpukit/posix/src/mutexsetprioceiling.c

    reec08ef r5a32c48  
    3232)
    3333{
    34   register POSIX_Mutex_Control *the_mutex;
    35   Priority_Control              the_priority;
    36   int                           error;
     34  POSIX_Mutex_Control     *the_mutex;
     35  const Scheduler_Control *scheduler;
     36  int                      error;
     37  int                      unlock_error;
    3738
    3839  if ( !old_ceiling )
    3940    return EINVAL;
    40 
    41   if ( !_POSIX_Priority_Is_valid( prioceiling ) )
    42     return EINVAL;
    43 
    44   the_priority = _POSIX_Priority_To_core( prioceiling );
    4541
    4642  /*
     
    5753  _Assert( the_mutex != NULL );
    5854
     55  scheduler = &_Scheduler_Table[ 0 ];
     56
    5957  *old_ceiling = _POSIX_Priority_From_core(
     58    scheduler,
    6059    the_mutex->Mutex.priority_ceiling
    6160  );
    62   the_mutex->Mutex.priority_ceiling = the_priority;
    6361
    64   error = pthread_mutex_unlock( mutex );
    65   _Assert( error == 0 );
    66   (void) error;
    67   return 0;
     62  if ( _POSIX_Priority_Is_valid( scheduler, prioceiling ) ) {
     63    Priority_Control priority;
     64
     65    priority = _POSIX_Priority_To_core( scheduler, prioceiling );
     66    the_mutex->Mutex.priority_ceiling = priority;
     67
     68    error = 0;
     69  } else {
     70    error = EINVAL;
     71  }
     72
     73  unlock_error = pthread_mutex_unlock( mutex );
     74  _Assert( unlock_error == 0 );
     75  (void) unlock_error;
     76  return error;
    6877}
  • cpukit/posix/src/psxpriorityisvalid.c

    reec08ef r5a32c48  
    3131
    3232bool _POSIX_Priority_Is_valid(
    33   int priority
     33  const Scheduler_Control *scheduler,
     34  int                      priority
    3435)
    3536{
    36   return ((priority >= POSIX_SCHEDULER_MINIMUM_PRIORITY) &&
    37           (priority <= POSIX_SCHEDULER_MAXIMUM_PRIORITY));
    38 
     37  return priority >= POSIX_SCHEDULER_MINIMUM_PRIORITY
     38    && (Priority_Control) priority < scheduler->maximum_priority;
    3939}
    4040
  • cpukit/posix/src/pthread.c

    reec08ef r5a32c48  
    3838#include <rtems/posix/config.h>
    3939#include <rtems/posix/keyimpl.h>
     40#include <rtems/score/assert.h>
    4041#include <rtems/score/cpusetimpl.h>
    41 #include <rtems/score/assert.h>
     42#include <rtems/score/schedulerimpl.h>
    4243
    4344Thread_Information _POSIX_Threads_Information;
     
    183184  _POSIX_Threads_Initialize_attributes( &api->Attributes );
    184185  api->Attributes.schedparam.sched_priority = _POSIX_Priority_From_core(
     186    _Scheduler_Get_own( created ),
    185187    created->current_priority
    186188  );
  • cpukit/posix/src/pthreadcreate.c

    reec08ef r5a32c48  
    7171  Thread_Control                     *the_thread;
    7272  Thread_Control                     *executing;
     73  const Scheduler_Control            *scheduler;
    7374  POSIX_API_Control                  *api;
    7475  int                                 schedpolicy = SCHED_RR;
     
    152153  }
    153154
    154   if ( !_POSIX_Priority_Is_valid( low_prio ) ) {
    155     return EINVAL;
    156   }
    157 
    158   if ( !_POSIX_Priority_Is_valid( high_prio ) ) {
    159     return EINVAL;
    160   }
    161 
    162   core_low_prio = _POSIX_Priority_To_core( low_prio );
    163   core_high_prio = _POSIX_Priority_To_core( high_prio );
     155  scheduler = _Scheduler_Get_own( executing );
     156
     157  if ( !_POSIX_Priority_Is_valid( scheduler, low_prio ) ) {
     158    return EINVAL;
     159  }
     160
     161  if ( !_POSIX_Priority_Is_valid( scheduler, high_prio ) ) {
     162    return EINVAL;
     163  }
     164
     165  core_low_prio = _POSIX_Priority_To_core( scheduler, low_prio );
     166  core_high_prio = _POSIX_Priority_To_core( scheduler, high_prio );
    164167
    165168#if defined(RTEMS_SMP)
  • cpukit/posix/src/pthreadgetschedparam.c

    reec08ef r5a32c48  
    2727#include <rtems/posix/pthreadimpl.h>
    2828#include <rtems/posix/priorityimpl.h>
     29#include <rtems/score/schedulerimpl.h>
    2930#include <rtems/score/threadimpl.h>
    3031
     
    3536)
    3637{
    37   Thread_Control    *the_thread;
    38   ISR_lock_Context   lock_context;
    39   POSIX_API_Control *api;
     38  Thread_Control          *the_thread;
     39  ISR_lock_Context         lock_context;
     40  POSIX_API_Control       *api;
     41  const Scheduler_Control *scheduler;
     42  Priority_Control         priority;
    4043
    4144  if ( policy == NULL || param == NULL ) {
     
    5558  *policy = api->Attributes.schedpolicy;
    5659  *param  = api->Attributes.schedparam;
    57   param->sched_priority = _POSIX_Priority_From_core(
    58     the_thread->real_priority
    59   );
     60
     61  scheduler = _Scheduler_Get_own( the_thread );
     62  priority = the_thread->real_priority;
    6063
    6164  _Thread_Lock_release_default( the_thread, &lock_context );
     65
     66  param->sched_priority = _POSIX_Priority_From_core( scheduler, priority );
    6267  return 0;
    6368}
  • cpukit/posix/src/pthreadsetschedparam.c

    reec08ef r5a32c48  
    2929#include <rtems/posix/priorityimpl.h>
    3030#include <rtems/score/threadimpl.h>
     31#include <rtems/score/schedulerimpl.h>
    3132
    3233typedef struct {
     
    4647  POSIX_Set_sched_param_context *context;
    4748  const struct sched_param      *param;
     49  const Scheduler_Control       *scheduler;
    4850  POSIX_API_Control             *api;
    4951  int                            low_prio;
     
    5557  context = arg;
    5658  param = context->param;
     59  scheduler = _Scheduler_Get_own( the_thread );
    5760
    5861  if ( context->policy == SCHED_SPORADIC ) {
     
    6467  }
    6568
    66   if ( !_POSIX_Priority_Is_valid( low_prio ) ) {
     69  if ( !_POSIX_Priority_Is_valid( scheduler, low_prio ) ) {
    6770    context->error = EINVAL;
    6871    return false;
    6972  }
    7073
    71   if ( !_POSIX_Priority_Is_valid( high_prio ) ) {
     74  if ( !_POSIX_Priority_Is_valid( scheduler, high_prio ) ) {
    7275    context->error = EINVAL;
    7376    return false;
    7477  }
    7578
    76   core_low_prio = _POSIX_Priority_To_core( low_prio );
    77   core_high_prio = _POSIX_Priority_To_core( high_prio );
     79  core_low_prio = _POSIX_Priority_To_core( scheduler, low_prio );
     80  core_high_prio = _POSIX_Priority_To_core( scheduler, high_prio );
    7881
    7982  *new_priority_p = core_high_prio;
  • cpukit/posix/src/pthreadsetschedprio.c

    reec08ef r5a32c48  
    1717#include <rtems/posix/threadsup.h>
    1818#include <rtems/score/threadimpl.h>
     19#include <rtems/score/schedulerimpl.h>
    1920
    2021typedef struct {
     
    3132  POSIX_Set_sched_prio_context *context;
    3233  int                           prio;
     34  const Scheduler_Control      *scheduler;
    3335  POSIX_API_Control            *api;
    3436  Priority_Control              current_priority;
     
    3739  context = arg;
    3840  prio = context->prio;
     41  scheduler = _Scheduler_Get_own( the_thread );
    3942
    40   if ( !_POSIX_Priority_Is_valid( prio ) ) {
     43  if ( !_POSIX_Priority_Is_valid( scheduler, prio ) ) {
    4144    context->error = EINVAL;
    4245    return false;
    4346  }
    4447
    45   new_priority = _POSIX_Priority_To_core( prio );
     48  new_priority = _POSIX_Priority_To_core( scheduler, prio );
    4649  *new_priority_p = new_priority;
    4750
Note: See TracChangeset for help on using the changeset viewer.