Re: [chrony-dev] [PATCH] enable stratum setting for refclocks (take 3)

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


On Fri, 2017-10-06 at 09:53 +0200, Miroslav Lichvar wrote:
> On Thu, Oct 05, 2017 at 09:42:10PM +0200, Andreas Steinmetz wrote:
> > > Does this really need a new SRC parameter? I'd prefer if this was
> > > an
> > > option specific to refclocks and it just changed the stratum that
> > > is
> > > passed with the refclock sample.
> > > 
> > 
> > Now no new SRC parameter, but a new SRC function. The problem is
> > that
> > the required access to the structure to set the refclock stratum
> > for
> > SRC is only available to SRC.
> 
> Maybe I'm missing some detail, but why not just change the value
> passed to SRC_AccumulateSample in refclock.c?

Sorry, missed that. Updated patch attached.

> 
> --- a/refclock.c
> +++ b/refclock.c
> @@ -635,7 +635,7 @@ poll_timeout(void *arg)
>          /* Handle special case when PPS is used with local stratum
> */
>          stratum = pps_stratum(inst, &sample_time);
>        else
> -        stratum = 0;
> +        stratum = inst->stratum;
>  
>        SRC_UpdateReachability(inst->source, 1);
>        SRC_AccumulateSample(inst->source, &sample_time, offset,
> 
> 
> -- 
> Miroslav Lichvar
> 
-- 
Andreas Steinmetz                       SPAMmers use robotrap@xxxxxxxx
diff -rNu chrony-3.2.orig/conf.c chrony-3.2/conf.c
--- chrony-3.2.orig/conf.c	2017-09-15 08:32:09.000000000 +0200
+++ chrony-3.2/conf.c	2017-10-06 21:00:27.727991288 +0200
@@ -680,7 +680,7 @@
 static void
 parse_refclock(char *line)
 {
-  int n, poll, dpoll, filter_length, pps_rate, min_samples, max_samples, sel_options;
+  int n, poll, dpoll, filter_length, pps_rate, min_samples, max_samples, sel_options, stratum;
   int max_lock_age, pps_forced;
   uint32_t ref_id, lock_ref_id;
   double offset, delay, precision, max_dispersion, pulse_width;
@@ -704,6 +704,7 @@
   ref_id = 0;
   max_lock_age = 2;
   lock_ref_id = 0;
+  stratum = 0;
 
   if (!*line) {
     command_parse_error();
@@ -774,6 +775,10 @@
     } else if (!strcasecmp(cmd, "maxdispersion")) {
       if (sscanf(line, "%lf%n", &max_dispersion, &n) != 1)
         break;
+    } else if (!strcasecmp(cmd, "stratum")) {
+      if (sscanf(line, "%d%n", &stratum, &n) != 1 ||
+          stratum >= NTP_MAX_STRATUM || stratum < 0)
+        break;
     } else if (!strcasecmp(cmd, "width")) {
       if (sscanf(line, "%lf%n", &pulse_width, &n) != 1)
         break;
@@ -819,6 +824,7 @@
   refclock->ref_id = ref_id;
   refclock->max_lock_age = max_lock_age;
   refclock->lock_ref_id = lock_ref_id;
+  refclock->stratum = stratum;
 }
 
 /* ================================================== */
diff -rNu chrony-3.2.orig/doc/chrony.conf.adoc chrony-3.2/doc/chrony.conf.adoc
--- chrony-3.2.orig/doc/chrony.conf.adoc	2017-09-15 08:32:09.000000000 +0200
+++ chrony-3.2/doc/chrony.conf.adoc	2017-10-06 21:00:27.728991299 +0200
@@ -516,6 +516,8 @@
 algorithm. Increasing the delay is useful to avoid having no majority in the
 source selection or to make it prefer other sources. The default is 1e-9 (1
 nanosecond).
+*stratum* _stratum_:::
+This option sets the NTP stratum of the refclock. This can be useful when the refclock provides time with a stratum other than 0. The default is 0.
 *precision* _precision_:::
 This option sets the precision of the reference clock (in seconds). The default
 value is the estimated precision of the system clock.
diff -rNu chrony-3.2.orig/doc/chrony.conf.man.in chrony-3.2/doc/chrony.conf.man.in
--- chrony-3.2.orig/doc/chrony.conf.man.in	2017-10-05 21:32:29.855702739 +0200
+++ chrony-3.2/doc/chrony.conf.man.in	2017-10-06 21:00:27.729991310 +0200
@@ -696,6 +696,12 @@
 nanosecond).
 .RE
 .sp
+\fBstratum\fP \fIstratum\fP
+.RS 4
+This option sets the NTP stratum of the refclock. This can be useful when the
+refclock provides time with a stratum other than 0. The default is 0.
+.RE
+.sp
 \fBprecision\fP \fIprecision\fP
 .RS 4
 This option sets the precision of the reference clock (in seconds). The default
diff -rNu chrony-3.2.orig/refclock.c chrony-3.2/refclock.c
--- chrony-3.2.orig/refclock.c	2017-09-15 08:32:09.000000000 +0200
+++ chrony-3.2/refclock.c	2017-10-06 21:07:03.497893326 +0200
@@ -79,6 +79,7 @@
   int pps_rate;
   int pps_active;
   int max_lock_age;
+  int stratum;
   struct MedianFilter filter;
   uint32_t ref_id;
   uint32_t lock_ref;
@@ -200,6 +201,7 @@
   inst->pps_rate = params->pps_rate;
   inst->pps_active = 0;
   inst->max_lock_age = params->max_lock_age;
+  inst->stratum = params->stratum;
   inst->lock_ref = params->lock_ref_id;
   inst->offset = params->offset;
   inst->delay = params->delay;
@@ -635,7 +637,7 @@
         /* Handle special case when PPS is used with local stratum */
         stratum = pps_stratum(inst, &sample_time);
       else
-        stratum = 0;
+        stratum = inst->stratum;
 
       SRC_UpdateReachability(inst->source, 1);
       SRC_AccumulateSample(inst->source, &sample_time, offset,
diff -rNu chrony-3.2.orig/refclock.h chrony-3.2/refclock.h
--- chrony-3.2.orig/refclock.h	2017-09-15 08:32:09.000000000 +0200
+++ chrony-3.2/refclock.h	2017-10-06 21:00:27.729991310 +0200
@@ -43,6 +43,7 @@
   int max_samples;
   int sel_options;
   int max_lock_age;
+  int stratum;
   uint32_t ref_id;
   uint32_t lock_ref_id;
   double offset;


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