aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/timekeeping.h1
-rw-r--r--kernel/time/timekeeping.c30
2 files changed, 31 insertions, 0 deletions
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 115d55e11bc9..91454dea2bc6 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -29,6 +29,7 @@ struct timespec get_monotonic_coarse(void);
29extern void getrawmonotonic(struct timespec *ts); 29extern void getrawmonotonic(struct timespec *ts);
30extern void ktime_get_ts64(struct timespec64 *ts); 30extern void ktime_get_ts64(struct timespec64 *ts);
31extern time64_t ktime_get_seconds(void); 31extern time64_t ktime_get_seconds(void);
32extern time64_t ktime_get_real_seconds(void);
32 33
33extern int __getnstimeofday64(struct timespec64 *tv); 34extern int __getnstimeofday64(struct timespec64 *tv);
34extern void getnstimeofday64(struct timespec64 *tv); 35extern void getnstimeofday64(struct timespec64 *tv);
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index a693270efafb..0aef92a0a701 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -676,6 +676,36 @@ time64_t ktime_get_seconds(void)
676} 676}
677EXPORT_SYMBOL_GPL(ktime_get_seconds); 677EXPORT_SYMBOL_GPL(ktime_get_seconds);
678 678
679/**
680 * ktime_get_real_seconds - Get the seconds portion of CLOCK_REALTIME
681 *
682 * Returns the wall clock seconds since 1970. This replaces the
683 * get_seconds() interface which is not y2038 safe on 32bit systems.
684 *
685 * For 64bit systems the fast access to tk->xtime_sec is preserved. On
686 * 32bit systems the access must be protected with the sequence
687 * counter to provide "atomic" access to the 64bit tk->xtime_sec
688 * value.
689 */
690time64_t ktime_get_real_seconds(void)
691{
692 struct timekeeper *tk = &tk_core.timekeeper;
693 time64_t seconds;
694 unsigned int seq;
695
696 if (IS_ENABLED(CONFIG_64BIT))
697 return tk->xtime_sec;
698
699 do {
700 seq = read_seqcount_begin(&tk_core.seq);
701 seconds = tk->xtime_sec;
702
703 } while (read_seqcount_retry(&tk_core.seq, seq));
704
705 return seconds;
706}
707EXPORT_SYMBOL_GPL(ktime_get_real_seconds);
708
679#ifdef CONFIG_NTP_PPS 709#ifdef CONFIG_NTP_PPS
680 710
681/** 711/**