]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads: add a MAX_THREADS define instead of LONGBITS
authorWilly Tarreau <w@1wt.eu>
Sat, 20 Jan 2018 17:19:22 +0000 (18:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 23 Jan 2018 14:28:20 +0000 (15:28 +0100)
This one allows not to inflate some structures when threads are
disabled. Now struct global is 1.4 kB instead of 33 kB.

Should be backported to 1.8 for ease of backporting of upcoming
patches.

include/common/hathreads.h
include/types/global.h
src/cfgparse.c
src/haproxy.c
src/listener.c

index 5f0b9695445dc07bfa2e39bd9f6d94a6b08ad2f2..f8195368620cbf0cba28de6d00ede8ee0b50f610 100644 (file)
@@ -30,6 +30,8 @@ extern THREAD_LOCAL unsigned long tid_bit; /* The bit corresponding to the threa
 
 #ifndef USE_THREAD
 
+#define MAX_THREADS 1
+
 #define __decl_hathreads(decl)
 
 #define HA_ATOMIC_CAS(val, old, new) ({((*val) == (*old)) ? (*(val) = (new) , 1) : (*(old) = *(val), 0);})
@@ -95,6 +97,8 @@ extern THREAD_LOCAL unsigned long tid_bit; /* The bit corresponding to the threa
 #include <pthread.h>
 #include <import/plock.h>
 
+#define MAX_THREADS LONGBITS
+
 #define __decl_hathreads(decl) decl
 
 /* TODO: thread: For now, we rely on GCC builtins but it could be a good idea to
index 6f3fedc3364db1d7bf677af6871d5104b39bfe2e..5c5cf732e0f024d755ad690d8619ba6a52d1735e 100644 (file)
@@ -168,7 +168,7 @@ struct global {
 #ifdef USE_CPU_AFFINITY
        struct {
                unsigned long proc[LONGBITS];             /* list of CPU masks for the 32/64 first processes */
-               unsigned long thread[LONGBITS][LONGBITS]; /* list of CPU masks for the 32/64 first threads per process */
+               unsigned long thread[LONGBITS][MAX_THREADS]; /* list of CPU masks for the 32/64 first threads per process */
        } cpu_map;
 #endif
 };
index baf9e60f749b7da783afdb60fc5a8136287b0a1c..eea820aa5f4b43d8ba76a0899759e26bb26de73c 100644 (file)
@@ -1175,12 +1175,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
                global.nbthread = atol(args[1]);
-               if (global.nbthread < 1 || global.nbthread > LONGBITS) {
-                       ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n",
-                                file, linenum, args[0], LONGBITS, global.nbthread);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
 #ifndef USE_THREAD
                if (global.nbthread > 1) {
                        ha_alert("HAProxy is not compiled with threads support, please check build options for USE_THREAD.\n");
@@ -1189,6 +1183,12 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 #endif
+               if (global.nbthread < 1 || global.nbthread > MAX_THREADS) {
+                       ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n",
+                                file, linenum, args[0], MAX_THREADS, global.nbthread);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
        }
        else if (!strcmp(args[0], "maxconn")) {
                if (alertif_too_many_args(1, file, linenum, args, &err_code))
@@ -1801,7 +1801,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        }
 
                        /* Mapping at the thread level */
-                       for (j = 0; j < LONGBITS; j++) {
+                       for (j = 0; j < MAX_THREADS; j++) {
                                /* Np mapping for this thread */
                                if (!(thread & (1UL << j)))
                                        continue;
index 20b18f8541778d77f545406fca50ad249cd5a5bb..a8d0fad87fe6619f5be282d2fac4704dbe449d35 100644 (file)
@@ -2986,7 +2986,7 @@ int main(int argc, char **argv)
                        if (global.cpu_map.proc[relative_pid-1])
                                global.cpu_map.thread[relative_pid-1][i] &= global.cpu_map.proc[relative_pid-1];
 
-                       if (i < LONGBITS &&       /* 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 */
 #if defined(__FreeBSD__) || defined(__NetBSD__)
                                cpuset_t cpuset;
index dfd36cca34d1f14ed620a519a1b9b9f64544bba4..fd70726846e5db7d7eb3f913330dfd8420b29f24 100644 (file)
@@ -963,7 +963,7 @@ static int bind_parse_process(char **args, int cur_arg, struct proxy *px, struct
 
        conf->bind_proc |= proc;
        if (thread) {
-               for (i = 0; i < LONGBITS; i++)
+               for (i = 0; i < MAX_THREADS; i++)
                        if (!proc || (proc & (1UL << i)))
                                conf->bind_thread[i] |= thread;
        }