mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-05 22:56:57 +02:00
MINOR: cpu-topo: allocate and initialize the ha_cpu_topo array.
This does the bare minimum to allocate and initialize a global ha_cpu_topo array for the number of supported CPUs and release it at deinit time.
This commit is contained in:
parent
d165f5d3ab
commit
656cedad42
1
Makefile
1
Makefile
@ -596,6 +596,7 @@ endif
|
||||
|
||||
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.
|
||||
|
10
include/haproxy/cpu_topo.h
Normal file
10
include/haproxy/cpu_topo.h
Normal file
@ -0,0 +1,10 @@
|
||||
#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 */
|
40
src/cpu_topo.c
Normal file
40
src/cpu_topo.c
Normal file
@ -0,0 +1,40 @@
|
||||
#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);
|
Loading…
Reference in New Issue
Block a user