forked from OSchip/llvm-project
Reland "[lit] Use os.cpu_count() to cleanup TODO"
The initial problem with the remaining bot config was resolved. We can now use Python3. Let's use `os.cpu_count()` to cleanup this helper. Differential Revision: https://reviews.llvm.org/D94734
This commit is contained in:
parent
48e09faa94
commit
302432f75d
|
@ -23,7 +23,7 @@ def parse_args():
|
||||||
metavar="N",
|
metavar="N",
|
||||||
help="Number of workers used for testing",
|
help="Number of workers used for testing",
|
||||||
type=_positive_int,
|
type=_positive_int,
|
||||||
default=lit.util.detectCPUs())
|
default=lit.util.usable_core_count())
|
||||||
parser.add_argument("--config-prefix",
|
parser.add_argument("--config-prefix",
|
||||||
dest="configPrefix",
|
dest="configPrefix",
|
||||||
metavar="NAME",
|
metavar="NAME",
|
||||||
|
|
|
@ -110,7 +110,7 @@ class Run(object):
|
||||||
# threads counts toward the current process limit. Try to raise the (soft)
|
# threads counts toward the current process limit. Try to raise the (soft)
|
||||||
# process limit so that tests don't fail due to resource exhaustion.
|
# process limit so that tests don't fail due to resource exhaustion.
|
||||||
def _increase_process_limit(self):
|
def _increase_process_limit(self):
|
||||||
ncpus = lit.util.detectCPUs()
|
ncpus = lit.util.usable_core_count()
|
||||||
desired_limit = self.workers * ncpus * 2 # the 2 is a safety factor
|
desired_limit = self.workers * ncpus * 2 # the 2 is a safety factor
|
||||||
|
|
||||||
# Importing the resource module will likely fail on Windows.
|
# Importing the resource module will likely fail on Windows.
|
||||||
|
|
|
@ -109,32 +109,23 @@ def to_unicode(s):
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
# TODO(yln): multiprocessing.cpu_count()
|
def usable_core_count():
|
||||||
# TODO(python3): len(os.sched_getaffinity(0)) and os.cpu_count()
|
"""Return the number of cores the current process can use, if supported.
|
||||||
def detectCPUs():
|
Otherwise, return the total number of cores (like `os.cpu_count()`).
|
||||||
"""Detects the number of CPUs on a system.
|
Default to 1 if undetermined.
|
||||||
|
|
||||||
Cribbed from pp.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Linux, Unix and MacOS:
|
try:
|
||||||
if hasattr(os, 'sysconf'):
|
n = len(os.sched_getaffinity(0))
|
||||||
if 'SC_NPROCESSORS_ONLN' in os.sysconf_names:
|
except AttributeError:
|
||||||
# Linux & Unix:
|
n = os.cpu_count() or 1
|
||||||
ncpus = os.sysconf('SC_NPROCESSORS_ONLN')
|
|
||||||
if isinstance(ncpus, int) and ncpus > 0:
|
# On Windows, with more than 32 processes, process creation often fails with
|
||||||
return ncpus
|
|
||||||
else: # OSX:
|
|
||||||
return int(subprocess.check_output(['sysctl', '-n', 'hw.ncpu'],
|
|
||||||
stderr=subprocess.STDOUT))
|
|
||||||
# Windows:
|
|
||||||
if 'NUMBER_OF_PROCESSORS' in os.environ:
|
|
||||||
ncpus = int(os.environ['NUMBER_OF_PROCESSORS'])
|
|
||||||
if ncpus > 0:
|
|
||||||
# With more than 32 processes, process creation often fails with
|
|
||||||
# "Too many open files". FIXME: Check if there's a better fix.
|
# "Too many open files". FIXME: Check if there's a better fix.
|
||||||
return min(ncpus, 32)
|
if platform.system() == 'Windows':
|
||||||
return 1 # Default
|
return min(n, 32)
|
||||||
|
|
||||||
|
return n
|
||||||
|
|
||||||
|
|
||||||
def mkdir(path):
|
def mkdir(path):
|
||||||
|
|
Loading…
Reference in New Issue