提交 f939890b 编写于 作者: I Ingo Molnar

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: NIngo Molnar <mingo@elte.hu>
上级 bc26c31d
...@@ -103,10 +103,27 @@ static void ntp_update_frequency(void) ...@@ -103,10 +103,27 @@ static void ntp_update_frequency(void)
tick_length_base = new_base; 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) static void ntp_update_offset(long offset)
{ {
long mtemp;
s64 freq_adj; s64 freq_adj;
s64 offset64;
long secs;
if (!(time_status & STA_PLL)) if (!(time_status & STA_PLL))
return; return;
...@@ -127,22 +144,21 @@ static void ntp_update_offset(long offset) ...@@ -127,22 +144,21 @@ static void ntp_update_offset(long offset)
*/ */
if (time_status & STA_FREQHOLD || time_reftime == 0) if (time_status & STA_FREQHOLD || time_reftime == 0)
time_reftime = xtime.tv_sec; time_reftime = xtime.tv_sec;
mtemp = xtime.tv_sec - time_reftime;
secs = xtime.tv_sec - time_reftime;
time_reftime = xtime.tv_sec; time_reftime = xtime.tv_sec;
freq_adj = (s64)offset * mtemp; offset64 = offset;
freq_adj <<= NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant); freq_adj = (offset64 * secs) <<
time_status &= ~STA_MODE; (NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant));
if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) {
freq_adj += div_s64((s64)offset << (NTP_SCALE_SHIFT - SHIFT_FLL), freq_adj = ntp_update_offset_fll(freq_adj, offset64, secs);
mtemp);
time_status |= STA_MODE; freq_adj = min(freq_adj + time_freq, MAXFREQ_SCALED);
}
freq_adj += time_freq; time_freq = max(freq_adj, -MAXFREQ_SCALED);
freq_adj = min(freq_adj, 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);
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册