xref: /dpdk/buildtools/get-numa-count.py (revision 9d4efc5cc6f90bcbd93a6fed904c8cbca9f5c447)
1#!/usr/bin/env python3
2# SPDX-License-Identifier: BSD-3-Clause
3# Copyright (c) 2021 PANTHEON.tech s.r.o.
4
5import ctypes
6import glob
7import os
8import subprocess
9import re
10
11if os.name == 'posix':
12    if os.path.isdir('/sys/devices/system/node'):
13        numa_nodes = glob.glob('/sys/devices/system/node/node*')
14        numa_nodes.sort(key=lambda l: int(re.findall('\d+', l)[0]))
15        print(int(os.path.basename(numa_nodes[-1])[4:]) + 1)
16    else:
17        subprocess.run(['sysctl', '-n', 'vm.ndomains'], check=False)
18
19elif os.name == 'nt':
20    libkernel32 = ctypes.windll.kernel32
21
22    numa_count = ctypes.c_ulong()
23
24    libkernel32.GetNumaHighestNodeNumber(ctypes.pointer(numa_count))
25    print(numa_count.value + 1)
26