diff options
author | John Stultz <john.stultz@linaro.org> | 2014-07-16 17:03:59 -0400 |
---|---|---|
committer | John Stultz <john.stultz@linaro.org> | 2014-07-23 13:17:53 -0400 |
commit | 49cd6f869984692547c57621bf42697aaa7f5622 (patch) | |
tree | f0bb760b91afa73f12f6f90db14b190728c0780b /include/linux/ktime.h | |
parent | 361a3bf00582469877f8d18ff20f1efa6b781274 (diff) |
time: More core infrastructure for timespec64
Helper and conversion functions for timespec64.
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Diffstat (limited to 'include/linux/ktime.h')
-rw-r--r-- | include/linux/ktime.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/linux/ktime.h b/include/linux/ktime.h index 538c283714e1..da6b680c252b 100644 --- a/include/linux/ktime.h +++ b/include/linux/ktime.h | |||
@@ -83,6 +83,12 @@ static inline ktime_t timespec_to_ktime(struct timespec ts) | |||
83 | return ktime_set(ts.tv_sec, ts.tv_nsec); | 83 | return ktime_set(ts.tv_sec, ts.tv_nsec); |
84 | } | 84 | } |
85 | 85 | ||
86 | /* convert a timespec64 to ktime_t format: */ | ||
87 | static inline ktime_t timespec64_to_ktime(struct timespec64 ts) | ||
88 | { | ||
89 | return ktime_set(ts.tv_sec, ts.tv_nsec); | ||
90 | } | ||
91 | |||
86 | /* convert a timeval to ktime_t format: */ | 92 | /* convert a timeval to ktime_t format: */ |
87 | static inline ktime_t timeval_to_ktime(struct timeval tv) | 93 | static inline ktime_t timeval_to_ktime(struct timeval tv) |
88 | { | 94 | { |
@@ -92,6 +98,9 @@ static inline ktime_t timeval_to_ktime(struct timeval tv) | |||
92 | /* Map the ktime_t to timespec conversion to ns_to_timespec function */ | 98 | /* Map the ktime_t to timespec conversion to ns_to_timespec function */ |
93 | #define ktime_to_timespec(kt) ns_to_timespec((kt).tv64) | 99 | #define ktime_to_timespec(kt) ns_to_timespec((kt).tv64) |
94 | 100 | ||
101 | /* Map the ktime_t to timespec conversion to ns_to_timespec function */ | ||
102 | #define ktime_to_timespec64(kt) ns_to_timespec64((kt).tv64) | ||
103 | |||
95 | /* Map the ktime_t to timeval conversion to ns_to_timeval function */ | 104 | /* Map the ktime_t to timeval conversion to ns_to_timeval function */ |
96 | #define ktime_to_timeval(kt) ns_to_timeval((kt).tv64) | 105 | #define ktime_to_timeval(kt) ns_to_timeval((kt).tv64) |
97 | 106 | ||
@@ -213,6 +222,25 @@ static inline __must_check bool ktime_to_timespec_cond(const ktime_t kt, | |||
213 | } | 222 | } |
214 | } | 223 | } |
215 | 224 | ||
225 | /** | ||
226 | * ktime_to_timespec64_cond - convert a ktime_t variable to timespec64 | ||
227 | * format only if the variable contains data | ||
228 | * @kt: the ktime_t variable to convert | ||
229 | * @ts: the timespec variable to store the result in | ||
230 | * | ||
231 | * Return: %true if there was a successful conversion, %false if kt was 0. | ||
232 | */ | ||
233 | static inline __must_check bool ktime_to_timespec64_cond(const ktime_t kt, | ||
234 | struct timespec64 *ts) | ||
235 | { | ||
236 | if (kt.tv64) { | ||
237 | *ts = ktime_to_timespec64(kt); | ||
238 | return true; | ||
239 | } else { | ||
240 | return false; | ||
241 | } | ||
242 | } | ||
243 | |||
216 | /* | 244 | /* |
217 | * The resolution of the clocks. The resolution value is returned in | 245 | * The resolution of the clocks. The resolution value is returned in |
218 | * the clock_getres() system call to give application programmers an | 246 | * the clock_getres() system call to give application programmers an |