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
13 if sys.version_info.major < 3:
14 print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
15 print("Please use Python 3 instead", file=sys.stderr)
20 base_path = "/sys/devices/system/cpu"
21 fd = open("{}/kernel_max".format(base_path))
22 max_cpus = int(fd.read())
24 for cpu in xrange(max_cpus + 1):
26 fd = open("{}/cpu{}/topology/core_id".format(base_path, cpu))
33 fd = open("{}/cpu{}/topology/physical_package_id".format(base_path, cpu))
34 socket = int(fd.read())
38 if socket not in sockets:
39 sockets.append(socket)
41 if key not in core_map:
43 core_map[key].append(cpu)
45 print(format("=" * (47 + len(base_path))))
46 print("Core and Socket Information (as reported by '{}')".format(base_path))
47 print("{}\n".format("=" * (47 + len(base_path))))
48 print("cores = ", cores)
49 print("sockets = ", sockets)
52 max_processor_len = len(str(len(cores) * len(sockets) * 2 - 1))
53 max_thread_count = len(list(core_map.values())[0])
54 max_core_map_len = (max_processor_len * max_thread_count) \
55 + len(", ") * (max_thread_count - 1) \
56 + len('[]') + len('Socket ')
57 max_core_id_len = len(str(max(cores)))
59 output = " ".ljust(max_core_id_len + len('Core '))
61 output += " Socket %s" % str(s).ljust(max_core_map_len - len('Socket '))
64 output = " ".ljust(max_core_id_len + len('Core '))
66 output += " --------".ljust(max_core_map_len)
71 output = "Core %s" % str(c).ljust(max_core_id_len)
74 output += " " + str(core_map[(s, c)]).ljust(max_core_map_len)
76 output += " " * (max_core_map_len + 1)