source: rtems/cpukit/rtems/src/ratemongetstatus.c @ 838167e

4.104.114.84.95
Last change on this file since 838167e was c3330a8, checked in by Joel Sherrill <joel.sherrill@…>, on 05/17/07 at 22:46:45

2007-05-17 Joel Sherrill <joel.sherrill@…>

  • ChangeLog?, configure.ac, libcsupport/src/times.c, libmisc/cpuuse/cpuuse.c, libmisc/stackchk/check.c, rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c, rtems/src/ratemonreportstatistics.c, rtems/src/ratemonresetall.c, rtems/src/ratemontimeout.c, score/Makefile.am, score/include/rtems/score/thread.h, score/include/rtems/score/timespec.h, score/src/threaddispatch.c, score/src/threadinitialize.c, score/src/threadtickletimeslice.c, score/src/timespecdivide.c: Add nanoseconds granularity to the rate monotonic period statistics and CPU usage statistics. This capability is enabled by default although may be conditionally disabled by the user. It could be too much overhead on small targets but it does not appear to be bad in early testing. Its impact on code size has not been evaluated either. It is possible that both forms of statistics gathering could be disabled with further tweaking of the conditional compilation.
  • score/src/timespecdividebyinteger.c: New file.
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  Rate Monotonic Manager -- Get Status
3 *
4 *  COPYRIGHT (c) 1989-2007.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/system.h>
19#include <rtems/rtems/status.h>
20#include <rtems/rtems/support.h>
21#include <rtems/score/isr.h>
22#include <rtems/score/object.h>
23#include <rtems/rtems/ratemon.h>
24#include <rtems/score/thread.h>
25
26#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
27    defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
28  #include <rtems/score/timespec.h>
29#endif
30
31/*PAGE
32 *
33 *  rtems_rate_monotonic_get_status
34 *
35 *  This directive allows a thread to obtain status information on a
36 *  period.
37 *
38 *  Input parameters:
39 *    id     - rate monotonic id
40 *    status - pointer to status control block
41 *
42 *  Output parameters:
43 *    RTEMS_SUCCESSFUL - if successful
44 *    error code        - if unsuccessful
45 *
46 */
47
48rtems_status_code rtems_rate_monotonic_get_status(
49  Objects_Id                           id,
50  rtems_rate_monotonic_period_status  *status
51)
52{
53  Objects_Locations              location;
54  Rate_monotonic_Control        *the_period;
55
56  if ( !status )
57    return RTEMS_INVALID_ADDRESS;
58
59  the_period = _Rate_monotonic_Get( id, &location );
60  switch ( location ) {
61    case OBJECTS_REMOTE:            /* should never return this */
62      return RTEMS_INTERNAL_ERROR;
63
64    case OBJECTS_ERROR:
65      return RTEMS_INVALID_ID;
66
67    case OBJECTS_LOCAL:
68      status->owner = ((the_period->owner) ? the_period->owner->Object.id : 0);
69      status->state = the_period->state;
70
71      if ( status->state == RATE_MONOTONIC_INACTIVE ) {
72        #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
73          status->since_last_period.tv_sec = 0;
74          status->since_last_period.tv_nsec = 0;
75        #else
76          status->ticks_since_last_period = 0;
77        #endif
78        #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
79          status->executed_since_last_period.tv_sec = 0;
80          status->executed_since_last_period.tv_nsec = 0;
81        #else
82          status->ticks_executed_since_last_period = 0;
83        #endif
84      } else {
85        /*
86         *  Both nanoseconds granularity options have to know the uptime.
87         *  This lets them share one single invocation of _TOD_Get_uptime().
88         */
89        #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
90            defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
91          struct timespec uptime;
92          _TOD_Get_uptime( &uptime );
93        #endif
94
95        #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
96          _Timespec_Subtract(
97            &the_period->time_at_period,
98            &uptime,
99            &status->since_last_period
100          );
101        #else
102          status->ticks_since_last_period =
103            _Watchdog_Ticks_since_boot - the_period->time_at_period;
104        #endif
105
106        #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
107          _Timespec_Subtract(
108            &_Thread_Time_of_last_context_switch,
109            &uptime,
110            &status->executed_since_last_period
111          );
112        #else
113          status->ticks_executed_since_last_period =
114            the_period->owner->ticks_executed -
115              the_period->owner_ticks_executed_at_period;
116        #endif
117      }
118
119      _Thread_Enable_dispatch();
120      return RTEMS_SUCCESSFUL;
121  }
122
123  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
124}
Note: See TracBrowser for help on using the repository browser.