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.
This commit is contained in:
Olivier Houchard 2026-03-03 16:50:18 +01:00 committed by Olivier Houchard
parent 65d3416da5
commit 0087651128
7 changed files with 29 additions and 22 deletions

View 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) \

View 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));
}

View 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));
}

View 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);
}

View 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

View 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);

View 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);
}
/*