This source file includes following definitions.
- sys_time
- sys_stime
- sys_gettimeofday
- warp_clock
- sys_settimeofday
- sys_adjtimex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <linux/errno.h>
22 #include <linux/sched.h>
23 #include <linux/kernel.h>
24 #include <linux/param.h>
25 #include <linux/string.h>
26 #include <linux/mm.h>
27 #include <linux/timex.h>
28
29
30
31
32
33 struct timezone sys_tz = { 0, 0};
34
35 asmlinkage int sys_time(int * tloc)
36 {
37 int i;
38
39 i = CURRENT_TIME;
40 if (tloc) {
41 int error = verify_area(VERIFY_WRITE, tloc, sizeof(*tloc));
42 if (error)
43 return error;
44 put_user(i,tloc);
45 }
46 return i;
47 }
48
49 asmlinkage int sys_stime(int * tptr)
50 {
51 int error, value;
52
53 if (!suser())
54 return -EPERM;
55 error = verify_area(VERIFY_READ, tptr, sizeof(*tptr));
56 if (error)
57 return error;
58 value = get_user(tptr);
59 cli();
60 xtime.tv_sec = value;
61 xtime.tv_usec = 0;
62 time_state = TIME_BAD;
63 time_maxerror = 0x70000000;
64 time_esterror = 0x70000000;
65 sti();
66 return 0;
67 }
68
69 asmlinkage int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
70 {
71 int error;
72
73 if (tv) {
74 struct timeval ktv;
75 error = verify_area(VERIFY_WRITE, tv, sizeof *tv);
76 if (error)
77 return error;
78 do_gettimeofday(&ktv);
79 memcpy_tofs(tv, &ktv, sizeof(ktv));
80 }
81 if (tz) {
82 error = verify_area(VERIFY_WRITE, tz, sizeof *tz);
83 if (error)
84 return error;
85 memcpy_tofs(tz, &sys_tz, sizeof(sys_tz));
86 }
87 return 0;
88 }
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 inline static void warp_clock(void)
107 {
108 cli();
109 xtime.tv_sec += sys_tz.tz_minuteswest * 60;
110 sti();
111 }
112
113
114
115
116
117
118
119
120
121
122
123 asmlinkage int sys_settimeofday(struct timeval *tv, struct timezone *tz)
124 {
125 static int firsttime = 1;
126 struct timeval new_tv;
127 struct timezone new_tz;
128
129 if (!suser())
130 return -EPERM;
131 if (tv) {
132 int error = verify_area(VERIFY_READ, tv, sizeof(*tv));
133 if (error)
134 return error;
135 memcpy_fromfs(&new_tv, tv, sizeof(*tv));
136 }
137 if (tz) {
138 int error = verify_area(VERIFY_READ, tz, sizeof(*tz));
139 if (error)
140 return error;
141 memcpy_fromfs(&new_tz, tz, sizeof(*tz));
142 }
143 if (tz) {
144 sys_tz = new_tz;
145 if (firsttime) {
146 firsttime = 0;
147 if (!tv)
148 warp_clock();
149 }
150 }
151 if (tv)
152 do_settimeofday(&new_tv);
153 return 0;
154 }
155
156 long pps_offset = 0;
157 long pps_jitter = MAXTIME;
158
159 long pps_freq = 0;
160 long pps_stabil = MAXFREQ;
161
162 long pps_valid = PPS_VALID;
163
164 int pps_shift = PPS_SHIFT;
165
166 long pps_jitcnt = 0;
167 long pps_calcnt = 0;
168 long pps_errcnt = 0;
169 long pps_stbcnt = 0;
170
171
172 void (*hardpps_ptr)(struct timeval *) = (void (*)(struct timeval *))0;
173
174
175
176
177 asmlinkage int sys_adjtimex(struct timex *txc_p)
178 {
179 long ltemp, mtemp, save_adjust;
180 int error;
181
182
183 struct timex txc;
184
185 error = verify_area(VERIFY_WRITE, txc_p, sizeof(struct timex));
186 if (error)
187 return error;
188
189
190
191
192
193 memcpy_fromfs(&txc, txc_p, sizeof(struct timex));
194
195
196 if (txc.modes && !suser())
197 return -EPERM;
198
199
200
201
202 if (txc.modes != ADJ_OFFSET_SINGLESHOT && (txc.modes & ADJ_OFFSET))
203
204 if (txc.offset <= - MAXPHASE || txc.offset >= MAXPHASE )
205 return -EINVAL;
206
207
208 if (txc.modes & ADJ_TICK)
209 if (txc.tick < 900000/HZ || txc.tick > 1100000/HZ)
210 return -EINVAL;
211
212 cli();
213
214
215 save_adjust = time_adjust;
216
217
218 if (txc.modes)
219 {
220 if (time_state == TIME_BAD)
221 time_state = TIME_OK;
222
223 if (txc.modes & ADJ_STATUS)
224 time_status = txc.status;
225
226 if (txc.modes & ADJ_FREQUENCY)
227 time_freq = txc.freq;
228
229 if (txc.modes & ADJ_MAXERROR)
230 time_maxerror = txc.maxerror;
231
232 if (txc.modes & ADJ_ESTERROR)
233 time_esterror = txc.esterror;
234
235 if (txc.modes & ADJ_TIMECONST)
236 time_constant = txc.constant;
237
238 if (txc.modes & ADJ_OFFSET)
239 if ((txc.modes == ADJ_OFFSET_SINGLESHOT)
240 || !(time_status & STA_PLL))
241 {
242 time_adjust = txc.offset;
243 }
244 else if ((time_status & STA_PLL)||(time_status & STA_PPSTIME))
245 {
246 ltemp = (time_status & STA_PPSTIME &&
247 time_status & STA_PPSSIGNAL) ?
248 pps_offset : txc.offset;
249
250
251
252
253
254 if (ltemp > MAXPHASE)
255 time_offset = MAXPHASE << SHIFT_UPDATE;
256 else if (ltemp < -MAXPHASE)
257 time_offset = -(MAXPHASE << SHIFT_UPDATE);
258 else
259 time_offset = ltemp << SHIFT_UPDATE;
260
261
262
263
264
265
266
267 if (time_status & STA_FREQHOLD || time_reftime == 0)
268 time_reftime = xtime.tv_sec;
269 mtemp = xtime.tv_sec - time_reftime;
270 time_reftime = xtime.tv_sec;
271 if (time_status & STA_FLL)
272 {
273 if (mtemp >= MINSEC)
274 {
275 ltemp = ((time_offset / mtemp) << (SHIFT_USEC -
276 SHIFT_UPDATE));
277 if (ltemp < 0)
278 time_freq -= -ltemp >> SHIFT_KH;
279 else
280 time_freq += ltemp >> SHIFT_KH;
281 }
282 }
283 else
284 {
285 if (mtemp < MAXSEC)
286 {
287 ltemp *= mtemp;
288 if (ltemp < 0)
289 time_freq -= -ltemp >> (time_constant +
290 time_constant + SHIFT_KF -
291 SHIFT_USEC);
292 else
293 time_freq += ltemp >> (time_constant +
294 time_constant + SHIFT_KF -
295 SHIFT_USEC);
296 }
297 }
298 if (time_freq > time_tolerance)
299 time_freq = time_tolerance;
300 else if (time_freq < -time_tolerance)
301 time_freq = -time_tolerance;
302 }
303 if (txc.modes & ADJ_TICK)
304 tick = txc.tick;
305
306 }
307 txc.offset = save_adjust;
308 txc.freq = time_freq;
309 txc.maxerror = time_maxerror;
310 txc.esterror = time_esterror;
311 txc.status = time_status;
312 txc.constant = time_constant;
313 txc.precision = time_precision;
314 txc.tolerance = time_tolerance;
315 txc.time = xtime;
316 txc.tick = tick;
317 txc.ppsfreq = pps_freq;
318 txc.jitter = pps_jitter;
319 txc.shift = pps_shift;
320 txc.stabil = pps_stabil;
321 txc.jitcnt = pps_jitcnt;
322 txc.calcnt = pps_calcnt;
323 txc.errcnt = pps_errcnt;
324 txc.stbcnt = pps_stbcnt;
325
326 sti();
327
328 memcpy_tofs(txc_p, &txc, sizeof(struct timex));
329 return time_state;
330 }