Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 02 Dec 2002 01:46:16 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Yury Tarasievich <grog@grsu.by>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: documentation on kernel locks, mutexes?
Message-ID:  <3DEB2BE8.162094EB@mindspring.com>
References:  <Pine.NEB.3.96L.1021130184341.29371C-100000@fledge.watson.org> <3DE9ABCF.80AAAC2F@mindspring.com> <20021202090318.GB3340@deptty.in.grsu.by>

next in thread | previous in thread | raw e-mail | index | archive | help
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):

<http://www.FreeBSD.org/cgi/man.cgi?query=lockmgr&apropos=0&sektion=9&manpath=FreeBSD+5.0-current&format=html>;

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3DEB2BE8.162094EB>