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

4.115
Last change on this file since 4da4a15 was 4da4a15, checked in by Chris Johns <chrisj@…>, on 11/09/16 at 00:42:10

c-user: Fix header levels. Minor fixes.

  • Property mode set to 100644
File size: 41.6 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.. raw:: latex
643
644   \clearpage
645
646.. _rtems_rate_monotonic_create:
647
648RATE_MONOTONIC_CREATE - Create a rate monotonic period
649------------------------------------------------------
650.. index:: create a period
651.. index:: rtems_rate_monotonic_create
652
653CALLING SEQUENCE:
654    .. code-block:: c
655
656        rtems_status_code rtems_rate_monotonic_create(
657            rtems_name  name,
658            rtems_id   *id
659        );
660
661DIRECTIVE STATUS CODES:
662    .. list-table::
663     :class: rtems-table
664
665     * - ``RTEMS_SUCCESSFUL``
666       - rate monotonic period created successfully
667     * - ``RTEMS_INVALID_NAME``
668       - invalid period name
669     * - ``RTEMS_TOO_MANY``
670       - too many periods created
671
672DESCRIPTION:
673    This directive creates a rate monotonic period.  The assigned rate
674    monotonic id is returned in id.  This id is used to access the period with
675    other rate monotonic manager directives.  For control and maintenance of
676    the rate monotonic period, RTEMS allocates a PCB from the local PCB free
677    pool and initializes it.
678
679NOTES:
680    This directive will not cause the calling task to be preempted.
681
682.. raw:: latex
683
684   \clearpage
685
686.. _rtems_rate_monotonic_ident:
687
688RATE_MONOTONIC_IDENT - Get ID of a period
689-----------------------------------------
690.. index:: get ID of a period
691.. index:: obtain ID of a period
692.. index:: rtems_rate_monotonic_ident
693
694CALLING SEQUENCE:
695    .. code-block:: c
696
697        rtems_status_code rtems_rate_monotonic_ident(
698            rtems_name  name,
699            rtems_id   *id
700        );
701
702DIRECTIVE STATUS CODES:
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
711DESCRIPTION:
712    This directive obtains the period id associated with the period name to be
713    acquired.  If the period name is not unique, then the period id will match
714    one of the periods with that name.  However, this period id is not
715    guaranteed to correspond to the desired period.  The period id is used to
716    access this period in other rate monotonic manager directives.
717
718NOTES:
719    This directive will not cause the running task to be preempted.
720
721.. raw:: latex
722
723   \clearpage
724
725.. _rtems_rate_monotonic_cancel:
726
727RATE_MONOTONIC_CANCEL - Cancel a period
728---------------------------------------
729.. index:: cancel a period
730.. index:: rtems_rate_monotonic_cancel
731
732CALLING SEQUENCE:
733    .. code-block:: c
734
735        rtems_status_code rtems_rate_monotonic_cancel(
736            rtems_id id
737        );
738
739DIRECTIVE STATUS CODES:
740    .. list-table::
741     :class: rtems-table
742
743     * - ``RTEMS_SUCCESSFUL``
744       - period canceled successfully
745     * - ``RTEMS_INVALID_ID``
746       - invalid rate monotonic period id
747     * - ``RTEMS_NOT_OWNER_OF_RESOURCE``
748       - rate monotonic period not created by calling task
749
750DESCRIPTION:
751
752    This directive cancels the rate monotonic period id.  This period will be
753    reinitiated by the next invocation of ``rtems_rate_monotonic_period``
754    with id.
755
756NOTES:
757    This directive will not cause the running task to be preempted.
758
759    The rate monotonic period specified by id must have been created by the
760    calling task.
761
762.. raw:: latex
763
764   \clearpage
765
766.. _rtems_rate_monotonic_delete:
767.. index:: rtems_rate_monotonic_delete
768
769RATE_MONOTONIC_DELETE - Delete a rate monotonic period
770------------------------------------------------------
771.. index:: delete a period
772
773CALLING SEQUENCE:
774    .. code-block:: c
775
776        rtems_status_code rtems_rate_monotonic_delete(
777            rtems_id id
778        );
779
780DIRECTIVE STATUS CODES:
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
789DESCRIPTION:
790
791    This directive deletes the rate monotonic period specified by id.  If the
792    period is running, it is automatically canceled.  The PCB for the deleted
793    period is reclaimed by RTEMS.
794
795NOTES:
796    This directive will not cause the running task to be preempted.
797
798    A rate monotonic period can be deleted by a task other than the task which
799    created the period.
800
801.. raw:: latex
802
803   \clearpage
804
805.. _rtems_rate_monotonic_period:
806
807RATE_MONOTONIC_PERIOD - Conclude current/Start next period
808----------------------------------------------------------
809.. index:: conclude current period
810.. index:: start current period
811.. index:: period initiation
812.. index:: rtems_rate_monotonic_period
813
814CALLING SEQUENCE:
815    .. code-block:: c
816
817        rtems_status_code rtems_rate_monotonic_period(
818            rtems_id       id,
819            rtems_interval length
820        );
821
822DIRECTIVE STATUS CODES:
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
837DESCRIPTION:
838    This directive initiates the rate monotonic period id with a length of
839    period ticks.  If id is running, then the calling task will block for the
840    remainder of the period before reinitiating the period with the specified
841    period.  If id was not running (either expired or never initiated), the
842    period is immediately initiated and the directive returns immediately.
843
844    If invoked with a period of ``RTEMS_PERIOD_STATUS`` ticks, the current
845    state of id will be returned.  The directive status indicates the current
846    state of the period.  This does not alter the state or period of the
847    period.
848
849NOTES:
850    This directive will not cause the running task to be preempted.
851
852.. raw:: latex
853
854   \clearpage
855
856.. _rtems_rate_monotonic_get_status:
857
858RATE_MONOTONIC_GET_STATUS - Obtain status from a period
859-------------------------------------------------------
860.. index:: get status of period
861.. index:: obtain status of period
862.. index:: rtems_rate_monotonic_get_status
863
864CALLING SEQUENCE:
865    .. code-block:: c
866
867        rtems_status_code rtems_rate_monotonic_get_status(
868            rtems_id                            id,
869            rtems_rate_monotonic_period_status *status
870        );
871
872DIRECTIVE STATUS CODES:
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    This directive returns status information associated with the rate
885    monotonic period id in the following data structure:
886
887    .. index:: rtems_rate_monotonic_period_status
888
889    .. code-block:: c
890
891        typedef struct {
892            rtems_id                              owner;
893            rtems_rate_monotonic_period_states    state;
894            rtems_rate_monotonic_period_time_t    since_last_period;
895            rtems_thread_cpu_usage_t              executed_since_last_period;
896        }  rtems_rate_monotonic_period_status;
897
898    .. COMMENT: RATE_MONOTONIC_INACTIVE does not have RTEMS in front of it.
899
900    A configure time option can be used to select whether the time information
901    is given in ticks or seconds and nanoseconds.  The default is seconds and
902    nanoseconds.  If the period's state is ``RATE_MONOTONIC_INACTIVE``, both
903    time values will be set to 0.  Otherwise, both time values will contain
904    time information since the last invocation of the
905    ``rtems_rate_monotonic_period`` directive.  More specifically, the
906    ticks_since_last_period value contains the elapsed time which has occurred
907    since the last invocation of the ``rtems_rate_monotonic_period`` directive
908    and the ``ticks_executed_since_last_period`` contains how much processor
909    time the owning task has consumed since the invocation of the
910    ``rtems_rate_monotonic_period`` directive.
911
912NOTES:
913    This directive will not cause the running task to be preempted.
914
915.. raw:: latex
916
917   \clearpage
918
919.. _rtems_rate_monotonic_get_statistics:
920
921RATE_MONOTONIC_GET_STATISTICS - Obtain statistics from a period
922---------------------------------------------------------------
923.. index:: get statistics of period
924.. index:: obtain statistics of period
925.. index:: rtems_rate_monotonic_get_statistics
926
927CALLING SEQUENCE:
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
935DIRECTIVE STATUS CODES:
936    .. list-table::
937     :class: rtems-table
938
939     * - ``RTEMS_SUCCESSFUL``
940       - period initiated successfully
941     * - ``RTEMS_INVALID_ID``
942       - invalid rate monotonic period id
943     * - ``RTEMS_INVALID_ADDRESS``
944       - invalid address of statistics
945
946DESCRIPTION:
947    This directive returns statistics information associated with the rate
948    monotonic period id in the following data structure:
949
950    .. index:: rtems_rate_monotonic_period_statistics
951
952    .. code-block:: c
953
954        typedef struct {
955            uint32_t     count;
956            uint32_t     missed_count;
957            #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
958              struct timespec min_cpu_time;
959              struct timespec max_cpu_time;
960              struct timespec total_cpu_time;
961            #else
962              uint32_t  min_cpu_time;
963              uint32_t  max_cpu_time;
964              uint32_t  total_cpu_time;
965            #endif
966            #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
967              struct timespec min_wall_time;
968              struct timespec max_wall_time;
969              struct timespec total_wall_time;
970            #else
971             uint32_t  min_wall_time;
972             uint32_t  max_wall_time;
973             uint32_t  total_wall_time;
974            #endif
975        }  rtems_rate_monotonic_period_statistics;
976
977    This directive returns the current statistics information for the period
978    instance assocaited with ``id``.  The information returned is indicated by
979    the structure above.
980
981NOTES:
982    This directive will not cause the running task to be preempted.
983
984.. raw:: latex
985
986   \clearpage
987
988.. _rtems_rate_monotonic_reset_statistics:
989
990RATE_MONOTONIC_RESET_STATISTICS - Reset statistics for a period
991---------------------------------------------------------------
992.. index:: reset statistics of period
993.. index:: rtems_rate_monotonic_reset_statistics
994
995CALLING SEQUENCE:
996    .. code-block:: c
997
998        rtems_status_code rtems_rate_monotonic_reset_statistics(
999            rtems_id  id
1000        );
1001
1002DIRECTIVE STATUS CODES:
1003    .. list-table::
1004     :class: rtems-table
1005
1006     * - ``RTEMS_SUCCESSFUL``
1007       - period initiated successfully
1008     * - ``RTEMS_INVALID_ID``
1009       - invalid rate monotonic period id
1010
1011DESCRIPTION:
1012    This directive resets the statistics information associated with this rate
1013    monotonic period instance.
1014
1015NOTES:
1016    This directive will not cause the running task to be preempted.
1017
1018.. raw:: latex
1019
1020   \clearpage
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.. index:: rtems_rate_monotonic_reset_all_statistics
1028
1029CALLING SEQUENCE:
1030    .. code-block:: c
1031
1032        void rtems_rate_monotonic_reset_all_statistics(void);
1033
1034DIRECTIVE STATUS CODES:
1035    NONE
1036
1037DESCRIPTION:
1038    This directive resets the statistics information associated with all rate
1039    monotonic period instances.
1040
1041NOTES:
1042    This directive will not cause the running task to be preempted.
1043
1044.. raw:: latex
1045
1046   \clearpage
1047
1048.. _rtems_rate_monotonic_report_statistics:
1049
1050RATE_MONOTONIC_REPORT_STATISTICS - Print period statistics report
1051-----------------------------------------------------------------
1052.. index:: print period statistics report
1053.. index:: period statistics report
1054.. index:: rtems_rate_monotonic_report_statistics
1055
1056CALLING SEQUENCE:
1057    .. code-block:: c
1058
1059        void rtems_rate_monotonic_report_statistics(void);
1060
1061DIRECTIVE STATUS CODES:
1062    NONE
1063
1064DESCRIPTION:
1065    This directive prints a report on all active periods which have executed at
1066    least one period. The following is an example of the output generated by
1067    this directive.
1068
1069    .. index:: rtems_rate_monotonic_period_statistics
1070
1071    .. code-block:: c
1072
1073        ID      OWNER   PERIODS  MISSED    CPU TIME    WALL TIME
1074        MIN/MAX/AVG  MIN/MAX/AVG
1075        0x42010001  TA1       502     0       0/1/0.99    0/0/0.00
1076        0x42010002  TA2       502     0       0/1/0.99    0/0/0.00
1077        0x42010003  TA3       501     0       0/1/0.99    0/0/0.00
1078        0x42010004  TA4       501     0       0/1/0.99    0/0/0.00
1079        0x42010005  TA5        10     0       0/1/0.90    0/0/0.00
1080
1081NOTES:
1082    This directive will not cause the running task to be preempted.
Note: See TracBrowser for help on using the repository browser.