Friday, October 9, 2020

10th of October

Marks Rpi Cluster is running 24/7. It currently consists of:
2 x Pi4 (2GB) as support nodes
3 x Pi4 (8GB) compute nodes
10 x Pi3 compute nodes

The Pi4 compute nodes are running Rosetta and Einstein in a 50/50 split. The Pi3 compute nodes are running Einstein work.


NTP
It stands for Network Time Protocol. It allows computers to get the time from other servers so they can keep their internal clock accurate. This is particularly relevant to the Rpi as it doesn't have a battery-backed clock and needs to sync the clock when it first powers up. First install the ntp package with the following command:

sudo apt update && sudo apt install ntp -y

Once installed edit the /etc/ntp.conf file and add some pool statements. There is already a reference to the Debian servers. Remove it or comment it out by putting a # symbol at the beginning of the line. Add the following lines.

server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburst

In my case I use au.pool.ntp.org as I am based in Australia. What this does is tell ntp to get its time from the ntp pool. The servers change every hour in order to spread the load. Once you have changed the config file restart the service with the following command:

sudo systemctl restart ntp 

To see what its doing type the following command:

ntpq -p

It will display something like this:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.au.pool.ntp.o .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.au.pool.ntp.o .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.au.pool.ntp.o .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.au.pool.ntp.o .POOL.          16 p    -   64    0    0.000    0.000   0.000
+time.cloudflare 10.26.8.188      3 u  782 1024  377    2.646    1.048   1.281
-ntp3.ds.network 162.159.200.123  4 u  846 1024  377   50.324    2.066   1.404
-103.38.120.36 ( 130.95.179.80    2 u  536 1024  377    6.104    0.501   1.310
*ntp.seby.io     17.253.66.125    2 u   53 1024  377    3.088    2.273   1.413
-103.76.40.123 ( 203.35.83.242    2 u  707 1024  377    2.987    0.123   0.895
+85.ip-139-99-23 162.159.200.123  4 u  814 1024  377    2.963   -0.103   1.260

That tells me that its using ntp.seby.io as its main time source (it has an asterisk on the left) and also using time.cloudflare and 85.ip-139-99-23 for comparison (they have a plus sign on the left). These change frequently and are different for other continents. That means the Pi is setting its time from the internet.


GPS time
I have a USB based GPS. I couldn't get it to work with the Pi when I first got it, over a year ago. My intention was to use it as a time source. Satellites have very accurate clocks and the GPS data returned can provide a reliable time source depending on how good your GPS is.

Last week I tackled it again. My GPS is a u-blox 8 but at $20 (AUD) I didn't expect much. Simply plug it into a USB port and put the GPS end somewhere where it can get an uninterrupted view of the sky. To get it to talk to the Pi we need to install a couple of packages called gpsd and gpsd-tools with the following command:

sudo apt install gpsd gpsd-tools -y

Gpsd takes the stream of data from the GPS and translates it into something other programs (like ntp) can use. Gpsd-tools has some tools to display the data coming off the GPS to help with debugging. I recommend using the package from buster-backports as its more up to date (version 3.20 at the time of writing).

We need to add some more lines to /etc/ntp.conf to tell it to use the GPS as a time source. Add the following:

# GPS Serial data reference (NTP0)
server 127.127.28.0 minpoll 4 maxpoll 4
fudge 127.127.28.0 refid GPS

# GPS PPS reference (NTP1)
server 127.127.28.1 minpoll 4 maxpoll 4 prefer
fudge 127.127.28.1 refid PPS

While the cgps and gpsmon tools were showing me there was data coming in from the GPS and it had a 3D fix it wasn't able to communicate with ntp using the shared memory segments.

There is a bug with the gpsd defaults used by Debian. That is the /etc/default/gpsd file provided by Debian has a line in it that reads GPSD_OPTIONS="". Its wrong. You need to edit the file and change it to GPSD_OPTIONS="-n". After that reboot the Pi and the ntp service will be able to access the shared memory segments that gpsd uses. It now looks like:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.au.pool.ntp.o .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.au.pool.ntp.o .POOL.          16 p    -   64    0    0.000    0.000   0.000
xSHM(0)          .GPS.            0 l    4   16  377    0.000   25.396   1.084
*SHM(1)          .PPS.            0 l    3   16  377    0.000   -0.035   0.117
+45.76.113.31 (d 17.253.66.253    2 u   64   64  377    2.079    0.935   0.092
+ntp.seby.io     17.253.66.125    2 u   18   64  377    2.234    0.889   0.122
-ntp1.ds.network 225.254.30.190   4 u   30   64  377   50.872    0.457   0.144
-time.cloudflare 10.26.8.188      3 u   19   64  377    1.869    0.306   0.060
-85.ip-139-99-23 162.159.200.123  4 u   44   64  377    2.208   -0.881   0.073
-220.158.215.20  202.46.178.18    2 u   34   64  377    4.041    1.291   0.047
 

This is telling me there are two shared memory segments SHM(0) and SHM(1) that ntp and gpsd are using. One is used for the gps time and the other for the PPS (Pulse Per Second) that some GPS's can supply, but not all do.

See the gpsd how-to guide for more details, in particular the section on debugging and tuning.

I have ordered two more cheap GPS's off the internet. I picked different ones to see if they are better. Given they are cheap I don't expect much. The u-blox works but the time jumps all over the place.

Adafruit have the Ultimate GPS hat for the Pi. It is expensive and unless the Pi is sitting outside you'll need a separate GPS antenna. It costs $100 for the hat and $30 for the antenna, plus shipping in Australia.


Update 15 Oct 2020
I've switched from using NTP to NTPsec which is more secure and provides similar functionality to NTP. You can read about it at ntpsec.org

The two cheap GPS's arrived. They don't provide a 1pps signal which makes them useless for time keeping. Most GPS's don't provide a 1pps signal. This is normally done via an RS232 serial cable and most computers don't have a serial port these days.

A recommended GPS for timing purposes is the NaviSys GR-801W. The W variant is for timing and does output a 1pps signal even though its connected via a USB cable. I have just ordered some directly from NaviSys in Taiwan. They cost approx 45 USD each and then there is shipping and PayPal fees on top of that.

No comments: