[ntp:questions] ntpd reads from shared memory but doesn't act on it

J. Jobin jobin at hotmail.com
Wed Sep 2 18:19:36 UTC 2009


Hi,

I'm trying to get ntpd to read from shared memory and then adjust the time accordingly. Problem is it seems to read the value that I put into shared memory but doesn't seem to adjust the time accordingly.

This is how I ran ntpd:

 ./ntpd -D 3 -u 113:124 -g

Using the gpsd program, I borrowed code from there and wrote my own little program to write into shared memory. When I run my program, I have it set to increase the time by 60 seconds and 300 microseconds, i.e., 60.000300 seconds. Example output from my program:

ntpshm_put: Clock: 1251851559 @ 1251851499.390156

Additionally, there is an entry in my /etc/ntp.conf that says fudge is 0.420. When I run my program, I see this output from gpsd immediately:

peer SHM(0) event 'event_reach' (0x84) status 'unreach, conf, 2 events, event_reach' (0x8024)
refclock_sample: n 1 offset 60.420300 disp 0.000000 jitter 0.000001
clock_filter: n 1 off 60.420300 del 0.000000 dsp 7.937500 jit 0.000001, age 0

That offset - 60.420300 - seems consistent with what I set. (60.0003000 + 0.420)

However even after half a day, ntpd doesn't seem to have adjusted the time. Maybe I'm forgetting to set some option? Maybe once is not enough for ntpd, and I need to keep writing new values regularly? Any idea on what I might be forgetting or doing incorrectly?

Some relevant information:

I don't want my ntpd to talk to external servers. The intention is that a script will write values into shared memory and ntpd should read this and adjust accordingly.


This is what my /etc/ntp.conf file looks like:
--------------------------------------------
driftfile /var/lib/ntp/ntp.drift

# Enable this if you want statistics to be logged.
statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# You do need to talk to an NTP server or two (or three).
#server ntp.ubuntu.com

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust

server 127.127.28.0 mode 1 minpoll 4 maxpoll 4
fudge 127.127.28.0 time1 0.420 refid GPS

server 127.127.28.1 mode 1 minpoll 4 maxpoll 4 prefer
fudge 127.127.28.1 refid GPS1

--------------------------------------------


The output of "ntpq -p"

     remote           refid      st t when poll reach   delay   offset  jitter
==========================================================
 SHM(0)          .GPS.            0 l  17h   16    0    0.000    0.000   0.001
 SHM(1)          .GPS1.           0 l    -   16    0    0.000    0.000   0.001


That "17h" corresponds to when my program wrote into the shared memory.

The output of "ntpdc"

ntpdc> loopinfo
offset:               0.000000 s
frequency:            -34.340 ppm
poll adjust:               0
watchdog timer:       63469 s


$ cat /var/lib/ntp/ntp.drift 
-34.340


$ cat /proc/sysvipc/shm
       key      shmid   perms size  cpid  lpid  nattch uid gid cuid  cgid    atime      dtime          ctime
1314148400      0        700   80   5014 25550   2    0   0    0   0 1251851499 1251851500  1251847089
1314148401    32769   700    80  5014 25550   1    0    0   0   0 1251851499 1251851500  1251847089
         0       65538  1600 393216 5466 5588    2 106 114 106  114 1251847098 1251847098 1251847098


On strange thing I did notice is that the "lpid" in the above output is always that of my program which writes into it. Looking at the ntpd output, it seems to read it from shared memory *after* my program has written into it. So, shouldn't the "lpid" be that of the ntpd process?

FWIW, I'm using ntpd version 4.2.4p7 on a 32-bit Ubuntu 8.04 machine.

Thanks.





_________________________________________________________________
With Windows Live, you can organize, edit, and share your photos.
http://www.windowslive.com/Desktop/PhotoGallery


More information about the questions mailing list