Hi,
Captus wrote:In RTOS design a way to make a kernel preemptive could be to use preemption points. Why?.. why doesn't preemption work during system calls using the timer interrupt that operates the CPU scheduler? As far as I can tell it's because interrupts are disabled during system calls, but I cant figure out for what reason they are disabled during system calls?
You can have a kernel that is preemptable by default that uses locking to disable preemption during critical sections. Alternatively you could do the opposite - have a kernel that is not preemptable by default that uses "anti-locking" to enable preemption between critical sections. It's mostly the same with different terminology.
Now, consider a kernel that has a single kernel stack that is shared by all tasks. In this case the kernel can't be easily preempted because you'd need to return to preempted tasks in the correct order to avoid trashing the kernel stack, and you'd risk kernel stack overflow if the kernel is preempted many times. However, if the kernel made sure it has nothing on the kernel stack before allowing itself to be preempted then these problems go away.
IMHO this is what preemption points are - a way to allow preemption in kernels that have a single shared kernel stack.
BTW there are advantages to having a single shared kernel stack - space and RAM used (e.g. 1024 tasks with 4 KB kernel stacks adds up to 4 MB of RAM instead of just 4 KB) and caching (a single kernel stack would almost always be in the CPU's caches).
I also think that it'd be extremely difficult to support SMP if your using preemption points. I'm not sure that any real time systems actually use SMP though, and I can't think of how SMP can help "worst case" times regardless of how it's done. In general, SMP means that a CPU may need to wait for other CPUs to leave a critical section before it can enter that critical section, and more CPUs gives longer "worst case" times - something you don't want in a real time system.
Cheers,
Brendan