From nobody Wed Jan 25 14:19:02 2023 X-Original-To: freebsd-hackers@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 4P25Yr64Zrz3bYll for ; Wed, 25 Jan 2023 14:19:12 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4P25Yq70sLz48hR for ; Wed, 25 Jan 2023 14:19:11 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of sebastian.huber@embedded-brains.de designates 85.10.215.148 as permitted sender) smtp.mailfrom=sebastian.huber@embedded-brains.de; dmarc=none Received: from sslproxy03.your-server.de ([88.198.220.132]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pKgcC-0006m2-6M for freebsd-hackers@freebsd.org; Wed, 25 Jan 2023 15:19:04 +0100 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy03.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pKgcC-000Nsf-3P for freebsd-hackers@freebsd.org; Wed, 25 Jan 2023 15:19:04 +0100 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id BF8A9480064 for ; Wed, 25 Jan 2023 15:19:03 +0100 (CET) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Xv7yhDbzAsWn for ; Wed, 25 Jan 2023 15:19:03 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 6EC4D4801E4 for ; Wed, 25 Jan 2023 15:19:03 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id P_N22QHqCvJv for ; Wed, 25 Jan 2023 15:19:03 +0100 (CET) Received: from [10.10.171.6] (unknown [10.10.171.6]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 4AF60480064 for ; Wed, 25 Jan 2023 15:19:03 +0100 (CET) Message-ID: <1ced1234-2e80-9137-2ae7-f98174de819d@embedded-brains.de> Date: Wed, 25 Jan 2023 15:19:02 +0100 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US To: FreeBSD Hackers From: Sebastian Huber Subject: hardpps() jitter detection Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldi-networks.de X-Virus-Scanned: Clear (ClamAV 0.103.7/26792/Wed Jan 25 09:49:26 2023) X-Spamd-Result: default: False [-3.25 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-0.99)[-0.993]; NEURAL_HAM_SHORT(-0.96)[-0.957]; R_SPF_ALLOW(-0.20)[+ip4:85.10.215.148]; MIME_GOOD(-0.10)[text/plain]; FROM_EQ_ENVFROM(0.00)[]; ASN(0.00)[asn:24940, ipnet:85.10.192.0/18, country:DE]; MIME_TRACE(0.00)[0:+]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; TO_DN_ALL(0.00)[]; R_DKIM_NA(0.00)[]; DMARC_NA(0.00)[embedded-brains.de]; RCVD_TLS_LAST(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_SEVEN(0.00)[8]; FROM_HAS_DN(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; HAS_X_AS(0.00)[] X-Rspamd-Queue-Id: 4P25Yq70sLz48hR X-Spamd-Bar: --- X-ThisMailContainsUnwantedMimeParts: N Hello, I have a question related to the hardpps() jitter detection. We have=20 currently this code: void hardpps(struct timespec *tsp, long nsec) { long u_sec, u_nsec, v_nsec; /* temps */ l_fp ftemp; NTP_LOCK(); /* * The signal is first processed by a range gate and frequency * discriminator. The range gate rejects noise spikes outside * the range +-500 us. The frequency discriminator rejects input * signals with apparent frequency outside the range 1 +-500 * PPM. If two hits occur in the same second, we ignore the * later hit; if not and a hit occurs outside the range gate, * keep the later hit for later comparison, but do not process * it. */ time_status |=3D STA_PPSSIGNAL | STA_PPSJITTER; time_status &=3D ~(STA_PPSWANDER | STA_PPSERROR); pps_valid =3D PPS_VALID; u_sec =3D tsp->tv_sec; u_nsec =3D tsp->tv_nsec; if (u_nsec >=3D (NANOSECOND >> 1)) { u_nsec -=3D NANOSECOND; u_sec++; } v_nsec =3D u_nsec - pps_tf[0].tv_nsec; if (u_sec =3D=3D pps_tf[0].tv_sec && v_nsec < NANOSECOND - MAXFREQ) goto out; pps_tf[2] =3D pps_tf[1]; pps_tf[1] =3D pps_tf[0]; pps_tf[0].tv_sec =3D u_sec; pps_tf[0].tv_nsec =3D u_nsec; /* * Compute the difference between the current and previous * counter values. If the difference exceeds 0.5 s, assume it * has wrapped around, so correct 1.0 s. If the result exceeds * the tick interval, the sample point has crossed a tick * boundary during the last second, so correct the tick. Very * intricate. */ u_nsec =3D nsec; if (u_nsec > (NANOSECOND >> 1)) u_nsec -=3D NANOSECOND; else if (u_nsec < -(NANOSECOND >> 1)) u_nsec +=3D NANOSECOND; pps_fcount +=3D u_nsec; if (v_nsec > MAXFREQ || v_nsec < -MAXFREQ) goto out; time_status &=3D ~STA_PPSJITTER; The v_nsec value is used to reject a sample if the time difference is=20 out of range. The v_nsec value is computed using the current time at the=20 PPS event (tsp) and the time at the previous PPS event (pps_tf[0]).=20 These time points are measured by a clock which is adjusted by the=20 hardpps() outputs. Wouldn't it be better to use the uncontrolled input=20 value (nsec) for the jitter detection? This is how Linux does it: https://github.com/torvalds/linux/blob/master/kernel/time/ntp.c#L1055 Is this maybe a typo, and the if (v_nsec > MAXFREQ || v_nsec < -MAXFREQ) should be if (u_nsec > MAXFREQ || u_nsec < -MAXFREQ) ? --=20 embedded brains GmbH Herr Sebastian HUBER Dornierstr. 4 82178 Puchheim Germany email: sebastian.huber@embedded-brains.de phone: +49-89-18 94 741 - 16 fax: +49-89-18 94 741 - 08 Registergericht: Amtsgericht M=C3=BCnchen Registernummer: HRB 157899 Vertretungsberechtigte Gesch=C3=A4ftsf=C3=BChrer: Peter Rasmussen, Thomas= D=C3=B6rfler Unsere Datenschutzerkl=C3=A4rung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/