Rate-monotonic scheduling

In computer science, rate-monotonic scheduling (RMS)[1] is a priority assignment algorithm used in real-time operating systems (RTOS) with a static-priority scheduling class.[2] The static priorities are assigned according to the cycle duration of the job, so a shorter cycle duration results in a higher job priority.

These operating systems are generally preemptive and have deterministic guarantees with regard to response times. Rate monotonic analysis is used in conjunction with those systems to provide scheduling guarantees for a particular application.

Introduction

A simple version of rate-monotonic analysis assumes that threads have the following properties:

  • No resource sharing (processes do not share resources, e.g. a hardware resource, a queue, or any kind of semaphore blocking or non-blocking (busy-waits))
  • Deterministic deadlines are exactly equal to periods
  • Static priorities (the task with the highest static priority that is runnable immediately preempts all other tasks)
  • Static priorities assigned according to the rate monotonic conventions (tasks with shorter periods/deadlines are given higher priorities)
  • Context switch times and other thread operations are free and have no impact on the model

It is a mathematical model that contains a calculated simulation of periods in a closed system, where round-robin and time-sharing schedulers fail to meet the scheduling needs otherwise. Rate monotonic scheduling looks at a run modeling of all threads in the system and determines how much time is needed to meet the guarantees for the set of threads in question.

Liu & Layland (1973) proved that for a set of n periodic tasks with unique periods, a feasible schedule that will always meet deadlines exists if the CPU utilization is below a specific bound (depending on the number of tasks). The schedulability test for RMS is:

where Ci is the computation time, Ti is the release period (with deadline one period later), and n is the number of processes to be scheduled. For example, U  0.8284 for two processes. When the number of processes tends towards infinity, this expression will tend towards:

Therefore, a rough estimate is that RMS can meet all of the deadlines if CPU utilization is less than 69.32%. The other 30.7% of the CPU can be dedicated to lower-priority non real-time tasks. It is known that a randomly generated periodic task system will meet all deadlines when the utilization is 85% or less,[3] however this fact depends on knowing the exact task statistics (periods, deadlines) which cannot be guaranteed for all task sets.

The hyperbolic bound[4] is a tighter sufficient condition for schedulability than the one presented by Liu and Layland:

,

where Ui is the CPU utilization for each task.

The rate-monotonic priority assignment is optimal, meaning that if any static-priority scheduling algorithm can meet all the deadlines, then the rate-monotonic algorithm can too. The deadline-monotonic scheduling algorithm is also optimal with equal periods and deadlines, in fact in this case the algorithms are identical; in addition, deadline monotonic scheduling is optimal when deadlines are less than periods.[5] For the task model in which deadlines can be greater than periods, Audsley's algorithm endowed with an exact schedulability test for this model finds an optimal priority assignment.[6]

Avoiding priority inversion

In many practical applications, resources are shared and the unmodified RMS will be subject to priority inversion and deadlock hazards. In practice, this is solved by disabling preemption or by priority inheritance. Alternative methods are to use lock free algorithms or avoid the sharing of a mutex/semaphore across threads with different priorities. This is so that resource conflicts cannot result in the first place.

Disabling of preemption

  • The OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() primitives that lock CPU interrupts in a real-time kernel, e.g. MicroC/OS-II
  • The splx() family of primitives which nest the locking of device interrupts (FreeBSD 5.x/6.x),

Priority inheritance

  • The basic priority inheritance protocol[7] promotes the priority of the task that holds the resource to the priority of the task that requests that resource at the time the request is made. Upon release of the resource, the original priority level before the promotion is restored. This method does not prevent deadlocks and suffers from chained blocking. That is, if a high priority task accesses multiple shared resources in sequence, it may have to wait (block) on a lower priority task for each of the resources.[8] The real-time patch to the Linux kernel includes an implementation of this formula.[9]
  • The priority ceiling protocol[10] enhances the basic priority inheritance protocol by assigning a ceiling priority to each semaphore, which is the priority of the highest job that will ever access that semaphore. A job cannot preempt a lower priority critical section if its priority is lower than the ceiling priority for that section. This method prevents deadlocks and bounds the blocking time to at most the length of one lower priority critical section. This method can be suboptimal, in that it can cause unnecessary blocking. The priority ceiling protocol is available in the VxWorks real-time kernel. It is also known as Highest Locker's Priority Protocol (HLP). [11]

Priority inheritance algorithms can be characterized by two parameters. First, is the inheritance lazy (only when essential) or immediate (boost priority before there is a conflict). Second is the inheritance optimistic (boost a minimum amount) or pessimistic (boost by more than the minimum amount):

pessimistic optimistic
immediate OS_ENTER_CRITICAL() / OS_EXIT_CRITICAL() splx(), highest locker
lazy priority ceiling protocol, basic priority inheritance protocol

In practice there is no mathematical difference (in terms of the Liu-Layland system utilization bound) between the lazy and immediate algorithms, and the immediate algorithms are more efficient to implement, and so they are the ones used by most practical systems.

An example of usage of basic priority inheritance is related to the "Mars Pathfinder reset bug" [12][13] which was fixed on Mars by changing the creation flags for the semaphore so as to enable the priority inheritance.

Example

Process Execution Time Period
P1 1 8
P2 2 5
P3 2 10

The utilization will be: .

The sufficient condition for processes, under which we can conclude that the system is schedulable is:

.

Since the system is schedulable.


For Harmonics task set we can use Ei/Pi <= 1 formula.

See also

References

  1. Liu, C. L.; Layland, J. (1973), "Scheduling algorithms for multiprogramming in a hard real-time environment", Journal of the ACM, 20 (1): 46–61, CiteSeerX 10.1.1.36.8216, doi:10.1145/321738.321743.
  2. Bovet, Daniel P.; Cesati, Marco, Understanding the Linux Kernel, http://oreilly.com/catalog/linuxkernel/chapter/ch10.html#85347 Archived 2014-09-21 at the Wayback Machine.
  3. Lehoczky, J.; Sha, L.; Ding, Y. (1989), "The rate monotonic scheduling algorithm: exact characterization and average case behavior", IEEE Real-Time Systems Symposium, pp. 166–171, doi:10.1109/REAL.1989.63567, ISBN 978-0-8186-2004-1.
  4. Enrico Bini, Giorgio C. Buttazzo and Giuseppe M. Buttazzo (2003), "Rate Monotonic Analysis: the Hyperbolic Bound", IEEE Transactions on Computers, 52 (7): 933–942, doi:10.1109/TC.2003.1214341CS1 maint: uses authors parameter (link)
  5. Leung, J. Y.; Whitehead, J. (1982), "On the complexity of fixed-priority scheduling of periodic, real-time tasks", Performance Evaluation, 2 (4): 237–250, doi:10.1016/0166-5316(82)90024-4.
  6. Alan Burns and Andy Wellings (2009), Real-Time Systems and Programming Languages (4th ed.), Addison-Wesley, pp. 391, 397, ISBN 978-0-321-41745-9
  7. Lampson, B. W.; Redell, D. D. (1980), "Experience with processes and monitors in Mesa", Communications of the ACM, 23 (2): 105–117, CiteSeerX 10.1.1.46.7240, doi:10.1145/358818.358824.
  8. Buttazzo, Giorgio (2011), Hard Real-Time Computing Systems: Predictable Scheduling Algorithms and Applications (Third ed.), New York, NY: Springer, p. 225
  9. "Real-Time Linux Wiki". kernel.org. 2008-03-26. Retrieved 2014-03-14.
  10. Sha, L.; Rajkumar, R.; Lehoczky, J. P. (1990), "Priority inheritance protocols: an approach to real-time synchronization", IEEE Transactions on Computers, 39 (9): 1175–1185, doi:10.1109/12.57058.
  11. Buttazzo, Giorgio (2011), Hard Real-Time Computing Systems: Predictable Scheduling Algorithms and Applications (Third ed.), New York, NY: Springer, p. 212
  12. http://research.microsoft.com/~mbj/Mars_Pathfinder/
  13. http://anthology.spacemonkeys.ca/archives/770-Mars-Pathfinder-Reset-Bug.html

Further reading

  • Buttazzo, Giorgio (2011), Hard Real-Time Computing Systems: Predictable Scheduling Algorithms and Applications, New York, NY: Springer.
  • Alan Burns and Andy Wellings (2009), Real-Time Systems and Programming Languages (4th ed.), Addison-Wesley, ISBN 978-0-321-41745-9
  • Liu, Jane W.S. (2000), Real-time systems, Upper Saddle River, NJ: Prentice Hall, Chapter 6.
  • Joseph, M.; Pandya, P. (1986), "Finding response times in real-time systems", BCS Computer Journal, 29 (5): 390–395, doi:10.1093/comjnl/29.5.390.
  • Sha, Lui; Goodenough, John B. (April 1990), "Real-Time Scheduling Theory and Ada", IEEE Computer, 23 (4): 53–62, doi:10.1109/2.55469
  • Mars Pathfinder Bug from Research @ Microsoft
  • What really happened on Mars Rover Pathfinder by Mike Jones from The Risks Digest, Vol. 19, Issue 49
  • The actual reason for the Mars Pathfinder Bug, but those who actually dealt with it, rather than someone whose company and therefore stock value depended upon the description of the problem, or someone who heard someone talking about the problem.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.