Changeset c82835a in rtems


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

rtems: Rework RTEMS API to SuperCore? priority

Use same structure as POSIX API for thread priority conversion to/from
SuperCore?.

Files:
13 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/capture/capture.c

    r1a4eac5 rc82835a  
    366366void rtems_capture_record_task( rtems_tcb* tcb )
    367367{
    368   rtems_capture_task_record_t rec;
    369   void*                       ptr;
     368  rtems_capture_task_record_t  rec;
     369  void*                        ptr;
    370370  rtems_interrupt_lock_context lock_context;
    371371
     
    373373
    374374  rec.stack_size = tcb->Start.Initial_stack.size;
    375   rec.start_priority = _RTEMS_tasks_Priority_from_Core(
    376     tcb->Start.initial_priority
    377   );
     375  rec.start_priority = rtems_capture_task_start_priority (tcb);
    378376
    379377  rtems_interrupt_lock_acquire (&capture_lock_global, &lock_context);
  • cpukit/libmisc/capture/capture.h

    r1a4eac5 rc82835a  
    4848#include <rtems.h>
    4949#include <rtems/rtems/tasksimpl.h>
     50#include <rtems/score/schedulerimpl.h>
    5051
    5152/**
     
    738739rtems_capture_task_start_priority (rtems_tcb* tcb)
    739740{
    740   return _RTEMS_tasks_Priority_from_Core(
     741  return _RTEMS_Priority_From_core(
     742    _Scheduler_Get_own( tcb ),
    741743    tcb->Start.initial_priority
    742744  );
  • cpukit/rtems/include/rtems/rtems/tasksimpl.h

    r1a4eac5 rc82835a  
    2020#include <rtems/rtems/tasks.h>
    2121#include <rtems/score/objectimpl.h>
     22#include <rtems/score/scheduler.h>
    2223#include <rtems/score/threadimpl.h>
    2324
     
    7576
    7677/**
    77  *  @brief Converts an RTEMS API priority into a core priority.
     78 * @brief Converts the RTEMS API priority to the corresponding SuperCore
     79 * priority and validates it.
    7880 *
    79  *  This function converts an RTEMS API priority into a core priority.
     81 * The RTEMS API system priority is accepted as valid.
     82 *
     83 * @param[in] scheduler The scheduler instance.
     84 * @param[in] priority The RTEMS API priority to convert and validate.
     85 * @param[out] valid Indicates if the RTEMS API priority is valid and a
     86 *   corresponding SuperCore priority in the specified scheduler instance
     87 *   exists.
     88 *
     89 * @return The corresponding SuperCore priority.
    8090 */
    81 RTEMS_INLINE_ROUTINE Priority_Control _RTEMS_tasks_Priority_to_Core(
    82   rtems_task_priority   priority
     91RTEMS_INLINE_ROUTINE Priority_Control _RTEMS_Priority_To_core(
     92  const Scheduler_Control *scheduler,
     93  rtems_task_priority      priority,
     94  bool                    *valid
    8395)
    8496{
     97  *valid = ( priority <= scheduler->maximum_priority );
     98
    8599  return (Priority_Control) priority;
    86100}
    87101
    88102/**
    89  *  @brief Converts a core priority into an RTEMS API priority.
     103 * @brief Converts the SuperCore priority to the corresponding RTEMS API
     104 * priority.
    90105 *
    91  *  This function converts a core priority into an RTEMS API priority.
     106 * @param[in] scheduler The scheduler instance.
     107 * @param[in] priority The SuperCore priority to convert.
     108 *
     109 * @return The corresponding RTEMS API priority.
    92110 */
    93 RTEMS_INLINE_ROUTINE rtems_task_priority _RTEMS_tasks_Priority_from_Core (
    94   Priority_Control priority
     111RTEMS_INLINE_ROUTINE rtems_task_priority _RTEMS_Priority_From_core(
     112  const Scheduler_Control *scheduler,
     113  Priority_Control         priority
    95114)
    96115{
    97116  return (rtems_task_priority) priority;
    98 }
    99 
    100 /**
    101  *  @brief Checks whether the priority is a valid user task.
    102  *
    103  *  This function returns TRUE if the_priority is a valid user task priority
    104  *  and FALSE otherwise.
    105  */
    106 RTEMS_INLINE_ROUTINE bool _RTEMS_tasks_Priority_is_valid (
    107   rtems_task_priority the_priority
    108 )
    109 {
    110   return (  ( the_priority >= RTEMS_MINIMUM_PRIORITY ) &&
    111             ( the_priority <= RTEMS_MAXIMUM_PRIORITY ) );
    112117}
    113118
  • cpukit/rtems/src/semcreate.c

    r1a4eac5 rc82835a  
    2323#include <rtems/rtems/statusimpl.h>
    2424#include <rtems/rtems/tasksimpl.h>
     25#include <rtems/score/schedulerimpl.h>
    2526#include <rtems/score/sysstate.h>
    2627
     
    3637)
    3738{
    38   Semaphore_Control *the_semaphore;
    39   Thread_Control    *executing;
    40   Status_Control     status;
    41   rtems_attribute    maybe_global;
    42   rtems_attribute    mutex_with_protocol;
    43   Semaphore_Variant  variant;
     39  Semaphore_Control       *the_semaphore;
     40  Thread_Control          *executing;
     41  Status_Control           status;
     42  rtems_attribute          maybe_global;
     43  rtems_attribute          mutex_with_protocol;
     44  Semaphore_Variant        variant;
     45  const Scheduler_Control *scheduler;
     46  bool                     valid;
     47  Priority_Control         priority;
    4448
    4549  if ( !rtems_is_name_valid( name ) )
     
    123127#endif
    124128
    125   priority_ceiling = _RTEMS_tasks_Priority_to_Core( priority_ceiling );
    126129  executing = _Thread_Get_executing();
    127130
     
    155158      break;
    156159    case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
    157       _CORE_ceiling_mutex_Initialize(
    158         &the_semaphore->Core_control.Mutex,
    159         priority_ceiling
    160       );
    161 
    162       if ( count == 0 ) {
    163         Thread_queue_Context queue_context;
    164 
    165         _Thread_queue_Context_initialize( &queue_context );
    166         _ISR_lock_ISR_disable( &queue_context.Lock_context );
    167         _CORE_mutex_Acquire_critical(
    168           &the_semaphore->Core_control.Mutex.Recursive.Mutex,
    169           &queue_context
     160      scheduler = _Scheduler_Get_own( executing );
     161      priority = _RTEMS_Priority_To_core( scheduler, priority_ceiling, &valid );
     162
     163      if ( valid ) {
     164        _CORE_ceiling_mutex_Initialize(
     165          &the_semaphore->Core_control.Mutex,
     166          priority
    170167        );
    171         status = _CORE_ceiling_mutex_Set_owner(
    172           &the_semaphore->Core_control.Mutex,
    173           executing,
    174           &queue_context
    175         );
    176 
    177         if ( status != STATUS_SUCCESSFUL ) {
    178           _Thread_queue_Destroy( &the_semaphore->Core_control.Wait_queue );
     168
     169        if ( count == 0 ) {
     170          Thread_queue_Context queue_context;
     171
     172          _Thread_queue_Context_initialize( &queue_context );
     173          _ISR_lock_ISR_disable( &queue_context.Lock_context );
     174          _CORE_mutex_Acquire_critical(
     175            &the_semaphore->Core_control.Mutex.Recursive.Mutex,
     176            &queue_context
     177          );
     178          status = _CORE_ceiling_mutex_Set_owner(
     179            &the_semaphore->Core_control.Mutex,
     180            executing,
     181            &queue_context
     182          );
     183
     184          if ( status != STATUS_SUCCESSFUL ) {
     185            _Thread_queue_Destroy( &the_semaphore->Core_control.Wait_queue );
     186          }
     187        } else {
     188          status = STATUS_SUCCESSFUL;
    179189        }
    180190      } else {
    181         status = STATUS_SUCCESSFUL;
     191        status = STATUS_INVALID_PRIORITY;
    182192      }
    183193
     
    185195#if defined(RTEMS_SMP)
    186196    case SEMAPHORE_VARIANT_MRSP:
    187       status = _MRSP_Initialize(
    188         &the_semaphore->Core_control.MRSP,
    189         priority_ceiling,
    190         executing,
    191         count == 0
    192       );
     197      scheduler = _Scheduler_Get_own( executing );
     198      priority = _RTEMS_Priority_To_core( scheduler, priority_ceiling, &valid );
     199
     200      if ( valid ) {
     201        status = _MRSP_Initialize(
     202          &the_semaphore->Core_control.MRSP,
     203          priority,
     204          executing,
     205          count == 0
     206        );
     207      } else {
     208        status = STATUS_INVALID_PRIORITY;
     209      }
     210
    193211      break;
    194212#endif
  • cpukit/rtems/src/semsetpriority.c

    r1a4eac5 rc82835a  
    2222
    2323static rtems_status_code _Semaphore_Set_priority(
    24   Semaphore_Control    *the_semaphore,
    25   rtems_id              scheduler_id,
    26   rtems_task_priority   new_priority,
    27   rtems_task_priority  *old_priority_p,
    28   Thread_queue_Context *queue_context
     24  Semaphore_Control       *the_semaphore,
     25  const Scheduler_Control *scheduler,
     26  rtems_task_priority      new_priority,
     27  rtems_task_priority     *old_priority_p,
     28  Thread_queue_Context    *queue_context
    2929)
    3030{
    3131  rtems_status_code    sc;
    32   rtems_task_priority  old_priority;
     32  bool                 valid;
     33  Priority_Control     core_priority;
     34  Priority_Control     old_priority;
    3335#if defined(RTEMS_SMP)
    3436  MRSP_Control        *mrsp;
     
    3638#endif
    3739
    38   new_priority = _RTEMS_tasks_Priority_to_Core( new_priority );
     40  core_priority = _RTEMS_Priority_To_core( scheduler, new_priority, &valid );
     41  if ( new_priority != RTEMS_CURRENT_PRIORITY && !valid ) {
     42    return RTEMS_INVALID_PRIORITY;
     43  }
    3944
    4045  switch ( the_semaphore->variant ) {
     
    4853
    4954      if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
    50         the_semaphore->Core_control.Mutex.priority_ceiling = new_priority;
     55        the_semaphore->Core_control.Mutex.priority_ceiling = core_priority;
    5156      }
    5257
     
    6065    case SEMAPHORE_VARIANT_MRSP:
    6166      mrsp = &the_semaphore->Core_control.MRSP;
    62       scheduler_index = _Scheduler_Get_index_by_id( scheduler_id );
     67      scheduler_index = _Scheduler_Get_index( scheduler );
    6368
    6469      _MRSP_Acquire_critical( mrsp, queue_context );
     
    6772
    6873      if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
    69         _MRSP_Set_ceiling_priority( mrsp, scheduler_index, new_priority );
     74        _MRSP_Set_ceiling_priority( mrsp, scheduler_index, core_priority );
    7075      }
    7176
     
    8792  }
    8893
    89   *old_priority_p = _RTEMS_tasks_Priority_from_Core( old_priority );
     94  *old_priority_p = _RTEMS_Priority_From_core( scheduler, old_priority );
    9095
    9196  return sc;
     
    99104)
    100105{
    101   Semaphore_Control    *the_semaphore;
    102   Thread_queue_Context  queue_context;
    103 
    104   if ( new_priority != RTEMS_CURRENT_PRIORITY &&
    105        !_RTEMS_tasks_Priority_is_valid( new_priority ) ) {
    106     return RTEMS_INVALID_PRIORITY;
    107   }
     106  const Scheduler_Control *scheduler;
     107  Semaphore_Control       *the_semaphore;
     108  Thread_queue_Context     queue_context;
    108109
    109110  if ( old_priority == NULL ) {
     
    111112  }
    112113
    113   if ( !_Scheduler_Is_id_valid( scheduler_id ) ) {
     114  if ( !_Scheduler_Get_by_id( scheduler_id, &scheduler ) ) {
    114115    return RTEMS_INVALID_ID;
    115116  }
     
    129130  return _Semaphore_Set_priority(
    130131    the_semaphore,
    131     scheduler_id,
     132    scheduler,
    132133    new_priority,
    133134    old_priority,
  • cpukit/rtems/src/taskcreate.c

    r1a4eac5 rc82835a  
    3838{
    3939  Thread_Control          *the_thread;
     40  const Scheduler_Control *scheduler;
    4041  bool                     is_fp;
    4142#if defined(RTEMS_MULTIPROCESSING)
     
    4546  bool                     status;
    4647  rtems_attribute          the_attribute_set;
    47   Priority_Control         core_priority;
     48  bool                     valid;
     49  Priority_Control         priority;
    4850  RTEMS_API_Control       *api;
    4951  ASR_Information         *asr;
     
    8486
    8587  if ( !_Attributes_Is_system_task( the_attribute_set ) ) {
    86     if ( !_RTEMS_tasks_Priority_is_valid( initial_priority ) )
     88    if ( initial_priority == PRIORITY_MINIMUM ) {
    8789      return RTEMS_INVALID_PRIORITY;
    88   }
    89 
    90   core_priority = _RTEMS_tasks_Priority_to_Core( initial_priority );
     90    }
     91  }
     92
     93  scheduler = _Scheduler_Get_by_CPU_index( _SMP_Get_current_processor() );
     94
     95  priority = _RTEMS_Priority_To_core( scheduler, initial_priority, &valid );
     96  if ( !valid ) {
     97    return RTEMS_INVALID_PRIORITY;
     98  }
    9199
    92100#if defined(RTEMS_MULTIPROCESSING)
     
    137145    &_RTEMS_tasks_Information,
    138146    the_thread,
    139     _Scheduler_Get_by_CPU_index( _SMP_Get_current_processor() ),
     147    scheduler,
    140148    NULL,
    141149    stack_size,
    142150    is_fp,
    143     core_priority,
     151    priority,
    144152    _Modes_Is_preempt(initial_modes)   ? true : false,
    145153    _Modes_Is_timeslice(initial_modes) ?
  • cpukit/rtems/src/tasksetpriority.c

    r1a4eac5 rc82835a  
    2020
    2121#include <rtems/rtems/tasksimpl.h>
     22#include <rtems/score/schedulerimpl.h>
    2223#include <rtems/score/threadimpl.h>
     24
     25typedef struct {
     26  const Scheduler_Control *scheduler;
     27  rtems_task_priority      new_priority;
     28  Priority_Control         old_priority;
     29  rtems_status_code        status;
     30} RTEMS_tasks_Set_priority_context;
     31
     32static bool _RTEMS_tasks_Set_priority_filter(
     33  Thread_Control   *the_thread,
     34  Priority_Control *new_priority_p,
     35  void             *arg
     36)
     37{
     38  RTEMS_tasks_Set_priority_context *context;
     39  const Scheduler_Control          *scheduler;
     40  bool                              valid;
     41  Priority_Control                  current_priority;
     42  Priority_Control                  new_priority;
     43
     44  context = arg;
     45  scheduler = _Scheduler_Get_own( the_thread );
     46  current_priority = the_thread->current_priority;
     47
     48  context->scheduler = scheduler;
     49  context->old_priority = current_priority;
     50
     51  new_priority = _RTEMS_Priority_To_core(
     52    scheduler,
     53    context->new_priority,
     54    &valid
     55  );
     56
     57  *new_priority_p = new_priority;
     58
     59  if ( !valid ) {
     60    context->status = RTEMS_INVALID_PRIORITY;
     61    return false;
     62  }
     63
     64  the_thread->real_priority = new_priority;
     65  context->status = STATUS_SUCCESSFUL;
     66
     67  return _Thread_Priority_less_than( current_priority, new_priority )
     68    || !_Thread_Owns_resources( the_thread );
     69}
    2370
    2471rtems_status_code rtems_task_set_priority(
    2572  rtems_id             id,
    2673  rtems_task_priority  new_priority,
    27   rtems_task_priority *old_priority
     74  rtems_task_priority *old_priority_p
    2875)
    2976{
    30   Thread_Control   *the_thread;
    31   ISR_lock_Context  lock_context;
    32   Per_CPU_Control  *cpu_self;
     77  Thread_Control          *the_thread;
     78  ISR_lock_Context         lock_context;
     79  const Scheduler_Control *scheduler;
     80  Priority_Control         old_priority;
     81  rtems_status_code        status;
    3382
    34   if ( new_priority != RTEMS_CURRENT_PRIORITY &&
    35        !_RTEMS_tasks_Priority_is_valid( new_priority ) )
    36     return RTEMS_INVALID_PRIORITY;
    37 
    38   if ( !old_priority )
     83  if ( old_priority_p == NULL ) {
    3984    return RTEMS_INVALID_ADDRESS;
     85  }
    4086
    4187  the_thread = _Thread_Get( id, &lock_context );
     
    4389  if ( the_thread == NULL ) {
    4490#if defined(RTEMS_MULTIPROCESSING)
    45     return _RTEMS_tasks_MP_Set_priority( id, new_priority, old_priority );
     91    return _RTEMS_tasks_MP_Set_priority( id, new_priority, old_priority_p );
    4692#else
    4793    return RTEMS_INVALID_ID;
     
    4995  }
    5096
    51   cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
    52   _ISR_lock_ISR_enable( &lock_context );
     97  if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
     98    RTEMS_tasks_Set_priority_context  context;
     99    Per_CPU_Control                  *cpu_self;
    53100
    54   if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
    55     _Thread_Set_priority(
     101    cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
     102    _ISR_lock_ISR_enable( &lock_context );
     103
     104    context.new_priority = new_priority;
     105    _Thread_Change_priority(
    56106      the_thread,
    57       _RTEMS_tasks_Priority_to_Core( new_priority ),
    58       old_priority,
     107      0,
     108      &context,
     109      _RTEMS_tasks_Set_priority_filter,
    59110      false
    60111    );
    61     *old_priority = _RTEMS_tasks_Priority_from_Core( *old_priority );
     112
     113    _Thread_Dispatch_enable( cpu_self );
     114    scheduler = context.scheduler;
     115    old_priority = context.old_priority;
     116    status = context.status;
    62117  } else {
    63     *old_priority = _RTEMS_tasks_Priority_from_Core(
    64       the_thread->current_priority
    65     );
     118    _Thread_State_acquire_critical( the_thread, &lock_context );
     119    scheduler = _Scheduler_Get_own( the_thread );
     120    old_priority = the_thread->current_priority;
     121    _Thread_State_release( the_thread, &lock_context );
     122    status = RTEMS_SUCCESSFUL;
    66123  }
    67124
    68   _Thread_Dispatch_enable( cpu_self );
    69   return RTEMS_SUCCESSFUL;
     125  *old_priority_p = _RTEMS_Priority_From_core( scheduler, old_priority );
     126  return status;
    70127}
  • cpukit/rtems/src/timerserver.c

    r1a4eac5 rc82835a  
    154154  }
    155155
    156   /*
    157    *  Make sure the requested priority is valid.  The if is
    158    *  structured so we check it is invalid before looking for
    159    *  a specific invalid value as the default.
    160    */
    161   if ( !_RTEMS_tasks_Priority_is_valid( priority ) ) {
    162     if ( priority != RTEMS_TIMER_SERVER_DEFAULT_PRIORITY )
    163       return RTEMS_INVALID_PRIORITY;
     156  if ( priority == RTEMS_TIMER_SERVER_DEFAULT_PRIORITY ) {
    164157    priority = PRIORITY_PSEUDO_ISR;
    165158  }
  • cpukit/score/include/rtems/score/status.h

    r1a4eac5 rc82835a  
    8787  STATUS_INVALID_NUMBER =
    8888    STATUS_BUILD( STATUS_CLASSIC_INVALID_NUMBER, EINVAL ),
     89  STATUS_INVALID_PRIORITY =
     90    STATUS_BUILD( STATUS_CLASSIC_INVALID_PRIORITY, EINVAL ),
    8991  STATUS_MAXIMUM_COUNT_EXCEEDED =
    9092    STATUS_BUILD( STATUS_CLASSIC_INTERNAL_ERROR, EOVERFLOW ),
  • testsuites/sptests/sp51/init.c

    r1a4eac5 rc82835a  
    6262  TEST_BEGIN();
    6363
     64  puts( "Create semaphore - priority ceiling unlocked - invalid ceiling" );
     65  sc = rtems_semaphore_create(
     66    rtems_build_name( 'S', 'E', 'M', '1' ),
     67    0,
     68    RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY_CEILING | RTEMS_PRIORITY,
     69    UINT32_MAX,
     70    &mutex
     71  );
     72  fatal_directive_status(sc, RTEMS_INVALID_PRIORITY, "rtems_semaphore_create");
     73
    6474  puts( "Create semaphore - priority ceiling locked - violate ceiling" );
    6575  sc = rtems_semaphore_create(
  • testsuites/sptests/sp51/sp51.scn

    r1a4eac5 rc82835a  
    1 *** TEST 51 ***
     1*** BEGIN OF TEST SP 51 ***
     2Create semaphore - priority ceiling unlocked - invalid ceiling
    23Create semaphore - priority ceiling locked - violate ceiling
    34Create semaphore - priority ceiling unlocked
    45Obtain semaphore -- violate ceiling
    56Release semaphore we did not obtain
    6 *** END OF TEST 51 ***
     7*** END OF TEST SP 51 ***
  • testsuites/sptests/spmrsp01/init.c

    r1a4eac5 rc82835a  
    4646static void test_mrsp_create_errors(void)
    4747{
     48  rtems_status_code sc;
     49  rtems_id id;
     50
    4851  puts("test MrsP create errors");
     52
     53  sc = rtems_semaphore_create(
     54    rtems_build_name('M', 'R', 'S', 'P'),
     55    1,
     56    RTEMS_MULTIPROCESSOR_RESOURCE_SHARING
     57      | RTEMS_BINARY_SEMAPHORE,
     58    UINT32_MAX,
     59    &id
     60  );
     61  rtems_test_assert(sc == RTEMS_INVALID_PRIORITY);
    4962
    5063  create_not_defined(
  • testsuites/sptests/sptimer_err02/init.c

    r1a4eac5 rc82835a  
    6767
    6868  /* invalid priority */
    69   status = rtems_timer_initiate_server( 0, 0, 0 );
     69  status = rtems_timer_initiate_server( UINT32_MAX - 1, 0, 0 );
    7070  fatal_directive_status(
    7171    status,
Note: See TracChangeset for help on using the changeset viewer.