Commit 19c7022c authored by Thomas Gambier's avatar Thomas Gambier Committed by Kirill Smelkov

support systems where 'model name' doesn't exist in /proc/cpuinfo

--------
kirr: I looked around a bit and I see that RISC-V indeed misses many
things, including model name in its /proc/cpuinfo but has isa there:

https://www.reddit.com/r/RISCV/comments/wfz050/samples_of_riscv_proccpuinfo/
https://lore.kernel.org/lkml/1538507707-22299-14-git-send-email-atish.patra@wdc.com/

However I also see that model name is x86-specific and isa is also not
present on other architectures, e.g. /proc/cpuinfo for ARM misses both
model name and isa.

So I adjusted the patch a bit to support environment where both `model
name` and `isa` are not present in /proc/cpuinfo - for example ARM.

In the future we might change to rely on `lscpu` instead completely to
avoid dealing with all these arch-specific peculiarities.

/reviewed-by @kirr
/reviewed-on !18
parent 39464b65
Pipeline #34572 failed with stage
in 0 seconds
...@@ -440,10 +440,16 @@ def system_info(): ...@@ -440,10 +440,16 @@ def system_info():
whoami = pwd.getpwuid(os.getuid()).pw_name whoami = pwd.getpwuid(os.getuid()).pw_name
emit('xnode:\t%s@%s' % (whoami, socket.getfqdn())) emit('xnode:\t%s@%s' % (whoami, socket.getfqdn()))
emit('uname:\t%s' % ' '.join(os.uname())) emit('uname:\t%s' % ' '.join(os.uname()))
emit('cpu:\t%s' % get1('/proc/cpuinfo', 'model name')) cpu = get1('/proc/cpuinfo', 'model name', None) # e.g. no 'model name' on riscv
isa = get1('/proc/cpuinfo', 'isa', None) # present on riscv, but not on x86
if cpu:
emit('cpu:\t%s' % cpu)
if isa:
emit('isa:\t%s' % isa)
# get1 returns first entry from file @path prefixed with ^<field>\s*: # get1 returns first entry from file @path prefixed with ^<field>\s*:
def get1(path, field, default=None): _nodefault = object()
def get1(path, field, default=_nodefault):
with open(path, 'r') as f: with open(path, 'r') as f:
data = f.read() data = f.read()
rex = re.compile(r'^%s\s*:\s*(.*)$' % field) rex = re.compile(r'^%s\s*:\s*(.*)$' % field)
...@@ -451,7 +457,7 @@ def get1(path, field, default=None): ...@@ -451,7 +457,7 @@ def get1(path, field, default=None):
m = rex.match(l) m = rex.match(l)
if m is not None: if m is not None:
return m.group(1) return m.group(1)
if default is not None: if default is not _nodefault:
return default return default
raise KeyError('%s does not have field %r' % (path, field)) raise KeyError('%s does not have field %r' % (path, field))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment