From ef1b64136eb11e65f9eb27b6083536fe1b69c707 Mon Sep 17 00:00:00 2001 From: Dominik Hassler Date: Tue, 20 Oct 2020 18:30:37 +0000 Subject: 13248 parallelise the quest for elves Reviewed by: Andy Fiddaman Reviewed by: Hans Rosenfeld Reviewed by: Toomas Soome Approved by: Dan McDonald --- usr/src/tools/scripts/find_elf.pl | 53 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/usr/src/tools/scripts/find_elf.pl b/usr/src/tools/scripts/find_elf.pl index 51fa5e15f1..58fc5f7059 100644 --- a/usr/src/tools/scripts/find_elf.pl +++ b/usr/src/tools/scripts/find_elf.pl @@ -22,6 +22,7 @@ # # Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. # # @@ -57,7 +58,28 @@ use POSIX qw(getenv); use Getopt::Std; use File::Basename; use IO::Dir; +use Config; + +BEGIN { + if ($Config{useithreads}) { + require threads; + require threads::shared; + threads::shared->import(qw(share)); + require Thread::Queue; + } +} + +chomp (my $NPROCESSORS_ONLN = `getconf NPROCESSORS_ONLN 2>/dev/null` || 1); +my $max_threads = $ENV{DMAKE_MAX_JOBS} || $NPROCESSORS_ONLN; +my $tq; +if ($Config{useithreads}) { + share(%Output); + share(%id_hash); + share(%alias_hash); + + $tq = Thread::Queue->new; +} ## GetObjectInfo(path) # @@ -229,6 +251,23 @@ sub ProcFile { # or generating nonsensical paths (i.e., 32/amd64/...). # sub ProcDir { + if ($Config{useithreads}) { + threads->create(sub { + while (my $q = $tq->dequeue) { + ProcFile(@$q) + } + }) for (1 .. $max_threads); + } + + _ProcDir(@_); + + if ($Config{useithreads}) { + $tq->end; + $_->join for threads->list; + } +} + +sub _ProcDir { my($FullDir, $RelDir, $AliasedPath, $SelfSymlink) = @_; my($NewFull, $NewRel, $Entry); @@ -279,7 +318,7 @@ sub ProcDir { # via that link. next if $SelfSymlink; - ProcDir($NewFull, $NewRel, $RecurseAliasedPath, + _ProcDir($NewFull, $NewRel, $RecurseAliasedPath, $RecurseSelfSymlink); next; } @@ -296,8 +335,16 @@ sub ProcDir { # Process any standard files. if (-f _) { my ($dev, $ino) = stat(_); - ProcFile($NewFull, $NewRel, $AliasedPath, - $IsSymLink, $dev, $ino); + if ($Config{useithreads}) { + $tq->enqueue([ $NewFull, $NewRel, + $AliasedPath, $IsSymLink, $dev, + $ino ]); + } + else { + ProcFile($NewFull, $NewRel, + $AliasedPath, $IsSymLink, $dev, + $ino); + } next; } -- cgit v1.2.3