Presented by Barr Group Principal Engineer Salomon Singer, this webinar examines best practices for assigning fixed priorities to a set of real-time operating systems (RTOS) tasks and interrupt service routines (ISRs). Viewers will learn how and why to use optimal methods to allow a critical set of tasks and interrupt service routines to meet all of their deadlines – even during transient overload periods. Lessons learned can be applied to the development of any priority-based preemptive RTOS, including real-time Linux.
The transcript of this webinar begins with at the beginning of the feature presentation on slide 4.
Slide 4: Instructor: Salomon Singer
Salomon Singer: Good afternoon ladies and gentlemen. My name is Solomon Singer, and it's my pleasure to be here today to talk to you about how to assign priorities to tasks in ISRs. If you want to prove that all the tasks in your system are going to meet all the deadlines you must first learn how to properly assign priorities to those tasks in ISRs.
Slide 5: Preemption
Before we start talking about how to assign priorities to tasks, we must start talking about preemption because only in the context of preemption are relative priorities relevant at all. So the definition of preemption is that the running task might be interrupted at any time. Why? A good example is because an interrupt just happened and so the CPU is going to treat the interrupt as a higher priority task, but also it is entirely possible that there is now a task that is ready to run that has higher priority than the current running task and DOS, he must get the CPU now. There are two main variations to preemption: one is time-slice and the other one is our priority-based; and one that we are going to be concentrating on is priority-based.
Slide 6: Priority-Based Preemption
When we are working with a priority-based preemption system, each and every one of the tasks that are comprised to system will be assigned a relative priority. Typically, this is a unique static integer, typically zero or one based, and the scheduling algorithm is extremely simple. The task with the highest priority gets the CPU as long as it is ready to run and it doesn't need anything else to do its work other than the CPU.
See the Complete Transcript
Attendees at the live webinar had the opportunity to ask technical questions related to the presentation. Below are a few of the questions from that session.
Q: How do you prioritize tasks with no deadlines?
A: The answer to this question is you don't need to take them into consideration when you're assigning priorities for RMA. The only constraint is that you take those tasks and you give them priorities that are lower than any other task that has deadlines.
Q: Can I use RMA even if all my tasks are non-periodic?
A: Absolutely yes. In the example, I showed you how you can treat an ISR that is not periodic. You would apply the exact same technique that I applied for the ISR to any of your tasks that are non-periodic.
Q: If I'm using RMA, does that mean that I can't boost or adjust the priorities of the tasks on the fly or at runtime?
A: You can, but you shouldn't. One of a nastiest side effect of modifying the priorities on the fly is that you would make your analysis significantly more complicated. Typically it shows a poor design when you are changing priorities on the fly.
Q: How are the task costs determined?
A: Task costs are determined by the worst case execution time for that task.
Q: In this two task example, the two tasks take 90 ms out of each 100 ms period. The duty cycle is 90%. Is the CPU overloaded in this case?
A: The CPU is overloaded only if you exceed 100% utilization.
Q: In the case where the two tasks have same priority, how is it decided?
A: If two tasks have the same frequency you can give them the same priority if your RTOS supports that, otherwise you can arbitrarily choose which of the two gets the higher priority.
Q: How is cost computed? From the run-time averages?
A: Cost is the worst case execution time. It can be measured and it can be calculated if you know the number of cycles and the clock frequency.
Q: How do you handle a sporadic interrupt which requires to be assigned the highest priority?
A: Make its frequency the highest.
Q: Is it always low number-high priority or can it also be vice-versa?
A: Not always but most of the time.
Q: In a communication system where the processor is handling both Tx and Rx, which tasks has higher priority as a general rule - Tx tasks or Rx tasks?
A: Unfortunately, there is no general rule. It depends on the frequency of the tasks. That is the only rule.
Q: If we know (or if we can measure) WCET and we know period, why do more RTOSes not use Earliest Deadline First scheduling instead of RMA?
A: One reason would be because with EDF in a transient overload, you can't predict which task will miss it’s deadline. Another reason would be the high computational overhead of EDF.
Q: Do task deadlines include the time cost of the context switch from the previous task?
A: Yes, task deadlines include the time cost of the context switch from the previous task.
Q: How do you measure WCET?
A: To measure WCET, attach a scope to a port and have the task toggle the port on entry and exit.
Q: Can Linux be used as real time os with rma?
A: Linux can only be used as a real time OS with RMA if it has a prioritized preemptive scheduler.