Date: Tue, 06 May 2003 15:32:56 -0400 (EDT) From: John Baldwin <jhb@FreeBSD.org> To: Greg <greg@codeconcepts.com> Cc: freebsd-smp@freebsd.org Subject: RE: spinlocks and cv_wait() Message-ID: <XFMail.20030506153256.jhb@FreeBSD.org> In-Reply-To: <200305061848.h46Imjva068831@gromit.codeconcepts.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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@FreeBSD.org> <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.20030506153256.jhb>