Skip to content

Commit

Permalink
#13 add socket number in the cpu_info for linux platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminlebigot committed Sep 3, 2022
1 parent 1abce10 commit 092463d
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion boagent/hardware/cpu/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
from cpuinfo import get_cpu_info
from cpuid import *
import cpuid_native
import sys


def get_socket_number_linux(location="/sys/devices/system/node/possible"):
if sys.platform != "linux":
return "cannot compute socket number for other OS than linux"
with open(location, 'r') as f:
data = f.read()
return int(data.split('-')[-1])+1


def is_set(id, reg_idx, bit):
regs = cpuid(id)
Expand Down Expand Up @@ -29,6 +39,29 @@ def get_cpus():
"bmi1": is_set(7, 1, 3),
"bmi2": is_set(7, 1, 8),
},
"cpu_info": get_cpu_info()
"cpu_info": get_cpu_info(),
"nb_socket": get_socket_number_linux()
}]
return cpu_info





if __name__ =="__main__":
print("socket number linux from a file : {}".format(get_socket_number_linux()))
print("Info from the library cpuid-py:")
cpu_info = get_cpus()
for toto in [cpu_info[0], get_cpu_info()]:
print("\n\n\n")
for key,value in toto.items():
if(value is dict):
for i,j in value.items():
if(j is dict):
for a,b in value.items():
print("{} : {}\n".format(a ,b))

print("{} : {}\n".format(i,j))

else:
print("{} : {}\n".format(key,value))

0 comments on commit 092463d

Please # to comment.