From owner-freebsd-arch@FreeBSD.ORG Sat Sep 5 08:36:28 2009 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 59E51106566C; Sat, 5 Sep 2009 08:36:28 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (bsdimp.com [199.45.160.85]) by mx1.freebsd.org (Postfix) with ESMTP id 198F88FC19; Sat, 5 Sep 2009 08:36:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by harmony.bsdimp.com (8.14.3/8.14.1) with ESMTP id n858ZE7T011573; Sat, 5 Sep 2009 02:35:14 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Sat, 05 Sep 2009 02:36:34 -0600 (MDT) Message-Id: <20090905.023634.831786645.imp@bsdimp.com> To: attilio@freebsd.org From: "M. Warner Losh" In-Reply-To: <20090904.172310.-1939841993.imp@bsdimp.com> References: <20090904.161634.-217944108.imp@bsdimp.com> <3bbf2fe10909041546y2b5633e1ue063955568df1a06@mail.gmail.com> <20090904.172310.-1939841993.imp@bsdimp.com> X-Mailer: Mew version 5.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: arch@freebsd.org Subject: Re: NEWBUS states X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Sep 2009 08:36:28 -0000 In message: <20090904.172310.-1939841993.imp@bsdimp.com> "M. Warner Losh" writes: : OK. Let me ponder based on that... It might be better for this round : of changes to leverage off the device 'flags' field to indicate that : we're attaching/detaching. This would not break the : device_is_attached() usage, and would solve the interlock problem : nicely. While it isn't as aesthetically pleasing as the new states, : it would allow us to easily MFC it without API/ABI breakage. This : field surely would be covered by the same set of locks as the state : field. : : I know that there's a good aesthetic argument to be made against this, : but on the other hand 'compatibility' hacks can violate one's : aesthetics. We can migrate to a more pleasing state-based model in 9 : and reduce the risk to other code from changing its semantics at this : late date. For a version of this hack, see http://people.freebsd.org/~imp/newbus-flags.diff This preserves the semantics of the state field as they exist today, while also providing protection against reentrent code. It also restores a check for GIANT_HELD to the attach routine, which seems to have disappeared along the way. While not needed when the locking does arrive, it is needed today, I believe. It also has the advantage that the following could easily be added to catch wayward drivers: int device_is_attached(device_t dev) { if (dev->flags & DF_TRANSITION) printf( "%s called %s while in attach/detach. This is no deprecated.", device_get_nameunit(dev), __func__); return (dev->state >= DS_ATTACHED); } Or make it a KASSERT later in the 9.x release cycle. Hope this make it clear what my proposed alternative would be... Warner P.S. Yes, I'd rate this code as speculative as the code it replaces (see my prior posts for this criticism). This is an example of how it could be done with less impact to the existing code base, a consideration only because we're in the high 50's of minutes in the 11th hour for the 8.0 release...