spinlocks and cv_wait()
John Baldwin
jhb at FreeBSD.org
Tue May 6 12:32:55 PDT 2003
On 06-May-2003 Greg wrote:
>
> Hi, I am working on a driver that has data which is accessed by both
> the top and bottom. It is a typical situation in which the top half
> initiates I/O and then awaits notification of completion by the
> bottom half.
>
> The problem seems to be that either that I am misunderstanding something
> fundamental in the FreeBSD locking implementation, or perhaps the
> implementation of cv_wait() is a bit too restrictive.
>
> Because the bottom half is a disk I/O interrupt handler, I presume the
> mutex must be of the MTX_SPIN variety, and therein is the problem. The
> top half acquires the mutex, checks the condition, and then calls cv_wait()
> if the condition is not met. Unfortunately, cv_wait() checks that the
> mutex is of the sleeping variety and trips an assert because it isn't
> (at kern_condvar.c line 240).
Your first assumption here is wrong. Interrupt handlers run in a (mostly)
top-half context and are allowed to use normal mutexes. MTX_SPIN mutexes
should be avoided when possible.
> As a data point, this code runs correctly on SMP Solaris, AIX, and
> FreeBSD-4 (taking into account the different locking APIs, of course).
>
> If anyone out there can shed some light on the problem it would be
> greatly appreciated.
>
> Thanks in advance!
> Greg
>
--
John Baldwin <jhb at FreeBSD.org> <>< http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve!" - http://www.FreeBSD.org/
More information about the freebsd-smp
mailing list