]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: quic: implement credit based pacing
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 10 Jan 2025 16:18:54 +0000 (17:18 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 23 Jan 2025 16:40:20 +0000 (17:40 +0100)
Implement a new method for QUIC pacing emission based on credit. This
represents the number of packets which can be emitted in a single burst.
After emission, decrement from the credit the number of emitted packets.
Several emission can be conducted in the same sequence until the credit
is completely decremented.

When a new emission sequence is initiated (i.e. under a new QMUX tasklet
invokation), credit is refilled according to the delay which occured
between the last and current emission context.

This new mechanism main advantage is that it allows to conduct several
emission in the same task context without having to wait between each
invokation. Wait is only forced if pacing is expired, which is now
equivalent to having a null credit.

Furthermore, if delay between two emissions sequence would have been
smaller than expected, credit is only partially refilled. This allows to
restart emission without having to wait for the whole credit to be
available.

On the implementation side, a new field <credit> is avaiable in
quic_pacer structure. It is automatically decremented on
quic_pacing_sent_done() invokation. Also, a new function
quic_pacing_reload() must be used by QUIC MUX when a new emission
sequence is initiated to refill credit. <next> field from quic_pacer has
been removed.

For the moment, credit is based on the burst configured via quic-cc-algo
keyword, or directly reported by BBR.

This should be backported up to 3.1.

include/haproxy/quic_pacing-t.h
include/haproxy/quic_pacing.h
src/mux_quic.c
src/quic_cc.c
src/quic_pacing.c
src/quic_tx.c

index 2c7d9338f80896bec315ed172685aef9a747ea2a..f910c78e05931ac66781f410bc46e235d57cbd13 100644 (file)
@@ -6,7 +6,8 @@
 
 struct quic_pacer {
        const struct quic_cc *cc; /* Congestion controler algo used for this connection */
-       ullong next; /* Nanosecond timestamp at which the next emission should be conducted */
+       ullong cur;  /* Nanosecond timestamp of the last credit reloading */
+       uint credit; /* Number of packets which can be emitted in a single burst */
 
        int last_sent; /* Number of datagrams sent during last paced emission */
 };
index 955f167dd974a7b2d5b98ef63d82e817ae1727f8..17e6469a21ff2b07953901a67953b699f54c231b 100644 (file)
@@ -10,11 +10,14 @@ static inline void quic_pacing_init(struct quic_pacer *pacer,
                                     const struct quic_cc *cc)
 {
        pacer->cc = cc;
-       pacer->next = 0;
+       pacer->cur = 0;
+       pacer->credit = cc->algo->pacing_burst(cc);
 }
 
 int quic_pacing_expired(const struct quic_pacer *pacer);
 
 void quic_pacing_sent_done(struct quic_pacer *pacer, int sent);
 
+int quic_pacing_reload(struct quic_pacer *pacer);
+
 #endif /* _HAPROXY_QUIC_PACING_H */
index f0766343ae307ba291f1122f55154340aa9b002c..b324e4e7afbcab1cba171fd365402ca03868681c 100644 (file)
@@ -2533,8 +2533,8 @@ static int qcc_io_send(struct qcc *qcc, int after_pacing)
                        goto out;
        }
 
-       if (qcc_is_pacing_active(qcc->conn)) {
-               if (!LIST_ISEMPTY(frms) && !quic_pacing_expired(&qcc->tx.pacer)) {
+       if (!LIST_ISEMPTY(frms) && qcc_is_pacing_active(qcc->conn)) {
+               if (!quic_pacing_reload(&qcc->tx.pacer)) {
                        if (!after_pacing)
                                ++qcc->tx.paced_sent_ctr;
                        tasklet_wakeup(qcc->wait_event.tasklet, TASK_F_UEVT1);
index 603914cd455a87a57e1bd78a7f6f0e7ba3199b09..2365960c18f9176632b2937b8592e82bcd6c8ef5 100644 (file)
@@ -54,7 +54,7 @@ void quic_cc_state_trace(struct buffer *buf, const struct quic_cc *cc)
 uint quic_cc_default_pacing_inter(const struct quic_cc *cc)
 {
        struct quic_cc_path *path = container_of(cc, struct quic_cc_path, cc);
-       return path->loss.srtt * 1000000 / (path->cwnd / path->mtu + 1);
+       return path->loss.srtt * 1000000 / (path->cwnd / path->mtu + 1) + 1;
 }
 
 /* Return the max number of datagrams which can be emitted in a burst with
index 19216858c32f667e68af2ea04e682967a243abea..0c4c0ad83f6de1d06a4b8ff7d5106be32dedd195 100644 (file)
@@ -6,12 +6,40 @@
 /* Returns true if <pacer> timer is expired and emission can be retried. */
 int quic_pacing_expired(const struct quic_pacer *pacer)
 {
-       return !pacer->next || pacer->next <= task_mono_time();
+       return pacer->credit;
 }
 
 /* Notify <pacer> about an emission of <sent> count of datagrams. */
 void quic_pacing_sent_done(struct quic_pacer *pacer, int sent)
 {
-       pacer->next = task_mono_time() + pacer->cc->algo->pacing_inter(pacer->cc) * sent;
+       BUG_ON(!pacer->credit || pacer->credit < sent);
+       pacer->credit -= sent;
+
        pacer->last_sent = sent;
 }
+
+/* Reload <pacer> credit when a new emission sequence is initiated. A maximal
+ * value is calculated if previous emission occurred long time enough.
+ *
+ * Returns the remaining credit or 0 if emission cannot be conducted this time.
+ */
+int quic_pacing_reload(struct quic_pacer *pacer)
+{
+       const uint64_t task_now_ns = task_mono_time();
+       const uint64_t inter = pacer->cc->algo->pacing_inter(pacer->cc);
+       uint64_t inc;
+       uint credit_max;
+
+       if (task_now_ns > pacer->cur) {
+               /* Calculate number of packets which could have been emitted since last emission sequence. Result is rounded up. */
+               inc = (task_now_ns - pacer->cur + inter - 1) / inter;
+
+               credit_max = pacer->cc->algo->pacing_burst(pacer->cc);
+               pacer->credit = MIN(pacer->credit + inc, credit_max);
+
+               /* Refresh pacing reload timer. */
+               pacer->cur = task_now_ns;
+       }
+
+       return pacer->credit;
+}
index 19bcad018a4fe90c4abf755814d9971e5ebfc4e8..d283ec9be0afc2e1e7cfba3266e5b5b5a3973ac2 100644 (file)
@@ -503,7 +503,7 @@ enum quic_tx_err qc_send_mux(struct quic_conn *qc, struct list *frms,
        }
 
        if (pacer) {
-               max_dgram = qc->path->cc.algo->pacing_burst(&qc->path->cc);
+               max_dgram = pacer->credit;
                BUG_ON(max_dgram <= 0); /* pacer must specify a positive burst value. */
        }