]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: vars: move the "proc" scope variables out of the global struct
authorWilly Tarreau <w@1wt.eu>
Sat, 8 May 2021 09:41:28 +0000 (11:41 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 8 May 2021 10:11:29 +0000 (12:11 +0200)
The presence of this field causes a long dependency chain because almost
everyone includes global-t.h, and vars include sample_data which include
some system includes as well as HTTP parts.

There is absolutely no reason for having the process-wide variables in
the global struct, let's just move them into vars.c and vars.h. This
reduces from ~190k to ~170k the preprocessed output of version.c.

addons/ot/src/vars.c
include/haproxy/global-t.h
include/haproxy/global.h
include/haproxy/vars.h
src/haproxy.c
src/vars.c

index 0db55141f7a7693759caad68ed16c5198cc7ac32..fff54acac568b4646ff42d90df1c9a840f9e63f1 100644 (file)
@@ -72,7 +72,7 @@ void flt_ot_vars_dump(struct stream *s)
         * source here to get the value of the 'vars' pointer, but it is defined
         * as 'static inline', so unfortunately none of this is possible.
         */
-       flt_ot_vars_scope_dump(&(global.vars), "PROC");
+       flt_ot_vars_scope_dump(&(proc_vars), "PROC");
        flt_ot_vars_scope_dump(&(s->sess->vars), "SESS");
        flt_ot_vars_scope_dump(&(s->vars_txn), "TXN");
        flt_ot_vars_scope_dump(&(s->vars_reqres), "REQ/RES");
@@ -102,7 +102,7 @@ static inline struct vars *flt_ot_get_vars(struct stream *s, const char *scope)
        struct vars *retptr = NULL;
 
        if (strcasecmp(scope, "proc") == 0)
-               retptr = &(global.vars);
+               retptr = &(proc_vars);
        else if (strcasecmp(scope, "sess") == 0)
                retptr = (&(s->sess->vars));
        else if (strcasecmp(scope, "txn") == 0)
index 8df1349aaf90b35e7a064bdd088fefe70cc4f24d..1bdbc1bbc49476e913af184921945750b8f692f3 100644 (file)
@@ -25,7 +25,6 @@
 #include <haproxy/api-t.h>
 #include <haproxy/buf-t.h>
 #include <haproxy/freq_ctr-t.h>
-#include <haproxy/vars-t.h>
 
 /* modes of operation (global.mode) */
 #define        MODE_DEBUG      0x01
@@ -186,7 +185,6 @@ struct global {
        unsigned int shctx_lookups, shctx_misses;
        unsigned int req_count; /* request counter (HTTP or TCP session) for logs and unique_id */
        int last_checks;
-       struct vars   vars;         /* list of variables for the process scope. */
 
        /* leave this at the end to make sure we don't share this cache line by accident */
        ALWAYS_ALIGN(64);
index 2ff7b5d017f38978b70398365c7e21b73e3e8887..1c50abaaa8688ca01fa72a13af675a5681d8b941 100644 (file)
@@ -25,7 +25,6 @@
 #include <haproxy/api-t.h>
 #include <haproxy/global-t.h>
 #include <haproxy/mworker-t.h>
-#include <haproxy/vars-t.h>
 
 extern const char *build_features;
 extern struct global global;
index aeb218a72d2386849a66a45a067d6f3143308da9..f809c62d5bf066300342fad510eb1aa36aa3b4b3 100644 (file)
@@ -27,6 +27,8 @@
 #include <haproxy/stream-t.h>
 #include <haproxy/vars-t.h>
 
+extern struct vars proc_vars;
+
 void vars_init(struct vars *vars, enum vars_scope scope);
 void var_accounting_diff(struct vars *vars, struct session *sess, struct stream *strm, int size);
 unsigned int var_clear(struct var *var);
index 76fe08cfb9dd54170ee535617e074a7a3899cd34..3de53bfceb114ed5e67d794da69e53b501964e2d 100644 (file)
@@ -1521,7 +1521,7 @@ static void init(int argc, char **argv)
        hlua_init();
 
        /* Initialize process vars */
-       vars_init(&global.vars, SCOPE_PROC);
+       vars_init(&proc_vars, SCOPE_PROC);
 
        global.tune.options |= GTUNE_USE_SELECT;  /* select() is always available */
 #if defined(USE_POLL)
@@ -2553,7 +2553,7 @@ void deinit(void)
                free(tff);
        }
 
-       vars_prune(&global.vars, NULL, NULL);
+       vars_prune(&proc_vars, NULL, NULL);
        pool_destroy_all();
        deinit_pollers();
 } /* end deinit() */
index 202a9aec0de2bef65b203715fdea60b1180debc3..572b5f56fe3c35ecdb075da07cdf5807cdbe3b81 100644 (file)
@@ -21,6 +21,9 @@
 /* This contains a pool of struct vars */
 DECLARE_STATIC_POOL(var_pool, "vars", sizeof(struct var));
 
+/* list of variables for the process scope. */
+struct vars proc_vars THREAD_ALIGNED(64);
+
 /* This array contain all the names of all the HAProxy vars.
  * This permits to identify two variables name with
  * only one pointer. It permits to not using  strdup() for
@@ -47,7 +50,7 @@ static inline struct vars *get_vars(struct session *sess, struct stream *strm, e
 {
        switch (scope) {
        case SCOPE_PROC:
-               return &global.vars;
+               return &proc_vars;
        case SCOPE_SESS:
                return sess ? &sess->vars : NULL;
        case SCOPE_CHECK: {
@@ -91,7 +94,7 @@ scope_sess:
                _HA_ATOMIC_ADD(&sess->vars.size, size);
                /* fall through */
        case SCOPE_PROC:
-               _HA_ATOMIC_ADD(&global.vars.size, size);
+               _HA_ATOMIC_ADD(&proc_vars.size, size);
                _HA_ATOMIC_ADD(&var_global_size, size);
        }
 }
@@ -128,7 +131,7 @@ scope_sess:
                        return 0;
                /* fall through */
        case SCOPE_PROC:
-               if (var_proc_limit && global.vars.size + size > var_proc_limit)
+               if (var_proc_limit && proc_vars.size + size > var_proc_limit)
                        return 0;
                if (var_global_limit && var_global_size + size > var_global_limit)
                        return 0;
@@ -187,7 +190,7 @@ void vars_prune_per_sess(struct vars *vars)
        HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock);
 
        _HA_ATOMIC_SUB(&vars->size, size);
-       _HA_ATOMIC_SUB(&global.vars.size, size);
+       _HA_ATOMIC_SUB(&proc_vars.size, size);
        _HA_ATOMIC_SUB(&var_global_size, size);
 }