ifneq ($(USE_CPU_AFFINITY:0=),)
OPTIONS_OBJS += src/cpuset.o
+ OPTIONS_OBJS += src/cpu_topo.o
endif
# OpenSSL is packaged in various forms and with various dependencies.
--- /dev/null
+#ifndef _HAPROXY_CPU_TOPO_H
+#define _HAPROXY_CPU_TOPO_H
+
+#include <haproxy/api.h>
+#include <haproxy/cpuset.h>
+#include <haproxy/cpu_topo-t.h>
+
+extern struct ha_cpu_topo *ha_cpu_topo;
+
+#endif /* _HAPROXY_CPU_TOPO_H */
--- /dev/null
+#define _GNU_SOURCE
+
+#include <haproxy/api.h>
+#include <haproxy/cpu_topo.h>
+
+/* CPU topology information, ha_cpuset_size() entries, allocated at boot */
+struct ha_cpu_topo *ha_cpu_topo = NULL;
+
+/* Allocates everything needed to store CPU topology at boot.
+ * Returns non-zero on success, zero on failure.
+ */
+static int cpu_topo_alloc(void)
+{
+ int maxcpus = ha_cpuset_size();
+ int cpu;
+
+ /* allocate the structures used to store CPU topology info */
+ ha_cpu_topo = (struct ha_cpu_topo*)malloc(maxcpus * sizeof(*ha_cpu_topo));
+ if (!ha_cpu_topo)
+ return 0;
+
+ /* preset all fields to -1 except the index and the state flags which
+ * are assumed to all be bound and online unless detected otherwise.
+ */
+ for (cpu = 0; cpu < maxcpus; cpu++) {
+ memset(&ha_cpu_topo[cpu], 0xff, sizeof(*ha_cpu_topo));
+ ha_cpu_topo[cpu].st = 0;
+ ha_cpu_topo[cpu].idx = cpu;
+ }
+
+ return 1;
+}
+
+static void cpu_topo_deinit(void)
+{
+ ha_free(&ha_cpu_topo);
+}
+
+INITCALL0(STG_ALLOC, cpu_topo_alloc);
+REGISTER_POST_DEINIT(cpu_topo_deinit);