source: rtems/cpukit/rtems/src/ratemongetstatus.c @ eaef4657

4.104.115
Last change on this file since eaef4657 was 9dc2c8d, checked in by Joel Sherrill <joel.sherrill@…>, on 12/10/08 at 22:13:28

2008-12-10 Joel Sherrill <joel.sherrill@…>

  • rtems/include/rtems/rtems/ratemon.h, rtems/include/rtems/rtems/types.h, rtems/src/ratemongetstatistics.c, rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c, rtems/src/ratemonreportstatistics.c, score/include/rtems/score/thread.h, score/src/coretodgetuptime.c: Make all Thread and Period Statistics use publicly defined types. Do not leak the SuperCore? Timestamp type through the APIs.
  • 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  #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
56      defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
57    Timestamp_Control            uptime;
58    Timestamp_Control            temp;
59  #endif
60
61  if ( !status )
62    return RTEMS_INVALID_ADDRESS;
63
64  the_period = _Rate_monotonic_Get( id, &location );
65  switch ( location ) {
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          _Timespec_Set_to_zero( &status->since_last_period );
74        #else
75          status->since_last_period = 0;
76        #endif
77        #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
78          _Timespec_Set_to_zero( &status->executed_since_last_period );
79        #else
80          status->executed_since_last_period = 0;
81        #endif
82      } else {
83        /*
84         *  Both nanoseconds granularity options have to know the uptime.
85         *  This lets them share one single invocation of _TOD_Get_uptime().
86         */
87        #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
88            defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
89          _TOD_Get_uptime( &uptime );
90        #endif
91
92        #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
93          _Timestamp_Subtract( &the_period->time_at_period, &uptime, &temp );
94          _Timestamp_To_timespec( &temp, &status->since_last_period );
95        #else
96          status->since_last_period =
97            _Watchdog_Ticks_since_boot - the_period->time_at_period;
98        #endif
99
100        #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
101          _Timestamp_Subtract(
102            &_Thread_Time_of_last_context_switch,
103            &uptime,
104            &temp
105          );
106          _Timestamp_To_timespec( &temp, &status->executed_since_last_period );
107        #else
108          status->executed_since_last_period =
109            the_period->owner->cpu_time_used -
110            the_period->owner_executed_at_period;
111        #endif
112      }
113
114      _Thread_Enable_dispatch();
115      return RTEMS_SUCCESSFUL;
116
117#if defined(RTEMS_MULTIPROCESSING)
118    case OBJECTS_REMOTE:            /* should never return this */
119#endif
120    case OBJECTS_ERROR:
121      break;
122  }
123
124  return RTEMS_INVALID_ID;
125}
Note: See TracBrowser for help on using the repository browser.