diff options
author | Björn Stenberg <bjorn@haxx.se> | 2009-07-24 21:53:32 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2009-07-24 21:53:32 +0000 |
commit | 4fc00222cb5851e28e83d367f173038c7d026b03 (patch) | |
tree | 01dc3cc97e5c09b405249686be586f5c3e1776b9 | |
parent | eb0061411d6fa08ab540107cdbd2906e18e516d7 (diff) | |
download | rockbox-4fc00222cb5851e28e83d367f173038c7d026b03.tar.gz rockbox-4fc00222cb5851e28e83d367f173038c7d026b03.zip |
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
-rw-r--r-- | tools/functions.make | 2 | ||||
-rwxr-xr-x | tools/multigcc.pl | 72 |
2 files changed, 73 insertions, 1 deletions
diff --git a/tools/functions.make b/tools/functions.make index d08742a133..045354da66 100644 --- a/tools/functions.make +++ b/tools/functions.make | |||
@@ -33,7 +33,7 @@ c2obj = $(addsuffix .o,$(basename $(subst $(ROOTDIR),$(BUILDDIR),$(1)))) | |||
33 | # calculate dependencies for a list of source files $(2) and output them | 33 | # calculate dependencies for a list of source files $(2) and output them |
34 | # to a file $(1)_, to be later renamed to $(1). | 34 | # to a file $(1)_, to be later renamed to $(1). |
35 | mkdepfile = $(shell \ | 35 | mkdepfile = $(shell \ |
36 | $(CC) $(PPCFLAGS) $(OTHER_INC) -MG -MM -include config.h $(2) | \ | 36 | perl $(TOOLSDIR)/multigcc.pl $(CC) $(PPCFLAGS) $(OTHER_INC) -MG -MM -include config.h -- $(2) | \ |
37 | sed -e "s: lang.h: lang/lang_core.o:" \ | 37 | sed -e "s: lang.h: lang/lang_core.o:" \ |
38 | -e 's:_asmdefs.o:_asmdefs.h:' \ | 38 | -e 's:_asmdefs.o:_asmdefs.h:' \ |
39 | -e "s: max_language_size.h: lang/max_language_size.h:" | \ | 39 | -e "s: max_language_size.h: lang/max_language_size.h:" | \ |
diff --git a/tools/multigcc.pl b/tools/multigcc.pl new file mode 100755 index 0000000000..db544355ca --- /dev/null +++ b/tools/multigcc.pl | |||
@@ -0,0 +1,72 @@ | |||
1 | #!/usr/bin/perl | ||
2 | use List::Util 'shuffle'; # standard from Perl 5.8 and later | ||
3 | |||
4 | my $tempfile = "multigcc.out"; | ||
5 | my @params; | ||
6 | my @files; | ||
7 | my $list = \@params; | ||
8 | |||
9 | # parse command line arguments | ||
10 | for my $a (@ARGV) { | ||
11 | if ($a eq "--") { | ||
12 | $list = \@files; | ||
13 | next; | ||
14 | } | ||
15 | |||
16 | push @{$list}, $a; | ||
17 | } | ||
18 | |||
19 | my $command = join " ", @params; | ||
20 | |||
21 | # shuffle the file list to spread the load as evenly as we can | ||
22 | @files = shuffle(@files); | ||
23 | |||
24 | # count number of cores | ||
25 | my $cores = 1; | ||
26 | if (open CPUINFO, "</proc/cpuinfo") { | ||
27 | $cores = scalar grep /^processor/i, <CPUINFO>; | ||
28 | close CPUINFO; | ||
29 | } | ||
30 | |||
31 | # don't run empty children | ||
32 | if (scalar @files < $cores) | ||
33 | { | ||
34 | $cores = 1; | ||
35 | } | ||
36 | |||
37 | # fork children | ||
38 | my @pids; | ||
39 | my $slice = int((scalar @files / $cores) + 0.5); | ||
40 | for my $i (0 .. $cores-1) | ||
41 | { | ||
42 | my $pid = fork; | ||
43 | if ($pid) | ||
44 | { | ||
45 | # mother | ||
46 | $pids[$i] = $pid; | ||
47 | } | ||
48 | else | ||
49 | { | ||
50 | # get my slice of the files | ||
51 | my @list = @files[$i * $slice .. $i * $slice + $slice - 1]; | ||
52 | |||
53 | # run command | ||
54 | system("$command @list > $tempfile.$$"); | ||
55 | |||
56 | exit; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | for my $i (0 .. $cores - 1) | ||
61 | { | ||
62 | # wait for child to complete | ||
63 | waitpid $pids[$i], 0; | ||
64 | |||
65 | # read & print result | ||
66 | if (open F, "<$tempfile.$pids[$i]") | ||
67 | { | ||
68 | print <F>; | ||
69 | close F; | ||
70 | unlink "$tempfile.$pids[$i]"; | ||
71 | } | ||
72 | } | ||