Subject: Disabling Preemption
To: None <tech-kern@netbsd.org>
From: Alan Ritter <rittera@cc.wwu.edu>
List: tech-kern
Date: 08/15/2005 15:41:09
Hi, I'm wondering if there is any way to temporarily disable preemption
from kernel threads.

I'm trying to port the FreeBSD NDIS code to NetBSD, and I think I'm pretty
close to getting it working for the e100bex (Intell Pro/100 Ethernet PCI
card).  Right now I can ping another machine, but after a while the whole
OS locks up, and there are some other problems.

I've been ignoring some of the locking issues for a while, while trying to
get something working, so now I'm going back and trying to figure it out. 
In FreeBSD, they handle the Windows DISPATCH_LEVEL irql by raising the
scheduling priority to PI_REALTIME.  According to a comment in the FreeBSD
code this "prevents anything except for an interrupt thread from
preempting us".  So far I haven't been able to figure out how to stop
preemption from another kernel thread created with kthread_create1() in
NetBSD, so right now I do nothing.  I was thinking about setting the
device's interrupts to happen at IPL_HIGH, and then just doing splsched()
to stop preemption, but this dosen't seem very reasonable...  Maybe I just
need to put a lock on each of the funcions that run in the kernel threads?

Anyway, I'm not that familiar with locking/threading issues, so I'd
greatly appreciate it if someone could point me in the right direction.

Thanks :-)