Subject: Re: foo_init()s in main() [was: CVS commit: src/sys]
To: Martin Husemann <martin@duskware.de>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-kern
Date: 11/22/2005 20:50:32
Martin Husemann wrote:

> On Tue, Nov 22, 2005 at 11:29:35AM +1100, Simon Burge wrote:
> > It really seems like we should do something to automate this, say based
> > on the FreeBSD sysinit stuff or linksets or something.
> 
> Yes, we should.
> Could anyone give a summary of "FreeBSD sysinit" stuff?

In a very brief nut-shell there's a macro SYSINIT:

	#define SYSINIT(uniquifier, subsystem, order, func, ident) \
	  ...

which builds a link set of initialisation functions.

"uniquifier" is used to build the link set variable name. "subsystem" is
a numeric constant that defines the order of the function in the startup
sequence [1]. "order" sorts orders within a subsystem [2]. "func" is the
function, and "ident" appears to be an arg to "func".

To pick an example at random, net/route.c then says:

   SYSINIT(route, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, route_init, 0);

The function that then iterates over the link set of initialisation
functions replaces what is our main() in init_main.c.

Note that this is just based on a glance at the FreeBSD code.  I may be
entirely wrong about how this works :-)

[1] - see sysinit_sub_id in
http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/kernel.h?rev=1.127

[2] - see sysinit_elem_order in
http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/kernel.h?rev=1.127

Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD Support and Service:         http://www.wasabisystems.com/