numam-dpdk/buildtools/get-numa-count.py
Juraj Linkeš 8ef09fdc50 build: add optional NUMA and CPU counts detection
Add an option to automatically discover the host's NUMA and CPU counts
and use those values for a non cross-build.
Give users the option to override the per-arch default values or values
from cross files by specifying them on the command line with -Dmax_lcores
and -Dmax_numa_nodes.

Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Reviewed-by: David Christensen <drc@linux.vnet.ibm.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
2021-09-16 09:43:28 +02:00

25 lines
666 B
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2021 PANTHEON.tech s.r.o.
import ctypes
import glob
import os
import subprocess
if os.name == 'posix':
if os.path.isdir('/sys/devices/system/node'):
numa_nodes = glob.glob('/sys/devices/system/node/node*')
numa_nodes.sort()
print(int(os.path.basename(numa_nodes[-1])[4:]) + 1)
else:
subprocess.run(['sysctl', '-n', 'vm.ndomains'], check=False)
elif os.name == 'nt':
libkernel32 = ctypes.windll.kernel32
numa_count = ctypes.c_ulong()
libkernel32.GetNumaHighestNodeNumber(ctypes.pointer(numa_count))
print(numa_count.value + 1)