From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org, Robin Jarry <rjarry@redhat.com>
Cc: bruce.richardson@intel.com
Subject: [PATCH v6 2/4] usertools/cpu_layout: print out NUMA nodes
Date: Thu, 22 Aug 2024 11:38:24 +0100 [thread overview]
Message-ID: <40cf4ee32f15952457ac5526cfce64728bd13d32.1724323106.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <3dd16eeb15638b8429c38fa77aa83101bf375143.1724323106.git.anatoly.burakov@intel.com>
In traditional NUMA case, NUMA nodes and physical sockets were used
interchangeably, but there are cases where there can be multiple NUMA
nodes per socket, as well as all CPU's being assigned NUMA node 0 even in
cases of multiple sockets. Use sysfs to print out NUMA information.
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
Notes:
v5 -> v6:
- Track NUMA changes per socket to avoid issues with missing cores
v2 -> v3:
- Sort imports alphabetically
usertools/cpu_layout.py | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
diff --git a/usertools/cpu_layout.py b/usertools/cpu_layout.py
index e133fb8ad3..5972cfecdb 100755
--- a/usertools/cpu_layout.py
+++ b/usertools/cpu_layout.py
@@ -5,6 +5,7 @@
"""Display CPU topology information."""
+import glob
import typing as T
@@ -29,12 +30,21 @@ def read_sysfs(path: str) -> str:
return fd.read().strip()
+def read_numa_node(base: str) -> int:
+ """Read the NUMA node of a CPU."""
+ node_glob = f"{base}/node*"
+ node_dirs = glob.glob(node_glob)
+ if not node_dirs:
+ return 0 # default to node 0
+ return int(node_dirs[0].split("node")[1])
+
+
def print_row(row: T.Tuple[str, ...], col_widths: T.List[int]) -> None:
"""Print a row of a table with the given column widths."""
first, *rest = row
w_first, *w_rest = col_widths
first_end = " " * 4
- rest_end = " " * 10
+ rest_end = " " * 4
print(first.ljust(w_first), end=first_end)
for cell, width in zip(rest, w_rest):
@@ -56,6 +66,7 @@ def main() -> None:
sockets_s: T.Set[int] = set()
cores_s: T.Set[int] = set()
core_map: T.Dict[T.Tuple[int, int], T.List[int]] = {}
+ numa_map: T.Dict[int, int] = {}
base_path = "/sys/devices/system/cpu"
cpus = range_expand(read_sysfs(f"{base_path}/online"))
@@ -64,12 +75,14 @@ def main() -> None:
lcore_base = f"{base_path}/cpu{cpu}"
core = int(read_sysfs(f"{lcore_base}/topology/core_id"))
socket = int(read_sysfs(f"{lcore_base}/topology/physical_package_id"))
+ node = read_numa_node(lcore_base)
cores_s.add(core)
sockets_s.add(socket)
key = (socket, core)
core_map.setdefault(key, [])
core_map[key].append(cpu)
+ numa_map[cpu] = node
cores = sorted(cores_s)
sockets = sorted(sockets_s)
@@ -78,24 +91,36 @@ def main() -> None:
print("cores = ", cores)
print("sockets = ", sockets)
+ print("numa = ", sorted(set(numa_map.values())))
print()
- # Core, [Socket, Socket, ...]
- heading_strs = "", *[f"Socket {s}" for s in sockets]
+ # Core, [NUMA, Socket, NUMA, Socket, ...]
+ heading_strs = "", *[v for s in sockets for v in ("", f"Socket {s}")]
sep_strs = tuple("-" * len(hstr) for hstr in heading_strs)
rows: T.List[T.Tuple[str, ...]] = []
+ # track NUMA changes per socket
+ prev_numa: T.Dict[int, T.Optional[int]] = {socket: None for socket in sockets}
for c in cores:
# Core,
row: T.Tuple[str, ...] = (f"Core {c}",)
- # [lcores, lcores, ...]
+ # [NUMA, lcores, NUMA, lcores, ...]
for s in sockets:
try:
lcores = core_map[(s, c)]
+
+ numa = numa_map[lcores[0]]
+ numa_changed = prev_numa[s] != numa
+ prev_numa[s] = numa
+
+ if numa_changed:
+ row += (f"NUMA {numa}",)
+ else:
+ row += ("",)
row += (str(lcores),)
except KeyError:
- row += ("",)
+ row += ("", "")
rows += [row]
# find max widths for each column, including header and rows
--
2.43.5
next prev parent reply other threads:[~2024-08-22 10:38 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-14 11:19 [PATCH v1 1/2] usertools/cpu_layout: update coding style Anatoly Burakov
2024-08-14 11:19 ` [PATCH v1 2/2] usertools/cpu_layout: print out NUMA nodes Anatoly Burakov
2024-08-16 12:16 ` [PATCH v2 1/4] usertools/cpu_layout: update coding style Anatoly Burakov
2024-08-16 12:16 ` [PATCH v2 2/4] usertools/cpu_layout: print out NUMA nodes Anatoly Burakov
2024-08-19 11:23 ` Robin Jarry
2024-08-16 12:16 ` [PATCH v2 3/4] usertools/dpdk-hugepages.py: sort by NUMA node Anatoly Burakov
2024-08-16 12:21 ` Burakov, Anatoly
2024-08-19 11:32 ` Robin Jarry
2024-08-20 9:04 ` Burakov, Anatoly
2024-08-20 9:06 ` Robin Jarry
2024-08-16 12:16 ` [PATCH v2 4/4] usertools/dpdk-devbind: print " Anatoly Burakov
2024-08-19 11:34 ` Robin Jarry
2024-08-20 9:08 ` Burakov, Anatoly
2024-08-20 9:28 ` Robin Jarry
2024-08-20 9:40 ` Burakov, Anatoly
2024-08-20 9:49 ` Robin Jarry
2024-08-20 9:56 ` Burakov, Anatoly
2024-08-20 10:00 ` Robin Jarry
2024-08-19 11:11 ` [PATCH v2 1/4] usertools/cpu_layout: update coding style Robin Jarry
2024-08-20 9:12 ` Burakov, Anatoly
2024-08-20 9:20 ` Robin Jarry
2024-08-20 9:31 ` Burakov, Anatoly
2024-08-20 9:45 ` Robin Jarry
2024-08-20 9:56 ` Burakov, Anatoly
2024-08-19 9:26 ` [PATCH v1 1/2] " Robin Jarry
2024-08-19 9:36 ` Burakov, Anatoly
2024-08-19 15:13 ` Stephen Hemminger
2024-08-20 15:35 ` [PATCH v3 1/4] " Anatoly Burakov
2024-08-20 15:35 ` [PATCH v3 2/4] usertools/cpu_layout: print out NUMA nodes Anatoly Burakov
2024-08-20 19:22 ` Robin Jarry
2024-08-21 8:49 ` Burakov, Anatoly
2024-08-20 15:35 ` [PATCH v3 3/4] usertools/dpdk-hugepages.py: update coding style Anatoly Burakov
2024-08-20 15:52 ` Stephen Hemminger
2024-08-21 8:53 ` Burakov, Anatoly
2024-08-20 15:57 ` Robin Jarry
2024-08-21 8:52 ` Burakov, Anatoly
2024-08-21 9:06 ` Burakov, Anatoly
2024-08-21 9:16 ` Burakov, Anatoly
2024-08-21 9:22 ` Robin Jarry
2024-08-20 15:35 ` [PATCH v3 4/4] usertools/dpdk-devbind: print NUMA node Anatoly Burakov
2024-08-20 15:59 ` [PATCH v3 1/4] usertools/cpu_layout: update coding style Robin Jarry
2024-08-21 8:49 ` Burakov, Anatoly
2024-08-21 9:22 ` [PATCH v4 " Anatoly Burakov
2024-08-21 9:22 ` [PATCH v4 2/4] usertools/cpu_layout: print out NUMA nodes Anatoly Burakov
2024-08-21 9:22 ` [PATCH v4 3/4] usertools/dpdk-hugepages.py: update coding style Anatoly Burakov
2024-08-21 9:26 ` Robin Jarry
2024-08-21 9:39 ` Burakov, Anatoly
2024-08-21 9:22 ` [PATCH v4 4/4] usertools/dpdk-devbind: print NUMA node Anatoly Burakov
2024-08-21 9:44 ` [PATCH v5 1/4] usertools/cpu_layout: update coding style Anatoly Burakov
2024-08-21 9:44 ` [PATCH v5 2/4] usertools/cpu_layout: print out NUMA nodes Anatoly Burakov
2024-08-21 11:43 ` Robin Jarry
2024-08-21 9:44 ` [PATCH v5 3/4] usertools/dpdk-hugepages.py: update coding style Anatoly Burakov
2024-08-21 11:43 ` Robin Jarry
2024-08-21 9:44 ` [PATCH v5 4/4] usertools/dpdk-devbind: print NUMA node Anatoly Burakov
2024-08-21 11:44 ` Robin Jarry
2024-08-21 10:16 ` [PATCH v5 1/4] usertools/cpu_layout: update coding style Robin Jarry
2024-08-22 10:38 ` [PATCH v6 " Anatoly Burakov
2024-08-22 10:38 ` Anatoly Burakov [this message]
2024-08-22 17:43 ` [PATCH v6 2/4] usertools/cpu_layout: print out NUMA nodes Robin Jarry
2024-10-12 17:56 ` Stephen Hemminger
2024-08-22 10:38 ` [PATCH v6 3/4] usertools/dpdk-hugepages.py: update coding style Anatoly Burakov
2024-08-22 10:38 ` [PATCH v6 4/4] usertools/dpdk-devbind: print NUMA node Anatoly Burakov
2024-10-12 17:57 ` Stephen Hemminger
2024-10-12 17:57 ` [PATCH v6 1/4] usertools/cpu_layout: update coding style Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=40cf4ee32f15952457ac5526cfce64728bd13d32.1724323106.git.anatoly.burakov@intel.com \
--to=anatoly.burakov@intel.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=rjarry@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).