[modules/sensors(2)] Better (?) CPU reading

Add support for ARM/PowerPC (BogoMIPS) and make sure that the module
doesn't throw errors when problems reading the CPU frequency occurs.

fixes #458
This commit is contained in:
Tobias Witek 2019-10-20 10:07:44 +02:00
parent cc58817978
commit 0f53567f31
2 changed files with 18 additions and 3 deletions

View file

@ -93,13 +93,21 @@ class Module(bumblebee.engine.Module):
return temperature return temperature
def get_mhz(self): def get_mhz(self):
mhz = None
try: try:
output = open("/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq").read() output = open("/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq").read()
mhz = int(float(output)/1000.0) mhz = int(float(output)/1000.0)
except: except:
output = open("/proc/cpuinfo").read() output = open("/proc/cpuinfo").read()
m = re.search(r"cpu MHz\s+:\s+(\d+)", output) m = re.search(r"cpu MHz\s+:\s+(\d+)", output)
mhz = int(m.group(1)) if m:
mhz = int(m.group(1))
else:
m = re.search(r"BogoMIPS\s+:\s+(\d+)", output)
if m:
return "{} BogoMIPS".format(int(m.group(1)))
if not mhz:
return "n/a"
if mhz < 1000: if mhz < 1000:
return "{} MHz".format(mhz) return "{} MHz".format(mhz)

View file

@ -132,18 +132,25 @@ class Module(bumblebee.engine.Module):
return output return output
def _cpu(self, _): def _cpu(self, _):
mhz = None
try: try:
output = open("/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq").read() output = open("/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq").read()
mhz = int(float(output)/1000.0) mhz = int(float(output)/1000.0)
except: except:
output = open("/proc/cpuinfo").read() output = open("/proc/cpuinfo").read()
m = re.search(r"cpu MHz\s+:\s+(\d+)", output) m = re.search(r"cpu MHz\s+:\s+(\d+)", output)
mhz = int(m.group(1)) if m:
mhz = int(m.group(1))
else:
m = re.search(r"BogoMIPS\s+:\s+(\d+)", output)
if m:
return "{} BogoMIPS".format(int(m.group(1)))
if not mhz:
return "n/a"
if mhz < 1000: if mhz < 1000:
return "{} MHz".format(mhz) return "{} MHz".format(mhz)
else: else:
return "{:0.01f} GHz".format(float(mhz)/1000.0) return "{:0.01f} GHz".format(float(mhz)/1000.0)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4