# HG changeset patch # User Vladimir Homutov # Date 1634643170 -10800 # Node ID da112e7f8de6e77ea4ea51f36771ea67d6dc8720 # Parent 1798acc01970ae5a03f785b7679fe34c32adcfea QUIC: switched to integer arithmetic in rtt calculations. RFC 9002 uses constants implying effective implementation, i.e. using bit shift operations instead of floating point. diff --git a/src/event/quic/ngx_event_quic_ack.c b/src/event/quic/ngx_event_quic_ack.c --- a/src/event/quic/ngx_event_quic_ack.c +++ b/src/event/quic/ngx_event_quic_ack.c @@ -14,17 +14,12 @@ /* RFC 9002, 6.1.1. Packet Threshold: kPacketThreshold */ #define NGX_QUIC_PKT_THR 3 /* packets */ -/* RFC 9002, 6.1.2. Time Threshold: kTimeThreshold, kGranularity */ -#define NGX_QUIC_TIME_THR 1.125 +/* RFC 9002, 6.1.2. Time Threshold: kGranularity */ #define NGX_QUIC_TIME_GRANULARITY 1 /* ms */ /* RFC 9002, 7.6.1. Duration: kPersistentCongestionThreshold */ #define NGX_QUIC_PERSISTENT_CONGESTION_THR 3 -#define ngx_quic_lost_threshold(qc) \ - ngx_max(NGX_QUIC_TIME_THR * ngx_max((qc)->latest_rtt, (qc)->avg_rtt), \ - NGX_QUIC_TIME_GRANULARITY) - /* send time of ACK'ed packets */ typedef struct { @@ -34,6 +29,7 @@ typedef struct { } ngx_quic_ack_stat_t; +static ngx_inline ngx_msec_t ngx_quic_lost_threshold(ngx_quic_connection_t *qc); static void ngx_quic_rtt_sample(ngx_connection_t *c, ngx_quic_ack_frame_t *ack, enum ssl_encryption_level_t level, ngx_msec_t send_time); static ngx_int_t ngx_quic_handle_ack_frame_range(ngx_connection_t *c, @@ -50,6 +46,19 @@ static void ngx_quic_congestion_lost(ngx static void ngx_quic_lost_handler(ngx_event_t *ev); +/* RFC 9002, 6.1.2. Time Threshold: kTimeThreshold, kGranularity */ +static ngx_inline ngx_msec_t +ngx_quic_lost_threshold(ngx_quic_connection_t *qc) +{ + ngx_msec_t thr; + + thr = ngx_max(qc->latest_rtt, qc->avg_rtt); + thr += thr >> 3; + + return ngx_max(thr, NGX_QUIC_TIME_GRANULARITY); +} + + ngx_int_t ngx_quic_handle_ack_frame(ngx_connection_t *c, ngx_quic_header_t *pkt, ngx_quic_frame_t *f) @@ -198,9 +207,9 @@ ngx_quic_rtt_sample(ngx_connection_t *c, adjusted_rtt -= ack_delay; } - qc->avg_rtt = 0.875 * qc->avg_rtt + 0.125 * adjusted_rtt; + qc->avg_rtt += (adjusted_rtt >> 3) - (qc->avg_rtt >> 3); rttvar_sample = ngx_abs((ngx_msec_int_t) (qc->avg_rtt - adjusted_rtt)); - qc->rttvar = 0.75 * qc->rttvar + 0.25 * rttvar_sample; + qc->rttvar += (rttvar_sample >> 2) - (qc->rttvar >> 2); } ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,