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

5
Last change on this file since 938c49e was 938c49e, checked in by Sebastian Huber <sebastian.huber@…>, on 01/31/17 at 11:59:08

Fix refs.bib entry

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