Skip to content

Commit

Permalink
Cherry-pick 278879@main (9bf347a). https://bugs.webkit.org/show_bug.c…
Browse files Browse the repository at this point in the history
…gi?id=273675

    Need to change the method for determining the number of CPUs on Linux
    https://bugs.webkit.org/show_bug.cgi?id=273675

    Reviewed by Carlos Garcia Campos.

    Try to use sysconf(_SC_NPROCESSORS_ONLN) on Linux to determine the
    amount of usable CPU cores. While Perl provides access to the function
    in its POSIX module, the _SC_NPROCESSORS_ONLN constant is not defined
    and the value of the constant is used instead. Using the value is fine
    as it is part of the user space API and not expected to ever change.
    As a fallback, make Perl parse /proc/cpuinfo directly instead of
    shelling out to a cat|grep pipeline: Perl knows how to regex and how
    to count just fine.

    * Tools/Scripts/webkitdirs.pm:
    (determineNumberOfCPUs): Replace usage of nproc command with sysconf,
    update /proc/cpuinfo parsing fallback.

    Canonical link: https://commits.webkit.org/278879@main

Canonical link: https://commits.webkit.org/274313.258@webkitglib/2.44
  • Loading branch information
aperezdc committed May 20, 2024
1 parent c6f625d commit 7307a61
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Tools/Scripts/webkitdirs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,18 @@ sub determineNumberOfCPUs
if (defined($ENV{NUMBER_OF_PROCESSORS})) {
$numberOfCPUs = $ENV{NUMBER_OF_PROCESSORS};
} elsif (isLinux()) {
# First try the nproc utility, if it exists. If we get no
# results fall back to just interpretting /proc directly.
chomp($numberOfCPUs = `nproc --all 2> /dev/null`);
use POSIX;
$numberOfCPUs = POSIX::sysconf(83); # _SC_NPROCESSORS_ONLN = 83
if ($numberOfCPUs eq "") {
$numberOfCPUs = (grep /processor/, `cat /proc/cpuinfo`);
$numberOfCPUs = 0;
open CPUINFO, "/proc/cpuinfo";
while (<CPUINFO>) {
if (/[Pp]rocessor\s/) { $numberOfCPUs++; }
}
close CPUINFO;
}
if ($numberOfCPUs == 0) {
$numberOfCPUs = 1;
}
} elsif (isAnyWindows()) {
# Assumes cygwin
Expand Down

0 comments on commit 7307a61

Please sign in to comment.