Dependency generation now uses all cores on multi-core machines.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22021 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
eb0061411d
commit
4fc00222cb
2 changed files with 73 additions and 1 deletions
|
@ -33,7 +33,7 @@ c2obj = $(addsuffix .o,$(basename $(subst $(ROOTDIR),$(BUILDDIR),$(1))))
|
||||||
# calculate dependencies for a list of source files $(2) and output them
|
# calculate dependencies for a list of source files $(2) and output them
|
||||||
# to a file $(1)_, to be later renamed to $(1).
|
# to a file $(1)_, to be later renamed to $(1).
|
||||||
mkdepfile = $(shell \
|
mkdepfile = $(shell \
|
||||||
$(CC) $(PPCFLAGS) $(OTHER_INC) -MG -MM -include config.h $(2) | \
|
perl $(TOOLSDIR)/multigcc.pl $(CC) $(PPCFLAGS) $(OTHER_INC) -MG -MM -include config.h -- $(2) | \
|
||||||
sed -e "s: lang.h: lang/lang_core.o:" \
|
sed -e "s: lang.h: lang/lang_core.o:" \
|
||||||
-e 's:_asmdefs.o:_asmdefs.h:' \
|
-e 's:_asmdefs.o:_asmdefs.h:' \
|
||||||
-e "s: max_language_size.h: lang/max_language_size.h:" | \
|
-e "s: max_language_size.h: lang/max_language_size.h:" | \
|
||||||
|
|
72
tools/multigcc.pl
Executable file
72
tools/multigcc.pl
Executable file
|
@ -0,0 +1,72 @@
|
||||||
|
#!/usr/bin/perl
|
||||||
|
use List::Util 'shuffle'; # standard from Perl 5.8 and later
|
||||||
|
|
||||||
|
my $tempfile = "multigcc.out";
|
||||||
|
my @params;
|
||||||
|
my @files;
|
||||||
|
my $list = \@params;
|
||||||
|
|
||||||
|
# parse command line arguments
|
||||||
|
for my $a (@ARGV) {
|
||||||
|
if ($a eq "--") {
|
||||||
|
$list = \@files;
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
push @{$list}, $a;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $command = join " ", @params;
|
||||||
|
|
||||||
|
# shuffle the file list to spread the load as evenly as we can
|
||||||
|
@files = shuffle(@files);
|
||||||
|
|
||||||
|
# count number of cores
|
||||||
|
my $cores = 1;
|
||||||
|
if (open CPUINFO, "</proc/cpuinfo") {
|
||||||
|
$cores = scalar grep /^processor/i, <CPUINFO>;
|
||||||
|
close CPUINFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
# don't run empty children
|
||||||
|
if (scalar @files < $cores)
|
||||||
|
{
|
||||||
|
$cores = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# fork children
|
||||||
|
my @pids;
|
||||||
|
my $slice = int((scalar @files / $cores) + 0.5);
|
||||||
|
for my $i (0 .. $cores-1)
|
||||||
|
{
|
||||||
|
my $pid = fork;
|
||||||
|
if ($pid)
|
||||||
|
{
|
||||||
|
# mother
|
||||||
|
$pids[$i] = $pid;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
# get my slice of the files
|
||||||
|
my @list = @files[$i * $slice .. $i * $slice + $slice - 1];
|
||||||
|
|
||||||
|
# run command
|
||||||
|
system("$command @list > $tempfile.$$");
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for my $i (0 .. $cores - 1)
|
||||||
|
{
|
||||||
|
# wait for child to complete
|
||||||
|
waitpid $pids[$i], 0;
|
||||||
|
|
||||||
|
# read & print result
|
||||||
|
if (open F, "<$tempfile.$pids[$i]")
|
||||||
|
{
|
||||||
|
print <F>;
|
||||||
|
close F;
|
||||||
|
unlink "$tempfile.$pids[$i]";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue