]> git.proxmox.com Git - ceph.git/blame - ceph/src/seastar/dpdk/usertools/cpu_layout.py
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / dpdk / usertools / cpu_layout.py
CommitLineData
11fdf7f2 1#!/usr/bin/env python
9f95a23c
TL
2# SPDX-License-Identifier: BSD-3-Clause
3# Copyright(c) 2010-2014 Intel Corporation
4# Copyright(c) 2017 Cavium, Inc. All rights reserved.
11fdf7f2 5
11fdf7f2 6from __future__ import print_function
7c673cae 7import sys
11fdf7f2
TL
8try:
9 xrange # Python 2
10except NameError:
11 xrange = range # Python 3
7c673cae
FG
12
13sockets = []
14cores = []
15core_map = {}
11fdf7f2
TL
16base_path = "/sys/devices/system/cpu"
17fd = open("{}/kernel_max".format(base_path))
18max_cpus = int(fd.read())
7c673cae 19fd.close()
11fdf7f2
TL
20for cpu in xrange(max_cpus + 1):
21 try:
22 fd = open("{}/cpu{}/topology/core_id".format(base_path, cpu))
23 except IOError:
24 continue
25 except:
26 break
27 core = int(fd.read())
28 fd.close()
29 fd = open("{}/cpu{}/topology/physical_package_id".format(base_path, cpu))
30 socket = int(fd.read())
31 fd.close()
32 if core not in cores:
33 cores.append(core)
34 if socket not in sockets:
35 sockets.append(socket)
36 key = (socket, core)
37 if key not in core_map:
38 core_map[key] = []
39 core_map[key].append(cpu)
7c673cae 40
11fdf7f2
TL
41print(format("=" * (47 + len(base_path))))
42print("Core and Socket Information (as reported by '{}')".format(base_path))
43print("{}\n".format("=" * (47 + len(base_path))))
44print("cores = ", cores)
45print("sockets = ", sockets)
46print("")
7c673cae
FG
47
48max_processor_len = len(str(len(cores) * len(sockets) * 2 - 1))
11fdf7f2
TL
49max_thread_count = len(list(core_map.values())[0])
50max_core_map_len = (max_processor_len * max_thread_count) \
51 + len(", ") * (max_thread_count - 1) \
52 + len('[]') + len('Socket ')
7c673cae
FG
53max_core_id_len = len(str(max(cores)))
54
11fdf7f2 55output = " ".ljust(max_core_id_len + len('Core '))
7c673cae 56for s in sockets:
11fdf7f2
TL
57 output += " Socket %s" % str(s).ljust(max_core_map_len - len('Socket '))
58print(output)
59
60output = " ".ljust(max_core_id_len + len('Core '))
7c673cae 61for s in sockets:
11fdf7f2
TL
62 output += " --------".ljust(max_core_map_len)
63 output += " "
64print(output)
7c673cae
FG
65
66for c in cores:
11fdf7f2
TL
67 output = "Core %s" % str(c).ljust(max_core_id_len)
68 for s in sockets:
69 if (s,c) in core_map:
70 output += " " + str(core_map[(s, c)]).ljust(max_core_map_len)
71 else:
72 output += " " * (max_core_map_len + 1)
73 print(output)