OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [doc/] [user/] [rtmon.t] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.