diff options
author | Felix Moessbauer <felix.moessbauer@siemens.com> | 2024-03-13 11:06:45 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-03-21 12:39:25 +0000 |
commit | a029bfe96c6542f178720c72a772b7ede9898118 (patch) | |
tree | 9dd4aafdb29b0cde32977f62db0c0b4844cf9d12 /lib/bb/utils.py | |
parent | 944fe0a77932a5559e01ae6035c4bffa5185ea6a (diff) | |
download | bitbake-contrib-a029bfe96c6542f178720c72a772b7ede9898118.tar.gz |
utils: better estimate number of available cpus
When running in a cgroup which is limited to a subset of cpus (via
cpuset.cpus), cpu_count() should return the number of cpus that can be
used instead of the number of cpus the system has.
This also aligns the semantics with nproc.
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/utils.py')
-rw-r--r-- | lib/bb/utils.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py index ad13d0433..ebee65d3d 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -1142,7 +1142,10 @@ def get_referenced_vars(start_expr, d): def cpu_count(): - return multiprocessing.cpu_count() + try: + return len(os.sched_getaffinity(0)) + except OSError: + return multiprocessing.cpu_count() def nonblockingfd(fd): fcntl.fcntl(fd, fcntl.F_SETFL, fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK) |