New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to change the method for determining the number of CPUs on Linux #28388
Need to change the method for determining the number of CPUs on Linux #28388
Conversation
https://bugs.webkit.org/show_bug.cgi?id=273675 Reviewed by NOBODY (OOPS!). nproc is unreliable, so remove it and rely on the fallback that greps /proc/cpuinfo instead. This looks a little bit fragile (e.g. it would fail if my AMD Ryzen "Processor" were instead an AMD Ryzen "processor") but surely an improvement. * Tools/Scripts/webkitdirs.pm: (determineNumberOfCPUs):
EWS run on current version of this PR (hash 48c72c6) |
How is lscpu -b --parse=cpu | awk '/^[^#]/{ ncpus += 1 } END { print ncpus } Surely counting lines that do not start with a |
Guess: it's counting deactivated core complexes? I don't know, but I don't see any reason to second guess the bug reporter.
We could do this, but it's nice to depend on as few external programs as possible, and this is already running in a really niche case: it's only used if you don't have ninja installed. |
# Don't use nproc because it returns unreliable results, https://webkit.org/b/273675 | ||
$numberOfCPUs = (grep /processor/, `cat /proc/cpuinfo`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't like this. And it is not really needed to shell out to nproc
, or even to grep
... remember that Perl is supposed to be a glorified grep
. So I would instead suggest:
# Don't use nproc because it returns unreliable results, https://webkit.org/b/273675 | |
$numberOfCPUs = (grep /processor/, `cat /proc/cpuinfo`); | |
use POSIX; | |
$numberOfCPUs = POSIX::sysconf(83); # _SC_NPROCESSORS_ONLN = 83 | |
if ($numberOfCPUs == "") { | |
open CPUINFO, "/proc/cpuinfo"; | |
$numberOfCPUs = 0; | |
while (<CPUINFO>) { | |
if (/^[Pp]rocessor\s/) { $numberOfCPUs++; } | |
} | |
close CPUINFO; | |
} |
(Yes, I tested both the sysconf
code path and the fallback to parsing /proc/cpuinfo
here.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but now you've written 100% of the code in this pull request, so we might as well close this one and let you open a new one for me to review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: #28645
Closing in favor of #28645 |
48c72c6
48c72c6