]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
Change detection of number of CPU cores.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 11 Mar 2012 13:40:11 +0000 (14:40 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 11 Mar 2012 13:40:11 +0000 (14:40 +0100)
Recently, /sys/class/cpuid was read to find out
how many CPUs were running in the system.
It did not work on the experimental OMAP kernel,
so we change it to a POSIX implementation that
returns the number of all online CPUs.

fireinfo/cpu.py

index 9199df96f486fe09a4b3b3215e36724af39eaf07..32d885db8124f9f3690255e7f46a930ea8397bd7 100644 (file)
 #                                                                             #
 ###############################################################################
 
-import os.path
+import os
 
 import system
 
 PROC_CPUINFO = "/proc/cpuinfo"
-SYS_CLASS_CPUID = "/sys/class/cpuid/cpu%d"
 
 class CPU(object):
        """
@@ -178,11 +177,7 @@ class CPU(object):
                """
                        Count number of CPUs (cores).
                """
-               i = 0
-               while (os.path.exists(SYS_CLASS_CPUID % i)):
-                       i += 1
-
-               return i or 1
+               return os.sysconf("SC_NPROCESSORS_ONLN")
 
 
 if __name__ == "__main__":