Skip to content

Commit 071eee4

Browse files
arndbjohnstultz-work
authored andcommitted
ntp/pps: replace getnstime_raw_and_real with 64-bit version
There is exactly one caller of getnstime_raw_and_real in the kernel, which is the pps_get_ts function. This changes the caller and the implementation to work on timespec64 types rather than timespec, to avoid the time_t overflow on 32-bit architectures. For consistency with the other new functions (ktime_get_seconds, ktime_get_real_*, ...), I'm renaming the function to ktime_get_raw_and_real_ts64. We still need to convert from the internal 64-bit type to 32 bit types in the caller, but this conversion is now pushed out from getnstime_raw_and_real to pps_get_ts. A follow-up patch changes the remaining pps code to completely avoid the conversion. 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 7ec88e4 commit 071eee4

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

‎include/linux/pps_kernel.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
115115

116116
static inline void pps_get_ts(struct pps_event_time *ts)
117117
{
118-
getnstime_raw_and_real(&ts->ts_raw, &ts->ts_real);
118+
struct timespec64 raw, real;
119+
120+
ktime_get_raw_and_real_ts64(&raw, &real);
121+
122+
ts->ts_raw = timespec64_to_timespec(raw);
123+
ts->ts_real = timespec64_to_timespec(real);
119124
}
120125

121126
#else /* CONFIG_NTP_PPS */

‎include/linux/timekeeping.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ extern void timekeeping_inject_sleeptime64(struct timespec64 *delta);
263263
/*
264264
* PPS accessor
265265
*/
266-
extern void getnstime_raw_and_real(struct timespec *ts_raw,
267-
struct timespec *ts_real);
266+
extern void ktime_get_raw_and_real_ts64(struct timespec64 *ts_raw,
267+
struct timespec64 *ts_real);
268268

269269
/*
270270
* Persistent clock related interfaces

‎kernel/time/timekeeping.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -849,15 +849,15 @@ EXPORT_SYMBOL_GPL(ktime_get_real_seconds);
849849
#ifdef CONFIG_NTP_PPS
850850

851851
/**
852-
* getnstime_raw_and_real - get day and raw monotonic time in timespec format
852+
* ktime_get_raw_and_real_ts64 - get day and raw monotonic time in timespec format
853853
* @ts_raw: pointer to the timespec to be set to raw monotonic time
854854
* @ts_real: pointer to the timespec to be set to the time of day
855855
*
856856
* This function reads both the time of day and raw monotonic time at the
857857
* same time atomically and stores the resulting timestamps in timespec
858858
* format.
859859
*/
860-
void getnstime_raw_and_real(struct timespec *ts_raw, struct timespec *ts_real)
860+
void ktime_get_raw_and_real_ts64(struct timespec64 *ts_raw, struct timespec64 *ts_real)
861861
{
862862
struct timekeeper *tk = &tk_core.timekeeper;
863863
unsigned long seq;
@@ -868,7 +868,7 @@ void getnstime_raw_and_real(struct timespec *ts_raw, struct timespec *ts_real)
868868
do {
869869
seq = read_seqcount_begin(&tk_core.seq);
870870

871-
*ts_raw = timespec64_to_timespec(tk->raw_time);
871+
*ts_raw = tk->raw_time;
872872
ts_real->tv_sec = tk->xtime_sec;
873873
ts_real->tv_nsec = 0;
874874

@@ -877,10 +877,10 @@ void getnstime_raw_and_real(struct timespec *ts_raw, struct timespec *ts_real)
877877

878878
} while (read_seqcount_retry(&tk_core.seq, seq));
879879

880-
timespec_add_ns(ts_raw, nsecs_raw);
881-
timespec_add_ns(ts_real, nsecs_real);
880+
timespec64_add_ns(ts_raw, nsecs_raw);
881+
timespec64_add_ns(ts_real, nsecs_real);
882882
}
883-
EXPORT_SYMBOL(getnstime_raw_and_real);
883+
EXPORT_SYMBOL(ktime_get_raw_and_real_ts64);
884884

885885
#endif /* CONFIG_NTP_PPS */
886886

0 commit comments

Comments
 (0)