mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-08 08:07:10 +02:00
MINOR: threads: flatten the per-thread cpu-map
When we initially experimented with threads and processes support, we needed to implement arrays of threads per process for cpu-map, but this is not needed anymore since we support either threads or processes. Let's simply make the thread-based cpu-map per thread and not per thread and per process since that's not used anymore. Doing so reduces the global struct from 33kB to 1.5kB.
This commit is contained in:
parent
a48237fd07
commit
81492c989c
@ -179,8 +179,8 @@ struct global {
|
|||||||
struct vars vars; /* list of variables for the process scope. */
|
struct vars vars; /* list of variables for the process scope. */
|
||||||
#ifdef USE_CPU_AFFINITY
|
#ifdef USE_CPU_AFFINITY
|
||||||
struct {
|
struct {
|
||||||
unsigned long proc[MAX_PROCS]; /* list of CPU masks for the 32/64 first processes */
|
unsigned long proc[MAX_PROCS]; /* list of CPU masks for the 32/64 first processes */
|
||||||
unsigned long thread[MAX_PROCS][MAX_THREADS]; /* list of CPU masks for the 32/64 first threads per process */
|
unsigned long thread[MAX_THREADS]; /* list of CPU masks for the 32/64 first threads */
|
||||||
} cpu_map;
|
} cpu_map;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -1009,33 +1009,34 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = n = 0; i < MAX_PROCS; i++) {
|
if (atleast2(proc)) {
|
||||||
/* No mapping for this process */
|
|
||||||
if (!(proc & (1UL << i)))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* Mapping at the process level */
|
/* Mapping at the process level */
|
||||||
if (!thread) {
|
for (i = n = 0; i < MAX_PROCS; i++) {
|
||||||
|
/* No mapping for this process */
|
||||||
|
if (!(proc & (1UL << i)))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (!autoinc)
|
if (!autoinc)
|
||||||
global.cpu_map.proc[i] = cpus;
|
global.cpu_map.proc[i] = cpus;
|
||||||
else {
|
else {
|
||||||
n += my_ffsl(cpus >> n);
|
n += my_ffsl(cpus >> n);
|
||||||
global.cpu_map.proc[i] = (1UL << (n-1));
|
global.cpu_map.proc[i] = (1UL << (n-1));
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (atleast2(thread)) {
|
||||||
/* Mapping at the thread level */
|
/* Mapping at the thread level */
|
||||||
for (j = 0; j < MAX_THREADS; j++) {
|
for (j = n = 0; j < MAX_THREADS; j++) {
|
||||||
/* Np mapping for this thread */
|
/* No mapping for this thread */
|
||||||
if (!(thread & (1UL << j)))
|
if (!(thread & (1UL << j)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!autoinc)
|
if (!autoinc)
|
||||||
global.cpu_map.thread[i][j] = cpus;
|
global.cpu_map.thread[j] = cpus;
|
||||||
else {
|
else {
|
||||||
n += my_ffsl(cpus >> n);
|
n += my_ffsl(cpus >> n);
|
||||||
global.cpu_map.thread[i][j] = (1UL << (n-1));
|
global.cpu_map.thread[j] = (1UL << (n-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3152,17 +3152,17 @@ int main(int argc, char **argv)
|
|||||||
/* Now the CPU affinity for all threads */
|
/* Now the CPU affinity for all threads */
|
||||||
for (i = 0; i < global.nbthread; i++) {
|
for (i = 0; i < global.nbthread; i++) {
|
||||||
if (global.cpu_map.proc[relative_pid-1])
|
if (global.cpu_map.proc[relative_pid-1])
|
||||||
global.cpu_map.thread[relative_pid-1][i] &= global.cpu_map.proc[relative_pid-1];
|
global.cpu_map.thread[i] &= global.cpu_map.proc[relative_pid-1];
|
||||||
|
|
||||||
if (i < MAX_THREADS && /* only the first 32/64 threads may be pinned */
|
if (i < MAX_THREADS && /* only the first 32/64 threads may be pinned */
|
||||||
global.cpu_map.thread[relative_pid-1][i]) {/* only do this if the thread has a THREAD map */
|
global.cpu_map.thread[i]) {/* only do this if the thread has a THREAD map */
|
||||||
#if defined(__FreeBSD__) || defined(__NetBSD__)
|
#if defined(__FreeBSD__) || defined(__NetBSD__)
|
||||||
cpuset_t cpuset;
|
cpuset_t cpuset;
|
||||||
#else
|
#else
|
||||||
cpu_set_t cpuset;
|
cpu_set_t cpuset;
|
||||||
#endif
|
#endif
|
||||||
int j;
|
int j;
|
||||||
unsigned long cpu_map = global.cpu_map.thread[relative_pid-1][i];
|
unsigned long cpu_map = global.cpu_map.thread[i];
|
||||||
|
|
||||||
CPU_ZERO(&cpuset);
|
CPU_ZERO(&cpuset);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user