Changeset eb37f9d in rtems


Ignore:
Timestamp:
Dec 8, 2009, 11:05:30 PM (9 years ago)
Author:
Glenn Humphrey <glenn.humphrey@…>
Branches:
4.10, 4.11, master
Children:
7199b1d
Parents:
a7a9af76
Message:

2009-12-08 Glenn Humphrey <glenn.humphrey@…>

  • rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c: Factored out common code to ensure consistent behavior between rtems_rate_monotonic_get_status and rtems_rate_monotonic_report_statistics.
Location:
cpukit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    ra7a9af76 reb37f9d  
     12009-12-08      Glenn Humphrey <glenn.humphrey@OARcorp.com>
     2
     3        * rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemongetstatus.c,
     4        rtems/src/ratemonperiod.c: Factored out common code to ensure
     5        consistent behavior between rtems_rate_monotonic_get_status and
     6        rtems_rate_monotonic_report_statistics.
     7
    182009-12-07      Cindy Cicalese <cicalese@mitre.org>
    29
  • cpukit/rtems/include/rtems/rtems/ratemon.h

    ra7a9af76 reb37f9d  
    4848 *  This encapsulates functionality related to the
    4949 *  Classic API Rate Monotonic Manager.
     50 *
     51 *  Statistics are kept for each period and can be obtained or printed via
     52 *  API calls.  The statistics kept include minimum, maximum and average times
     53 *  for both cpu usage and wall time.  The statistics indicate the execution time
     54 *  used by the owning thread between successive calls to rtems_rate_monotonic_period.
    5055 */
    5156/**@{*/
     
    225230
    226231  /**
    227    * This field contains the total CPU usage used while executing
    228    * the body of the loop that is executed each period.
    229    */
    230   Thread_CPU_usage_t                      owner_executed_at_period;
    231 
    232   /**
    233    * This field contains the total wall timer that passed while
    234    * executing the body of the loop that is executed each period.
    235    */
    236   Rate_monotonic_Period_time_t            time_at_period;
    237 
    238   /**
    239232   * This field contains the length of the next period to be
    240233   * executed.
     
    249242
    250243  /**
    251    * This field contains the statistics which are maintained
    252    * on each period.
     244   * This field contains the cpu usage value of the owning thread when
     245   * the period was initiated.  It is used to compute the period's
     246   * statistics.
     247   */
     248  Thread_CPU_usage_t                      cpu_usage_period_initiated;
     249
     250  /**
     251   * This field contains the wall time value when the period
     252   * was initiated.  It is used to compute the period's statistics.
     253   */
     254  Rate_monotonic_Period_time_t            time_period_initiated;
     255
     256  /**
     257   * This field contains the statistics maintained for the period.
    253258   */
    254259  Rate_monotonic_Statistics               Statistics;
     
    286291 *
    287292 *  This routine implements the rtems_rate_monotonic_ident directive.
    288  *  This directive returns the period ID associated with name.
    289  *  If more than one period is named name, then the period
    290  *  to which the ID belongs is arbitrary.
     293 *  It returns the period ID associated with name.  If more than one period
     294 *  is named name, then the period to which the ID belongs is arbitrary.
    291295 */
    292296rtems_status_code rtems_rate_monotonic_ident(
     
    342346 *  @brief rtems_rate_monotonic_reset_statistics
    343347 *
    344  *  This directive allows a thread to reset the statistics information
     348 *  This routine allows a thread to reset the statistics information
    345349 *  on a specific period instance.
    346350 */
     
    352356 *  @brief rtems_rate_monotonic_reset_all_statistics
    353357 *
    354  *  This directive allows a thread to reset the statistics information
     358 *  This routine allows a thread to reset the statistics information
    355359 *  on ALL period instances.
    356360 */
     
    360364 *  @brief rtems_rate_monotonic_report_statistics
    361365 *
    362  *  This directive allows a thread to print the statistics information
     366 *  This routine allows a thread to print the statistics information
    363367 *  on ALL period instances which have non-zero counts using printk.
    364368 */
     
    371375 *  @brief rtems_rate_monotonic_report_statistics
    372376 *
    373  *  This directive allows a thread to print the statistics information
     377 *  This routine allows a thread to print the statistics information
    374378 *  on ALL period instances which have non-zero counts using printk.
    375379 */
     
    402406  Objects_Id  id,
    403407  void       *ignored
     408);
     409
     410/**
     411 *  @brief _Rate_monotonic_Get_status(
     412 *
     413 *  This routine is invoked to compute the elapsed wall time and cpu
     414 *  time for a period.
     415 *
     416 *  @param[in] the_period points to the period being operated upon.
     417 *  @param[out] wall_since_last_period is set to the wall time elapsed
     418 *              since the period was initiated.
     419 *  @param[out] cpu_since_last_period is set to the cpu time used by the
     420 *              owning thread since the period was initiated.
     421 *
     422 *  @return This routine returns true if the status can be determined
     423 *          and false otherwise.
     424 */
     425bool _Rate_monotonic_Get_status(
     426  Rate_monotonic_Control        *the_period,
     427  Rate_monotonic_Period_time_t  *wall_since_last_period,
     428  Thread_CPU_usage_t            *cpu_since_last_period
    404429);
    405430
  • cpukit/rtems/src/ratemongetstatus.c

    ra7a9af76 reb37f9d  
    5050)
    5151{
     52  Thread_CPU_usage_t             executed;
    5253  Objects_Locations              location;
     54  Rate_monotonic_Period_time_t   since_last_period;
    5355  Rate_monotonic_Control        *the_period;
    54   #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
    55     Timestamp_Control            uptime;
    56     Timestamp_Control            temp;
    57   #endif
     56  bool                           valid_status;
    5857
    5958  if ( !status )
     
    8079
    8180      } else {
     81
     82        /*
     83         *  Grab the current status.
     84         */
     85        valid_status =
     86          _Rate_monotonic_Get_status(
     87            the_period, &since_last_period, &executed
     88          );
     89        if (!valid_status) {
     90          _Thread_Enable_dispatch();
     91          return RTEMS_NOT_DEFINED;
     92        }
     93
    8294        #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
    83           _TOD_Get_uptime( &uptime );
    84           _Timestamp_Subtract( &the_period->time_at_period, &uptime, &temp );
    85           _Timestamp_To_timespec( &temp, &status->since_last_period );
    86           _Timestamp_Subtract(
    87             &_Thread_Time_of_last_context_switch,
    88             &uptime,
    89             &temp
     95          _Timestamp_To_timespec(
     96            &since_last_period, &status->since_last_period
    9097          );
    91           _Timestamp_To_timespec( &temp, &status->executed_since_last_period );
     98          _Timestamp_To_timespec(
     99            &executed, &status->executed_since_last_period
     100          );
    92101        #else
    93           status->since_last_period =
    94             _Watchdog_Ticks_since_boot - the_period->time_at_period;
    95           status->executed_since_last_period =
    96             the_period->owner->cpu_time_used -
    97             the_period->owner_executed_at_period;
     102          status->since_last_period = since_last_period;
     103          status->executed_since_last_period = executed;
    98104        #endif
    99105      }
  • cpukit/rtems/src/ratemonperiod.c

    ra7a9af76 reb37f9d  
    2424#include <rtems/score/thread.h>
    2525
     26bool _Rate_monotonic_Get_status(
     27  Rate_monotonic_Control        *the_period,
     28  Rate_monotonic_Period_time_t  *wall_since_last_period,
     29  Thread_CPU_usage_t            *cpu_since_last_period
     30)
     31{
     32  #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
     33    Timestamp_Control        uptime;
     34  #endif
     35    Thread_Control          *owning_thread = the_period->owner;
     36    Thread_CPU_usage_t       used;
     37
     38  /*
     39   *  Determine elapsed wall time since period initiated.
     40   */
     41  #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
     42    _TOD_Get_uptime( &uptime );
     43    _Timestamp_Subtract(
     44      &the_period->time_period_initiated, &uptime, wall_since_last_period
     45    );
     46  #else
     47    *wall_since_last_period =
     48      _Watchdog_Ticks_since_boot - the_period->time_period_initiated;
     49  #endif
     50
     51  /*
     52   *  Determine cpu usage since period initiated.
     53   */
     54  used = owning_thread->cpu_time_used;
     55
     56  #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
     57    if (owning_thread == _Thread_Executing) {
     58
     59      Thread_CPU_usage_t ran;
     60
     61      /* How much time time since last context switch */
     62      _Timestamp_Subtract(
     63        &_Thread_Time_of_last_context_switch, &uptime, &ran
     64      );
     65
     66      /* cpu usage += ran */
     67      _Timestamp_Add_to( &used, &ran );
     68
     69      /*
     70       *  The cpu usage info was reset while executing.  Can't
     71       *  determine a status.
     72       */
     73      if (_Timestamp_Less_than(&used, &the_period->cpu_usage_period_initiated))
     74        return false;
     75
     76       /* used = current cpu usage - cpu usage at start of period */
     77      _Timestamp_Subtract(
     78         &the_period->cpu_usage_period_initiated,
     79         &used,
     80         cpu_since_last_period
     81      );
     82    }
     83  #else
     84      /*
     85       *  The cpu usage info was reset while executing.  Can't
     86       *  determine a status.
     87       */
     88      if (used < the_period->cpu_usage_period_initiated)
     89        return false;
     90
     91      *cpu_since_last_period = used - the_period->cpu_usage_period_initiated;
     92  #endif
     93  return true;
     94}
     95
    2696void _Rate_monotonic_Initiate_statistics(
    2797  Rate_monotonic_Control *the_period
     
    43113   */
    44114  #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
    45     the_period->time_at_period = uptime;
    46   #else
    47     the_period->time_at_period = _Watchdog_Ticks_since_boot;
    48   #endif
    49 
    50   the_period->owner_executed_at_period = owning_thread->cpu_time_used;
     115    the_period->time_period_initiated = uptime;
     116  #else
     117    the_period->time_period_initiated = _Watchdog_Ticks_since_boot;
     118  #endif
     119
     120  the_period->cpu_usage_period_initiated = owning_thread->cpu_time_used;
    51121
    52122  /*
     
    71141      );
    72142
    73       _Timespec_Add_to( &the_period->owner_executed_at_period, &ran );
     143      _Timespec_Add_to( &the_period->cpu_usage_period_initiated, &ran );
    74144    }
    75145  #endif
     
    80150)
    81151{
    82   Rate_monotonic_Statistics      *stats;
    83152  Thread_CPU_usage_t              executed;
    84153  Rate_monotonic_Period_time_t    since_last_period;
    85 
    86   /*
    87    *  If using nanosecond statistics, we need to obtain the uptime.
    88    */
    89   #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
    90     Timestamp_Control  uptime;
    91 
    92     _TOD_Get_uptime( &uptime );
    93   #endif
     154  Rate_monotonic_Statistics      *stats;
     155  bool                            valid_status;
    94156
    95157  /*
     
    109171
    110172  /*
    111    *  Grab basic information for time statistics.
    112    */
    113   #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
    114     _Timespec_Subtract(
    115       &the_period->time_at_period,
    116       &uptime,
    117       &since_last_period
    118     );
    119   #else
    120     since_last_period = _Watchdog_Ticks_since_boot - the_period->time_at_period;
    121   #endif
    122 
    123   #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
    124     {
    125       Thread_CPU_usage_t ran, used;
    126 
    127       /* Grab CPU usage when the thread got switched in */
    128       used = _Thread_Executing->cpu_time_used;
    129 
    130       /* partial period, cpu usage info reset while executing.  Throw away */
    131       if (_Timestamp_Less_than( &used, &the_period->owner_executed_at_period))
    132         return;
    133 
    134       /* How much time time since last context switch */
    135       _Timestamp_Subtract(&_Thread_Time_of_last_context_switch, &uptime, &ran);
    136 
    137       /* executed += ran */
    138       _Timestamp_Add_to( &used, &ran );
    139 
    140        /* executed = current cpu usage - value at start of period */
    141       _Timestamp_Subtract(
    142          &the_period->owner_executed_at_period,
    143          &used,
    144          &executed
    145       );
    146     }
    147   #else
    148       /* partial period, cpu usage info reset while executing.  Throw away */
    149       if (the_period->owner->cpu_time_used <
    150           the_period->owner_executed_at_period)
    151         return;
    152       executed = the_period->owner->cpu_time_used -
    153         the_period->owner_executed_at_period;
    154   #endif
     173   *  Grab status for time statistics.
     174   */
     175  valid_status =
     176    _Rate_monotonic_Get_status( the_period, &since_last_period, &executed );
     177  if (!valid_status)
     178    return;
    155179
    156180  /*
Note: See TracChangeset for help on using the changeset viewer.