Page 1 of 1

Preemptive kernel

Posted: Sat Jul 26, 2008 5:14 pm
by Jeko
I think a preemptive kernel would be very useful for the multiprocessing to kill the deadlocks.
What do you think about this?

Have you any idea about implementing this?

Re: Preemptive kernel

Posted: Sun Jul 27, 2008 1:42 am
by cyr1x
I'd say no. As the kernel might be working on more places which increases the chance that a deadlock occurs.
Although the chance a deadlock locks up the kernel is lower, but data might be inconsistent.

Re: Preemptive kernel

Posted: Sun Jul 27, 2008 2:55 am
by JamesM
There are no real disadvantages to having a preemptible kernel, apart from coding time and effort. Whether you actually preempt in the kernel is another matter - linux for example provides a config switch so that you can choose.

Re: Preemptive kernel

Posted: Sun Jul 27, 2008 10:54 am
by Jeko
JamesM wrote:preemptible kernel
http://en.wikipedia.org/wiki/Preemptive_multitasking wrote:Some modern systems have preemptive kernels

Re: Preemptive kernel

Posted: Sun Jul 27, 2008 11:04 am
by Jeko
However, how can I implement preemption in the kernel?

Re: Preemptive kernel

Posted: Sun Jul 27, 2008 11:40 am
by thooot
To do preemption in the kernel just don't do anything to prevent it. So on a system call don't disable interrupts and make sure your scheduler doesn't distinguish between kernel mode and user mode when scheduling threads.

Re: Preemptive kernel

Posted: Sun Jul 27, 2008 11:45 am
by Jeko
thooot wrote:To do preemption in the kernel just don't do anything to prevent it. So on a system call don't disable interrupts and make sure your scheduler doesn't distinguish between kernel mode and user mode when scheduling threads.
Are there anything to do related to security?

Re: Preemptive kernel

Posted: Mon Jul 28, 2008 6:29 am
by JamesM
Jeko wrote:
JamesM wrote:preemptible kernel
http://en.wikipedia.org/wiki/Preemptive_multitasking wrote:Some modern systems have preemptive kernels
What's your point? "preemptible" means the kernel is designed to be able to be preempted. "preemptive" means the preemption is enabled. It can be preemptible without being preemptive.

Re: Preemptive kernel

Posted: Mon Jul 28, 2008 10:31 pm
by thooot
Jeko wrote:Are there anything to do related to security?
Not that I'm aware of. You do need to watch out for places where you don't want to be preempted though (such as when you're holding a spinlock).

Re: Preemptive kernel

Posted: Tue Jul 29, 2008 2:35 am
by Jeko
JamesM wrote:
Jeko wrote:
JamesM wrote:preemptible kernel
http://en.wikipedia.org/wiki/Preemptive_multitasking wrote:Some modern systems have preemptive kernels
What's your point? "preemptible" means the kernel is designed to be able to be preempted. "preemptive" means the preemption is enabled. It can be preemptible without being preemptive.
Ah...Sorry :oops:
thooot wrote:Not that I'm aware of. You do need to watch out for places where you don't want to be preempted though (such as when you're holding a spinlock).
So a preemptive kernel is a normal kernel with multitasking enabled?

Re: Preemptive kernel

Posted: Tue Jul 29, 2008 3:23 am
by Korona
It's not necessarily good to enable preemption in most parts of the kernel. Imagine a microkernel that has very fast system calls. All the work is done by user space application. When a user space process calls a write() system call (of course I'm talking about non-blocking system calls here) in order to write some bytes to a pipe (or message box) the kernel generally has to acquire a spinlock or semaphore before it can modify the pipe's buffer. If the kernel is interrupted before releasing the lock it might switch to another processes that also tries to access the pipe. The second process has to wait until the first process finishes its write() operation. Now imagine that many processes that access a single (kernel-) resource that is currently locked by another process. If preemption was disabled for the write() system call throughput would be greatly improved (at least for all threads on the same processor). It's not always good to enable preemption for every system call; especially for system calls that are very fast and have a constant worst-case running time. write()ing to a pipe is usually O(size_of_pipe_buffer) with very small constants. Even if write() is not preemptive interrupts will still be processed without any significant delay.