1 | /** |
---|
2 | * @file rtems/rtems/ratemon.h |
---|
3 | * |
---|
4 | * This include file contains all the constants, structures, and |
---|
5 | * prototypes associated with the Rate Monotonic Manager. This manager |
---|
6 | * provides facilities to implement threads which execute in a periodic |
---|
7 | * fashion. |
---|
8 | * |
---|
9 | * Directives provided are: |
---|
10 | * |
---|
11 | * - create a rate monotonic timer |
---|
12 | * - cancel a period |
---|
13 | * - delete a rate monotonic timer |
---|
14 | * - conclude current and start the next period |
---|
15 | * - obtain status information on a period |
---|
16 | */ |
---|
17 | |
---|
18 | /* COPYRIGHT (c) 1989-2009. |
---|
19 | * On-Line Applications Research Corporation (OAR). |
---|
20 | * |
---|
21 | * The license and distribution terms for this file may be |
---|
22 | * found in the file LICENSE in this distribution or at |
---|
23 | * http://www.rtems.com/license/LICENSE. |
---|
24 | * |
---|
25 | * $Id$ |
---|
26 | */ |
---|
27 | |
---|
28 | #ifndef _RTEMS_RTEMS_RATEMON_H |
---|
29 | #define _RTEMS_RTEMS_RATEMON_H |
---|
30 | |
---|
31 | /** |
---|
32 | * This constant is defined to extern most of the time when using |
---|
33 | * this header file. However by defining it to nothing, the data |
---|
34 | * declared in this header file can be instantiated. This is done |
---|
35 | * in a single per manager file. |
---|
36 | */ |
---|
37 | #ifndef RTEMS_RATEMON_EXTERN |
---|
38 | #define RTEMS_RATEMON_EXTERN extern |
---|
39 | #endif |
---|
40 | |
---|
41 | #include <rtems/bspIo.h> |
---|
42 | |
---|
43 | /** |
---|
44 | * @defgroup ClassicRateMon Classic API Rate Monotonic |
---|
45 | * |
---|
46 | * This encapsulates functionality related to the |
---|
47 | * Classic API Rate Monotonic Manager. |
---|
48 | */ |
---|
49 | /**@{*/ |
---|
50 | |
---|
51 | #ifdef __cplusplus |
---|
52 | extern "C" { |
---|
53 | #endif |
---|
54 | |
---|
55 | /* |
---|
56 | * The user can define this at configure time and go back to ticks |
---|
57 | * resolution. |
---|
58 | */ |
---|
59 | #if !defined(__RTEMS_USE_TICKS_RATE_MONOTONIC_STATISTICS__) |
---|
60 | /** |
---|
61 | * Enable the nanosecond accurate statistics |
---|
62 | * |
---|
63 | * When not defined, the older style tick accurate granularity |
---|
64 | * is used. |
---|
65 | */ |
---|
66 | #define RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS |
---|
67 | #endif |
---|
68 | |
---|
69 | /** |
---|
70 | * This is the type used to manage the rate monotonic timing |
---|
71 | * statistics. |
---|
72 | */ |
---|
73 | #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) |
---|
74 | typedef struct timespec rtems_rate_monotonic_period_time_t; |
---|
75 | #else |
---|
76 | typedef uint32_t rtems_rate_monotonic_period_time_t; |
---|
77 | #endif |
---|
78 | |
---|
79 | #include <rtems/score/object.h> |
---|
80 | #include <rtems/score/thread.h> |
---|
81 | #include <rtems/score/watchdog.h> |
---|
82 | #include <rtems/rtems/status.h> |
---|
83 | #include <rtems/rtems/support.h> |
---|
84 | |
---|
85 | #include <string.h> |
---|
86 | |
---|
87 | |
---|
88 | /** |
---|
89 | * The following enumerated type defines the states in which a |
---|
90 | * period may be. |
---|
91 | */ |
---|
92 | typedef enum { |
---|
93 | /** |
---|
94 | * This value indicates the period is off the watchdog chain, |
---|
95 | * and has never been initialized. |
---|
96 | */ |
---|
97 | RATE_MONOTONIC_INACTIVE, |
---|
98 | |
---|
99 | /** |
---|
100 | * This value indicates the period is on the watchdog chain, and |
---|
101 | * the owner is blocked waiting on it. |
---|
102 | */ |
---|
103 | RATE_MONOTONIC_OWNER_IS_BLOCKING, |
---|
104 | |
---|
105 | /** |
---|
106 | * This value indicates the period is on the watchdog chain, and |
---|
107 | * running. The owner should be executed or blocked waiting on |
---|
108 | * another object. |
---|
109 | */ |
---|
110 | RATE_MONOTONIC_ACTIVE, |
---|
111 | |
---|
112 | /** |
---|
113 | * This value indicates the period is on the watchdog chain, and |
---|
114 | * has expired. The owner should be blocked waiting for the next period. |
---|
115 | */ |
---|
116 | RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING, |
---|
117 | |
---|
118 | /** |
---|
119 | * This value indicates the period is off the watchdog chain, and |
---|
120 | * has expired. The owner is still executing and has taken too much |
---|
121 | * all time to complete this iteration of the period. |
---|
122 | */ |
---|
123 | RATE_MONOTONIC_EXPIRED |
---|
124 | } rtems_rate_monotonic_period_states; |
---|
125 | |
---|
126 | /** |
---|
127 | * The following constant is the interval passed to the rate_monontonic_period |
---|
128 | * directive to obtain status information. |
---|
129 | */ |
---|
130 | #define RTEMS_PERIOD_STATUS WATCHDOG_NO_TIMEOUT |
---|
131 | |
---|
132 | /** |
---|
133 | * The following defines the statistics kept on each period instance. |
---|
134 | */ |
---|
135 | typedef struct { |
---|
136 | /** This field contains the number of periods executed. */ |
---|
137 | uint32_t count; |
---|
138 | /** This field contains the number of periods missed. */ |
---|
139 | uint32_t missed_count; |
---|
140 | |
---|
141 | /** This field contains the least amount of CPU time used in a period. */ |
---|
142 | rtems_thread_cpu_usage_t min_cpu_time; |
---|
143 | /** This field contains the highest amount of CPU time used in a period. */ |
---|
144 | rtems_thread_cpu_usage_t max_cpu_time; |
---|
145 | /** This field contains the total amount of wall time used in a period. */ |
---|
146 | rtems_thread_cpu_usage_t total_cpu_time; |
---|
147 | |
---|
148 | /** This field contains the least amount of wall time used in a period. */ |
---|
149 | rtems_rate_monotonic_period_time_t min_wall_time; |
---|
150 | /** This field contains the highest amount of wall time used in a period. */ |
---|
151 | rtems_rate_monotonic_period_time_t max_wall_time; |
---|
152 | /** This field contains the total amount of CPU time used in a period. */ |
---|
153 | rtems_rate_monotonic_period_time_t total_wall_time; |
---|
154 | } rtems_rate_monotonic_period_statistics; |
---|
155 | |
---|
156 | /** |
---|
157 | * The following defines the period status structure. |
---|
158 | */ |
---|
159 | typedef struct { |
---|
160 | /** This is the Id of the thread using this period. */ |
---|
161 | Objects_Id owner; |
---|
162 | |
---|
163 | /** This is the current state of this period. */ |
---|
164 | rtems_rate_monotonic_period_states state; |
---|
165 | |
---|
166 | /** |
---|
167 | * This is the length of wall time that has passed since this period |
---|
168 | * was last initiated. If the period is expired or has not been initiated, |
---|
169 | * then this field has no meaning. |
---|
170 | */ |
---|
171 | rtems_rate_monotonic_period_time_t since_last_period; |
---|
172 | |
---|
173 | /** |
---|
174 | * This is the amount of CPU time that has been used since this period |
---|
175 | * was last initiated. If the period is expired or has not been initiated, |
---|
176 | * then this field has no meaning. |
---|
177 | */ |
---|
178 | rtems_thread_cpu_usage_t executed_since_last_period; |
---|
179 | } rtems_rate_monotonic_period_status; |
---|
180 | |
---|
181 | /** |
---|
182 | * The following structure defines the control block used to manage |
---|
183 | * each period. |
---|
184 | */ |
---|
185 | typedef struct { |
---|
186 | /** This field is the object management portion of a Period instance. */ |
---|
187 | Objects_Control Object; |
---|
188 | |
---|
189 | /** This is the timer used to provide the unblocking mechanism. */ |
---|
190 | Watchdog_Control Timer; |
---|
191 | |
---|
192 | /** This field indicates the current state of the period. */ |
---|
193 | rtems_rate_monotonic_period_states state; |
---|
194 | |
---|
195 | /** |
---|
196 | * This field contains the total CPU usage used while executing |
---|
197 | * the body of the loop that is executed each period. |
---|
198 | */ |
---|
199 | rtems_thread_cpu_usage_t owner_executed_at_period; |
---|
200 | |
---|
201 | /** |
---|
202 | * This field contains the total wall timer that passed while |
---|
203 | * executing the body of the loop that is executed each period. |
---|
204 | */ |
---|
205 | rtems_rate_monotonic_period_time_t time_at_period; |
---|
206 | |
---|
207 | /** |
---|
208 | * This field contains the length of the next period to be |
---|
209 | * executed. |
---|
210 | */ |
---|
211 | uint32_t next_length; |
---|
212 | |
---|
213 | /** |
---|
214 | * This field contains a pointer to the TCB for the thread |
---|
215 | * which owns and uses this period instance. |
---|
216 | */ |
---|
217 | Thread_Control *owner; |
---|
218 | |
---|
219 | /** |
---|
220 | * This field contains the statistics which are maintained |
---|
221 | * on each period. |
---|
222 | */ |
---|
223 | rtems_rate_monotonic_period_statistics Statistics; |
---|
224 | } Rate_monotonic_Control; |
---|
225 | |
---|
226 | /** |
---|
227 | * @brief Rate Monotonic Period Class Management Structure |
---|
228 | * |
---|
229 | * This instance of Objects_Information is used to manage the |
---|
230 | * set of rate monotonic period instances. |
---|
231 | */ |
---|
232 | RTEMS_RATEMON_EXTERN Objects_Information _Rate_monotonic_Information; |
---|
233 | |
---|
234 | /** |
---|
235 | * @brief Rate Monotonic Manager Initialization |
---|
236 | * |
---|
237 | * This routine performs the initialization necessary for this manager. |
---|
238 | */ |
---|
239 | void _Rate_monotonic_Manager_initialization( |
---|
240 | uint32_t maximum_periods |
---|
241 | ); |
---|
242 | |
---|
243 | /** |
---|
244 | * @brief rtems_rate_monotonic_create |
---|
245 | * |
---|
246 | * This routine implements the rate_monotonic_create directive. The |
---|
247 | * period will have the name name. It returns the id of the |
---|
248 | * created period in ID. |
---|
249 | */ |
---|
250 | rtems_status_code rtems_rate_monotonic_create( |
---|
251 | rtems_name name, |
---|
252 | Objects_Id *id |
---|
253 | ); |
---|
254 | |
---|
255 | /** |
---|
256 | * @brief rtems_rate_monotonic_ident |
---|
257 | * |
---|
258 | * This routine implements the rtems_rate_monotonic_ident directive. |
---|
259 | * This directive returns the period ID associated with name. |
---|
260 | * If more than one period is named name, then the period |
---|
261 | * to which the ID belongs is arbitrary. |
---|
262 | */ |
---|
263 | rtems_status_code rtems_rate_monotonic_ident( |
---|
264 | rtems_name name, |
---|
265 | Objects_Id *id |
---|
266 | ); |
---|
267 | |
---|
268 | /** |
---|
269 | * @brief rtems_rate_monotonic_cancel |
---|
270 | * |
---|
271 | * This routine implements the rtems_rate_monotonic_cancel directive. This |
---|
272 | * directive stops the period associated with ID from continuing to |
---|
273 | * run. |
---|
274 | */ |
---|
275 | rtems_status_code rtems_rate_monotonic_cancel( |
---|
276 | Objects_Id id |
---|
277 | ); |
---|
278 | |
---|
279 | /** |
---|
280 | * @brief rtems_rate_monotonic_delete |
---|
281 | * |
---|
282 | * This routine implements the rtems_rate_monotonic_delete directive. The |
---|
283 | * period indicated by ID is deleted. |
---|
284 | */ |
---|
285 | rtems_status_code rtems_rate_monotonic_delete( |
---|
286 | Objects_Id id |
---|
287 | ); |
---|
288 | |
---|
289 | /** |
---|
290 | * @brief rtems_rate_monotonic_get_status |
---|
291 | * |
---|
292 | * This routine implements the rtems_rate_monotonic_get_status directive. |
---|
293 | * Information about the period indicated by ID is returned. |
---|
294 | * |
---|
295 | */ |
---|
296 | rtems_status_code rtems_rate_monotonic_get_status( |
---|
297 | Objects_Id id, |
---|
298 | rtems_rate_monotonic_period_status *status |
---|
299 | ); |
---|
300 | |
---|
301 | /** |
---|
302 | * @brief rtems_rate_monotonic_get_statistics |
---|
303 | * |
---|
304 | * This routine implements the rtems_rate_monotonic_get_statistics directive. |
---|
305 | * Statistics gathered from the use of this period are returned. |
---|
306 | */ |
---|
307 | rtems_status_code rtems_rate_monotonic_get_statistics( |
---|
308 | Objects_Id id, |
---|
309 | rtems_rate_monotonic_period_statistics *statistics |
---|
310 | ); |
---|
311 | |
---|
312 | /** |
---|
313 | * @brief rtems_rate_monotonic_reset_statistics |
---|
314 | * |
---|
315 | * This directive allows a thread to reset the statistics information |
---|
316 | * on a specific period instance. |
---|
317 | */ |
---|
318 | rtems_status_code rtems_rate_monotonic_reset_statistics( |
---|
319 | Objects_Id id |
---|
320 | ); |
---|
321 | |
---|
322 | /** |
---|
323 | * @brief rtems_rate_monotonic_reset_all_statistics |
---|
324 | * |
---|
325 | * This directive allows a thread to reset the statistics information |
---|
326 | * on ALL period instances. |
---|
327 | */ |
---|
328 | void rtems_rate_monotonic_reset_all_statistics( void ); |
---|
329 | |
---|
330 | /** |
---|
331 | * @brief rtems_rate_monotonic_report_statistics |
---|
332 | * |
---|
333 | * This directive allows a thread to print the statistics information |
---|
334 | * on ALL period instances which have non-zero counts using printk. |
---|
335 | */ |
---|
336 | void rtems_rate_monotonic_report_statistics_with_plugin( |
---|
337 | void *context, |
---|
338 | rtems_printk_plugin_t print |
---|
339 | ); |
---|
340 | |
---|
341 | /** |
---|
342 | * @brief rtems_rate_monotonic_report_statistics |
---|
343 | * |
---|
344 | * This directive allows a thread to print the statistics information |
---|
345 | * on ALL period instances which have non-zero counts using printk. |
---|
346 | */ |
---|
347 | void rtems_rate_monotonic_report_statistics( void ); |
---|
348 | |
---|
349 | /** |
---|
350 | * @brief rtems_rate_monotonic_period |
---|
351 | * |
---|
352 | * This routine implements the rtems_rate_monotonic_period directive. When |
---|
353 | * length is non-zero, this directive initiates the period associated with |
---|
354 | * ID from continuing for a period of length. If length is zero, then |
---|
355 | * result is set to indicate the current state of the period. |
---|
356 | */ |
---|
357 | rtems_status_code rtems_rate_monotonic_period( |
---|
358 | Objects_Id id, |
---|
359 | rtems_interval length |
---|
360 | ); |
---|
361 | |
---|
362 | /** |
---|
363 | * @brief _Rate_monotonic_Timeout |
---|
364 | * |
---|
365 | * This routine is invoked when the period represented |
---|
366 | * by ID expires. If the thread which owns this period is blocked |
---|
367 | * waiting for the period to expire, then it is readied and the |
---|
368 | * period is restarted. If the owning thread is not waiting for the |
---|
369 | * period to expire, then the period is placed in the EXPIRED |
---|
370 | * state and not restarted. |
---|
371 | */ |
---|
372 | void _Rate_monotonic_Timeout( |
---|
373 | Objects_Id id, |
---|
374 | void *ignored |
---|
375 | ); |
---|
376 | |
---|
377 | /** |
---|
378 | * @brief _Rate_monotonic_Initiate_per_period_statistics( |
---|
379 | * |
---|
380 | * This routine is invoked when a period is initiated via an explicit |
---|
381 | * call to rtems_rate_monotonic_period for the period's first iteration |
---|
382 | * or from _Rate_monotonic_Timeout for period iterations 2-n. |
---|
383 | * |
---|
384 | * @param[in] the_period points to the period being operated upon. |
---|
385 | */ |
---|
386 | void _Rate_monotonic_Initiate_per_period_statistics( |
---|
387 | Rate_monotonic_Control *the_period |
---|
388 | ); |
---|
389 | |
---|
390 | /** |
---|
391 | * @brief _Rate_monotonic_Initiate_statistics( |
---|
392 | * |
---|
393 | * This routine is invoked when a period is initiated via an explicit |
---|
394 | * call to rtems_rate_monotonic_period for the period's first iteration |
---|
395 | * or from _Rate_monotonic_Timeout for period iterations 2-n. |
---|
396 | * |
---|
397 | * @param[in] the_period points to the period being operated upon. |
---|
398 | */ |
---|
399 | void _Rate_monotonic_Initiate_statistics( |
---|
400 | Rate_monotonic_Control *the_period |
---|
401 | ); |
---|
402 | |
---|
403 | /** |
---|
404 | * @brief _Rate_monotonic_Reset_wall_time_statistics |
---|
405 | * |
---|
406 | * This method resets the statistics information for a period instance. |
---|
407 | */ |
---|
408 | #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS |
---|
409 | #define _Rate_monotonic_Reset_wall_time_statistics( _the_period ) \ |
---|
410 | do { \ |
---|
411 | /* set the minimums to a large value */ \ |
---|
412 | (_the_period)->Statistics.min_wall_time.tv_sec = 0x7fffffff; \ |
---|
413 | (_the_period)->Statistics.min_wall_time.tv_nsec = 0x7fffffff; \ |
---|
414 | } while (0) |
---|
415 | #else |
---|
416 | #define _Rate_monotonic_Reset_wall_time_statistics( _the_period ) \ |
---|
417 | do { \ |
---|
418 | /* set the minimum to a large value */ \ |
---|
419 | (_the_period)->Statistics.min_wall_time = 0xffffffff; \ |
---|
420 | } while (0) |
---|
421 | #endif |
---|
422 | |
---|
423 | /** |
---|
424 | * @brief Rate_monotonic_Reset_cpu_use_statistics |
---|
425 | * |
---|
426 | * This helper method resets the period CPU usage statistics structure. |
---|
427 | */ |
---|
428 | #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS |
---|
429 | #define _Rate_monotonic_Reset_cpu_use_statistics( _the_period ) \ |
---|
430 | do { \ |
---|
431 | /* set the minimums to a large value */ \ |
---|
432 | (_the_period)->Statistics.min_cpu_time.tv_sec = 0x7fffffff; \ |
---|
433 | (_the_period)->Statistics.min_cpu_time.tv_nsec = 0x7fffffff; \ |
---|
434 | } while (0) |
---|
435 | #else |
---|
436 | #define _Rate_monotonic_Reset_cpu_use_statistics( _the_period ) \ |
---|
437 | do { \ |
---|
438 | /* set the minimum to a large value */ \ |
---|
439 | (_the_period)->Statistics.min_cpu_time = 0xffffffff; \ |
---|
440 | } while (0) |
---|
441 | #endif |
---|
442 | |
---|
443 | /** |
---|
444 | * @brief Rate_monotonic_Reset_statistics |
---|
445 | * |
---|
446 | * This helper method resets the period wall time statistics structure. |
---|
447 | */ |
---|
448 | #define _Rate_monotonic_Reset_statistics( _the_period ) \ |
---|
449 | do { \ |
---|
450 | memset( \ |
---|
451 | &(_the_period)->Statistics, \ |
---|
452 | 0, \ |
---|
453 | sizeof( rtems_rate_monotonic_period_statistics ) \ |
---|
454 | ); \ |
---|
455 | _Rate_monotonic_Reset_cpu_use_statistics( _the_period ); \ |
---|
456 | _Rate_monotonic_Reset_wall_time_statistics( _the_period ); \ |
---|
457 | } while (0) |
---|
458 | |
---|
459 | #ifndef __RTEMS_APPLICATION__ |
---|
460 | #include <rtems/rtems/ratemon.inl> |
---|
461 | #endif |
---|
462 | |
---|
463 | #ifdef __cplusplus |
---|
464 | } |
---|
465 | #endif |
---|
466 | |
---|
467 | /**@}*/ |
---|
468 | |
---|
469 | #endif |
---|
470 | /* end of include file */ |
---|