1 | /* |
---|
2 | * Rate Monotonic Manager -- Get Status |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2009. |
---|
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 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
---|
27 | #include <rtems/score/timespec.h> |
---|
28 | #endif |
---|
29 | |
---|
30 | /*PAGE |
---|
31 | * |
---|
32 | * rtems_rate_monotonic_get_status |
---|
33 | * |
---|
34 | * This directive allows a thread to obtain status information on a |
---|
35 | * period. |
---|
36 | * |
---|
37 | * Input parameters: |
---|
38 | * id - rate monotonic id |
---|
39 | * status - pointer to status control block |
---|
40 | * |
---|
41 | * Output parameters: |
---|
42 | * RTEMS_SUCCESSFUL - if successful |
---|
43 | * error code - if unsuccessful |
---|
44 | * |
---|
45 | */ |
---|
46 | |
---|
47 | rtems_status_code rtems_rate_monotonic_get_status( |
---|
48 | Objects_Id id, |
---|
49 | rtems_rate_monotonic_period_status *status |
---|
50 | ) |
---|
51 | { |
---|
52 | Thread_CPU_usage_t executed; |
---|
53 | Objects_Locations location; |
---|
54 | Rate_monotonic_Period_time_t since_last_period; |
---|
55 | Rate_monotonic_Control *the_period; |
---|
56 | bool valid_status; |
---|
57 | |
---|
58 | if ( !status ) |
---|
59 | return RTEMS_INVALID_ADDRESS; |
---|
60 | |
---|
61 | the_period = _Rate_monotonic_Get( id, &location ); |
---|
62 | switch ( location ) { |
---|
63 | |
---|
64 | case OBJECTS_LOCAL: |
---|
65 | status->owner = the_period->owner->Object.id; |
---|
66 | status->state = the_period->state; |
---|
67 | |
---|
68 | /* |
---|
69 | * If the period is inactive, there is no information. |
---|
70 | */ |
---|
71 | if ( status->state == RATE_MONOTONIC_INACTIVE ) { |
---|
72 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
---|
73 | _Timespec_Set_to_zero( &status->since_last_period ); |
---|
74 | _Timespec_Set_to_zero( &status->executed_since_last_period ); |
---|
75 | #else |
---|
76 | status->since_last_period = 0; |
---|
77 | status->executed_since_last_period = 0; |
---|
78 | #endif |
---|
79 | |
---|
80 | } 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 | |
---|
94 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
---|
95 | _Timestamp_To_timespec( |
---|
96 | &since_last_period, &status->since_last_period |
---|
97 | ); |
---|
98 | _Timestamp_To_timespec( |
---|
99 | &executed, &status->executed_since_last_period |
---|
100 | ); |
---|
101 | #else |
---|
102 | status->since_last_period = since_last_period; |
---|
103 | status->executed_since_last_period = executed; |
---|
104 | #endif |
---|
105 | } |
---|
106 | |
---|
107 | _Thread_Enable_dispatch(); |
---|
108 | return RTEMS_SUCCESSFUL; |
---|
109 | |
---|
110 | #if defined(RTEMS_MULTIPROCESSING) |
---|
111 | case OBJECTS_REMOTE: /* should never return this */ |
---|
112 | #endif |
---|
113 | case OBJECTS_ERROR: |
---|
114 | break; |
---|
115 | } |
---|
116 | |
---|
117 | return RTEMS_INVALID_ID; |
---|
118 | } |
---|