Re: [chrony-dev] SOCK refclock system time resolution

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


On Wed, Sep 13, 2023 at 07:13:04AM -0400, Josef 'Jeff' Sipek wrote:
> Just to make sure I understand, the "proper" way is to adjust the offset to
> compensate for any rounding?  IOW, something like what I had in my program
> before I messed with chrony's code:
> 
> 	uint64_t sys; /* system clock unix time in ns */
> 	uint64_t ref; /* reference clock unix time in ns */
> 
> 	...
> 
> 	/* align sys time to microseconds, adjust ref time to maintain offset */
> 	ref -= (sys % 1000);
> 	sys -= (sys % 1000);

This shouldn't be necessary. Just pass the difference as seconds in
double. You can verify the raw offset reported in the refclocks log is
matching the values you are feeding into SOCK.
> 
> 	/* send message to chrony */
> 	msg->tv.tv_sec = sys / 1000000000;
> 	msg->tv.tv_usec = (sys / 1000) % 1000000;
> 	msg->offset = (ref - sys) / 1e9;

I think the difference should be casted to int64_t before going to
double.

-- 
Miroslav Lichvar


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


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