Skip to contentSkip to conversation

time: Fix accumulation bug triggered by long delay.

PATCH In review John Stultz 1 participant 2 messages Mar 18, 2010 – Mar 23, 2010 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 time: Fix accumulation bug triggered by long delay.

The logarithmic accumulation done in the timekeeping has some overflow protection that limits the max shift value. That means it will take more then shift loops to accumulate all of the cycles. This causes the shift decrement to underflow, which causes the loop to never exit.

The simplest fix would be simply to do a:

	if (shift)
		shift--;

However that is not optimal, as we know the cycle offset is larger then the interval << shift, the above would make shift drop to zero, then we would be spinning for quite awhile accumulating at interval chunks at a time.

Instead, this patch only decreases shift if the offset is smaller then cycle_interval << shift. This makes sure we accumulate using the largest chunks possible without overflowing tick_length, and limits the number of iterations through the loop.

This issue was found and reported by Sonic Zhang, who also tested the fix. Many thanks your explanation and testing!

CC Thomas Gleixner <[email protected]>
CC Sonic Zhang <[email protected]>
---
 kernel/time/timekeeping.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/time/timekeeping.c +2 -1
index 1673637..39f6177 100644
@@ -818,7 +818,8 @@ void update_wall_time(void)
 	shift = min(shift, maxshift);
 	while (offset >= timekeeper.cycle_interval) {
 		offset = logarithmic_accumulation(offset, shift);
-		shift--;
+		if(offset < timekeeper.cycle_interval<<shift)
+			shift--;
 	}
 
 	/* correct the clock when NTP error is too big */
Signature · 1 line
1.6.0.4
#1 lore raw
Commit-ID:  830ec0458c390f29c6c99e1ff7feab9e36368d12
Gitweb:     http://git.kernel.org/tip/830ec0458c390f29c6c99e1ff7feab9e36368d12
Author:     John Stultz <[email protected]>
AuthorDate: Thu, 18 Mar 2010 14:47:30 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 23 Mar 2010 16:41:01 +0100

time: Fix accumulation bug triggered by long delay.

The logarithmic accumulation done in the timekeeping has some overflow protection that limits the max shift value. That means it will take more then shift loops to accumulate all of the cycles. This causes the shift decrement to underflow, which causes the loop to never exit.

The simplest fix would be simply to do a:

	if (shift)
		shift--;

However that is not optimal, as we know the cycle offset is larger then the interval << shift, the above would make shift drop to zero, then we would be spinning for quite awhile accumulating at interval chunks at a time.

Instead, this patch only decreases shift if the offset is smaller then cycle_interval << shift. This makes sure we accumulate using the largest chunks possible without overflowing tick_length, and limits the number of iterations through the loop.

This issue was found and reported by Sonic Zhang, who also tested the fix. Many thanks your explanation and testing!

LKML-Reference: <[email protected]>

---
 kernel/time/timekeeping.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/time/timekeeping.c +2 -1
index 1673637..39f6177 100644
@@ -818,7 +818,8 @@ void update_wall_time(void)
 	shift = min(shift, maxshift);
 	while (offset >= timekeeper.cycle_interval) {
 		offset = logarithmic_accumulation(offset, shift);
-		shift--;
+		if(offset < timekeeper.cycle_interval<<shift)
+			shift--;
 	}
 
 	/* correct the clock when NTP error is too big */