Changeset 232972 in webkit
- Timestamp:
- Jun 19, 2018 11:59:51 AM (6 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r232968 r232972 1 2018-06-19 Leo Balter <leonardo.balter@gmail.com> 2 3 Test262-Runner: Improve files queue to optimize CPU usage/balancing 4 https://bugs.webkit.org/show_bug.cgi?id=186443 5 6 Reviewed by Michael Saboff. 7 8 This patch creates a queue manager for to keep the child process open while the parent process feed each child with test files to run. 9 * Scripts/test262/Runner.pm: 10 (processCLI): 11 (main): 12 1 13 2018-06-19 Wenson Hsieh <wenson_hsieh@apple.com> 2 14 -
trunk/Tools/Scripts/test262/Runner.pm
r232906 r232972 43 43 use Config; 44 44 use Time::HiRes qw(time); 45 use IO::Handle; 46 use IO::Select; 45 47 46 48 my $Bin; … … 75 77 76 78 # Commandline settings 77 my $max _process;79 my $maxProcesses; 78 80 my @cliTestDirs; 79 81 my $verbose; … … 127 129 't|t262=s' => \$test262Dir, 128 130 'o|test-only=s@' => \@cliTestDirs, 129 'p|child-processes=i' => \$max _process,131 'p|child-processes=i' => \$maxProcesses, 130 132 'h|help' => \$help, 131 133 'release' => \$release, … … 256 258 } 257 259 258 $max _process ||= getProcesses();260 $maxProcesses ||= getProcesses(); 259 261 260 262 print "\nSettings:\n" 261 263 . "Test262 Dir: " . abs2rel($test262Dir) . "\n" 262 264 . "JSC: " . abs2rel($JSC) . "\n" 263 . "Child Processes: $max _process\n";265 . "Child Processes: $maxProcesses\n"; 264 266 265 267 print "Test timeout: $timeout\n" if $timeout; … … 278 280 print "---\n\n"; 279 281 } 280 281 282 282 283 sub main { … … 314 315 } 315 316 316 # If we are processing many files, fork process 317 if (scalar @files > $max_process * 5) { 317 my $pm = Parallel::ForkManager->new($maxProcesses); 318 my $select = IO::Select->new(); 319 320 my @children; 321 my @parents; 322 my $activeChildren = 0; 323 324 my @resultsfhs; 325 326 # Open each process 327 PROCESSES: 328 foreach (0..$maxProcesses-1) { 329 my $i = $_; 318 330 319 331 # Make temporary files to record results 320 my @resultsfhs; 321 for (my $i = 0; $i <= $max_process-1; $i++) { 322 my ($fh, $filename) = getTempFile(); 323 $resultsfhs[$i] = $fh; 324 } 325 326 my $pm = Parallel::ForkManager->new($max_process); 327 my $filesperprocess = int(scalar @files / $max_process); 328 329 FILES: 330 for (my $i = 0; $i <= $max_process-1; $i++) { 331 $pm->start and next FILES; # do the fork 332 srand(time ^ $$); # Creates a new seed for each fork 333 334 my $first = $filesperprocess * $i; 335 my $last = $i == $max_process-1 ? scalar @files : $filesperprocess * ($i+1); 336 337 for (my $j = $first; $j < $last; $j++) { 338 processFile($files[$j], $resultsfhs[$i]); 339 }; 340 341 $pm->finish; # do the exit in the child process 342 }; 343 344 $pm->wait_all_children; 345 346 # Read results from file into @results and close 347 for (my $i = 0; $i <= $max_process-1; $i++) { 348 seek($resultsfhs[$i], 0, 0); 349 push @results, LoadFile($resultsfhs[$i]); 350 close $resultsfhs[$i]; 351 } 352 } 353 # Otherwising, running sequentially is fine 354 else { 355 my ($resfh, $resfilename) = getTempFile(); 356 foreach my $file (@files) { 357 processFile($file, $resfh); 358 }; 359 seek($resfh, 0, 0); 360 @results = LoadFile($resfh); 361 close $resfh; 332 my ($fh, $filename) = getTempFile(); 333 $resultsfhs[$i] = $fh; 334 335 socketpair($children[$i], $parents[$i], 1, 1, 0); 336 my $child = $children[$i]; 337 my $parent = $parents[$i]; 338 $child->autoflush(1); 339 $parent->autoflush(1); 340 341 # seeds each child with a file; 342 343 my $pid = $pm->start; 344 if ($pid) { # parent 345 $select->add($child); 346 # each child starts with a file; 347 my $file = shift @files; 348 chomp $file; 349 if ($file) { 350 print $child "$file\n"; 351 $activeChildren++; 352 } 353 354 next PROCESSES; 355 } 356 357 # children will start here 358 srand(time ^ $$); # Creates a new seed for each fork 359 CHILD: 360 while (<$parent>) { 361 my $file = $_; 362 chomp $file; 363 if ($file eq 'END') { 364 last; 365 } 366 367 processFile($file, $resultsfhs[$i]); 368 print $parent "signal\n"; 369 } 370 371 $child->close(); 372 $pm->finish; 373 } 374 375 my @ready; 376 FILES: 377 while ($activeChildren and @ready = $select->can_read($timeout)) { 378 foreach (@ready) { 379 my $readyChild = $_; 380 my $childMsg = <$readyChild>; 381 chomp $childMsg; 382 $activeChildren--; 383 my $file = shift @files; 384 if ($file) { 385 chomp $file; 386 print $readyChild "$file\n"; 387 $activeChildren++; 388 } elsif (!$activeChildren) { 389 last FILES; 390 } 391 } 392 } 393 394 foreach (@children) { 395 print $_ "END\n"; 396 } 397 398 foreach (@parents) { 399 $_->close(); 400 } 401 402 my $count = 0; 403 for my $parent (@parents) { 404 my $child = $children[$count]; 405 print $child "END\n"; 406 $parent->close(); 407 $count++; 408 } 409 410 $pm->wait_all_children; 411 412 # Read results from file into @results and close 413 foreach (0..$maxProcesses-1) { 414 my $i = $_; 415 seek($resultsfhs[$i], 0, 0); 416 push @results, LoadFile($resultsfhs[$i]); 417 close $resultsfhs[$i]; 362 418 } 363 419 … … 1036 1092 =item B<--child-processes, -p> 1037 1093 1038 Specify number of child processes.1094 Specify the number of child processes. 1039 1095 1040 1096 =item B<--t262, -t>
Note: See TracChangeset
for help on using the changeset viewer.