All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ntp: Clamp PLL update interval
@ 2010-09-07 14:43 Miroslav Lichvar
  2010-09-09 18:16 ` john stultz
  2010-09-09 18:51 ` [tip:timers/core] " tip-bot for Miroslav Lichvar
  0 siblings, 2 replies; 3+ messages in thread
From: Miroslav Lichvar @ 2010-09-07 14:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: john stultz, 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.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
---
 kernel/time/ntp.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index c631168..d232189 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -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);
 
-- 
1.7.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ntp: Clamp PLL update interval
  2010-09-07 14:43 [PATCH] ntp: Clamp PLL update interval Miroslav Lichvar
@ 2010-09-09 18:16 ` john stultz
  2010-09-09 18:51 ` [tip:timers/core] " tip-bot for Miroslav Lichvar
  1 sibling, 0 replies; 3+ messages in thread
From: john stultz @ 2010-09-09 18:16 UTC (permalink / raw)
  To: Miroslav Lichvar; +Cc: linux-kernel, Thomas Gleixner

On Tue, 2010-09-07 at 16:43 +0200, Miroslav Lichvar wrote:
> 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.
> 
> Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>

Thanks Miroslav!

Acked-by: John Stultz <johnstul@us.ibm.com>


> ---
>  kernel/time/ntp.c |   14 +++++++++++---
>  1 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
> index c631168..d232189 100644
> --- a/kernel/time/ntp.c
> +++ b/kernel/time/ntp.c
> @@ -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);
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:timers/core] ntp: Clamp PLL update interval
  2010-09-07 14:43 [PATCH] ntp: Clamp PLL update interval Miroslav Lichvar
  2010-09-09 18:16 ` john stultz
@ 2010-09-09 18:51 ` tip-bot for Miroslav Lichvar
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Miroslav Lichvar @ 2010-09-09 18:51 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, mlichvar, hpa, mingo, johnstul, tglx

Commit-ID:  8af3c153baf95374eff20a37f00c59a295b52756
Gitweb:     http://git.kernel.org/tip/8af3c153baf95374eff20a37f00c59a295b52756
Author:     Miroslav Lichvar <mlichvar@redhat.com>
AuthorDate: Tue, 7 Sep 2010 16:43:46 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
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.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Acked-by: john stultz <johnstul@us.ibm.com>
LKML-Reference: <1283870626-9472-1-git-send-email-mlichvar@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/time/ntp.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index c631168..d232189 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -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);
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-09-09 18:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-07 14:43 [PATCH] ntp: Clamp PLL update interval Miroslav Lichvar
2010-09-09 18:16 ` john stultz
2010-09-09 18:51 ` [tip:timers/core] " tip-bot for Miroslav Lichvar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.