Skip to contentSkip to conversation

ntp: Clamp PLL update interval

PATCH In review Miroslav Lichvar 2 participants 3 messages Sep 7, 2010 – Sep 9, 2010 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore

Miroslav Lichvar

author reviewer
#0 lore raw

PATCH 1/1 ntp: Clamp PLL update interval

Clamp update interval to reduce PLL gain with low sampling rate (e.g. intermittent network connection) to avoid instability.

The clamp roughly corresponds to the loop time constant, it's 8 * poll interval for SHIFT_PLL 2 and 32 * poll interval for SHIFT_PLL 4. This gives good results without affecting the gain in normal conditions where ntpd skips only up to seven consecutive samples.

---
 kernel/time/ntp.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
kernel/time/ntp.c +11 -3
index c631168..d232189 100644
@@ -149,10 +149,18 @@ static void ntp_update_offset(long offset)
 	time_reftime = get_seconds();
 
 	offset64    = offset;
-	freq_adj    = (offset64 * secs) <<
-			(NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant));
+	freq_adj    = ntp_update_offset_fll(offset64, secs);
 
-	freq_adj    += ntp_update_offset_fll(offset64, secs);
+	/*
+	 * Clamp update interval to reduce PLL gain with low
+	 * sampling rate (e.g. intermittent network connection)
+	 * to avoid instability.
+	 */
+	if (unlikely(secs > 1 << (SHIFT_PLL + 1 + time_constant)))
+		secs = 1 << (SHIFT_PLL + 1 + time_constant);
+
+	freq_adj    += (offset64 * secs) <<
+			(NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant));
 
 	freq_adj    = min(freq_adj + time_freq, MAXFREQ_SCALED);
 
Signature · 1 line
1.7.2
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Miroslav Lichvar

Clamp update interval to reduce PLL gain with low sampling rate (e.g. intermittent network connection) to avoid instability.

The clamp roughly corresponds to the loop time constant, it's 8 * poll interval for SHIFT_PLL 2 and 32 * poll interval for SHIFT_PLL 4. This gives good results without affecting the gain in normal conditions where ntpd skips only up to seven consecutive samples.

Thanks Miroslav!

Quoted 30 lines
---
 kernel/time/ntp.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
kernel/time/ntp.c +11 -3
index c631168..d232189 100644
@@ -149,10 +149,18 @@ static void ntp_update_offset(long offset)
 	time_reftime = get_seconds();
 
 	offset64    = offset;
-	freq_adj    = (offset64 * secs) <<
-			(NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant));
+	freq_adj    = ntp_update_offset_fll(offset64, secs);
 
-	freq_adj    += ntp_update_offset_fll(offset64, secs);
+	/*
+	 * Clamp update interval to reduce PLL gain with low
+	 * sampling rate (e.g. intermittent network connection)
+	 * to avoid instability.
+	 */
+	if (unlikely(secs > 1 << (SHIFT_PLL + 1 + time_constant)))
+		secs = 1 << (SHIFT_PLL + 1 + time_constant);
+
+	freq_adj    += (offset64 * secs) <<
+			(NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant));
 
 	freq_adj    = min(freq_adj + time_freq, MAXFREQ_SCALED);
 
#2 lore raw
In reply to Miroslav Lichvar
Commit-ID:  8af3c153baf95374eff20a37f00c59a295b52756
Gitweb:     http://git.kernel.org/tip/8af3c153baf95374eff20a37f00c59a295b52756
Author:     Miroslav Lichvar <[email protected]>
AuthorDate: Tue, 7 Sep 2010 16:43:46 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 9 Sep 2010 20:48:37 +0200

ntp: Clamp PLL update interval

Clamp update interval to reduce PLL gain with low sampling rate (e.g. intermittent network connection) to avoid instability.

The clamp roughly corresponds to the loop time constant, it's 8 * poll interval for SHIFT_PLL 2 and 32 * poll interval for SHIFT_PLL 4. This gives good results without affecting the gain in normal conditions where ntpd skips only up to seven consecutive samples.

LKML-Reference: <[email protected]>

---
 kernel/time/ntp.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
kernel/time/ntp.c +11 -3
index c631168..d232189 100644
@@ -149,10 +149,18 @@ static void ntp_update_offset(long offset)
 	time_reftime = get_seconds();
 
 	offset64    = offset;
-	freq_adj    = (offset64 * secs) <<
-			(NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant));
+	freq_adj    = ntp_update_offset_fll(offset64, secs);
 
-	freq_adj    += ntp_update_offset_fll(offset64, secs);
+	/*
+	 * Clamp update interval to reduce PLL gain with low
+	 * sampling rate (e.g. intermittent network connection)
+	 * to avoid instability.
+	 */
+	if (unlikely(secs > 1 << (SHIFT_PLL + 1 + time_constant)))
+		secs = 1 << (SHIFT_PLL + 1 + time_constant);
+
+	freq_adj    += (offset64 * secs) <<
+			(NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant));
 
 	freq_adj    = min(freq_adj + time_freq, MAXFREQ_SCALED);