INTRODUCTIONNTP timeservers are a crucial part of any large-scale, distributed system, especially if the components of the system are spread across multiple sites. There are many commercial and homebrew options for setting up an NTP timesource. Some are fairly simple to set up, and others (like the Symmetricom bc635 PCIe card) require a little more work.
I have recently set up an NTP server using the aforementioned card, and after all my troubles to get it set up, I decided to document the procedures used in this blog post.
Download the latest ntp source from http://www.ntp.org/downloads.html .For this tutorial, I used version 4.2.6p5
There is a PDF from Symmetricom support that outlines most of the steps necessary to fix the driver. This list is largely a copy of their "how-to". However, I have elaborated on a few of the steps where I had issues.
- Install the bc635/637 driver. To do this, either run make install OR cp the windrvr6.ko and windrvr6_usb.ko files into the /lib/modules/drivers/ area, then do a depmod -a. There is a script called wdreg that will load up the driver, wdreg windrvr6. I added a call to the wdreg script in /etc/rc.local in order to get the module loading on boot, one could also add a rule to /etc/modules.conf.
- To verify, run the bc63xPCIcfg file that comes with the driver, from the sample/ folder.
- After rebooting the computer, the sample program should still work.
- Copy the libbcsdk.so file from the sample/ folder to /usr/lib/ (or another library directory of your choice).
- Make a link to the device driver, ln -s /dev/windrvr6 /dev/btfp0 (btfp0 is the old /dev file that ntpd looks for)
- If you haven't already done so, download the ntpd source code from www.ntp.org/downloads.html
- I used the ntp-4.6.2p5 source for this, but the 4.2.6p2 source has been used by others
- Extract the source, then modify the Makefile.in file in the ntpd/ folder. Find the segment that has ntpd_LDADD = $(LDADD) $(LIBOPTS_LDADD) ../libntp/libntp.a -lm @LCRYPTO@ @LSCF@, and add -lbcsdk
- Run this command in the ntpd/ directory - ./configure --enable-BANCOMM --enable-linuxcaps
- Look at the Makefile (NOT Makefile.in). There should be a line like ntpd_LDADD = $(LDADD) $(LIBOPTS_LDADD) ../libntp/libntp.a -lm -lbcsdk If not, add the -lbcsdk here, but know that running ./configure again will overwrite this Makefile.
- Edit the refclock_bancomm.c file as follows
extern uint32_t __attribute__ ((weak)) bcReadBinTimeEx(SYMMT_PCI_HANDLE, uint64_t *, uint64_t*, uint32_t*, uint8_t*);
At line 440
case 2: /* Linux/Windows, PCI, 2 32bit time words */
struct tm temp;
if (bcReadBinTimeEx(stfp_handle, &btm, &btm, &nano, &dmy) == 0)
msyslog(LOG_ERR, "get_datumtime error: %m");
temp = *gmtime((time_t *)&btm);
time_vme->year = (unsigned short)temp.tm_year+1900;
time_vme->day = (unsigned short)temp.tm_yday+1;
time_vme->hr = (unsigned short)temp.tm_hour;
time_vme->mn = (unsigned short)temp.tm_min;
time_vme->sec = (unsigned short)temp.tm_sec;
time_vme->frac = (btm & 0x000FFFFF) * 1000;
time_vme->frac += (nano & 0x0000000F) * 100;
time_vme->status = (unsigned short)dmy;
printf("Epoch time read from the BANCOMM card -> %ld\n", btm);
printf("Decimal time read from the BANCOMM card -> Day:%d Year:%d H%02d:M%02d:S%02d.%06lu%d Status:%d\n",
printf("Decimal time read into time_vme -> Day:%hu Year:%hu H%hu:M%hu:S%hu.%lu Status:%hu\n",
One can remove all the commented lines, as well as the lines surrounded by
#ifdef DEBUG, but I have left them here for completeness.
Now run make. This should build a ntpd executable that will work with the libbcsdk.so library in order to read time from the Symmetricom PCIe GPS. If anyone knows how to handle the nanoseconds field, please let me know and I will update this post!
I then had to modify ntp.conf to use the device
# No restrictions on loopback
#Allow systems to sync
restrict 10.0.0.0 mask 255.0.0.0 nomodify notrap
restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap
#Setup GPS PCIe Clock
restrict 127.127.0.0 mask 255.255.0.0
server 127.127.16.0 prefer mode 2 iburst minpoll 4 maxpoll 4
#Local clock source
#fudge 127.127.1.0 stratum 8
Here the server 127.127.16.x is a special subnet which refers to the Symmetricom(or BANCOMM) hardware clock when ntpd is compiled to support this radio.
The mode keyword is specific to each hardware radio. For Symmetricom, I have been unable to find information on what this mode means, but for Meinberg
Assuming that Symmetricom has the same convention, this would mean it is using a time string to send the information.
iburst allows the computer to sync more quickly with GPS time.
minpoll and maxpoll specify a time in seconds to poll the timesource for
For CentOS 6.2, I had to replace the existing ntpd in /usr/sbin/ntpd with the custom built version.
I have also had problems with ntpd not starting on boot -
I had to manually add a call starting ntpd to /etc/rc.local even though chkconfig showed ntpd on. It seems that ntpd starts but crashes? To be continued as I explore the issue further.
CHECKING THAT IT WORKS
Running ntpq -p should show the GPS clock, and you should see the reach column increase as the computer syncs with the card. If you see things working, but then an x appears in front of the entry for the card, that means there is another ntpd source that disagrees time-wise.
I have seen this in the past, which worries me a little, as I am supposedly pulling time straight from GPS. Maybe there is a bug in my code - or maybe the other server was wrong? In any case, using the GPS card as the only time source works great and has greatly decreased the footprint of my system.