Subject: Re: foo_init()s in main() [was: CVS commit: src/sys]
To: Jason Thorpe <thorpej@shagadelic.org>
From: Andrey Petrov <andrei@xensource.com>
List: tech-kern
Date: 11/22/2005 15:13:08
On Tue, Nov 22, 2005 at 02:18:31PM -0800, Jason Thorpe wrote:
>
> On Nov 22, 2005, at 1:53 PM, Bill Studenmund wrote:
>
> >How do you think we should encode dependencies? I agree that the
> >FreeBSD
> >way is uncentralized. However someone who studies the whole system can
> >tune it so that things get loaded in the right order (just pick the
> >right
> >set of "FIRST", "SECOND", and so on). How would we do that w/o the
> >master
> >list of values?
>
> The init routine for each subsystem could easily enough call init
> routines for the subsystems on which it depends. Each of those init
> routines would internally handle the "once" handling.
>
> e.g.
>
> static void
> foo_init0(void)
> {
> /* do stuff */
> }
>
> void
> foo_init(void)
> {
> static ONCE_DECL(once_control);
>
> RUN_ONCE(once_control, foo_init0);
> }
>
>
>
> So, consider a network driver, which would call if_attach()...
> if_attach() would in turn call if_init(), which would in turn call
> if_init0() once.
>
> For things like lists / tables / etc., we can change to using static
> initializers for those.
>
It could be done by kernel linker(loader) so he'll be responsible for module loading
and initialization, and so it wouldn't be needed to code dependiencies explicitly.
-Andrey