]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: Allocate listener RX buffers
authorFrédéric Lécaille <flecaille@haproxy.com>
Wed, 20 Oct 2021 09:09:58 +0000 (11:09 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 5 Nov 2021 14:20:04 +0000 (15:20 +0100)
At this time we allocate an RX buffer by thread.
Also take the opportunity offered by this patch to rename TX related variable
names to distinguish them from the RX part.

include/haproxy/receiver-t.h
include/haproxy/xprt_quic-t.h
src/proto_quic.c
src/xprt_quic.c

index 3e1ff81dbf82426a882d36d41e8d996ea3a1fe80..f7412dfeb8233795ff584c34917bb5e4c1d76d6d 100644 (file)
@@ -68,8 +68,10 @@ struct receiver {
        struct eb_root odcids;           /* QUIC original destination connection IDs. */
        struct eb_root cids;             /* QUIC connection IDs. */
        __decl_thread(HA_RWLOCK_T cids_lock); /* RW lock for connection IDs tree accesses */
-       struct qring *qrings;            /* Array of rings (one by thread) */
-       struct mt_list tx_qrings;        /* The same as ->qrings but arranged in a list */
+       struct qring *tx_qrings;         /* Array of rings (one by thread) */
+       struct mt_list tx_qring_list;    /* The same as ->qrings but arranged in a list */
+       struct rxbuf *rxbufs;            /* Array of buffers for RX (one by thread) */
+       struct mt_list rxbuf_list;       /* The same as ->rxbufs but arranged in a list */
 #endif
        /* warning: this struct is huge, keep it at the bottom */
        struct sockaddr_storage addr;    /* the address the socket is bound to */
index 07ccf2319b00d136d23bbef38ef47105a8c6940a..f7975cfb15d68c53026d71338be1f625b4f0d6df 100644 (file)
@@ -232,9 +232,12 @@ enum quic_pkt_type {
 
 /* Size of the internal buffer of QUIC TX ring buffers (must be a power of 2) */
 #define QUIC_TX_RING_BUFSZ  (1UL << 12)
+/* Size of the internal buffer of QUIC RX buffer. */
+#define QUIC_RX_BUFSZ  (1UL << 18)
 
 extern struct trace_source trace_quic;
 extern struct pool_head *pool_head_quic_tx_ring;
+extern struct pool_head *pool_head_quic_rxbuf;
 extern struct pool_head *pool_head_quic_rx_packet;
 extern struct pool_head *pool_head_quic_tx_packet;
 extern struct pool_head *pool_head_quic_frame;
@@ -587,6 +590,12 @@ struct qring {
        struct mt_list mt_list;
 };
 
+/* QUIC RX buffer */
+struct rxbuf {
+       struct buffer buf;
+       struct mt_list mt_list;
+};
+
 /* The number of buffers for outgoing packets (must be a power of two). */
 #define QUIC_CONN_TX_BUFS_NB 8
 #define QUIC_CONN_TX_BUF_SZ  QUIC_PACKET_MAXLEN
index 1aa3e69500c64bf99884b5378e9b6b9ed76cf843..9c2bbd6ef76da0da11d460da89c9b4328b4db52a 100644 (file)
@@ -528,19 +528,19 @@ static void quic_add_listener(struct protocol *proto, struct listener *listener)
 /* Allocate the TX ring buffers for <l> listener.
  * Return 1 if succeeded, 0 if not.
  */
-static int quic_alloc_rings_listener(struct listener *l)
+static int quic_alloc_tx_rings_listener(struct listener *l)
 {
        struct qring *qr;
        int i;
 
-       l->rx.qrings = calloc(global.nbthread, sizeof *l->rx.qrings);
-       if (!l->rx.qrings)
+       l->rx.tx_qrings = calloc(global.nbthread, sizeof *l->rx.tx_qrings);
+       if (!l->rx.tx_qrings)
                return 0;
 
-       MT_LIST_INIT(&l->rx.tx_qrings);
+       MT_LIST_INIT(&l->rx.tx_qring_list);
        for (i = 0; i < global.nbthread; i++) {
                unsigned char *buf;
-               struct qring *qr = &l->rx.qrings[i];
+               struct qring *qr = &l->rx.tx_qrings[i];
 
                buf = pool_alloc(pool_head_quic_tx_ring);
                if (!buf)
@@ -552,17 +552,51 @@ static int quic_alloc_rings_listener(struct listener *l)
                        goto err;
                }
 
-               MT_LIST_APPEND(&l->rx.tx_qrings, &qr->mt_list);
+               MT_LIST_APPEND(&l->rx.tx_qring_list, &qr->mt_list);
        }
 
        return 1;
 
  err:
-       while ((qr = MT_LIST_POP(&l->rx.tx_qrings, typeof(qr), mt_list))) {
+       while ((qr = MT_LIST_POP(&l->rx.tx_qring_list, typeof(qr), mt_list))) {
                pool_free(pool_head_quic_tx_ring, qr->cbuf->buf);
                cbuf_free(qr->cbuf);
        }
-       free(l->rx.qrings);
+       free(l->rx.tx_qrings);
+       return 0;
+}
+
+/* Allocate the RX buffers for <l> listener.
+ * Return 1 if succeeded, 0 if not.
+ */
+static int quic_alloc_rxbufs_listener(struct listener *l)
+{
+       int i;
+       struct rxbuf *rxbuf;
+
+       l->rx.rxbufs = calloc(global.nbthread, sizeof *l->rx.rxbufs);
+       if (!l->rx.rxbufs)
+               return 0;
+
+       MT_LIST_INIT(&l->rx.rxbuf_list);
+       for (i = 0; i < global.nbthread; i++) {
+               char *buf;
+
+               rxbuf = &l->rx.rxbufs[i];
+               buf = pool_alloc(pool_head_quic_rxbuf);
+               if (!buf)
+                       goto err;
+
+               rxbuf->buf = b_make(buf, QUIC_RX_BUFSZ, 0, 0);
+               MT_LIST_APPEND(&l->rx.rxbuf_list, &rxbuf->mt_list);
+       }
+
+       return 1;
+
+ err:
+       while ((rxbuf = MT_LIST_POP(&l->rx.rxbuf_list, typeof(rxbuf), mt_list)))
+               pool_free(pool_head_quic_rxbuf, rxbuf->buf.area);
+       free(l->rx.rxbufs);
        return 0;
 }
 
@@ -596,8 +630,9 @@ static int quic_bind_listener(struct listener *listener, char *errmsg, int errle
                goto udp_return;
        }
 
-       if (!quic_alloc_rings_listener(listener)) {
-               msg = "could not initialize tx rings";
+       if (!quic_alloc_tx_rings_listener(listener) ||
+           !quic_alloc_rxbufs_listener(listener)) {
+               msg = "could not initialize tx/rx rings";
                err |= ERR_WARN;
                goto udp_return;
        }
index 49165c38fb30bac3efcd18bc081d7afb4178e060..9de8a038a688b8f53302ccc7dc034f023f877f8d 100644 (file)
@@ -139,6 +139,7 @@ INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE);
 static BIO_METHOD *ha_quic_meth;
 
 DECLARE_POOL(pool_head_quic_tx_ring, "quic_tx_ring_pool", QUIC_TX_RING_BUFSZ);
+DECLARE_POOL(pool_head_quic_rxbuf, "quic_rxbuf_pool", QUIC_RX_BUFSZ);
 DECLARE_STATIC_POOL(pool_head_quic_conn_ctx,
                     "quic_conn_ctx_pool", sizeof(struct ssl_sock_ctx));
 DECLARE_STATIC_POOL(pool_head_quic_conn, "quic_conn", sizeof(struct quic_conn));
@@ -3016,7 +3017,7 @@ static struct quic_conn *qc_new_conn(unsigned int version, int ipv4,
                if (scid_len)
                        memcpy(qc->dcid.data, scid, scid_len);
                qc->dcid.len = scid_len;
-               qc->tx.qring_list = &l->rx.tx_qrings;
+               qc->tx.qring_list = &l->rx.tx_qring_list;
                qc->li = l;
        }
        /* QUIC Client (outgoing connection to servers) */