All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harald Geyer <harald@ccbib.org>
To: Jonathan Cameron <jic23@kernel.org>,
	John Stultz <john.stultz@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Weinberger <richard@nod.at>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Harald Geyer <harald@ccbib.org>
Subject: [PATCHv2 1/2] timekeeping: Provide new API to get the current time resolution
Date: Tue,  7 Apr 2015 11:12:35 +0000	[thread overview]
Message-ID: <1428405156-6761-2-git-send-email-harald@ccbib.org> (raw)
In-Reply-To: <1428405156-6761-1-git-send-email-harald@ccbib.org>

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.

Signed-off-by: Harald Geyer <harald@ccbib.org>
---
changes since V1:
Improved commit message.

 include/linux/timekeeping.h |    1 +
 kernel/time/timekeeping.c   |   17 +++++++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 3eaae47..983b61e 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -163,6 +163,7 @@ extern ktime_t ktime_get(void);
 extern ktime_t ktime_get_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);
 
 /**
  * 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 91db941..8efd964 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -586,6 +586,23 @@ ktime_t ktime_get(void)
 }
 EXPORT_SYMBOL_GPL(ktime_get);
 
+u32 ktime_get_resolution_ns(void)
+{
+	struct timekeeper *tk = &tk_core.timekeeper;
+	unsigned int seq;
+	u32 nsecs;
+
+	WARN_ON(timekeeping_suspended);
+
+	do {
+		seq = read_seqcount_begin(&tk_core.seq);
+		nsecs = tk->tkr.mult >> tk->tkr.shift;
+	} while (read_seqcount_retry(&tk_core.seq, seq));
+
+	return nsecs;
+}
+EXPORT_SYMBOL_GPL(ktime_get_resolution_ns);
+
 static ktime_t *offsets[TK_OFFS_MAX] = {
 	[TK_OFFS_REAL]	= &tk_core.timekeeper.offs_real,
 	[TK_OFFS_BOOT]	= &tk_core.timekeeper.offs_boot,
-- 
1.7.2.5


  reply	other threads:[~2015-04-07 11:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-07 11:12 [PATCHv2 0/2] Provide new API to get the current time resolution Harald Geyer
2015-04-07 11:12 ` Harald Geyer [this message]
2015-04-07 22:30   ` [PATCHv2 1/2] timekeeping: " Richard Weinberger
2015-04-08  7:21     ` Richard Weinberger
2015-04-07 11:12 ` [PATCHv2 2/2] iio: dht11: Use new function ktime_get_resolution_ns() Harald Geyer
2015-04-09 13:13   ` Jonathan Cameron
2015-06-29 18:59     ` Harald Geyer
2015-06-29 19:37       ` Hartmut Knaack
2015-06-30 19:37         ` harald
2015-06-30 19:39           ` Richard Weinberger
2015-07-01 19:04           ` Hartmut Knaack
2015-07-05 12:15           ` Jonathan Cameron
2015-07-06 15:06             ` harald
2015-07-07 13:39             ` [PATCHv3 1/4] iio: dht11: whitespace changes to make checkpatch.pl --strict happy Harald Geyer
2015-07-07 13:39               ` [PATCHv3 2/4] iio: dht11: add comment " Harald Geyer
2015-07-19 13:06                 ` Jonathan Cameron
2015-07-07 13:39               ` [PATCHv3 3/4] iio: dht11: avoid multiple assignments " Harald Geyer
2015-07-19 13:08                 ` Jonathan Cameron
2015-07-07 13:39               ` [PATCHv3 4/4] iio: dht11: Use new function ktime_get_resolution_ns() Harald Geyer
2015-07-19 13:10                 ` Jonathan Cameron
2015-07-19 13:04               ` [PATCHv3 1/4] iio: dht11: whitespace changes to make checkpatch.pl --strict happy Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428405156-6761-2-git-send-email-harald@ccbib.org \
    --to=harald@ccbib.org \
    --cc=jic23@kernel.org \
    --cc=john.stultz@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richard@nod.at \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.