Internals: Move max_procs to VtOs package. No test change intended.
This commit is contained in:
parent
00ac706f67
commit
76ec35a8f6
|
|
@ -91,6 +91,19 @@ class VtOs:
|
|||
return os.environ[var]
|
||||
return default
|
||||
|
||||
@staticproperty
|
||||
@lru_cache(maxsize=1)
|
||||
def max_procs() -> int: # pylint: disable=no-method-argument
|
||||
"""Return maximum processor count can use (system CPUs or numactl setting)"""
|
||||
try:
|
||||
procs = len(os.sched_getaffinity(0))
|
||||
except AttributeError:
|
||||
procs = multiprocessing.cpu_count()
|
||||
if procs < 2:
|
||||
print("driver.py: Python didn't find at least two CPUs")
|
||||
procs = 2
|
||||
return procs
|
||||
|
||||
@staticmethod
|
||||
def mkdir_ok(path: str) -> None:
|
||||
"""Make directory, no error if exists"""
|
||||
|
|
@ -1699,6 +1712,11 @@ class VlTest:
|
|||
"""Return environment variable, returning default if does not exist"""
|
||||
return VtOs.getenv_def(var, default)
|
||||
|
||||
@staticproperty
|
||||
def max_procs() -> int: # pylint: disable=no-method-argument
|
||||
"""Return maximum processor count can use (system CPUs or numactl setting)"""
|
||||
return VtOs.max_procs
|
||||
|
||||
def mkdir_ok(self, filename) -> None:
|
||||
"""Make directory, no error if exists"""
|
||||
if test.verbose:
|
||||
|
|
@ -2734,13 +2752,13 @@ class VlTest:
|
|||
|
||||
|
||||
def calc_jobs() -> int:
|
||||
ok_threads = max_procs()
|
||||
ok_threads = VtOs.max_procs
|
||||
print("driver.py: Found %d cores, using -j %d" % (ok_threads, ok_threads))
|
||||
return ok_threads
|
||||
|
||||
|
||||
def calc_threads(default_threads) -> int:
|
||||
ok_threads = max_procs()
|
||||
ok_threads = int(VtOs.max_procs) # int() to appease pylint
|
||||
return ok_threads if (ok_threads < default_threads) else default_threads
|
||||
|
||||
|
||||
|
|
@ -2764,21 +2782,6 @@ def _calc_hashset() -> list:
|
|||
# Verilator utilities
|
||||
|
||||
|
||||
def get_cpu_count():
|
||||
try:
|
||||
return len(os.sched_getaffinity(0))
|
||||
except AttributeError:
|
||||
return multiprocessing.cpu_count()
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def max_procs() -> int:
|
||||
procs = get_cpu_count()
|
||||
if procs < 2:
|
||||
print("driver.py: Python didn't find at least two CPUs")
|
||||
return procs
|
||||
|
||||
|
||||
def _parameter(param: str) -> None:
|
||||
global _Parameter_Next_Level
|
||||
if _Parameter_Next_Level:
|
||||
|
|
|
|||
|
|
@ -8,17 +8,8 @@
|
|||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
import vltest_bootstrap
|
||||
import multiprocessing
|
||||
import os
|
||||
|
||||
|
||||
def get_cpu_count():
|
||||
try:
|
||||
return len(os.sched_getaffinity(0))
|
||||
except AttributeError:
|
||||
return multiprocessing.cpu_count()
|
||||
|
||||
|
||||
# If a test fails, broken .cmake may disturb the next run
|
||||
test.clean_objs()
|
||||
|
||||
|
|
@ -39,7 +30,7 @@ test.run(logfile=test.obj_dir + "/cmake.log",
|
|||
test.run(logfile=test.obj_dir + "/build.log",
|
||||
cmd=[
|
||||
'cd "' + test.obj_dir + '" && cmake --build', '.', ('-v' if test.verbose else ''),
|
||||
'-j ' + str(get_cpu_count()), '--', "CXX_FLAGS=" + str(threads)
|
||||
'-j ' + str(test.max_procs), '--', "CXX_FLAGS=" + str(threads)
|
||||
])
|
||||
|
||||
test.run(logfile=test.obj_dir + "/run.log",
|
||||
|
|
|
|||
Loading…
Reference in New Issue