From: Amaury Denoyelle Date: Fri, 10 Jan 2025 16:18:54 +0000 (+0100) Subject: MEDIUM: quic: implement credit based pacing X-Git-Tag: v3.2-dev4~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4489a61585283803726b10c5b081c26f24b7d8dd;p=thirdparty%2Fhaproxy.git MEDIUM: quic: implement credit based pacing 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 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. 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. --- diff --git a/include/haproxy/quic_pacing-t.h b/include/haproxy/quic_pacing-t.h index 2c7d9338f..f910c78e0 100644 --- a/include/haproxy/quic_pacing-t.h +++ b/include/haproxy/quic_pacing-t.h @@ -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 */ }; diff --git a/include/haproxy/quic_pacing.h b/include/haproxy/quic_pacing.h index 955f167dd..17e6469a2 100644 --- a/include/haproxy/quic_pacing.h +++ b/include/haproxy/quic_pacing.h @@ -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 */ diff --git a/src/mux_quic.c b/src/mux_quic.c index f0766343a..b324e4e7a 100644 --- a/src/mux_quic.c +++ b/src/mux_quic.c @@ -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); diff --git a/src/quic_cc.c b/src/quic_cc.c index 603914cd4..2365960c1 100644 --- a/src/quic_cc.c +++ b/src/quic_cc.c @@ -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 diff --git a/src/quic_pacing.c b/src/quic_pacing.c index 19216858c..0c4c0ad83 100644 --- a/src/quic_pacing.c +++ b/src/quic_pacing.c @@ -6,12 +6,40 @@ /* Returns true if 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 about an emission of 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 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; +} diff --git a/src/quic_tx.c b/src/quic_tx.c index 19bcad018..d283ec9be 100644 --- a/src/quic_tx.c +++ b/src/quic_tx.c @@ -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. */ }