Subject: Re: Kernel threads
To: Bharani Chadalavada <bharani.chadalavada@nexsi.com>
From: Bill Sommerfeld <sommerfeld@orchard.arlington.ma.us>
List: tech-kern
Date: 02/02/2001 21:14:41
> I am a newbie to NetBSD kernel hacking and I am trying to implement a
> device monitor routine which needs to run with interrupts
> enabled(reading some registers etc). I am thinking of doing this using
> kernel threads.(like a pagedaemon, reaper etc). Now this runs only in
> the kernel context. Can I do something similar to the way reaper is
> implemented for example? 

Yes.

> It would be great if someone gives me some links which describe how
> to do this or some code snippets in other ports etc.. (my machine is
> mips based),

A number of device drivers now spawn kernel threads; you might want to
take a look for calls to kthread_create() and kthread_create1() in
drivers all over the system, including the USB and PCMCIA subsystems.

for instance, 

	sys/dev/ic/i82365.c 
	sys/dev/ic/tcic2.c

The interface is currently a little convoluted, as one cannot create
threads extremely early in boot; instead, kthread_create() is given a
pointer to a function which is then called back when it's safe to
actually create the thread; that callback function should call
kthread_create1() with the "base" function of the thread.

					- Bill