aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/hrtimer.h1
-rw-r--r--include/linux/time.h1
-rw-r--r--kernel/time/timekeeping.c51
3 files changed, 52 insertions, 1 deletions
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 20b8e6601a04..7a9e7ee0f35c 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -312,6 +312,7 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
312 312
313extern ktime_t ktime_get(void); 313extern ktime_t ktime_get(void);
314extern ktime_t ktime_get_real(void); 314extern ktime_t ktime_get_real(void);
315extern ktime_t ktime_get_boottime(void);
315 316
316 317
317DECLARE_PER_CPU(struct tick_device, tick_cpu_device); 318DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
diff --git a/include/linux/time.h b/include/linux/time.h
index 379b9037b5b4..fa39150cb816 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -161,6 +161,7 @@ extern void getnstime_raw_and_real(struct timespec *ts_raw,
161 struct timespec *ts_real); 161 struct timespec *ts_real);
162extern void getboottime(struct timespec *ts); 162extern void getboottime(struct timespec *ts);
163extern void monotonic_to_bootbased(struct timespec *ts); 163extern void monotonic_to_bootbased(struct timespec *ts);
164extern void get_monotonic_boottime(struct timespec *ts);
164 165
165extern struct timespec timespec_trunc(struct timespec t, unsigned gran); 166extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
166extern int timekeeping_valid_for_hres(void); 167extern int timekeeping_valid_for_hres(void);
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 6262c1d18397..5fbd9aa7df95 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -907,7 +907,7 @@ static void update_wall_time(void)
907 * getboottime - Return the real time of system boot. 907 * getboottime - Return the real time of system boot.
908 * @ts: pointer to the timespec to be set 908 * @ts: pointer to the timespec to be set
909 * 909 *
910 * Returns the time of day in a timespec. 910 * Returns the wall-time of boot in a timespec.
911 * 911 *
912 * This is based on the wall_to_monotonic offset and the total suspend 912 * This is based on the wall_to_monotonic offset and the total suspend
913 * time. Calls to settimeofday will affect the value returned (which 913 * time. Calls to settimeofday will affect the value returned (which
@@ -925,6 +925,55 @@ void getboottime(struct timespec *ts)
925} 925}
926EXPORT_SYMBOL_GPL(getboottime); 926EXPORT_SYMBOL_GPL(getboottime);
927 927
928
929/**
930 * get_monotonic_boottime - Returns monotonic time since boot
931 * @ts: pointer to the timespec to be set
932 *
933 * Returns the monotonic time since boot in a timespec.
934 *
935 * This is similar to CLOCK_MONTONIC/ktime_get_ts, but also
936 * includes the time spent in suspend.
937 */
938void get_monotonic_boottime(struct timespec *ts)
939{
940 struct timespec tomono, sleep;
941 unsigned int seq;
942 s64 nsecs;
943
944 WARN_ON(timekeeping_suspended);
945
946 do {
947 seq = read_seqbegin(&xtime_lock);
948 *ts = xtime;
949 tomono = wall_to_monotonic;
950 sleep = total_sleep_time;
951 nsecs = timekeeping_get_ns();
952
953 } while (read_seqretry(&xtime_lock, seq));
954
955 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec + sleep.tv_sec,
956 ts->tv_nsec + tomono.tv_nsec + sleep.tv_nsec + nsecs);
957}
958EXPORT_SYMBOL_GPL(get_monotonic_boottime);
959
960/**
961 * ktime_get_boottime - Returns monotonic time since boot in a ktime
962 *
963 * Returns the monotonic time since boot in a ktime
964 *
965 * This is similar to CLOCK_MONTONIC/ktime_get, but also
966 * includes the time spent in suspend.
967 */
968ktime_t ktime_get_boottime(void)
969{
970 struct timespec ts;
971
972 get_monotonic_boottime(&ts);
973 return timespec_to_ktime(ts);
974}
975EXPORT_SYMBOL_GPL(ktime_get_boottime);
976
928/** 977/**
929 * monotonic_to_bootbased - Convert the monotonic time to boot based. 978 * monotonic_to_bootbased - Convert the monotonic time to boot based.
930 * @ts: pointer to the timespec to be converted 979 * @ts: pointer to the timespec to be converted