]> code.ossystems Code Review - openembedded-core.git/commitdiff
utils: respect scheduler affinity in cpu_count()
authorRoss Burton <ross@burtonini.com>
Mon, 28 Sep 2020 16:18:55 +0000 (17:18 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 30 Sep 2020 14:01:46 +0000 (15:01 +0100)
cpu_count() returns multiprocessing.cpu_count() but that is simply returns
os.cpu_count() so we could use that directly.

However this returns the number of CPUs on the host, not the number of
usable CPUs on the host. If the user is using scheduler affinity then
the number of usable CPUs may be less, so when determining how many cores
we can use check the affinity instead.

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oe/utils.py

index 13f4271da04fd09115275199b89207b77f1a6cf8..468c76f30f285977df0b999d0bbc691c6d6faa30 100644 (file)
@@ -249,8 +249,7 @@ def trim_version(version, num_parts=2):
     return trimmed
 
 def cpu_count(at_least=1):
-    import multiprocessing
-    cpus = multiprocessing.cpu_count()
+    cpus = len(os.sched_getaffinity(0))
     return max(cpus, at_least)
 
 def execute_pre_post_process(d, cmds):