The NUMA node of a logical CPU (sysfs), or -1.
| 675 | |
| 676 | // The NUMA node of a logical CPU (sysfs), or -1. |
| 677 | int cpu_numa_node(int cpu) { |
| 678 | if (cpu < 0) return -1; |
| 679 | const std::string root = sysfs_root(); |
| 680 | char path[512]; |
| 681 | for (int node = 0; node < 64; ++node) { |
| 682 | std::snprintf(path, sizeof path, "%s/devices/system/cpu/cpu%d/node%d", root.c_str(), cpu, node); |
| 683 | if (access(path, F_OK) == 0) return node; |
| 684 | } |
| 685 | return -1; |
| 686 | } |
| 687 | #endif |
| 688 | |
| 689 | // The NUMA nodes with CPUs this machine has (0.2.2: the split is tried by itself from 2 on). Linux: the sysfs node folder |
no test coverage detected