Skip to content

Commit

Permalink
timekeeping: Provide ktime_mono_to_any()
Browse files Browse the repository at this point in the history
ktime based conversion function to map a monotonic time stamp to a
different CLOCK.

Signed-off-by: Thomas Gleixner <[email protected]>
Signed-off-by: John Stultz <[email protected]>
  • Loading branch information
KAGA-KOKO authored and johnstultz-work committed Jul 23, 2014
1 parent 48064f5 commit 9a6b519
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/linux/timekeeping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
20 changes: 20 additions & 0 deletions kernel/time/timekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,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
Expand Down

0 comments on commit 9a6b519

Please sign in to comment.