source: rtems/doc/user/rtmon.t @ a94c5a5d

4.104.114.84.95
Last change on this file since a94c5a5d was a94c5a5d, checked in by Joel Sherrill <joel.sherrill@…>, on 05/31/97 at 15:55:10

Changed bitwise OR's used to build up option and attribute sets
to be correct in either C or Ada.

Added the interrupt disable, enable, flash, and is in progress directives.

changed "97" to "1997"

  • Property mode set to 100644
File size: 42.1 KB
Line 
1@c
2@c  COPYRIGHT (c) 1996.
3@c  On-Line Applications Research Corporation (OAR).
4@c  All rights reserved.
5@c
6
7@c
8@c  Open Issues
9@c    - nicen up the tables
10@c    - use math mode to print formulas
11@c
12
13@ifinfo
14@node Rate Monotonic Manager, Rate Monotonic Manager Introduction, Scheduling Concepts Task State Transitions, Top
15@end ifinfo
16@chapter Rate Monotonic Manager
17@ifinfo
18@menu
19* Rate Monotonic Manager Introduction::
20* Rate Monotonic Manager Background::
21* Rate Monotonic Manager Operations::
22* Rate Monotonic Manager Directives::
23@end menu
24@end ifinfo
25
26@ifinfo
27@node Rate Monotonic Manager Introduction, Rate Monotonic Manager Background, Rate Monotonic Manager, Rate Monotonic Manager
28@end ifinfo
29@section Introduction
30
31The rate monotonic manager provides facilities to
32implement tasks which execute in a periodic fashion.  The
33directives provided by the rate monotonic manager are:
34
35@itemize @bullet
36@item @code{rate_monotonic_create} - Create a rate monotonic period
37@item @code{rate_monotonic_ident} - Get ID of a period
38@item @code{rate_monotonic_cancel} - Cancel a period
39@item @code{rate_monotonic_delete} - Delete a rate monotonic period
40@item @code{rate_monotonic_period} - Conclude current/Start next period
41@item @code{rate_monotonic_get_status} - Obtain status information on period
42@end itemize
43
44@ifinfo
45@node Rate Monotonic Manager Background, Rate Monotonic Manager Definitions, Rate Monotonic Manager Introduction, Rate Monotonic Manager
46@end ifinfo
47@section Background
48@ifinfo
49@menu
50* Rate Monotonic Manager Definitions::
51* Rate Monotonic Scheduling Algorithm::
52* Schedulability Analysis::
53* Assumptions::
54* Processor Utilization Rule::
55* Processor Utilization Rule Example::
56* First Deadline Rule::
57* First Deadline Rule Example::
58* Relaxation of Assumptions::
59* Further Reading::
60@end menu
61@end ifinfo
62
63The rate monotonic manager provides facilities to
64manage the execution of periodic tasks.  This manager was
65designed to support application designers who utilize the Rate
66Monotonic Scheduling Algorithm (RMS) to insure that their
67periodic tasks will meet their deadlines, even under transient
68overload conditions.  Although designed for hard real-time
69systems, the services provided by the rate monotonic manager may
70be used by any application which requires periodic tasks.
71
72@ifinfo
73@node Rate Monotonic Manager Definitions, Rate Monotonic Scheduling Algorithm, Rate Monotonic Manager Background, Rate Monotonic Manager Background
74@end ifinfo
75@subsection Rate Monotonic Manager Definitions
76
77A periodic task is one which must be executed at a
78regular interval.  The interval between successive iterations of
79the task is referred to as its period.  Periodic tasks can be
80characterized by the length of their period and execution time.
81The period and execution time of a task can be used to determine
82the processor utilization for that task.  Processor utilization
83is the percentage of processor time used and can be calculated
84on a per-task or system-wide basis.  Typically, the task's
85worst-case execution time will be less than its period.  For
86example, a periodic task's requirements may state that it should
87execute for 10 milliseconds every 100 milliseconds.  Although
88the execution time may be the average, worst, or best case, the
89worst-case execution time is more appropriate for use when
90analyzing system behavior under transient overload conditions.
91
92In contrast, an aperiodic task executes at irregular
93intervals and has only a soft deadline.  In other words, the
94deadlines for aperiodic tasks are not rigid, but adequate
95response times are desirable.  For example, an aperiodic task
96may process user input from a terminal.
97
98Finally, a sporadic task is an aperiodic task with a
99hard deadline and minimum interarrival time.  The minimum
100interarrival time is the minimum period of time which exists
101between successive iterations of the task.  For example, a
102sporadic task could be used to process the pressing of a fire
103button on a joystick.  The mechanical action of the fire button
104insures a minimum time period between successive activations,
105but the missile must be launched by a hard deadline.
106
107@ifinfo
108@node Rate Monotonic Scheduling Algorithm, Schedulability Analysis, Rate Monotonic Manager Definitions, Rate Monotonic Manager Background
109@end ifinfo
110@subsection Rate Monotonic Scheduling Algorithm
111
112The Rate Monotonic Scheduling Algorithm (RMS) is
113important to real-time systems designers because it allows one
114to guarantee that a set of tasks is schedulable.  A set of tasks
115is said to be schedulable if all of the tasks can meet their
116deadlines.  RMS provides a set of rules which can be used to
117perform a guaranteed schedulability analysis for a task set.
118This analysis determines whether a task set is schedulable under
119worst-case conditions and emphasizes the predictability of the
120system's behavior.  It has been proven that:
121
122@itemize @code{ }
123@b{RMS is an optimal static priority algorithm for
124scheduling independent, preemptible, periodic tasks
125on a single processor.}
126@end itemize
127
128RMS is optimal in the sense that if a set of tasks
129can be scheduled by any static priority algorithm, then RMS will
130be able to schedule that task set.  RMS bases it schedulability
131analysis on the processor utilization level below which all
132deadlines can be met.
133
134RMS calls for the static assignment of task
135priorities based upon their period.  The shorter a task's
136period, the higher its priority.  For example, a task with a 1
137millisecond period has higher priority than a task with a 100
138millisecond period.  If two tasks have the same period, than RMS
139does not distinguish between the tasks.  However, RTEMS
140specifies that when given tasks of equal priority, the task
141which has been ready longest will execute first.  RMS's priority
142assignment scheme does not provide one with exact numeric values
143for task priorities.  For example, consider the following task
144set and priority assignments:
145
146@ifset use-ascii
147@example
148@group
149+--------------------+---------------------+---------------------+
150|        Task        |       Period        |      Priority       |
151|                    |  (in milliseconds)  |                     |
152+--------------------+---------------------+---------------------+
153|         1          |         100         |         Low         |
154+--------------------+---------------------+---------------------+
155|         2          |          50         |       Medium        |
156+--------------------+---------------------+---------------------+
157|         3          |          50         |       Medium        |
158+--------------------+---------------------+---------------------+
159|         4          |          25         |        High         |
160+--------------------+---------------------+---------------------+
161@end group
162@end example
163@end ifset
164
165@ifset use-tex
166@sp 1
167@tex
168\centerline{\vbox{\offinterlineskip\halign{
169\vrule\strut#&
170\hbox to 0.75in{\enskip\hfil#\hfil}&
171\vrule#&
172\hbox to 1.25in{\enskip\hfil#\hfil}&
173\vrule#&
174\hbox to 1.25in{\enskip\hfil#\hfil}&
175\vrule#\cr\noalign{\hrule}
176&\bf Task&& \bf Period && \bf Priority &\cr
177& && \bf (in milliseconds) && &\cr\noalign{\hrule}
178& 1 && 100 && Low &\cr\noalign{\hrule}
179& 2 && 50 && Medium &\cr\noalign{\hrule}
180& 3 && 50 && Medium &\cr\noalign{\hrule}
181& 4 && 25 && Low &\cr\noalign{\hrule}
182}}\hfil}
183@end tex
184@end ifset
185
186@ifset use-html
187@html
188<CENTER>
189  <TABLE COLS=3 WIDTH="80%" BORDER=2>
190<TR><TD ALIGN=center><STRONG>Task</STRONG></TD>
191    <TD ALIGN=center><STRONG>Period (in milliseconds)</STRONG></TD>
192    <TD ALIGN=center><STRONG>Priority</STRONG></TD></TR>
193<TR><TD ALIGN=center>1</TD>
194    <TD ALIGN=center>100 </TD>
195    <TD ALIGN=center>Low</TD></TR>
196<TR><TD ALIGN=center>2</TD>
197    <TD ALIGN=center>50 </TD>
198    <TD ALIGN=center>Medium</TD></TR>
199<TR><TD ALIGN=center>3</TD>
200    <TD ALIGN=center>50 </TD>
201    <TD ALIGN=center>Medium</TD></TR>
202<TR><TD ALIGN=center>4</TD>
203    <TD ALIGN=center>25 </TD>
204    <TD ALIGN=center>High</TD></TR>
205  </TABLE>
206</CENTER>
207@end html
208@end ifset
209
210RMS only calls for task 1 to have the lowest
211priority, task 4 to have the highest priority, and tasks 2 and 3
212to have an equal priority between that of tasks 1 and 4.  The
213actual RTEMS priorities assigned to the tasks must only adhere
214to those guidelines.
215
216Many applications have tasks with both hard and soft
217deadlines.  The tasks with hard deadlines are typically referred
218to as the critical task set, with the soft deadline tasks being
219the non-critical task set.  The critical task set can be
220scheduled using RMS, with the non-critical tasks not executing
221under transient overload, by simply assigning priorities such
222that the lowest priority critical task (i.e. longest period) has
223a higher priority than the highest priority non-critical task.
224Although RMS may be used to assign priorities to the
225non-critical tasks, it is not necessary.  In this instance,
226schedulability is only guaranteed for the critical task set.
227
228@ifinfo
229@node Schedulability Analysis, Assumptions, Rate Monotonic Scheduling Algorithm, Rate Monotonic Manager Background
230@end ifinfo
231@subsection Schedulability Analysis
232
233RMS allows application designers to insure that tasks
234can meet all deadlines, even under transient overload, without
235knowing exactly when any given task will execute by applying
236proven schedulability analysis rules.
237
238@lowersections
239
240@ifinfo
241@node Assumptions, Processor Utilization Rule, Schedulability Analysis, Rate Monotonic Manager Background
242@end ifinfo
243@subsection Assumptions
244
245The schedulability analysis rules for RMS were
246developed based on the following assumptions:
247
248
249@itemize @bullet
250@item The requests for all tasks for which hard deadlines
251exist are periodic, with a constant interval between requests.
252
253@item Each task must complete before the next request for it
254occurs.
255
256@item The tasks are independent in that a task does not depend
257on the initiation or completion of requests for other tasks.
258
259@item The execution time for each task without preemption or
260interruption is constant and does not vary.
261
262@item Any non-periodic tasks in the system are special.  These
263tasks displace periodic tasks while executing and do not have
264hard, critical deadlines.
265@end itemize
266
267Once the basic schedulability analysis is understood,
268some of the above assumptions can be relaxed and the
269side-effects accounted for.
270
271@ifinfo
272@node Processor Utilization Rule, Processor Utilization Rule Example, Assumptions, Rate Monotonic Manager Background
273@end ifinfo
274@subsection Processor Utilization Rule
275
276The Processor Utilization Rule requires that
277processor utilization be calculated based upon the period and
278execution time of each task.  The fraction of processor time
279spent executing task index is Time(index) / Period(index).  The
280processor utilization can be calculated as follows:
281
282@example
283@group
284Utilization = 0
285
286for index = 1 to maximum_tasks
287  Utilization = Utilization + (Time(index)/Period(index))
288@end group
289@end example
290
291To insure schedulability even under transient
292overload, the processor utilization must adhere to the following
293rule:
294
295@example
296Utilization = maximum_tasks * (2(1/maximum_tasks) - 1)
297@end example
298
299As the number of tasks increases, the above formula
300approaches ln(2) for a worst-case utilization factor of
301approximately 0.693.  Many tasks sets can be scheduled with a
302greater utilization factor.  In fact, the average processor
303utilization threshold for a randomly generated task set is
304approximately 0.88.
305
306@ifinfo
307@node Processor Utilization Rule Example, First Deadline Rule, Processor Utilization Rule, Rate Monotonic Manager Background
308@end ifinfo
309@subsection Processor Utilization Rule Example
310
311This example illustrates the application of the
312Processor Utilization Rule to an application with three critical
313periodic tasks.  The following table details the RMS priority,
314period, execution time, and processor utilization for each task:
315
316@ifset use-ascii
317@example
318@group
319    +------------+----------+--------+-----------+-------------+
320    |    Task    |   RMS    | Period | Execution |  Processor  |
321    |            | Priority |        |   Time    | Utilization |
322    +------------+----------+--------+-----------+-------------+
323    |     1      |   High   |  100   |    15     |    0.15     |
324    +------------+----------+--------+-----------+-------------+
325    |     2      |  Medium  |  200   |    50     |    0.25     |
326    +------------+----------+--------+-----------+-------------+
327    |     3      |   Low    |  300   |   100     |    0.33     |
328    +------------+----------+--------+-----------+-------------+
329@end group
330@end example
331@end ifset
332
333@ifset use-tex
334@sp 1
335@tex
336\centerline{\vbox{\offinterlineskip\halign{
337\vrule\strut#&
338\hbox to 0.75in{\enskip\hfil#\hfil}&
339\vrule#&
340\hbox to 0.75in{\enskip\hfil#\hfil}&
341\vrule#&
342\hbox to 0.75in{\enskip\hfil#\hfil}&
343\vrule#&
344\hbox to 1.00in{\enskip\hfil#\hfil}&
345\vrule#&
346\hbox to 1.00in{\enskip\hfil#\hfil}&
347\vrule#\cr\noalign{\hrule}
348&\bf Task&& \bf RMS && \bf Period && \bf Execution &&\bf Processor&\cr
349& && \bf Priority && &&\bf Time &&\bf Utilization &\cr\noalign{\hrule}
350& 1 && High && 100 && 15 && 0.15 &\cr\noalign{\hrule}
351& 2 && Medium && 200 && 50 && 0.25 &\cr\noalign{\hrule}
352& 3 && Low && 300 && 100 && 0.33 &\cr\noalign{\hrule}
353}}\hfil}
354@end tex
355@end ifset
356 
357@ifset use-html
358@html
359<CENTER>
360  <TABLE COLS=5 WIDTH="80%" BORDER=2>
361<TR><TD ALIGN=center><STRONG>Task</STRONG></TD>
362    <TD ALIGN=center><STRONG>RMS Priority</STRONG></TD>
363    <TD ALIGN=center><STRONG>Period</STRONG></TD>
364    <TD ALIGN=center><STRONG>Execution Time</STRONG></TD>
365    <TD ALIGN=center><STRONG>Processor Utilization</STRONG></TD></TR>
366<TR><TD ALIGN=center>1</TD>
367    <TD ALIGN=center>High</TD>
368    <TD ALIGN=center>100</TD>
369    <TD ALIGN=center>15</TD>
370    <TD ALIGN=center>0.15</TD></TR>
371<TR><TD ALIGN=center>2</TD>
372    <TD ALIGN=center>Medium</TD>
373    <TD ALIGN=center>200</TD>
374    <TD ALIGN=center>50</TD>
375    <TD ALIGN=center>0.25</TD></TR>
376<TR><TD ALIGN=center>3</TD>
377    <TD ALIGN=center>Low</TD>
378    <TD ALIGN=center>300</TD>
379    <TD ALIGN=center>100</TD>
380    <TD ALIGN=center>0.33</TD></TR>
381  </TABLE>
382</CENTER>
383@end html
384@end ifset
385
386The total processor utilization for this task set is
3870.73 which is below the upper bound of 3 * (2(1/3) - 1), or
3880.779, imposed by the Processor Utilization Rule.  Therefore,
389this task set is guaranteed to be schedulable using RMS.
390
391@ifinfo
392@node First Deadline Rule, First Deadline Rule Example, Processor Utilization Rule Example, Rate Monotonic Manager Background
393@end ifinfo
394@subsection First Deadline Rule
395
396If a given set of tasks do exceed the processor
397utilization upper limit imposed by the Processor Utilization
398Rule, they can still be guaranteed to meet all their deadlines
399by application of the First Deadline Rule.  This rule can be
400stated as follows:
401
402For a given set of independent periodic tasks, if
403each task meets its first deadline when all tasks are started at
404the same time, then the deadlines will always be met for any
405combination of start times.
406
407A key point with this rule is that ALL periodic tasks
408are assumed to start at the exact same instant in time.
409Although this assumption may seem to be invalid,  RTEMS makes it
410quite easy to insure.  By having a non-preemptible user
411initialization task, all application tasks, regardless of
412priority, can be created and started before the initialization
413deletes itself.  This technique insures that all tasks begin to
414compete for execution time at the same instant -- when the user
415initialization task deletes itself.
416
417@ifinfo
418@node First Deadline Rule Example, Relaxation of Assumptions, First Deadline Rule, Rate Monotonic Manager Background
419@end ifinfo
420@subsection First Deadline Rule Example
421
422The First Deadline Rule can insure schedulability
423even when the Processor Utilization Rule fails.  The example
424below is a modification of the Processor Utilization Rule
425example where task execution time has been increased from 15 to
42625 units.  The following table details the RMS priority, period,
427execution time, and processor utilization for each task:
428
429@ifset use-ascii
430@example
431@group
432    +------------+----------+--------+-----------+-------------+
433    |    Task    |   RMS    | Period | Execution |  Processor  |
434    |            | Priority |        |   Time    | Utilization |
435    +------------+----------+--------+-----------+-------------+
436    |     1      |   High   |  100   |    25     |    0.25     |
437    +------------+----------+--------+-----------+-------------+
438    |     2      |  Medium  |  200   |    50     |    0.25     |
439    +------------+----------+--------+-----------+-------------+
440    |     3      |   Low    |  300   |   100     |    0.33     |
441    +------------+----------+--------+-----------+-------------+
442@end group
443@end example
444@end ifset
445
446@ifset use-tex
447@sp 1
448@tex
449\centerline{\vbox{\offinterlineskip\halign{
450\vrule\strut#&
451\hbox to 0.75in{\enskip\hfil#\hfil}&
452\vrule#&
453\hbox to 0.75in{\enskip\hfil#\hfil}&
454\vrule#&
455\hbox to 0.75in{\enskip\hfil#\hfil}&
456\vrule#&
457\hbox to 1.00in{\enskip\hfil#\hfil}&
458\vrule#&
459\hbox to 1.00in{\enskip\hfil#\hfil}&
460\vrule#\cr\noalign{\hrule}
461&\bf Task&& \bf RMS && \bf Period && \bf Execution &&\bf Processor&\cr
462& && \bf Priority && &&\bf Time &&\bf Utilization &\cr\noalign{\hrule}
463& 1 && High && 100 && 25 && 0.25 &\cr\noalign{\hrule}
464& 2 && Medium && 200 && 50 && 0.25 &\cr\noalign{\hrule}
465& 3 && Low && 300 && 100 && 0.33 &\cr\noalign{\hrule}
466}}\hfil}
467@end tex
468@end ifset
469 
470@ifset use-html
471@html
472<CENTER>
473  <TABLE COLS=5 WIDTH="80%" BORDER=2>
474<TR><TD ALIGN=center><STRONG>Task</STRONG></TD>
475    <TD ALIGN=center><STRONG>RMS Priority</STRONG></TD>
476    <TD ALIGN=center><STRONG>Period</STRONG></TD>
477    <TD ALIGN=center><STRONG>Execution Time</STRONG></TD>
478    <TD ALIGN=center><STRONG>Processor Utilization</STRONG></TD></TR>
479<TR><TD ALIGN=center>1</TD>
480    <TD ALIGN=center>High</TD>
481    <TD ALIGN=center>100</TD>
482    <TD ALIGN=center>25</TD>
483    <TD ALIGN=center>0.25</TD></TR>
484<TR><TD ALIGN=center>2</TD>
485    <TD ALIGN=center>Medium</TD>
486    <TD ALIGN=center>200</TD>
487    <TD ALIGN=center>50</TD>
488    <TD ALIGN=center>0.25</TD></TR>
489<TR><TD ALIGN=center>3</TD>
490    <TD ALIGN=center>Low</TD>
491    <TD ALIGN=center>300</TD>
492    <TD ALIGN=center>100</TD>
493    <TD ALIGN=center>0.33</TD></TR>
494  </TABLE>
495</CENTER>
496@end html
497@end ifset
498
499The total processor utilization for the modified task
500set is 0.83 which is above the upper bound of 3 * (2(1/3) - 1),
501or 0.779, imposed by the Processor Utilization Rule.  Therefore,
502this task set is not guaranteed to be schedulable using RMS.
503However, the First Deadline Rule can guarantee the
504schedulability of this task set.  This rule calls for one to
505examine each occurrence of deadline until either all tasks have
506met their deadline or one task failed to meet its first
507deadline.  The following table details the time of each deadline
508occurrence, the maximum number of times each task may have run,
509the total execution time, and whether all the deadlines have
510been met.
511
512@ifset use-ascii
513@example
514@group
515+----------+------+------+------+----------------------+---------------+
516| Deadline | Task | Task | Task |        Total         | All Deadlines |
517|   Time   |  1   |  2   |  3   |    Execution Time    |     Met?      |
518+----------+------+------+------+----------------------+---------------+
519|   100    |  1   |  1   |  1   |  25 + 50 + 100 = 175 |      NO       |
520+----------+------+------+------+----------------------+---------------+
521|   200    |  2   |  1   |  1   |  50 + 50 + 100 = 200 |     YES       |
522+----------+------+------+------+----------------------+---------------+
523@end group
524@end example
525@end ifset
526
527@ifset use-tex
528@sp 1
529@tex
530\centerline{\vbox{\offinterlineskip\halign{
531\vrule\strut#&
532\hbox to 0.75in{\enskip\hfil#\hfil}&
533\vrule#&
534\hbox to 0.75in{\enskip\hfil#\hfil}&
535\vrule#&
536\hbox to 0.75in{\enskip\hfil#\hfil}&
537\vrule#&
538\hbox to 0.75in{\enskip\hfil#\hfil}&
539\vrule#&
540\hbox to 2.00in{\enskip\hfil#\hfil}&
541\vrule#&
542\hbox to 1.00in{\enskip\hfil#\hfil}&
543\vrule#\cr\noalign{\hrule}
544&\bf Deadline&& \bf Task &&\bf Task&&\bf Task&&\bf Total          &&\bf All Deadlines &\cr
545&\bf Time    && \bf 1    &&\bf 2   &&\bf 3   &&\bf Execution Time &&\bf Net?&\cr\noalign{\hrule}
546& 100&& 1 && 1 && 1 && 25 + 50 + 100 = 175 && NO &\cr\noalign{\hrule}
547& 200&& 2 && 1 && 1 && 50 + 50 + 100 = 200 && YES &\cr\noalign{\hrule}
548}}\hfil}
549@end tex
550@end ifset
551 
552@ifset use-html
553@html
554<CENTER>
555  <TABLE COLS=6 WIDTH="80%" BORDER=2>
556<TR><TD ALIGN=center><STRONG>Deadline Time</STRONG></TD>
557    <TD ALIGN=center><STRONG>Task 1</STRONG></TD>
558    <TD ALIGN=center><STRONG>Task 2</STRONG></TD>
559    <TD ALIGN=center><STRONG>Task 3</STRONG></TD>
560    <TD ALIGN=center><STRONG>Total Execution Time</STRONG></TD>
561    <TD ALIGN=center><STRONG>All Deadlines Met?</STRONG></TD></TR>
562<TR><TD ALIGN=center>100</TD>
563    <TD ALIGN=center>1</TD>
564    <TD ALIGN=center>1</TD>
565    <TD ALIGN=center>1</TD>
566    <TD ALIGN=center>25 + 50 + 100 = 175</TD>
567    <TD ALIGN=center>NO</TD></TR>
568<TR><TD ALIGN=center>200</TD>
569    <TD ALIGN=center>2</TD>
570    <TD ALIGN=center>1</TD>
571    <TD ALIGN=center>1</TD>
572    <TD ALIGN=center>50 + 50 + 100 = 175</TD>
573    <TD ALIGN=center>YES</TD></TR>
574  </TABLE>
575</CENTER>
576@end html
577@end ifset
578
579The key to this analysis is to recognize when each
580task will execute.  For example at time 100, task 1 must have
581met its first deadline, but tasks 2 and 3 may also have begun
582execution.  In this example, at time 100 tasks 1 and 2 have
583completed execution and thus have met their first deadline.
584Tasks 1 and 2 have used (25 + 50) = 75 time units, leaving (100
585- 75) = 25 time units for task 3 to begin.  Because task 3 takes
586100 ticks to execute, it will not have completed execution at
587time 100.  Thus at time 100, all of the tasks except task 3 have
588met their first deadline.
589
590At time 200, task 1 must have met its second deadline
591and task 2 its first deadline.  As a result, of the first 200
592time units, task 1 uses (2 * 25) = 50 and task 2 uses 50,
593leaving (200 - 100) time units for task 3.  Task 3 requires 100
594time units to execute, thus it will have completed execution at
595time 200.  Thus, all of the tasks have met their first deadlines
596at time 200, and the task set is schedulable using the First
597Deadline Rule.
598
599@ifinfo
600@node Relaxation of Assumptions, Further Reading, First Deadline Rule Example, Rate Monotonic Manager Background
601@end ifinfo
602@subsection Relaxation of Assumptions
603
604The assumptions used to develop the RMS
605schedulability rules are uncommon in most real-time systems.
606For example, it was assumed that tasks have constant unvarying
607execution time.  It is possible to relax this assumption, simply
608by using the worst-case execution time of each task.
609
610Another assumption is that the tasks are independent.
611This means that the tasks do not wait for one another or
612contend for resources.  This assumption can be relaxed by
613accounting for the amount of time a task spends waiting to
614acquire resources.  Similarly, each task's execution time must
615account for any I/O performed and any RTEMS directive calls.
616
617In addition, the assumptions did not account for the
618time spent executing interrupt service routines.  This can be
619accounted for by including all the processor utilization by
620interrupt service routines in the utilization calculation.
621Similarly, one should also account for the impact of delays in
622accessing local memory caused by direct memory access and other
623processors accessing local dual-ported memory.
624
625The assumption that nonperiodic tasks are used only
626for initialization or failure-recovery can be relaxed by placing
627all periodic tasks in the critical task set.  This task set can
628be scheduled and analyzed using RMS.  All nonperiodic tasks are
629placed in the non-critical task set.  Although the critical task
630set can be guaranteed to execute even under transient overload,
631the non-critical task set is not guaranteed to execute.
632
633In conclusion, the application designer must be fully
634cognizant of the system and its run-time behavior when
635performing schedulability analysis for a system using RMS.
636Every hardware and software factor which impacts the execution
637time of each task must be accounted for in the schedulability
638analysis.
639
640@ifinfo
641@node Further Reading, Rate Monotonic Manager Operations, Relaxation of Assumptions, Rate Monotonic Manager Background
642@end ifinfo
643@subsection Further Reading
644
645For more information on Rate Monotonic Scheduling and
646its schedulability analysis, the reader is referred to the
647following:
648
649@itemize @code{ }
650@item @cite{C. L. Liu and J. W. Layland. "Scheduling Algorithms for
651Multiprogramming in a Hard Real Time Environment." @b{Journal of
652the Association of Computing Machinery}. January 1973. pp. 46-61.}
653
654@item @cite{John Lehoczky, Lui Sha, and Ye Ding. "The Rate Monotonic
655Scheduling Algorithm: Exact Characterization and Average Case
656Behavior."  @b{IEEE Real-Time Systems Symposium}. 1989. pp. 166-171.}
657
658@item @cite{Lui Sha and John Goodenough. "Real-Time Scheduling
659Theory and Ada."  @b{IEEE Computer}. April 1990. pp. 53-62.}
660
661@item @cite{Alan Burns. "Scheduling hard real-time systems: a
662review."  @b{Software Engineering Journal}. May 1991. pp. 116-128.}
663@end itemize
664
665@raisesections
666
667@ifinfo
668@node Rate Monotonic Manager Operations, Creating a Rate Monotonic Period, Further Reading, Rate Monotonic Manager
669@end ifinfo
670@section Operations
671@ifinfo
672@menu
673* Creating a Rate Monotonic Period::
674* Manipulating a Period::
675* Obtaining a Period's Status::
676* Canceling a Period::
677* Deleting a Rate Monotonic Period::
678* Examples::
679* Simple Periodic Task::
680* Task with Multiple Periods::
681@end menu
682@end ifinfo
683
684@ifinfo
685@node Creating a Rate Monotonic Period, Manipulating a Period, Rate Monotonic Manager Operations, Rate Monotonic Manager Operations
686@end ifinfo
687@subsection Creating a Rate Monotonic Period
688
689The rate_monotonic_create directive creates a rate
690monotonic period which is to be used by the calling task to
691delineate a period.  RTEMS allocates a Period Control Block
692(PCB) from the PCB free list.  This data structure is used by
693RTEMS to manage the newly created rate monotonic period.  RTEMS
694returns a unique period ID to the application which is used by
695other rate monotonic manager directives to access this rate
696monotonic period.
697
698@ifinfo
699@node Manipulating a Period, Obtaining a Period's Status, Creating a Rate Monotonic Period, Rate Monotonic Manager Operations
700@end ifinfo
701@subsection Manipulating a Period
702
703The rate_monotonic_period directive is used to
704establish and maintain periodic execution utilizing a previously
705created rate monotonic period.   Once initiated by the
706rate_monotonic_period directive, the period is said to run until
707it either expires or is reinitiated.  The state of the rate
708monotonic period results in one of the following scenarios:
709
710@itemize @bullet
711@item If the rate monotonic period is running, the calling
712task will be blocked for the remainder of the outstanding period
713and, upon completion of that period, the period will be
714reinitiated with the specified period.
715
716@item If the rate monotonic period is not currently running
717and has not expired, it is initiated with a length of period
718ticks and the calling task returns immediately.
719
720@item If the rate monotonic period has expired before the task
721invokes the rate_monotonic_period directive, the period will be
722initiated with a length of period ticks and the calling task
723returns immediately with a timeout error status.
724@end itemize
725
726@ifinfo
727@node Obtaining a Period's Status, Canceling a Period, Manipulating a Period, Rate Monotonic Manager Operations
728@end ifinfo
729@subsection Obtaining a Period's Status
730
731If the rate_monotonic_period directive is invoked
732with a period of @code{PERIOD_STATUS} ticks, the current state of the
733specified rate monotonic period will be returned.  The following
734table details the relationship between the period's status and
735the directive status code returned by the rate_monotonic_period
736directive:
737
738@itemize @bullet
739@item @code{SUCCESSFUL} - period is running
740
741@item @code{TIMEOUT} - period has expired
742
743@item @code{NOT_DEFINED} - period has never been initiated
744@end itemize
745
746Obtaining the status of a rate monotonic period does
747not alter the state or length of that period.
748
749@ifinfo
750@node Canceling a Period, Deleting a Rate Monotonic Period, Obtaining a Period's Status, Rate Monotonic Manager Operations
751@end ifinfo
752@subsection Canceling a Period
753
754The rate_monotonic_cancel directive is used to stop
755the period maintained by the specified rate monotonic period.
756The period is stopped and the rate monotonic period can be
757reinitiated using the rate_monotonic_period directive.
758
759@ifinfo
760@node Deleting a Rate Monotonic Period, Examples, Canceling a Period, Rate Monotonic Manager Operations
761@end ifinfo
762@subsection Deleting a Rate Monotonic Period
763
764The rate_monotonic_delete directive is used to delete
765a rate monotonic period.  If the period is running and has not
766expired, the period is automatically canceled.  The rate
767monotonic period's control block is returned to the PCB free
768list when it is deleted.  A rate monotonic period can be deleted
769by a task other than the task which created the period.
770
771@ifinfo
772@node Examples, Simple Periodic Task, Deleting a Rate Monotonic Period, Rate Monotonic Manager Operations
773@end ifinfo
774@subsection Examples
775
776The following sections illustrate common uses of rate
777monotonic periods to construct periodic tasks.
778
779@ifinfo
780@node Simple Periodic Task, Task with Multiple Periods, Examples, Rate Monotonic Manager Operations
781@end ifinfo
782@subsection Simple Periodic Task
783
784This example consists of a single periodic task
785which, after initialization, executes every 100 clock ticks.
786
787@page
788@example
789rtems_task Periodic_task()
790@{
791  rtems_name        name;
792  rtems_id          period;
793  rtems_status_code status;
794
795  name = build_name( 'P', 'E', 'R', 'D' );
796
797  (void) rate_monotonic_create( name, &period );
798
799  while ( 1 ) @{
800    if ( rate_monotonic_period( period, 100 ) == TIMEOUT )
801      break;
802
803    /* Perform some periodic actions */
804  @}
805
806  /* missed period so delete period and SELF */
807
808  (void) rate_monotonic_delete( period );
809  (void) task_delete( SELF );
810@}
811@end example
812
813
814The above task creates a rate monotonic period as
815part of its initialization.  The first time the loop is
816executed, the rate_monotonic_period directive will initiate the
817period for 100 ticks and return immediately.  Subsequent
818invocations of the rate_monotonic_period directive will result
819in the task blocking for the remainder of the 100 tick period.
820If, for any reason, the body of the loop takes more than 100
821ticks to execute, the rate_monotonic_period directive will
822return the TIMEOUT status.  If the above task misses its
823deadline, it will delete the rate monotonic period and itself.
824
825@ifinfo
826@node Task with Multiple Periods, Rate Monotonic Manager Directives, Simple Periodic Task, Rate Monotonic Manager Operations
827@end ifinfo
828@subsection Task with Multiple Periods
829
830This example consists of a single periodic task
831which, after initialization, performs two sets of actions every
832100 clock ticks.  The first set of actions is performed in the
833first forty clock ticks of every 100 clock ticks, while the
834second set of actions is performed between the fortieth and
835seventieth clock ticks.  The last thirty clock ticks are not
836used by this task.
837
838@page
839@example
840task Periodic_task()
841@{
842  rtems_name        name_1, name_2;
843  rtems_id          period_1, period_2;
844  rtems_status_code status;
845
846  name_1 = build_name( 'P', 'E', 'R', '1' );
847  name_2 = build_name( 'P', 'E', 'R', '2' );
848
849  (void ) rate_monotonic_create( name_1, &period_1 );
850  (void ) rate_monotonic_create( name_2, &period_2 );
851
852  while ( 1 ) @{
853    if ( rate_monotonic_period( period_1, 100 ) == TIMEOUT )
854      break;
855
856    if ( rate_monotonic_period( period_2, 40 ) == TIMEOUT )
857      break;
858
859    /*
860     *  Perform first set of actions between clock
861     *  ticks 0 and 39 of every 100 ticks.
862     */
863
864    if ( rate_monotonic_period( period_2, 30 ) == TIMEOUT )
865      break;
866
867    /*
868     *  Perform second set of actions between clock 40 and 69
869     *  of every 100 ticks.  THEN ...
870     *
871     *  Check to make sure we didn't miss the period_2 period.
872     */
873
874    if ( rate_monotonic_period( period_2, STATUS ) == TIMEOUT )
875      break;
876
877    (void) rate_monotonic_cancel( period_2 );
878  @}
879
880  /* missed period so delete period and SELF */
881
882  (void ) rate_monotonic_delete( period_1 );
883  (void ) rate_monotonic_delete( period_2 );
884  (void ) task_delete( SELF );
885@}
886@end example
887
888The above task creates two rate monotonic periods as
889part of its initialization.  The first time the loop is
890executed, the rate_monotonic_period directive will initiate the
891period_1 period for 100 ticks and return immediately.
892Subsequent invocations of the rate_monotonic_period directive
893for period_1 will result in the task blocking for the remainder
894of the 100 tick period.  The period_2 period is used to control
895the execution time of the two sets of actions within each 100
896tick period established by period_1.  The rate_monotonic_cancel(
897period_2 ) call is performed to insure that the period_2 period
898does not expire while the task is blocked on the period_1
899period.  If this cancel operation were not performed, every time
900the rate_monotonic_period( period_1, 40 ) call is executed,
901except for the initial one, a directive status of TIMEOUT is
902returned.  It is important to note that every time this call is
903made, the period_1 period will be initiated immediately and the
904task will not block.
905
906If, for any reason, the task misses any deadline, the
907rate_monotonic_period directive will return the TIMEOUT
908directive status.  If the above task misses its deadline, it
909will delete the rate monotonic periods and itself.
910
911@ifinfo
912@node Rate Monotonic Manager Directives, RATE_MONOTONIC_CREATE - Create a rate monotonic period, Task with Multiple Periods, Rate Monotonic Manager
913@end ifinfo
914@section Directives
915@ifinfo
916@menu
917* RATE_MONOTONIC_CREATE - Create a rate monotonic period::
918* RATE_MONOTONIC_IDENT - Get ID of a period::
919* RATE_MONOTONIC_CANCEL - Cancel a period::
920* RATE_MONOTONIC_DELETE - Delete a rate monotonic period::
921* RATE_MONOTONIC_PERIOD - Conclude current/Start next period::
922* RATE_MONOTONIC_GET_STATUS - Obtain status information on period::
923@end menu
924@end ifinfo
925
926This section details the rate monotonic manager's
927directives.  A subsection is dedicated to each of this manager's
928directives and describes the calling sequence, related
929constants, usage, and status codes.
930
931@page
932@ifinfo
933@node RATE_MONOTONIC_CREATE - Create a rate monotonic period, RATE_MONOTONIC_IDENT - Get ID of a period, Rate Monotonic Manager Directives, Rate Monotonic Manager Directives
934@end ifinfo
935@subsection RATE_MONOTONIC_CREATE - Create a rate monotonic period
936
937@subheading CALLING SEQUENCE:
938
939@ifset is-C
940@example
941rtems_status_code rtems_rate_monotonic_create(
942  rtems_name  name,
943  rtems_id   *id
944);
945@end example
946@end ifset
947
948@ifset is-Ada
949@example
950procedure Rate_Monotonic_Create (
951   Name   : in     RTEMS.Name;
952   ID     :    out RTEMS.ID;
953   Result :    out RTEMS.Status_Codes
954);
955@end example
956@end ifset
957
958@subheading DIRECTIVE STATUS CODES:
959@code{SUCCESSFUL} - rate monotonic period created successfully@*
960@code{INVALID_NAME} - invalid task name@*
961@code{TOO_MANY} - too many periods created
962
963@subheading DESCRIPTION:
964
965This directive creates a rate monotonic period.  The
966assigned rate monotonic id is returned in id.  This id is used
967to access the period with other rate monotonic manager
968directives.  For control and maintenance of the rate monotonic
969period, RTEMS allocates a PCB from the local PCB free pool and
970initializes it.
971
972@subheading NOTES:
973
974This directive will not cause the calling task to be
975preempted.
976
977@page
978@ifinfo
979@node RATE_MONOTONIC_IDENT - Get ID of a period, RATE_MONOTONIC_CANCEL - Cancel a period, RATE_MONOTONIC_CREATE - Create a rate monotonic period, Rate Monotonic Manager Directives
980@end ifinfo
981@subsection RATE_MONOTONIC_IDENT - Get ID of a period
982
983@subheading CALLING SEQUENCE:
984
985@ifset is-C
986@example
987rtems_status_code rtems_rate_monotonic_ident(
988  rtems_name  name,
989  rtems_id   *id
990);
991@end example
992@end ifset
993
994@ifset is-Ada
995@example
996procedure Rate_Monotonic_Ident (
997   Name   : in     RTEMS.Name;
998   ID     :    out RTEMS.ID;
999   Result :    out RTEMS.Status_Codes
1000);
1001@end example
1002@end ifset
1003
1004@subheading DIRECTIVE STATUS CODES:
1005@code{SUCCESSFUL} - period identified successfully@*
1006@code{INVALID_NAME} - period name not found
1007
1008@subheading DESCRIPTION:
1009
1010This directive obtains the period id associated with
1011the period name to be acquired.  If the period name is not
1012unique, then the period id will match one of the periods with
1013that name.  However, this period id is not guaranteed to
1014correspond to the desired period.  The period id is used to
1015access this period in other rate monotonic manager directives.
1016
1017@subheading NOTES:
1018
1019This directive will not cause the running task to be
1020preempted.
1021
1022@page
1023@ifinfo
1024@node RATE_MONOTONIC_CANCEL - Cancel a period, RATE_MONOTONIC_DELETE - Delete a rate monotonic period, RATE_MONOTONIC_IDENT - Get ID of a period, Rate Monotonic Manager Directives
1025@end ifinfo
1026@subsection RATE_MONOTONIC_CANCEL - Cancel a period
1027
1028@subheading CALLING SEQUENCE:
1029
1030@ifset is-C
1031@example
1032rtems_status_code rtems_rate_monotonic_cancel(
1033  rtems_id id
1034);
1035@end example
1036@end ifset
1037
1038@ifset is-Ada
1039@example
1040procedure Rate_Monotonic_Cancel (
1041   ID     : in     RTEMS.ID;
1042   Result :    out RTEMS.Status_Codes
1043);
1044@end example
1045@end ifset
1046
1047@subheading DIRECTIVE STATUS CODES:
1048@code{SUCCESSFUL} - period canceled successfully@*
1049@code{INVALID_ID} - invalid rate monotonic period id@*
1050@code{NOT_OWNER_OF_RESOURCE} - rate monotonic period not created by calling task
1051
1052@subheading DESCRIPTION:
1053
1054This directive cancels the rate monotonic period id.
1055This period will be reinitiated by the next invocation of
1056rate_monotonic_period with id.
1057
1058@subheading NOTES:
1059
1060This directive will not cause the running task to be
1061preempted.
1062
1063The rate monotonic period specified by id must have
1064been created by the calling task.
1065
1066@page
1067@ifinfo
1068@node RATE_MONOTONIC_DELETE - Delete a rate monotonic period, RATE_MONOTONIC_PERIOD - Conclude current/Start next period, RATE_MONOTONIC_CANCEL - Cancel a period, Rate Monotonic Manager Directives
1069@end ifinfo
1070@subsection RATE_MONOTONIC_DELETE - Delete a rate monotonic period
1071
1072@subheading CALLING SEQUENCE:
1073
1074@ifset is-C
1075@example
1076rtems_status_code rtems_rate_monotonic_delete(
1077  rtems_id id
1078);
1079@end example
1080@end ifset
1081
1082@ifset is-Ada
1083@example
1084procedure Rate_Monotonic_Delete (
1085   ID     : in     RTEMS.ID;
1086   Result :    out RTEMS.Status_Codes
1087);
1088@end example
1089@end ifset
1090
1091@subheading DIRECTIVE STATUS CODES:
1092@code{SUCCESSFUL} - period deleted successfully@*
1093@code{INVALID_ID} - invalid rate monotonic period id
1094
1095@subheading DESCRIPTION:
1096
1097This directive deletes the rate monotonic period
1098specified by id.  If the period is running, it is automatically
1099canceled.  The PCB for the deleted period is reclaimed by RTEMS.
1100
1101@subheading NOTES:
1102
1103This directive will not cause the running task to be
1104preempted.
1105
1106A rate monotonic period can be deleted by a task
1107other than the task which created the period.
1108
1109@page
1110@ifinfo
1111@node RATE_MONOTONIC_PERIOD - Conclude current/Start next period, RATE_MONOTONIC_GET_STATUS - Obtain status information on period, RATE_MONOTONIC_DELETE - Delete a rate monotonic period, Rate Monotonic Manager Directives
1112@end ifinfo
1113@subsection RATE_MONOTONIC_PERIOD - Conclude current/Start next period
1114
1115@subheading CALLING SEQUENCE:
1116
1117@ifset is-C
1118@example
1119rtems_status_code rtems_rate_monotonic_period(
1120  rtems_id       id,
1121  rtems_interval length
1122);
1123@end example
1124@end ifset
1125
1126@ifset is-Ada
1127@example
1128procedure Rate_Monotonic_Period (
1129   ID      : in     RTEMS.ID;
1130   Length  : in     RTEMS.Interval;
1131   Result  :    out RTEMS.Status_Codes
1132);
1133@end example
1134@end ifset
1135
1136@subheading DIRECTIVE STATUS CODES:
1137@code{SUCCESSFUL} - period initiated successfully@*
1138@code{INVALID_ID} - invalid rate monotonic period id@*
1139@code{NOT_OWNER_OF_RESOURCE} - period not created by calling task@*
1140@code{NOT_DEFINED} - period has never been initiated@*
1141@code{TIMEOUT} - period has expired
1142
1143@subheading DESCRIPTION:
1144
1145This directive initiates the rate monotonic period id
1146with a length of period ticks.  If id is running, then the
1147calling task will block for the remainder of the period before
1148reinitiating the period with the specified period.  If id was
1149not running (either expired or never initiated), the period is
1150immediately initiated and the directive returns immediately.
1151
1152If invoked with a period of @code{PERIOD_STATUS} ticks, the
1153current state of id will be returned.  The directive status
1154indicates the current state of the period.  This does not alter
1155the state or period of the period.
1156
1157@subheading NOTES:
1158
1159This directive will not cause the running task to be preempted.
1160
1161---------------------
1162@page
1163@ifinfo
1164@node RATE_MONOTONIC_GET_STATUS - Obtain status information on period, Board Support Packages, RATE_MONOTONIC_PERIOD - Conclude current/Start next period, Rate Monotonic Manager Directives
1165@end ifinfo
1166@subsection RATE_MONOTONIC_GET_STATUS - Obtain status information on period
1167
1168@subheading CALLING SEQUENCE:
1169
1170@ifset is-C
1171@example
1172rtems_status_code rtems_rate_monotonic_get_status(
1173  rtems_id                            id,
1174  rtems_rate_monotonic_period_status *status
1175);
1176@end example
1177@end ifset
1178
1179@ifset is-Ada
1180@example
1181procedure Rate_Monotonic_Get_Status (
1182   ID      : in     RTEMS.ID;
1183   Status  :    out RTEMS.Rate_Monotonic_Period_Status;
1184   Result  :    out RTEMS.Status_Codes
1185);
1186@end example
1187@end ifset
1188
1189@subheading DIRECTIVE STATUS CODES:
1190@code{SUCCESSFUL} - period initiated successfully@*
1191@code{INVALID_ID} - invalid rate monotonic period id@*
1192@code{INVALID_ADDRESS} - invalid address of status@*
1193
1194@subheading DESCRIPTION:
1195
1196This directive returns status information associated with
1197the rate monotonic period id in the following data structure:
1198
1199@ifset is-C
1200@example
1201typedef struct @{
1202  rtems_rate_monotonic_period_states  state;
1203  unsigned32                          ticks_since_last_period;
1204  unsigned32                          ticks_executed_since_last_period;
1205@}  rtems_rate_monotonic_period_status;
1206@end example
1207@end ifset
1208
1209@ifset is-Ada
1210@example
1211type Rate_Monotonic_Period_Status is
1212   begin
1213      State                            : RTEMS.Rate_Monotonic_Period_States;
1214      Ticks_Since_Last_Period          : RTEMS.Unsigned32;
1215      Ticks_Executed_Since_Last_Period : RTEMS.Unsigned32;
1216   end record;
1217@end example
1218@end ifset
1219
1220If the period's state is @code{RATE_MONOTONIC_INACTIVE}, both
1221ticks_since_last_period and ticks_executed_since_last_period
1222will be set to 0.  Otherwise, ticks_since_last_period will
1223contain the number of clock ticks which have occurred since
1224the last invocation of the rtems_rate_monotonic_period directive.
1225Also in this case, the ticks_executed_since_last_period will indicate
1226how much processor time the owning task has consumed since the invocation
1227of the rtems_rate_monotonic_period directive.
1228
1229@subheading NOTES:
1230
1231This directive will not cause the running task to be preempted.
Note: See TracBrowser for help on using the repository browser.