[PATCH] rtemstoolkit: Use multiprocessing.cpu_count()

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Mar 5 09:36:46 UTC 2020


The previous implementation does not work on some Linux distributions,
e.g. Debian on sparc64.  Use a standard function instead.
---
 source-builder/sb/linux.py | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/source-builder/sb/linux.py b/source-builder/sb/linux.py
index 43a6d1d..4f7add5 100644
--- a/source-builder/sb/linux.py
+++ b/source-builder/sb/linux.py
@@ -22,6 +22,7 @@
 # RTEMS project's spec files.
 #
 
+import multiprocessing
 import pprint
 import os
 
@@ -31,20 +32,6 @@ import path
 
 def load():
     uname = os.uname()
-    smp_mflags = ''
-    processors = '/bin/grep processor /proc/cpuinfo'
-    e = execute.capture_execution()
-    exit_code, proc, output = e.shell(processors)
-    ncpus = 0
-    if exit_code == 0:
-        try:
-            for l in output.split('\n'):
-                count = l.split(':')[1].strip()
-                if int(count) > ncpus:
-                    ncpus = int(count)
-        except:
-            pass
-    ncpus = str(ncpus + 1)
     if uname[4].startswith('arm'):
         cpu = 'arm'
     else:
@@ -52,7 +39,7 @@ def load():
 
     version = uname[2]
     defines = {
-        '_ncpus':           ('none',    'none',     ncpus),
+        '_ncpus':           ('none',    'none',     str(multiprocessing.cpu_count())),
         '_os':              ('none',    'none',     'linux'),
         '_host':            ('triplet', 'required', cpu + '-linux-gnu'),
         '_host_vendor':     ('none',    'none',     'gnu'),
-- 
2.16.4



More information about the devel mailing list