Patches contributed by Eötvös Lorand University


commit 13093cb0e59053bf97910de3a24f07cdff71c62c
Author: Ingo Molnar <mingo@elte.hu>
Date:   Thu Feb 26 03:16:47 2009 +0100

    gpu/drm, x86, PAT: PAT support for io_mapping_*, export symbols for modules
    
    Impact: build fix
    
     ERROR: "reserve_io_memtype_wc" [drivers/gpu/drm/i915/i915.ko] undefined!
     ERROR: "free_io_memtype" [drivers/gpu/drm/i915/i915.ko] undefined!
    
    Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
index 94596f794b1b..d5e28424622c 100644
--- a/arch/x86/mm/iomap_32.c
+++ b/arch/x86/mm/iomap_32.c
@@ -68,6 +68,7 @@ reserve_io_memtype_wc(u64 base, unsigned long size, pgprot_t *prot)
 out_err:
 	return -EINVAL;
 }
+EXPORT_SYMBOL_GPL(reserve_io_memtype_wc);
 
 void
 free_io_memtype(u64 base, unsigned long size)
@@ -75,6 +76,7 @@ free_io_memtype(u64 base, unsigned long size)
 	if (pat_enabled)
 		free_memtype(base, base + size);
 }
+EXPORT_SYMBOL_GPL(free_io_memtype);
 
 /* Map 'pfn' using fixed map 'type' and protections 'prot'
  */

commit 39854fe8c165872d743f6a0c4860ca2de8e45ac9
Author: Ingo Molnar <mingo@elte.hu>
Date:   Sun Feb 22 16:06:58 2009 +0100

    time: ntp: clean up second_overflow()
    
    Impact: cleanup, no functionality changed
    
    The 'time_adj' local variable is named in a very confusing
    way because it almost shadows the 'time_adjust' global
    variable - which is used in this same function.
    
    Rename it to 'delta' - to make them stand apart more clearly.
    
    kernel/time/ntp.o:
    
       text    data     bss     dec     hex filename
       2545     114     144    2803     af3 ntp.o.before
       2545     114     144    2803     af3 ntp.o.after
    
    md5:
       1bf0b3be564512279ba7cee299d1d2be  ntp.o.before.asm
       1bf0b3be564512279ba7cee299d1d2be  ntp.o.after.asm
    
    Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index a3fe7ef2d83b..c74eb7d9d854 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -236,7 +236,7 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
  */
 void second_overflow(void)
 {
-	s64 time_adj;
+	s64 delta;
 
 	/* Bump the maxerror field */
 	time_maxerror += MAXFREQ / NSEC_PER_USEC;
@@ -249,10 +249,11 @@ void second_overflow(void)
 	 * Compute the phase adjustment for the next second. The offset is
 	 * reduced by a fixed factor times the time constant.
 	 */
-	tick_length	= tick_length_base;
-	time_adj	= shift_right(time_offset, SHIFT_PLL + time_constant);
-	time_offset	-= time_adj;
-	tick_length	+= time_adj;
+	tick_length	 = tick_length_base;
+
+	delta		 = shift_right(time_offset, SHIFT_PLL + time_constant);
+	time_offset	-= delta;
+	tick_length	+= delta;
 
 	if (!time_adjust)
 		return;

commit 069569e025706f27f939785f86a94d5d8ce55dce
Author: Ingo Molnar <mingo@elte.hu>
Date:   Sun Feb 22 16:03:37 2009 +0100

    time: ntp: simplify ntp_tick_adj calculations
    
    Impact: micro-optimization
    
    Convert the (internal) ntp_tick_adj value we store from unscaled
    units to scaled units. This is a constant that we never modify,
    so scaling it up once during bootup is enough - we dont have to
    do it for every adjustment step.
    
    Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 7447d57e021a..a3fe7ef2d83b 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -71,7 +71,8 @@ static long			time_reftime;
 
 long				time_adjust;
 
-static long			ntp_tick_adj;
+/* constant (boot-param configurable) NTP tick adjustment (upscaled)	*/
+static s64			ntp_tick_adj;
 
 /*
  * NTP methods:
@@ -89,7 +90,7 @@ static void ntp_update_frequency(void)
 	second_length		 = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ)
 						<< NTP_SCALE_SHIFT;
 
-	second_length		+= (s64)ntp_tick_adj << NTP_SCALE_SHIFT;
+	second_length		+= ntp_tick_adj;
 	second_length		+= time_freq;
 
 	tick_nsec		 = div_u64(second_length, HZ) >> NTP_SCALE_SHIFT;
@@ -540,6 +541,8 @@ int do_adjtimex(struct timex *txc)
 static int __init ntp_tick_adj_setup(char *str)
 {
 	ntp_tick_adj = simple_strtol(str, NULL, 0);
+	ntp_tick_adj <<= NTP_SCALE_SHIFT;
+
 	return 1;
 }
 

commit 2b9d1496e7835a603c340e8f0dd81f4b74d5f248
Author: Ingo Molnar <mingo@elte.hu>
Date:   Sun Feb 22 15:48:43 2009 +0100

    time: ntp: make 64-bit constants more robust
    
    Impact: cleanup, no functionality changed
    
     - make PPM_SCALE an explicit s64 constant, to
       remove (s64) casts from usage sites.
    
    kernel/time/ntp.o:
    
       text    data     bss     dec     hex filename
       2536     114     136    2786     ae2 ntp.o.before
       2536     114     136    2786     ae2 ntp.o.after
    
    md5:
       40a7728d1188aa18e83e21a81fa7b150  ntp.o.before.asm
       40a7728d1188aa18e83e21a81fa7b150  ntp.o.after.asm
    
    Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/include/linux/timex.h b/include/linux/timex.h
index 998a55d80acf..aa3475fcff64 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -190,7 +190,7 @@ struct timex {
  * offset and maximum frequency tolerance.
  */
 #define SHIFT_USEC 16		/* frequency offset scale (shift) */
-#define PPM_SCALE (NSEC_PER_USEC << (NTP_SCALE_SHIFT - SHIFT_USEC))
+#define PPM_SCALE ((s64)NSEC_PER_USEC << (NTP_SCALE_SHIFT - SHIFT_USEC))
 #define PPM_SCALE_INV_SHIFT 19
 #define PPM_SCALE_INV ((1ll << (PPM_SCALE_INV_SHIFT + NTP_SCALE_SHIFT)) / \
 		       PPM_SCALE + 1)
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 4346ed6e623f..7447d57e021a 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -408,7 +408,7 @@ static inline void process_adjtimex_modes(struct timex *txc, struct timespec *ts
 		time_status &= ~STA_NANO;
 
 	if (txc->modes & ADJ_FREQUENCY) {
-		time_freq = (s64)txc->freq * PPM_SCALE;
+		time_freq = txc->freq * PPM_SCALE;
 		time_freq = min(time_freq, MAXFREQ_SCALED);
 		time_freq = max(time_freq, -MAXFREQ_SCALED);
 	}
@@ -505,7 +505,7 @@ int do_adjtimex(struct timex *txc)
 		result = TIME_ERROR;
 
 	txc->freq	   = shift_right((time_freq >> PPM_SCALE_INV_SHIFT) *
-					 (s64)PPM_SCALE_INV, NTP_SCALE_SHIFT);
+					 PPM_SCALE_INV, NTP_SCALE_SHIFT);
 	txc->maxerror	   = time_maxerror;
 	txc->esterror	   = time_esterror;
 	txc->status	   = time_status;

commit e96291653b2e4df02f160b574070f6e632868e5e
Author: Ingo Molnar <mingo@elte.hu>
Date:   Sun Feb 22 15:35:18 2009 +0100

    time: ntp: refactor do_adjtimex() some more
    
    Impact: cleanup, no functionality changed
    
    Further simplify do_adjtimex():
    
     - introduce the ntp_start_leap_timer() helper function
     - eliminate the goto adj_done complication
    
    Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index aded09be98cc..4346ed6e623f 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -332,14 +332,33 @@ static void notify_cmos_timer(void)
 static inline void notify_cmos_timer(void) { }
 #endif
 
+/*
+ * Start the leap seconds timer:
+ */
+static inline void ntp_start_leap_timer(struct timespec *ts)
+{
+	long now = ts->tv_sec;
+
+	if (time_status & STA_INS) {
+		time_state = TIME_INS;
+		now += 86400 - now % 86400;
+		hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
+
+		return;
+	}
+
+	if (time_status & STA_DEL) {
+		time_state = TIME_DEL;
+		now += 86400 - (now + 1) % 86400;
+		hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
+	}
+}
 
 /*
  * Propagate a new txc->status value into the NTP state:
  */
 static inline void process_adj_status(struct timex *txc, struct timespec *ts)
 {
-	long now;
-
 	if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) {
 		time_state = TIME_OK;
 		time_status = STA_UNSYNC;
@@ -358,22 +377,12 @@ static inline void process_adj_status(struct timex *txc, struct timespec *ts)
 
 	switch (time_state) {
 	case TIME_OK:
-	start_timer:
-		now = ts->tv_sec;
-		if (time_status & STA_INS) {
-			time_state = TIME_INS;
-			now += 86400 - now % 86400;
-			hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
-		} else if (time_status & STA_DEL) {
-			time_state = TIME_DEL;
-			now += 86400 - (now + 1) % 86400;
-			hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
-		}
+		ntp_start_leap_timer(ts);
 		break;
 	case TIME_INS:
 	case TIME_DEL:
 		time_state = TIME_OK;
-		goto start_timer;
+		ntp_start_leap_timer(ts);
 	case TIME_WAIT:
 		if (!(time_status & (STA_INS | STA_DEL)))
 			time_state = TIME_OK;
@@ -394,6 +403,7 @@ static inline void process_adjtimex_modes(struct timex *txc, struct timespec *ts
 
 	if (txc->modes & ADJ_NANO)
 		time_status |= STA_NANO;
+
 	if (txc->modes & ADJ_MICRO)
 		time_status &= ~STA_NANO;
 
@@ -405,6 +415,7 @@ static inline void process_adjtimex_modes(struct timex *txc, struct timespec *ts
 
 	if (txc->modes & ADJ_MAXERROR)
 		time_maxerror = txc->maxerror;
+
 	if (txc->modes & ADJ_ESTERROR)
 		time_esterror = txc->esterror;
 
@@ -421,6 +432,7 @@ static inline void process_adjtimex_modes(struct timex *txc, struct timespec *ts
 
 	if (txc->modes & ADJ_OFFSET)
 		ntp_update_offset(txc->offset);
+
 	if (txc->modes & ADJ_TICK)
 		tick_usec = txc->tick;
 
@@ -457,7 +469,7 @@ int do_adjtimex(struct timex *txc)
 		if (txc->modes & ADJ_TICK &&
 		    (txc->tick <  900000/USER_HZ ||
 		     txc->tick > 1100000/USER_HZ))
-				return -EINVAL;
+			return -EINVAL;
 
 		if (txc->modes & ADJ_STATUS && time_state != TIME_OK)
 			hrtimer_cancel(&leap_timer);
@@ -467,7 +479,6 @@ int do_adjtimex(struct timex *txc)
 
 	write_seqlock_irq(&xtime_lock);
 
-	/* If there are input parameters, then process them */
 	if (txc->modes & ADJ_ADJTIME) {
 		long save_adjust = time_adjust;
 
@@ -477,19 +488,18 @@ int do_adjtimex(struct timex *txc)
 			ntp_update_frequency();
 		}
 		txc->offset = save_adjust;
-		goto adj_done;
-	}
+	} else {
 
-	/* If there are input parameters, then process them: */
-	if (txc->modes)
-		process_adjtimex_modes(txc, &ts);
+		/* If there are input parameters, then process them: */
+		if (txc->modes)
+			process_adjtimex_modes(txc, &ts);
 
-	txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
+		txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
 				  NTP_SCALE_SHIFT);
-	if (!(time_status & STA_NANO))
-		txc->offset /= NSEC_PER_USEC;
+		if (!(time_status & STA_NANO))
+			txc->offset /= NSEC_PER_USEC;
+	}
 
-adj_done:
 	result = time_state;	/* mostly `TIME_OK' */
 	if (time_status & (STA_UNSYNC|STA_CLOCKERR))
 		result = TIME_ERROR;
@@ -514,6 +524,7 @@ int do_adjtimex(struct timex *txc)
 	txc->calcnt	   = 0;
 	txc->errcnt	   = 0;
 	txc->stbcnt	   = 0;
+
 	write_sequnlock_irq(&xtime_lock);
 
 	txc->time.tv_sec = ts.tv_sec;

commit 80f2257116474ceed5fccab510b4f7245c0f49d7
Author: Ingo Molnar <mingo@elte.hu>
Date:   Sun Feb 22 15:15:32 2009 +0100

    time: ntp: refactor do_adjtimex()
    
    Impact: cleanup, no functionality changed
    
    do_adjtimex() is currently a monster function with a maze of
    branches. Refactor the txc->modes setting aspects of it into
    two new helper functions:
    
            process_adj_status()
            process_adjtimex_modes()
    
    kernel/time/ntp.o:
    
       text    data     bss     dec     hex filename
       2512     114     136    2762     aca ntp.o.before
       2512     114     136    2762     aca ntp.o.after
    
    Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index fc08eb10ced4..aded09be98cc 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -332,6 +332,102 @@ static void notify_cmos_timer(void)
 static inline void notify_cmos_timer(void) { }
 #endif
 
+
+/*
+ * Propagate a new txc->status value into the NTP state:
+ */
+static inline void process_adj_status(struct timex *txc, struct timespec *ts)
+{
+	long now;
+
+	if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) {
+		time_state = TIME_OK;
+		time_status = STA_UNSYNC;
+	}
+	/* only set allowed bits */
+	time_status &= STA_RONLY;
+
+	/*
+	 * If we turn on PLL adjustments then reset the
+	 * reference time to current time.
+	 */
+	if (!(time_status & STA_PLL) && (txc->status & STA_PLL))
+		time_reftime = xtime.tv_sec;
+
+	time_status |= txc->status & ~STA_RONLY;
+
+	switch (time_state) {
+	case TIME_OK:
+	start_timer:
+		now = ts->tv_sec;
+		if (time_status & STA_INS) {
+			time_state = TIME_INS;
+			now += 86400 - now % 86400;
+			hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
+		} else if (time_status & STA_DEL) {
+			time_state = TIME_DEL;
+			now += 86400 - (now + 1) % 86400;
+			hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
+		}
+		break;
+	case TIME_INS:
+	case TIME_DEL:
+		time_state = TIME_OK;
+		goto start_timer;
+	case TIME_WAIT:
+		if (!(time_status & (STA_INS | STA_DEL)))
+			time_state = TIME_OK;
+		break;
+	case TIME_OOP:
+		hrtimer_restart(&leap_timer);
+		break;
+	}
+}
+/*
+ * Called with the xtime lock held, so we can access and modify
+ * all the global NTP state:
+ */
+static inline void process_adjtimex_modes(struct timex *txc, struct timespec *ts)
+{
+	if (txc->modes & ADJ_STATUS)
+		process_adj_status(txc, ts);
+
+	if (txc->modes & ADJ_NANO)
+		time_status |= STA_NANO;
+	if (txc->modes & ADJ_MICRO)
+		time_status &= ~STA_NANO;
+
+	if (txc->modes & ADJ_FREQUENCY) {
+		time_freq = (s64)txc->freq * PPM_SCALE;
+		time_freq = min(time_freq, MAXFREQ_SCALED);
+		time_freq = max(time_freq, -MAXFREQ_SCALED);
+	}
+
+	if (txc->modes & ADJ_MAXERROR)
+		time_maxerror = txc->maxerror;
+	if (txc->modes & ADJ_ESTERROR)
+		time_esterror = txc->esterror;
+
+	if (txc->modes & ADJ_TIMECONST) {
+		time_constant = txc->constant;
+		if (!(time_status & STA_NANO))
+			time_constant += 4;
+		time_constant = min(time_constant, (long)MAXTC);
+		time_constant = max(time_constant, 0l);
+	}
+
+	if (txc->modes & ADJ_TAI && txc->constant > 0)
+		time_tai = txc->constant;
+
+	if (txc->modes & ADJ_OFFSET)
+		ntp_update_offset(txc->offset);
+	if (txc->modes & ADJ_TICK)
+		tick_usec = txc->tick;
+
+	if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET))
+		ntp_update_frequency();
+}
+
 /*
  * adjtimex mainly allows reading (and writing, if superuser) of
  * kernel time-keeping variables. used by xntpd.
@@ -383,90 +479,10 @@ int do_adjtimex(struct timex *txc)
 		txc->offset = save_adjust;
 		goto adj_done;
 	}
-	if (txc->modes) {
-		long sec;
-
-		if (txc->modes & ADJ_STATUS) {
-			if ((time_status & STA_PLL) &&
-			    !(txc->status & STA_PLL)) {
-				time_state = TIME_OK;
-				time_status = STA_UNSYNC;
-			}
-			/* only set allowed bits */
-			time_status &= STA_RONLY;
-			/*
-			 * If we turn on PLL adjustments then reset the
-			 * reference time to current time.
-			 */
-			if (!(time_status & STA_PLL) && (txc->status & STA_PLL))
-				time_reftime = xtime.tv_sec;
-
-			time_status |= txc->status & ~STA_RONLY;
-
-			switch (time_state) {
-			case TIME_OK:
-			start_timer:
-				sec = ts.tv_sec;
-				if (time_status & STA_INS) {
-					time_state = TIME_INS;
-					sec += 86400 - sec % 86400;
-					hrtimer_start(&leap_timer, ktime_set(sec, 0), HRTIMER_MODE_ABS);
-				} else if (time_status & STA_DEL) {
-					time_state = TIME_DEL;
-					sec += 86400 - (sec + 1) % 86400;
-					hrtimer_start(&leap_timer, ktime_set(sec, 0), HRTIMER_MODE_ABS);
-				}
-				break;
-			case TIME_INS:
-			case TIME_DEL:
-				time_state = TIME_OK;
-				goto start_timer;
-				break;
-			case TIME_WAIT:
-				if (!(time_status & (STA_INS | STA_DEL)))
-					time_state = TIME_OK;
-				break;
-			case TIME_OOP:
-				hrtimer_restart(&leap_timer);
-				break;
-			}
-		}
-
-		if (txc->modes & ADJ_NANO)
-			time_status |= STA_NANO;
-		if (txc->modes & ADJ_MICRO)
-			time_status &= ~STA_NANO;
 
-		if (txc->modes & ADJ_FREQUENCY) {
-			time_freq = (s64)txc->freq * PPM_SCALE;
-			time_freq = min(time_freq, MAXFREQ_SCALED);
-			time_freq = max(time_freq, -MAXFREQ_SCALED);
-		}
-
-		if (txc->modes & ADJ_MAXERROR)
-			time_maxerror = txc->maxerror;
-		if (txc->modes & ADJ_ESTERROR)
-			time_esterror = txc->esterror;
-
-		if (txc->modes & ADJ_TIMECONST) {
-			time_constant = txc->constant;
-			if (!(time_status & STA_NANO))
-				time_constant += 4;
-			time_constant = min(time_constant, (long)MAXTC);
-			time_constant = max(time_constant, 0l);
-		}
-
-		if (txc->modes & ADJ_TAI && txc->constant > 0)
-			time_tai = txc->constant;
-
-		if (txc->modes & ADJ_OFFSET)
-			ntp_update_offset(txc->offset);
-		if (txc->modes & ADJ_TICK)
-			tick_usec = txc->tick;
-
-		if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET))
-			ntp_update_frequency();
-	}
+	/* If there are input parameters, then process them: */
+	if (txc->modes)
+		process_adjtimex_modes(txc, &ts);
 
 	txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
 				  NTP_SCALE_SHIFT);

commit 10dd31a7a17254d6ba793305fc590455393e610e
Author: Ingo Molnar <mingo@elte.hu>
Date:   Sun Feb 22 13:38:40 2009 +0100

    time: ntp: fix bug in ntp_update_offset() & do_adjtimex()
    
    Impact: change (fix) the way the NTP PLL seconds offset is initialized/tracked
    
    Fix a bug and do a micro-optimization:
    
    When PLL is enabled we do not reset time_reftime. If the PLL
    was off for a long time (for example after bootup), this is
    arguably the wrong thing to do.
    
    We already had a hack for the common boot-time case in
    ntp_update_offset(), in form of:
    
            if (unlikely(time_status & STA_FREQHOLD || time_reftime == 0))
                    secs = 0;
    
    But the update delta should be reset later on too - not just when
    the PLL is enabled for the first time after bootup.
    
    So do it on !STA_PLL -> STA_PLL transitions.
    
    This changes behavior, as previously if ntpd was disabled for
    a long time and we restarted it, we'd run from that last update,
    with a very large delta.
    
    Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 580a35028693..fc08eb10ced4 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -142,7 +142,7 @@ static void ntp_update_offset(long offset)
 	 * and in which mode (PLL or FLL).
 	 */
 	secs = xtime.tv_sec - time_reftime;
-	if (unlikely(time_status & STA_FREQHOLD || time_reftime == 0))
+	if (unlikely(time_status & STA_FREQHOLD))
 		secs = 0;
 
 	time_reftime = xtime.tv_sec;
@@ -394,6 +394,13 @@ int do_adjtimex(struct timex *txc)
 			}
 			/* only set allowed bits */
 			time_status &= STA_RONLY;
+			/*
+			 * If we turn on PLL adjustments then reset the
+			 * reference time to current time.
+			 */
+			if (!(time_status & STA_PLL) && (txc->status & STA_PLL))
+				time_reftime = xtime.tv_sec;
+
 			time_status |= txc->status & ~STA_RONLY;
 
 			switch (time_state) {

commit c7986acba211e8285e14c9603fb89e6f4ea0b9f8
Author: Ingo Molnar <mingo@elte.hu>
Date:   Sun Feb 22 13:29:09 2009 +0100

    time: ntp: micro-optimize ntp_update_offset()
    
    Impact: cleanup, no functionality changed
    
    The time_reftime update in ntp_update_offset() to xtime.tv_sec
    is a convoluted way of saying that we want to freeze the frequency
    and want the 'secs' delta to be 0. Also make this branch unlikely.
    
    This shaves off 8 bytes from the code size:
    
       text    data     bss     dec     hex filename
       2504     114     136    2754     ac2 ntp.o.before
       2496     114     136    2746     aba ntp.o.after
    
    Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 5202dde2f0af..580a35028693 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -141,10 +141,10 @@ static void ntp_update_offset(long offset)
 	 * Select how the frequency is to be controlled
 	 * and in which mode (PLL or FLL).
 	 */
-	if (time_status & STA_FREQHOLD || time_reftime == 0)
-		time_reftime = xtime.tv_sec;
-
 	secs = xtime.tv_sec - time_reftime;
+	if (unlikely(time_status & STA_FREQHOLD || time_reftime == 0))
+		secs = 0;
+
 	time_reftime = xtime.tv_sec;
 
 	offset64    = offset;

commit 478b7aab1682246a3d1e76e27a0aecb2f0013379
Author: Ingo Molnar <mingo@elte.hu>
Date:   Sun Feb 22 13:22:23 2009 +0100

    time: ntp: simplify ntp_update_offset_fll()
    
    Impact: cleanup, no functionality changed
    
    Change ntp_update_offset_fll() to delta logic instead of
    absolute value logic. This eliminates 'freq_adj' from the
    function.
    
    Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index ee437e1445d1..5202dde2f0af 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -103,20 +103,19 @@ static void ntp_update_frequency(void)
 	tick_length_base	 = new_base;
 }
 
-static inline s64 ntp_update_offset_fll(s64 freq_adj, s64 offset64, long secs)
+static inline s64 ntp_update_offset_fll(s64 offset64, long secs)
 {
 	time_status &= ~STA_MODE;
 
 	if (secs < MINSEC)
-		return freq_adj;
+		return 0;
 
 	if (!(time_status & STA_FLL) && (secs <= MAXSEC))
-		return freq_adj;
+		return 0;
 
-	freq_adj += div_s64(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs);
 	time_status |= STA_MODE;
 
-	return freq_adj;
+	return div_s64(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs);
 }
 
 static void ntp_update_offset(long offset)
@@ -152,7 +151,7 @@ static void ntp_update_offset(long offset)
 	freq_adj    = (offset64 * secs) <<
 			(NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant));
 
-	freq_adj    = ntp_update_offset_fll(freq_adj, offset64, secs);
+	freq_adj    += ntp_update_offset_fll(offset64, secs);
 
 	freq_adj    = min(freq_adj + time_freq, MAXFREQ_SCALED);
 

commit f939890b6687e05c42361655fb6610fa08f5a601
Author: Ingo Molnar <mingo@elte.hu>
Date:   Sun Feb 22 12:57:49 2009 +0100

    time: ntp: refactor and clean up ntp_update_offset()
    
    Impact: cleanup, no functionality changed
    
    - introduce the ntp_update_offset_fll() helper
    - clean up the flow and variable naming
    
    kernel/time/ntp.o:
    
       text    data     bss     dec     hex filename
       2504     114     136    2754     ac2 ntp.o.before
       2504     114     136    2754     ac2 ntp.o.after
    
    md5:
       01f7b8e1a5472a3056f9e4ae84d46315  ntp.o.before.asm
       01f7b8e1a5472a3056f9e4ae84d46315  ntp.o.after.asm
    
    Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index f1abad738579..ee437e1445d1 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -103,10 +103,27 @@ static void ntp_update_frequency(void)
 	tick_length_base	 = new_base;
 }
 
+static inline s64 ntp_update_offset_fll(s64 freq_adj, s64 offset64, long secs)
+{
+	time_status &= ~STA_MODE;
+
+	if (secs < MINSEC)
+		return freq_adj;
+
+	if (!(time_status & STA_FLL) && (secs <= MAXSEC))
+		return freq_adj;
+
+	freq_adj += div_s64(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs);
+	time_status |= STA_MODE;
+
+	return freq_adj;
+}
+
 static void ntp_update_offset(long offset)
 {
-	long mtemp;
 	s64 freq_adj;
+	s64 offset64;
+	long secs;
 
 	if (!(time_status & STA_PLL))
 		return;
@@ -127,22 +144,21 @@ static void ntp_update_offset(long offset)
 	 */
 	if (time_status & STA_FREQHOLD || time_reftime == 0)
 		time_reftime = xtime.tv_sec;
-	mtemp = xtime.tv_sec - time_reftime;
+
+	secs = xtime.tv_sec - time_reftime;
 	time_reftime = xtime.tv_sec;
 
-	freq_adj = (s64)offset * mtemp;
-	freq_adj <<= NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant);
-	time_status &= ~STA_MODE;
-	if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) {
-		freq_adj += div_s64((s64)offset << (NTP_SCALE_SHIFT - SHIFT_FLL),
-				    mtemp);
-		time_status |= STA_MODE;
-	}
-	freq_adj += time_freq;
-	freq_adj = min(freq_adj, MAXFREQ_SCALED);
-	time_freq = max(freq_adj, -MAXFREQ_SCALED);
+	offset64    = offset;
+	freq_adj    = (offset64 * secs) <<
+			(NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant));
+
+	freq_adj    = ntp_update_offset_fll(freq_adj, offset64, secs);
+
+	freq_adj    = min(freq_adj + time_freq, MAXFREQ_SCALED);
+
+	time_freq   = max(freq_adj, -MAXFREQ_SCALED);
 
-	time_offset = div_s64((s64)offset << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ);
+	time_offset = div_s64(offset64 << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ);
 }
 
 /**