Skip to content

Commit 21787a3

Browse files
committed
linux: detect fake numa in the Linux kernel cmdline
fake numa is a development hack for changing the NUMA layout but some of its options (uniform splitting) are going to be used in production, so detect it (without using it yet). Signed-off-by: Brice Goglin <[email protected]>
1 parent cd3db48 commit 21787a3

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

hwloc/topology-linux.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct hwloc_linux_backend_data_s {
5656
} arch;
5757
int is_knl;
5858
int is_amd_with_CU;
59+
int is_fake_numa_uniform; /* 0 if not fake, -1 if fake non-uniform, N if fake=<N>U */
5960
int use_numa_distances;
6061
int use_numa_distances_for_cpuless;
6162
int use_numa_initiators;
@@ -5531,6 +5532,40 @@ static int check_sysfs_cpu_path(int root_fd, int *old_filenames)
55315532
return -1;
55325533
}
55335534

5535+
static void
5536+
hwloc_linuxfs_check_kernel_cmdline(struct hwloc_linux_backend_data_s *data)
5537+
{
5538+
FILE *file;
5539+
char cmdline[4096];
5540+
char *fakenuma;
5541+
5542+
file = hwloc_fopen("/proc/cmdline", "r", data->root_fd);
5543+
if (!file)
5544+
return;
5545+
5546+
cmdline[0] = 0;
5547+
fgets(cmdline, sizeof(cmdline), file);
5548+
5549+
fakenuma = strstr(cmdline, "numa=fake=");
5550+
if (fakenuma) {
5551+
/* in fake numa emulation, SLIT is updated but HMAT isn't, hence we need to disable/fix things later */
5552+
unsigned width = 0;
5553+
char type = 0;
5554+
if (sscanf(fakenuma+10, "%u%c", &width, &type) == 2 && type == 'U') {
5555+
/* if <N>U, each node is split in 8 nodes, we can still do things in this case */
5556+
data->is_fake_numa_uniform = width;
5557+
} else {
5558+
/* otherwise fake nodes are created by just dividing the entire RAM,
5559+
* without respecting locality at all
5560+
*/
5561+
data->is_fake_numa_uniform = -1;
5562+
}
5563+
hwloc_debug("Found fake numa %d\n", data->is_fake_numa_uniform);
5564+
}
5565+
5566+
fclose(file);
5567+
}
5568+
55345569
static int
55355570
hwloc_linuxfs_look_cpu(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
55365571
{
@@ -5583,6 +5618,11 @@ hwloc_linuxfs_look_cpu(struct hwloc_backend *backend, struct hwloc_disc_status *
55835618
*/
55845619
hwloc_gather_system_info(topology, data);
55855620

5621+
/**********************************
5622+
* Detect things in /proc/cmdline
5623+
*/
5624+
hwloc_linuxfs_check_kernel_cmdline(data);
5625+
55865626
/**********************
55875627
* /proc/cpuinfo
55885628
*/
@@ -7215,6 +7255,7 @@ hwloc_linux_component_instantiate(struct hwloc_topology *topology,
72157255
data->arch = HWLOC_LINUX_ARCH_UNKNOWN;
72167256
data->is_knl = 0;
72177257
data->is_amd_with_CU = 0;
7258+
data->is_fake_numa_uniform = 0;
72187259
data->is_real_fsroot = 1;
72197260
data->root_path = NULL;
72207261
fsroot_path = getenv("HWLOC_FSROOT");

0 commit comments

Comments
 (0)