From owner-freebsd-current@FreeBSD.ORG Wed Nov 3 17:04:14 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 AD3681065672 for ; Wed, 3 Nov 2010 17:04:14 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-iw0-f182.google.com (mail-iw0-f182.google.com [209.85.214.182]) by mx1.freebsd.org (Postfix) with ESMTP id 71B9B8FC18 for ; Wed, 3 Nov 2010 17:04:14 +0000 (UTC) Received: by iwn39 with SMTP id 39so928865iwn.13 for ; Wed, 03 Nov 2010 10:04:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=E4NjuZTm2ZdvuZiRMrjaIPkPFxw7cty7I7cb3fWFW18=; b=IjiJE9IqG2LHbnr4G/PalcQQwUqY1Itsf2i/4OPeQaIHQVKgRnJzb4RoQd15bhc15q QtWwKfgZXn3g9owJZh5WbxqsS8y3ImaqSLoKGhaWVldcPzFbOuFnE78pjqaBYGcwMlWH PZQoyNJslSCH7OOoRQyzTkZFZ0232MjbqTKS4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=HTrIpMdeY/IuKZ9evMOzBKZP7pDynPl+pT5mTSgW8yoMAMhSS8fjzDxglWXV+o5GTZ Wb71urPlycIjW/sWUf+9BhHdOPs3Z17ThqxL77a+hOeOgEAzeflpgPB0wRddk/GFTe19 d85fEB2Tgf7ebhNfsjRZVNgGOUn/frse8IZrI= MIME-Version: 1.0 Received: by 10.231.36.11 with SMTP id r11mr5448797ibd.58.1288803853537; Wed, 03 Nov 2010 10:04:13 -0700 (PDT) Sender: mdf356@gmail.com Received: by 10.231.159.198 with HTTP; Wed, 3 Nov 2010 10:04:13 -0700 (PDT) In-Reply-To: <4CD190EF.5080600@icyb.net.ua> References: <4CD190EF.5080600@icyb.net.ua> Date: Wed, 3 Nov 2010 10:04:13 -0700 X-Google-Sender-Auth: Xqcul_ec2hZdO7se7-sULu6f2pE Message-ID: From: mdf@FreeBSD.org To: Andriy Gapon 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:04:14 -0000 On Wed, Nov 3, 2010 at 9:42 AM, Andriy Gapon wrote: > on 03/11/2010 18:27 mdf@FreeBSD.org said the following: >> 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. > > Such a handler runs in an interrupt thread. > The "harder" interrupt handler is called interrupt filter in FreeBSD term= inology. > =A0I think that it was formerly known as fast interrupt. So a MTX_DEF is okay in that environment? What would "best practices" be considered for what code should be run in the interrupt handler versus a soft interrupt? In this case the kinds of things we have to do at some level of interrupt are: - handle a heartbeat interrupt from firmware a few times a second - get a DMA completion interrupt (completely handling this requires calling biodone on all the associated bios) - receive an ECC interrupt (this requires reading registers off the card for details) At the moment we're on stable/7, but we will be migrating the code base to something more recent in another year or so, if that affects the answer. Is there any documentation on best practices for writing a FreeBSD driver? Thanks, matthew