/usr/share/checkbox/scripts/cpu_topology is in checkbox 0.13.7.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #!/usr/bin/python
'''
cpu_topology
Written by Jeffrey Lane <jeffrey.lane@canonical.com>
'''
import sys
import os
class proc_cpuinfo():
'''
Class to get and handle information from /proc/cpuinfo
Creates a dictionary of data gleaned from that file.
'''
def __init__(self):
self.cpuinfo = {}
cpu = ()
cpu_fh = open('/proc/cpuinfo','r')
try:
temp = cpu_fh.readlines()
finally:
cpu_fh.close()
for i in temp:
if i.startswith('processor'):
key = 'cpu'+(i.split(':')[1].strip())
self.cpuinfo[key] = {}
elif i.startswith('core id'):
self.cpuinfo[key].update({'core_id':i.split(':')[1].strip()})
elif i.startswith('physical id'):
self.cpuinfo[key].update({'physical_package_id':i.split(':')[1].strip()})
else:
continue
class sysfs_cpu():
'''
Class to get and handle information from sysfs as relates to CPU topology
Creates an informational class to present information on various CPUs
'''
def __init__(self,proc):
self.syscpu = {}
self.path = '/sys/devices/system/cpu/'+proc+'/topology'
items = ['core_id', 'physical_package_id']
for i in items:
syscpu_fh = open(os.path.join(self.path,i),'r')
try:
self.syscpu[i] = syscpu_fh.readline().strip()
finally:
syscpu_fh.close()
def compare(proc_cpu,sys_cpu):
cpu_map = {}
'''
If there is only 1 CPU the test don't look for core_id
and physical_package_id because those information are absent in
/proc/cpuinfo on singlecore system
'''
for key in proc_cpu.iterkeys():
if not proc_cpu.has_key('cpu1'):
cpu_map[key] = True
else:
for subkey in proc_cpu[key].iterkeys():
if proc_cpu[key][subkey] == sys_cpu[key][subkey]:
cpu_map[key] = True
else:
cpu_map[key] = False
return cpu_map
def main():
cpuinfo = proc_cpuinfo()
sys_cpu = {}
keys = cpuinfo.cpuinfo.iterkeys()
for k in keys:
sys_cpu[k] = sysfs_cpu(k).syscpu
cpu_map = compare(cpuinfo.cpuinfo,sys_cpu)
keys = [k for k in sys_cpu.iterkeys()]
keys.sort()
for key in keys:
print "%s:\tPhysical ID: %s\tCore ID: %s" % (key,
sys_cpu[key]['physical_package_id'],
sys_cpu[key]['core_id'])
if False in cpu_map or len(cpu_map) < 1:
return 1
else:
return 0
if __name__ == '__main__':
sys.exit(main())
|