Skip to content

Commit

Permalink
timekeeping: Add ktime_get_coarse_with_offset
Browse files Browse the repository at this point in the history
I have run into a couple of drivers using current_kernel_time()
suffering from the y2038 problem, and they could be converted
to using ktime_t, but don't have interfaces that skip the nanosecond
calculation at the moment.

This introduces ktime_get_coarse_with_offset() as a simpler
variant of ktime_get_with_offset(), and adds wrappers for the
three time domains we support with the existing function.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: y2038@lists.linaro.org
Cc: John Stultz <john.stultz@linaro.org>
Link: https://lkml.kernel.org/r/20180427134016.2525989-5-arnd@arndb.de
  • Loading branch information
Arnd Bergmann authored and Thomas Gleixner committed May 19, 2018
1 parent fb7fcc9 commit b9ff604
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/linux/timekeeping.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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_coarse_with_offset(enum tk_offsets offs);
extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
extern ktime_t ktime_get_raw(void);
extern u32 ktime_get_resolution_ns(void);
Expand All @@ -63,6 +64,11 @@ static inline ktime_t ktime_get_real(void)
return ktime_get_with_offset(TK_OFFS_REAL);
}

static inline ktime_t ktime_get_coarse_real(void)
{
return ktime_get_coarse_with_offset(TK_OFFS_REAL);
}

/**
* ktime_get_boottime - Returns monotonic time since boot in ktime_t format
*
Expand All @@ -74,6 +80,11 @@ static inline ktime_t ktime_get_boottime(void)
return ktime_get_with_offset(TK_OFFS_BOOT);
}

static inline ktime_t ktime_get_coarse_boottime(void)
{
return ktime_get_coarse_with_offset(TK_OFFS_BOOT);
}

/**
* ktime_get_clocktai - Returns the TAI time of day in ktime_t format
*/
Expand All @@ -82,6 +93,11 @@ static inline ktime_t ktime_get_clocktai(void)
return ktime_get_with_offset(TK_OFFS_TAI);
}

static inline ktime_t ktime_get_coarse_clocktai(void)
{
return ktime_get_coarse_with_offset(TK_OFFS_TAI);
}

/**
* ktime_mono_to_real - Convert monotonic time to clock realtime
*/
Expand Down
19 changes: 19 additions & 0 deletions kernel/time/timekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,25 @@ ktime_t ktime_get_with_offset(enum tk_offsets offs)
}
EXPORT_SYMBOL_GPL(ktime_get_with_offset);

ktime_t ktime_get_coarse_with_offset(enum tk_offsets offs)
{
struct timekeeper *tk = &tk_core.timekeeper;
unsigned int seq;
ktime_t base, *offset = offsets[offs];

WARN_ON(timekeeping_suspended);

do {
seq = read_seqcount_begin(&tk_core.seq);
base = ktime_add(tk->tkr_mono.base, *offset);

} while (read_seqcount_retry(&tk_core.seq, seq));

return base;

}
EXPORT_SYMBOL_GPL(ktime_get_coarse_with_offset);

/**
* ktime_mono_to_any() - convert mononotic time to any other time
* @tmono: time to convert.
Expand Down

0 comments on commit b9ff604

Please sign in to comment.