MINOR: cfgparse: use hap_cpuset for parse_cpu_set
Replace the unsigned long parameter by a hap_cpuset. This allows to
address CPU with index greater than LONGBITS.
This function is used to parse the 'cpu-map' statement. However at the
moment, the result is casted back to a long to store it in the global
structure. The next step is to replace ulong in in cpu_map in the
global structure with hap_cpuset.
diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c
index c26c086..40f3018 100644
--- a/src/cfgparse-global.c
+++ b/src/cfgparse-global.c
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE /* for CPU_* from cpuset.h */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -13,6 +14,7 @@
#include <haproxy/buf.h>
#include <haproxy/cfgparse.h>
+#include <haproxy/cpuset.h>
#include <haproxy/compression.h>
#include <haproxy/global.h>
#include <haproxy/log.h>
@@ -1027,7 +1029,8 @@
#ifdef USE_CPU_AFFINITY
char *slash;
unsigned long proc = 0, thread = 0, cpus;
- int i, j, n, autoinc;
+ int i, j, n, k, autoinc;
+ struct hap_cpuset cpuset;
if (!*args[1] || !*args[2]) {
ha_alert("parsing [%s:%d] : %s expects a process number "
@@ -1068,12 +1071,23 @@
}
}
- if (parse_cpu_set((const char **)args+2, &cpus, &errmsg)) {
+ if (parse_cpu_set((const char **)args+2, &cpuset, &errmsg)) {
ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
-
+#if defined(CPUSET_USE_CPUSET)
+ k = 0;
+ while (CPU_COUNT(&cpuset.cpuset)) {
+ while (!CPU_ISSET(k, &cpuset.cpuset))
+ ++k;
+ cpus |= 1 << k;
+ CPU_CLR(k, &cpuset.cpuset);
+ ++k;
+ }
+#elif defined(CPUSET_USE_ULONG)
+ cpus = cpuset.cpuset;
+#endif
if (autoinc &&
my_popcountl(proc) != my_popcountl(cpus) &&
my_popcountl(thread) != my_popcountl(cpus)) {