From: Willy Tarreau Date: Thu, 28 May 2026 15:41:18 +0000 (+0200) Subject: MINOR: cpu-topo: notify when cpu-policy is ignored due to other settings X-Git-Tag: v3.4.0~54 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dad00a7442c1dbb0d859956379814aa32f1ae700;p=thirdparty%2Fhaproxy.git MINOR: cpu-topo: notify when cpu-policy is ignored due to other settings 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. --- diff --git a/src/cpu_topo.c b/src/cpu_topo.c index a9ba92fb5..b14e69fae 100644 --- a/src/cpu_topo.c +++ b/src/cpu_topo.c @@ -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; } }