]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cpu-topo: notify when cpu-policy is ignored due to other settings
authorWilly Tarreau <w@1wt.eu>
Thu, 28 May 2026 15:41:18 +0000 (17:41 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 28 May 2026 16:49:47 +0000 (18:49 +0200)
The cpu-policy directive is ignored when nbthreads, thread-groups, or
cpu-map are set. In addition, first-usable-node is ignored when the
process was externally restricted (e.g. taskset). This is difficult to
debug when it happens because multiple parameters come into the mix and
it's easy to forget to unset one. Let's emit a notice when this happens
and the policy was forced. This way, it remains silent with the default
policy, but if it was forced, the incompatibility is reported.

It's worth noting that ll the cpu-policy functions take a char **err
but none uses it. It could have been useful here instead of calling
ha_notice() all along, but one needs to determine who the consumers
are and who will be responsible for freeing the message, so let's go
with ha_notice() given that were were already some diag_warnings in
these functions.

It could be helpful to backport this to 3.2.

src/cpu_topo.c

index a9ba92fb5619d0c6cf77c99bdcdc5b27b122206d..b14e69fae049e91970a94cab8f60d061719d476e 100644 (file)
@@ -19,6 +19,7 @@
 
 /* cpu_policy_conf flags */
 #define CPU_POLICY_ONE_THREAD_PER_CORE (1 << 0)
+#define CPU_POLICY_SET_IN_CONFIG       (1 << 1)
 
 /* cpu_policy_conf affinities */
 #define CPU_AFFINITY_PER_GROUP  (1 << 0)
@@ -1106,14 +1107,23 @@ static int cpu_policy_first_usable_node(int policy, int tmin, int tmax, int gmin
        int grp, thr;
        int thr_count = 0;
 
-       if (!global.numa_cpu_mapping)
+       if (!global.numa_cpu_mapping) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when numa-cpu-mapping is set.\n");
                return 0;
+       }
 
-       if (global.nbthread)
+       if (global.nbthread) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when nbthreads is set.\n");
                return 0;
+       }
 
-       if (cpu_mask_forced)
+       if (cpu_mask_forced) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy first-numa-node is ignored when CPUs were externally restricted.\n");
                return 0;
+       }
 
        /* determine first and second nodes with usable CPUs */
        for (cpu = 0; cpu <= cpu_topo_lastcpu; cpu++) {
@@ -1505,11 +1515,17 @@ static int cpu_policy_group_by_cluster(int policy, int tmin, int tmax, int gmin,
        int cid;
        int div;
 
-       if (global.nbthread)
+       if (global.nbthread) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when nbthreads is set.\n");
                return 0;
+       }
 
-       if (global.nbtgroups)
+       if (global.nbtgroups) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when thread-groups is set.\n");
                return 0;
+       }
 
        ha_cpuset_zero(&visited_cl_set);
 
@@ -1598,11 +1614,17 @@ static int cpu_policy_group_by_ccx(int policy, int tmin, int tmax, int gmin, int
        int l3id;
        int div;
 
-       if (global.nbthread)
+       if (global.nbthread) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when nbthreads is set.\n");
                return 0;
+       }
 
-       if (global.nbtgroups)
+       if (global.nbtgroups) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when thread-groups is set.\n");
                return 0;
+       }
 
        ha_cpuset_zero(&visited_ccx_set);
 
@@ -1681,8 +1703,17 @@ static int cpu_policy_performance(int policy, int tmin, int tmax, int gmin, int
        int cpu, cluster;
        int capa;
 
-       if (global.nbthread || global.nbtgroups)
+       if (global.nbthread) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when nbthreads is set.\n");
+               return 0;
+       }
+
+       if (global.nbtgroups) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when thread-groups is set.\n");
                return 0;
+       }
 
        /* sort clusters by average reverse capacity */
        cpu_cluster_reorder_by_avg_capa(ha_cpu_clusters, cpu_topo_maxcpus);
@@ -1726,8 +1757,17 @@ static int cpu_policy_efficiency(int policy, int tmin, int tmax, int gmin, int g
        int cpu, cluster;
        int capa;
 
-       if (global.nbthread || global.nbtgroups)
+       if (global.nbthread) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when nbthreads is set.\n");
                return 0;
+       }
+
+       if (global.nbtgroups) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when thread-groups is set.\n");
+               return 0;
+       }
 
        /* sort clusters by average reverse capacity */
        cpu_cluster_reorder_by_avg_capa(ha_cpu_clusters, cpu_topo_maxcpus);
@@ -1768,8 +1808,17 @@ static int cpu_policy_resource(int policy, int tmin, int tmax, int gmin, int gma
        int cpu, cluster;
        int capa;
 
-       if (global.nbthread || global.nbtgroups)
+       if (global.nbthread) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when nbthreads is set.\n");
                return 0;
+       }
+
+       if (global.nbtgroups) {
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when thread-groups is set.\n");
+               return 0;
+       }
 
        /* sort clusters by reverse capacity */
        cpu_cluster_reorder_by_capa(ha_cpu_clusters, cpu_topo_maxcpus);
@@ -1804,6 +1853,8 @@ int cpu_apply_policy(int tmin, int tmax, int gmin, int gmax, char **err)
 
        if (cpu_map_configured()) {
                /* nothing to do */
+               if (cpu_policy_conf.flags & CPU_POLICY_SET_IN_CONFIG)
+                       ha_notice("cpu-policy is ignored when cpu-map is set.\n");
                return 0;
        }
 
@@ -2359,6 +2410,7 @@ static int cfg_parse_cpu_policy(char **args, int section_type, struct proxy *cur
        for (i = 0; ha_cpu_policy[i].name; i++) {
                if (strcmp(args[1], ha_cpu_policy[i].name) == 0) {
                        cpu_policy_conf.cpu_policy = i;
+                       cpu_policy_conf.flags |= CPU_POLICY_SET_IN_CONFIG;
                        return 0;
                }
        }