xref: /dpdk/buildtools/get-numa-count.py (revision daa02b5cddbb8e11b31d41e2bf7bb1ae64dcae2f)
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
9
10if os.name == 'posix':
11    if os.path.isdir('/sys/devices/system/node'):
12        numa_nodes = glob.glob('/sys/devices/system/node/node*')
13        numa_nodes.sort()
14        print(int(os.path.basename(numa_nodes[-1])[4:]) + 1)
15    else:
16        subprocess.run(['sysctl', '-n', 'vm.ndomains'], check=False)
17
18elif os.name == 'nt':
19    libkernel32 = ctypes.windll.kernel32
20
21    numa_count = ctypes.c_ulong()
22
23    libkernel32.GetNumaHighestNodeNumber(ctypes.pointer(numa_count))
24    print(numa_count.value + 1)
25