From nobody Mon Feb 27 22:12:19 2023 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 4PQZVW5DJHz3tDYb; Mon, 27 Feb 2023 22:12:19 +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 4PQZVW4VyXz3QWg; Mon, 27 Feb 2023 22:12:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677535939; 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=grPO3u8G+83O0ZJ8tzphq2TUVqCYQKqnA6//RQbAcyk=; b=ovdC6sxVaA3KaklpeidtR5i4Mu/iwid0p4NJZb8ZzpcqlvYCT9aijFpnlygSPW/x/fUa7g upn4Bd85kr8MymPUQYNY7VanKc57/7EHDv1Vn0/48V4Xxwt1zF4yCZYDlSm0QCAslPPjpT q7hz1sC9VErasVPbyfx6f9wSVkDG2Wwg8CFvIYLUUnv4S4/yekSc+S/2vyacQP3H/DHRh6 66PT3xfo2R0OqW7vMTF6OsGEIEG92Z8pPN9v/hBC4r3t5pful6UOUgWz8KEZ/ZWwYDnsCk ceF42ICDjOIKdbHNUuiugBsXntL8zC3Fis4jRZgUVnp2lhqIcYcnqlLqSu35bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677535939; 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=grPO3u8G+83O0ZJ8tzphq2TUVqCYQKqnA6//RQbAcyk=; b=m3WY32btdR0YcaZ4cIDXBULeUxQiz3iEFaIy8lUXchlPiIwxQl8QiWECl70kONNJqPGOFI BALvaLnl8MqRB4pkZAzAhbRbaOmftqBCac0nJNuejxdD4v11W9LUNcAO9lTsWFYQ01uxgY XXhVAUevLU1XVicf2AiLZoFvvUeN3FUW4OJk4/yrFYrBkh9FxVo/B0Vx3DrlDmepwicOCu d1PoDxjsYq3egNVHnq3Ik6HiX/wAN87PfOOke0txsgQXOmh0DLBM4Din3NDP46KBm6BT+O LrmTPCW4ygz6glS7JViYvEK8cqohXY9dqhtU/8YRZjN5Wba5TD9YlI6PAjNmBA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677535939; a=rsa-sha256; cv=none; b=X+GRbr+BDWS7gPG3+65oW8+DYbQ7Rsb/5z1kPSPVGgwdkue5EyH0li9xvHMQaWXz/SikGL diimXJqiyfObyq/PHA1anKxEUhAxDqFRmr/ViXNyucW3ykohUAnsRxInkFsjYPOlVYZ3jw s1XR6z+Dhjwq4Rh2Vhx6Vi8Lzv2/WMeUwDTHup4brM/AK2RR7hsNjUWK6N5HRL610FgwzG 5LT0cdhSGMOHbRgMMUnrtwNFx29+C2r2abzQKd7UKtNBP+bD8HNbEnPwi6TeGXOznnniIL 9zRL4TYwoIOg5wYHoY4l9NvnCDog5CaUFArKXbHHRm8kkOcttTwdWOxEsrvDqA== 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 4PQZVW3c2szjXh; Mon, 27 Feb 2023 22:12:19 +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 31RMCJEa028800; Mon, 27 Feb 2023 22:12:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31RMCJx0028799; Mon, 27 Feb 2023 22:12:19 GMT (envelope-from git) Date: Mon, 27 Feb 2023 22:12:19 GMT Message-Id: <202302272212.31RMCJx0028799@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: fd88f4e190bc - main - pps: Simplify capture and event processing 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: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fd88f4e190bc0a56f8d30179900553ce12d1c0d7 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=fd88f4e190bc0a56f8d30179900553ce12d1c0d7 commit fd88f4e190bc0a56f8d30179900553ce12d1c0d7 Author: Sebastian Huber AuthorDate: 2023-02-27 21:49:09 +0000 Commit: Warner Losh CommitDate: 2023-02-27 22:10:55 +0000 pps: Simplify capture and event processing Use local variables for the captured timehand and timecounter in pps_event(). This fixes a potential issue in the nsec preparation for hardpps(). Here the timecounter was accessed through the captured timehand after the generation was checked. Make a snapshot of the relevent timehand values early in pps_event(). Check the timehand generation only once during the capture and event processing. Use atomic_thread_fence_acq() similar to the other readers. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/604 --- sys/kern/kern_tc.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c index 20520adc0aba..b466fd4399e4 100644 --- a/sys/kern/kern_tc.c +++ b/sys/kern/kern_tc.c @@ -1772,14 +1772,14 @@ pps_capture(struct pps_state *pps) #endif tc = th->th_counter; pps->capcount = tc->tc_get_timecount(tc); - atomic_thread_fence_acq(); - if (pps->capgen != th->th_generation) - pps->capgen = 0; } void pps_event(struct pps_state *pps, int event) { + struct timehands *capth; + struct timecounter *captc; + uint64_t capth_scale; struct bintime bt; struct timespec ts, *tsp, *osp; u_int tcount, *pcount; @@ -1798,9 +1798,17 @@ pps_event(struct pps_state *pps, int event) /* Nothing to do if not currently set to capture this event type. */ if ((event & pps->ppsparam.mode) == 0) return; + + /* Make a snapshot of the captured timehand */ + capth = pps->capth; + captc = capth->th_counter; + capth_scale = capth->th_scale; + tcount = capth->th_offset_count; + bt = capth->th_bintime; + /* If the timecounter was wound up underneath us, bail out. */ - if (pps->capgen == 0 || pps->capgen != - atomic_load_acq_int(&pps->capth->th_generation)) + atomic_thread_fence_acq(); + if (pps->capgen == 0 || pps->capgen != capth->th_generation) return; /* Things would be easier with arrays. */ @@ -1838,25 +1846,19 @@ pps_event(struct pps_state *pps, int event) * If the timecounter changed, we cannot compare the count values, so * we have to drop the rest of the PPS-stuff until the next event. */ - if (pps->ppstc != pps->capth->th_counter) { - pps->ppstc = pps->capth->th_counter; + if (__predict_false(pps->ppstc != captc)) { + pps->ppstc = captc; *pcount = pps->capcount; pps->ppscount[2] = pps->capcount; return; } /* Convert the count to a timespec. */ - tcount = pps->capcount - pps->capth->th_offset_count; - tcount &= pps->capth->th_counter->tc_counter_mask; - bt = pps->capth->th_bintime; - bintime_addx(&bt, pps->capth->th_scale * tcount); + tcount = pps->capcount - tcount; + tcount &= captc->tc_counter_mask; + bintime_addx(&bt, capth_scale * tcount); bintime2timespec(&bt, &ts); - /* If the timecounter was wound up underneath us, bail out. */ - atomic_thread_fence_acq(); - if (pps->capgen != pps->capth->th_generation) - return; - *pcount = pps->capcount; (*pseq)++; *tsp = ts; @@ -1890,9 +1892,9 @@ pps_event(struct pps_state *pps, int event) */ tcount = pps->capcount - pps->ppscount[2]; pps->ppscount[2] = pps->capcount; - tcount &= pps->capth->th_counter->tc_counter_mask; + tcount &= captc->tc_counter_mask; scale = (uint64_t)1 << 63; - scale /= pps->capth->th_counter->tc_frequency; + scale /= captc->tc_frequency; scale *= 2; bt.sec = 0; bt.frac = 0;