[PATCH 2/2] first stab at NOFORK applet support

Bernhard Fischer rep.nop at aon.at
Tue May 9 20:27:53 UTC 2006


On Tue, May 09, 2006 at 12:20:14AM -0400, Rob Landley wrote:
>On Saturday 06 May 2006 1:29 am, Denis Vlasenko wrote:
>> Consolidating globals consists of consolidating bss and consolidating data.
>> Data consolidation is done exactly like bss (that is, all data variables
>> are to be put into a structure) with the addition of one
>> memcpy(data_buffer, data_template, sizeof(struct DATA))
>
>I just did a cleanup on sed.c, moving all its globals and statics into a 
>single global structure called "bbg" (busybox globals).  (I left out the 
>"static const" strings, since they're read-only data which doesn't count for 
>this purpose.  They might as well be #defines...)
>
>On the whole, the optimizer treated the structure members about the same way 
>it treated the statics.  I ran bloatcheck between each variable I moved into 
>the structure, and 90% of the time it made no difference.  There were a few 
>points where it added a couple extra instructions, but also a few cases where 
>it shrank when I converted.
>
>On the whole sed wound up a total of 17 bytes bigger after I'd moved 
>everything into the structure, and 10 bytes of that was me having to manually 
>initialize a value since everything in the structure starts at 0 now.  Which 
>was annoying but within the noise, and I suspect the initalization just moved 
>from a bit where bloatcheck can't see it to where it can, since I shrank a 
>couple strings and that didn't affect bloatcheck's results, which means nm 
>isn't outputting preinitialized data...

Just a quick sidenote..
Perhaps it'd be better to use bitfield for the pure true/false values like
be_quiet, in_place:
struct sed_globals
	/* options */
	__extension__ unsigned be_quiet:1;
	__extension__ unsigned in_place:3;/*or how many you need*/
...
}
Even with the implied padding you'd call for by only using 1+3, you'd
save a little bit there, eventually.

cheers,
>
>I did a couple other small cleanups anyway to bring the size down about 30 
>bytes, just to feel better about it.  And I played with the assembly dumps a 
>bit to see what it was doing, and the changes were all places where the 
>optimizer had put the code through a blender.
>
>Anyway: Dennis.  There's an example of an app with its globals in a structure, 
>and although the gcc 4.0 optimizer isn't perfect it at least isn't doing 
>anything actively stupid.  (Considering how much work they put into 
>optimizing c++, I suspected that would be the case.)
>
>If we want sed to be reentrant, we can memset the structure and live should be 
>good modulo resource leaks (memory, open files, etc) which I think 
>FEATURE_CLEAN_UP is properly handling right now but it may need a tweak.
>
>What do you think?
>
>Rob
>-- 
>Never bet against the cheap plastic solution.
>_______________________________________________
>busybox mailing list
>busybox at busybox.net
>http://busybox.net/cgi-bin/mailman/listinfo/busybox
>



More information about the busybox mailing list