Preemptive kernel

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Preemptive kernel

Post 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?
Rewriting virtual memory manager - Working on ELF support - Working on Device Drivers Handling

http://sourceforge.net/projects/jeko - Jeko Operating System
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Re: Preemptive kernel

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Preemptive kernel

Post 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.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Preemptive kernel

Post by Jeko »

JamesM wrote:preemptible kernel
http://en.wikipedia.org/wiki/Preemptive_multitasking wrote:Some modern systems have preemptive kernels
Rewriting virtual memory manager - Working on ELF support - Working on Device Drivers Handling

http://sourceforge.net/projects/jeko - Jeko Operating System
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Preemptive kernel

Post by Jeko »

However, how can I implement preemption in the kernel?
Rewriting virtual memory manager - Working on ELF support - Working on Device Drivers Handling

http://sourceforge.net/projects/jeko - Jeko Operating System
thooot
Member
Member
Posts: 30
Joined: Sun Jun 01, 2008 11:20 am

Re: Preemptive kernel

Post 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.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Preemptive kernel

Post 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?
Rewriting virtual memory manager - Working on ELF support - Working on Device Drivers Handling

http://sourceforge.net/projects/jeko - Jeko Operating System
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Preemptive kernel

Post 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.
thooot
Member
Member
Posts: 30
Joined: Sun Jun 01, 2008 11:20 am

Re: Preemptive kernel

Post 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).
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Preemptive kernel

Post 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?
Rewriting virtual memory manager - Working on ELF support - Working on Device Drivers Handling

http://sourceforge.net/projects/jeko - Jeko Operating System
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Preemptive kernel

Post 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.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
Post Reply