Tics Realtime -----


 
Home Services Products Tutorials Contact Us
- - - - -

Assigning Task Priorities

Task priorities are fundamental to multi-tasking kernels that employ priority based preemptive scheduling. Task priorities characterize the task behavior and the dynamics of the system as a whole. The following concepts of priority apply to Tics; other systems may vary.

The Meaning of Task Priority in Real-time Systems

The highest priority task will run until it voluntarily relinquishes control. Once control is relinquished, the next highest priority task will run until it relinquishes control, or the highest priority task needs to resume (due to, for example, an event). This behavior continues all the way down the priority chain.

This behavior means that the highest priority task will run forever unless it voluntarily relinquishes control, which is as it should be. There is no concept of "fairness" in real-time systems, otherwise, the concept of real-time priority would have no meaning. When more than one task is at the same priority they are handled in fifo order within that priority group.

Be Practical About Priorities

Preemption should be avoided as it can cause complications.. Therefore, avoiding preemption by running all tasks at the same priority,( i.e., cooperatively), is preferred. Unless there are obvious reasons for using priorities, it is suggested that all tasks be set to the same priority, and the system stress tested in a rigorous manner. If it is determined that the system cannot fail with all tasks at the same priority, then no priority analysis is required.

If it is proven that priorities are absolutely necessary, then it must be understood that for all practical purposes there can be only one deterministic high priority task in a preemptive multi-tasking system. Consider a system comprised of 9 tasks, 8 running at default priority and 1 task, taskA, running at high priority. No matter what task is running, the high priority task will preempt the running task when it needs to run. Now consider 7 tasks at default priority and 2 tasks, taskA and taskB, at high priority. Now taskA is not guaranteed to preempt the running task when it needs to run because the running task may be taskB which is of the same priority. What this means is that your system can have only 1 critical task. If your system has more than 1 critical operation, then handle them in isr's, use dedicated hardware timers if available and applicable, or consider using multiple processors. For ultra crtical real-time systems the best approach may be avoid a mutli-tasking kernel altogether and code a tight cyclical executive system. For more details on this approach please send us email.

Comments

Priorities are not a panacea, and should be used wisely and sparingly if at all. It has been our experience that most real-time systems perform adequately with the cooperative approach. For those situations where priorities are needed, we recommend running only 1 task at high priority and others at default priority if possible. We recommend against many levels of priorities. Keep your application simple and predictable. Lastly we recommend heavy stress testing especially in critical real-time systems. We will cover real-time testing in next month's issue.


We welcome comments. Let us know what subjects you would like written up. Send comments to Mike@TicsRealtime.com

Copyright © 2000, Tics Realtime