From owner-freebsd-hackers Mon Dec 2 1:51:56 2002 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 B3ED737B404 for ; Mon, 2 Dec 2002 01:51:54 -0800 (PST) Received: from snipe.mail.pas.earthlink.net (snipe.mail.pas.earthlink.net [207.217.120.62]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4299C43E88 for ; Mon, 2 Dec 2002 01:51:54 -0800 (PST) (envelope-from tlambert2@mindspring.com) Received: from pool0097.cvx22-bradley.dialup.earthlink.net ([209.179.198.97] helo=mindspring.com) by snipe.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 18InCq-0000rE-00; Mon, 02 Dec 2002 01:49:37 -0800 Message-ID: <3DEB2BE8.162094EB@mindspring.com> Date: Mon, 02 Dec 2002 01:46:16 -0800 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Yury Tarasievich Cc: freebsd-hackers@freebsd.org Subject: Re: documentation on kernel locks, mutexes? References: <3DE9ABCF.80AAAC2F@mindspring.com> <20021202090318.GB3340@deptty.in.grsu.by> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Yury Tarasievich wrote: > > While it's true that kernel locks and mutexes are documented for > > SMPng, he posted to -hackers, not -current, and so he's probably > > not interested in -current primitives that aren't available in > > the 4.x -RELEASE and -STABLE branches. > > Exactly my point, thanks! > > And I'll point again that: > - links in handbook DO NOT work (freebsd.org does not have these > pages (specifically lockmgr(9), mutex(9)) The handbook is old, and non-authoritative, and non-version-linked. It's a good place to get started, but a poor place to find this kind of specific information (e.g. the section on changing KVA space size is incomplete for the version it applies to, and only applies to some versions of FreeBSD, not others, so the information is not generally useful). > - and there are no man pages for them in distribution > > I've even checked this with 4.4-RELEASE at hand -- seen same. The easiest place to look for this is on a FreeBSD -current (5.x) system manual pages, as they currently exist. If you don't have a 5.x system (most commercial shops I know of do not maintain one, since they never ship product except on -RELEASE systems), then you can access manual pages online. Since the lockmgr() interface is (practically) deprecated at this point, it hasn't changed much, and is unlikely to change much. So you can use the 5.x documentation; here is the one for lockmgr(9): Note that the 4.x version of this code takes a "struct proc *" as a sleep context, not a "struct thread *". In any case, you probably don't want to be using this in 4.x code at all in a driver, since drivers operate at interrupt; it's only useful in the top end, to protect against reentrancy, and to provide a sleep context. For your purposes, you are more likely to not have to worry about it at all, considering that you can't enter the kernel in 4.x without hilding "giant". If the reason you are needing this is for a rendevous (what would normally be implemented in other SMP OS's as a condition variable), so you can sleep on work being done, then you *may* want to use lockmgr -- if you *NEVER* call it at interrupt. Otherwise, you probably want to use tsleep() and wakeup(), so long as tsleep() is never called at interrupt. Basically, you can not suspend an interrupt processing routine, for any reason. As I said before, it's generally a good idea to pick a "similar" driver, and use it as a template, rather than trying to program from documentation (which doesn't have a high enough density at this point to make it a useful pursuit). -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message