aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/time/timekeeping.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/time/timekeeping.c')
-rw-r--r--kernel/time/timekeeping.c59
1 files changed, 57 insertions, 2 deletions
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 7a248135c6f2..02c0b2c9c674 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -290,10 +290,65 @@ static void change_clocksource(void)
290 clock->name); 290 clock->name);
291 */ 291 */
292} 292}
293#else 293#else /* GENERIC_TIME */
294static inline void clocksource_forward_now(void) { } 294static inline void clocksource_forward_now(void) { }
295static inline void change_clocksource(void) { } 295static inline void change_clocksource(void) { }
296#endif 296
297/**
298 * ktime_get - get the monotonic time in ktime_t format
299 *
300 * returns the time in ktime_t format
301 */
302ktime_t ktime_get(void)
303{
304 struct timespec now;
305
306 ktime_get_ts(&now);
307
308 return timespec_to_ktime(now);
309}
310EXPORT_SYMBOL_GPL(ktime_get);
311
312/**
313 * ktime_get_ts - get the monotonic clock in timespec format
314 * @ts: pointer to timespec variable
315 *
316 * The function calculates the monotonic clock from the realtime
317 * clock and the wall_to_monotonic offset and stores the result
318 * in normalized timespec format in the variable pointed to by @ts.
319 */
320void ktime_get_ts(struct timespec *ts)
321{
322 struct timespec tomono;
323 unsigned long seq;
324
325 do {
326 seq = read_seqbegin(&xtime_lock);
327 getnstimeofday(ts);
328 tomono = wall_to_monotonic;
329
330 } while (read_seqretry(&xtime_lock, seq));
331
332 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec,
333 ts->tv_nsec + tomono.tv_nsec);
334}
335EXPORT_SYMBOL_GPL(ktime_get_ts);
336#endif /* !GENERIC_TIME */
337
338/**
339 * ktime_get_real - get the real (wall-) time in ktime_t format
340 *
341 * returns the time in ktime_t format
342 */
343ktime_t ktime_get_real(void)
344{
345 struct timespec now;
346
347 getnstimeofday(&now);
348
349 return timespec_to_ktime(now);
350}
351EXPORT_SYMBOL_GPL(ktime_get_real);
297 352
298/** 353/**
299 * getrawmonotonic - Returns the raw monotonic time in a timespec 354 * getrawmonotonic - Returns the raw monotonic time in a timespec