source: rtems/cpukit/rtems/include/rtems/rtems/ratemon.h @ 3a46b72

5
Last change on this file since 3a46b72 was 3a46b72, checked in by Kuan-Hsun Chen <c0066c@…>, on 12/21/16 at 16:42:39

Enhancement of the RMS manager for the overrun handling.

Three additional functions:
rtems_rate_monotonic_postponed_job_count,
_Rate_monotonic_Renew_deadline, and _Rate_monotonic_Release_postponed_job.

Four refined functions:
_Rate_monotonic_Activate, _Rate_monotonic_Block_while_expired,
rtems_rate_monotonic_period, _Rate_monotonic_Timeout.

Rate_monotonic_Control contains one counter for counting the postponed jobs
and one for recording the recent deadline.

Update #2795.

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