source: rtems-docs/c-user/rate_monotonic_manager.rst @ e52906b

5
Last change on this file since e52906b was e52906b, checked in by Sebastian Huber <sebastian.huber@…>, on 01/09/19 at 15:14:06

Simplify SPDX-License-Identifier comment

  • Property mode set to 100644
File size: 41.6 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 1988, 2008 On-Line Applications Research Corporation (OAR)
4.. Copyright (C) 2017 Kuan-Hsun Chen.
5
6.. index:: rate mononitonic tasks
7.. index:: periodic tasks
8
9Rate Monotonic Manager
10**********************
11
12Introduction
13============
14
15The rate monotonic manager provides facilities to implement tasks which execute
16in a periodic fashion.  Critically, it also gathers information about the
17execution of those periods and can provide important statistics to the user
18which can be used to analyze and tune the application.  The directives provided
19by the rate monotonic manager are:
20
21- rtems_rate_monotonic_create_ - Create a rate monotonic period
22
23- rtems_rate_monotonic_ident_ - Get ID of a period
24
25- rtems_rate_monotonic_cancel_ - Cancel a period
26
27- rtems_rate_monotonic_delete_ - Delete a rate monotonic period
28
29- rtems_rate_monotonic_period_ - Conclude current/Start next period
30
31- rtems_rate_monotonic_get_status_ - Obtain status from a period
32
33- rtems_rate_monotonic_get_statistics_ - Obtain statistics from a period
34
35- rtems_rate_monotonic_reset_statistics_ - Reset statistics for a period
36
37- rtems_rate_monotonic_reset_all_statistics_ - Reset statistics for all periods
38
39- rtems_rate_monotonic_report_statistics_ - Print period statistics report
40
41Background
42==========
43
44The rate monotonic manager provides facilities to manage the execution of
45periodic tasks.  This manager was designed to support application designers who
46utilize the Rate Monotonic Scheduling Algorithm (RMS) to ensure that their
47periodic tasks will meet their deadlines, even under transient overload
48conditions.  Although designed for hard real-time systems, the services
49provided by the rate monotonic manager may be used by any application which
50requires periodic tasks.
51
52Rate Monotonic Manager Required Support
53---------------------------------------
54
55A clock tick is required to support the functionality provided by this manager.
56
57Period Statistics
58-----------------
59
60This manager maintains a set of statistics on each period object.  These
61statistics are reset implictly at period creation time and may be reset or
62obtained at any time by the application.  The following is a list of the
63information kept:
64
65``owner``
66  is the id of the thread that owns this period.
67
68``count``
69  is the total number of periods executed.
70
71``missed_count``
72  is the number of periods that were missed.
73
74``min_cpu_time``
75  is the minimum amount of CPU execution time consumed on any execution of the
76  periodic loop.
77
78``max_cpu_time``
79  is the maximum amount of CPU execution time consumed on any execution of the
80  periodic loop.
81
82``total_cpu_time``
83  is the total amount of CPU execution time consumed by executions of the
84  periodic loop.
85
86``min_wall_time``
87  is the minimum amount of wall time that passed on any execution of the
88  periodic loop.
89
90``max_wall_time``
91  is the maximum amount of wall time that passed on any execution of the
92  periodic loop.
93
94``total_wall_time``
95  is the total amount of wall time that passed during executions of the
96  periodic loop.
97
98Each period is divided into two consecutive phases.  The period starts with the
99active phase of the task and is followed by the inactive phase of the task.  In
100the inactive phase the task is blocked and waits for the start of the next
101period.  The inactive phase is skipped in case of a period miss.  The wall time
102includes the time during the active phase of the task on which the task is not
103executing on a processor.  The task is either blocked (for example it waits for
104a resource) or a higher priority tasks executes, thus preventing it from
105executing.  In case the wall time exceeds the period time, then this is a
106period miss.  The gap between the wall time and the period time is the margin
107between a period miss or success.
108
109The period statistics information is inexpensive to maintain and can provide
110very useful insights into the execution characteristics of a periodic task
111loop.  But it is just information.  The period statistics reported must be
112analyzed by the user in terms of what the applications is.  For example, in an
113application where priorities are assigned by the Rate Monotonic Algorithm, it
114would be very undesirable for high priority (i.e. frequency) tasks to miss
115their period.  Similarly, in nearly any application, if a task were supposed to
116execute its periodic loop every 10 milliseconds and it averaged 11
117milliseconds, then application requirements are not being met.
118
119The information reported can be used to determine the "hot spots" in the
120application.  Given a period's id, the user can determine the length of that
121period.  From that information and the CPU usage, the user can calculate the
122percentage of CPU time consumed by that periodic task.  For example, a task
123executing for 20 milliseconds every 200 milliseconds is consuming 10 percent of
124the processor's execution time.  This is usually enough to make it a good
125candidate for optimization.
126
127However, execution time alone is not enough to gauge the value of optimizing a
128particular task.  It is more important to optimize a task executing 2
129millisecond every 10 milliseconds (20 percent of the CPU) than one executing 10
130milliseconds every 100 (10 percent of the CPU).  As a general rule of thumb,
131the higher frequency at which a task executes, the more important it is to
132optimize that task.
133
134.. index:: periodic task, definition
135
136Periodicity Definitions
137----------------------------------
138
139A periodic task is one which must be executed at a regular interval.  The
140interval between successive iterations of the task is referred to as its
141period.  Periodic tasks can be characterized by the length of their period and
142execution time.  The period and execution time of a task can be used to
143determine the processor utilization for that task.  Processor utilization is
144the percentage of processor time used and can be calculated on a per-task or
145system-wide basis.  Typically, the task's worst-case execution time will be
146less than its period.  For example, a periodic task's requirements may state
147that it should execute for 10 milliseconds every 100 milliseconds.  Although
148the execution time may be the average, worst, or best case, the worst-case
149execution time is more appropriate for use when analyzing system behavior under
150transient overload conditions... index:: aperiodic task, definition
151
152In contrast, an aperiodic task executes at irregular intervals and has only a
153soft deadline.  In other words, the deadlines for aperiodic tasks are not
154rigid, but adequate response times are desirable.  For example, an aperiodic
155task may process user input from a terminal.
156
157.. index:: sporadic task, definition
158
159Finally, a sporadic task is an aperiodic task with a hard deadline and minimum
160interarrival time.  The minimum interarrival time is the minimum period of time
161which exists between successive iterations of the task.  For example, a
162sporadic task could be used to process the pressing of a fire button on a
163joystick.  The mechanical action of the fire button ensures a minimum time
164period between successive activations, but the missile must be launched by a
165hard deadline.
166
167.. index:: Rate Monotonic Scheduling Algorithm, definition
168.. index:: RMS Algorithm, definition
169
170Rate Monotonic Scheduling Algorithm
171-----------------------------------
172
173The Rate Monotonic Scheduling Algorithm (RMS) is important to real-time systems
174designers because it allows one to sufficiently guarantee that a set of tasks
175is schedulable (see :cite:`Liu:1973:Scheduling`, :cite:`Lehoczky:1989:RM`,
176:cite:`Sha:1990:Ada`, :cite:`Burns:1991:Review`).
177
178A set of tasks is said to be schedulable if all of the tasks can meet their
179deadlines.  RMS provides a set of rules which can be used to perform
180a guaranteed schedulability analysis for a task set.  This analysis determines
181whether a task set is schedulable under worst-case conditions and emphasizes
182the predictability of the system's behavior.  It has been proven that:
183
184.. sidebar:: *RMS*
185
186  RMS is an optimal fixed-priority algorithm for scheduling independent,
187  preemptible, periodic tasks on a single processor.
188
189RMS is optimal in the sense that if a set of tasks can be scheduled by any
190fixed-priority algorithm, then RMS will be able to schedule that task set.
191RMS bases it schedulability analysis on the processor utilization level below
192which all deadlines can be met.
193
194RMS calls for the static assignment of task priorities based upon their period.
195The shorter a task's period, the higher its priority.  For example, a task with
196a 1 millisecond period has higher priority than a task with a 100 millisecond
197period.  If two tasks have the same period, then RMS does not distinguish
198between the tasks.  However, RTEMS specifies that when given tasks of equal
199priority, the task which has been ready longest will execute first.  RMS's
200priority assignment scheme does not provide one with exact numeric values for
201task priorities.  For example, consider the following task set and priority
202assignments:
203
204+--------------------+---------------------+---------------------+
205| Task               | Period              | Priority            |
206|                    | (in milliseconds)   |                     |
207+====================+=====================+=====================+
208|         1          |         100         |         Low         |
209+--------------------+---------------------+---------------------+
210|         2          |          50         |       Medium        |
211+--------------------+---------------------+---------------------+
212|         3          |          50         |       Medium        |
213+--------------------+---------------------+---------------------+
214|         4          |          25         |        High         |
215+--------------------+---------------------+---------------------+
216
217RMS only calls for task 1 to have the lowest priority, task 4 to have the
218highest priority, and tasks 2 and 3 to have an equal priority between that of
219tasks 1 and 4.  The actual RTEMS priorities assigned to the tasks must only
220adhere to those guidelines.
221
222Many applications have tasks with both hard and soft deadlines.  The tasks with
223hard deadlines are typically referred to as the critical task set, with the
224soft deadline tasks being the non-critical task set.  The critical task set can
225be scheduled using RMS, with the non-critical tasks not executing under
226transient overload, by simply assigning priorities such that the lowest
227priority critical task (i.e. longest period) has a higher priority than the
228highest priority non-critical task.  Although RMS may be used to assign
229priorities to the non-critical tasks, it is not necessary.  In this instance,
230schedulability is only guaranteed for the critical task set.
231
232.. index:: RMS schedulability analysis
233
234Schedulability Analysis
235-----------------------
236
237RMS allows application designers to ensure that tasks can meet all deadlines under fixed-priority assignment,
238even under transient overload, without knowing exactly when any given task will
239execute by applying proven schedulability analysis rules.
240
241Assumptions
242^^^^^^^^^^^
243
244The schedulability analysis rules for RMS were developed based on the following
245assumptions:
246
247- The requests for all tasks for which hard deadlines exist are periodic, with
248  a constant interval between requests.
249
250- Each task must complete before the next request for it occurs.
251
252- The tasks are independent in that a task does not depend on the initiation or
253  completion of requests for other tasks.
254
255- The execution time for each task without preemption or interruption is
256  constant and does not vary.
257
258- Any non-periodic tasks in the system are special.  These tasks displace
259  periodic tasks while executing and do not have hard, critical deadlines.
260
261Once the basic schedulability analysis is understood, some of the above
262assumptions can be relaxed and the side-effects accounted for.
263
264.. index:: RMS Processor Utilization Rule
265
266Processor Utilization Rule
267^^^^^^^^^^^^^^^^^^^^^^^^^^
268
269The Processor Utilization Rule requires that processor utilization be
270calculated based upon the period and execution time of each task.
271The fraction of processor time spent executing task index is ``Time(i)
272/ Period(i)``.  The processor utilization can be calculated as follows
273where n is the number of tasks in the set being analyzed:
274
275.. math::
276
277    Utilization = \sum_{i=1}^{n} Time_i/Period_i
278
279To ensure schedulability even under transient overload, the processor
280utilization must adhere to the following rule:
281
282.. math::
283
284    maximumUtilization = n * (2^{\frac{1}{n}} - 1)
285
286As the number of tasks increases, the above formula approaches ln(2) for a
287worst-case utilization factor of approximately 0.693.  Many tasks sets can be
288scheduled with a greater utilization factor.  In fact, the average processor
289utilization threshold for a randomly generated task set is approximately 0.88.
290See more detail in :cite:`Liu:1973:Scheduling`.
291
292Processor Utilization Rule Example
293^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
294
295This example illustrates the application of the Processor Utilization Rule to
296an application with three critical periodic tasks.  The following table details
297the RMS priority, period, execution time, and processor utilization for each
298task:
299
300+------------+----------+--------+-----------+-------------+
301| Task       | RMS      | Period | Execution | Processor   |
302|            | Priority |        | Time      | Utilization |
303+============+==========+========+===========+=============+
304|     1      |   High   |  100   |    15     |    0.15     |
305+------------+----------+--------+-----------+-------------+
306|     2      |  Medium  |  200   |    50     |    0.25     |
307+------------+----------+--------+-----------+-------------+
308|     3      |   Low    |  300   |   100     |    0.33     |
309+------------+----------+--------+-----------+-------------+
310
311The total processor utilization for this task set is 0.73 which is below the
312upper bound of 3 * (2**(1/3) - 1), or 0.779, imposed by the Processor
313Utilization Rule.  Therefore, this task set is guaranteed to be schedulable
314using RMS.
315
316.. index:: RMS First Deadline Rule
317
318First Deadline Rule
319^^^^^^^^^^^^^^^^^^^
320
321If a given set of tasks do exceed the processor utilization upper limit imposed
322by the Processor Utilization Rule, they can still be guaranteed to meet all
323their deadlines by application of the First Deadline Rule.  This rule can be
324stated as follows:
325
326For a given set of independent periodic tasks, if each task meets its first
327deadline when all tasks are started at the same time, then the deadlines will
328always be met for any combination of start times.
329
330A key point with this rule is that ALL periodic tasks are assumed to start at
331the exact same instant in time.  Although this assumption may seem to be
332invalid, RTEMS makes it quite easy to ensure.  By having a non-preemptible user
333initialization task, all application tasks, regardless of priority, can be
334created and started before the initialization deletes itself.  This technique
335ensures that all tasks begin to compete for execution time at the same instant
336- when the user initialization task deletes itself.
337See more detail in :cite:`Lehoczky:1989:RM`.
338
339First Deadline Rule Example
340^^^^^^^^^^^^^^^^^^^^^^^^^^^
341
342The First Deadline Rule can ensure schedulability even when the Processor
343Utilization Rule fails.  The example below is a modification of the Processor
344Utilization Rule example where task execution time has been increased from 15
345to 25 units.  The following table details the RMS priority, period, execution
346time, and processor utilization for each task:
347
348+------------+----------+--------+-----------+-------------+
349| Task       | RMS      | Period | Execution | Processor   |
350|            | Priority |        | Time      | Utilization |
351+============+==========+========+===========+=============+
352|     1      |   High   |  100   |    25     |    0.25     |
353+------------+----------+--------+-----------+-------------+
354|     2      |  Medium  |  200   |    50     |    0.25     |
355+------------+----------+--------+-----------+-------------+
356|     3      |   Low    |  300   |   100     |    0.33     |
357+------------+----------+--------+-----------+-------------+
358
359The total processor utilization for the modified task set is 0.83 which is
360above the upper bound of 3 * (2**(1/3) - 1), or 0.779, imposed by the Processor
361Utilization Rule.  Therefore, this task set is not guaranteed to be schedulable
362using RMS.  However, the First Deadline Rule can guarantee the schedulability
363of this task set.  This rule calls for one to examine each occurrence of
364deadline until either all tasks have met their deadline or one task failed to
365meet its first deadline.  The following table details the time of each deadline
366occurrence, the maximum number of times each task may have run, the total
367execution time, and whether all the deadlines have been met:
368
369+----------+------+------+------+----------------------+---------------+
370| Deadline | Task | Task | Task | Total                | All Deadlines |
371| Time     | 1    | 2    | 3    | Execution Time       | Met?          |
372+==========+======+======+======+======================+===============+
373|   100    |  1   |  1   |  1   |  25 + 50 + 100 = 175 |      NO       |
374+----------+------+------+------+----------------------+---------------+
375|   200    |  2   |  1   |  1   |  50 + 50 + 100 = 200 |     YES       |
376+----------+------+------+------+----------------------+---------------+
377
378The key to this analysis is to recognize when each task will execute.  For
379example at time 100, task 1 must have met its first deadline, but tasks 2 and 3
380may also have begun execution.  In this example, at time 100 tasks 1 and 2 have
381completed execution and thus have met their first deadline.  Tasks 1 and 2 have
382used (25 + 50) = 75 time units, leaving (100 - 75) = 25 time units for task 3
383to begin.  Because task 3 takes 100 ticks to execute, it will not have
384completed execution at time 100.  Thus at time 100, all of the tasks except
385task 3 have met their first deadline.
386
387At time 200, task 1 must have met its second deadline and task 2 its first
388deadline.  As a result, of the first 200 time units, task 1 uses (2 * 25) = 50
389and task 2 uses 50, leaving (200 - 100) time units for task 3.  Task 3 requires
390100 time units to execute, thus it will have completed execution at time 200.
391Thus, all of the tasks have met their first deadlines at time 200, and the task
392set is schedulable using the First Deadline Rule.
393
394Relaxation of Assumptions
395^^^^^^^^^^^^^^^^^^^^^^^^^
396
397The assumptions used to develop the RMS schedulability rules are uncommon in
398most real-time systems.  For example, it was assumed that tasks have constant
399unvarying execution time.  It is possible to relax this assumption, simply by
400using the worst-case execution time of each task.
401
402Another assumption is that the tasks are independent.  This means that the
403tasks do not wait for one another or contend for resources.  This assumption
404can be relaxed by accounting for the amount of time a task spends waiting to
405acquire resources.  Similarly, each task's execution time must account for any
406I/O performed and any RTEMS directive calls.
407
408In addition, the assumptions did not account for the time spent executing
409interrupt service routines.  This can be accounted for by including all the
410processor utilization by interrupt service routines in the utilization
411calculation.  Similarly, one should also account for the impact of delays in
412accessing local memory caused by direct memory access and other processors
413accessing local dual-ported memory.
414
415The assumption that nonperiodic tasks are used only for initialization or
416failure-recovery can be relaxed by placing all periodic tasks in the critical
417task set.  This task set can be scheduled and analyzed using RMS.  All
418nonperiodic tasks are placed in the non-critical task set.  Although the
419critical task set can be guaranteed to execute even under transient overload,
420the non-critical task set is not guaranteed to execute.
421
422In conclusion, the application designer must be fully cognizant of the system
423and its run-time behavior when performing schedulability analysis for a system
424using RMS.  Every hardware and software factor which impacts the execution time
425of each task must be accounted for in the schedulability analysis.
426
427Operations
428==========
429
430Creating a Rate Monotonic Period
431--------------------------------
432
433The ``rtems_rate_monotonic_create`` directive creates a rate monotonic period
434which is to be used by the calling task to delineate a period.  RTEMS allocates
435a Period Control Block (PCB) from the PCB free list.  This data structure is
436used by RTEMS to manage the newly created rate monotonic period.  RTEMS returns
437a unique period ID to the application which is used by other rate monotonic
438manager directives to access this rate monotonic period.
439
440Manipulating a Period
441---------------------
442
443The ``rtems_rate_monotonic_period`` directive is used to establish and maintain
444periodic execution utilizing a previously created rate monotonic period.  Once
445initiated by the ``rtems_rate_monotonic_period`` directive, the period is said
446to run until it either expires or is reinitiated.  The state of the rate
447monotonic period results in one of the following scenarios:
448
449- If the rate monotonic period is running, the calling task will be blocked for
450  the remainder of the outstanding period and, upon completion of that period,
451  the period will be reinitiated with the specified period.
452
453- If the rate monotonic period is not currently running and has not expired, it
454  is initiated with a length of period ticks and the calling task returns
455  immediately.
456
457- If the rate monotonic period has expired before the task invokes the
458  ``rtems_rate_monotonic_period`` directive, the postponed job will be released
459  until there is no more postponed jobs. The calling task returns immediately
460  with a timeout error status. In the watchdog routine, the period will still
461  be updated periodically and track the count of the postponed jobs :cite:`Chen:2016:Overrun`.
462  Please note, the count of the postponed jobs is only saturated until 0xffffffff.
463
464Obtaining the Status of a Period
465--------------------------------
466
467If the ``rtems_rate_monotonic_period`` directive is invoked with a period of
468``RTEMS_PERIOD_STATUS`` ticks, the current state of the specified rate
469monotonic period will be returned.  The following table details the
470relationship between the period's status and the directive status code returned
471by the ``rtems_rate_monotonic_period`` directive:
472
473.. list-table::
474 :class: rtems-table
475
476 * - ``RTEMS_SUCCESSFUL``
477   - period is running
478 * - ``RTEMS_TIMEOUT``
479   - period has expired
480 * - ``RTEMS_NOT_DEFINED``
481   - period has never been initiated
482
483Obtaining the status of a rate monotonic period does not alter the state or
484length of that period.
485
486Canceling a Period
487------------------
488
489The ``rtems_rate_monotonic_cancel`` directive is used to stop the period
490maintained by the specified rate monotonic period.  The period is stopped and
491the rate monotonic period can be reinitiated using the
492``rtems_rate_monotonic_period`` directive.
493
494Deleting a Rate Monotonic Period
495--------------------------------
496
497The ``rtems_rate_monotonic_delete`` directive is used to delete a rate
498monotonic period.  If the period is running and has not expired, the period is
499automatically canceled.  The rate monotonic period's control block is returned
500to the PCB free list when it is deleted.  A rate monotonic period can be
501deleted by a task other than the task which created the period.
502
503Examples
504--------
505
506The following sections illustrate common uses of rate monotonic periods to
507construct periodic tasks.
508
509Simple Periodic Task
510--------------------
511
512This example consists of a single periodic task which, after initialization,
513executes every 100 clock ticks.
514
515.. code-block:: c
516    :linenos:
517
518    rtems_task Periodic_task(rtems_task_argument arg)
519    {
520        rtems_name        name;
521        rtems_id          period;
522        rtems_status_code status;
523        name = rtems_build_name( 'P', 'E', 'R', 'D' );
524        status = rtems_rate_monotonic_create( name, &period );
525        if ( status != RTEMS_STATUS_SUCCESSFUL ) {
526            printf( "rtems_monotonic_create failed with status of %d.\n", rc );
527            exit( 1 );
528        }
529        while ( 1 ) {
530            if ( rtems_rate_monotonic_period( period, 100 ) == RTEMS_TIMEOUT )
531                break;
532            /* Perform some periodic actions */
533        }
534        /* missed period so delete period and SELF */
535        status = rtems_rate_monotonic_delete( period );
536        if ( status != RTEMS_STATUS_SUCCESSFUL ) {
537            printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
538            exit( 1 );
539        }
540        status = rtems_task_delete( SELF );    /* should not return */
541        printf( "rtems_task_delete returned with status of %d.\n", status );
542        exit( 1 );
543    }
544
545The above task creates a rate monotonic period as part of its initialization.
546The first time the loop is executed, the ``rtems_rate_monotonic_period``
547directive will initiate the period for 100 ticks and return immediately.
548Subsequent invocations of the ``rtems_rate_monotonic_period`` directive will
549result in the task blocking for the remainder of the 100 tick period.  If, for
550any reason, the body of the loop takes more than 100 ticks to execute, the
551``rtems_rate_monotonic_period`` directive will return the ``RTEMS_TIMEOUT``
552status. If the above task misses its deadline, it will delete the rate
553monotonic period and itself.
554
555Task with Multiple Periods
556--------------------------
557
558This example consists of a single periodic task which, after initialization,
559performs two sets of actions every 100 clock ticks.  The first set of actions
560is performed in the first forty clock ticks of every 100 clock ticks, while the
561second set of actions is performed between the fortieth and seventieth clock
562ticks.  The last thirty clock ticks are not used by this task.
563
564.. code-block:: c
565    :linenos:
566
567    rtems_task Periodic_task(rtems_task_argument arg)
568    {
569        rtems_name        name_1, name_2;
570        rtems_id          period_1, period_2;
571        rtems_status_code status;
572        name_1 = rtems_build_name( 'P', 'E', 'R', '1' );
573        name_2 = rtems_build_name( 'P', 'E', 'R', '2' );
574        (void ) rtems_rate_monotonic_create( name_1, &period_1 );
575        (void ) rtems_rate_monotonic_create( name_2, &period_2 );
576        while ( 1 ) {
577            if ( rtems_rate_monotonic_period( period_1, 100 ) == TIMEOUT )
578                break;
579            if ( rtems_rate_monotonic_period( period_2, 40 ) == TIMEOUT )
580            break;
581            /*
582             *  Perform first set of actions between clock
583             *  ticks 0 and 39 of every 100 ticks.
584             */
585            if ( rtems_rate_monotonic_period( period_2, 30 ) == TIMEOUT )
586                break;
587            /*
588             *  Perform second set of actions between clock 40 and 69
589             *  of every 100 ticks.  THEN ...
590             *
591             *  Check to make sure we didn't miss the period_2 period.
592             */
593            if ( rtems_rate_monotonic_period( period_2, STATUS ) == TIMEOUT )
594                break;
595            (void) rtems_rate_monotonic_cancel( period_2 );
596        }
597        /* missed period so delete period and SELF */
598        (void ) rtems_rate_monotonic_delete( period_1 );
599        (void ) rtems_rate_monotonic_delete( period_2 );
600        (void ) task_delete( SELF );
601    }
602
603The above task creates two rate monotonic periods as part of its
604initialization.  The first time the loop is executed, the
605``rtems_rate_monotonic_period`` directive will initiate the period_1 period for
606100 ticks and return immediately.  Subsequent invocations of the
607``rtems_rate_monotonic_period`` directive for period_1 will result in the task
608blocking for the remainder of the 100 tick period.  The period_2 period is used
609to control the execution time of the two sets of actions within each 100 tick
610period established by period_1.  The ``rtems_rate_monotonic_cancel( period_2
611)`` call is performed to ensure that the period_2 period does not expire while
612the task is blocked on the period_1 period.  If this cancel operation were not
613performed, every time the ``rtems_rate_monotonic_period( period_2, 40 )`` call
614is executed, except for the initial one, a directive status of
615``RTEMS_TIMEOUT`` is returned.  It is important to note that every time this
616call is made, the period_2 period will be initiated immediately and the task
617will not block.
618
619If, for any reason, the task misses any deadline, the
620``rtems_rate_monotonic_period`` directive will return the ``RTEMS_TIMEOUT``
621directive status. If the above task misses its deadline, it will delete the
622rate monotonic periods and itself.
623
624Directives
625==========
626
627This section details the rate monotonic manager's directives.  A subsection is
628dedicated to each of this manager's directives and describes the calling
629sequence, related constants, usage, and status codes.
630
631.. raw:: latex
632
633   \clearpage
634
635.. index:: create a period
636.. index:: rtems_rate_monotonic_create
637
638.. _rtems_rate_monotonic_create:
639
640RATE_MONOTONIC_CREATE - Create a rate monotonic period
641------------------------------------------------------
642
643CALLING SEQUENCE:
644    .. code-block:: c
645
646        rtems_status_code rtems_rate_monotonic_create(
647            rtems_name  name,
648            rtems_id   *id
649        );
650
651DIRECTIVE STATUS CODES:
652    .. list-table::
653     :class: rtems-table
654
655     * - ``RTEMS_SUCCESSFUL``
656       - rate monotonic period created successfully
657     * - ``RTEMS_INVALID_NAME``
658       - invalid period name
659     * - ``RTEMS_TOO_MANY``
660       - too many periods created
661
662DESCRIPTION:
663    This directive creates a rate monotonic period.  The assigned rate
664    monotonic id is returned in id.  This id is used to access the period with
665    other rate monotonic manager directives.  For control and maintenance of
666    the rate monotonic period, RTEMS allocates a PCB from the local PCB free
667    pool and initializes it.
668
669NOTES:
670    This directive will not cause the calling task to be preempted.
671
672.. raw:: latex
673
674   \clearpage
675
676.. index:: get ID of a period
677.. index:: obtain ID of a period
678.. index:: rtems_rate_monotonic_ident
679
680.. _rtems_rate_monotonic_ident:
681
682RATE_MONOTONIC_IDENT - Get ID of a period
683-----------------------------------------
684
685CALLING SEQUENCE:
686    .. code-block:: c
687
688        rtems_status_code rtems_rate_monotonic_ident(
689            rtems_name  name,
690            rtems_id   *id
691        );
692
693DIRECTIVE STATUS CODES:
694    .. list-table::
695     :class: rtems-table
696
697     * - ``RTEMS_SUCCESSFUL``
698       - period identified successfully
699     * - ``RTEMS_INVALID_NAME``
700       - period name not found
701
702DESCRIPTION:
703    This directive obtains the period id associated with the period name to be
704    acquired.  If the period name is not unique, then the period id will match
705    one of the periods with that name.  However, this period id is not
706    guaranteed to correspond to the desired period.  The period id is used to
707    access this period in other rate monotonic manager directives.
708
709NOTES:
710    This directive will not cause the running task to be preempted.
711
712.. raw:: latex
713
714   \clearpage
715
716.. index:: cancel a period
717.. index:: rtems_rate_monotonic_cancel
718
719.. _rtems_rate_monotonic_cancel:
720
721RATE_MONOTONIC_CANCEL - Cancel a period
722---------------------------------------
723
724CALLING SEQUENCE:
725    .. code-block:: c
726
727        rtems_status_code rtems_rate_monotonic_cancel(
728            rtems_id id
729        );
730
731DIRECTIVE STATUS CODES:
732    .. list-table::
733     :class: rtems-table
734
735     * - ``RTEMS_SUCCESSFUL``
736       - period canceled successfully
737     * - ``RTEMS_INVALID_ID``
738       - invalid rate monotonic period id
739     * - ``RTEMS_NOT_OWNER_OF_RESOURCE``
740       - rate monotonic period not created by calling task
741
742DESCRIPTION:
743
744    This directive cancels the rate monotonic period id.  This period will be
745    reinitiated by the next invocation of ``rtems_rate_monotonic_period``
746    with id.
747
748NOTES:
749    This directive will not cause the running task to be preempted.
750
751    The rate monotonic period specified by id must have been created by the
752    calling task.
753
754.. raw:: latex
755
756   \clearpage
757
758.. index:: rtems_rate_monotonic_delete
759.. index:: delete a period
760
761.. _rtems_rate_monotonic_delete:
762
763RATE_MONOTONIC_DELETE - Delete a rate monotonic period
764------------------------------------------------------
765
766CALLING SEQUENCE:
767    .. code-block:: c
768
769        rtems_status_code rtems_rate_monotonic_delete(
770            rtems_id id
771        );
772
773DIRECTIVE STATUS CODES:
774    .. list-table::
775     :class: rtems-table
776
777     * - ``RTEMS_SUCCESSFUL``
778       - period deleted successfully
779     * - ``RTEMS_INVALID_ID``
780       - invalid rate monotonic period id
781
782DESCRIPTION:
783
784    This directive deletes the rate monotonic period specified by id.  If the
785    period is running, it is automatically canceled.  The PCB for the deleted
786    period is reclaimed by RTEMS.
787
788NOTES:
789    This directive will not cause the running task to be preempted.
790
791    A rate monotonic period can be deleted by a task other than the task which
792    created the period.
793
794.. raw:: latex
795
796   \clearpage
797
798.. index:: conclude current period
799.. index:: start current period
800.. index:: period initiation
801.. index:: rtems_rate_monotonic_period
802
803.. _rtems_rate_monotonic_period:
804
805RATE_MONOTONIC_PERIOD - Conclude current/Start next period
806----------------------------------------------------------
807
808CALLING SEQUENCE:
809    .. code-block:: c
810
811        rtems_status_code rtems_rate_monotonic_period(
812            rtems_id       id,
813            rtems_interval length
814        );
815
816DIRECTIVE STATUS CODES:
817    .. list-table::
818     :class: rtems-table
819
820     * - ``RTEMS_SUCCESSFUL``
821       - period initiated successfully
822     * - ``RTEMS_INVALID_ID``
823       - invalid rate monotonic period id
824     * - ``RTEMS_NOT_OWNER_OF_RESOURCE``
825       - period not created by calling task
826     * - ``RTEMS_NOT_DEFINED``
827       - period has never been initiated (only possible when period is set to PERIOD_STATUS)
828     * - ``RTEMS_TIMEOUT``
829       - period has expired
830
831DESCRIPTION:
832    This directive initiates the rate monotonic period id with a length of
833    period ticks.  If id is running, then the calling task will block for the
834    remainder of the period before reinitiating the period with the specified
835    period.  If id was not running (either expired or never initiated), the
836    period is immediately initiated and the directive returns immediately.
837    If id has expired its period, the postponed job will be released immediately
838    and the following calls of this directive will release postponed
839    jobs until there is no more deadline miss.
840
841    If invoked with a period of ``RTEMS_PERIOD_STATUS`` ticks, the current
842    state of id will be returned.  The directive status indicates the current
843    state of the period.  This does not alter the state or period of the
844    period.
845
846NOTES:
847    This directive will not cause the running task to be preempted.
848
849.. raw:: latex
850
851   \clearpage
852
853.. index:: get status of period
854.. index:: obtain status of period
855.. index:: rtems_rate_monotonic_get_status
856
857.. _rtems_rate_monotonic_get_status:
858
859RATE_MONOTONIC_GET_STATUS - Obtain status from a period
860-------------------------------------------------------
861
862CALLING SEQUENCE:
863    .. code-block:: c
864
865        rtems_status_code rtems_rate_monotonic_get_status(
866            rtems_id                            id,
867            rtems_rate_monotonic_period_status *status
868        );
869
870DIRECTIVE STATUS CODES:
871    .. list-table::
872     :class: rtems-table
873
874     * - ``RTEMS_SUCCESSFUL``
875       - period initiated successfully
876     * - ``RTEMS_INVALID_ID``
877       - invalid rate monotonic period id
878     * - ``RTEMS_INVALID_ADDRESS``
879       - invalid address of status
880
881*DESCRIPTION:
882    This directive returns status information associated with the rate
883    monotonic period id in the following data structure:
884
885    .. index:: rtems_rate_monotonic_period_status
886
887    .. code-block:: c
888
889        typedef struct {
890            rtems_id                              owner;
891            rtems_rate_monotonic_period_states    state;
892            rtems_rate_monotonic_period_time_t    since_last_period;
893            rtems_thread_cpu_usage_t              executed_since_last_period;
894            uint32_t                              postponed_jobs_count;
895        }  rtems_rate_monotonic_period_status;
896
897    .. COMMENT: RATE_MONOTONIC_INACTIVE does not have RTEMS in front of it.
898
899    A configure time option can be used to select whether the time information
900    is given in ticks or seconds and nanoseconds.  The default is seconds and
901    nanoseconds.  If the period's state is ``RATE_MONOTONIC_INACTIVE``, both
902    time values will be set to 0.  Otherwise, both time values will contain
903    time information since the last invocation of the
904    ``rtems_rate_monotonic_period`` directive.  More specifically, the
905    since_last_period value contains the elapsed time which has occurred since
906    the last invocation of the ``rtems_rate_monotonic_period`` directive and
907    the ``executed_since_last_period`` contains how much processor time the
908    owning task has consumed since the invocation of the
909    ``rtems_rate_monotonic_period`` directive. In addition, the
910    ``postponed_jobs_count value`` contains the count of jobs which are not
911    released yet.
912
913NOTES:
914    This directive will not cause the running task to be preempted.
915
916.. raw:: latex
917
918   \clearpage
919
920.. index:: get statistics of period
921.. index:: obtain statistics of period
922.. index:: rtems_rate_monotonic_get_statistics
923
924.. _rtems_rate_monotonic_get_statistics:
925
926RATE_MONOTONIC_GET_STATISTICS - Obtain statistics from a period
927---------------------------------------------------------------
928
929CALLING SEQUENCE:
930    .. code-block:: c
931
932        rtems_status_code rtems_rate_monotonic_get_statistics(
933            rtems_id                                id,
934            rtems_rate_monotonic_period_statistics *statistics
935        );
936
937DIRECTIVE STATUS CODES:
938    .. list-table::
939     :class: rtems-table
940
941     * - ``RTEMS_SUCCESSFUL``
942       - period initiated successfully
943     * - ``RTEMS_INVALID_ID``
944       - invalid rate monotonic period id
945     * - ``RTEMS_INVALID_ADDRESS``
946       - invalid address of statistics
947
948DESCRIPTION:
949    This directive returns statistics information associated with the rate
950    monotonic period id in the following data structure:
951
952    .. index:: rtems_rate_monotonic_period_statistics
953
954    .. code-block:: c
955
956        typedef struct {
957            uint32_t     count;
958            uint32_t     missed_count;
959            #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
960              struct timespec min_cpu_time;
961              struct timespec max_cpu_time;
962              struct timespec total_cpu_time;
963            #else
964              uint32_t  min_cpu_time;
965              uint32_t  max_cpu_time;
966              uint32_t  total_cpu_time;
967            #endif
968            #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
969              struct timespec min_wall_time;
970              struct timespec max_wall_time;
971              struct timespec total_wall_time;
972            #else
973             uint32_t  min_wall_time;
974             uint32_t  max_wall_time;
975             uint32_t  total_wall_time;
976            #endif
977        }  rtems_rate_monotonic_period_statistics;
978
979    This directive returns the current statistics information for the period
980    instance assocaited with ``id``.  The information returned is indicated by
981    the structure above.
982
983NOTES:
984    This directive will not cause the running task to be preempted.
985
986.. raw:: latex
987
988   \clearpage
989
990.. index:: reset statistics of period
991.. index:: rtems_rate_monotonic_reset_statistics
992
993.. _rtems_rate_monotonic_reset_statistics:
994
995RATE_MONOTONIC_RESET_STATISTICS - Reset statistics for a period
996---------------------------------------------------------------
997
998CALLING SEQUENCE:
999    .. code-block:: c
1000
1001        rtems_status_code rtems_rate_monotonic_reset_statistics(
1002            rtems_id  id
1003        );
1004
1005DIRECTIVE STATUS CODES:
1006    .. list-table::
1007     :class: rtems-table
1008
1009     * - ``RTEMS_SUCCESSFUL``
1010       - period initiated successfully
1011     * - ``RTEMS_INVALID_ID``
1012       - invalid rate monotonic period id
1013
1014DESCRIPTION:
1015    This directive resets the statistics information associated with this rate
1016    monotonic period instance.
1017
1018NOTES:
1019    This directive will not cause the running task to be preempted.
1020
1021.. raw:: latex
1022
1023   \clearpage
1024
1025.. index:: reset statistics of all periods
1026.. index:: rtems_rate_monotonic_reset_all_statistics
1027
1028.. _rtems_rate_monotonic_reset_all_statistics:
1029
1030RATE_MONOTONIC_RESET_ALL_STATISTICS - Reset statistics for all periods
1031----------------------------------------------------------------------
1032
1033CALLING SEQUENCE:
1034    .. code-block:: c
1035
1036        void rtems_rate_monotonic_reset_all_statistics(void);
1037
1038DIRECTIVE STATUS CODES:
1039    NONE
1040
1041DESCRIPTION:
1042    This directive resets the statistics information associated with all rate
1043    monotonic period instances.
1044
1045NOTES:
1046    This directive will not cause the running task to be preempted.
1047
1048.. raw:: latex
1049
1050   \clearpage
1051
1052.. index:: print period statistics report
1053.. index:: period statistics report
1054.. index:: rtems_rate_monotonic_report_statistics
1055
1056.. _rtems_rate_monotonic_report_statistics:
1057
1058RATE_MONOTONIC_REPORT_STATISTICS - Print period statistics report
1059-----------------------------------------------------------------
1060
1061CALLING SEQUENCE:
1062    .. code-block:: c
1063
1064        void rtems_rate_monotonic_report_statistics(void);
1065
1066DIRECTIVE STATUS CODES:
1067    NONE
1068
1069DESCRIPTION:
1070    This directive prints a report on all active periods which have executed at
1071    least one period. The following is an example of the output generated by
1072    this directive.
1073
1074    .. index:: rtems_rate_monotonic_period_statistics
1075
1076    .. code-block:: c
1077
1078        ID      OWNER   PERIODS  MISSED    CPU TIME    WALL TIME
1079        MIN/MAX/AVG  MIN/MAX/AVG
1080        0x42010001  TA1       502     0       0/1/0.99    0/0/0.00
1081        0x42010002  TA2       502     0       0/1/0.99    0/0/0.00
1082        0x42010003  TA3       501     0       0/1/0.99    0/0/0.00
1083        0x42010004  TA4       501     0       0/1/0.99    0/0/0.00
1084        0x42010005  TA5        10     0       0/1/0.90    0/0/0.00
1085
1086NOTES:
1087    This directive will not cause the running task to be preempted.
Note: See TracBrowser for help on using the repository browser.