From 00876511287184e5c0ae14d37f2f99261da0ef27 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Tue, 3 Mar 2026 16:50:18 +0100 Subject: [PATCH] MINOR: counters: Introduce COUNTERS_UPDATE_MAX() 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 | 5 +++++ include/haproxy/proxy.h | 9 +++++---- include/haproxy/server.h | 3 ++- src/backend.c | 2 +- src/listener.c | 14 +++++++------- src/proxy.c | 2 +- src/stream.c | 16 ++++++++-------- 7 files changed, 29 insertions(+), 22 deletions(-) diff --git a/include/haproxy/counters.h b/include/haproxy/counters.h index b536215a7..6850e7b84 100644 --- a/include/haproxy/counters.h +++ b/include/haproxy/counters.h @@ -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) \ diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index 5b73b25d4..7a8a15519 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -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)); } diff --git a/include/haproxy/server.h b/include/haproxy/server.h index cffc400db..6294bf246 100644 --- a/include/haproxy/server.h +++ b/include/haproxy/server.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -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)); } diff --git a/src/backend.c b/src/backend.c index 109fba3aa..2034b2dd3 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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); } diff --git a/src/listener.c b/src/listener.c index 5b5d0f2fa..4f35878b5 100644 --- a/src/listener.c +++ b/src/listener.c @@ -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 diff --git a/src/proxy.c b/src/proxy.c index ab0543827..21002b8ae 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -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); diff --git a/src/stream.c b/src/stream.c index 3a0c6b806..daf2fc3b1 100644 --- a/src/stream.c +++ b/src/stream.c @@ -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); } /*