Skip to content

Commit 7ec88e4

Browse files
arndbjohnstultz-work
authored andcommitted
ntp/pps: use timespec64 for hardpps()
There is only one user of the hardpps function in the kernel, so it makes sense to atomically change it over to using 64-bit timestamps for y2038 safety. In the hardpps implementation, we also need to change the pps_normtime structure, which is similar to struct timespec and also requires a 64-bit seconds portion. This introduces two temporary variables in pps_kc_event() to do the conversion, they will be removed again in the next step, which seemed preferable to having a larger patch changing it all at the same time. Acked-by: Richard Cochran <richardcochran@gmail.com> Acked-by: David S. Miller <davem@davemloft.net> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: John Stultz <john.stultz@linaro.org>
1 parent 9ffecb1 commit 7ec88e4

5 files changed

Lines changed: 12 additions & 10 deletions

File tree

‎drivers/pps/kc.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ void pps_kc_event(struct pps_device *pps, struct pps_event_time *ts,
113113
int event)
114114
{
115115
unsigned long flags;
116+
struct timespec64 real = timespec_to_timespec64(ts->ts_real);
117+
struct timespec64 raw = timespec_to_timespec64(ts->ts_raw);
116118

117119
/* Pass some events to kernel consumer if activated */
118120
spin_lock_irqsave(&pps_kc_hardpps_lock, flags);
119121
if (pps == pps_kc_hardpps_dev && event & pps_kc_hardpps_mode)
120-
hardpps(&ts->ts_real, &ts->ts_raw);
122+
hardpps(&real, &raw);
121123
spin_unlock_irqrestore(&pps_kc_hardpps_lock, flags);
122124
}

‎include/linux/timex.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ extern unsigned long tick_nsec; /* SHIFTED_HZ period (nsec) */
152152
#define NTP_INTERVAL_LENGTH (NSEC_PER_SEC/NTP_INTERVAL_FREQ)
153153

154154
extern int do_adjtimex(struct timex *);
155-
extern void hardpps(const struct timespec *, const struct timespec *);
155+
extern void hardpps(const struct timespec64 *, const struct timespec64 *);
156156

157157
int read_current_timer(unsigned long *timer_val);
158158
void ntp_notify_cmos_timer(void);

‎kernel/time/ntp.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static time64_t ntp_next_leap_sec = TIME64_MAX;
9999
static int pps_valid; /* signal watchdog counter */
100100
static long pps_tf[3]; /* phase median filter */
101101
static long pps_jitter; /* current jitter (ns) */
102-
static struct timespec pps_fbase; /* beginning of the last freq interval */
102+
static struct timespec64 pps_fbase; /* beginning of the last freq interval */
103103
static int pps_shift; /* current interval duration (s) (shift) */
104104
static int pps_intcnt; /* interval counter */
105105
static s64 pps_freq; /* frequency offset (scaled ns/s) */
@@ -773,13 +773,13 @@ int __do_adjtimex(struct timex *txc, struct timespec64 *ts, s32 *time_tai)
773773
* pps_normtime.nsec has a range of ( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ]
774774
* while timespec.tv_nsec has a range of [0, NSEC_PER_SEC) */
775775
struct pps_normtime {
776-
__kernel_time_t sec; /* seconds */
776+
s64 sec; /* seconds */
777777
long nsec; /* nanoseconds */
778778
};
779779

780780
/* normalize the timestamp so that nsec is in the
781781
( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ] interval */
782-
static inline struct pps_normtime pps_normalize_ts(struct timespec ts)
782+
static inline struct pps_normtime pps_normalize_ts(struct timespec64 ts)
783783
{
784784
struct pps_normtime norm = {
785785
.sec = ts.tv_sec,
@@ -861,7 +861,7 @@ static long hardpps_update_freq(struct pps_normtime freq_norm)
861861
pps_errcnt++;
862862
pps_dec_freq_interval();
863863
printk_deferred(KERN_ERR
864-
"hardpps: PPSERROR: interval too long - %ld s\n",
864+
"hardpps: PPSERROR: interval too long - %lld s\n",
865865
freq_norm.sec);
866866
return 0;
867867
}
@@ -948,7 +948,7 @@ static void hardpps_update_phase(long error)
948948
* This code is based on David Mills's reference nanokernel
949949
* implementation. It was mostly rewritten but keeps the same idea.
950950
*/
951-
void __hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
951+
void __hardpps(const struct timespec64 *phase_ts, const struct timespec64 *raw_ts)
952952
{
953953
struct pps_normtime pts_norm, freq_norm;
954954

@@ -969,7 +969,7 @@ void __hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
969969
}
970970

971971
/* ok, now we have a base for frequency calculation */
972-
freq_norm = pps_normalize_ts(timespec_sub(*raw_ts, pps_fbase));
972+
freq_norm = pps_normalize_ts(timespec64_sub(*raw_ts, pps_fbase));
973973

974974
/* check that the signal is in the range
975975
* [1s - MAXFREQ us, 1s + MAXFREQ us], otherwise reject it */

‎kernel/time/ntp_internal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ extern ktime_t ntp_get_next_leap(void);
99
extern int second_overflow(unsigned long secs);
1010
extern int ntp_validate_timex(struct timex *);
1111
extern int __do_adjtimex(struct timex *, struct timespec64 *, s32 *);
12-
extern void __hardpps(const struct timespec *, const struct timespec *);
12+
extern void __hardpps(const struct timespec64 *, const struct timespec64 *);
1313
#endif /* _LINUX_NTP_INTERNAL_H */

‎kernel/time/timekeeping.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2025,7 +2025,7 @@ int do_adjtimex(struct timex *txc)
20252025
/**
20262026
* hardpps() - Accessor function to NTP __hardpps function
20272027
*/
2028-
void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
2028+
void hardpps(const struct timespec64 *phase_ts, const struct timespec64 *raw_ts)
20292029
{
20302030
unsigned long flags;
20312031

0 commit comments

Comments
 (0)