diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2014-07-16 17:04:22 -0400 |
---|---|---|
committer | John Stultz <john.stultz@linaro.org> | 2014-07-23 13:18:01 -0400 |
commit | 9a6b51976ea3a326b6de534beec3fd87275f4ef6 (patch) | |
tree | 4f9eed2b231c527dab091620da6354fff97eae28 | |
parent | 48064f5f67d58f95094305ac575d5372b58e265f (diff) |
timekeeping: Provide ktime_mono_to_any()
ktime based conversion function to map a monotonic time stamp to a
different CLOCK.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: John Stultz <john.stultz@linaro.org>
-rw-r--r-- | include/linux/timekeeping.h | 9 | ||||
-rw-r--r-- | kernel/time/timekeeping.c | 20 |
2 files changed, 29 insertions, 0 deletions
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 3050a7d0a5a9..910a98ef2154 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h | |||
@@ -109,6 +109,7 @@ enum tk_offsets { | |||
109 | extern ktime_t ktime_get(void); | 109 | extern ktime_t ktime_get(void); |
110 | extern ktime_t ktime_get_with_offset(enum tk_offsets offs); | 110 | extern ktime_t ktime_get_with_offset(enum tk_offsets offs); |
111 | extern ktime_t ktime_get_monotonic_offset(void); | 111 | extern ktime_t ktime_get_monotonic_offset(void); |
112 | extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs); | ||
112 | 113 | ||
113 | /** | 114 | /** |
114 | * ktime_get_real - get the real (wall-) time in ktime_t format | 115 | * ktime_get_real - get the real (wall-) time in ktime_t format |
@@ -137,6 +138,14 @@ static inline ktime_t ktime_get_clocktai(void) | |||
137 | return ktime_get_with_offset(TK_OFFS_TAI); | 138 | return ktime_get_with_offset(TK_OFFS_TAI); |
138 | } | 139 | } |
139 | 140 | ||
141 | /** | ||
142 | * ktime_mono_to_real - Convert monotonic time to clock realtime | ||
143 | */ | ||
144 | static inline ktime_t ktime_mono_to_real(ktime_t mono) | ||
145 | { | ||
146 | return ktime_mono_to_any(mono, TK_OFFS_REAL); | ||
147 | } | ||
148 | |||
140 | /* | 149 | /* |
141 | * RTC specific | 150 | * RTC specific |
142 | */ | 151 | */ |
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index e99350319eec..032e77a54a79 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
@@ -451,6 +451,26 @@ ktime_t ktime_get_with_offset(enum tk_offsets offs) | |||
451 | EXPORT_SYMBOL_GPL(ktime_get_with_offset); | 451 | EXPORT_SYMBOL_GPL(ktime_get_with_offset); |
452 | 452 | ||
453 | /** | 453 | /** |
454 | * ktime_mono_to_any() - convert mononotic time to any other time | ||
455 | * @tmono: time to convert. | ||
456 | * @offs: which offset to use | ||
457 | */ | ||
458 | ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs) | ||
459 | { | ||
460 | ktime_t *offset = offsets[offs]; | ||
461 | unsigned long seq; | ||
462 | ktime_t tconv; | ||
463 | |||
464 | do { | ||
465 | seq = read_seqcount_begin(&tk_core.seq); | ||
466 | tconv = ktime_add(tmono, *offset); | ||
467 | } while (read_seqcount_retry(&tk_core.seq, seq)); | ||
468 | |||
469 | return tconv; | ||
470 | } | ||
471 | EXPORT_SYMBOL_GPL(ktime_mono_to_any); | ||
472 | |||
473 | /** | ||
454 | * ktime_get_ts64 - get the monotonic clock in timespec64 format | 474 | * ktime_get_ts64 - get the monotonic clock in timespec64 format |
455 | * @ts: pointer to timespec variable | 475 | * @ts: pointer to timespec variable |
456 | * | 476 | * |