From owner-freebsd-arm@freebsd.org Thu Aug 15 21:05:20 2019 Return-Path: Delivered-To: freebsd-arm@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 14749B6480 for ; Thu, 15 Aug 2019 21:05:20 +0000 (UTC) (envelope-from per@hedeland.org) Received: from outbound1g.eu.mailhop.org (outbound1g.eu.mailhop.org [52.28.6.212]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 468f9V3lxzz4QgJ for ; Thu, 15 Aug 2019 21:05:17 +0000 (UTC) (envelope-from per@hedeland.org) ARC-Seal: i=1; a=rsa-sha256; t=1565903116; cv=none; d=outbound.mailhop.org; s=arc-outbound20181012; b=qMfXwzpj/t0BGglLyRLyq6yiMkY46NeVkDZOvTMHaTbQHNGRzqDsWF7XoIF2wa61mh3LLEYQnPK8E gndeHg5DQZXmQefC4GeHfuYPlAcSD41P+mkPNcHa4F09talBIBRaDjMp72pJBZybLv63o4Fe12K1lb GagxBAWLmeW4GrXaUzq/hc/Kox6hBkobyh4de/qmwdKhyWXGeyt0Wu/ofJvA5MwWjMLxjMmIZ3PoE9 9TYrsgV+p7J2fomDoUmVoY8JXhuxM34PDzApnArBH1BGdM1kgg3k3eayrfgpvotyo39bp7/8mbN8UL 0SDSXgJzcYciemWreXr8VfzSznJfstA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=arc-outbound20181012; h=content-transfer-encoding:content-type:in-reply-to:mime-version:date: message-id:from:references:cc:to:subject:dkim-signature:from; bh=oRVuFz3KTOGTk+BgCdNYZ78ljzApZrcAKrUsaZaDqF0=; b=oCofQ2pmuMFqsVVPdLCDS4ZYwbzH0uO3oQfWLPgevG6YWx46wWQbS0wHZ3YRGWVbXGlLuS18ojJs0 SxUOWv7Z8txnjRWbsBYCIUB4ouQpozwRzgORLryZ+NKSkmMpvaQpAD4vHyddRpMWHTS33u9wnDfUS9 1mdjPxiDghwjH5VhrRreADrIGyNPTeT7CwAKlHWcwENEQEpiKeRT5axzlOQ8cMdHF++gc2VeWDILX+ CpRUU1bH2l4lZumRGBW42DoKHQNg5Vdeym/96PcJ5D55HG7WmhRwgFjkk+bvHpowk2Hjqx8kZfPs8f egoe+mSVnam/ct2HunV0LZfXhREhxlQ== ARC-Authentication-Results: i=1; outbound3.eu.mailhop.org; spf=none smtp.mailfrom=hedeland.org smtp.remote-ip=81.228.157.209; dmarc=none header.from=hedeland.org; arc=none header.oldest-pass=0; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=dkim-high; h=content-transfer-encoding:content-type:in-reply-to:mime-version:date: message-id:from:references:cc:to:subject:from; bh=oRVuFz3KTOGTk+BgCdNYZ78ljzApZrcAKrUsaZaDqF0=; b=k33nB8j3A3oemPgnwuCktYqtG7O0K+zk2dP88R1fbRgolo43lDPRQxa9xTNTv2qWZ0b328XWnF/df vSpuIEyPQjfvIJJSHP9FDoKe7+vxEc/VyCvGut1flBTuEcHq06WNOiuka4T1EROeueTEzf1c/ifc7y ctUvmTI6jTjh6LvZs/Q0GaEQ62jjwBMzhfJGREm/CMoXR8eeIGaNIXrtb65n7OkfoOkj60NbfBGYE5 oHGZgp4FLz8CCSYpLd6TMaV3srlgg2d1eRq89fJ/Dbsg4cvfLlr7ZogPC3Cv0dK5XG7H3v0FfflRp3 PFKKN5InbY5Ugycpdupy3/84dHO5qKw== X-MHO-RoutePath: cGVyaGVkZWxhbmQ= X-MHO-User: 5e6c9272-bfa0-11e9-98b8-25195f42ee1c X-Report-Abuse-To: https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information X-Originating-IP: 81.228.157.209 X-Mail-Handler: DuoCircle Outbound SMTP Received: from hedeland.org (unknown [81.228.157.209]) by outbound3.eu.mailhop.org (Halon) with ESMTPSA id 5e6c9272-bfa0-11e9-98b8-25195f42ee1c; Thu, 15 Aug 2019 21:05:11 +0000 (UTC) Received: from pluto.hedeland.org (pluto.hedeland.org [10.1.1.5]) by tellus.hedeland.org (8.15.2/8.15.2) with ESMTPS id x7FL5AwG043725 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Thu, 15 Aug 2019 23:05:11 +0200 (CEST) (envelope-from per@hedeland.org) Subject: Re: Is it a good idea to use a usb-serial adapter for PPS? Yes, it is. To: Ian Lepore Cc: freebsd-arm@freebsd.org References: <69a9bed3-4d0a-f8f6-91af-a8f7d84ee307@hedeland.org> <345bae77417c2495f55799b4c7ca2784f4ece9ed.camel@freebsd.org> <7312032d-2908-9414-0445-6b442c3a02e5@hedeland.org> <523b6f0a0fa5f2aeec298fa74df25d3c4af66acc.camel@freebsd.org> <0426fc8b-5398-d8ab-561e-7823c24403a5@hedeland.org> <24b0eaf25b64d6098b390df092866c69e352d859.camel@freebsd.org> From: Per Hedeland Message-ID: <16c91be1-6f2a-b26d-22c7-be8e4ba8eec0@hedeland.org> Date: Thu, 15 Aug 2019 23:05:10 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <24b0eaf25b64d6098b390df092866c69e352d859.camel@freebsd.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 468f9V3lxzz4QgJ X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=outbound.mailhop.org header.s=dkim-high header.b=k33nB8j3; dmarc=none; spf=none (mx1.freebsd.org: domain of per@hedeland.org has no SPF policy when checking 52.28.6.212) smtp.mailfrom=per@hedeland.org X-Spamd-Result: default: False [-5.53 / 15.00]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[outbound.mailhop.org:s=dkim-high]; HAS_XOIP(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[hedeland.org]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[outbound.mailhop.org:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[212.6.28.52.list.dnswl.org : 127.0.20.0]; NEURAL_HAM_SHORT(-0.98)[-0.977,0]; RECEIVED_SPAMHAUS_PBL(0.00)[209.157.228.81.khpj7ygk5idzvmvt5x4ziurxhy.zen.dq.spamhaus.net : 127.0.0.11]; R_SPF_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; IP_SCORE(-1.25)[ipnet: 52.28.0.0/16(-4.87), asn: 16509(-1.35), country: US(-0.05)]; ASN(0.00)[asn:16509, ipnet:52.28.0.0/16, country:US]; MID_RHS_MATCH_FROM(0.00)[]; SUBJECT_HAS_QUESTION(0.00)[]; ARC_ALLOW(-1.00)[i=1] X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Porting FreeBSD to ARM processors." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Aug 2019 21:05:20 -0000 On 2019-08-15 17:49, Ian Lepore wrote: > On Thu, 2019-08-15 at 13:46 +0200, Per Hedeland wrote: >> On 2019-08-09 22:17, Ian Lepore wrote: >>> On Fri, 2019-08-09 at 21:36 +0200, Per Hedeland wrote: >>>> On 2019-08-09 17:28, Ian Lepore wrote: >>>>> On Thu, 2019-08-08 at 22:26 +0200, Per Hedeland wrote: >>>>>> On 2019-08-07 18:53, Ross Alexander wrote: >>>>>>> In Message-ID: < >>>>>>> B9EFA4D4-C1AD-4181-B421-F6BD53434FA5@dons.net.au>, >>>>>>> someone wrote [sorry, attrib trail is a little blurry ed.]: >>>>>>> >>>>>>>>> Most people are not worried about their kernel clock >>>>>>>>> being >>>>>>>>> 200 >>>>>>>>> microseconds off from UTC, even if they're using the >>>>>>>>> PPS >>>>>>>>> signal >>>>>>>>> from a >>>>>>>>> GPS receiver. So I think most people should feel >>>>>>>>> completely at >>>>>>>>> ease >>>>>>>>> using a USB serial adapter as the input device for a >>>>>>>>> PPS >>>>>>>>> signal. >>>>>>> >>>>>>> Some people do worry, although getting PPS to work over USB >>>>>>> is >>>>>>> a >>>>>>> fine >>>>>>> first step and I'm grateful for the breadcrumb trail. >>>>>> >>>>>> For those that do worry, you can of course tell ntpd to >>>>>> correct >>>>>> for a >>>>>> semi-fixed offset (via the 'time1' option to the 'fudge' >>>>>> command) >>>>>> - >>>>>> once you know how large the offset is... More important is a >>>>>> low >>>>>> jitter, and 20-30 microseconds seems quite good. >> >> [snip] >> >>>> Would you object to >>>> me posting an article with a *link* to your message >>>> (i.e. >>>> > https://lists.freebsd.org/pipermail/freebsd-arm/2019-August/020263.html >>>> ) >>>> in the newsgroup? >>> >>> It might be better to use the link to the copy I sent to the >>> freebsd- >>> usb list, since it's more directly on-topic: >>> >>> > https://lists.freebsd.org/pipermail/freebsd-usb/2019-August/016078.html >>> >>> I also think it would be wise to add a caveat that the results are >>> for >>> FreeBSD. I would expect linux performance to be similar. But for >>> Windows, all bets are off; Windows drivers for usb-serial devices >>> are >>> said to vary wildly in quality depending on the vendor. >> >> OK, I took it to the newsgroup, and while the initial comments were >> pretty much "it's impossible to get good results via USB" even though >> your test seemed to show that it wasn't, after some discussion it >> seems quite strange to me too that you get a pretty much fixed offset >> and low jitter, since the USB communication including DCD/CTS >> detection is apparently based on polling from the host. >> >> I have a theory that your making the kernel clock be based on the 10 >> MHz clock also ended up locking the USB poll frequency to that clock, >> and thus to the PPS signal - this would certainly explain the result. >> Do you think this is a possibility? Would it be possible for you to >> re-run the test without modifying the kernel clock? (I do understand >> that the results will be harder to interpret with the drift, and >> ntpd's correction of it, coming into play.) >> >> --Per >> > > I'm not sure what you mean by "modifying the kernel clock". The kernel > clock always runs on some frequency source. Typically it's derived > from the cheap 24 MHz crystal that clocks the SoC, sometimes after > being scaled up to 66 MHz by a phase-fractional PLL within the SoC. I > arranged to use a very stable nearly-drift-free frequency source > instead of a cheap crystal for counting time in the kernel. > > The kernel clock has nothing to do with usb, including polling > intervals; the usb controller hardware handles that, and the root > source clock for that is the cheap 24 MHz crystal. The thing that made me hypothesize that the kernel clock *could* have *something* to do with the USB polling frequency was this observation in https://blog.dan.drown.org/pps-over-usb (link provided by one of the posters in the newsgroup, though he didn't refer specifically to this): Looking closer at the USB latency, you can see the PPS drifting relative to the host schedule of polling the USB device for its status. The system clock error was 2.215ppm during this time period, and this drift matches that error exactly. This probably means USB on this system shares the same clock as the system clock. This hardware is a Raspberry Pi 2, and I suspect it won't be true for other platforms. So at least on RPi 2, there appears to be a relation between the "normal" system/kernel clock and the USB polling frequency. But I have no idea if there is such a relation on the system you used, and even in that case, *I* certainly can't see how using a different source for the kernel clock could affect the USB polling frequency, which is why asked if you thought that it was a possibility... > I think people are massively confused by usb. A usb 2.0 bus runs at > 480MHz. That means the time to transmit a packet describing a usb > serial pin-change event takes literally a dozen or so nanoseconds. The > time it takes to transmit an entire sector of disk data is 2 > microseconds; even if continuous disk data is flowing, the usb serial > adapter gets its round-robin opportunity to send a packet on the bus in > between them. Yes, the transmission speed is obviously not a problem, the question is about varying latency due to the polling. > A USB 2.0 bus spends most of its time idle. The > devices on the bus are polled, but the polling happens in time slots > that are 125 microseconds wide. There's just no reason for a lot of > jitter or latency. In the newsgroup it was claimed that the polling frequency was 1 kHz for USB 1.1 and 4 kHz for USB 2.0, but it seems it should indeed be 8 kHz for 2.0 "high" speed. And your test used one USB 1.1 device and one 2.0 device. And "a lot" is a bit subjective, but for any polling at a frequency that isn't an exact integral number of periods per second, there will be a latency between the start of the PPS pulse and the detection in the host that *varies* in an interval the size of the polling interval. I believe that interval should thus be expected to be 1000 microseconds for 1.1 and 125 microseconds for 2.0. Your ntpq output showed an offset close to 200 microseconds for both devices, and I *assumed* that it was more or less constant and thus ntpd could trivially be told to correct for it - but maybe that assumption was incorrect, there was only one instance of ntpq output? If it actually varied in an interval per above, I would expect the jitter to be significantly higher though. And if it *is* more or less constant, can you explain how this is possible? Even the 2.0 125 microsecond case should be clearly visible in the offset reported by ntpd across a sequence of ntpq requests. > I'm not on a crusade to change the minds of people who make judgements > based on gut feelings and reject objective measurements. I put the > measurements out there, and I described the measurement methodology. > (Precision timing is what I do for a living, btw.) I'm perfectly > willing to explain the methodology in more detail or help interpret the > results, but I'm not going to butt heads with people who just reject > data they don't like for emotional reasons. Well, I guess a problem here is that it's my confused head that is butted between yours and those of the supposedly-experts that participate in the NTP newsgroup/maillist:-) - you already declined to participate there, and I don't expect that any of them will take the trouble to participate here. Maybe we'll just have to leave it at that... --Per