From: Vladimír Čunát Date: Tue, 29 Dec 2020 14:51:50 +0000 (+0100) Subject: lib/selection: tweak computation of RTT estimates X-Git-Tag: v5.3.0~30^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3a8bbb42e0e1bab9ea5e71f96ddd86574774227;p=thirdparty%2Fknot-resolver.git lib/selection: tweak computation of RTT estimates - fix switched \alpha and \beta from the RFC (no big deal, I think) - use the same order as in the RFC (perhaps that caused the switch?) - avoid floating-point arithmetics (it's simple with these formulas) - simplify the the backoff formula (MINs instead of branches) --- diff --git a/lib/selection.c b/lib/selection.c index 192275535..e6c39a259 100644 --- a/lib/selection.c +++ b/lib/selection.c @@ -134,15 +134,9 @@ static bool no_rtt_info(struct rtt_state s) static unsigned back_off_timeout(uint32_t to, int pow) { - if (pow > MAX_BACKOFF) { - to *= 1 << MAX_BACKOFF; - } else { - to *= (1 << pow); - } - if (to > MAX_TIMEOUT) { - to = MAX_TIMEOUT; - } - return to; + pow = MIN(pow, MAX_BACKOFF); + to <<= pow; + return MIN(to, MAX_TIMEOUT); } /* This is verbatim (minus the default timeout value and minimal variance) @@ -161,12 +155,10 @@ static struct rtt_state calc_rtt_state(struct rtt_state old, unsigned new_rtt) return (struct rtt_state){ new_rtt, new_rtt / 2, 0 }; } - struct rtt_state ret; - - ret.srtt = (int32_t)(0.75 * old.srtt + 0.25 * new_rtt); - ret.variance = (int32_t)(0.875 * old.variance + - 0.125 * abs(old.srtt - (int32_t)new_rtt)); - ret.consecutive_timeouts = 0; + struct rtt_state ret = { 0 }; + ret.variance = (3 * old.variance + abs(old.srtt - (int32_t)new_rtt) + + 2/*rounding*/) / 4; + ret.srtt = (7 * old.srtt + new_rtt + 4/*rounding*/) / 8; return ret; }