TMP ms pacing with budget calcul

This commit is contained in:
Amaury Denoyelle 2024-10-31 09:45:45 +00:00
parent bbaf5bccdf
commit 780b890b0e
5 changed files with 118 additions and 89 deletions

View File

@ -7,10 +7,14 @@
struct quic_pacer { struct quic_pacer {
struct list frms; struct list frms;
const struct quic_cc_path *path; const struct quic_cc_path *path;
//int next;
//unsigned int curr;
//int pkt_ms;
//int sent;
int burst;
int budget;
int last_sent;
int next; int next;
unsigned int curr;
int pkt_ms;
int sent;
}; };
#endif /* _HAPROXY_QUIC_PACING_T_H */ #endif /* _HAPROXY_QUIC_PACING_T_H */

View File

@ -13,12 +13,18 @@ static inline void quic_pacing_init(struct quic_pacer *pacer,
LIST_INIT(&pacer->frms); LIST_INIT(&pacer->frms);
pacer->path = path; pacer->path = path;
//pacer->next = TICK_ETERNITY; //pacer->next = TICK_ETERNITY;
pacer->next = now_ms; //pacer->next = now_ms;
//pacer->curr = now_ms; //pacer->curr = now_ms;
pacer->curr = TICK_ETERNITY; //pacer->curr = TICK_ETERNITY;
pacer->pkt_ms = 0; //pacer->pkt_ms = 0;
pacer->sent = 0; //pacer->sent = 0;
pacer->last_sent = now_ms;
//pacer->budget = global.tune.quic_frontend_max_tx_burst;
pacer->budget = 0;
pacer->burst = global.tune.quic_frontend_max_tx_burst;
pacer->next = TICK_ETERNITY;
} }
static inline void quic_pacing_reset(struct quic_pacer *pacer) static inline void quic_pacing_reset(struct quic_pacer *pacer)
@ -47,7 +53,7 @@ static inline int quic_pacing_ns_pkt(const struct quic_pacer *pacer, int sent)
return (pacer->path->cwnd / (pacer->path->mtu + 1)) / (pacer->path->loss.srtt + 1) + 1; return (pacer->path->cwnd / (pacer->path->mtu + 1)) / (pacer->path->loss.srtt + 1) + 1;
} }
int quic_pacing_expired(const struct quic_pacer *pacer); //int quic_pacing_expired(const struct quic_pacer *pacer);
enum quic_tx_err quic_pacing_send(struct quic_pacer *pacer, struct quic_conn *qc); enum quic_tx_err quic_pacing_send(struct quic_pacer *pacer, struct quic_conn *qc);
@ -56,4 +62,6 @@ int quic_pacing_prepare(struct quic_pacer *pacer);
//void quic_pacing_sent_done(struct quic_pacer *pacer, int sent); //void quic_pacing_sent_done(struct quic_pacer *pacer, int sent);
int quic_pacing_sent_done(struct quic_pacer *pacer, int sent, enum quic_tx_err err); int quic_pacing_sent_done(struct quic_pacer *pacer, int sent, enum quic_tx_err err);
int quic_pacing_next(struct quic_pacer *pacer);
#endif /* _HAPROXY_QUIC_PACING_H */ #endif /* _HAPROXY_QUIC_PACING_H */

View File

@ -277,6 +277,7 @@ static void qcc_refresh_timeout(struct qcc *qcc)
void qcc_wakeup(struct qcc *qcc) void qcc_wakeup(struct qcc *qcc)
{ {
TRACE_POINT(QMUX_EV_QCC_WAKE, qcc->conn);
HA_ATOMIC_AND(&qcc->wait_event.tasklet->state, ~TASK_F_USR1); HA_ATOMIC_AND(&qcc->wait_event.tasklet->state, ~TASK_F_USR1);
tasklet_wakeup(qcc->wait_event.tasklet); tasklet_wakeup(qcc->wait_event.tasklet);
@ -287,12 +288,23 @@ void qcc_wakeup(struct qcc *qcc)
static void qcc_wakeup_pacing(struct qcc *qcc) static void qcc_wakeup_pacing(struct qcc *qcc)
{ {
TRACE_POINT(QMUX_EV_QCC_WAKE, qcc->conn);
BUG_ON(LIST_ISEMPTY(&qcc->tx.pacer.frms));
HA_ATOMIC_OR(&qcc->wait_event.tasklet->state, TASK_F_USR1); HA_ATOMIC_OR(&qcc->wait_event.tasklet->state, TASK_F_USR1);
tasklet_wakeup(qcc->wait_event.tasklet); tasklet_wakeup(qcc->wait_event.tasklet);
//qcc->task->expire = qcc->tx.pacer.next;
//BUG_ON(tick_is_expired(qcc->task->expire, now_ms)); qcc->task->expire = TICK_ETERNITY;
//task_queue(qcc->task); task_queue(qcc->task);
//TRACE_POINT(QMUX_EV_STRM_WAKE, qcc->conn); }
static void qcc_task_pacing(struct qcc *qcc)
{
TRACE_POINT(QMUX_EV_QCC_WAKE, qcc->conn);
//HA_ATOMIC_AND(&qcc->wait_event.tasklet->state, ~TASK_F_USR1);
qcc->task->expire = now_ms == qcc->tx.pacer.next ? tick_add(qcc->tx.pacer.next, 1) : qcc->tx.pacer.next;
BUG_ON(tick_is_expired(qcc->task->expire, now_ms));
task_queue(qcc->task);
TRACE_POINT(QMUX_EV_STRM_WAKE, qcc->conn);
} }
/* Mark a stream as open if it was idle. This can be used on every /* Mark a stream as open if it was idle. This can be used on every
@ -2176,6 +2188,7 @@ static int qcc_io_send(struct qcc *qcc)
*/ */
quic_pacing_reset(pacer); quic_pacing_reset(pacer);
//HA_ATOMIC_AND(&qcc->wait_event.tasklet->state, ~TASK_F_USR1);
/* Check for transport error. */ /* Check for transport error. */
if (qcc->flags & QC_CF_ERR_CONN || qcc->conn->flags & CO_FL_ERROR) { if (qcc->flags & QC_CF_ERR_CONN || qcc->conn->flags & CO_FL_ERROR) {
@ -2277,9 +2290,17 @@ static int qcc_io_send(struct qcc *qcc)
} }
} }
if (!LIST_ISEMPTY(frms) && !quic_pacing_expired(&qcc->tx.pacer)) { //if (!LIST_ISEMPTY(frms) && !quic_pacing_expired(&qcc->tx.pacer)) {
qcc_wakeup_pacing(qcc); if (!LIST_ISEMPTY(frms)) {
return 1; if (!qcc->tx.pacer.budget) {
qcc->tx.pacer.next = tick_add(now_ms, quic_pacing_next(pacer));
//fprintf(stderr, "wait for %ldms\n", qcc->tx.pacer.burst * qcc->tx.pacer.path->loss.srtt * qcc->tx.pacer.path->mtu / qcc->tx.pacer.path->cwnd);
qcc_task_pacing(qcc);
return 1;
}
//else {
// qcc_wakeup_pacing(qcc);
//}
} }
/* Retry sending until no frame to send, data rejected or connection /* Retry sending until no frame to send, data rejected or connection
@ -2317,11 +2338,14 @@ static int qcc_io_send(struct qcc *qcc)
sent_done: sent_done:
if (ret == 1) { if (ret == 1) {
qcc->tx.pacer.next = tick_add(now_ms, quic_pacing_next(pacer));
//fprintf(stderr, "wait for %ldms\n", pacer->burst * pacer->path->loss.srtt * pacer->path->mtu / pacer->path->cwnd);
qcc_wakeup_pacing(qcc); qcc_wakeup_pacing(qcc);
} }
else if (!LIST_ISEMPTY(quic_pacing_frms(pacer))) { else if (!LIST_ISEMPTY(quic_pacing_frms(pacer))) {
/* Deallocate frames that the transport layer has rejected. */ /* Deallocate frames that the transport layer has rejected. */
quic_pacing_reset(pacer); quic_pacing_reset(pacer);
//HA_ATOMIC_AND(&qcc->wait_event.tasklet->state, ~TASK_F_USR1);
} }
/* Re-insert on-error QCS at the end of the send-list. */ /* Re-insert on-error QCS at the end of the send-list. */
@ -2643,6 +2667,7 @@ static void qcc_release(struct qcc *qcc)
} }
quic_pacing_reset(&qcc->tx.pacer); quic_pacing_reset(&qcc->tx.pacer);
//HA_ATOMIC_AND(&qcc->wait_event.tasklet->state, ~TASK_F_USR1);
if (qcc->app_ops && qcc->app_ops->release) if (qcc->app_ops && qcc->app_ops->release)
qcc->app_ops->release(qcc->ctx); qcc->app_ops->release(qcc->ctx);
@ -2679,7 +2704,7 @@ static int qcc_purge_sending(struct qcc *qcc)
if (ret == QUIC_TX_ERR_AGAIN) { if (ret == QUIC_TX_ERR_AGAIN) {
BUG_ON(LIST_ISEMPTY(quic_pacing_frms(pacer))); BUG_ON(LIST_ISEMPTY(quic_pacing_frms(pacer)));
TRACE_POINT(QMUX_EV_QCC_WAKE, qcc->conn); TRACE_POINT(QMUX_EV_QCC_WAKE, qcc->conn);
qcc_wakeup_pacing(qcc); //qcc_wakeup_pacing(qcc);
return 1; return 1;
} }
else if (ret == QUIC_TX_ERR_FATAL) { else if (ret == QUIC_TX_ERR_FATAL) {
@ -2693,6 +2718,8 @@ static int qcc_purge_sending(struct qcc *qcc)
TRACE_POINT(QMUX_EV_QCC_WAKE, qcc->conn); TRACE_POINT(QMUX_EV_QCC_WAKE, qcc->conn);
if (!LIST_ISEMPTY(quic_pacing_frms(pacer))) if (!LIST_ISEMPTY(quic_pacing_frms(pacer)))
qcc_subscribe_send(qcc); qcc_subscribe_send(qcc);
//else
// HA_ATOMIC_AND(&qcc->wait_event.tasklet->state, ~TASK_F_USR1);
return 0; return 0;
} }
} }
@ -2704,8 +2731,18 @@ struct task *qcc_io_cb(struct task *t, void *ctx, unsigned int status)
TRACE_ENTER(QMUX_EV_QCC_WAKE, qcc->conn); TRACE_ENTER(QMUX_EV_QCC_WAKE, qcc->conn);
if (status & TASK_F_USR1) { if (status & TASK_F_USR1) {
++activity[tid].ctr0;
//HA_ATOMIC_AND(&qcc->wait_event.tasklet->state, ~TASK_F_USR1);
//ABORT_NOW(); //ABORT_NOW();
qcc_purge_sending(qcc); if (qcc_purge_sending(qcc)) {
if (!qcc->tx.pacer.budget) {
qcc->tx.pacer.next = tick_add(now_ms, quic_pacing_next(&qcc->tx.pacer));
//fprintf(stderr, "wait for %ldms\n", qcc->tx.pacer.burst * qcc->tx.pacer.path->loss.srtt * qcc->tx.pacer.path->mtu / qcc->tx.pacer.path->cwnd);
qcc_task_pacing(qcc);
}
else
qcc_wakeup_pacing(qcc);
}
return NULL; return NULL;
} }
@ -2745,21 +2782,21 @@ static struct task *qcc_timeout_task(struct task *t, void *ctx, unsigned int sta
goto requeue; goto requeue;
} }
//fprintf(stderr, "woken up after %dms\n", now_ms - qcc->tx.pacer.next); //fprintf(stderr, "woken up after %dms\n", now_ms - qcc->tx.pacer.next);
#if 0
if (!qcc_may_expire(qcc)) {
TRACE_DEVEL("cannot expired", QMUX_EV_QCC_WAKE, qcc->conn);
t->expire = TICK_ETERNITY;
goto requeue;
}
#endif
} }
++activity[tid].ctr1;
if (qcc_purge_sending(qcc)) { if (qcc_purge_sending(qcc)) {
qcc->task->expire = qcc->tx.pacer.next; //qcc->task->expire = qcc->tx.pacer.next;
BUG_ON(tick_is_expired(qcc->task->expire, now_ms)); if (!qcc->tx.pacer.budget) {
TRACE_POINT(QMUX_EV_QCC_WAKE, qcc->conn); qcc->tx.pacer.next = tick_add(now_ms, quic_pacing_next(&qcc->tx.pacer));
goto requeue; qcc->task->expire = now_ms == qcc->tx.pacer.next ? tick_add(qcc->tx.pacer.next, 1) : qcc->tx.pacer.next;
BUG_ON(tick_is_expired(qcc->task->expire, now_ms));
TRACE_POINT(QMUX_EV_QCC_WAKE, qcc->conn);
goto requeue;
}
else {
qcc_wakeup_pacing(qcc);
}
} }
t->expire = TICK_ETERNITY; t->expire = TICK_ETERNITY;
goto requeue; goto requeue;

View File

@ -5,23 +5,24 @@
struct quic_conn; struct quic_conn;
int quic_pacing_expired(const struct quic_pacer *pacer) //int quic_pacing_expired(const struct quic_pacer *pacer)
{ //{
//return !pacer->next || pacer->next <= now_mono_time(); // //return !pacer->next || pacer->next <= now_mono_time();
//return !pacer->next || pacer->next <= now_ms; // //return !pacer->next || pacer->next <= now_ms;
return tick_is_expired(pacer->next, now_ms); // return tick_is_expired(pacer->next, now_ms);
} //}
enum quic_tx_err quic_pacing_send(struct quic_pacer *pacer, struct quic_conn *qc) enum quic_tx_err quic_pacing_send(struct quic_pacer *pacer, struct quic_conn *qc)
{ {
enum quic_tx_err ret; enum quic_tx_err ret;
if (!quic_pacing_expired(pacer)) //if (!quic_pacing_expired(pacer))
return QUIC_TX_ERR_AGAIN; //if (!pacer->budget)
// return QUIC_TX_ERR_AGAIN;
BUG_ON(LIST_ISEMPTY(&pacer->frms)); BUG_ON(LIST_ISEMPTY(&pacer->frms));
ret = qc_send_mux(qc, &pacer->frms, pacer); ret = qc_send_mux(qc, &pacer->frms, pacer);
BUG_ON(ret == QUIC_TX_ERR_AGAIN && tick_is_expired(pacer->next, now_ms)); //BUG_ON(ret == QUIC_TX_ERR_AGAIN && tick_is_expired(pacer->next, now_ms));
/* TODO handle QUIC_TX_ERR_FATAL */ /* TODO handle QUIC_TX_ERR_FATAL */
return ret; return ret;
@ -29,60 +30,34 @@ enum quic_tx_err quic_pacing_send(struct quic_pacer *pacer, struct quic_conn *qc
int quic_pacing_prepare(struct quic_pacer *pacer) int quic_pacing_prepare(struct quic_pacer *pacer)
{ {
if (pacer->curr == now_ms) { int idle = tick_remain(pacer->last_sent, now_ms);
BUG_ON(pacer->sent > pacer->pkt_ms); int pkts = idle * pacer->path->cwnd / (pacer->path->loss.srtt * pacer->path->mtu + 1);
return pacer->pkt_ms - pacer->sent;
} TRACE_POINT(QMUX_EV_QCC_WAKE, NULL);
else {
int not_consumed = pacer->pkt_ms - pacer->sent; pacer->budget += pkts;
BUG_ON(not_consumed < 0); if (pacer->budget > pacer->burst * 2) {
//if (not_consumed) TRACE_POINT(QMUX_EV_QCC_WAKE, NULL);
// fprintf(stderr, "not consumed %d (%d - %d)\n", not_consumed, pacer->pkt_ms, pacer->sent); pacer->budget = pacer->burst * 2;
pacer->curr = now_ms;
pacer->sent = 0;
pacer->pkt_ms = quic_pacing_ns_pkt(pacer, 0);
//pacer->pkt_ms = quic_pacing_ns_pkt(pacer, 0) + not_consumed;
BUG_ON(!pacer->pkt_ms);
return pacer->pkt_ms;
} }
//fprintf(stderr, "prepare = %d %d/%d\n", pkts, pacer->budget, pacer->burst);
return MIN(pacer->budget, pacer->burst);
}
int quic_pacing_next(struct quic_pacer *pacer)
{
//return (pacer->burst / 4) * pacer->path->loss.srtt * pacer->path->mtu / pacer->path->cwnd;
return 1;
} }
int quic_pacing_sent_done(struct quic_pacer *pacer, int sent, enum quic_tx_err err) int quic_pacing_sent_done(struct quic_pacer *pacer, int sent, enum quic_tx_err err)
{ {
//const int pkt_ms = quic_pacing_ns_pkt(pacer, 1); BUG_ON(sent > pacer->budget);
TRACE_POINT(QMUX_EV_QCC_WAKE, NULL);
#if 0 pacer->budget -= sent;
if (pacer->curr == now_ms) { if (sent) {
pacer->sent += sent; TRACE_POINT(QMUX_EV_QCC_WAKE, NULL);
} pacer->last_sent = now_ms;
else {
int not_consumed = pkt_ms - pacer->sent;
if (not_consumed < 0)
not_consumed = 0;
if (not_consumed)
fprintf(stderr, "not consumed %d (%d - %d)\n", not_consumed, pkt_ms, pacer->sent);
//pacer->sent = 0;
//pacer->sent -= not_consumed;
pacer->curr = now_ms;
pacer->sent = sent;
}
#endif
BUG_ON(pacer->curr != now_ms);
pacer->sent += sent;
if (pacer->sent >= pacer->pkt_ms) {
//pacer->next = tick_add(now_ms, 1);
pacer->next = tick_add(now_ms, MAX((pacer->sent / pacer->pkt_ms), 1));
BUG_ON(tick_is_expired(pacer->next, now_ms));
//fprintf(stderr, "pacing in %dms (%d / %d)\n", pacer->sent / pkt_ms, pacer->sent, pkt_ms);
return 1;
}
else {
return 0;
} }
return 0;
} }

View File

@ -513,9 +513,12 @@ enum quic_tx_err qc_send_mux(struct quic_conn *qc, struct list *frms,
} }
#endif #endif
max_dgram = quic_pacing_prepare(pacer); max_dgram = quic_pacing_prepare(pacer);
BUG_ON(!max_dgram); //BUG_ON(!max_dgram);
if (!max_dgram) if (!max_dgram) {
pacer->next = tick_add(now_ms, quic_pacing_next(pacer));
//fprintf(stderr, "wait for %ldms\n", pacer->burst * pacer->path->loss.srtt * pacer->path->mtu / pacer->path->cwnd);
return QUIC_TX_ERR_AGAIN; return QUIC_TX_ERR_AGAIN;
}
} }
TRACE_STATE("preparing data (from MUX)", QUIC_EV_CONN_TXPKT, qc); TRACE_STATE("preparing data (from MUX)", QUIC_EV_CONN_TXPKT, qc);
@ -638,6 +641,7 @@ static int qc_prep_pkts(struct quic_conn *qc, struct buffer *buf,
// goto out; // goto out;
// } // }
//} //}
BUG_ON(max_dgrams && dgram_cnt > max_dgrams);
if (max_dgrams && dgram_cnt == max_dgrams) { if (max_dgrams && dgram_cnt == max_dgrams) {
BUG_ON(LIST_ISEMPTY(frms)); BUG_ON(LIST_ISEMPTY(frms));
TRACE_PROTO("reached max allowed built datagrams", QUIC_EV_CONN_PHPKTS, qc, qel); TRACE_PROTO("reached max allowed built datagrams", QUIC_EV_CONN_PHPKTS, qc, qel);
@ -890,6 +894,7 @@ int qc_send(struct quic_conn *qc, int old_data, struct list *send_list,
} }
ret += prep_pkts; ret += prep_pkts;
BUG_ON(max_dgrams && ret > max_dgrams);
if (max_dgrams && ret == max_dgrams && !LIST_ISEMPTY(send_list)) { if (max_dgrams && ret == max_dgrams && !LIST_ISEMPTY(send_list)) {
TRACE_DEVEL("stopping for artificial pacing", QUIC_EV_CONN_TXPKT, qc); TRACE_DEVEL("stopping for artificial pacing", QUIC_EV_CONN_TXPKT, qc);
break; break;