From owner-freebsd-current@FreeBSD.ORG Wed Nov 3 17:10:00 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 22DA81065674; Wed, 3 Nov 2010 17:10:00 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-ew0-f54.google.com (mail-ew0-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 6431D8FC15; Wed, 3 Nov 2010 17:09:58 +0000 (UTC) Received: by ewy28 with SMTP id 28so423717ewy.13 for ; Wed, 03 Nov 2010 10:09:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=6mrmO9Fipp3fyCqSTp8OqrqrI8UUa+rJ4Uvct3/Yp6I=; b=JKBMsCJY0rgoCY5q4OYvYDexHgOf0bEcRMSiV7KuxjpDCQUCym71rtXXwWQCo0SnGt 83Kjepcg/2ZwmhdpbkWYgrytyRuxwHBHtxvkJxvr6n0ttZWeQy6HliWvAH3BlLNmAtuu 6x5JBgpglme4gjKr9RvlB9nz15ORZ2146UgXg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=jjEF0oJLIqvCnZTz/14hUP4ThUy5PGzAcd4dFM0lJjKm528MhKpQG2urmB6pNrI5sb nU+ZRjDXiKZC8XE0XyiAFHxAxaS5qvxMQp/SZbxrH2sga85LrCPFttrN2xClnzAW0jAq bsYXMKann0hgsgpmaNI9uwoeIrv6oFRCxPMiw= MIME-Version: 1.0 Received: by 10.213.34.198 with SMTP id m6mr4677265ebd.68.1288802446581; Wed, 03 Nov 2010 09:40:46 -0700 (PDT) Received: by 10.213.106.15 with HTTP; Wed, 3 Nov 2010 09:40:46 -0700 (PDT) In-Reply-To: References: Date: Wed, 3 Nov 2010 12:40:46 -0400 Message-ID: From: Ryan Stone To: mdf@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-current@freebsd.org Subject: Re: MTX_DEF versus MTX_SPIN X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Nov 2010 17:10:00 -0000 On Wed, Nov 3, 2010 at 12:27 PM, wrote: > It's not clear to me from the man pages (perhaps I didn't look at the > right one?) in which environments I need a spinlock. =A0For example, I > wouldn't think it's safe to use a MTX_DEF in a hard interrupt handler > (i.e one that was registered with BUS_SETUP_INTR), but I see some code > lying around here that does it and nothing I'm aware of has broken. You can get either a hard interrupt handler(or fast handler in FreeBSD parlance) or a soft handler using BUS_SETUP_INTR. On FreeBSD 7 and later fast interrupt handlers are passed to filter argument to BUS_SETUP_INTR and soft handlers are passed to the ithread argument(on earlier versions you had to pass the INTR_FAST flag to get a fast handler). You are correct that fast interrupt handlers may only acquire spinlocks, not mutexes. Soft interrupt handlers have their own thread associated with them and so it's safe to acquire MTX_DEF locks in that thread. In your particular example you are running from the context of a software interrupt thread, so you are safe to acquire MTX_DEF mutexes.