Re: [chrony-users] Newbie Help Needed

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-users Archives ]


On Wed, Jan 03, 2018 at 08:37:00PM -0800, Stuart Maclean wrote:
> Currently my PPS driver is a Linux driver that I wrote.  All I do when the
> PPS interrupt fires is grab Linux system time and pass it back to a user
> space program via a character device named /dev/csacpps.
>
> My intent was that that program would also ready the serial line for the
> CSAC's 'time counter since epoch', using a simple select+read+read main
> loop, and place the two 'votes' for the correct current time (current time
> meaning that instant when the CSAC's pps fired) in a SHM segment that
> chronyc would read, and from there chrony would use adjtimex to manipulate
> my system clock parameters so that, for a short time at least, the system
> time would 'tick' at the same rate as the CSAC.

That could work. However, you will need to either combine the PPS
timestamp with the serial data, or provide two separate refclocks (one
PPS and one non-PPS) and let chronyd combine the data.

You would need to use the SOCK protocol for the later as SHM cannot
transport PPS-only samples. The chrony configuration would look like
this:

refclock SOCK /var/run/chrony.serial.sock refid CSAC noselect
refclock SOCK /var/run/chrony.pps.sock refid PPS lock CSAC

For development and debugging, it might help to have an additional
(NTP) source and mark both refclocks with noselect and disable the
lock to see if they work as expected.

In a pseudocode the program would do something like this:

	fd1 = socket(AF_UNIX, SOCK_DGRAM, 0);
	connect(fd1, {"/var/run/chrony.serial.sock"});
	fd2 = socket(AF_UNIX, SOCK_DGRAM, 0);
	connect(fd2, {"/var/run/chrony.pps.sock"});

	gettimeofday(&sample.tv);
	sample.offset = sample.tv - CSAC; // or negative value of that?
	sample.pulse = 0;
	sample.leap = 0;
	sample.magic = SOCK_MAGIC;

	send(fd1, &sample, sizeof sample, 0);

	sample.tv_sec = pps_timestamp.tv_sec;
	sample.tv_usec = pps_timestamp.tv_nsec / 1000;
	sample.offset = pps_timestamp.tv_nsec / 1e9;
	sample.pulse = 1;
	sample.leap = 0;
	sample.magic = SOCK_MAGIC;

	send(fd2, &sample, sizeof sample, 0);

A working example for sending SOCK samples is here:
https://github.com/mlichvar/ntp-refclock/blob/master/sock.c

Does that help?

-- 
Miroslav Lichvar

-- 
To unsubscribe email chrony-users-request@xxxxxxxxxxxxxxxxxxxx 
with "unsubscribe" in the subject.
For help email chrony-users-request@xxxxxxxxxxxxxxxxxxxx 
with "help" in the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/