diff options
| -rw-r--r-- | include/linux/timekeeping.h | 16 | ||||
| -rw-r--r-- | kernel/time/timekeeping.c | 19 |
2 files changed, 35 insertions, 0 deletions
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 3ef9791d7d75..42f71f4b658a 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h | |||
| @@ -51,6 +51,7 @@ enum tk_offsets { | |||
| 51 | 51 | ||
| 52 | extern ktime_t ktime_get(void); | 52 | extern ktime_t ktime_get(void); |
| 53 | extern ktime_t ktime_get_with_offset(enum tk_offsets offs); | 53 | extern ktime_t ktime_get_with_offset(enum tk_offsets offs); |
| 54 | extern ktime_t ktime_get_coarse_with_offset(enum tk_offsets offs); | ||
| 54 | extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs); | 55 | extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs); |
| 55 | extern ktime_t ktime_get_raw(void); | 56 | extern ktime_t ktime_get_raw(void); |
| 56 | extern u32 ktime_get_resolution_ns(void); | 57 | extern u32 ktime_get_resolution_ns(void); |
| @@ -63,6 +64,11 @@ static inline ktime_t ktime_get_real(void) | |||
| 63 | return ktime_get_with_offset(TK_OFFS_REAL); | 64 | return ktime_get_with_offset(TK_OFFS_REAL); |
| 64 | } | 65 | } |
| 65 | 66 | ||
| 67 | static inline ktime_t ktime_get_coarse_real(void) | ||
| 68 | { | ||
| 69 | return ktime_get_coarse_with_offset(TK_OFFS_REAL); | ||
| 70 | } | ||
| 71 | |||
| 66 | /** | 72 | /** |
| 67 | * ktime_get_boottime - Returns monotonic time since boot in ktime_t format | 73 | * ktime_get_boottime - Returns monotonic time since boot in ktime_t format |
| 68 | * | 74 | * |
| @@ -74,6 +80,11 @@ static inline ktime_t ktime_get_boottime(void) | |||
| 74 | return ktime_get_with_offset(TK_OFFS_BOOT); | 80 | return ktime_get_with_offset(TK_OFFS_BOOT); |
| 75 | } | 81 | } |
| 76 | 82 | ||
| 83 | static inline ktime_t ktime_get_coarse_boottime(void) | ||
| 84 | { | ||
| 85 | return ktime_get_coarse_with_offset(TK_OFFS_BOOT); | ||
| 86 | } | ||
| 87 | |||
| 77 | /** | 88 | /** |
| 78 | * ktime_get_clocktai - Returns the TAI time of day in ktime_t format | 89 | * ktime_get_clocktai - Returns the TAI time of day in ktime_t format |
| 79 | */ | 90 | */ |
| @@ -82,6 +93,11 @@ static inline ktime_t ktime_get_clocktai(void) | |||
| 82 | return ktime_get_with_offset(TK_OFFS_TAI); | 93 | return ktime_get_with_offset(TK_OFFS_TAI); |
| 83 | } | 94 | } |
| 84 | 95 | ||
| 96 | static inline ktime_t ktime_get_coarse_clocktai(void) | ||
| 97 | { | ||
| 98 | return ktime_get_coarse_with_offset(TK_OFFS_TAI); | ||
| 99 | } | ||
| 100 | |||
| 85 | /** | 101 | /** |
| 86 | * ktime_mono_to_real - Convert monotonic time to clock realtime | 102 | * ktime_mono_to_real - Convert monotonic time to clock realtime |
| 87 | */ | 103 | */ |
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index ed9b74ec9c0b..4786df904c22 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
| @@ -795,6 +795,25 @@ ktime_t ktime_get_with_offset(enum tk_offsets offs) | |||
| 795 | } | 795 | } |
| 796 | EXPORT_SYMBOL_GPL(ktime_get_with_offset); | 796 | EXPORT_SYMBOL_GPL(ktime_get_with_offset); |
| 797 | 797 | ||
| 798 | ktime_t ktime_get_coarse_with_offset(enum tk_offsets offs) | ||
| 799 | { | ||
| 800 | struct timekeeper *tk = &tk_core.timekeeper; | ||
| 801 | unsigned int seq; | ||
| 802 | ktime_t base, *offset = offsets[offs]; | ||
| 803 | |||
| 804 | WARN_ON(timekeeping_suspended); | ||
| 805 | |||
| 806 | do { | ||
| 807 | seq = read_seqcount_begin(&tk_core.seq); | ||
| 808 | base = ktime_add(tk->tkr_mono.base, *offset); | ||
| 809 | |||
| 810 | } while (read_seqcount_retry(&tk_core.seq, seq)); | ||
| 811 | |||
| 812 | return base; | ||
| 813 | |||
| 814 | } | ||
| 815 | EXPORT_SYMBOL_GPL(ktime_get_coarse_with_offset); | ||
| 816 | |||
| 798 | /** | 817 | /** |
| 799 | * ktime_mono_to_any() - convert mononotic time to any other time | 818 | * ktime_mono_to_any() - convert mononotic time to any other time |
| 800 | * @tmono: time to convert. | 819 | * @tmono: time to convert. |
