diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-02-22 06:57:49 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-02-25 12:38:11 -0500 |
commit | f939890b6687e05c42361655fb6610fa08f5a601 (patch) | |
tree | 9d01f8c51bd2fe883c407a36bf034b412181c483 /kernel | |
parent | bc26c31d446bc9c24cd6f7003777a05fe268ae48 (diff) |
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>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/time/ntp.c | 44 |
1 files changed, 30 insertions, 14 deletions
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) | |||
103 | tick_length_base = new_base; | 103 | tick_length_base = new_base; |
104 | } | 104 | } |
105 | 105 | ||
106 | static inline s64 ntp_update_offset_fll(s64 freq_adj, s64 offset64, long secs) | ||
107 | { | ||
108 | time_status &= ~STA_MODE; | ||
109 | |||
110 | if (secs < MINSEC) | ||
111 | return freq_adj; | ||
112 | |||
113 | if (!(time_status & STA_FLL) && (secs <= MAXSEC)) | ||
114 | return freq_adj; | ||
115 | |||
116 | freq_adj += div_s64(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs); | ||
117 | time_status |= STA_MODE; | ||
118 | |||
119 | return freq_adj; | ||
120 | } | ||
121 | |||
106 | static void ntp_update_offset(long offset) | 122 | static void ntp_update_offset(long offset) |
107 | { | 123 | { |
108 | long mtemp; | ||
109 | s64 freq_adj; | 124 | s64 freq_adj; |
125 | s64 offset64; | ||
126 | long secs; | ||
110 | 127 | ||
111 | if (!(time_status & STA_PLL)) | 128 | if (!(time_status & STA_PLL)) |
112 | return; | 129 | return; |
@@ -127,22 +144,21 @@ static void ntp_update_offset(long offset) | |||
127 | */ | 144 | */ |
128 | if (time_status & STA_FREQHOLD || time_reftime == 0) | 145 | if (time_status & STA_FREQHOLD || time_reftime == 0) |
129 | time_reftime = xtime.tv_sec; | 146 | time_reftime = xtime.tv_sec; |
130 | mtemp = xtime.tv_sec - time_reftime; | 147 | |
148 | secs = xtime.tv_sec - time_reftime; | ||
131 | time_reftime = xtime.tv_sec; | 149 | time_reftime = xtime.tv_sec; |
132 | 150 | ||
133 | freq_adj = (s64)offset * mtemp; | 151 | offset64 = offset; |
134 | freq_adj <<= NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant); | 152 | freq_adj = (offset64 * secs) << |
135 | time_status &= ~STA_MODE; | 153 | (NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant)); |
136 | if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) { | 154 | |
137 | freq_adj += div_s64((s64)offset << (NTP_SCALE_SHIFT - SHIFT_FLL), | 155 | freq_adj = ntp_update_offset_fll(freq_adj, offset64, secs); |
138 | mtemp); | 156 | |
139 | time_status |= STA_MODE; | 157 | freq_adj = min(freq_adj + time_freq, MAXFREQ_SCALED); |
140 | } | 158 | |
141 | freq_adj += time_freq; | 159 | time_freq = max(freq_adj, -MAXFREQ_SCALED); |
142 | freq_adj = min(freq_adj, MAXFREQ_SCALED); | ||
143 | time_freq = max(freq_adj, -MAXFREQ_SCALED); | ||
144 | 160 | ||
145 | time_offset = div_s64((s64)offset << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ); | 161 | time_offset = div_s64(offset64 << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ); |
146 | } | 162 | } |
147 | 163 | ||
148 | /** | 164 | /** |