Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 02 Nov 2005 14:58:39 -0700 (MST)
From:      "M. Warner Losh" <imp@bsdimp.com>
To:        scottl@samsco.org
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: locking in a device driver
Message-ID:  <20051102.145839.69381782.imp@bsdimp.com>
In-Reply-To: <43692C86.4040509@samsco.org>
References:  <20051102.121248.74711520.imp@bsdimp.com> <43692719.90805@alphaque.com> <43692C86.4040509@samsco.org>

next in thread | previous in thread | raw e-mail | index | archive | help
In message: <43692C86.4040509@samsco.org>
            Scott Long <scottl@samsco.org> writes:
: Dinesh Nair wrote:
: > 
: > 
: > On 11/03/05 03:12 Warner Losh said the following:
: > 
: >> Yes.  if you tsleep with signals enabled, the periodic timer will go
: >> off, and you'll return early.  This typically isn't what you want
: >> either.
: > 
: > 
: > looks like i've got a lot of work to do, poring thru all the ioctls for 
: > the device and trying to use another method to wait instead of tsleep().
: 
: Note that a thread can block on select/poll in 4.x and still allow other
: threads to run.  I used this to solve a very similar problem to your in
: a 4.x app of mine.  I have the app thread wait on select() on the device
: node for the driver.  When the driver gets to a state when an ioctl
: won't block (like data being available to read), then it does the
: appropriate magic in it's d_poll method.  select in userland sees this,
: allows the thread to resume running, and the thread then calls ioctl.
: Of course you have to be careful that you don't have multiple threads
: competing for the same data or that the data won't somehow disappear
: before the ioctl call runs.  But it does work.  Look at the aac(4)
: driver for my example of this.

Yes.  If you have the ability to know that an ioctl won't block before
you call it, that would work too.  This method is a little trickier,
like you say, but can be made to work.  I've also seen ioctls that
were split into a 'foo_start' and 'foo_finish' pair (someimtes with a
non-blocking foo_status) to get around this restriction...

While ioctls generally cannot block, one can use these sorts of
techniques to avoid blocking.  I'm glad that kernel threads are here
so we don't have to keep propigating these hacks...

Warner




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051102.145839.69381782.imp>