time: ntp: refactor and clean up ntp_update_offset()
authorIngo Molnar <mingo@elte.hu>
Sun, 22 Feb 2009 11:57:49 +0000 (12:57 +0100)
committerIngo Molnar <mingo@elte.hu>
Wed, 25 Feb 2009 17:38:11 +0000 (18:38 +0100)
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>
kernel/time/ntp.c

index f1abad738579998cd87dea6fc21b52e92979bf64..ee437e1445d1d8f42a934448f659fce22d3adda9 100644 (file)
@@ -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);
 }
 
 /**