@@ -65,7 +65,9 @@ static void ntp_update_offset(long offset)
65
65
if (!(time_status & STA_PLL ))
66
66
return ;
67
67
68
- time_offset = offset * NSEC_PER_USEC ;
68
+ time_offset = offset ;
69
+ if (!(time_status & STA_NANO ))
70
+ time_offset *= NSEC_PER_USEC ;
69
71
70
72
/*
71
73
* Scale the phase adjustment and
@@ -86,8 +88,11 @@ static void ntp_update_offset(long offset)
86
88
freq_adj = time_offset * mtemp ;
87
89
freq_adj = shift_right (freq_adj , time_constant * 2 +
88
90
(SHIFT_PLL + 2 ) * 2 - SHIFT_NSEC );
89
- if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC ))
91
+ time_status &= ~STA_MODE ;
92
+ if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC )) {
90
93
freq_adj += div_s64 (time_offset << (SHIFT_NSEC - SHIFT_FLL ), mtemp );
94
+ time_status |= STA_MODE ;
95
+ }
91
96
freq_adj += time_freq ;
92
97
freq_adj = min (freq_adj , (s64 )MAXFREQ_NSEC );
93
98
time_freq = max (freq_adj , (s64 )- MAXFREQ_NSEC );
@@ -272,6 +277,7 @@ static inline void notify_cmos_timer(void) { }
272
277
*/
273
278
int do_adjtimex (struct timex * txc )
274
279
{
280
+ struct timespec ts ;
275
281
long save_adjust ;
276
282
int result ;
277
283
@@ -282,69 +288,58 @@ int do_adjtimex(struct timex *txc)
282
288
/* Now we validate the data before disabling interrupts */
283
289
284
290
if ((txc -> modes & ADJ_OFFSET_SINGLESHOT ) == ADJ_OFFSET_SINGLESHOT ) {
285
- /* singleshot must not be used with any other mode bits */
286
- if (txc -> modes != ADJ_OFFSET_SINGLESHOT &&
287
- txc -> modes != ADJ_OFFSET_SS_READ )
291
+ /* singleshot must not be used with any other mode bits */
292
+ if (txc -> modes & ~ADJ_OFFSET_SS_READ )
288
293
return - EINVAL ;
289
294
}
290
295
291
- if (txc -> modes != ADJ_OFFSET_SINGLESHOT && (txc -> modes & ADJ_OFFSET ))
292
- /* adjustment Offset limited to +- .512 seconds */
293
- if (txc -> offset <= - MAXPHASE || txc -> offset >= MAXPHASE )
294
- return - EINVAL ;
295
-
296
296
/* if the quartz is off by more than 10% something is VERY wrong ! */
297
297
if (txc -> modes & ADJ_TICK )
298
298
if (txc -> tick < 900000 /USER_HZ ||
299
299
txc -> tick > 1100000 /USER_HZ )
300
300
return - EINVAL ;
301
301
302
302
write_seqlock_irq (& xtime_lock );
303
- result = time_state ; /* mostly `TIME_OK' */
304
303
305
304
/* Save for later - semantics of adjtime is to return old value */
306
305
save_adjust = time_adjust ;
307
306
308
- #if 0 /* STA_CLOCKERR is never set yet */
309
- time_status &= ~STA_CLOCKERR ; /* reset STA_CLOCKERR */
310
- #endif
311
307
/* If there are input parameters, then process them */
312
308
if (txc -> modes ) {
313
- if (txc -> modes & ADJ_STATUS ) /* only set allowed bits */
314
- time_status = (txc -> status & ~STA_RONLY ) |
315
- (time_status & STA_RONLY );
309
+ if (txc -> modes & ADJ_STATUS ) {
310
+ if ((time_status & STA_PLL ) &&
311
+ !(txc -> status & STA_PLL )) {
312
+ time_state = TIME_OK ;
313
+ time_status = STA_UNSYNC ;
314
+ }
315
+ /* only set allowed bits */
316
+ time_status &= STA_RONLY ;
317
+ time_status |= txc -> status & ~STA_RONLY ;
318
+ }
319
+
320
+ if (txc -> modes & ADJ_NANO )
321
+ time_status |= STA_NANO ;
322
+ if (txc -> modes & ADJ_MICRO )
323
+ time_status &= ~STA_NANO ;
316
324
317
325
if (txc -> modes & ADJ_FREQUENCY ) {
318
- if (txc -> freq > MAXFREQ || txc -> freq < - MAXFREQ ) {
319
- result = - EINVAL ;
320
- goto leave ;
321
- }
322
- time_freq = ((s64 )txc -> freq * NSEC_PER_USEC )
326
+ time_freq = min (txc -> freq , MAXFREQ );
327
+ time_freq = min (time_freq , - MAXFREQ );
328
+ time_freq = ((s64 )time_freq * NSEC_PER_USEC )
323
329
>> (SHIFT_USEC - SHIFT_NSEC );
324
330
}
325
331
326
- if (txc -> modes & ADJ_MAXERROR ) {
327
- if (txc -> maxerror < 0 || txc -> maxerror >= NTP_PHASE_LIMIT ) {
328
- result = - EINVAL ;
329
- goto leave ;
330
- }
332
+ if (txc -> modes & ADJ_MAXERROR )
331
333
time_maxerror = txc -> maxerror ;
332
- }
333
-
334
- if (txc -> modes & ADJ_ESTERROR ) {
335
- if (txc -> esterror < 0 || txc -> esterror >= NTP_PHASE_LIMIT ) {
336
- result = - EINVAL ;
337
- goto leave ;
338
- }
334
+ if (txc -> modes & ADJ_ESTERROR )
339
335
time_esterror = txc -> esterror ;
340
- }
341
336
342
337
if (txc -> modes & ADJ_TIMECONST ) {
343
- if ( txc -> constant < 0 ) { /* NTP v4 uses values > 6 */
344
- result = - EINVAL ;
345
- goto leave ;
346
- }
347
- time_constant = min ( txc -> constant + 4 , ( long ) MAXTC );
338
+ time_constant = txc -> constant ;
339
+ if (!( time_status & STA_NANO ))
340
+ time_constant += 4 ;
341
+ time_constant = min ( time_constant , ( long ) MAXTC );
342
+ time_constant = max ( time_constant , 0l );
348
343
}
349
344
350
345
if (txc -> modes & ADJ_OFFSET ) {
@@ -360,16 +355,20 @@ int do_adjtimex(struct timex *txc)
360
355
if (txc -> modes & (ADJ_TICK |ADJ_FREQUENCY |ADJ_OFFSET ))
361
356
ntp_update_frequency ();
362
357
}
363
- leave :
358
+
359
+ result = time_state ; /* mostly `TIME_OK' */
364
360
if (time_status & (STA_UNSYNC |STA_CLOCKERR ))
365
361
result = TIME_ERROR ;
366
362
367
363
if ((txc -> modes == ADJ_OFFSET_SINGLESHOT ) ||
368
364
(txc -> modes == ADJ_OFFSET_SS_READ ))
369
365
txc -> offset = save_adjust ;
370
- else
366
+ else {
371
367
txc -> offset = ((long )shift_right (time_offset , SHIFT_UPDATE )) *
372
- NTP_INTERVAL_FREQ / 1000 ;
368
+ NTP_INTERVAL_FREQ ;
369
+ if (!(time_status & STA_NANO ))
370
+ txc -> offset /= NSEC_PER_USEC ;
371
+ }
373
372
txc -> freq = (time_freq / NSEC_PER_USEC ) <<
374
373
(SHIFT_USEC - SHIFT_NSEC );
375
374
txc -> maxerror = time_maxerror ;
@@ -391,7 +390,11 @@ int do_adjtimex(struct timex *txc)
391
390
txc -> stbcnt = 0 ;
392
391
write_sequnlock_irq (& xtime_lock );
393
392
394
- do_gettimeofday (& txc -> time );
393
+ getnstimeofday (& ts );
394
+ txc -> time .tv_sec = ts .tv_sec ;
395
+ txc -> time .tv_usec = ts .tv_nsec ;
396
+ if (!(time_status & STA_NANO ))
397
+ txc -> time .tv_usec /= NSEC_PER_USEC ;
395
398
396
399
notify_cmos_timer ();
397
400
0 commit comments