* Re: Recommendation for activating a deferred module init in the kernel
@ 2008-06-18 6:47 Gilad Ben-Yossef
2008-06-18 8:20 ` David Woodhouse
0 siblings, 1 reply; 30+ messages in thread
From: Gilad Ben-Yossef @ 2008-06-18 6:47 UTC (permalink / raw)
To: Tim Bird; +Cc: linux-embedded
[Resending due to reject from vger mail server. My apologies if you got
this twice ]
Hi,
Tim Bird wrote:
> I am working with a product team on bootup time issues. One technique
> that we are forward-porting from an old kernel (and that I thought I
> might work on mainlining) is to compile modules statically into the kernel,
> but defer their initialization until after boot time.
>
This may sound like a stupid question, but why are you compiling the
modules statically?
I mean, it sounds to me like the perfect way to do what you want is to
compile the modules dynamically (you can store them in a an in kernel
initramfs if you want to keep them attached to the kernel binary for
ease of maintenance) and simply call a script that calls modprobe when
it's OK to load them?
Sounds a hell of lot simpler to me...
Gilad
--
Gilad Ben-Yossef
Chief Coffee Drinker
Codefidence Ltd.
The code is free, your time isn't.(TM)
Web: http://codefidence.com
Email: gilad@codefidence.com
Office: +972-8-9316883 ext. 201
Fax: +972-8-9316885
Mobile: +972-52-8260388
Q: How many NSA agents does it take to replace a lightbulb?
A: dSva7DrYiY24yeTItKyyogFXD5gRuoRqPNQ9v6WCLLywZPINlu!
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-18 6:47 Recommendation for activating a deferred module init in the kernel Gilad Ben-Yossef
@ 2008-06-18 8:20 ` David Woodhouse
2008-06-18 8:32 ` David Woodhouse
2008-06-18 8:52 ` Adrian Bunk
0 siblings, 2 replies; 30+ messages in thread
From: David Woodhouse @ 2008-06-18 8:20 UTC (permalink / raw)
To: Gilad Ben-Yossef; +Cc: Tim Bird, linux-embedded
On Wed, 2008-06-18 at 09:47 +0300, Gilad Ben-Yossef wrote:
> This may sound like a stupid question, but why are you compiling the
> modules statically?
I wondered that.
One potential reason to avoid modules is that they waste RAM -- you have
to allocate an integral number of pages for each one, which means an
average of 2KiB wasted for each module you load. Although that isn't
much, it's not zero either. It might be possible to optimise that by
'packing' module allocations, if you're careful about it.
Also, on some architectures modules have historically been less
efficient because when kernel and module text are too far apart in the
virtual address space, you have to insert trampolines for all calls
between them. I believe this used to be the case on ARM, but it got
fixed by moving stuff around? It's only v850 which still does this
AFAICT.
Do we actually manage to free inittext/initdata from modules on all
architectures now? The comments in <linux/init.h> suggest not, but I
think they lie -- it looks like like kernel/module.c will handle that
entirely generically for sections named ".init*" -- it'll allocate space
for those sections in a separate module_alloc() call, and free them
itself. (Do bear this in mind, if you take the above suggestion about
packing in module_alloc().)
So the only real reason I can see to avoid modules in the _current_
kernel would be the wasted RAM, which should be something we can
address. Tim, have I missed something? What _were_ your reasons for
avoiding modules, and can we do something about those instead of trying
to defer the initialisation of in-kernel code?
Delaying init of certain modules seems like a poor man's substitute for
a properly multi-threaded startup....
--
dwmw2
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-18 8:20 ` David Woodhouse
@ 2008-06-18 8:32 ` David Woodhouse
2008-06-18 8:52 ` Adrian Bunk
1 sibling, 0 replies; 30+ messages in thread
From: David Woodhouse @ 2008-06-18 8:32 UTC (permalink / raw)
To: Gilad Ben-Yossef; +Cc: Tim Bird, linux-embedded
On Wed, 2008-06-18 at 09:20 +0100, David Woodhouse wrote:
> So the only real reason I can see to avoid modules in the _current_
> kernel would be the wasted RAM, which should be something we can
> address. Tim, have I missed something?
... like the time it takes to actually load modules and do the
relocations, perhaps? You did say you were doing it to improve boot
time. But this is the stuff you were happy to _defer_, so presumably not
in your fast path?
If that _is_ a real concern, then given the observation¹ that most
systems load exactly the same modules in exactly the same order every
time they boot... has anyone looked at doing 'prelink' for modules?
--
dwmw2
¹ which I just pulled out of my arse, admittedly. But I think it's true :)
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-18 8:20 ` David Woodhouse
2008-06-18 8:32 ` David Woodhouse
@ 2008-06-18 8:52 ` Adrian Bunk
2008-06-18 8:57 ` Geert Uytterhoeven
1 sibling, 1 reply; 30+ messages in thread
From: Adrian Bunk @ 2008-06-18 8:52 UTC (permalink / raw)
To: David Woodhouse; +Cc: Gilad Ben-Yossef, Tim Bird, linux-embedded
On Wed, Jun 18, 2008 at 09:20:22AM +0100, David Woodhouse wrote:
> On Wed, 2008-06-18 at 09:47 +0300, Gilad Ben-Yossef wrote:
> > This may sound like a stupid question, but why are you compiling the
> > modules statically?
>
> I wondered that.
>
> One potential reason to avoid modules is that they waste RAM -- you have
> to allocate an integral number of pages for each one, which means an
> average of 2KiB wasted for each module you load. Although that isn't
> much, it's not zero either. It might be possible to optimise that by
> 'packing' module allocations, if you're careful about it.
>...
> So the only real reason I can see to avoid modules in the _current_
> kernel would be the wasted RAM, which should be something we can
> address.
>...
You miss the size increase imposed by CONFIG_MODULES=y.
E.g. setting CONFIG_MODULES=y in the arm collie_defconfig will
increase the size of vmlinux by 14% (sic).
I haven't investigated why it takes that much space, but stuff like
kernel/module.o taking 23kB and each EXPORT_SYMBOL requiring a few
bytes simply cannot be completely eliminated.
> dwmw2
cu
Adrian
--
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-18 8:52 ` Adrian Bunk
@ 2008-06-18 8:57 ` Geert Uytterhoeven
2008-06-18 9:59 ` David Woodhouse
0 siblings, 1 reply; 30+ messages in thread
From: Geert Uytterhoeven @ 2008-06-18 8:57 UTC (permalink / raw)
To: Adrian Bunk; +Cc: David Woodhouse, Gilad Ben-Yossef, Tim Bird, linux-embedded
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1804 bytes --]
On Wed, 18 Jun 2008, Adrian Bunk wrote:
> On Wed, Jun 18, 2008 at 09:20:22AM +0100, David Woodhouse wrote:
> > On Wed, 2008-06-18 at 09:47 +0300, Gilad Ben-Yossef wrote:
> > > This may sound like a stupid question, but why are you compiling the
> > > modules statically?
> >
> > I wondered that.
> >
> > One potential reason to avoid modules is that they waste RAM -- you have
> > to allocate an integral number of pages for each one, which means an
> > average of 2KiB wasted for each module you load. Although that isn't
> > much, it's not zero either. It might be possible to optimise that by
> > 'packing' module allocations, if you're careful about it.
> >...
> > So the only real reason I can see to avoid modules in the _current_
> > kernel would be the wasted RAM, which should be something we can
> > address.
> >...
>
> You miss the size increase imposed by CONFIG_MODULES=y.
>
> E.g. setting CONFIG_MODULES=y in the arm collie_defconfig will
> increase the size of vmlinux by 14% (sic).
>
> I haven't investigated why it takes that much space, but stuff like
> kernel/module.o taking 23kB and each EXPORT_SYMBOL requiring a few
> bytes simply cannot be completely eliminated.
Sounds like we need a tool that strips out the unneeded symbols, given a list
of modules?
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Techsoft Centre
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453
Fax: +32 (0)2 700 8622
E-mail: Geert.Uytterhoeven@sonycom.com
Internet: http://www.sony-europe.com/
Sony Technology and Software Centre Europe
A division of Sony Service Centre (Europe) N.V.
Registered office: Technologielaan 7 · B-1840 Londerzeel · Belgium
VAT BE 0413.825.160 · RPR Brussels
Fortis 293-0376800-10 GEBA-BE-BB
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-18 8:57 ` Geert Uytterhoeven
@ 2008-06-18 9:59 ` David Woodhouse
2008-06-18 10:33 ` Adrian Bunk
0 siblings, 1 reply; 30+ messages in thread
From: David Woodhouse @ 2008-06-18 9:59 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Adrian Bunk, Gilad Ben-Yossef, Tim Bird, linux-embedded
On Wed, 2008-06-18 at 10:57 +0200, Geert Uytterhoeven wrote:
> On Wed, 18 Jun 2008, Adrian Bunk wrote:
> > On Wed, Jun 18, 2008 at 09:20:22AM +0100, David Woodhouse wrote:
> > > On Wed, 2008-06-18 at 09:47 +0300, Gilad Ben-Yossef wrote:
> > > > This may sound like a stupid question, but why are you compiling the
> > > > modules statically?
> > >
> > > I wondered that.
> > >
> > > One potential reason to avoid modules is that they waste RAM -- you have
> > > to allocate an integral number of pages for each one, which means an
> > > average of 2KiB wasted for each module you load. Although that isn't
> > > much, it's not zero either. It might be possible to optimise that by
> > > 'packing' module allocations, if you're careful about it.
> > >...
> > > So the only real reason I can see to avoid modules in the _current_
> > > kernel would be the wasted RAM, which should be something we can
> > > address.
> > >...
> >
> > You miss the size increase imposed by CONFIG_MODULES=y.
> >
> > E.g. setting CONFIG_MODULES=y in the arm collie_defconfig will
> > increase the size of vmlinux by 14% (sic).
> >
> > I haven't investigated why it takes that much space, but stuff like
> > kernel/module.o taking 23kB and each EXPORT_SYMBOL requiring a few
> > bytes simply cannot be completely eliminated.
>
> Sounds like we need a tool that strips out the unneeded symbols, given a list
> of modules?
And do the --gc-sections step again after that... :)
--
dwmw2
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-18 9:59 ` David Woodhouse
@ 2008-06-18 10:33 ` Adrian Bunk
2008-06-18 10:41 ` David Woodhouse
2008-06-18 11:37 ` Geert Uytterhoeven
0 siblings, 2 replies; 30+ messages in thread
From: Adrian Bunk @ 2008-06-18 10:33 UTC (permalink / raw)
To: David Woodhouse
Cc: Geert Uytterhoeven, Gilad Ben-Yossef, Tim Bird, linux-embedded
On Wed, Jun 18, 2008 at 10:59:50AM +0100, David Woodhouse wrote:
> On Wed, 2008-06-18 at 10:57 +0200, Geert Uytterhoeven wrote:
> > On Wed, 18 Jun 2008, Adrian Bunk wrote:
> > > On Wed, Jun 18, 2008 at 09:20:22AM +0100, David Woodhouse wrote:
> > > > On Wed, 2008-06-18 at 09:47 +0300, Gilad Ben-Yossef wrote:
> > > > > This may sound like a stupid question, but why are you compiling the
> > > > > modules statically?
> > > >
> > > > I wondered that.
> > > >
> > > > One potential reason to avoid modules is that they waste RAM -- you have
> > > > to allocate an integral number of pages for each one, which means an
> > > > average of 2KiB wasted for each module you load. Although that isn't
> > > > much, it's not zero either. It might be possible to optimise that by
> > > > 'packing' module allocations, if you're careful about it.
> > > >...
> > > > So the only real reason I can see to avoid modules in the _current_
> > > > kernel would be the wasted RAM, which should be something we can
> > > > address.
> > > >...
> > >
> > > You miss the size increase imposed by CONFIG_MODULES=y.
> > >
> > > E.g. setting CONFIG_MODULES=y in the arm collie_defconfig will
> > > increase the size of vmlinux by 14% (sic).
> > >
> > > I haven't investigated why it takes that much space, but stuff like
> > > kernel/module.o taking 23kB and each EXPORT_SYMBOL requiring a few
> > > bytes simply cannot be completely eliminated.
> >
> > Sounds like we need a tool that strips out the unneeded symbols, given a list
> > of modules?
>
> And do the --gc-sections step again after that... :)
But even after all optimizations CONFIG_MODULES=y will still cause a
significant additional cost [1] when thinking in the dimensions of
Tim's "the 30 or so Linux-tiny patches that I use get me about 110k of
reductions. For me, this is about 5% of my kernel size" statement in
another thread.
> dwmw2
cu
Adrian
[1] as I said, kernel/module.o alone takes 23kB
--
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-18 10:33 ` Adrian Bunk
@ 2008-06-18 10:41 ` David Woodhouse
2008-06-18 11:37 ` Geert Uytterhoeven
1 sibling, 0 replies; 30+ messages in thread
From: David Woodhouse @ 2008-06-18 10:41 UTC (permalink / raw)
To: Adrian Bunk
Cc: Geert Uytterhoeven, Gilad Ben-Yossef, Tim Bird, linux-embedded
On Wed, 2008-06-18 at 13:33 +0300, Adrian Bunk wrote:
> But even after all optimizations CONFIG_MODULES=y will still cause a
> significant additional cost [1] when thinking in the dimensions of
> Tim's "the 30 or so Linux-tiny patches that I use get me about 110k of
> reductions. For me, this is about 5% of my kernel size" statement in
> another thread.
Yes. If the system in question is currently being built without
CONFIG_MODULES, that's fairly much a no-go for my alternative
suggestion.
--
dwmw2
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-18 10:33 ` Adrian Bunk
2008-06-18 10:41 ` David Woodhouse
@ 2008-06-18 11:37 ` Geert Uytterhoeven
2008-06-18 14:56 ` Nicolas Pitre
1 sibling, 1 reply; 30+ messages in thread
From: Geert Uytterhoeven @ 2008-06-18 11:37 UTC (permalink / raw)
To: Adrian Bunk; +Cc: David Woodhouse, Gilad Ben-Yossef, Tim Bird, linux-embedded
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1742 bytes --]
On Wed, 18 Jun 2008, Adrian Bunk wrote:
> On Wed, Jun 18, 2008 at 10:59:50AM +0100, David Woodhouse wrote:
> > On Wed, 2008-06-18 at 10:57 +0200, Geert Uytterhoeven wrote:
> > > On Wed, 18 Jun 2008, Adrian Bunk wrote:
> > > > You miss the size increase imposed by CONFIG_MODULES=y.
> > > >
> > > > E.g. setting CONFIG_MODULES=y in the arm collie_defconfig will
> > > > increase the size of vmlinux by 14% (sic).
> > > >
> > > > I haven't investigated why it takes that much space, but stuff like
> > > > kernel/module.o taking 23kB and each EXPORT_SYMBOL requiring a few
> > > > bytes simply cannot be completely eliminated.
> > >
> > > Sounds like we need a tool that strips out the unneeded symbols, given a list
> > > of modules?
> >
> > And do the --gc-sections step again after that... :)
>
> But even after all optimizations CONFIG_MODULES=y will still cause a
> significant additional cost [1] when thinking in the dimensions of
> Tim's "the 30 or so Linux-tiny patches that I use get me about 110k of
> reductions. For me, this is about 5% of my kernel size" statement in
> another thread.
>
> [1] as I said, kernel/module.o alone takes 23kB
Which could be freed after the last module has been loaded?
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Techsoft Centre
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453
Fax: +32 (0)2 700 8622
E-mail: Geert.Uytterhoeven@sonycom.com
Internet: http://www.sony-europe.com/
Sony Technology and Software Centre Europe
A division of Sony Service Centre (Europe) N.V.
Registered office: Technologielaan 7 · B-1840 Londerzeel · Belgium
VAT BE 0413.825.160 · RPR Brussels
Fortis 293-0376800-10 GEBA-BE-BB
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-18 11:37 ` Geert Uytterhoeven
@ 2008-06-18 14:56 ` Nicolas Pitre
0 siblings, 0 replies; 30+ messages in thread
From: Nicolas Pitre @ 2008-06-18 14:56 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Adrian Bunk, David Woodhouse, Gilad Ben-Yossef, Tim Bird,
linux-embedded
On Wed, 18 Jun 2008, Geert Uytterhoeven wrote:
> On Wed, 18 Jun 2008, Adrian Bunk wrote:
> > On Wed, Jun 18, 2008 at 10:59:50AM +0100, David Woodhouse wrote:
> > > On Wed, 2008-06-18 at 10:57 +0200, Geert Uytterhoeven wrote:
> > > > On Wed, 18 Jun 2008, Adrian Bunk wrote:
> > > > > You miss the size increase imposed by CONFIG_MODULES=y.
> > > > >
> > > > > E.g. setting CONFIG_MODULES=y in the arm collie_defconfig will
> > > > > increase the size of vmlinux by 14% (sic).
> > > > >
> > > > > I haven't investigated why it takes that much space, but stuff like
> > > > > kernel/module.o taking 23kB and each EXPORT_SYMBOL requiring a few
> > > > > bytes simply cannot be completely eliminated.
> > > >
> > > > Sounds like we need a tool that strips out the unneeded symbols, given a list
> > > > of modules?
> > >
> > > And do the --gc-sections step again after that... :)
> >
> > But even after all optimizations CONFIG_MODULES=y will still cause a
> > significant additional cost [1] when thinking in the dimensions of
> > Tim's "the 30 or so Linux-tiny patches that I use get me about 110k of
> > reductions. For me, this is about 5% of my kernel size" statement in
> > another thread.
> >
> > [1] as I said, kernel/module.o alone takes 23kB
>
> Which could be freed after the last module has been loaded?
Even if you free the module loading infrastructure afterwards, you still
have to carry it in flash for both the kernel part and the user part.
And the whole process (having to sort out module loading in user space,
etc.) is still more complex than not having to load modules at all. Many
embedded designs have fixed hardware configuration and purpose which
makes dynamic module loading an unnecessary bloat.
Having the kernel span a parallel thread with a lower priority to
initialize drivers could be a much simpler solution in terms of size and
speed. This way the init process could run early, and devices would
become available eventually just as if corresponding modules were
loaded.
The only difficulty is to properly determine how to distinguish between
drivers that have to be initialized early in order to mount the root fs
and the others that can wait.
Nicolas
^ permalink raw reply [flat|nested] 30+ messages in thread
* Recommendation for activating a deferred module init in the kernel
@ 2008-06-17 18:23 Tim Bird
2008-06-17 18:51 ` David VomLehn
` (3 more replies)
0 siblings, 4 replies; 30+ messages in thread
From: Tim Bird @ 2008-06-17 18:23 UTC (permalink / raw)
To: linux-embedded
Hi all,
I am working with a product team on bootup time issues. One technique
that we are forward-porting from an old kernel (and that I thought I
might work on mainlining) is to compile modules statically into the kernel,
but defer their initialization until after boot time.
Normally, module init routines are declared with module_init(), which,
when they are statically linked into the kernel, uses the macro
__define_initcall() to add an entry to a special init segment.
This is called during bootup by do_initcall() (in init/main.c),
and the memory where the function resides is eventually freed.
There are several phases of initcalls (see include/linux/init.h),
including core, postcore, arch, subsys, fs, rootfs, device, and late.
In our modification, we:
1) add another phase for deferred initcalls
2) modify the module_init macro definition to use that phase, for the
modules we wish to defer initialization of
3) modify the free code to not free the memory until later
4) add an ioctl to trigger the deferred initialization (and memory free)
One of the main sub-systems that we defer initialization of this
way is USB, and this saves quite a bit of time. (Of course the
same, or slightly more CPU cycles are eventually used during
bootup time. But this lets us get to user space quicker so we
can start user-visible applications faster.)
I'm not that happy using an ioctl for this trigger. What is
the preferred method of activating a kernel feature like this?
I presume something in /proc or /sys, but I'm not sure.
Also, is there something like this in the kernel now that I'm
missing?
Any advice or comments would be welcome.
Thanks,
-- Tim
=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-17 18:23 Tim Bird
@ 2008-06-17 18:51 ` David VomLehn
2008-06-17 19:07 ` Jörn Engel
` (2 subsequent siblings)
3 siblings, 0 replies; 30+ messages in thread
From: David VomLehn @ 2008-06-17 18:51 UTC (permalink / raw)
To: Tim Bird; +Cc: linux-embedded
Tim Bird wrote:
> Hi all,
>
> I am working with a product team on bootup time issues. One technique that we
> are forward-porting from an old kernel (and that I thought I might work on
> mainlining) is to compile modules statically into the kernel, but defer their
> initialization until after boot time.
...
> One of the main sub-systems that we defer initialization of this way is USB,
> and this saves quite a bit of time. (Of course the same, or slightly more CPU
> cycles are eventually used during bootup time. But this lets us get to user
> space quicker so we can start user-visible applications faster.)
>
> I'm not that happy using an ioctl for this trigger. What is the preferred
> method of activating a kernel feature like this? I presume something in /proc
> or /sys, but I'm not sure.
From your description, it seems as though you always want to do the
initialization, you just may want to delay it until well after starting up user
space. If something like this were performance-critical, an ioctl might be
justified, but this would be a one-time trigger. I think that making this as
closely analogous to loading a kernel module as possible is a good conceptual
approach. Since you might choose, at run time, whether or not to load a kernel
module, it makes sense to do this on a device-by-device basis. To me, that
suggests doing something in /sys.
My first impression was that this was an awful kludge, but drawing the parallel
to loadable modules makes me not only happier, but also leads me into wondering
if there shouldn't be a generic framework for supporting this. So, instead of
using module_init, there might be some other macro that indicated that this
driver was to be initialized in a deferred, and optional, fashion.
--
David VomLehn, dvomlehn@cisco.com
The opinions expressed herein are likely mine, but might not be my employer's...
- - - - - Cisco - - - - -
This e-mail and any attachments may contain information which is confidential,
proprietary, privileged or otherwise protected by law. The information is solely
intended for the named addressee (or a person responsible for delivering it to
the addressee). If you are not the intended recipient of this message, you are
not authorized to read, print, retain, copy or disseminate this message or any
part of it. If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete it from your computer.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-17 18:23 Tim Bird
2008-06-17 18:51 ` David VomLehn
@ 2008-06-17 19:07 ` Jörn Engel
2008-06-17 19:22 ` Jim Freeman
2008-06-17 19:52 ` Tim Bird
2008-06-18 12:38 ` Amol Lad
[not found] ` <4858A659.8030502@codefidence.com>
3 siblings, 2 replies; 30+ messages in thread
From: Jörn Engel @ 2008-06-17 19:07 UTC (permalink / raw)
To: Tim Bird; +Cc: linux-embedded
On Tue, 17 June 2008 11:23:18 -0700, Tim Bird wrote:
>
> I'm not that happy using an ioctl for this trigger. What is
> the preferred method of activating a kernel feature like this?
> I presume something in /proc or /sys, but I'm not sure.
I personally would be unhappy with any kind of interface for this. It
would be much nicer to make it transparent and still get the benefits.
One option would be to start a kernel thread for the initialization and
renice it to 19 or so.
If you want an explicit trigger, you could either hook into init_post()
or have hooks in the open functions of drivers with deferred
initialization. Obviously you need to wait for completion here anyway,
so adding a trigger wouldn't be too expensive.
Jörn
--
Joern's library part 13:
http://www.chip-architect.com/
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-17 19:07 ` Jörn Engel
@ 2008-06-17 19:22 ` Jim Freeman
2008-06-17 20:06 ` Tim Bird
2008-06-17 19:52 ` Tim Bird
1 sibling, 1 reply; 30+ messages in thread
From: Jim Freeman @ 2008-06-17 19:22 UTC (permalink / raw)
To: J??rn Engel; +Cc: Tim Bird, linux-embedded
On Tue, Jun 17, 2008 at 09:07:51PM +0200, J??rn Engel wrote:
> On Tue, 17 June 2008 11:23:18 -0700, Tim Bird wrote:
> >
> > I'm not that happy using an ioctl for this trigger. What is
> > the preferred method of activating a kernel feature like this?
> > I presume something in /proc or /sys, but I'm not sure.
>
> I personally would be unhappy with any kind of interface for this. It
> would be much nicer to make it transparent and still get the benefits.
> One option would be to start a kernel thread for the initialization and
> renice it to 19 or so.
>
> If you want an explicit trigger, you could either hook into init_post()
> or have hooks in the open functions of drivers with deferred
> initialization. Obviously you need to wait for completion here anyway,
> so adding a trigger wouldn't be too expensive.
Run modprobe? Have it do just the _init bits without a load/link
of the actual module text?
> J??rn
>
> --
> Joern's library part 13:
> http://www.chip-architect.com/
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-17 19:07 ` Jörn Engel
2008-06-17 19:22 ` Jim Freeman
@ 2008-06-17 19:52 ` Tim Bird
2008-06-17 19:55 ` Tim Bird
2008-06-17 20:19 ` Jörn Engel
1 sibling, 2 replies; 30+ messages in thread
From: Tim Bird @ 2008-06-17 19:52 UTC (permalink / raw)
To: Jörn Engel; +Cc: linux-embedded, linux kernel
Jörn Engel wrote:
> On Tue, 17 June 2008 11:23:18 -0700, Tim Bird wrote:
>> I'm not that happy using an ioctl for this trigger. What is
>> the preferred method of activating a kernel feature like this?
>> I presume something in /proc or /sys, but I'm not sure.
>
> I personally would be unhappy with any kind of interface for this. It
> would be much nicer to make it transparent and still get the benefits.
> One option would be to start a kernel thread for the initialization and
> renice it to 19 or so.
That's an interesting idea. I'm pretty sure the product guys want
an explicit trigger, so they can make sure they've got the main
application well underway before this deferred initialization occurs.
>
> If you want an explicit trigger, you could either hook into init_post()
> or have hooks in the open functions of drivers with deferred
> initialization.
This would presumably require multiple calls (one to the open of
each deferred module). I would still need a trigger for the memory
free operation, unless I hardcode the order of the opening and just
"know" that the last one should free the memory. I'll have to see
if all the modules being loaded like this have open()s.
Thanks for the ideas!
-- Tim
=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-17 19:52 ` Tim Bird
@ 2008-06-17 19:55 ` Tim Bird
2008-06-17 20:23 ` Jörn Engel
2008-06-17 20:19 ` Jörn Engel
1 sibling, 1 reply; 30+ messages in thread
From: Tim Bird @ 2008-06-17 19:55 UTC (permalink / raw)
To: Jörn Engel; +Cc: linux-embedded, linux kernel
Tim Bird wrote:
>> If you want an explicit trigger, you could either hook into init_post()
>> or have hooks in the open functions of drivers with deferred
>> initialization.
>
> This would presumably require multiple calls (one to the open of
> each deferred module). I would still need a trigger for the memory
> free operation, unless I hardcode the order of the opening and just
> "know" that the last one should free the memory. I'll have to see
> if all the modules being loaded like this have open()s.
Sorry - I responded too quickly. I'm not sure I follow the
original suggestion. How would I call the open function of
a module that is not initialized yet?
-- Tim
=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-17 19:55 ` Tim Bird
@ 2008-06-17 20:23 ` Jörn Engel
2008-06-17 20:35 ` Josh Boyer
0 siblings, 1 reply; 30+ messages in thread
From: Jörn Engel @ 2008-06-17 20:23 UTC (permalink / raw)
To: Tim Bird; +Cc: linux-embedded, linux kernel
On Tue, 17 June 2008 12:55:31 -0700, Tim Bird wrote:
>
> Sorry - I responded too quickly. I'm not sure I follow the
> original suggestion. How would I call the open function of
> a module that is not initialized yet?
Hmm, good point. I guess that suggestion has just failed the reality
test.
Jörn
--
You ain't got no problem, Jules. I'm on the motherfucker. Go back in
there, chill them niggers out and wait for the Wolf, who should be
coming directly.
-- Marsellus Wallace
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-17 20:23 ` Jörn Engel
@ 2008-06-17 20:35 ` Josh Boyer
2008-06-17 22:48 ` Stefan Richter
0 siblings, 1 reply; 30+ messages in thread
From: Josh Boyer @ 2008-06-17 20:35 UTC (permalink / raw)
To: Jörn Engel; +Cc: Tim Bird, linux-embedded, linux kernel
On Tue, 17 Jun 2008 22:23:19 +0200
Jörn Engel <joern@logfs.org> wrote:
> On Tue, 17 June 2008 12:55:31 -0700, Tim Bird wrote:
> >
> > Sorry - I responded too quickly. I'm not sure I follow the
> > original suggestion. How would I call the open function of
> > a module that is not initialized yet?
>
> Hmm, good point. I guess that suggestion has just failed the reality
> test.
Have a simple module that calls the initialization functions for
anything with a deferred init. Then you can open that and use an ioctl
to...
I think if we try really really hard, we can make this a Rube-Goldberg
Machine!
josh
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-17 20:35 ` Josh Boyer
@ 2008-06-17 22:48 ` Stefan Richter
2008-06-18 0:03 ` Johannes Stezenbach
0 siblings, 1 reply; 30+ messages in thread
From: Stefan Richter @ 2008-06-17 22:48 UTC (permalink / raw)
To: Tim Bird; +Cc: Josh Boyer, Jörn Engel, linux-embedded, linux kernel
>> On Tue, 17 June 2008 12:55:31 -0700, Tim Bird wrote:
>>> Sorry - I responded too quickly. I'm not sure I follow the
>>> original suggestion. How would I call the open function of
>>> a module that is not initialized yet?
You will be able to open a character device file as soon as cdev_init()
finished... when the Big Kernel Lock is not being taken around
file_operations.open() anymore.
On Tue, 17 Jun 2008 11:28:29 -0700, Tim Bird wrote:
| One technique
| that we are forward-porting from an old kernel (and that I thought I
| might work on mainlining) is to compile modules statically into the
| kernel, but defer their initialization until after boot time.
...
| One of the main sub-systems that we defer initialization of this
| way is USB, and this saves quite a bit of time. (Of course the
| same, or slightly more CPU cycles are eventually used during
| bootup time. But this lets us get to user space quicker so we
| can start user-visible applications faster.)
What if you don't defer module initialization, but merely device probing?
$ ls /sys/bus/*/drivers_autoprobe
/sys/bus/acpi/drivers_autoprobe
/sys/bus/firewire/drivers_autoprobe
/sys/bus/i2c/drivers_autoprobe
/sys/bus/ide/drivers_autoprobe
/sys/bus/pci/drivers_autoprobe
/sys/bus/pci_express/drivers_autoprobe
/sys/bus/platform/drivers_autoprobe
/sys/bus/pnp/drivers_autoprobe
/sys/bus/scsi/drivers_autoprobe
/sys/bus/serio/drivers_autoprobe
/sys/bus/usb/drivers_autoprobe
If you set /sys/bus/foo/drivers_autoprobe to 0 (default is 1), then a
/sys/bus/foo/drivers/bar will not be bound to devices. You can trigger
driver--device binding later per device by writing a device's bus ID
into /sys/bus/foo/drivers/bar/bind, or by writing into
/sys/bus/foo/drivers_probe (I guess; I only used the per-device way so far).
Now, since you want to do this with statically linked drivers, i.e. need
to prevent probing before userspace and sysfs are up and running, you
probably need to modify the bus types or/and the driver core so that the
the less vital buses have drivers_autoprobe off by default.
On the other hand, maybe you want to have probes of some PCI drivers
executed but not the probes of some other PCI drivers; uhci_hcd for
example. I guess you could achieve that by modifying
drivers/pci/pci-driver.c::pci_bus_match(). E.g. add a sysfs attribute
to pci-driver.c which, as long as containing its initial value, lets
bus_match skip certain unwanted drivers (or match only whitelisted
drivers). Later, userspace writes into the extra sysfs attribute and
into the standard driver core sysfs attributes to trigger the deferred
driver probes.
--
Stefan Richter
-=====-==--- -==- =--=-
http://arcgraph.de/sr/
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-17 22:48 ` Stefan Richter
@ 2008-06-18 0:03 ` Johannes Stezenbach
2008-06-18 0:10 ` Stefan Richter
0 siblings, 1 reply; 30+ messages in thread
From: Johannes Stezenbach @ 2008-06-18 0:03 UTC (permalink / raw)
To: Stefan Richter
Cc: Tim Bird, Josh Boyer, Jörn Engel, linux-embedded,
linux kernel
On Wed, Jun 18, 2008 at 12:48:27AM +0200, Stefan Richter wrote:
>>> On Tue, 17 June 2008 12:55:31 -0700, Tim Bird wrote:
> On Tue, 17 Jun 2008 11:28:29 -0700, Tim Bird wrote:
> | One of the main sub-systems that we defer initialization of this
> | way is USB, and this saves quite a bit of time. (Of course the
> | same, or slightly more CPU cycles are eventually used during
> | bootup time. But this lets us get to user space quicker so we
> | can start user-visible applications faster.)
>
> What if you don't defer module initialization, but merely device probing?
...
> If you set /sys/bus/foo/drivers_autoprobe to 0 (default is 1), then a
> /sys/bus/foo/drivers/bar will not be bound to devices. You can trigger
> driver--device binding later per device by writing a device's bus ID
> into /sys/bus/foo/drivers/bar/bind, or by writing into
> /sys/bus/foo/drivers_probe (I guess; I only used the per-device way so
> far).
I think the USB bus enumeration can take significant time:
recognize a device is connected, turn on bus power, try
to read descriptors (bus powered devices might be slow to
respond after power up). And this will happen even with
drivers_autoprobe == 0, right?
OTOH I think just calling the module init function when no
devices are present on the bus doesn't need much time.
If you could delay the enumeration it would not be neccessary
to mess with drivers_autoprobe. However, I don't know enough
about USB so I don't know how to do it...
Johannes
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-18 0:03 ` Johannes Stezenbach
@ 2008-06-18 0:10 ` Stefan Richter
2008-06-18 9:38 ` Johannes Stezenbach
0 siblings, 1 reply; 30+ messages in thread
From: Stefan Richter @ 2008-06-18 0:10 UTC (permalink / raw)
To: Johannes Stezenbach
Cc: Tim Bird, Josh Boyer, Jörn Engel, linux-embedded,
linux kernel
Johannes Stezenbach wrote:
> I think the USB bus enumeration can take significant time:
> recognize a device is connected, turn on bus power, try
> to read descriptors (bus powered devices might be slow to
> respond after power up). And this will happen even with
> drivers_autoprobe == 0, right?
Probably... I don't know which particular steps happen in the USB core
before upper layer drivers are bound. Not binding the [eou]hci-hcd PCI
driver would certainly be more effective.
--
Stefan Richter
-=====-==--- -==- =--=-
http://arcgraph.de/sr/
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-18 0:10 ` Stefan Richter
@ 2008-06-18 9:38 ` Johannes Stezenbach
0 siblings, 0 replies; 30+ messages in thread
From: Johannes Stezenbach @ 2008-06-18 9:38 UTC (permalink / raw)
To: Stefan Richter
Cc: Tim Bird, Josh Boyer, Jörn Engel, linux-embedded,
linux kernel
On Wed, Jun 18, 2008, Stefan Richter wrote:
> Johannes Stezenbach wrote:
>> I think the USB bus enumeration can take significant time:
>> recognize a device is connected, turn on bus power, try
>> to read descriptors (bus powered devices might be slow to
>> respond after power up). And this will happen even with
>> drivers_autoprobe == 0, right?
>
> Probably... I don't know which particular steps happen in the USB core
> before upper layer drivers are bound. Not binding the [eou]hci-hcd PCI
> driver would certainly be more effective.
Well, in embedded systems you often don't have a PCI bus,
but platform devices. Maybe it's as simple as delaying
the USB platform_device_register() call, I don't know.
Johannes
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-17 19:52 ` Tim Bird
2008-06-17 19:55 ` Tim Bird
@ 2008-06-17 20:19 ` Jörn Engel
1 sibling, 0 replies; 30+ messages in thread
From: Jörn Engel @ 2008-06-17 20:19 UTC (permalink / raw)
To: Tim Bird; +Cc: linux-embedded, linux kernel
On Tue, 17 June 2008 12:52:22 -0700, Tim Bird wrote:
> Jörn Engel wrote:
> > On Tue, 17 June 2008 11:23:18 -0700, Tim Bird wrote:
> >> I'm not that happy using an ioctl for this trigger. What is
> >> the preferred method of activating a kernel feature like this?
> >> I presume something in /proc or /sys, but I'm not sure.
> >
> > I personally would be unhappy with any kind of interface for this. It
> > would be much nicer to make it transparent and still get the benefits.
> > One option would be to start a kernel thread for the initialization and
> > renice it to 19 or so.
>
> That's an interesting idea. I'm pretty sure the product guys want
> an explicit trigger, so they can make sure they've got the main
> application well underway before this deferred initialization occurs.
Well, there should be a way to ensure this doesn't hog the cpu at all -
unless it is idle or someone is actually waiting for the initialization
to finish. Not sure if nice 19 is good enough for that.
> > If you want an explicit trigger, you could either hook into init_post()
> > or have hooks in the open functions of drivers with deferred
> > initialization.
>
> This would presumably require multiple calls (one to the open of
> each deferred module). I would still need a trigger for the memory
> free operation, unless I hardcode the order of the opening and just
> "know" that the last one should free the memory. I'll have to see
> if all the modules being loaded like this have open()s.
If you want to keep things simple - and I believe initially you should -
you can simply do all initializations in one go. Something like this:
int foo_open(...)
{
wait_for_deferred_init();
...
}
static DECLARE_COMPLETION(init_complete);
void wait_for_deferred_init(void)
{
static atomic_t in_progress = ATOMIC_INIT(-1);
if (!atomic_inc_not_zero(in_progress) {
wait_for_completion(init_complete);
return;
}
for (all deferred initcalls)
foo_init();
complete(init_complete);
free_memory();
}
Jörn
--
Anything that can go wrong, will.
-- Finagle's Law
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Recommendation for activating a deferred module init in the kernel
2008-06-17 18:23 Tim Bird
2008-06-17 18:51 ` David VomLehn
2008-06-17 19:07 ` Jörn Engel
@ 2008-06-18 12:38 ` Amol Lad
[not found] ` <4858A659.8030502@codefidence.com>
3 siblings, 0 replies; 30+ messages in thread
From: Amol Lad @ 2008-06-18 12:38 UTC (permalink / raw)
To: Tim Bird; +Cc: linux-embedded
>
> I am working with a product team on bootup time issues. One technique
> that we are forward-porting from an old kernel (and that I thought I
> might work on mainlining) is to compile modules statically into the kernel,
> but defer their initialization until after boot time.
I landed in same problem sometime back with USB and tried two approaches
1. Dirty approach of deferring loading of all usb modules till you see
application startup "from user point of view" is done. I then just
call into a script which loads all the usb modules "in parallel" with
rest of app initialization
2. The usb modules that I load are usbcore, host controller driver,
scsi_mod, sd_mod and usb_storage. I noted that it's actually scsi
enumeration that takes a long time; usb enumeration was much faster. I
compiled usbcore and host controller driver statically in the kernel,
enabled CONFIG_HOTPLUG and did rest of the module loading in a script
invoked from /sbin/hotplug.
Amol
^ permalink raw reply [flat|nested] 30+ messages in thread
[parent not found: <4858A659.8030502@codefidence.com>]
* Re: Recommendation for activating a deferred module init in the kernel
[not found] ` <4858A659.8030502@codefidence.com>
@ 2008-06-18 16:08 ` Tim Bird
[not found] ` <4859ECF3.3000500@codefidence.com>
0 siblings, 1 reply; 30+ messages in thread
From: Tim Bird @ 2008-06-18 16:08 UTC (permalink / raw)
To: Gilad Ben-Yossef; +Cc: linux-embedded
Gilad Ben-Yossef wrote:
> This may sound like a stupid question, but why are you compiling the
> modules statically?
>
> I mean, it sounds to me like the perfect way to do what you want is to
> compile the modules dynamically (you can store them in a an in kernel
> initramfs if you want to keep them attached to the kernel binary for
> ease of maintenance) and simply call a script that calls modprobe when
> it's OK to load them?
I'm not positive, but I think we link them statically for size and
time reasons. Statically linking the modules means we can eliminate
the module load code from the kernel, and also save ourselves the ELF
sections (in each module) which hold relocation information, etc.
Also, insmod-ing (or modprobe-ing) the modules takes extra time
overhead for the symbol relocation step. Since this would be
deferred in our case, this might not be a big deal, but it does
add to the total length of time required to boot.
> Sounds a hell of lot simpler to me...
Our patch isn't that big or complicated now. I just didn't like
the ioctl(). Replacing the ioctl with some other lightweight
mechanism shouldn't complicate the code too much.
I'm not sure requiring a shell interpreter (to run the script)
a script, a program (modprobe) and a whole new set of memory
operations (to handle the initramfs), is simpler than a single
ioctl. (It might be, in the non-embedded case, where the
presence of these things is taken for granted.)
-- Tim
=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2008-07-01 14:20 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-18 6:47 Recommendation for activating a deferred module init in the kernel Gilad Ben-Yossef
2008-06-18 8:20 ` David Woodhouse
2008-06-18 8:32 ` David Woodhouse
2008-06-18 8:52 ` Adrian Bunk
2008-06-18 8:57 ` Geert Uytterhoeven
2008-06-18 9:59 ` David Woodhouse
2008-06-18 10:33 ` Adrian Bunk
2008-06-18 10:41 ` David Woodhouse
2008-06-18 11:37 ` Geert Uytterhoeven
2008-06-18 14:56 ` Nicolas Pitre
-- strict thread matches above, loose matches on Subject: below --
2008-06-17 18:23 Tim Bird
2008-06-17 18:51 ` David VomLehn
2008-06-17 19:07 ` Jörn Engel
2008-06-17 19:22 ` Jim Freeman
2008-06-17 20:06 ` Tim Bird
2008-06-17 19:52 ` Tim Bird
2008-06-17 19:55 ` Tim Bird
2008-06-17 20:23 ` Jörn Engel
2008-06-17 20:35 ` Josh Boyer
2008-06-17 22:48 ` Stefan Richter
2008-06-18 0:03 ` Johannes Stezenbach
2008-06-18 0:10 ` Stefan Richter
2008-06-18 9:38 ` Johannes Stezenbach
2008-06-17 20:19 ` Jörn Engel
2008-06-18 12:38 ` Amol Lad
[not found] ` <4858A659.8030502@codefidence.com>
2008-06-18 16:08 ` Tim Bird
[not found] ` <4859ECF3.3000500@codefidence.com>
2008-06-19 17:58 ` Tim Bird
2008-06-22 7:08 ` Gilad Ben-Yossef
2008-06-23 17:40 ` Tim Bird
2008-07-01 14:20 ` Gilad Ben-Yossef
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).