From 3888b9dcec6936a3937287ab780e80754967a71f Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 10 Apr 2014 15:45:11 +0200 Subject: [PATCH] sources: rework special mode ending with unreachable sources Instead of giving up when a source has 7 reach updates, continue as long as at least one source has fewer than 7 updates and can still have 3 samples to be selectable in that number of updates. When no sources are responding, it will give up sooner. --- sources.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/sources.c b/sources.c index a4b67e1..d7f7b06 100644 --- a/sources.c +++ b/sources.c @@ -45,6 +45,7 @@ #include "nameserv.h" #include "mkdirpp.h" #include "sched.h" +#include "regress.h" /* ================================================== */ /* Flag indicating that we are initialised */ @@ -346,6 +347,25 @@ SRC_UnsetSelectable(SRC_Instance inst) /* ================================================== */ +static int +special_mode_end(void) +{ + int i; + + for (i = 0; i < n_sources; i++) { + /* Don't expect more updates than from an offline iburst NTP source */ + if (sources[i]->reachability_size >= SOURCE_REACH_BITS - 1) + continue; + + /* Check if the source could still have enough samples to be selectable */ + if (SOURCE_REACH_BITS - 1 - sources[i]->reachability_size + + SRC_Samples(sources[i]) >= MIN_SAMPLES_FOR_REGRESS) + return 0; + } + + return 1; +} + void SRC_UpdateReachability(SRC_Instance inst, int reachable) { @@ -361,9 +381,8 @@ SRC_UpdateReachability(SRC_Instance inst, int reachable) SRC_SelectSource(NULL); } - /* End special reference mode on last reachability update from iburst */ - if (REF_GetMode() != REF_ModeNormal && - inst->reachability_size >= SOURCE_REACH_BITS - 1) { + /* Check if special reference update mode failed */ + if (REF_GetMode() != REF_ModeNormal && special_mode_end()) { REF_SetUnsynchronised(); } }