Commit-ID: 9a6b51976ea3a326b6de534beec3fd87275f4ef6 Gitweb: http://git.kernel.org/tip/9a6b51976ea3a326b6de534beec3fd87275f4ef6 Author: Thomas Gleixner <tglx@xxxxxxxxxxxxx> AuthorDate: Wed, 16 Jul 2014 21:04:22 +0000 Committer: John Stultz <john.stultz@xxxxxxxxxx> CommitDate: Wed, 23 Jul 2014 10:18:01 -0700 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@xxxxxxxxxxxxx> Signed-off-by: John Stultz <john.stultz@xxxxxxxxxx> --- include/linux/timekeeping.h | 9 +++++++++ kernel/time/timekeeping.c | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 3050a7d..910a98e 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -109,6 +109,7 @@ enum tk_offsets { extern ktime_t ktime_get(void); extern ktime_t ktime_get_with_offset(enum tk_offsets offs); extern ktime_t ktime_get_monotonic_offset(void); +extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs); /** * ktime_get_real - get the real (wall-) time in ktime_t format @@ -137,6 +138,14 @@ static inline ktime_t ktime_get_clocktai(void) return ktime_get_with_offset(TK_OFFS_TAI); } +/** + * ktime_mono_to_real - Convert monotonic time to clock realtime + */ +static inline ktime_t ktime_mono_to_real(ktime_t mono) +{ + return ktime_mono_to_any(mono, TK_OFFS_REAL); +} + /* * RTC specific */ diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index e993503..032e77a 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) EXPORT_SYMBOL_GPL(ktime_get_with_offset); /** + * ktime_mono_to_any() - convert mononotic time to any other time + * @tmono: time to convert. + * @offs: which offset to use + */ +ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs) +{ + ktime_t *offset = offsets[offs]; + unsigned long seq; + ktime_t tconv; + + do { + seq = read_seqcount_begin(&tk_core.seq); + tconv = ktime_add(tmono, *offset); + } while (read_seqcount_retry(&tk_core.seq, seq)); + + return tconv; +} +EXPORT_SYMBOL_GPL(ktime_mono_to_any); + +/** * ktime_get_ts64 - get the monotonic clock in timespec64 format * @ts: pointer to timespec variable * -- To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html