From nobody Tue Sep 20 17:13:54 2022 X-Original-To: dev-commits-src-main@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 4MX7S257Qsz4crsm; Tue, 20 Sep 2022 17:13:54 +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 4MX7S24ZzMz3sB3; Tue, 20 Sep 2022 17:13:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663694034; 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=Xbddaw8ScE+QIVrfF5Z78c0EH7slxwkpEG9MuoOIGCg=; b=NcbImrxV4nNkl4wl1qVEVulzN/glrjJWCEAlMfOjuLanwYXmPU5S6nDUPmHNZzR3HEfX50 FGapOY+eE7yY6wptFqc9AljcvCmVSQ7+cb2L48PmvpzGdMusWxWHc15+1olermTuxqzu+A P8oxv2ivl3oBmIw+mJkPgkeTErjgqjrbtSQ6ynlylMHM55tGuDxVoa5FVVv6GVbYqGfTIf yz8VRFsdsI1vqdD5Oo2oUa5bJvptKdeZalvnkNsNifsvtQ7QOHr36gMFLLwvO0Sd2jkl47 XsXDaN/Nx92ITVOh/8M54/RJsz+MVIkAEItjjwG6aoQQty+GIlynZUx9cobC7Q== 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 4MX7S23bl9znHQ; Tue, 20 Sep 2022 17:13:54 +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 28KHDsTR047899; Tue, 20 Sep 2022 17:13:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28KHDs8k047898; Tue, 20 Sep 2022 17:13:54 GMT (envelope-from git) Date: Tue, 20 Sep 2022 17:13:54 GMT Message-Id: <202209201713.28KHDs8k047898@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Randall Stewart Subject: git: 7cc3ea9c6f8b - main - mlx5 M_TSTMP accuracy looses quite a bit of precision so lets fix it. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rrs X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7cc3ea9c6f8b99315b671c7bd75a03f8f1cdc8e3 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663694034; 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=Xbddaw8ScE+QIVrfF5Z78c0EH7slxwkpEG9MuoOIGCg=; b=K8t0zSGtmR4haEPFLYXoFQCCuXSkECinQpBQ4JcWkSF3k5HaPrM9v4Y0STHI4Y1O3gvc1N YfGfvn0KiF3pq+L+lamex1myOTktyWFXq3x4cquaxrrhz3ni3Z9sLjXhVRDUGoy7XTGntq hlMc3Z2lFdcI38M9KT3z7k7i2hwjN8iks8lEV8y8BhQ3Vn7mNN7Y64qi/dQDxLROHCR0YI 6OZzuYKRmCCiJqaf5Co++pZcMiyJb9lsLEFQ8lQUAO2OZ5Jk9qn1Zc9hUNAX/9vijDOlqM 3H+Ywa/QremA475eirQlaLhMfj4ONMq+GikQZbDNLFETvvtyzTVYdec+Dg+CSQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663694034; a=rsa-sha256; cv=none; b=CmTid5T+xCJiStdtSpxyKqBSIwdTn+4fD+dY8k6b5TcU/jke1x+2r3LUC3XA6EKDZl67nR tOfsfoO55/P2ayhEpd115NiHHo7JzHcXkM+CI2iLceBpDvQagg2/0CKlCoPoZYfWgz4J+K F5Ev/eJiH7RZTdxLxDeL2k1Ij7UF1Gk5cRwwyFvc0LEiBuOb0KSe1XzuCRDa/MApiV7cit 4Ddce+d2hODQUDdy5hgqfjm5cG4QzJoT+r66RM7lGCmCF4pQ2byUla8N/s2Fa+C3IA8f5g +Zr3PBHVvsNUX/2tiZ312VyA8J80sW+PRUGpYck15ojcKLaK+hveYjG7PTpkIA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by rrs: URL: https://cgit.FreeBSD.org/src/commit/?id=7cc3ea9c6f8b99315b671c7bd75a03f8f1cdc8e3 commit 7cc3ea9c6f8b99315b671c7bd75a03f8f1cdc8e3 Author: Randall Stewart AuthorDate: 2022-09-20 17:12:16 +0000 Commit: Randall Stewart CommitDate: 2022-09-20 17:12:16 +0000 mlx5 M_TSTMP accuracy looses quite a bit of precision so lets fix it. The way that the clock is synchronized between the system and the current mlx5 for the purposes of the M_TSTMP being carried we loose a lot of precision. Instead lets change the math that calculates this to separate out the seconds/nanoseconds and operate on the two values so we don't get overflow instead of just shifting the value down and loosing precision. Reviewed by: kib, hselasky Sponsored by: Netflix Inc Differential Revision: https://reviews.freebsd.org/D36327 --- sys/dev/mlx5/mlx5_en/en.h | 1 + sys/dev/mlx5/mlx5_en/mlx5_en_main.c | 2 ++ sys/dev/mlx5/mlx5_en/mlx5_en_rx.c | 64 ++++++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/sys/dev/mlx5/mlx5_en/en.h b/sys/dev/mlx5/mlx5_en/en.h index 9eeb8c1a396d..d24383f4c927 100644 --- a/sys/dev/mlx5/mlx5_en/en.h +++ b/sys/dev/mlx5/mlx5_en/en.h @@ -1144,6 +1144,7 @@ struct mlx5e_priv { int clbr_curr; struct mlx5e_clbr_point clbr_points[2]; u_int clbr_gen; + uint64_t cclk; struct mlx5e_dcbx dcbx; bool sw_is_port_buf_owner; diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c index 0cae0696a180..47bf627ed7af 100644 --- a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c +++ b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c @@ -4797,6 +4797,8 @@ mlx5e_create_ifp(struct mlx5_core_dev *mdev) &priv->clbr_done, 0, "RX timestamps calibration state"); callout_init(&priv->tstmp_clbr, 1); + /* Pull out the frequency of the clock in hz */ + priv->cclk = (uint64_t)MLX5_CAP_GEN(mdev, device_frequency_khz) * 1000ULL; mlx5e_reset_calibration_callout(priv); pa.pa_version = PFIL_VERSION; diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c b/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c index 6d8c36299ca1..f6caddfdf933 100644 --- a/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c +++ b/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c @@ -214,7 +214,10 @@ static uint64_t mlx5e_mbuf_tstmp(struct mlx5e_priv *priv, uint64_t hw_tstmp) { struct mlx5e_clbr_point *cp, dcp; - uint64_t a1, a2, res; + uint64_t tstmp_sec, tstmp_nsec; + uint64_t hw_clocks; + uint64_t rt_cur_to_prev, res_s, res_n, res_s_modulo, res; + uint64_t hw_clk_div; u_int gen; do { @@ -224,19 +227,49 @@ mlx5e_mbuf_tstmp(struct mlx5e_priv *priv, uint64_t hw_tstmp) return (0); dcp = *cp; atomic_thread_fence_acq(); - } while (gen != cp->clbr_gen); - - a1 = (hw_tstmp - dcp.clbr_hw_prev) >> MLX5E_TSTMP_PREC; - a2 = (dcp.base_curr - dcp.base_prev) >> MLX5E_TSTMP_PREC; - res = (a1 * a2) << MLX5E_TSTMP_PREC; - + } while (gen != dcp.clbr_gen); /* - * Divisor cannot be zero because calibration callback - * checks for the condition and disables timestamping - * if clock halted. + * Our goal here is to have a result that is: + * + * ( (cur_time - prev_time) ) + * ((hw_tstmp - hw_prev) * ----------------------------- ) + prev_time + * ( (hw_cur - hw_prev) ) + * + * With the constraints that we cannot use float and we + * don't want to overflow the uint64_t numbers we are using. + * + * The plan is to take the clocking value of the hw timestamps + * and split them into seconds and nanosecond equivalent portions. + * Then we operate on the two portions seperately making sure to + * bring back the carry over from the seconds when we divide. + * + * First up lets get the two divided into separate entities + * i.e. the seconds. We use the clock frequency for this. + * Note that priv->cclk was setup with the clock frequency + * in hz so we are all set to go. */ - res /= (dcp.clbr_hw_curr - dcp.clbr_hw_prev) >> MLX5E_TSTMP_PREC; - + hw_clocks = hw_tstmp - dcp.clbr_hw_prev; + tstmp_sec = hw_clocks / priv->cclk; + tstmp_nsec = hw_clocks % priv->cclk; + /* Now work with them separately */ + rt_cur_to_prev = (dcp.base_curr - dcp.base_prev); + res_s = tstmp_sec * rt_cur_to_prev; + res_n = tstmp_nsec * rt_cur_to_prev; + /* Now lets get our divider */ + hw_clk_div = dcp.clbr_hw_curr - dcp.clbr_hw_prev; + /* Make sure to save the remainder from the seconds divide */ + res_s_modulo = res_s % hw_clk_div; + res_s /= hw_clk_div; + /* scale the remainder to where it should be */ + res_s_modulo *= priv->cclk; + /* Now add in the remainder */ + res_n += res_s_modulo; + /* Now do the divide */ + res_n /= hw_clk_div; + res_s *= priv->cclk; + /* Recombine the two */ + res = res_s + res_n; + /* And now add in the base time to get to the real timestamp */ res += dcp.base_prev; return (res); } @@ -370,10 +403,11 @@ mlx5e_build_rx_mbuf(struct mlx5_cqe64 *cqe, tstmp &= ~MLX5_CQE_TSTMP_PTP; mb->m_flags |= M_TSTMP_HPREC; } - mb->m_pkthdr.rcv_tstmp = tstmp; - mb->m_flags |= M_TSTMP; + if (tstmp != 0) { + mb->m_pkthdr.rcv_tstmp = tstmp; + mb->m_flags |= M_TSTMP; + } } - switch (get_cqe_tls_offload(cqe)) { case CQE_TLS_OFFLOAD_DECRYPTED: /* set proper checksum flag for decrypted packets */