From owner-freebsd-arch@FreeBSD.ORG Thu Mar 10 20:28:20 2011 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 994C8106564A; Thu, 10 Mar 2011 20:28:20 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 6CDF18FC12; Thu, 10 Mar 2011 20:28:20 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id EBAE846B89; Thu, 10 Mar 2011 15:28:19 -0500 (EST) Received: from jhbbsd.localnet (unknown [209.249.190.10]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 799B68A01B; Thu, 10 Mar 2011 15:28:19 -0500 (EST) From: John Baldwin To: mdf@freebsd.org Date: Thu, 10 Mar 2011 15:28:18 -0500 User-Agent: KMail/1.13.5 (FreeBSD/7.4-CBSD-20110107; KDE/4.4.5; amd64; ; ) References: <201103101446.37589.jhb@freebsd.org> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201103101528.18987.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Thu, 10 Mar 2011 15:28:19 -0500 (EST) Cc: freebsd-arch@freebsd.org Subject: Re: style(9) rules for nested includes 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: Thu, 10 Mar 2011 20:28:20 -0000 On Thursday, March 10, 2011 3:10:58 pm mdf@freebsd.org wrote: > On Thu, Mar 10, 2011 at 11:46 AM, John Baldwin wrote: > > On Thursday, March 10, 2011 12:17:28 pm mdf@freebsd.org wrote: > >> I recall a recent discussion/PR about nested includes in the context > >> of and being a few of the only ones > >> allowed. However, I don't see anything in style(9) about this. > > > > bde@ is probably the most authoritative. My understanding is that the only > > nested includes allowed in sys/sys/*.h are the two listed above and any header > > that starts with an underscore (sys/_mutex.h, etc.). The underscore variants > > were added to allow nested includes when absolutely necessary, but those > > includes are the bare minimum required to define structures, etc. > > > >> Now we come to the reason I ask. I'm working on a patch to change the > >> static sysctl code to use the standard SYSININT/SYSUNINIT code rather > >> than have special treatment in kern_linker.c, but to do this I need to > >> either change quite a few places that include , or > >> include instead of in sysctl.h, as > >> the SI_SUB_SYSCTLS value isn't visible otherwise. > > > > Hmm, what is the reason to use SYSINIT's instead of a dedicated linker set? > > Mostly for consistency. The DB_COMMAND linker set was changed to use > SYSINITs for version 8, and AFIAK SYSCTL is the only global kernel > thing using a separate linker set. That was because DB commands in modules just didn't work at all before. :) > There's also a minor bug in initialization ordering where a static > SYSCTL_PROC could use a lock initialized by SX_SYSINIT or MTX_SYSINIT, > but at runtime module load the sysctl is exposed before the > SI_SUB_LOCK stage has run, so in theory someone doing sysctl -a would > crash the kernel on an attempt to lock an uninitialized mtx/sx. We > saw this happen once at Isilon. Hmm, this is a legitimate reason, though I'd be tempted to fix that by just registering sysctls after sysinit's have been invoked and vice versa on unload. It seems that would be a simpler fix with far less code churn and not having to deal with the nested include mess, etc. One thing I often do, btw when dealing these sorts of interdependencies in a loadable module, is to use a single SYSINIT or module event handler to do all the setup and teardown of a single kld. This lets you handle errors far better (SYSINIT's don't allow for that at all) and more explicitly order the set of operations. -- John Baldwin