2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2010-2014 Intel Corporation
4 # Copyright(c) 2017 Cavium, Inc. All rights reserved.
9 base_path = "/sys/devices/system/cpu"
10 fd = open("{}/kernel_max".format(base_path))
11 max_cpus = int(fd.read())
13 for cpu in range(max_cpus + 1):
15 fd = open("{}/cpu{}/topology/core_id".format(base_path, cpu))
22 fd = open("{}/cpu{}/topology/physical_package_id".format(base_path, cpu))
23 socket = int(fd.read())
27 if socket not in sockets:
28 sockets.append(socket)
30 if key not in core_map:
32 core_map[key].append(cpu)
34 print(format("=" * (47 + len(base_path))))
35 print("Core and Socket Information (as reported by '{}')".format(base_path))
36 print("{}\n".format("=" * (47 + len(base_path))))
37 print("cores = ", cores)
38 print("sockets = ", sockets)
41 max_processor_len = len(str(len(cores) * len(sockets) * 2 - 1))
42 max_thread_count = len(list(core_map.values())[0])
43 max_core_map_len = (max_processor_len * max_thread_count) \
44 + len(", ") * (max_thread_count - 1) \
45 + len('[]') + len('Socket ')
46 max_core_id_len = len(str(max(cores)))
48 output = " ".ljust(max_core_id_len + len('Core '))
50 output += " Socket %s" % str(s).ljust(max_core_map_len - len('Socket '))
53 output = " ".ljust(max_core_id_len + len('Core '))
55 output += " --------".ljust(max_core_map_len)
60 output = "Core %s" % str(c).ljust(max_core_id_len)
63 output += " " + str(core_map[(s, c)]).ljust(max_core_map_len)
65 output += " " * (max_core_map_len + 1)