|
A general assumption concerning preemptive schedulers is that they introduce too much overhead, both in processing time an memory overhead. Is this really so? In order to say something about it, a comparison needs to be made with the alternative, a cooperative scheduler. Concerning usage of RAM, these two types of scheduler do differ. A preemptive scheduler consumes more RAM because every thread has got its own stack while a cooperative scheduler has got a single stack. These stacks are generally considered to be overhead and therefore a waste of RAM. Whether this is entirely true is discussed in “All these stacks consume too much memory”. Lets have a look at processing overhead. A preemptive scheduler is said to introduce processing overhead because it has to switch threads. When switching from one active thread to another, the state of one thread is saved while the state of the other is restored. It is true this consumes CPU cycles. AVIX for example takes ~90 cycles from the point the scheduler is started to the point where the new thread starts running. For the entire switch, one must add to this figure the cycles spent in code determining that a new thread has to be activated. Taking a mutex as an example, AVIX consumes ~200 cycles from the point a mutex is freed up to the point where the thread locking the mutex is restarted. On a 40 MIPS controller this consumes ~5µs. The question now is whether with a cooperative scheduler you get this type of functionality for free. A cooperative scheduler repeatedly calls all threads, where the threads themselves determine whether or not they have to do something. It shall be obvious often this is not the case. The thread is however called just to find nothing has to happen which is a waste of CPU cycles. It shall be obvious this quite easily adds up far beyond the 200 cycles mentioned with the preemptive scheduler. Of course for a fair comparison the frequency these cycles are ‘wasted’ with have to be taken into account but since this very much depends on the dynamics of the system no general statement can be made here. In general it is justified to state the overhead of a cooperative scheduler encompasses that of a preemptive scheduler. Top of page...
|