source: rtems-docs/c_user/rate_monotonic_manager.rst @ 9aafb39

4.115
Last change on this file since 9aafb39 was e6fe68d, checked in by Chris Johns <chrisj@…>, on 09/13/16 at 23:23:27

c_user: Fix minor error.

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