bronx.system.cpus¶
This module is in charge of getting informations on CPUs.
Various concrete implementations may be provided since the mechanism to retrieve
information on CPUs is not portable across platforms. At the present time, the
only concrete implementation is the LinuxCpusInfo class that relies on
the /proc/cpuinfo virtual file.
On Belenos (2x AMD Rome socket with 64 cores each):
>>> cpu_i = LinuxCpusInfo()
>>> cpu_i.nphysical_cores
128
>>> cpu_i.nvirtual_cores
128
>>> cpu_i.nsockets
2
>>> cpu_i.nphysical_cores_per_socket
64
>>> cpu_i.smt_threads
1
>>> import pprint
>>> pprint.pprint(cpu_i.cpus_hierarchy)
defaultdict(functools.partial(<class 'collections.defaultdict'>, <class 'list'>),
{0: defaultdict(<class 'list'>,
{0: [0],
1: [1],
2: [2],
3: [3],
4: [4],
5: [5],
6: [6],
7: [7],
8: [8],
9: [9],
10: [10],
11: [11],
12: [12],
13: [13],
14: [14],
15: [15],
16: [16],
17: [17],
18: [18],
19: [19],
20: [20],
21: [21],
22: [22],
23: [23],
24: [24],
25: [25],
26: [26],
27: [27],
28: [28],
29: [29],
30: [30],
31: [31],
32: [32],
33: [33],
34: [34],
35: [35],
36: [36],
37: [37],
38: [38],
39: [39],
40: [40],
41: [41],
42: [42],
43: [43],
44: [44],
45: [45],
46: [46],
47: [47],
48: [48],
49: [49],
50: [50],
51: [51],
52: [52],
53: [53],
54: [54],
55: [55],
56: [56],
57: [57],
58: [58],
59: [59],
60: [60],
61: [61],
62: [62],
63: [63]}),
1: defaultdict(<class 'list'>,
{0: [64],
1: [65],
2: [66],
3: [67],
4: [68],
5: [69],
6: [70],
7: [71],
8: [72],
9: [73],
10: [74],
11: [75],
12: [76],
13: [77],
14: [78],
15: [79],
16: [80],
17: [81],
18: [82],
19: [83],
20: [84],
21: [85],
22: [86],
23: [87],
24: [88],
25: [89],
26: [90],
27: [91],
28: [92],
29: [93],
30: [94],
31: [95],
32: [96],
33: [97],
34: [98],
35: [99],
36: [100],
37: [101],
38: [102],
39: [103],
40: [104],
41: [105],
42: [106],
43: [107],
44: [108],
45: [109],
46: [110],
47: [111],
48: [112],
49: [113],
50: [114],
51: [115],
52: [116],
53: [117],
54: [118],
55: [119],
56: [120],
57: [121],
58: [122],
59: [123],
60: [124],
61: [125],
62: [126],
63: [127]})})
Module Attributes¶
- bronx.system.cpus.CpuInfo = <class 'bronx.system.cpus.CpuInfo'>
Data about a given CPU
Functions¶
Classes¶
- class bronx.system.cpus.CpuInfo(socket_id, core_id)¶
Bases:
tupleData about a given CPU
- property core_id¶
Alias for field number 1
- property socket_id¶
Alias for field number 0
- class bronx.system.cpus.CpusInfo[source]¶
Bases:
objectProvide various informations about CPUs (abstract class).
- abstract property cpus¶
The raw dictionary of the system’s CPUs.
- property cpus_hierarchy¶
A hierarchical view of CPUs.
This returns a dictionary with the following structure:
dict(socket_id1:dict(core_id1:list(cpuid1, cpuid2, ...), ...), ...)
For a given socket_id and core_id, the list of cpuIDs shows all of the virtual CPUs associated to the physical core.
- property nphysical_cores¶
The total number of physical cores on this system.
- property nphysical_cores_per_socket¶
The number of physical cores per socket.
- property nsockets¶
The number of sockets on this system.
- property nvirtual_cores¶
The total number of virtual cores on this system.
- property physical_cores_smtthreads¶
For each physical core, associate the first CPUid and its siblings
- raw_cpulist(bsize=1)[source]¶
Re-arrange the list of CPUs in a very simple way.
- Parameters:
bsize (int) – unused
- Return type:
generator (of int)
- property smt_threads¶
The Simultaneous MultiThreading threads count.
- socketpacked_cpulist(bsize=1)[source]¶
Re-arrange the list of CPUs in a round-robin manner across sockets.
- Parameters:
bsize (int) – The number of threads used by a task (the CPU will be arranged in a way that all of one task’s threads are located on the same socket).
- Return type:
generator (of int)
For example, on a two sockets system, with bsize=1, the first element will be the first physical core of socket#0, the second element will be the first physical core of socket#1, the third element will be the second physical core of socket#0, …
With bsize=2 and the same example, the generator would produce something like:
list(Socket0-Core0, Socket0-Core1, Socket1-Core0, Socket1-Core1, Socket0-Core2, Socket0-Core3, ...)
- class bronx.system.cpus.LinuxCpusInfo[source]¶
Bases:
CpusInfoProvide various informations about CPUs based on the /proc/cpuinfo file.
Check the the /proc/cpuinfo file exists before going on.
- property cpus¶
The dictionary of the system’s CPUs.
If needed, process /proc/cpuinfo to get all the necessary data.
Exceptions¶
Bases:
ExceptionRaised whenever the necessary commands and/or system files are missing.