From patchwork Wed May 20 17:19:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 48812 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4298721411 for ; Wed, 20 May 2015 17:20:00 +0000 (UTC) Received: by wiz9 with SMTP id 9sf22873972wiz.3 for ; Wed, 20 May 2015 10:19:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=0qBJUZQNipyZcbJxCNCPe28iNZx0eWtAj0fIO8RC4vQ=; b=BQX9knL5qmeN0yAUm7hs5OpUy0sqvcAL3dTiV6zX7PJXK/JPzlCX0t5QEbzzoNq+Mf mlVfnvtiRy791Cz9b7ZU8+CzdHIyMiDDps42Vg6sjq9I+tlHtkLVkSr4b+vf4dgLkpVm 0i0lGWE51HltL7xfeRzO1ng2C8Fd7pE0y0IbCNvTws5o5te54pfhaon6khzOT0T99XW4 1kcCytlaCBNhU0aErP6yHpFslechL5ayWimCCDK5cdiNXYeOl/RKL3JsUmlvlWvhydrm G/dafXNEsSrJzxXOM0s7qeYm083clRrRotiWkTP93O9UdOmVHrD+ehVgsfX6gUwuIsxw u3TQ== X-Gm-Message-State: ALoCoQkyB4vH+4PNNMWIFCDwU6r1744Ov9NAj23hx9gioghgNpuXveYg6gFmsb+c5DPj+c3Zi0kZ X-Received: by 10.112.151.146 with SMTP id uq18mr27330965lbb.20.1432142399182; Wed, 20 May 2015 10:19:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.130 with SMTP id ay2ls253810lab.89.gmail; Wed, 20 May 2015 10:19:59 -0700 (PDT) X-Received: by 10.112.220.34 with SMTP id pt2mr27267481lbc.81.1432142399034; Wed, 20 May 2015 10:19:59 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id h19si11535526lbo.102.2015.05.20.10.19.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 May 2015 10:19:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by lagv1 with SMTP id v1so84471941lag.3 for ; Wed, 20 May 2015 10:19:58 -0700 (PDT) X-Received: by 10.152.37.228 with SMTP id b4mr26257675lak.117.1432142398605; Wed, 20 May 2015 10:19:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1678530lbb; Wed, 20 May 2015 10:19:57 -0700 (PDT) X-Received: by 10.68.250.194 with SMTP id ze2mr66365083pbc.24.1432142392232; Wed, 20 May 2015 10:19:52 -0700 (PDT) Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com. [209.85.192.169]) by mx.google.com with ESMTPS id bf3si27291824pbd.193.2015.05.20.10.19.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 May 2015 10:19:51 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.169 as permitted sender) client-ip=209.85.192.169; Received: by pdfh10 with SMTP id h10so75888852pdf.3 for ; Wed, 20 May 2015 10:19:51 -0700 (PDT) X-Received: by 10.66.221.193 with SMTP id qg1mr64154330pac.134.1432142391079; Wed, 20 May 2015 10:19:51 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id fp3sm16745952pdb.52.2015.05.20.10.19.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 May 2015 10:19:50 -0700 (PDT) From: John Stultz To: LKML Cc: Harald Geyer , Thomas Gleixner , Ingo Molnar , John Stultz Subject: [PATCH 2/7] timekeeping: Provide new API to get the current time resolution Date: Wed, 20 May 2015 10:19:31 -0700 Message-Id: <1432142376-2077-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1432142376-2077-1-git-send-email-john.stultz@linaro.org> References: <1432142376-2077-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Harald Geyer 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 Cc: Ingo Molnar Signed-off-by: Harald Geyer [jstultz: Tweaked to make it build after upstream changes] Signed-off-by: John Stultz --- include/linux/timekeeping.h | 1 + kernel/time/timekeeping.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 99176af..9af5c12 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 3365e32..85d3763 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -702,6 +702,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_mono.mult >> tk->tkr_mono.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,