Skip to content

Commit a94f0ef

Browse files
committed
CPU: adds NUMA node detection
1 parent da3a9be commit a94f0ef

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

src/detection/cpu/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef struct FFCPUResult
2121
uint16_t coresPhysical;
2222
uint16_t coresLogical;
2323
uint16_t coresOnline;
24+
uint16_t numaNodes;
2425

2526
uint32_t frequencyBase; // GHz
2627
uint32_t frequencyMax; // GHz

src/detection/cpu/cpu_bsd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
100100
detectThermalTemp(&cpu->temperature);
101101
}
102102

103+
cpu->numaNodes = (uint16_t) ffSysctlGetInt("vm.ndomains", 0);
104+
103105
return NULL;
104106
}

src/detection/cpu/cpu_linux.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ static double detectCPUTemp(void)
138138
return FF_CPU_TEMP_UNSET;
139139
}
140140

141+
static void detectNumaNodes(FFCPUResult* cpu)
142+
{
143+
FF_AUTO_CLOSE_DIR DIR* dir = opendir("/sys/devices/system/node/");
144+
if (!dir) return;
145+
146+
struct dirent* entry;
147+
while ((entry = readdir(dir)) != NULL)
148+
{
149+
if (entry->d_type != DT_DIR && entry->d_type != DT_UNKNOWN)
150+
continue;
151+
if (ffStrStartsWith(entry->d_name, "node") && ffCharIsDigit(entry->d_name[strlen("node")]))
152+
cpu->numaNodes++;
153+
}
154+
}
155+
141156
#ifdef __ANDROID__
142157
#include "common/settings.h"
143158

@@ -568,6 +583,8 @@ FF_MAYBE_UNUSED static const char* detectCPUX86(const FFCPUOptions* options, FFC
568583
if (!detectFrequency(cpu, options) || cpu->frequencyBase == 0)
569584
cpu->frequencyBase = (uint32_t) ffStrbufToUInt(&cpuMHz, 0);
570585

586+
detectNumaNodes(cpu);
587+
571588
return NULL;
572589
}
573590

@@ -877,6 +894,7 @@ FF_MAYBE_UNUSED static const char* detectCPUOthers(const FFCPUOptions* options,
877894
detectPhysicalCores(cpu);
878895

879896
ffCPUDetectByCpuid(cpu);
897+
detectNumaNodes(cpu);
880898

881899
return NULL;
882900
}

src/detection/cpu/cpu_windows.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ static const char* detectNCores(FFCPUResult* cpu)
230230
++cpu->coresPhysical;
231231
else if (ptr->Relationship == RelationProcessorPackage)
232232
++cpu->packages;
233+
else if (ptr->Relationship == RelationNumaNode)
234+
++cpu->numaNodes;
233235
}
234236

235237
return NULL;

src/modules/cpu/cpu.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ bool ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
217217
else
218218
yyjson_mut_obj_add_null(doc, obj, "march");
219219

220+
if (cpu.numaNodes > 0)
221+
yyjson_mut_obj_add_uint(doc, obj, "numaNodes", cpu.numaNodes);
222+
else
223+
yyjson_mut_obj_add_null(doc, obj, "numaNodes");
224+
220225
success = true;
221226
}
222227

@@ -259,6 +264,6 @@ FFModuleBaseInfo ffCPUModuleInfo = {
259264
{"Temperature (formatted)", "temperature"},
260265
{"Logical core count grouped by frequency", "core-types"},
261266
{"Processor package count", "packages"},
262-
{"X86-64 CPU microarchitecture", "march"},
267+
{"CPU microarchitecture", "march"},
263268
}))
264269
};

0 commit comments

Comments
 (0)