Skip to content

Commit a076b21

Browse files
ntp: Remove ntp_lock, using the timekeeping locks to protect ntp state
In order to properly handle the NTP state in future changes to the timekeeping lock management, this patch moves the management of all of the ntp state under the timekeeping locks. This allows us to remove the ntp_lock. Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Prarit Bhargava <prarit@redhat.com> Signed-off-by: John Stultz <john.stultz@linaro.org>
1 parent 0b5154f commit a076b21

1 file changed

Lines changed: 4 additions & 37 deletions

File tree

‎kernel/time/ntp.c‎

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
/*
2424
* NTP timekeeping variables:
25+
*
26+
* Note: All of the NTP state is protected by the timekeeping locks.
2527
*/
2628

27-
DEFINE_RAW_SPINLOCK(ntp_lock);
28-
2929

3030
/* USER_HZ period (usecs): */
3131
unsigned long tick_usec = TICK_USEC;
@@ -132,8 +132,6 @@ static inline void pps_reset_freq_interval(void)
132132

133133
/**
134134
* pps_clear - Clears the PPS state variables
135-
*
136-
* Must be called while holding a write on the ntp_lock
137135
*/
138136
static inline void pps_clear(void)
139137
{
@@ -148,8 +146,6 @@ static inline void pps_clear(void)
148146
/* Decrease pps_valid to indicate that another second has passed since
149147
* the last PPS signal. When it reaches 0, indicate that PPS signal is
150148
* missing.
151-
*
152-
* Must be called while holding a write on the ntp_lock
153149
*/
154150
static inline void pps_dec_valid(void)
155151
{
@@ -344,10 +340,6 @@ static void ntp_update_offset(long offset)
344340
*/
345341
void ntp_clear(void)
346342
{
347-
unsigned long flags;
348-
349-
raw_spin_lock_irqsave(&ntp_lock, flags);
350-
351343
time_adjust = 0; /* stop active adjtime() */
352344
time_status |= STA_UNSYNC;
353345
time_maxerror = NTP_PHASE_LIMIT;
@@ -360,20 +352,12 @@ void ntp_clear(void)
360352

361353
/* Clear PPS state variables */
362354
pps_clear();
363-
raw_spin_unlock_irqrestore(&ntp_lock, flags);
364-
365355
}
366356

367357

368358
u64 ntp_tick_length(void)
369359
{
370-
unsigned long flags;
371-
s64 ret;
372-
373-
raw_spin_lock_irqsave(&ntp_lock, flags);
374-
ret = tick_length;
375-
raw_spin_unlock_irqrestore(&ntp_lock, flags);
376-
return ret;
360+
return tick_length;
377361
}
378362

379363

@@ -391,9 +375,6 @@ int second_overflow(unsigned long secs)
391375
{
392376
s64 delta;
393377
int leap = 0;
394-
unsigned long flags;
395-
396-
raw_spin_lock_irqsave(&ntp_lock, flags);
397378

398379
/*
399380
* Leap second processing. If in leap-insert state at the end of the
@@ -475,8 +456,6 @@ int second_overflow(unsigned long secs)
475456
time_adjust = 0;
476457

477458
out:
478-
raw_spin_unlock_irqrestore(&ntp_lock, flags);
479-
480459
return leap;
481460
}
482461

@@ -571,10 +550,7 @@ static inline void process_adj_status(struct timex *txc, struct timespec *ts)
571550
time_status |= txc->status & ~STA_RONLY;
572551
}
573552

574-
/*
575-
* Called with ntp_lock held, so we can access and modify
576-
* all the global NTP state:
577-
*/
553+
578554
static inline void process_adjtimex_modes(struct timex *txc,
579555
struct timespec *ts,
580556
s32 *time_tai)
@@ -666,8 +642,6 @@ int __do_adjtimex(struct timex *txc, struct timespec *ts, s32 *time_tai)
666642
{
667643
int result;
668644

669-
raw_spin_lock_irq(&ntp_lock);
670-
671645
if (txc->modes & ADJ_ADJTIME) {
672646
long save_adjust = time_adjust;
673647

@@ -708,8 +682,6 @@ int __do_adjtimex(struct timex *txc, struct timespec *ts, s32 *time_tai)
708682
/* fill PPS status fields */
709683
pps_fill_timex(txc);
710684

711-
raw_spin_unlock_irq(&ntp_lock);
712-
713685
txc->time.tv_sec = ts->tv_sec;
714686
txc->time.tv_usec = ts->tv_nsec;
715687
if (!(time_status & STA_NANO))
@@ -906,8 +878,6 @@ void __hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
906878

907879
pts_norm = pps_normalize_ts(*phase_ts);
908880

909-
raw_spin_lock_irqsave(&ntp_lock, flags);
910-
911881
/* clear the error bits, they will be set again if needed */
912882
time_status &= ~(STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR);
913883

@@ -919,7 +889,6 @@ void __hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
919889
* just start the frequency interval */
920890
if (unlikely(pps_fbase.tv_sec == 0)) {
921891
pps_fbase = *raw_ts;
922-
raw_spin_unlock_irqrestore(&ntp_lock, flags);
923892
return;
924893
}
925894

@@ -934,7 +903,6 @@ void __hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
934903
time_status |= STA_PPSJITTER;
935904
/* restart the frequency calibration interval */
936905
pps_fbase = *raw_ts;
937-
raw_spin_unlock_irqrestore(&ntp_lock, flags);
938906
pr_err("hardpps: PPSJITTER: bad pulse\n");
939907
return;
940908
}
@@ -951,7 +919,6 @@ void __hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
951919

952920
hardpps_update_phase(pts_norm.nsec);
953921

954-
raw_spin_unlock_irqrestore(&ntp_lock, flags);
955922
}
956923
#endif /* CONFIG_NTP_PPS */
957924

0 commit comments

Comments
 (0)