aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2014-07-16 17:05:04 -0400
committerJohn Stultz <john.stultz@linaro.org>2014-07-23 18:01:49 -0400
commitf519b1a2e08c913375324a927992bb328387f169 (patch)
tree0a4ccfd703fc4bed1da94cf9f1ed355f0eda0a60
parent2044fdb03eb4e511d5028be0917899931f17461f (diff)
timekeeping: Provide ktime_get_raw()
Provide a ktime_t based interface for raw monotonic time. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: John Stultz <john.stultz@linaro.org>
-rw-r--r--include/linux/timekeeper_internal.h3
-rw-r--r--include/linux/timekeeping.h6
-rw-r--r--kernel/time/timekeeping.c25
3 files changed, 34 insertions, 0 deletions
diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h
index 8e5d77a01787..2e20275a7083 100644
--- a/include/linux/timekeeper_internal.h
+++ b/include/linux/timekeeper_internal.h
@@ -54,6 +54,9 @@ struct timekeeper {
54 /* The current UTC to TAI offset in seconds */ 54 /* The current UTC to TAI offset in seconds */
55 s32 tai_offset; 55 s32 tai_offset;
56 56
57 /* Monotonic raw base time */
58 ktime_t base_raw;
59
57 /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */ 60 /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
58 struct timespec64 raw_time; 61 struct timespec64 raw_time;
59 62
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index f0f12a84a31b..58ad7eff83ff 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -107,6 +107,7 @@ enum tk_offsets {
107extern ktime_t ktime_get(void); 107extern ktime_t ktime_get(void);
108extern ktime_t ktime_get_with_offset(enum tk_offsets offs); 108extern ktime_t ktime_get_with_offset(enum tk_offsets offs);
109extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs); 109extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
110extern ktime_t ktime_get_raw(void);
110 111
111/** 112/**
112 * ktime_get_real - get the real (wall-) time in ktime_t format 113 * ktime_get_real - get the real (wall-) time in ktime_t format
@@ -158,6 +159,11 @@ static inline u64 ktime_get_boot_ns(void)
158 return ktime_to_ns(ktime_get_boottime()); 159 return ktime_to_ns(ktime_get_boottime());
159} 160}
160 161
162static inline u64 ktime_get_raw_ns(void)
163{
164 return ktime_to_ns(ktime_get_raw());
165}
166
161/* 167/*
162 * Timespec interfaces utilizing the ktime based ones 168 * Timespec interfaces utilizing the ktime based ones
163 */ 169 */
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 118e91e3071c..af8051f4420d 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -305,6 +305,9 @@ static inline void tk_update_ktime_data(struct timekeeper *tk)
305 nsec *= NSEC_PER_SEC; 305 nsec *= NSEC_PER_SEC;
306 nsec += tk->wall_to_monotonic.tv_nsec; 306 nsec += tk->wall_to_monotonic.tv_nsec;
307 tk->base_mono = ns_to_ktime(nsec); 307 tk->base_mono = ns_to_ktime(nsec);
308
309 /* Update the monotonic raw base */
310 tk->base_raw = timespec64_to_ktime(tk->raw_time);
308} 311}
309 312
310/* must hold timekeeper_lock */ 313/* must hold timekeeper_lock */
@@ -467,6 +470,27 @@ ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs)
467EXPORT_SYMBOL_GPL(ktime_mono_to_any); 470EXPORT_SYMBOL_GPL(ktime_mono_to_any);
468 471
469/** 472/**
473 * ktime_get_raw - Returns the raw monotonic time in ktime_t format
474 */
475ktime_t ktime_get_raw(void)
476{
477 struct timekeeper *tk = &tk_core.timekeeper;
478 unsigned int seq;
479 ktime_t base;
480 s64 nsecs;
481
482 do {
483 seq = read_seqcount_begin(&tk_core.seq);
484 base = tk->base_raw;
485 nsecs = timekeeping_get_ns_raw(tk);
486
487 } while (read_seqcount_retry(&tk_core.seq, seq));
488
489 return ktime_add_ns(base, nsecs);
490}
491EXPORT_SYMBOL_GPL(ktime_get_raw);
492
493/**
470 * ktime_get_ts64 - get the monotonic clock in timespec64 format 494 * ktime_get_ts64 - get the monotonic clock in timespec64 format
471 * @ts: pointer to timespec variable 495 * @ts: pointer to timespec variable
472 * 496 *
@@ -878,6 +902,7 @@ void __init timekeeping_init(void)
878 tk_set_xtime(tk, &now); 902 tk_set_xtime(tk, &now);
879 tk->raw_time.tv_sec = 0; 903 tk->raw_time.tv_sec = 0;
880 tk->raw_time.tv_nsec = 0; 904 tk->raw_time.tv_nsec = 0;
905 tk->base_raw.tv64 = 0;
881 if (boot.tv_sec == 0 && boot.tv_nsec == 0) 906 if (boot.tv_sec == 0 && boot.tv_nsec == 0)
882 boot = tk_xtime(tk); 907 boot = tk_xtime(tk);
883 908