Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Jul 2002 15:21:06 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Daniel Lundqvist <daniel@malarhojden.nu>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: select()/poll() i kernel.
Message-ID:  <3D471152.4347ABD1@mindspring.com>
References:  <20020730152514.GA66448@malarhojden.nu>

next in thread | previous in thread | raw e-mail | index | archive | help
Daniel Lundqvist wrote:
> I was wondering if there is a select()/poll() for use in kernel by
> kernel threads? I've been looking around in sys/kern/ but didn't find anything.
> I'm currently developing under 4.6.
> 
> Please CC me since I'm not a member of the list.

4.6 does not have kernel threads; it has kernel processes (kproc's),
however, which are just standard processes which have been assumed
to have entered the kernel.  As such, they are suitable for use as a
context for blocking operations (you can only sleep things that have
the ability to have scheduler queue entries, and therefore be awakened
at a later time).

There is no explicit support for a "select" call; most operations on
file descriptors assume a process context in user space from which
parameters can be copied, and results copied out.

Rather than correcting the FreeBSD model to internally add a space
identifier parameter to the body of the call, and make the system
calls call that, instead of being directly wired in, you have two
real options:

1)	Use "The mmap trick" to obtain memory in the user space
	portion of the kproc address space, so that when uiomove
	and/or copyin/copyout operate, they have someplace to get
	or put the data.

2)	Write the moral equivalent of the select(2) (or poll(2))
	code that can be called from kernel space, and call it
	from your kproc.

Note that either of these will *only* work from a kproc, where the
current process identfier is the kproc.  So you can't use them in
fault handlers or interrupt handlers, if that's what yu are thinking.

Really, FreeBSD needs a better abstraction of the file I/O and other
operations in kernel space, so that doing this type of work is much
easier.

On the other hand... it's likely that your expectations of how a
kproc can be used as if it were a kernel thread are unreasonable,
so maybe it's just as well that there is not explicit support for
this kind of thing, like there is in Linux, AIX, and Solaris.

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D471152.4347ABD1>