From de0eddf5120c71a3e6c5326d20a45cf55ba0d381 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 25 Feb 2026 10:13:21 +0100 Subject: [PATCH] MINOR: counters: add EXTRA_COUNTERS_BASE() to retrieve extra_counters base storage The goal is to always retrieve the storage address of the first thread group for the given module. This will be used to iterate over all thread groups. For now it returns the same value as EXTRA_COUNTERS_GET(). --- include/haproxy/counters.h | 6 ++++++ src/h3_stats.c | 2 +- src/mux_h1.c | 2 +- src/mux_h2.c | 2 +- src/quic_stats.c | 2 +- src/resolvers.c | 2 +- src/ssl_sock.c | 2 +- 7 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/haproxy/counters.h b/include/haproxy/counters.h index 5fbe94d6f..26d2ebe53 100644 --- a/include/haproxy/counters.h +++ b/include/haproxy/counters.h @@ -104,6 +104,12 @@ void counters_be_shared_drop(struct be_counters_shared *counters); }) /* 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) \ + (likely(counters) ? \ + ((void *)(*(counters)->datap + (mod)->counters_off[(counters)->type])) : \ + (trash_counters)) + #define EXTRA_COUNTERS_GET(counters, mod) \ (likely(counters) ? \ ((void *)(*(counters)->datap + (mod)->counters_off[(counters)->type])) : \ diff --git a/src/h3_stats.c b/src/h3_stats.c index f82c70422..16453f25d 100644 --- a/src/h3_stats.c +++ b/src/h3_stats.c @@ -141,7 +141,7 @@ static int h3_fill_stats(struct stats_module *mod, struct extra_counters *ctr, if (!ctr) goto store_metric; - counters = EXTRA_COUNTERS_GET(ctr, mod); + counters = EXTRA_COUNTERS_BASE(ctr, mod); switch (current_field) { /* h3 frame type counters */ diff --git a/src/mux_h1.c b/src/mux_h1.c index b37d2b692..94a773c71 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -284,7 +284,7 @@ static int h1_fill_stats(struct stats_module *mod, struct extra_counters *ctr, if (!ctr) goto store_metric; - counters = EXTRA_COUNTERS_GET(ctr, mod); + counters = EXTRA_COUNTERS_BASE(ctr, mod); switch (current_field) { case H1_ST_OPEN_CONN: diff --git a/src/mux_h2.c b/src/mux_h2.c index fdbf9613b..21d615528 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -383,7 +383,7 @@ static int h2_fill_stats(struct stats_module *mod, struct extra_counters *ctr, if (!ctr) goto store_metric; - counters = EXTRA_COUNTERS_GET(ctr, mod); + counters = EXTRA_COUNTERS_BASE(ctr, mod); switch (current_field) { case H2_ST_HEADERS_RCVD: diff --git a/src/quic_stats.c b/src/quic_stats.c index 0dc6b632d..7e7e1aaee 100644 --- a/src/quic_stats.c +++ b/src/quic_stats.c @@ -104,7 +104,7 @@ static int quic_fill_stats(struct stats_module *mod, struct extra_counters *ctr, if (!ctr) goto store_metric; - counters = EXTRA_COUNTERS_GET(ctr, mod); + counters = EXTRA_COUNTERS_BASE(ctr, mod); switch (current_field) { case QUIC_ST_RXBUF_FULL: diff --git a/src/resolvers.c b/src/resolvers.c index c717b013a..b8306d33d 100644 --- a/src/resolvers.c +++ b/src/resolvers.c @@ -134,7 +134,7 @@ static int resolv_fill_stats(struct stats_module *mod, struct extra_counters *ct if (!ctr) goto store_metric; - counters = EXTRA_COUNTERS_GET(ctr, mod); + counters = EXTRA_COUNTERS_BASE(ctr, mod); switch (current_field) { case RSLV_STAT_ID: diff --git a/src/ssl_sock.c b/src/ssl_sock.c index 510798e55..4fbfcb4dd 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -206,7 +206,7 @@ static int ssl_fill_stats(struct stats_module *mod, struct extra_counters *ctr, if (!ctr) goto store_metric; - counters = EXTRA_COUNTERS_GET(ctr, mod); + counters = EXTRA_COUNTERS_BASE(ctr, mod); switch (current_field) { case SSL_ST_SESS: