Home |
RTKernel-32 Programming Manual Multitasking, Real-Time, and RTKernel-32 Alternate APIs for RTKernel-32 Preemptive or Cooperative Multitasking? Starting Objects' Methods as Tasks Performance and Interrupt Response Times Task Switches in Cooperative Scheduling Using the FPU in Interrupt Handlers |
Preemptive or Cooperative Multitasking?RTKernel-32 allows you to choose between preemptive and cooperative multitasking. The proper choice depends on the requirements of the application. To make the right decision, it is necessary to exactly understand the differences between preemptive and cooperative multitasking (see Multitasking, Real-Time, and RTKernel-32, What is Multitasking?). Advantages of Preemptive SchedulingThe main advantage of preemptive scheduling is real-time response on the task level. The task response time - i.e., the time required to activate a task waiting for an interrupt - largely depends only on the interrupt latency (the time span during which no other interrupts can be accepted). In cooperative scheduling, the task response time is the longest time span that can elapse between two calls to the kernel. Unfortunately, an upper limit for this time span cannot be defined in many cases. It is the responsibility of the programmer to ensure that the time spans between calls to the kernel or the scheduler are sufficiently small. Advantages of Cooperative SchedulingWith cooperative scheduling and the single-processor kernel, substantially fewer reentrance problems are encountered than in preemptive scheduling, because tasks cannot be interrupted arbitrarily by other tasks, but only at positions permitted by the programmer (i.e., in kernel calls). This advantages does not apply to the multiprocessor kernel. It should be noted that even though real-time response is impeded on the task level, it is fully preserved on the interrupt handler level. Interrupt handlers can continue to use semaphores and mailboxes in cooperative scheduling. Therefore, interrupt-driven modules like RTCom can run independently of the scheduling algorithm currently active. Also, these modules' performance is identical in both cases. While RTKernel-32's Idle Task is running (or a task with a similar structure, e.g., the CPU Monitor Counter task), tasks' response times to interrupts are practically identical, with or without preemptive scheduling. For programs that don't require a response time on the order of micro- or milliseconds at the task level, cooperative scheduling is recommended.
|