diff --git a/include/haproxy/cpuset.h b/include/haproxy/cpuset.h index 78c4df270..e4811bcd6 100644 --- a/include/haproxy/cpuset.h +++ b/include/haproxy/cpuset.h @@ -3,7 +3,7 @@ #include -extern struct cpu_map cpu_map[MAX_TGROUPS]; +extern struct cpu_map *cpu_map; /* Unset all indexes in . */ diff --git a/src/cpuset.c b/src/cpuset.c index 73b97b975..3ce6cf223 100644 --- a/src/cpuset.c +++ b/src/cpuset.c @@ -5,7 +5,7 @@ #include #include -struct cpu_map cpu_map[MAX_TGROUPS]; +struct cpu_map *cpu_map; void ha_cpuset_zero(struct hap_cpuset *set) { @@ -185,3 +185,24 @@ int cpu_map_configured(void) } return 0; } + +/* Allocates everything needed to store CPU information at boot. + * Returns non-zero on success, zero on failure. + */ +static int cpuset_alloc(void) +{ + /* allocate the structures used to store CPU topology info */ + cpu_map = (struct cpu_map*)calloc(MAX_TGROUPS, sizeof(*cpu_map)); + if (!cpu_map) + return 0; + + return 1; +} + +static void cpuset_deinit(void) +{ + ha_free(&cpu_map); +} + +INITCALL0(STG_ALLOC, cpuset_alloc); +REGISTER_POST_DEINIT(cpuset_deinit); diff --git a/src/haproxy.c b/src/haproxy.c index 18308bc59..383d1e47d 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1530,19 +1530,6 @@ static void init_early(int argc, char **argv) exit(EXIT_FAILURE); } - /* Some CPU affinity stuff may have to be initialized */ -#ifdef USE_CPU_AFFINITY - { - int g, i; - - for (g = 0; g < MAX_TGROUPS; g++) { - for (i = 0; i < MAX_THREADS_PER_GROUP; ++i) { - ha_cpuset_zero(&cpu_map[g].thread[i]); - } - } - } -#endif - /* extract the program name from argv[0], it will be used for the logs * and error messages. */