Live data from Hacker News

FPGA NTP Server

research.wand.net.nz

21–30 of 70 posts

Re: FPGA NTP Server

#21
post #11
post #10

Earlier quoted context omitted.

I personally enjoyed the challenge of setting up PTP at home. Why would a hacker scoff at nanosecond-level timekeeping —- isn’t the entire internet a “telco/enterprise” thing?

did you write about your experience? I am interested in this but have very limited knowledge about it at this point.

Install linuxptp on the boxes you designate as grandmaster and client. On your grandmaster clock host:

  ptp4l -i eth0 -m
On the client:

  ptp4l -i eth0 -s &
If you want to sync client system clock and watch the synchronization process:

  phc2sys -a -r -m

Re: FPGA NTP Server

#22
Interesting project, especially to gain insights into the FPGA programming part.

I think it is essentially a mixture of PTP and NTP now.

I guess this will work within the same local network, as the major inaccuracy of NTP comes from the asymmetric path delays at the network layer over the Internet.

PTP solves this by incorporating these hardware timestamps exactly. But this works only within the same LAN.

Here is an interesting PTP core:

https://github.com/freecores/ha1588

Yes it is "old" but that is typically fine with HW projects.

Re: FPGA NTP Server

#24
There exists an open source NTP server project by Netnod in Sweden.

The servers has been up and running, providing NTP including NTP AUTH services since about 2015. The FPGA based platform also provides experimental NTS services since about last summer.

https://www.netnod.se/ntp/connect-to-ntp-servers

https://github.com/Netnod/FPGA_NTP_SERVER

Re: FPGA NTP Server

#25
post #22

Interesting project, especially to gain insights into the FPGA programming part. I think it is essentially a mixture of PTP and NTP now. I guess this will work within the same local network, as the major inaccuracy of NTP comes from the asymmetric path delays at the network layer over the Internet. PTP solves this by incorporating these hardware timestamps exactly. But this works only within the same LAN. Here is an…

The main difference between PTP and NTP is that PTP relies on hardware support in switches and routers. Those are not cheap. If they had the same support for NTP, it would perform as well.

A highly accurate stratum-1 NTP server can be build with a common computer NIC. No need to mess with FPGAs (unless that's your thing). The Intel I210 is about $50. It has a PPS input and output. With some calibration, the timestamping can be accurate to few tens of nanoseconds.

NTP can work very well between directly connected NICs. But without hardware support in the switches/routers, that accuracy degrades quickly in the network. A single switch can easily add hundreds of nanoseconds worth of jitter and tens of nanoseconds worth of asymmetry.

Re: FPGA NTP Server

#26
For less demanding users, a Raspberry Pi and a cheap GPS module can do the trick[1]. I get less than +/-300us in error according to chronyc on the clients.

Note that if you get one of the GPS modules, some do not expose the PPS pin to the headers, so might require some board modification (they use it just to drive a LED). I got one like this[2] that has it exposed.

Also note that the small antennas only work outside, the slightly larger square ones work inside but very near a window. I got an active antenna[3] as I wanted it more inside the room.

And finally the NEO-6M module I linked to is quite old, the newer NEO-7M and NEO-8M lock on faster etc, but for me this was sufficient.

Oh and I had to disable serial echo[4], almost forgot about that.

[1]: https://n4bfr.com/2020/04/raspberry-pi-with-chrony/2/

[2]: https://www.aliexpress.com/item/4001136384325.html?spm=a2g0s...

[3]: https://www.aliexpress.com/item/33059221782.html?spm=a2g0s.9...

[4]: https://raspberrypi.stackexchange.com/a/104296

Re: FPGA NTP Server

#27
> Microprocessor based Network Time Protocol (NTP) servers suffer from a large amount of timestamp jitter, due to the hardware and Operating System (OS) being shared among other applications.

So instead of configuring Linux correctly and dedicating a core for your NTP you have created custom hardware. Congratulations, now you have two problems.

I have been working on algorithmic trading and it is not that hard to reliably (like 100% of the time) respond within couple microseconds.

You will never notice it, though, because your network will introduce way more variability. This is especially the case with NTP which usually is a single box shared between large number of servers throughout your network.

Re: FPGA NTP Server

#29

Earlier quoted context omitted.

ptp is If you look at the white rabbit FPGA PTP updates, its in the ns range. Any kind of GPS + most intel nics will get you PTP with an accurate clock. If you didn't need to sync too many devices you could use a single system with a bunch of nics as your "switch".

This post didn’t sound right to me, but I realized that my raspi4 GPS NTP server has been running ntp and not chrony. Chrony is better at modeling non deterministic timing behavior, so I swapped to that. It’s been ten minutes now and chronyc tracking has been marching the offset down. It’s sub 1 us at this point. System time : 0.000000123 seconds fast of NTP time Last offset : +0.000000366 seconds How to get this pre…

Assuming you're using a PPS signal and a kernel driver, presumably there's an interrupt handler or perhaps a capture timer peripheral that is capturing a hardware timer when the PPS edge occurs. It doesn't matter too much when the userspace code gets around to adjusting the hardware timer as long as it can compute the difference between when the PPS edge came in and when it should have come in. The Linux API for fine tuning the system time works in deltas rather than absolute timestamps, so it is once again fairly immune to userspace scheduling jitter.

Even good hardware oscillators can have a wide amount of drift, say 50uS per second, but they tend to be stable over several minutes outside of extreme thermal environments. Therefore, it's pretty easy to estimate and compensate for drift using a PPS signal as a reference. Presumably, that compensation is partially what takes a while for the time daemon to converge on.

Additionally, the clock sync daemon likely takes a while to converge because it isn't directly controlling the system time. Rather, it is sending hints to the kernel for it to adjust the time. The kernel decides how best to do that, and it does it in a way that attempts to avoid breaking other userspace programs that are running. For example, it tries to keep system time monotonically increasing. This means that there's relatively low gain in the feedback loop, and so it takes a while to cancel out error.

It's possible for a userspace program to instead explicitly set system time, but that really isn't intended to be used in Linux unless time is more than 0.5 seconds off. The API call to do that is inherently vulnerable to userspace scheduling jitter, but it's fine since 0.5 seconds is orders of magnitude longer than the expected jitter. You get the system time within the ballpark, and then incrementally adjust it until it's perfect.

If you're not using a kernel driver to capture the PPS edge's timestamp, then you're going to have a rougher time. Either you're just going to have to accept the fact that you can't do better than the scheduling jitter (other than assume it averages out), or you're going to have to do something clever/terrible. One idea would be to have your userspace process go to sleep until, say, 1ms before you expect the next PPS edge to come in. Then, go into a tight polling loop until the edge occurs. As long as reading the PPS pin from userspace is non-blocking and your process doesn't get preempted, you should be able to get at least within microseconds. You can poll system time in the same tight loop, allowing you to fairly reliably detect whether the process got preempted or not.

Re: FPGA NTP Server

#30
post #27

> Microprocessor based Network Time Protocol (NTP) servers suffer from a large amount of timestamp jitter, due to the hardware and Operating System (OS) being shared among other applications. So instead of configuring Linux correctly and dedicating a core for your NTP you have created custom hardware. Congratulations, now you have two problems. I have been working on algorithmic trading and it is not that hard to rel…

Yes, doing things fast is the unremarkable part. Doing things fast and synchronously over the network is the trickier one.
Post reply on HN