Ticket #1462: pr1462-49.diff

File pr1462-49.diff, 8.6 KB (added by Joel Sherrill, on 10/30/09 at 16:55:39)

Minor update to posted patch.

  • cpukit/rtems/src/ratemonperiod.c

    ? cpukit/rtems/src/.ratemonperiod.c.swp
    RCS file: /usr1/CVS/rtems/cpukit/rtems/src/ratemonperiod.c,v
    retrieving revision 1.17.2.1
    diff -u -r1.17.2.1 ratemonperiod.c
     
    11/*
    22 *  Rate Monotonic Manager - Period Blocking and Status
    33 *
    4  *  COPYRIGHT (c) 1989-2007.
     4 *  COPYRIGHT (c) 1989-2009.
    55 *  On-Line Applications Research Corporation (OAR).
    66 *
    77 *  The license and distribution terms for this file may be
     
    2828  extern struct timespec _Thread_Time_of_last_context_switch;
    2929#endif
    3030
     31void _Rate_monotonic_Initiate_statistics(
     32  Rate_monotonic_Control *the_period
     33)
     34{
     35  Thread_Control *owning_thread = the_period->owner;
     36
     37  /*
     38   *  If any statistics are at nanosecond granularity, we need to
     39   *  obtain the uptime.
     40   */
     41  #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
     42      defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
     43
     44    struct timespec  uptime;
     45
     46    _TOD_Get_uptime( &uptime );
     47  #endif
     48
     49  /*
     50   *  Set the starting point and the CPU time used for the statistics.
     51   */
     52  #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
     53    the_period->time_at_period = uptime;
     54  #else
     55    the_period->time_at_period = _Watchdog_Ticks_since_boot;
     56  #endif
     57
     58  the_period->owner_executed_at_period = owning_thread->cpu_time_used;
     59
     60  /*
     61   *  If using nanosecond granularity for CPU Usage Statistics and the
     62   *  period's thread is currently executing, then we need to take into
     63   *  account how much time the executing thread has run since the last
     64   *  context switch.  When this routine is invoked from
     65   *  rtems_rate_monotonic_period, the owner will be the executing thread.
     66   *  When this routine is invoked from _Rate_monotonic_Timeout, it will not.
     67   */
     68  #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
     69    if (owning_thread == _Thread_Executing) {
     70
     71      rtems_thread_cpu_usage_t ran;
     72
     73      /*
     74       *  Adjust the CPU time used to account for the time since last
     75       *  context switch.
     76       */
     77      _Timespec_Subtract(
     78        &_Thread_Time_of_last_context_switch, &uptime, &ran
     79      );
     80
     81      _Timespec_Add_to( &the_period->owner_executed_at_period, &ran );
     82    }
     83  #endif
     84}
     85
    3186void _Rate_monotonic_Update_statistics(
    3287  Rate_monotonic_Control    *the_period
    3388)
     
    55110   */
    56111
    57112  /*
    58    *  Grab basic information
     113   *  Update the counts.
     114   */
     115
     116  stats = &the_period->Statistics;
     117  stats->count++;
     118
     119  if ( the_period->state == RATE_MONOTONIC_EXPIRED )
     120    stats->missed_count++;
     121
     122  /*
     123   *  Grab basic information for time statistics.
    59124   */
    60125
    61126  #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
     
    86151
    87152       /* executed = current cpu usage - value at start of period */
    88153      _Timespec_Subtract(
    89          &the_period->owner_executed_at_period,
    90          &used,
    91          &executed
     154         &the_period->owner_executed_at_period, &used, &executed
    92155      );
    93156    }
    94157  #else
     
    97160  #endif
    98161
    99162  /*
    100    *  Now update the statistics
    101    */
    102 
    103   stats = &the_period->Statistics;
    104   stats->count++;
    105 
    106 
    107   if ( the_period->state == RATE_MONOTONIC_EXPIRED )
    108     stats->missed_count++;
    109 
    110   /*
    111163   *  Update CPU time
    112164   */
    113165
     
    180232  ISR_Level                            level;
    181233
    182234  the_period = _Rate_monotonic_Get( id, &location );
    183   switch ( location ) {
    184235
     236  switch ( location ) {
    185237    case OBJECTS_LOCAL:
    186238      if ( !_Thread_Is_executing( the_period->owner ) ) {
    187239        _Thread_Enable_dispatch();
     
    207259      }
    208260
    209261      _ISR_Disable( level );
     262
    210263      switch ( the_period->state ) {
    211264        case RATE_MONOTONIC_INACTIVE: {
    212           #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
    213               defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
    214             struct timespec uptime;
    215           #endif
    216 
    217           /*
    218            *  No need to update statistics -- there are not a period active
    219            */
    220265
    221266          _ISR_Enable( level );
    222267
    223 
    224           #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
    225               defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
    226             _TOD_Get_uptime( &uptime );
    227           #endif
    228              
    229           #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
    230             /*
    231              * Since the statistics didn't update the starting time,
    232              * we do it here.
    233              */
    234             the_period->time_at_period = uptime;
    235           #else
    236             the_period->time_at_period = _Watchdog_Ticks_since_boot;
    237           #endif
    238 
    239           #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
    240             {
    241               rtems_thread_cpu_usage_t ran;
    242 
    243               the_period->owner_executed_at_period =
    244                 _Thread_Executing->cpu_time_used;
    245 
    246               /* How much time time since last context switch */
    247               _Timespec_Subtract(
    248                 &_Thread_Time_of_last_context_switch,
    249                 &uptime,
    250                 &ran
    251               );
    252 
    253               /* The thread had executed before the last context switch also.
    254                *   
    255                *     the_period->owner_executed_at_period += ran
    256                */
    257               _Timespec_Add_to( &the_period->owner_executed_at_period, &ran );
    258             }
    259           #else
    260             the_period->owner_executed_at_period =
    261               _Thread_Executing->cpu_time_used;
    262           #endif
     268          /*
     269           *  Baseline statistics information for the beginning of a period.
     270           */
     271          _Rate_monotonic_Initiate_statistics( the_period );
    263272
    264273          the_period->state = RATE_MONOTONIC_ACTIVE;
    265274          _Watchdog_Initialize(
     
    278287        case RATE_MONOTONIC_ACTIVE:
    279288
    280289          /*
    281            *  Update statistics from the concluding period
     290           *  Update statistics from the concluding period.
    282291           */
    283292          _Rate_monotonic_Update_statistics( the_period );
    284293
     
    287296           *  in the process of blocking on the period and that we
    288297           *  may be changing the length of the next period.
    289298           */
    290 
    291299          the_period->state = RATE_MONOTONIC_OWNER_IS_BLOCKING;
    292300          the_period->next_length = length;
    293301
     
    300308           *  Did the watchdog timer expire while we were actually blocking
    301309           *  on it?
    302310           */
    303 
    304311          _ISR_Disable( level );
    305312            local_state = the_period->state;
    306313            the_period->state = RATE_MONOTONIC_ACTIVE;
     
    310317           *  If it did, then we want to unblock ourself and continue as
    311318           *  if nothing happen.  The period was reset in the timeout routine.
    312319           */
    313 
    314320          if ( local_state == RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING )
    315321            _Thread_Clear_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD );
    316322
     
    319325          break;
    320326
    321327        case RATE_MONOTONIC_EXPIRED:
     328
    322329          /*
    323330           *  Update statistics from the concluding period
    324331           */
  • cpukit/rtems/src/ratemontimeout.c

    RCS file: /usr1/CVS/rtems/cpukit/rtems/src/ratemontimeout.c,v
    retrieving revision 1.9
    diff -u -r1.9 ratemontimeout.c
     
    11/*
    22 *  Rate Monotonic Manager -- Period End Timeout Handler
    33 *
    4  *  COPYRIGHT (c) 1989-2007.
     4 *  COPYRIGHT (c) 1989-2009.
    55 *  On-Line Applications Research Corporation (OAR).
    66 *
    77 *  The license and distribution terms for this file may be
     
    5151   *  When we get here, the Timer is already off the chain so we do not
    5252   *  have to worry about that -- hence no _Watchdog_Remove().
    5353   */
    54 
    5554  the_period = _Rate_monotonic_Get( id, &location );
    5655  switch ( location ) {
    5756
     
    6160            the_thread->Wait.id == the_period->Object.id ) {
    6261        _Thread_Unblock( the_thread );
    6362
     63        _Rate_monotonic_Initiate_statistics( the_period );
     64
    6465        _Watchdog_Insert_ticks( &the_period->Timer, the_period->next_length );
    6566      } else if ( the_period->state == RATE_MONOTONIC_OWNER_IS_BLOCKING ) {
    6667        the_period->state = RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING;
    6768
     69        _Rate_monotonic_Initiate_statistics( the_period );
     70
    6871        _Watchdog_Insert_ticks( &the_period->Timer, the_period->next_length );
    6972      } else
    7073        the_period->state = RATE_MONOTONIC_EXPIRED;