Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

time: Remove duplicated code in ktime_get_raw_and_real()

The code in ktime_get_snapshot() is a superset of the code in
ktime_get_raw_and_real() code. Further, ktime_get_raw_and_real() is
called only by the PPS code, pps_get_ts(). Consolidate the
pps_get_ts() code into a single function calling ktime_get_snapshot()
and eliminate ktime_get_raw_and_real(). A side effect of this is that
the raw and real results of pps_get_ts() correspond to exactly the
same clock cycle. Previously these values represented separate reads
of the system clock.

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: kevin.b.stanton@intel.com
Cc: kevin.j.clarke@intel.com
Cc: hpa@zytor.com
Cc: jeffrey.t.kirsher@intel.com
Cc: netdev@vger.kernel.org
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Christopher S. Hall <christopher.s.hall@intel.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>

authored by

Christopher S. Hall and committed by
John Stultz
ba26621e 9da0f49c

+10 -51
+8 -13
include/linux/pps_kernel.h
··· 111 111 kt->nsec = ts.tv_nsec; 112 112 } 113 113 114 + static inline void pps_get_ts(struct pps_event_time *ts) 115 + { 116 + struct system_time_snapshot snap; 117 + 118 + ktime_get_snapshot(&snap); 119 + ts->ts_real = ktime_to_timespec64(snap.real); 114 120 #ifdef CONFIG_NTP_PPS 115 - 116 - static inline void pps_get_ts(struct pps_event_time *ts) 117 - { 118 - ktime_get_raw_and_real_ts64(&ts->ts_raw, &ts->ts_real); 121 + ts->ts_raw = ktime_to_timespec64(snap.raw); 122 + #endif 119 123 } 120 - 121 - #else /* CONFIG_NTP_PPS */ 122 - 123 - static inline void pps_get_ts(struct pps_event_time *ts) 124 - { 125 - ktime_get_real_ts64(&ts->ts_real); 126 - } 127 - 128 - #endif /* CONFIG_NTP_PPS */ 129 124 130 125 /* Subtract known time delay from PPS event time(s) */ 131 126 static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta)
+2 -38
kernel/time/timekeeping.c
··· 888 888 s64 nsec_real; 889 889 cycle_t now; 890 890 891 + WARN_ON_ONCE(timekeeping_suspended); 892 + 891 893 do { 892 894 seq = read_seqcount_begin(&tk_core.seq); 893 895 ··· 906 904 systime_snapshot->raw = ktime_add_ns(base_raw, nsec_raw); 907 905 } 908 906 EXPORT_SYMBOL_GPL(ktime_get_snapshot); 909 - 910 - #ifdef CONFIG_NTP_PPS 911 - 912 - /** 913 - * ktime_get_raw_and_real_ts64 - get day and raw monotonic time in timespec format 914 - * @ts_raw: pointer to the timespec to be set to raw monotonic time 915 - * @ts_real: pointer to the timespec to be set to the time of day 916 - * 917 - * This function reads both the time of day and raw monotonic time at the 918 - * same time atomically and stores the resulting timestamps in timespec 919 - * format. 920 - */ 921 - void ktime_get_raw_and_real_ts64(struct timespec64 *ts_raw, struct timespec64 *ts_real) 922 - { 923 - struct timekeeper *tk = &tk_core.timekeeper; 924 - unsigned long seq; 925 - s64 nsecs_raw, nsecs_real; 926 - 927 - WARN_ON_ONCE(timekeeping_suspended); 928 - 929 - do { 930 - seq = read_seqcount_begin(&tk_core.seq); 931 - 932 - *ts_raw = tk->raw_time; 933 - ts_real->tv_sec = tk->xtime_sec; 934 - ts_real->tv_nsec = 0; 935 - 936 - nsecs_raw = timekeeping_get_ns(&tk->tkr_raw); 937 - nsecs_real = timekeeping_get_ns(&tk->tkr_mono); 938 - 939 - } while (read_seqcount_retry(&tk_core.seq, seq)); 940 - 941 - timespec64_add_ns(ts_raw, nsecs_raw); 942 - timespec64_add_ns(ts_real, nsecs_real); 943 - } 944 - EXPORT_SYMBOL(ktime_get_raw_and_real_ts64); 945 - 946 - #endif /* CONFIG_NTP_PPS */ 947 907 948 908 /** 949 909 * do_gettimeofday - Returns the time of day in a timeval