Changeset 2212a2ad in rtems


Ignore:
Timestamp:
Jun 24, 2009, 6:38:52 AM (11 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, master
Children:
40b905cc
Parents:
046f4715
Message:

2009-06-24 Joel Sherrill <joel.sherrill@…>

  • posix/Makefile.am, posix/include/rtems/posix/priority.h, posix/include/rtems/posix/pthread.h, posix/inline/rtems/posix/priority.inl, posix/src/killinfo.c, posix/src/pthread.c, posix/src/pthreadcreate.c, posix/src/pthreadsetschedparam.c: Various modifications to improve binary code coverage analysis. Some of these are to mark code as debug only. Some are to break conditional expressions into multiple lines. Some are to move inline methods that are not time critical into subroutines to make them easier to test. Inlining them multiple times means that their logic paths are spread across multiple methods. This explodes the test cases required.
  • posix/src/psxpriorityisvalid.c, posix/src/psxtransschedparam.c: New files.
Location:
cpukit
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r046f4715 r2212a2ad  
     12009-06-24      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * posix/Makefile.am, posix/include/rtems/posix/priority.h,
     4        posix/include/rtems/posix/pthread.h,
     5        posix/inline/rtems/posix/priority.inl, posix/src/killinfo.c,
     6        posix/src/pthread.c, posix/src/pthreadcreate.c,
     7        posix/src/pthreadsetschedparam.c: Various modifications to improve
     8        binary code coverage analysis. Some of these are to mark code as
     9        debug only. Some are to break conditional expressions into multiple
     10        lines. Some are to move inline methods that are not time critical
     11        into subroutines to make them easier to test. Inlining them multiple
     12        times means that their logic paths are spread across multiple
     13        methods. This explodes the test cases required.
     14        * posix/src/psxpriorityisvalid.c, posix/src/psxtransschedparam.c: New files.
     15
    1162009-06-18      Joel Sherrill <joel.sherrill@OARcorp.com>
    217
  • cpukit/posix/Makefile.am

    r046f4715 r2212a2ad  
    122122    src/pthreadattrgetinheritsched.c src/pthreadattrsetinheritsched.c \
    123123    src/pthreadattrgetscope.c src/pthreadattrsetscope.c \
    124     src/pthreadinitthreads.c
     124    src/pthreadinitthreads.c src/psxtransschedparam.c
    125125
    126126## PSIGNAL_C_FILES
     
    168168libposix_a_SOURCES += src/getitimer.c src/setitimer.c
    169169
     170## SUPPORT_C_FILES
     171libposix_a_SOURCES += src/psxpriorityisvalid.c
     172
    170173EXTRA_DIST += src/README.mqueue
    171174
  • cpukit/posix/include/rtems/posix/priority.h

    r046f4715 r2212a2ad  
    44
    55/*
    6  *  COPYRIGHT (c) 1989-2007.
     6 *  COPYRIGHT (c) 1989-2008.
    77 *  On-Line Applications Research Corporation (OAR).
    88 *
     
    1919#include <rtems/score/priority.h>
    2020
    21 /*
     21/**
    2222 *  1003.1b-1993,2.2.2.80 definition of priority, p. 19
    2323 *
     
    3535 *  we use the internal constant.
    3636 */
    37 
    3837#define POSIX_SCHEDULER_MAXIMUM_PRIORITY (PRIORITY_MAXIMUM - 1)
    3938
     39
     40/**
     41 *  This is the numerically least important POSIX priority.
     42 */
    4043#define POSIX_SCHEDULER_MINIMUM_PRIORITY (1)
    4144
    42 RTEMS_INLINE_ROUTINE bool _POSIX_Priority_Is_valid(
     45/**
     46 *  1003.1b-1993,2.2.2.80 definition of priority, p. 19
     47 *
     48 *  "Numerically higher values represent higher priorities."
     49 *
     50 *  Thus, RTEMS Core has priorities run in the opposite sense of the POSIX API.
     51 *
     52 *  @param[in] priority is the priority to test
     53 *
     54 *  @return This method returns true if the priority is valid and
     55 *          false otherwise.
     56 */
     57bool _POSIX_Priority_Is_valid(
    4358  int priority
    4459);
    4560
     61/**
     62 *  @brief Convert POSIX Priority To SuperCore Priority
     63 *
     64 *  This method converts a POSIX API priority into onto the corresponding
     65 *  SuperCore value.
     66 *
     67 *  @param[in] priority is the POSIX API priority.
     68 *
     69 *  @return This method returns the corresponding SuperCore priority.
     70 */
    4671RTEMS_INLINE_ROUTINE Priority_Control _POSIX_Priority_To_core(
    4772  int priority
    4873);
    4974
     75/**
     76 *  @brief Convert SuperCore Priority To POSIX Priority
     77 *
     78 *  This method converts a SuperCore priority into onto the corresponding
     79 *  POSIX API value.
     80 *
     81 *  @param[in] priority is the POSIX API priority.
     82 *
     83 *  @return This method returns the corresponding POSIX priority.
     84 */
    5085RTEMS_INLINE_ROUTINE int _POSIX_Priority_From_core(
    5186  Priority_Control priority
  • cpukit/posix/include/rtems/posix/pthread.h

    r046f4715 r2212a2ad  
    3737 *  this class of objects.
    3838 */
    39 
    4039POSIX_EXTERN Objects_Information  _POSIX_Threads_Information;
    4140
     41/**
     42 *  This variable contains the default POSIX Thread attributes.
     43 */
    4244extern const pthread_attr_t _POSIX_Threads_Default_attributes;
    4345
     
    5153extern void (*_POSIX_Threads_Initialize_user_threads_p)(void);
    5254
    53 /*
    54  *  _POSIX_Threads_Manager_initialization
    55  *
    56  *  DESCRIPTION:
     55/**
     56 *  @brief _POSIX_Threads_Manager_initialization
    5757 *
    5858 *  This routine performs the initialization necessary for this manager.
    5959 */
    60 
    6160void _POSIX_Threads_Manager_initialization(void);
    6261
    63 /*
    64  *  _POSIX_Threads_Allocate
    65  *
    66  *  DESCRIPTION:
     62/**
     63 *  @brief _POSIX_Threads_Allocate
    6764 *
    6865 *  This function allocates a pthread control block from
    6966 *  the inactive chain of free pthread control blocks.
     67 *
     68 *  @return This method returns a newly allocated thread.
    7069 */
    71 
    7270RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate( void );
    7371
    74 /*
    75  *  _POSIX_Threads_Free
    76  *
    77  *  DESCRIPTION:
     72/**
     73 *  @brief _POSIX_Threads_Free
    7874 *
    7975 *  This routine frees a pthread control block to the
    8076 *  inactive chain of free pthread control blocks.
     77 *
     78 *  @param[in] the_pthread is the thread to free
    8179 */
    82 
    8380RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free(
    8481  Thread_Control *the_pthread
    8582);
    8683
    87 /*
    88  *  _POSIX_Threads_Get
    89  *
    90  *  DESCRIPTION:
     84/**
     85 *  @brief _POSIX_Threads_Get
    9186 *
    9287 *  This function maps pthread IDs to pthread control blocks.
     
    9792 *  and the_pthread is undefined.  Otherwise, location is set
    9893 *  to OBJECTS_ERROR and the_pthread is undefined.
     94 *
     95 *  @param[in] id is the id to lookup
     96 *  @param[in] location points to the returned location value
     97 *
     98 *  @return This methods returns a pointer to the corresponding Thread_Control.
    9999 */
    100 
    101100RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Get(
    102101  pthread_t          id,
     
    104103);
    105104
    106 /*
    107  *  _POSIX_Threads_Is_null
    108  *
    109  *  DESCRIPTION:
     105/**
     106 *  @brief _POSIX_Threads_Is_null
    110107 *
    111108 *  This function returns TRUE if the_pthread is NULL and FALSE otherwise.
     109 *
     110 *  @param[in] the_pthread is the thread pointer to check.
     111 *
     112 *  @return This method returns true if the thread pointer is null.
    112113 */
    113 
    114114RTEMS_INLINE_ROUTINE bool _POSIX_Threads_Is_null(
    115115  Thread_Control *the_pthread
    116116);
    117117
    118 /*
    119  *  _POSIX_Threads_Sporadic_budget_callout
    120  *
    121  *  DESCRIPTION:
     118/**
     119 *  @brief _POSIX_Threads_Sporadic_budget_callout
    122120 *
    123121 *  This routine handles the sporadic scheduling algorithm.
     122 *
     123 *  @param[in] the_thread is the thread whose budget has been exceeded.
    124124 */
    125 
    126125void _POSIX_Threads_Sporadic_budget_callout(
    127126  Thread_Control *the_thread
    128127);
    129128
    130 /*
     129/**
    131130 *  _POSIX_Threads_Sporadic_budget_TSR
    132131 *
    133  *  DESCRIPTION:
     132 *  This routine supports the sporadic scheduling algorithm.
    134133 *
    135  *  This routine supports the sporadic scheduling algorithm.
     134 *  @param[in] the_thread is the thread whose budget has been exceeded.
    136135 */
    137 
    138136void _POSIX_Threads_Sporadic_budget_TSR(
    139137  Objects_Id      id,
    140138  void           *argument
     139);
     140
     141/**
     142 *  @brief Translate sched_param into SuperCore Terms
     143 *
     144 *  This method translates the POSIX API sched_param into the corresponding
     145 *  SuperCore settings.
     146 *
     147 *  @param[in] policy is the POSIX scheduling policy
     148 *  @param[in] param points to the scheduling parameter structure
     149 *  @param[in] budget_algorithm points to the output CPU Budget algorithm
     150 *  @param[in] budget_callout points to the output CPU Callout
     151 *
     152 *  @return This method returns 0 on success or a POSIX error code.
     153 */
     154int _POSIX_Thread_Translate_sched_param(
     155  int                                  policy,
     156  struct sched_param                  *param,
     157  Thread_CPU_budget_algorithms        *budget_algorithm,
     158  Thread_CPU_budget_algorithm_callout *budget_callout
    141159);
    142160
  • cpukit/posix/inline/rtems/posix/priority.inl

    r046f4715 r2212a2ad  
    44
    55/* 
    6  *  COPYRIGHT (c) 1989-2007.
     6 *  COPYRIGHT (c) 1989-2009.
    77 *  On-Line Applications Research Corporation (OAR).
    88 *
     
    2121#define _RTEMS_POSIX_PRIORITY_INL
    2222
    23 /*
    24  *  1003.1b-1993,2.2.2.80 definition of priority, p. 19
    25  *
    26  *  "Numerically higher values represent higher priorities."
    27  *
    28  *  Thus, RTEMS Core has priorities run in the opposite sense of the POSIX API.
    29  */
    30 
    31 RTEMS_INLINE_ROUTINE bool _POSIX_Priority_Is_valid(
    32   int priority
    33 )
    34 {
    35   return ((priority >= POSIX_SCHEDULER_MINIMUM_PRIORITY) &&
    36           (priority <= POSIX_SCHEDULER_MAXIMUM_PRIORITY));
    37 
    38 }
    39 
    4023RTEMS_INLINE_ROUTINE Priority_Control _POSIX_Priority_To_core(
    4124  int priority
  • cpukit/posix/src/killinfo.c

    r046f4715 r2212a2ad  
    187187    the_info = _Objects_Information_table[ the_api ][ 1 ];
    188188
    189     /*
    190      *  This cannot happen in the current (as of June 2009) implementation
    191      *  of initialization but at some point, the object information
    192      *  structure for a particular manager may not be installed.
    193      */
    194     if ( !the_info )
    195       continue;
     189    #if defined(RTEMS_DEBUG)
     190      /*
     191       *  This cannot happen in the current (as of June 2009) implementation
     192       *  of initialization but at some point, the object information
     193       *  structure for a particular manager may not be installed.
     194       */
     195      if ( !the_info )
     196        continue;
     197    #endif
    196198
    197199    maximum = the_info->maximum;
     
    218220      api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    219221
    220       if ( !api )
    221         continue;
     222      #if defined(RTEMS_DEBUG)
     223        if ( !api )
     224          continue;
     225      #endif
    222226
    223227      if ( !_POSIX_signals_Is_interested( api, mask ) )
  • cpukit/posix/src/pthread.c

    r046f4715 r2212a2ad  
    173173   *  If the thread is not a posix thread, then all posix signals are blocked
    174174   *  by default.
     175   *
     176   *  The check for class == 1 is debug.  Should never really happen.
    175177   */
    176178
    177179  /* XXX use signal constants */
    178180  api->signals_pending = 0;
    179   if ( _Objects_Get_API( created->Object.id ) == OBJECTS_POSIX_API &&
    180        _Objects_Get_class( created->Object.id ) == 1 ) {
     181  if ( _Objects_Get_API( created->Object.id ) == OBJECTS_POSIX_API
     182       #if defined(RTEMS_DEBUG)
     183         && _Objects_Get_class( created->Object.id ) == 1
     184       #endif
     185  ) {
    181186    executing_api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
    182187    api->signals_blocked = executing_api->signals_blocked;
  • cpukit/posix/src/pthreadcreate.c

    r046f4715 r2212a2ad  
    5555  struct sched_param                  schedparam;
    5656  Objects_Name                        name;
     57  int                                 rc;
    5758
    5859  if ( !start_routine )
     
    7475    return EINVAL;
    7576
    76 #if 0
    77   int  cputime_clock_allowed;  /* see time.h */
    78   rtems_set_errno_and_return_minus_one( ENOSYS );
    79 #endif
     77  #if 0
     78    int  cputime_clock_allowed;  /* see time.h */
     79    rtems_set_errno_and_return_minus_one( ENOSYS );
     80  #endif
    8081
    8182  /*
     
    8788   *  attributes structure.
    8889   */
    89 
    9090  switch ( the_attr->inheritsched ) {
    9191    case PTHREAD_INHERIT_SCHED:
     
    108108   *  contention (i.e. no system wide contention).
    109109   */
    110 
    111110  if ( the_attr->contentionscope != PTHREAD_SCOPE_PROCESS )
    112111    return ENOTSUP;
     
    115114   *  Interpret the scheduling parameters.
    116115   */
    117 
    118116  if ( !_POSIX_Priority_Is_valid( schedparam.sched_priority ) )
    119117    return EINVAL;
     
    124122   *  Set the core scheduling policy information.
    125123   */
    126 
    127   budget_callout = NULL;
    128   budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
    129 
    130   switch ( schedpolicy ) {
    131     case SCHED_OTHER:
    132       budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
    133       break;
    134 
    135     case SCHED_FIFO:
    136       budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
    137       break;
    138 
    139     case SCHED_RR:
    140       budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
    141       break;
    142 
    143     case SCHED_SPORADIC:
    144       budget_algorithm  = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
    145       budget_callout = _POSIX_Threads_Sporadic_budget_callout;
    146 
    147       if ( _Timespec_To_ticks( &schedparam.ss_replenish_period ) <
    148            _Timespec_To_ticks( &schedparam.ss_initial_budget ) )
    149         return EINVAL;
    150 
    151       if ( !_POSIX_Priority_Is_valid( schedparam.ss_low_priority ) )
    152         return EINVAL;
    153 
    154       break;
    155 
    156     default:
    157       return EINVAL;
    158   }
     124  rc = _POSIX_Thread_Translate_sched_param(
     125    schedpolicy,
     126    &schedparam,
     127    &budget_algorithm,
     128    &budget_callout
     129  );
     130  if ( rc )
     131    return rc;
    159132
    160133  /*
     
    162135   *  supports it.
    163136   */
    164 
    165 
    166 #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
    167   is_fp = true;
    168 #else
    169   is_fp = false;
    170 #endif
     137  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
     138    is_fp = true;
     139  #else
     140    is_fp = false;
     141  #endif
    171142
    172143  /*
     
    180151   *  NOTE:  Global threads are not currently supported.
    181152   */
    182 
    183153  the_thread = _POSIX_Threads_Allocate();
    184 
    185154  if ( !the_thread ) {
    186155    _RTEMS_Unlock_allocator();
     
    191160   *  Initialize the core thread for this task.
    192161   */
    193 
    194162  name.name_p = NULL;   /* posix threads don't have a name by default */
    195163  status = _Thread_Initialize(
     
    216184   *  finish initializing the per API structure
    217185   */
    218 
    219 
    220186  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    221187
     
    231197   *  NOTE:  Since the thread starts with all unblocked, this is necessary.
    232198   */
    233 
    234199  the_thread->do_post_task_switch_extension = true;
    235200
     
    237202   *  POSIX threads are allocated and started in one operation.
    238203   */
    239 
    240204  status = _Thread_Start(
    241205    the_thread,
     
    246210  );
    247211
     212  #if defined(RTEMS_DEBUG)
     213    /*
     214     *  _Thread_Start only fails if the thread was in the incorrect state
     215     * 
     216     *  NOTE: This can only happen if someone slips in and touches the
     217     *        thread while we are creating it.
     218     */
     219    if ( !status ) {
     220      _POSIX_Threads_Free( the_thread );
     221      _RTEMS_Unlock_allocator();
     222      return EINVAL;
     223    }
     224  #endif
     225
    248226  if ( schedpolicy == SCHED_SPORADIC ) {
    249227    _Watchdog_Insert_ticks(
     
    254232
    255233  /*
    256    *  _Thread_Start only fails if the thread was in the incorrect state
    257    * 
    258    *  NOTE: This can only happen if someone slips in and touches the
    259    *        thread while we are creating it.
    260    */
    261 
    262   if ( !status ) {
    263     _POSIX_Threads_Free( the_thread );
    264     _RTEMS_Unlock_allocator();
    265     return EINVAL;
    266   }
    267 
    268   /*
    269234   *  Return the id and indicate we successfully created the thread
    270235   */
    271 
    272236  *thread = the_thread->Object.id;
    273237
  • cpukit/posix/src/pthreadsetschedparam.c

    r046f4715 r2212a2ad  
    3737  Thread_CPU_budget_algorithm_callout  budget_callout;
    3838  Objects_Locations                    location;
     39  int                                  rc;
    3940
    4041  /*
    4142   *  Check all the parameters
    4243   */
    43 
    4444  if ( !param )
    4545    return EINVAL;
    4646
    47   if ( !_POSIX_Priority_Is_valid( param->sched_priority ) )
    48     return EINVAL;
    49 
    50   budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
    51   budget_callout = NULL;
    52 
    53   switch ( policy ) {
    54     case SCHED_OTHER:
    55       budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
    56       break;
    57 
    58     case SCHED_FIFO:
    59       budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
    60       break;
    61 
    62     case SCHED_RR:
    63       budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
    64       break;
    65 
    66     case SCHED_SPORADIC:
    67       budget_algorithm  = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
    68       budget_callout = _POSIX_Threads_Sporadic_budget_callout;
    69 
    70       if ( _Timespec_To_ticks( &param->ss_replenish_period ) <
    71            _Timespec_To_ticks( &param->ss_initial_budget ) )
    72         return EINVAL;
    73 
    74       if ( !_POSIX_Priority_Is_valid( param->ss_low_priority ) )
    75         return EINVAL;
    76 
    77       break;
    78 
    79     default:
    80       return EINVAL;
    81   }
     47  rc = _POSIX_Thread_Translate_sched_param(
     48    policy,
     49    param,
     50    &budget_algorithm,
     51    &budget_callout
     52  );
     53  if ( rc )
     54    return rc;
    8255
    8356  /*
    8457   *  Actually change the scheduling policy and parameters
    8558   */
    86 
    8759  the_thread = _POSIX_Threads_Get( thread, &location );
    8860  switch ( location ) {
Note: See TracChangeset for help on using the changeset viewer.