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