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 | |
---|
48 | rtems_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 | |
---|
62 | case OBJECTS_LOCAL: |
---|
63 | status->owner = ((the_period->owner) ? the_period->owner->Object.id : 0); |
---|
64 | status->state = the_period->state; |
---|
65 | |
---|
66 | if ( status->state == RATE_MONOTONIC_INACTIVE ) { |
---|
67 | #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS |
---|
68 | status->since_last_period.tv_sec = 0; |
---|
69 | status->since_last_period.tv_nsec = 0; |
---|
70 | #else |
---|
71 | status->ticks_since_last_period = 0; |
---|
72 | #endif |
---|
73 | #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS |
---|
74 | status->executed_since_last_period.tv_sec = 0; |
---|
75 | status->executed_since_last_period.tv_nsec = 0; |
---|
76 | #else |
---|
77 | status->ticks_executed_since_last_period = 0; |
---|
78 | #endif |
---|
79 | } else { |
---|
80 | /* |
---|
81 | * Both nanoseconds granularity options have to know the uptime. |
---|
82 | * This lets them share one single invocation of _TOD_Get_uptime(). |
---|
83 | */ |
---|
84 | #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \ |
---|
85 | defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS) |
---|
86 | struct timespec uptime; |
---|
87 | _TOD_Get_uptime( &uptime ); |
---|
88 | #endif |
---|
89 | |
---|
90 | #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS |
---|
91 | _Timespec_Subtract( |
---|
92 | &the_period->time_at_period, |
---|
93 | &uptime, |
---|
94 | &status->since_last_period |
---|
95 | ); |
---|
96 | #else |
---|
97 | status->ticks_since_last_period = |
---|
98 | _Watchdog_Ticks_since_boot - the_period->time_at_period; |
---|
99 | #endif |
---|
100 | |
---|
101 | #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS |
---|
102 | _Timespec_Subtract( |
---|
103 | &_Thread_Time_of_last_context_switch, |
---|
104 | &uptime, |
---|
105 | &status->executed_since_last_period |
---|
106 | ); |
---|
107 | #else |
---|
108 | status->ticks_executed_since_last_period = |
---|
109 | the_period->owner->ticks_executed - |
---|
110 | the_period->owner_ticks_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 | } |
---|