2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2010-2014 Intel Corporation
4 # Copyright(c) 2017 Cavium, Inc. All rights reserved.
6 from __future__ import print_function
11 xrange = range # Python 3
16 base_path = "/sys/devices/system/cpu"
17 fd = open("{}/kernel_max".format(base_path))
18 max_cpus = int(fd.read())
20 for cpu in xrange(max_cpus + 1):
22 fd = open("{}/cpu{}/topology/core_id".format(base_path, cpu))
29 fd = open("{}/cpu{}/topology/physical_package_id".format(base_path, cpu))
30 socket = int(fd.read())
34 if socket not in sockets:
35 sockets.append(socket)
37 if key not in core_map:
39 core_map[key].append(cpu)
41 print(format("=" * (47 + len(base_path))))
42 print("Core and Socket Information (as reported by '{}')".format(base_path))
43 print("{}\n".format("=" * (47 + len(base_path))))
44 print("cores = ", cores)
45 print("sockets = ", sockets)
48 max_processor_len = len(str(len(cores) * len(sockets) * 2 - 1))
49 max_thread_count = len(list(core_map.values())[0])
50 max_core_map_len = (max_processor_len * max_thread_count) \
51 + len(", ") * (max_thread_count - 1) \
52 + len('[]') + len('Socket ')
53 max_core_id_len = len(str(max(cores)))
55 output = " ".ljust(max_core_id_len + len('Core '))
57 output += " Socket %s" % str(s).ljust(max_core_map_len - len('Socket '))
60 output = " ".ljust(max_core_id_len + len('Core '))
62 output += " --------".ljust(max_core_map_len)
67 output = "Core %s" % str(c).ljust(max_core_id_len)
70 output += " " + str(core_map[(s, c)]).ljust(max_core_map_len)
72 output += " " * (max_core_map_len + 1)