]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: counters: Introduce COUNTERS_UPDATE_MAX()
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 3 Mar 2026 15:50:18 +0000 (16:50 +0100)
committerOlivier Houchard <cognet@ci0.org>
Thu, 5 Mar 2026 14:39:42 +0000 (15:39 +0100)
Introduce COUNTERS_UPDATE_MAX(), and use it instead of using
HA_ATOMIC_UPDATE_MAX() directly.
For now it just calls HA_ATOMIC_UPDATE_MAX(), but will later be modified
so that we can disable max calculation.
This can be backported up to 2.8 if the usage of COUNTERS_UPDATE_MAX()
generates too many conflicts.

include/haproxy/counters.h
include/haproxy/proxy.h
include/haproxy/server.h
src/backend.c
src/listener.c
src/proxy.c
src/stream.c

index b536215a75033e2bad7cb5c9d1b1a90858257425..6850e7b84d42a2eb43d1ab461176c20265f96e61 100644 (file)
@@ -103,6 +103,11 @@ void counters_be_shared_drop(struct be_counters_shared *counters);
        __ret;                                                                \
 })
 
+#define COUNTERS_UPDATE_MAX(counter, count)                                   \
+       do {                                                                  \
+               HA_ATOMIC_UPDATE_MAX(counter, count);                         \
+       } while (0)
+
 /* Manipulation of extra_counters, for boot-time registrable modules */
 /* retrieve the base storage of extra counters (first tgroup if any) */
 #define EXTRA_COUNTERS_BASE(counters, mod) \
index 5b73b25d4015dfd2678b8c3d025429ba20120405..7a8a155198dd56d50e83a27c3d520ce22e5fb4d6 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <haproxy/api.h>
 #include <haproxy/applet-t.h>
+#include <haproxy/counters.h>
 #include <haproxy/freq_ctr.h>
 #include <haproxy/list.h>
 #include <haproxy/listener-t.h>
@@ -181,7 +182,7 @@ static inline void proxy_inc_fe_conn_ctr(struct listener *l, struct proxy *fe)
        }
        if (l && l->counters && l->counters->shared.tg)
                _HA_ATOMIC_INC(&l->counters->shared.tg[tgid - 1]->cum_conn);
-       HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.cps_max,
+       COUNTERS_UPDATE_MAX(&fe->fe_counters.cps_max,
                             update_freq_ctr(&fe->fe_counters._conn_per_sec, 1));
 }
 
@@ -194,7 +195,7 @@ static inline void proxy_inc_fe_sess_ctr(struct listener *l, struct proxy *fe)
        }
        if (l && l->counters && l->counters->shared.tg)
                _HA_ATOMIC_INC(&l->counters->shared.tg[tgid - 1]->cum_sess);
-       HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.sps_max,
+       COUNTERS_UPDATE_MAX(&fe->fe_counters.sps_max,
                             update_freq_ctr(&fe->fe_counters._sess_per_sec, 1));
 }
 
@@ -221,7 +222,7 @@ static inline void proxy_inc_be_ctr(struct proxy *be)
                _HA_ATOMIC_INC(&be->be_counters.shared.tg[tgid - 1]->cum_sess);
                update_freq_ctr(&be->be_counters.shared.tg[tgid - 1]->sess_per_sec, 1);
        }
-       HA_ATOMIC_UPDATE_MAX(&be->be_counters.sps_max,
+       COUNTERS_UPDATE_MAX(&be->be_counters.sps_max,
                             update_freq_ctr(&be->be_counters._sess_per_sec, 1));
 }
 
@@ -241,7 +242,7 @@ static inline void proxy_inc_fe_req_ctr(struct listener *l, struct proxy *fe,
        }
        if (l && l->counters && l->counters->shared.tg)
                _HA_ATOMIC_INC(&l->counters->shared.tg[tgid - 1]->p.http.cum_req[http_ver]);
-       HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.p.http.rps_max,
+       COUNTERS_UPDATE_MAX(&fe->fe_counters.p.http.rps_max,
                             update_freq_ctr(&fe->fe_counters.p.http._req_per_sec, 1));
 }
 
index cffc400dbc264c97fae4e088fb1155095a3ecf84..6294bf246f8ea03aed4fdc6e4216d754f0f72aa2 100644 (file)
@@ -29,6 +29,7 @@
 #include <haproxy/api.h>
 #include <haproxy/applet-t.h>
 #include <haproxy/arg-t.h>
+#include <haproxy/counters.h>
 #include <haproxy/freq_ctr.h>
 #include <haproxy/proxy-t.h>
 #include <haproxy/resolvers-t.h>
@@ -212,7 +213,7 @@ static inline void srv_inc_sess_ctr(struct server *s)
                _HA_ATOMIC_INC(&s->counters.shared.tg[tgid - 1]->cum_sess);
                update_freq_ctr(&s->counters.shared.tg[tgid - 1]->sess_per_sec, 1);
        }
-       HA_ATOMIC_UPDATE_MAX(&s->counters.sps_max,
+       COUNTERS_UPDATE_MAX(&s->counters.sps_max,
                             update_freq_ctr(&s->counters._sess_per_sec, 1));
 }
 
index 109fba3aa785db6939c35c36e0261f5b41a4ea23..2034b2dd39987446a807b76f14b6b62f50bae0af 100644 (file)
@@ -2266,7 +2266,7 @@ int connect_server(struct stream *s)
 
                s->flags |= SF_CURR_SESS;
                count = _HA_ATOMIC_ADD_FETCH(&srv->cur_sess, 1);
-               HA_ATOMIC_UPDATE_MAX(&srv->counters.cur_sess_max, count);
+               COUNTERS_UPDATE_MAX(&srv->counters.cur_sess_max, count);
                if (s->be->lbprm.server_take_conn)
                        s->be->lbprm.server_take_conn(srv);
        }
index 5b5d0f2fae963f5478149c70ce2491791686db76..4f35878b5edca04423b48de38e1409c86c820ab6 100644 (file)
@@ -172,10 +172,10 @@ struct task *accept_queue_process(struct task *t, void *context, unsigned int st
                 * connection.
                 */
                if (!(li->bind_conf->options & BC_O_UNLIMITED)) {
-                       HA_ATOMIC_UPDATE_MAX(&global.sps_max,
+                       COUNTERS_UPDATE_MAX(&global.sps_max,
                                             update_freq_ctr(&global.sess_per_sec, 1));
                        if (li->bind_conf->options & BC_O_USE_SSL) {
-                               HA_ATOMIC_UPDATE_MAX(&global.ssl_max,
+                               COUNTERS_UPDATE_MAX(&global.ssl_max,
                                                     update_freq_ctr(&global.ssl_per_sec, 1));
                        }
                }
@@ -1227,16 +1227,16 @@ void listener_accept(struct listener *l)
 
                /* The connection was accepted, it must be counted as such */
                if (l->counters)
-                       HA_ATOMIC_UPDATE_MAX(&l->counters->conn_max, next_conn);
+                       COUNTERS_UPDATE_MAX(&l->counters->conn_max, next_conn);
 
                if (p) {
-                       HA_ATOMIC_UPDATE_MAX(&p->fe_counters.conn_max, next_feconn);
+                       COUNTERS_UPDATE_MAX(&p->fe_counters.conn_max, next_feconn);
                        proxy_inc_fe_conn_ctr(l, p);
                }
 
                if (!(l->bind_conf->options & BC_O_UNLIMITED)) {
                        count = update_freq_ctr(&global.conn_per_sec, 1);
-                       HA_ATOMIC_UPDATE_MAX(&global.cps_max, count);
+                       COUNTERS_UPDATE_MAX(&global.cps_max, count);
                }
 
                _HA_ATOMIC_INC(&activity[tid].accepted);
@@ -1575,13 +1575,13 @@ void listener_accept(struct listener *l)
                 */
                if (!(l->bind_conf->options & BC_O_UNLIMITED)) {
                        count = update_freq_ctr(&global.sess_per_sec, 1);
-                       HA_ATOMIC_UPDATE_MAX(&global.sps_max, count);
+                       COUNTERS_UPDATE_MAX(&global.sps_max, count);
                }
 #ifdef USE_OPENSSL
                if (!(l->bind_conf->options & BC_O_UNLIMITED) &&
                    l->bind_conf && l->bind_conf->options & BC_O_USE_SSL) {
                        count = update_freq_ctr(&global.ssl_per_sec, 1);
-                       HA_ATOMIC_UPDATE_MAX(&global.ssl_max, count);
+                       COUNTERS_UPDATE_MAX(&global.ssl_max, count);
                }
 #endif
 
index ab054382745bea98f77a4d3d9db1e3ccb9351d4f..21002b8aeda62593099ccb7d1d2faa906e5aafc6 100644 (file)
@@ -4120,7 +4120,7 @@ int stream_set_backend(struct stream *s, struct proxy *be)
        else
                s->be_tgcounters = NULL;
 
-       HA_ATOMIC_UPDATE_MAX(&be->be_counters.conn_max,
+       COUNTERS_UPDATE_MAX(&be->be_counters.conn_max,
                             HA_ATOMIC_ADD_FETCH(&be->beconn, 1));
        proxy_inc_be_ctr(be);
 
index 3a0c6b806ad371cb6591a80ab476428c0be5937e..daf2fc3b1aa8b321cee57361ca4c38828a172a68 100644 (file)
@@ -2834,10 +2834,10 @@ void stream_update_time_stats(struct stream *s)
                swrate_add_dynamic(&srv->counters.c_time, samples_window, t_connect);
                swrate_add_dynamic(&srv->counters.d_time, samples_window, t_data);
                swrate_add_dynamic(&srv->counters.t_time, samples_window, t_close);
-               HA_ATOMIC_UPDATE_MAX(&srv->counters.qtime_max, t_queue);
-               HA_ATOMIC_UPDATE_MAX(&srv->counters.ctime_max, t_connect);
-               HA_ATOMIC_UPDATE_MAX(&srv->counters.dtime_max, t_data);
-               HA_ATOMIC_UPDATE_MAX(&srv->counters.ttime_max, t_close);
+               COUNTERS_UPDATE_MAX(&srv->counters.qtime_max, t_queue);
+               COUNTERS_UPDATE_MAX(&srv->counters.ctime_max, t_connect);
+               COUNTERS_UPDATE_MAX(&srv->counters.dtime_max, t_data);
+               COUNTERS_UPDATE_MAX(&srv->counters.ttime_max, t_close);
        }
        if (s->be_tgcounters)
                samples_window = (((s->be->mode == PR_MODE_HTTP) ?
@@ -2848,10 +2848,10 @@ void stream_update_time_stats(struct stream *s)
        swrate_add_dynamic(&s->be->be_counters.c_time, samples_window, t_connect);
        swrate_add_dynamic(&s->be->be_counters.d_time, samples_window, t_data);
        swrate_add_dynamic(&s->be->be_counters.t_time, samples_window, t_close);
-       HA_ATOMIC_UPDATE_MAX(&s->be->be_counters.qtime_max, t_queue);
-       HA_ATOMIC_UPDATE_MAX(&s->be->be_counters.ctime_max, t_connect);
-       HA_ATOMIC_UPDATE_MAX(&s->be->be_counters.dtime_max, t_data);
-       HA_ATOMIC_UPDATE_MAX(&s->be->be_counters.ttime_max, t_close);
+       COUNTERS_UPDATE_MAX(&s->be->be_counters.qtime_max, t_queue);
+       COUNTERS_UPDATE_MAX(&s->be->be_counters.ctime_max, t_connect);
+       COUNTERS_UPDATE_MAX(&s->be->be_counters.dtime_max, t_data);
+       COUNTERS_UPDATE_MAX(&s->be->be_counters.ttime_max, t_close);
 }
 
 /*