From owner-freebsd-current@freebsd.org Wed Aug 5 00:04:24 2015 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4AD119B37A5 for ; Wed, 5 Aug 2015 00:04:24 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 28B38107E for ; Wed, 5 Aug 2015 00:04:24 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from ralph.baldwin.cx (75-48-78-19.lightspeed.cncrca.sbcglobal.net [75.48.78.19]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 16CB4B94A; Tue, 4 Aug 2015 20:04:23 -0400 (EDT) From: John Baldwin To: freebsd-current@freebsd.org Cc: John-Mark Gurney , Ryan Stone Subject: Re: How should a driver shutdown a taskqueue on detach? Date: Tue, 04 Aug 2015 14:08:02 -0700 Message-ID: <8275579.N9C6ZanMsb@ralph.baldwin.cx> User-Agent: KMail/4.14.3 (FreeBSD/10.2-PRERELEASE; KDE/4.14.3; amd64; ; ) In-Reply-To: <20150701232510.GH96349@funkthat.com> References: <20150701232510.GH96349@funkthat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 04 Aug 2015 20:04:23 -0400 (EDT) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 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, 05 Aug 2015 00:04:24 -0000 On Wednesday, July 01, 2015 04:25:10 PM John-Mark Gurney wrote: > Ryan Stone wrote this message on Wed, Jul 01, 2015 at 15:44 -0400: > > I'm trying to figure out how a driver is supposed to shut down its > > interrupt-handling taskqueue when it detaches. taskqueue(9) recommends > > disabling interrupts, draining each task and then freeing the taskqueue. > > The problem that I have is the interrupt-handling tasks will sometimes > > re-enable interrupts on the device. Is there a better way than using some > > kind of flag internally in the driver to note that a detach is in progress > > that the interrupt handlers will have to check before enabling interrupts? > > Why not disabled interrupts, unregister interrupt handler, and then > make sure interrupts are disabled (only needed to prevent an interrupt > storm)? Once you have unregistered the interrupt handler, it can't run > again... Then you're free to drain the task queue safely... Yes. Do the bus_teardown_intr() first, then drain any pending tasks. -- John Baldwin