From owner-freebsd-drivers@FreeBSD.ORG Thu Dec 11 06:38:07 2014 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 441ADB6A for ; Thu, 11 Dec 2014 06:38:07 +0000 (UTC) Received: from mail-oi0-x235.google.com (mail-oi0-x235.google.com [IPv6:2607:f8b0:4003:c06::235]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0AC4D28C for ; Thu, 11 Dec 2014 06:38:07 +0000 (UTC) Received: by mail-oi0-f53.google.com with SMTP id x69so3248961oia.40 for ; Wed, 10 Dec 2014 22:38:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=g4sGRa7KDUCcVbsHIz4hc68VR3z20T+VLrf5BSWB8dU=; b=rCIeEOEdDg+w/X3jWULR+eKmaxV+ruN9f6ru9b7unePrrPCGnQXGeqEKUQKtxLkfsP Z4jG/tjmb71mPX9TouffIWMdGlgYogCoEnNtRVF5U8hs1HR1V4CnJenhF/ue8fCBzI5c 6OJwWXL/wrT5cy49wqtO9DCkCfPocyfdA2jnUou1eSdAYbJfNz6baIODT/DA/jb+YDnh dm8bypNcEMeDrZDcPz2VmahoefAQfxPMCLl7Fd3hlOz1MIaMkiQJScLtJ2qE8SvU76Cf JzLgdv9gzi2FWwSglBiRYG4VN459pHEBILvemeaEeK8iVfEY2zabFOtSoIoyU5HjiEXa dbxg== MIME-Version: 1.0 X-Received: by 10.202.98.10 with SMTP id w10mr5001609oib.104.1418279886379; Wed, 10 Dec 2014 22:38:06 -0800 (PST) Received: by 10.60.25.106 with HTTP; Wed, 10 Dec 2014 22:38:06 -0800 (PST) Date: Thu, 11 Dec 2014 03:38:06 -0300 Message-ID: Subject: Locking a MTX_DEF inside an interrupt thread From: Martin Galvan To: freebsd-drivers@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Dec 2014 06:38:07 -0000 Hi everyone! I was reading the man page on bus_setup_intr() and noticed it warned against sleeping inside an ithread routine. However, I saw a few drivers that start their ithread routines by locking a MTX_DEF mutex, which I understand will make a thread sleep if the mutex is already being held by another thread. Based on that, I'd like to ask you guys a few questions: 1) Why can't we sleep inside an ithread? Isn't being able to context-switch (and thus avoiding using spinlocks) the whole point of using a separate thread for an interrupt handler? 2) What would be the 'correct' way to write an ithread routine which uses shared resources (such as a softc)? 3) Should we fix the drivers that use MTX_DEF mutexes inside their ithreads? Thanks a lot!