From: Amaury Denoyelle Date: Fri, 28 Apr 2023 14:46:11 +0000 (+0200) Subject: MINOR: proxy: factorize send rate measurement X-Git-Tag: v2.8-dev9~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bc0adfa334575d9a24ac3c6c0d1d4ad943a576cc;p=thirdparty%2Fhaproxy.git MINOR: proxy: factorize send rate measurement Implement a new dedicated function increment_send_rate() which can be call anywhere new bytes must be accounted for global total sent. --- diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index 547c6718fa..39a46376fd 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -30,6 +30,7 @@ #include #include #include +#include extern struct proxy *proxies_list; extern struct eb_root used_proxy_id; /* list of proxy IDs in use */ @@ -235,6 +236,22 @@ static inline int in_proxies_list(struct proxy *list, struct proxy *proxy) return 0; } +/* Add to the global total bytes sent and adjust the send rate. Set + * if this was sent usigin splicing. + */ +static inline void increment_send_rate(uint64_t bytes, int splice) +{ + /* We count the total bytes sent, and the send rate for 32-byte blocks. + * The reason for the latter is that freq_ctr are limited to 4GB and + * that it's not enough per second. + */ + + if (splice) + _HA_ATOMIC_ADD(&th_ctx->spliced_out_bytes, bytes); + _HA_ATOMIC_ADD(&th_ctx->out_bytes, bytes); + update_freq_ctr(&th_ctx->out_32bps, (bytes + 16) / 32); +} + #endif /* _HAPROXY_PROXY_H */ /* diff --git a/src/mux_quic.c b/src/mux_quic.c index 44a8d2729c..82d2076c6f 100644 --- a/src/mux_quic.c +++ b/src/mux_quic.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -20,7 +19,6 @@ #include #include #include -#include #include DECLARE_POOL(pool_head_qcc, "qcc", sizeof(struct qcc)); @@ -1648,13 +1646,8 @@ void qcc_streams_sent_done(struct qcs *qcs, uint64_t data, uint64_t offset) /* Add measurement for send rate. This is done at the MUX layer * to account only for STREAM frames without retransmission. - * - * we count the total bytes sent, and the send rate for 32-byte blocks. - * The reason for the latter is that freq_ctr are limited to 4GB and - * that it's not enough per second. */ - _HA_ATOMIC_ADD(&th_ctx->out_bytes, ret); - update_freq_ctr(&th_ctx->out_32bps, (ret + 16) / 32); + increment_send_rate(diff, 0); } if (qcs->tx.offset == qcs->tx.sent_offset && !b_data(&qcs->tx.buf)) { diff --git a/src/raw_sock.c b/src/raw_sock.c index 9901f9b182..31ca970f18 100644 --- a/src/raw_sock.c +++ b/src/raw_sock.c @@ -26,9 +26,9 @@ #include #include #include -#include #include #include +#include #include @@ -147,15 +147,9 @@ int raw_sock_to_pipe(struct connection *conn, void *xprt_ctx, struct pipe *pipe, conn->flags &= ~CO_FL_WAIT_L4_CONN; leave: - if (retval > 0) { - /* we count the total bytes sent, and the send rate for 32-byte - * blocks. The reason for the latter is that freq_ctr are - * limited to 4GB and that it's not enough per second. - */ - _HA_ATOMIC_ADD(&th_ctx->out_bytes, retval); - _HA_ATOMIC_ADD(&th_ctx->spliced_out_bytes, retval); - update_freq_ctr(&th_ctx->out_32bps, (retval + 16) / 32); - } + if (retval > 0) + increment_send_rate(retval, 1); + return retval; out_read0: @@ -416,14 +410,9 @@ static size_t raw_sock_from_buf(struct connection *conn, void *xprt_ctx, const s conn->flags &= ~CO_FL_WAIT_L4_CONN; } - if (done > 0) { - /* we count the total bytes sent, and the send rate for 32-byte - * blocks. The reason for the latter is that freq_ctr are - * limited to 4GB and that it's not enough per second. - */ - _HA_ATOMIC_ADD(&th_ctx->out_bytes, done); - update_freq_ctr(&th_ctx->out_32bps, (done + 16) / 32); - } + if (done > 0) + increment_send_rate(done, 0); + return done; }