From 2a706fc8ae3c917fd3b3427582d2093db6f91e08 Mon Sep 17 00:00:00 2001 From: arigo Date: Sat, 13 Sep 2008 16:23:30 +0200 Subject: [PATCH] [svn r58108] A hyperthreaded cpu core should only count as 1, although it is present as 2 entries in /proc/cpuinfo. Counting it as 2 is misleading because it is *by far* not as efficient as two independent cores. --HG-- branch : trunk --- contrib/sysinfo.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/contrib/sysinfo.py b/contrib/sysinfo.py index 9c0a00969..b136a5666 100644 --- a/contrib/sysinfo.py +++ b/contrib/sysinfo.py @@ -65,18 +65,26 @@ class RemoteInfo: def getcpuinfo(self): if self.islinux(): - return self.exreceive(""" - numcpus = 0 - model = None - for line in open("/proc/cpuinfo"): - if not line.strip(): - continue - key, value = line.split(":") - key = key.strip() - if key == "processor": - numcpus += 1 - elif key == "model name": - model = value.strip() + return self.exreceive(""" + # a hyperthreaded cpu core only counts as 1, although it + # is present as 2 in /proc/cpuinfo. Counting it as 2 is + # misleading because it is *by far* not as efficient as + # two independent cores. + cpus = {} + cpuinfo = {} + f = open("/proc/cpuinfo") + lines = f.readlines() + f.close() + for line in lines + ['']: + if line.strip(): + key, value = line.split(":", 1) + cpuinfo[key.strip()] = value.strip() + else: + corekey = (cpuinfo.get("physical id"), + cpuinfo.get("core id")) + cpus[corekey] = 1 + numcpus = len(cpus) + model = cpuinfo.get("model name") channel.send((numcpus, model)) """)