From nobody Mon Sep 26 22:10:42 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 4Mbxlk6X3Sz4VC0H; Mon, 26 Sep 2022 22:10:42 +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 4Mbxlk5m2dz3vlw; Mon, 26 Sep 2022 22:10:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664230242; 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=2oyyiWWjkHATqk0BkpnLkrjeT3DEwOcms8x5z6X8W5U=; b=XDYGlI3rR+NeYbRPeYLWxJcqAUaqRrX09/AgqM5kn7xC4S/dq4VMcAx+NLhVFV8X4fTGE+ p6BQePEL/fZm7DNKptG0WSHlATqj3uuLILfSRiu+MrIopupgdRWzbYPdsYENlltutX7s50 BiWoRZl95IGM0vzR2co4UNaZshet8rKIIjngotD7N5xPmFzdvIe6jmCszNifx4QzmbFYOd tYHErHLHDv75VAVdFj3VLhReoS6iBOeT4+a3DkWVuLgM9/kiwnRmV0Spm3eX+9WXYaE9LM jLvzZKG2yXwK8QXVwU/vz/RKrFe/AtHsmkcFb8cjxTRCKHjZPcV5gMPbaD4gUA== 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 4Mbxlk4qxVzvXh; Mon, 26 Sep 2022 22:10:42 +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 28QMAgje046547; Mon, 26 Sep 2022 22:10:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28QMAggV046546; Mon, 26 Sep 2022 22:10:42 GMT (envelope-from git) Date: Mon, 26 Sep 2022 22:10:42 GMT Message-Id: <202209262210.28QMAggV046546@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: cee4fc7cada8 - main - cxgbe: Use secq(9) to manage the timestamp generations. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cee4fc7cada8244f375a6542f03d1f255c719bf1 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664230242; 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=2oyyiWWjkHATqk0BkpnLkrjeT3DEwOcms8x5z6X8W5U=; b=fhmNdas6R89kVbaJEyW1RLfDjT4uMowGMOzeKcpFSbp842d8sX/OHhjrDj3G2Hnu5opEvY b/RU2eCSY5s2JNzf7hPsnM2VOOU/6Or8wBvLUdofAqm1Fi2OW4kDVs7FPL0zPxRXijltua 6LPJJWplqq0OB/28R7RkVvD8FwI+eT0XoWMsAAQJM0onJTmzIpXJi7o1hz+sIQLXgK2nn1 IZ+TBAmwD5m/wSEO38iNTtoQ4dkic8qiWJEVvZ2EwY6QvKVEN+6EzYFOYgzWq2QAE84RUo IiI/0D8y3ujh1IqTnPxxUZbsoIHSuRbrW66OGGnMnP3mONfrf8N7jMAg+UrV8g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664230242; a=rsa-sha256; cv=none; b=o2yhgk0nVySs2GbMYbDtGu1G0OUlh9orX2UFh3RHncpzj+vPjg6mkWfCDf6GQyur8zekzR vMppsHOVWC+YQf0L/+PQh+KrL5FwcOjTz2mo1EQhBYTqQMdEkQwu8zLHj0DtcB2QuPl394 KLqf0h2z+j/GZ4uf8uz0c2SwaJgfiln14SDiWxCgzWwMezQj0bw0ECK4UWf5obCZyNMjmb E5duEtUpXroECwm/wSIQqDFcXec9ha687m9I8MeCiGTLauCrl8V+gJkDGKwddKlDHPDun1 KE66FeOgDJxdCOBn+glKhR1s+2lLDp6biyOGj/bYsSH1DyqHhIGQWzyHOVUtbw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=cee4fc7cada8244f375a6542f03d1f255c719bf1 commit cee4fc7cada8244f375a6542f03d1f255c719bf1 Author: John Baldwin AuthorDate: 2022-09-26 21:58:06 +0000 Commit: John Baldwin CommitDate: 2022-09-26 21:58:41 +0000 cxgbe: Use secq(9) to manage the timestamp generations. This is mostly cosmetic, but it also doesn't leave a gap of time where no structures are valid. Instead, we permit the ISR to continue to use the previous structure if the write to update cal_current isn't yet visible. Reviewed by: gallatin Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D36669 --- sys/dev/cxgbe/adapter.h | 3 ++- sys/dev/cxgbe/t4_main.c | 28 +++++++++++++++++----------- sys/dev/cxgbe/t4_sge.c | 11 ++++++----- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/sys/dev/cxgbe/adapter.h b/sys/dev/cxgbe/adapter.h index 9312549cf7ba..c62ada5b9225 100644 --- a/sys/dev/cxgbe/adapter.h +++ b/sys/dev/cxgbe/adapter.h @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -871,7 +872,7 @@ struct clock_sync { uint64_t hw_prev; sbintime_t sbt_cur; sbintime_t sbt_prev; - uint32_t gen; + seqc_t gen; }; struct adapter { diff --git a/sys/dev/cxgbe/t4_main.c b/sys/dev/cxgbe/t4_main.c index 9f982ca32097..25d9831c2019 100644 --- a/sys/dev/cxgbe/t4_main.c +++ b/sys/dev/cxgbe/t4_main.c @@ -1114,35 +1114,41 @@ t4_calibration(void *arg) { struct adapter *sc; struct clock_sync *cur, *nex; + uint64_t hw; + sbintime_t sbt; int next_up; sc = (struct adapter *)arg; + KASSERT((hw_off_limits(sc) == 0), ("hw_off_limits at t4_calibration")); + hw = t4_read_reg64(sc, A_SGE_TIMESTAMP_LO); + sbt = sbinuptime(); + cur = &sc->cal_info[sc->cal_current]; next_up = (sc->cal_current + 1) % CNT_CAL_INFO; nex = &sc->cal_info[next_up]; if (__predict_false(sc->cal_count == 0)) { /* First time in, just get the values in */ - cur->hw_cur = t4_read_reg64(sc, A_SGE_TIMESTAMP_LO); - cur->sbt_cur = sbinuptime(); + cur->hw_cur = hw; + cur->sbt_cur = sbt; sc->cal_count++; goto done; } - nex->hw_prev = cur->hw_cur; - nex->sbt_prev = cur->sbt_cur; - KASSERT((hw_off_limits(sc) == 0), ("hw_off_limits at t4_calibration")); - nex->hw_cur = t4_read_reg64(sc, A_SGE_TIMESTAMP_LO); - nex->sbt_cur = sbinuptime(); - if ((nex->hw_cur - nex->hw_prev) == 0) { + + if (cur->hw_cur == hw) { /* The clock is not advancing? */ sc->cal_count = 0; atomic_store_rel_int(&cur->gen, 0); goto done; } - atomic_store_rel_int(&cur->gen, 0); + + seqc_write_begin(&nex->gen); + nex->hw_prev = cur->hw_cur; + nex->sbt_prev = cur->sbt_cur; + nex->hw_cur = hw; + nex->sbt_cur = sbt; + seqc_write_end(&nex->gen); sc->cal_current = next_up; - sc->cal_gen++; - atomic_store_rel_int(&nex->gen, sc->cal_gen); done: callout_reset_sbt_curcpu(&sc->cal_callout, SBT_1S, 0, t4_calibration, sc, C_DIRECT_EXEC); diff --git a/sys/dev/cxgbe/t4_sge.c b/sys/dev/cxgbe/t4_sge.c index 161a753cc4ee..954e8f58e3e9 100644 --- a/sys/dev/cxgbe/t4_sge.c +++ b/sys/dev/cxgbe/t4_sge.c @@ -1530,16 +1530,17 @@ t4_tstmp_to_ns(struct adapter *sc, uint64_t lf) uint64_t hw_clk_div; sbintime_t sbt_cur_to_prev, sbt; uint64_t hw_tstmp = lf & 0xfffffffffffffffULL; /* 60b, not 64b. */ - uint32_t gen; + seqc_t gen; - do { + for (;;) { cur = &sc->cal_info[sc->cal_current]; - gen = atomic_load_acq_int(&cur->gen); + gen = seqc_read(&cur->gen); if (gen == 0) return (0); dcur = *cur; - atomic_thread_fence_acq(); - } while (gen != dcur.gen); + if (seqc_consistent(&cur->gen, gen)) + break; + } /* * Our goal here is to have a result that is: