source: rtems/cpukit/rtems/include/rtems/rtems/ratemon.h @ 33c3b54d

4.104.115
Last change on this file since 33c3b54d was 33c3b54d, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/29/09 at 11:57:23

Whitespace removal.

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