]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse: move the binding detection into numa_detect_topology()
authorWilly Tarreau <w@1wt.eu>
Thu, 6 Jul 2023 13:48:27 +0000 (15:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 14 Mar 2025 17:30:30 +0000 (18:30 +0100)
For now the function refrains from detecting the CPU topology when a
restrictive taskset or cpu-map was already performed on the process,
and it's documented as such, the reason being that until we're able
to automatically create groups, better not change user settings. But
we'll need to be able to detect bound CPUs and to process them as
desired by the user, so we now need to move that detection into the
function itself. It changes nothing to the logic, just gives more
freedom to the function.

src/cfgparse.c

index f63c259923c3bbfb0361488f98b3361e4b894a5b..4096b88d8800a2c230b3d92f4dda03ae730d50ef 100644 (file)
@@ -2743,8 +2743,8 @@ static int numa_filter(const struct dirent *dir)
  */
 static int numa_detect_topology()
 {
-       struct dirent **node_dirlist;
-       int node_dirlist_size;
+       struct dirent **node_dirlist = NULL;
+       int node_dirlist_size = 0;
 
        struct hap_cpuset active_cpus, node_cpu_set;
        const char *parse_cpu_set_args[2];
@@ -2754,6 +2754,10 @@ static int numa_detect_topology()
        /* node_cpu_set count is used as return value */
        ha_cpuset_zero(&node_cpu_set);
 
+       /* let's ignore restricted affinity */
+       if (cpu_mask_forced || cpu_map_configured())
+               goto free_scandir_entries;
+
        /* 1. count the sysfs node<X> directories */
        node_dirlist = NULL;
        node_dirlist_size = scandir(NUMA_DETECT_SYSTEM_SYSFS_PATH"/node", &node_dirlist, numa_filter, alphasort);
@@ -2819,14 +2823,18 @@ static int numa_detect_topology()
        size_t len = sizeof(ndomains);
        int grp, thr;
 
+       ha_cpuset_zero(&node_cpu_set);
+
+       /* let's ignore restricted affinity */
+       if (cpu_mask_forced || cpu_map_configured())
+               goto leave;
+
        if (sysctlbyname("vm.ndomains", &ndomains, &len, NULL, 0) == -1) {
                ha_notice("Cannot assess the number of CPUs domains\n");
                return 0;
        }
 
        BUG_ON(ndomains > MAXMEMDOM);
-       ha_cpuset_zero(&node_cpu_set);
-
        if (ndomains < 2)
                goto leave;
 
@@ -2922,7 +2930,7 @@ int check_config_validity()
                {
                        int numa_cores = 0;
 #if defined(USE_CPU_AFFINITY)
-                       if (global.numa_cpu_mapping && !cpu_mask_forced && !cpu_map_configured())
+                       if (global.numa_cpu_mapping)
                                numa_cores = numa_detect_topology();
 #endif
                        global.nbthread = numa_cores ? numa_cores :