source: rtems/cpukit/rtems/include/rtems/rtems/ratemon.h @ 300eaad

5
Last change on this file since 300eaad was 300eaad, checked in by Sebastian Huber <sebastian.huber@…>, on 03/21/16 at 09:41:31

rtems: Delete Rate_monotonic_Period_time_t

Variables with this type directly used the _Timestamp_*() functions.

  • Property mode set to 100644
File size: 12.5 KB
Line 
1/**
2 * @file rtems/rtems/ratemon.h
3 *
4 * @defgroup ClassicRateMon Rate Monotonic Scheduler
5 *
6 * @ingroup ClassicRTEMS
7 * @brief Classic API Rate Monotonic Manager.
8 *
9 * This include file contains all the constants, structures, and
10 * prototypes associated with the Rate Monotonic Manager. This manager
11 * provides facilities to implement threads which execute in a periodic
12 * fashion.
13 *
14 * Directives provided are:
15 *
16 * - create a rate monotonic timer
17 * - cancel a period
18 * - delete a rate monotonic timer
19 * - conclude current and start the next period
20 * - obtain status information on a period
21 */
22
23/* COPYRIGHT (c) 1989-2009, 2016.
24 * On-Line Applications Research Corporation (OAR).
25 *
26 * The license and distribution terms for this file may be
27 * found in the file LICENSE in this distribution or at
28 * http://www.rtems.org/license/LICENSE.
29 */
30
31#ifndef _RTEMS_RTEMS_RATEMON_H
32#define _RTEMS_RTEMS_RATEMON_H
33
34#include <rtems/rtems/types.h>
35#include <rtems/rtems/status.h>
36#include <rtems/score/thread.h>
37#include <rtems/score/watchdog.h>
38#include <rtems/bspIo.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/**
45 *  @defgroup ClassicRateMon Rate Monotonic Scheduler
46 *
47 *  @ingroup ClassicRTEMS
48 *
49 *  This encapsulates functionality related to the Classic API Rate
50 *  Monotonic Manager.
51 *
52 *  Statistics are kept for each period and can be obtained or printed via
53 *  API calls.  The statistics kept include minimum, maximum and average times
54 *  for both cpu usage and wall time.  The statistics indicate the execution
55 *  and wall time used by the owning thread between successive calls to
56 *  rtems_rate_monotonic_period.
57 */
58/**@{*/
59
60/**
61 *  This is the public type used for the rate monotonic timing
62 *  statistics.
63 */
64#include <rtems/score/timespec.h>
65
66typedef struct timespec rtems_rate_monotonic_period_time_t;
67
68/**
69 *  This is the internal type used for the rate monotonic timing
70 *  statistics.
71 */
72#include <rtems/score/timestamp.h>
73
74/**
75 *  The following enumerated type defines the states in which a
76 *  period may be.
77 */
78typedef enum {
79  /**
80   * This value indicates the period is off the watchdog chain,
81   * and has never been initialized.
82   */
83  RATE_MONOTONIC_INACTIVE,
84
85  /**
86   * This value indicates the period is on the watchdog chain, and
87   * the owner is blocked waiting on it.
88   */
89  RATE_MONOTONIC_OWNER_IS_BLOCKING,
90
91  /**
92   * This value indicates the period is on the watchdog chain, and
93   * running.  The owner should be executed or blocked waiting on
94   * another object.
95   */
96  RATE_MONOTONIC_ACTIVE,
97
98  /**
99   * This value indicates the period is on the watchdog chain, and
100   * has expired.  The owner should be blocked waiting for the next period.
101   */
102  RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING,
103
104  /**
105   * This value indicates the period is off the watchdog chain, and
106   * has expired.  The owner is still executing and has taken too much
107   * all time to complete this iteration of the period.
108   */
109  RATE_MONOTONIC_EXPIRED
110}   rtems_rate_monotonic_period_states;
111
112/**
113 *  The following constant is the interval passed to the rate_monontonic_period
114 *  directive to obtain status information.
115 */
116#define RTEMS_PERIOD_STATUS       WATCHDOG_NO_TIMEOUT
117
118/**
119 *  The following defines the PUBLIC data structure that has the
120 *  statistics kept on each period instance.
121 *
122 *  @note The public structure uses struct timespec while the
123 *        internal one uses Timestamp_Control.
124 */
125typedef struct {
126  /** This field contains the number of periods executed. */
127  uint32_t     count;
128  /** This field contains the number of periods missed. */
129  uint32_t     missed_count;
130
131  /** This field contains the least amount of CPU time used in a period. */
132  rtems_thread_cpu_usage_t             min_cpu_time;
133  /** This field contains the highest amount of CPU time used in a period. */
134  rtems_thread_cpu_usage_t             max_cpu_time;
135  /** This field contains the total amount of wall time used in a period. */
136  rtems_thread_cpu_usage_t             total_cpu_time;
137
138  /** This field contains the least amount of wall time used in a period. */
139  rtems_rate_monotonic_period_time_t   min_wall_time;
140  /** This field contains the highest amount of wall time used in a period. */
141  rtems_rate_monotonic_period_time_t   max_wall_time;
142  /** This field contains the total amount of CPU time used in a period. */
143  rtems_rate_monotonic_period_time_t   total_wall_time;
144}  rtems_rate_monotonic_period_statistics;
145
146/**
147 *  The following defines the INTERNAL data structure that has the
148 *  statistics kept on each period instance.
149 */
150typedef struct {
151  /** This field contains the number of periods executed. */
152  uint32_t     count;
153  /** This field contains the number of periods missed. */
154  uint32_t     missed_count;
155
156  /** This field contains the least amount of CPU time used in a period. */
157  Timestamp_Control min_cpu_time;
158  /** This field contains the highest amount of CPU time used in a period. */
159  Timestamp_Control max_cpu_time;
160  /** This field contains the total amount of wall time used in a period. */
161  Timestamp_Control total_cpu_time;
162
163  /** This field contains the least amount of wall time used in a period. */
164  Timestamp_Control min_wall_time;
165  /** This field contains the highest amount of wall time used in a period. */
166  Timestamp_Control max_wall_time;
167  /** This field contains the total amount of CPU time used in a period. */
168  Timestamp_Control total_wall_time;
169}  Rate_monotonic_Statistics;
170
171/**
172 *  The following defines the period status structure.
173 */
174typedef struct {
175  /** This is the Id of the thread using this period. */
176  rtems_id                             owner;
177
178  /** This is the current state of this period. */
179  rtems_rate_monotonic_period_states   state;
180
181  /**
182   *  This is the length of wall time that has passed since this period
183   *  was last initiated.  If the period is expired or has not been initiated,
184   *  then this field has no meaning.
185   */
186  rtems_rate_monotonic_period_time_t   since_last_period;
187
188  /**
189   *  This is the amount of CPU time that has been used since this period
190   *  was last initiated.  If the period is expired or has not been initiated,
191   *  then this field has no meaning.
192   */
193  rtems_thread_cpu_usage_t             executed_since_last_period;
194}  rtems_rate_monotonic_period_status;
195
196/**
197 *  The following structure defines the control block used to manage
198 *  each period.
199 */
200typedef struct {
201  /** This field is the object management portion of a Period instance. */
202  Objects_Control                         Object;
203
204  /** This is the timer used to provide the unblocking mechanism. */
205  Watchdog_Control                        Timer;
206
207  /** This field indicates the current state of the period. */
208  rtems_rate_monotonic_period_states      state;
209
210  /**
211   * This field contains the length of the next period to be
212   * executed.
213   */
214  uint32_t                                next_length;
215
216  /**
217   * This field contains a pointer to the TCB for the thread
218   * which owns and uses this period instance.
219   */
220  Thread_Control                         *owner;
221
222  /**
223   * This field contains the cpu usage value of the owning thread when
224   * the period was initiated.  It is used to compute the period's
225   * statistics.
226   */
227  Timestamp_Control                       cpu_usage_period_initiated;
228
229  /**
230   * This field contains the wall time value when the period
231   * was initiated.  It is used to compute the period's statistics.
232   */
233  Timestamp_Control                       time_period_initiated;
234
235  /**
236   * This field contains the statistics maintained for the period.
237   */
238  Rate_monotonic_Statistics               Statistics;
239}   Rate_monotonic_Control;
240
241/**
242 *  @brief Create a Period
243 *
244 *  Rate Monotonic Manager
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 */
250rtems_status_code rtems_rate_monotonic_create(
251  rtems_name    name,
252  rtems_id     *id
253);
254
255/**
256 * @brief RTEMS Rate Monotonic Name to Id
257 *
258 * This routine implements the rtems_rate_monotonic_ident directive.
259 * It returns the period ID associated with name. If more than one period
260 * is named name, then the period to which the ID belongs is arbitrary.
261 *
262 * @param[in] name is the user defined period name
263 * @param[in] id is the pointer to period id
264 *
265 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
266 *         error. Otherwise, a status code is returned indicating the
267 *         source of the error. If successful, the id will
268 *         be filled in with the region id.
269 */
270rtems_status_code rtems_rate_monotonic_ident(
271  rtems_name    name,
272  rtems_id     *id
273);
274
275/**
276 * @brief RTEMS Rate Monotonic Cancel
277 *
278 * This routine implements the rtems_rate_monotonic_cancel directive. This
279 * directive stops the period associated with ID from continuing to
280 * run.
281 *
282 * @param[in] id is the rate monotonic id
283 *
284 * @retval RTEMS_SUCCESSFUL if successful and caller is not the owning thread
285 * or error code if unsuccessful
286 *
287 */
288rtems_status_code rtems_rate_monotonic_cancel(
289  rtems_id   id
290);
291
292/**
293 * @brief RTEMS Delete Rate Monotonic
294 *
295 * This routine implements the rtems_rate_monotonic_delete directive. The
296 * period indicated by ID is deleted.
297 *
298 * @param[in] id is the rate monotonic id
299 *
300 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
301 *         error. Otherwise, a status code is returned indicating the
302 *         source of the error.
303 */
304rtems_status_code rtems_rate_monotonic_delete(
305  rtems_id   id
306);
307
308/**
309 * @brief RTEMS Rate Monotonic Get Status
310 *
311 * This routine implements the rtems_rate_monotonic_get_status directive.
312 * Information about the period indicated by ID is returned.
313 *
314 * @param[in] id is the rate monotonic id
315 * @param[in] status is the pointer to status control block
316 *
317 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
318 *         error. Otherwise, a status code is returned indicating the
319 *         source of the error.
320 *
321 */
322rtems_status_code rtems_rate_monotonic_get_status(
323  rtems_id                             id,
324  rtems_rate_monotonic_period_status  *status
325);
326
327/**
328 * @brief RTEMS Rate Monotonic Get Statistics
329 *
330 * This routine implements the rtems_rate_monotonic_get_statistics directive.
331 * Statistics gathered from the use of this period are returned.
332 *
333 * @param[in] id is the rate monotonic id
334 * @param[in] statistics is the pointer to statistics control block
335 *
336 * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
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 *  Rate Monotonic Manager -- Reset Statistics
347 *
348 *  This routine allows a thread to reset the statistics information
349 *  on a specific period instance.
350 */
351rtems_status_code rtems_rate_monotonic_reset_statistics(
352  rtems_id                                 id
353);
354
355/**
356 *  @brief rtems_rate_monotonic_reset_all_statistics
357 *
358 *  This routine allows a thread to reset the statistics information
359 *  on ALL period instances.
360 */
361void rtems_rate_monotonic_reset_all_statistics( void );
362
363/**
364 *  @brief RTEMS Report Rate Monotonic Statistics
365 *
366 *  This routine allows a thread to print the statistics information
367 *  on ALL period instances which have non-zero counts using printk.
368 *  The implementation of this directive straddles the fence between
369 *  inside and outside of RTEMS.  It is presented as part of the Manager
370 *  but actually uses other services of the Manager.
371 */
372void rtems_rate_monotonic_report_statistics_with_plugin(
373  void                  *context,
374  rtems_printk_plugin_t  print
375);
376
377/**
378 *  @brief RTEMS Report Rate Monotonic Statistics
379 *
380 *  This routine allows a thread to print the statistics information
381 *  on ALL period instances which have non-zero counts using printk.
382 */
383void rtems_rate_monotonic_report_statistics( void );
384
385/**
386 * @brief RTEMS Rate Monotonic Period
387 *
388 * This routine implements the rtems_rate_monotonic_period directive. When
389 * length is non-zero, this directive initiates the period associated with
390 * ID from continuing for a period of length. If length is zero, then
391 * result is set to indicate the current state of the period.
392 *
393 * @param[in] id is the rate monotonic id
394 * @param[in] length is the length of period (in ticks)
395 *
396 * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
397 */
398rtems_status_code rtems_rate_monotonic_period(
399  rtems_id        id,
400  rtems_interval  length
401);
402
403/**@}*/
404
405#ifdef __cplusplus
406}
407#endif
408
409#endif
410/* end of include file */
Note: See TracBrowser for help on using the repository browser.