From owner-freebsd-current@FreeBSD.ORG Wed Nov 3 16:27:09 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 8DDB8106564A for ; Wed, 3 Nov 2010 16:27:09 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-pw0-f54.google.com (mail-pw0-f54.google.com [209.85.160.54]) by mx1.freebsd.org (Postfix) with ESMTP id 6545F8FC19 for ; Wed, 3 Nov 2010 16:27:09 +0000 (UTC) Received: by pwi8 with SMTP id 8so328828pwi.13 for ; Wed, 03 Nov 2010 09:27:08 -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:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=38ssT7+n5k/PLT22QN3Bg7C8RybwM7sNyTaTrcIPkRM=; b=Bs2kUKvgSKhWspL83J4PQNJm+8VUsp+hX37QPgt2wZBJz8NTXjUOQzyaj2OmZ1e3W9 3Zh3lnLuLEQ575lG4sGsKfodGVRozVZdgR3RX/GvcnT2bvZ/lSso7G0bjX6DvT28qPJt GX7QvZ6xNER2KcZR3fco4vKUQN219oVxi5hSo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=TIvAvVzwN8EiTNnKiL49eVggHjWtL+1AzTO9FTnjHLQ0LQVSBXHexpF3GDPVDbba1B VKzkZGela/odknKd798sxcyESE/y2pK2cspBdB+insa8ufjCVDvaJiVsDiEPQPj+bcdW K/ZQv1I45VikuMl2z7lUYM89yv857v2R13Qvs= MIME-Version: 1.0 Received: by 10.42.22.69 with SMTP id n5mr354713icb.477.1288801628033; Wed, 03 Nov 2010 09:27:08 -0700 (PDT) Sender: mdf356@gmail.com Received: by 10.231.159.198 with HTTP; Wed, 3 Nov 2010 09:27:07 -0700 (PDT) Date: Wed, 3 Nov 2010 09:27:07 -0700 X-Google-Sender-Auth: NZDV_J3ZK2-yiYpWhVi_kpqZ66Q Message-ID: From: mdf@FreeBSD.org To: freebsd-current@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Subject: 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 16:27:09 -0000 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. For 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. Perhaps this comes to me still not understanding exactly how interrupts work on FreeBSD. If I capture the stack in a hard interrupt, it looks something like: #0 0xffffff87b07f43b5 at rnv_hard_intr+0x35 #1 0xffffffff8026e7ce at ithread_execute_handlers+0x9e #2 0xffffffff8026ead0 at ithread_loop+0x70 #3 0xffffffff8026b84c at fork_exit+0x9c #4 0xffffffff804a7f7e at fork_trampoline+0xe And there the stack ends. From my perspective, this doesn't look like anything was actually interrupted. By way of explaining what I mean, on AIX we defined 10 levels of software interrupt, and we trained the kernel debugger to understand the save frames that were acquired on interrupt to print a full stack. So a full stack dump might show something like a few frames from one interrupt handler, then a save area, then a frames from a lower priority interrupt, then another save area, then the base-level stack. In this kind of programming environment, it was important to know at what interrupt level your handler would execute, so that locks acquired to synchronize between the top-half and bottom-half were acquired with interupts disabled to the same level. So, back to my question. Is it safe to take a MTX_DEF in a hard interrupt? What about a soft interrupt? I have to assume it's okay in a soft-interrupt context (swi_sched, callout, etc.), since softclock() will acquire a MTX_DEF on behalf of a callout. Thanks, matthew