From owner-freebsd-hackers@FreeBSD.ORG Tue Jan 27 14:47:46 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E56F316A4CE for ; Tue, 27 Jan 2004 14:47:46 -0800 (PST) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id C8DC943D1F for ; Tue, 27 Jan 2004 14:47:31 -0800 (PST) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (localhost [127.0.0.1]) by fledge.watson.org (8.12.10/8.12.10) with ESMTP id i0RMiNUd050956; Tue, 27 Jan 2004 17:44:23 -0500 (EST) (envelope-from robert@fledge.watson.org) Received: from localhost (robert@localhost)i0RMiNXU050953; Tue, 27 Jan 2004 17:44:23 -0500 (EST) (envelope-from robert@fledge.watson.org) Date: Tue, 27 Jan 2004 17:44:22 -0500 (EST) From: Robert Watson X-Sender: robert@fledge.watson.org To: Renaud Molla Wanadoo In-Reply-To: <4016B48C.7030001@wanadoo.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-hackers@freebsd.org Subject: Re: kernel threads X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Jan 2004 22:47:47 -0000 On Tue, 27 Jan 2004, Renaud Molla Wanadoo wrote: > I'm trying to use the kthread library under 5.2-RELEASE but can't > compile my program (which actually only tries to create a thread). > > I've read that there is now KSE to create kernel threads, but i am > wondering if it could be used within the kernel code. I'm left a little unclear by your message what it is you're trying to do. In traditional parlance, a "kernel thread" is a thread executing kernel code in the kernel. These are created using the kthread(9) API, which is available both to kernel modules and code compiled directly into the kernel. You can see examples of kthread use (both compiled in and in modules) by grepping in the src/sys/kern and src/sys/dev/* trees. The only real caveat here that I know if is that you need to grab the Giant lock if your thread will use it, since kthreads don't start holding Giant, and that if you call kthread_exit(), you will need to grab Giant before that. A use of "kernel thread" popularized by linux is the idea of userspace threads that are backed by a kernel schedulable thread, as opposed to multiple userspace threads being mapped into a single thread making up a single process. In FreeBSD 5.x, the "libc_r" library provides multiple user threads multiplexed onto a single kernel-visible thread/process. "libkse" and "libthr" provide M:N and 1:1 models. By linking your application against libkse or libthr and using the pthreads API, you will automatically get parallelism and latency improvements over libc_r. Hope this helps. Robert N M Watson FreeBSD Core Team, TrustedBSD Projects robert@fledge.watson.org Senior Research Scientist, McAfee Research