source: rtems/cpukit/rtems/include/rtems/rtems/ratemon.h @ 52adc808

4.115
Last change on this file since 52adc808 was 52adc808, checked in by Alex Ivanov <alexivanov97@…>, on 12/02/12 at 16:03:09

score misc: Clean up Doxygen #12 (GCI 2012)

This patch is a task from GCI 2012 which improves the Doxygen
comments in the RTEMS source.

http://www.google-melange.com/gci/task/view/google/gci2012/8025203

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