From nobody Wed May 31 19:23:44 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QWfM51CNfz4XSfP; Wed, 31 May 2023 19:23:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QWfM50MQCz3M98; Wed, 31 May 2023 19:23:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685561025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=USB+YY6JvIENdJz9gCKMXqtiE/8qMzk2VWVMLX+uM7I=; b=VcEtg8zHHOJ43NXzrhYBe49l6RrHM55/a5WnRTRDYQrFwfearQpj9QHtwB+rXx1vzLyNU0 UcXRCya3c2Dh65Wg+DokLxfoOe5fh1oDRQzgdKaCpHqNlvQBzcTd/gU2s+aMhz2AsnhvzZ ZXtpOvT+U+ZMZ+zrU3QHFH2bF2ANX9e8iA1NMUoUZuZo6X8LJtJv5zsWC2Rs5fwh+KpoJP VyM4aChoIIZ8FD9dWFJ1IC02NWGKykaaMG0G+ibX8ZfYsA4X7KH2+Kj4RTay3sDRFXhrqO FkWd49/5I81fKubuQDbdc/rGKiOSpRj82tzXqu3PnlW3wi/okT2drwOKnc/G/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685561025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=USB+YY6JvIENdJz9gCKMXqtiE/8qMzk2VWVMLX+uM7I=; b=UjV1rSc4QCqUiXSfufSQFq3TQBFL5di+2b/2Tgrxayy4ZZzsOLmNjaPOPz8IN/qWSmMJgm rnSLUFZ8e0IWx46U4yA9fboX3AjPb6yl9ssDAEBJBm/2tNyMDnWN9cdo5eRap83N3Z3Bpd p1Ad7sZ8ufPFFox/J/e2smGbIuA3lgNH+n53gEATDjvTAxbnYOY/8pdAW8/GTL4xoCrwnL jpr+20ms110jwES1rvq5kCZ3tQlmbofNa3s/KE9TZvmt5p508ZQQEcmG+c58Je4CCuwFaD W7oU+8XFUphZ3AR+G8vqOOTt8lyvXz7lCkWcdhHyR0wWcS9dup3dgdv2oo0npg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685561025; a=rsa-sha256; cv=none; b=UrN+e1O6m1o1w8hybqjeb00BPE6OdV6JIdSfyV2e1N+nanivqxLjVU8ROqTKANgcEIRo3W 4BUo5abRrav+yclLsI3uYGhA0yOk9NsAYEdrpKWV7fQg7MaBZTGhnWvcW+l5hPS2tVDO3O e0QESAkOKz6x7tV35PYWyCsl3xL/7Xqu0/ZKSZOzGX8dNK3pmHFl8n+o8zB8lXBEZr8UfG fMOa4aWEfMhEhODRjL8URvn/gOxOU8onF8X8o+YzaBdDq512hSIWp6B6VnNyshBEAetmX0 IgRmhG4x1tHlMzQbG2nbbBjs8eo64pJR9/Xee4E6Cb1mUZyRBAUJqI0jxCc0Wg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QWfM46G9MznXZ; Wed, 31 May 2023 19:23:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34VJNitG020904; Wed, 31 May 2023 19:23:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34VJNidX020903; Wed, 31 May 2023 19:23:44 GMT (envelope-from git) Date: Wed, 31 May 2023 19:23:44 GMT Message-Id: <202305311923.34VJNidX020903@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Jonathan T. Looney" Subject: git: 4f2cc73f34eb - main - tcp: Refactor tcp_get_srtt() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jtl X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4f2cc73f34eb5f4bd6e66afda1c367676547f516 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jtl: URL: https://cgit.FreeBSD.org/src/commit/?id=4f2cc73f34eb5f4bd6e66afda1c367676547f516 commit 4f2cc73f34eb5f4bd6e66afda1c367676547f516 Author: Jonathan T. Looney AuthorDate: 2023-05-31 19:16:20 +0000 Commit: Jonathan T. Looney CommitDate: 2023-05-31 19:16:20 +0000 tcp: Refactor tcp_get_srtt() Refactor tcp_get_srtt() into its two component operations: unit conversion and shifting. No functional change is intended. Reviewed by: cc, tuexen Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D40304 --- sys/netinet/tcp_subr.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 52222d7c1634..fe065fd08737 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -4647,28 +4647,33 @@ tcp_get_srtt(struct tcpcb *tp, int granularity) { uint32_t srtt; - if (tp->t_tmr_granularity == TCP_TMR_GRANULARITY_USEC) - srtt = tp->t_srtt; - else if (tp->t_tmr_granularity == TCP_TMR_GRANULARITY_TICKS) { - /* TICKS are stored shifted; unshift for the real TICKS */ - srtt = tp->t_srtt >> TCP_RTT_SHIFT; - } - if (tp->t_tmr_granularity == granularity) - return (srtt); - /* If we reach here they are oppsite what the caller wants */ - if (granularity == TCP_TMR_GRANULARITY_USEC) { - /* - * The user wants useconds and internally - * its kept in ticks, convert to useconds. - * Put unshift at last improves precision. - */ - srtt = TICKS_2_USEC(tp->t_srtt) >> TCP_RTT_SHIFT; - } else if (granularity == TCP_TMR_GRANULARITY_TICKS) { - /* - * The user wants ticks and internally its - * kept in useconds, convert to ticks. - */ - srtt = USEC_2_TICKS(srtt); + KASSERT(granularity == TCP_TMR_GRANULARITY_USEC || + granularity == TCP_TMR_GRANULARITY_TICKS, + ("%s: called with unexpected granularity %d", __func__, + granularity)); + + srtt = tp->t_srtt; + + /* + * We only support two granularities. If the stored granularity + * does not match the granularity requested by the caller, + * convert the stored value to the requested unit of granularity. + */ + if (tp->t_tmr_granularity != granularity) { + if (granularity == TCP_TMR_GRANULARITY_USEC) + srtt = TICKS_2_USEC(srtt); + else + srtt = USEC_2_TICKS(srtt); } + + /* + * If the srtt is stored with ticks granularity, we need to + * unshift to get the actual value. We do this after the + * conversion above (if one was necessary) in order to maximize + * precision. + */ + if (tp->t_tmr_granularity == TCP_TMR_GRANULARITY_TICKS) + srtt = srtt >> TCP_RTT_SHIFT; + return (srtt); }