From nobody Fri Nov 11 01:48:24 2022 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 4N7hS91SXwz4f3vs; Fri, 11 Nov 2022 01:48:25 +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 4N7hS911mHz3KhB; Fri, 11 Nov 2022 01:48:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668131305; 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=KhrID4QbEwExY6gzSh15mHwYGYKsPosLyYshedMzL5A=; b=rbiHiL3qB15V4cvKnrYoI4njt20bgSDhMScERryahE+TPh6cvmnm49+kJ1n7FSlwyfRkQB WOYb0xaL2xuTxLFPN5MvnJKpoGfc+TttYC0m054pw4C0uHZQuYSH24X5abzcknZ53kStOo 16aqUzdY6tYO96caA3kn9gTDhEwklsIk/cI81M+8zeATkDJnqF0mUi35clOyBAxRUfKynE bnDg7OCUd3RhjFm8KSuUrz/qnnEt0kfggkC5i9CUr2nfe4aTf6Rk38mpkTk0jM7UkN+lWr cDTfP7QSMjhpMI3UGLi/+/SDqQO/Q24RszbrMfHMBaTU0HTrD7rjvljWym9KPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668131305; 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=KhrID4QbEwExY6gzSh15mHwYGYKsPosLyYshedMzL5A=; b=bTpJmQ1+jpWI2m5oOE4uPsCU63jsgSgyRB1+OZfOQuxH0Uf3G25i5DjVkcqdxmOz84CINA Rih55FjF9pkUVNvudAx0Q0miUC5dmY9WFIFf+gC6E1/SS6sWyViRwy+8g/yt1ssYsAFVfb mQNOPqWnVcSKy46GYG4ocQhOo9qd9NHLBHlwIAjjQvPjRwru1VLUI5IQWAN4uZ8zEJNcAG XKn1vziSZc484q6jbWAVHyvxA069KTGMLPSIf5YVzDfDrnT6uRDBKRexJ5Vv5H4+Qa2Eid HEMOq2mX4EooC3Eh7SotHgUCKBS7qvCBuJCwDcR5GLUgdCtgomslZ/X4xNAGUw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668131305; a=rsa-sha256; cv=none; b=f1+auNXaR6epikRG6uwWV5DrSgFm+Yt6h5QC/GVLVA9k10PqjoVSADrn3VV3MVYAPoXUrr XYiXeyf6MOhkXQIbpsgTuLah3s47XQswIilfi6cJem9IHAdQTK5ytTjkMP0TWnnUBhPRyZ /d2ueeOIrd2VJOwvNdLT+01S/gvBJ5etbJ2Bsh13nSEYY8XHnAN7KlqgbTSsF+u+FAesHp av7vBZ440NhsuLZ9CcxGqKA+E4n/2wBGHnAJJ+ONQPj5T0WKacQHzDYDp+Hyf8hYpNONHz 0wTF4kRqhtHa0GIn1QDC6SDGos4+QXptUG18OYXc26KEQwxzZ8xvuFIwdioepg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4N7hS907qxzPLG; Fri, 11 Nov 2022 01:48:25 +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 2AB1mOLq056588; Fri, 11 Nov 2022 01:48:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AB1mO0k056584; Fri, 11 Nov 2022 01:48:24 GMT (envelope-from git) Date: Fri, 11 Nov 2022 01:48:24 GMT Message-Id: <202211110148.2AB1mO0k056584@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: f771c03297b0 - stable/13 - cxgbe: Use secq(9) to manage the timestamp generations. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f771c03297b0b187c63365aac061346748388e6d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=f771c03297b0b187c63365aac061346748388e6d commit f771c03297b0b187c63365aac061346748388e6d Author: John Baldwin AuthorDate: 2022-09-26 21:58:06 +0000 Commit: John Baldwin CommitDate: 2022-11-11 01:26:44 +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 (cherry picked from commit cee4fc7cada8244f375a6542f03d1f255c719bf1) --- 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 4d246512b868..9e6ccaf31754 100644 --- a/sys/dev/cxgbe/adapter.h +++ b/sys/dev/cxgbe/adapter.h @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -867,7 +868,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 eff4db09aa12..b21b5a795fe3 100644 --- a/sys/dev/cxgbe/t4_main.c +++ b/sys/dev/cxgbe/t4_main.c @@ -1115,35 +1115,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 fc8a55111a4c..defd7d996f10 100644 --- a/sys/dev/cxgbe/t4_sge.c +++ b/sys/dev/cxgbe/t4_sge.c @@ -1520,16 +1520,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: