From owner-freebsd-smp@FreeBSD.ORG Tue May 6 12:32:55 2003 Return-Path: Delivered-To: freebsd-smp@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2AFA737B404 for ; Tue, 6 May 2003 12:32:55 -0700 (PDT) Received: from mail.speakeasy.net (mail13.speakeasy.net [216.254.0.213]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9553343F3F for ; Tue, 6 May 2003 12:32:52 -0700 (PDT) (envelope-from jhb@FreeBSD.org) Received: (qmail 25400 invoked from network); 6 May 2003 19:32:58 -0000 Received: from unknown (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender )encrypted SMTP for ; 6 May 2003 19:32:58 -0000 Received: from laptop.baldwin.cx ([216.133.140.1]) by server.baldwin.cx (8.12.8/8.12.8) with ESMTP id h46JWnp0001213; Tue, 6 May 2003 15:32:49 -0400 (EDT) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.5.4 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <200305061848.h46Imjva068831@gromit.codeconcepts.com> Date: Tue, 06 May 2003 15:32:56 -0400 (EDT) From: John Baldwin To: Greg cc: freebsd-smp@freebsd.org Subject: RE: spinlocks and cv_wait() X-BeenThere: freebsd-smp@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: FreeBSD SMP implementation group List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 May 2003 19:32:55 -0000 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 <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/