Re: sensor offset for ntpd

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Maurice Janssen
Date: Wednesday, September 12, 2007 - 11:26 am

On Tuesday, September 11, 2007 at 10:22:22 +0200, Henning Brauer wrote:

OK, here's a diff against the latest parse.y (with tabs instead of
spaces all over the place like the previous diff, sorry about that).

BTW: it looks like the default value of 1 for the weight is gone,
causing ntpd to never sync to a server or sensor if no explicit weight
value is given.

I tried to change it into something like 
weight          : /* empty */   { opts.weight = 1; }
                | WEIGHT NUMBER {
but yacc keeps complaining about 2 lines never being reduced.
I obviously don't understand the format well enough to fix it properly.

Maurice



Index: ntpd.conf.5
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/ntpd.conf.5,v
retrieving revision 1.16
diff -u -r1.16 ntpd.conf.5
--- ntpd.conf.5	31 May 2007 19:20:26 -0000	1.16
+++ ntpd.conf.5	12 Sep 2007 18:16:22 -0000
@@ -72,6 +72,7 @@
 .Ed
 .It Xo Ic sensor Ar device
 .Op Ic weight Ar weight-value
+.Op Ic offset Ar milliseconds
 .Xc
 Specify a timedelta sensor device
 .Xr ntpd 8
@@ -91,6 +92,14 @@
 .Bd -literal -offset indent
 sensor *
 sensor udcf0
+.Ed
+.Pp
+An optional offset in milliseconds can be given to compensate
+for the sensors offset.
+For example, if your DCF77 receiver is lagging 15 ms behind
+actual time:
+.Bd -literal -offset indent
+sensor udcf0 offset -15
 .Ed
 .It Xo Ic server Ar address
 .Op Ic weight Ar weight-value
Index: ntpd.h
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/ntpd.h,v
retrieving revision 1.85
diff -u -r1.85 ntpd.h
--- ntpd.h	4 Aug 2007 02:58:02 -0000	1.85
+++ ntpd.h	12 Sep 2007 18:16:22 -0000
@@ -143,12 +143,14 @@
 	int				 sensordevid;
 	u_int8_t			 weight;
 	u_int8_t			 shift;
+	int32_t				 sensor_offset;
 };
 
 struct ntp_conf_sensor {
 	TAILQ_ENTRY(ntp_conf_sensor)		 entry;
 	char					*device;
 	u_int8_t				 weight;
+	int32_t					 sensor_offset;
 };
 
 struct ntp_freq {
Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/parse.y,v
retrieving revision 1.31
diff -u -r1.31 parse.y
--- parse.y	11 Sep 2007 23:33:37 -0000	1.31
+++ parse.y	12 Sep 2007 18:16:22 -0000
@@ -53,6 +53,7 @@
 
 struct opts {
 	int		weight;
+	int32_t		sensor_offset;
 } opts;
 
 typedef struct {
@@ -68,14 +69,14 @@
 %}
 
 %token	LISTEN ON
-%token	SERVER SERVERS SENSOR WEIGHT
+%token	SERVER SERVERS SENSOR WEIGHT SENSOROFFSET
 %token	ERROR
 %token	<v.string>		STRING
 %token	<v.number>		NUMBER
 %type	<v.addr>		address
 %type	<v.opts>		server_opts server_opts_l server_opt
 %type	<v.opts>		sensor_opts sensor_opts_l sensor_opt
-%type	<v.opts>		weight
+%type	<v.opts>		weight sensor_offset
 %%
 
 grammar		: /* empty */
@@ -193,6 +194,7 @@
 
 			s = new_sensor($2);
 			s->weight = $3.weight;
+			s->sensor_offset = $3.sensor_offset;
 			free($2);
 			TAILQ_INSERT_TAIL(&conf->ntp_conf_sensors, s, entry);
 		}
@@ -233,6 +235,7 @@
 		| sensor_opt
 		;
 sensor_opt	: weight
+		| sensor_offset
 		;
 
 weight		: WEIGHT NUMBER	{
@@ -244,6 +247,15 @@
 		}
 		;
 
+sensor_offset	: SENSOROFFSET NUMBER	{
+			if ($2 < -127000 || $2 > 127000) {
+				yyerror("weight must be between -127000 and 127000 milliseconds");
+				YYERROR;
+			}
+			opts.sensor_offset = $2;
+		}
+		;
+
 %%
 
 struct keywords {
@@ -279,6 +291,7 @@
 	/* this has to be sorted always */
 	static const struct keywords keywords[] = {
 		{ "listen",		LISTEN},
+		{ "offset",		SENSOROFFSET},
 		{ "on",			ON},
 		{ "sensor",		SENSOR},
 		{ "server",		SERVER},
Index: sensors.c
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/sensors.c,v
retrieving revision 1.33
diff -u -r1.33 sensors.c
--- sensors.c	4 Aug 2007 02:58:02 -0000	1.33
+++ sensors.c	12 Sep 2007 18:16:22 -0000
@@ -121,6 +121,7 @@
 
 	s->next = getmonotime();
 	s->weight = cs->weight;
+	s->sensor_offset = cs->sensor_offset;
 	if ((s->device = strdup(dxname)) == NULL)
 		fatal("sensor_add strdup");
 	s->sensordevid = sensordev;
@@ -176,7 +177,8 @@
 	 * sensor.value = TS - TD in ns
 	 * if value is positive, system time is ahead
 	 */
-	s->offsets[s->shift].offset = (sensor.value / -1e9) - getoffset();
+	s->offsets[s->shift].offset = (sensor.value / -1e9) - getoffset() -
+		(s->sensor_offset / 1e3);
 	s->offsets[s->shift].rcvd = sensor.tv.tv_sec;
 	s->offsets[s->shift].good = 1;
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Job Opportunity (part-time). Salary: about $45.000/year, Dixie Cannon, (Wed Dec 31, 5:00 pm)
Re: sensor offset for ntpd, Otto Moerbeek, (Mon Sep 10, 12:15 pm)
Re: sensor offset for ntpd, Maurice Janssen, (Mon Sep 10, 11:13 pm)
Re: sensor offset for ntpd, Henning Brauer, (Tue Sep 11, 1:22 am)
Re: sensor offset for ntpd, Maurice Janssen, (Wed Sep 12, 11:26 am)
Dhaka::Website Design &amp; Development, Hosting,Cargo Trace m ..., Winux Group Tel: 989 ..., (Sat Dec 27, 5:29 am)
Latest info on events around the Middle East., Expo Guide Arabia, (Thu Jul 16, 9:15 pm)
kill an unused IPv6 statistic, Claudio Jeker, (Mon Dec 20, 8:44 am)
Re: kill an unused IPv6 statistic, Kenneth R Westerback, (Mon Dec 20, 10:18 am)
UPDATE: Test-Simple-0.96, Abel Abraham Camaril ..., (Sun Jan 2, 4:04 pm)
Re: UPDATE: Test-Simple-0.96, Abel Abraham Camaril ..., (Sun Jan 2, 6:24 pm)