aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Geyer <harald@ccbib.org>2015-04-07 07:12:35 -0400
committerJohn Stultz <john.stultz@linaro.org>2015-05-22 12:12:28 -0400
commit6374f9124efea5fae9cba263108583c39e22f86b (patch)
tree1dc1736d56f2ef68c114e338d31e0f295a83aef7
parent6f7d79849a00bba82d3139ff91ff2aaabd12841e (diff)
timekeeping: Provide new API to get the current time resolution
This patch series introduces a new function u32 ktime_get_resolution_ns(void) which allows to clean up some driver code. In particular the IIO subsystem has a function to provide timestamps for events but no means to get their resolution. So currently the dht11 driver tries to guess the resolution in a rather messy and convoluted way. We can do much better with the new code. This API is not designed to be exposed to user space. This has been tested on i386, sunxi and mxs. Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Signed-off-by: Harald Geyer <harald@ccbib.org> [jstultz: Tweaked to make it build after upstream changes] Signed-off-by: John Stultz <john.stultz@linaro.org>
-rw-r--r--include/linux/timekeeping.h1
-rw-r--r--kernel/time/timekeeping.c17
2 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 99176af216af..9af5c1214682 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -163,6 +163,7 @@ extern ktime_t ktime_get(void);
163extern ktime_t ktime_get_with_offset(enum tk_offsets offs); 163extern ktime_t ktime_get_with_offset(enum tk_offsets offs);
164extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs); 164extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
165extern ktime_t ktime_get_raw(void); 165extern ktime_t ktime_get_raw(void);
166extern u32 ktime_get_resolution_ns(void);
166 167
167/** 168/**
168 * ktime_get_real - get the real (wall-) time in ktime_t format 169 * ktime_get_real - get the real (wall-) time in ktime_t format
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 3365e32dc208..85d376396313 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -702,6 +702,23 @@ ktime_t ktime_get(void)
702} 702}
703EXPORT_SYMBOL_GPL(ktime_get); 703EXPORT_SYMBOL_GPL(ktime_get);
704 704
705u32 ktime_get_resolution_ns(void)
706{
707 struct timekeeper *tk = &tk_core.timekeeper;
708 unsigned int seq;
709 u32 nsecs;
710
711 WARN_ON(timekeeping_suspended);
712
713 do {
714 seq = read_seqcount_begin(&tk_core.seq);
715 nsecs = tk->tkr_mono.mult >> tk->tkr_mono.shift;
716 } while (read_seqcount_retry(&tk_core.seq, seq));
717
718 return nsecs;
719}
720EXPORT_SYMBOL_GPL(ktime_get_resolution_ns);
721
705static ktime_t *offsets[TK_OFFS_MAX] = { 722static ktime_t *offsets[TK_OFFS_MAX] = {
706 [TK_OFFS_REAL] = &tk_core.timekeeper.offs_real, 723 [TK_OFFS_REAL] = &tk_core.timekeeper.offs_real,
707 [TK_OFFS_BOOT] = &tk_core.timekeeper.offs_boot, 724 [TK_OFFS_BOOT] = &tk_core.timekeeper.offs_boot,