diff --git a/lib/ngtcp2_cc.c b/lib/ngtcp2_cc.c index 38d97cc7c0df348b59c8f93836487343c794a66d..a508dbe97785bf3874c50cfad22b98a612946c39 100644 --- a/lib/ngtcp2_cc.c +++ b/lib/ngtcp2_cc.c @@ -276,6 +276,7 @@ void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat, uint64_t target; uint64_t tx, kx, time_delta, delta; uint64_t add, tcp_add; + uint64_t m; if (pkt->pktns_id == NGTCP2_PKTNS_ID_APP && cc->window_end != -1 && cc->window_end <= pkt->pkt_num) { @@ -341,6 +342,9 @@ void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat, "cubic-ca epoch_start=%" PRIu64 " k=%" PRIu64 " origin_point=%" PRIu64, cc->epoch_start, cc->k, cc->origin_point); + + cc->pending_add = 0; + cc->pending_w_add = 0; } min_rtt = cstat->min_rtt == UINT64_MAX ? cstat->initial_rtt : cstat->min_rtt; @@ -366,13 +370,19 @@ void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat, } if (target > cstat->cwnd) { - add = cstat->max_udp_payload_size * (target - cstat->cwnd) / cstat->cwnd; + m = cc->pending_add + cstat->max_udp_payload_size * (target - cstat->cwnd); + add = m / cstat->cwnd; + cc->pending_add = m % cstat->cwnd; } else { - /* TODO too small, no increment at all */ - add = cstat->max_udp_payload_size / (100 * cstat->cwnd); + m = cc->pending_add + cstat->max_udp_payload_size; + add = m / (100 * cstat->cwnd); + cc->pending_add = m % (100 * cstat->cwnd); } - cc->w_tcp += cstat->max_udp_payload_size * pkt->pktlen * 9 / 17 / cstat->cwnd; + m = cc->pending_w_add + cstat->max_udp_payload_size * pkt->pktlen * 9; + + cc->w_tcp += m / (17 * cstat->cwnd); + cc->pending_w_add = m % (17 * cstat->cwnd); if (cc->w_tcp > cstat->cwnd) { tcp_add = diff --git a/lib/ngtcp2_cc.h b/lib/ngtcp2_cc.h index c3886a6e6b41cb54d374100daea345f5837d30da..05010d57251c39f10066662869744f177163d1ed 100644 --- a/lib/ngtcp2_cc.h +++ b/lib/ngtcp2_cc.h @@ -95,6 +95,8 @@ typedef struct ngtcp2_cubic_cc { uint64_t current_round_min_rtt; uint64_t last_round_min_rtt; int64_t window_end; + uint64_t pending_add; + uint64_t pending_w_add; } ngtcp2_cubic_cc; int ngtcp2_cc_cubic_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,