From patchwork Fri Jun 21 15:05:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 167393 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp858545ilk; Fri, 21 Jun 2019 08:05:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxr5ZXUwqtPAFZFqV7/8F+Za5lxxKxTe1kfFMcP8NLKYZ8X5Vykf4RaUsTTaucxRNQzoygJ X-Received: by 2002:a17:90a:9201:: with SMTP id m1mr7343549pjo.38.1561129541584; Fri, 21 Jun 2019 08:05:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561129541; cv=none; d=google.com; s=arc-20160816; b=fMi+1SYKEdfGo1GHV8VGUmz6buPqitX9Hzg0JIk+mCy986tu324sxmJrY3BMHa+v/+ l0bgIjAURTtY1pt9uRiKcCkQJ5kaqFkrIjNJaU8TaQj/uk8ZznR10AivbWh3tXG2Bhx3 2vPXkq9d1YebPETzciK9iEL0pnzLLpm8y3ieArRri/2jB7jElLYSt07YwJFl9uQzOr6b va9y2BtxWfmfxD4RXFy3y2ba8pd4Di9HTGZ6k3989YxFGKKYpexIvm5Oz1n5EQe6NrQ2 AsjsGXCiHWkPkgqyztLvCh2qKtivicYf/yF+q8AR2e/OmrZ1g0EiGNiDM/7POlQSjjVV QHEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=XaZ2vtA1x0vo0S4BqVqI8VMwBipnEgnxveBtLQZxeKM=; b=wnKwWn0Nz/Uw0L4op8wYlizvlNqoCuyLE5XjlkRlw83W0b2HpuE69Qtsbg3wTW0A6p hyDbM0HhpJQs0lehcZ/o7FGa4uEANMcEM9Ll0QY0t3K2kU0ODwaiRqDYJh053P9aKZ8+ 8bbKoEzjCALsf5p7ojiVmF3mD0YQcGLW2s+G4/SqlRaU2gYhpVM0yK/wIoiiE64/5stJ HSqbn+YXM12tK/IFImj760ZhD8rssEx91nYKQBU4jk0TBLahyHXukNJo0S4gzERMZC56 p5h4CfE1sPViaGW7HaKRxLZBlK2P87O57w4WO9wg6U7UWd14kJw3cP8bPEDuqVHniIcY anuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=dXGh30j+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m9si2597208pgq.373.2019.06.21.08.05.41; Fri, 21 Jun 2019 08:05:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=dXGh30j+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726328AbfFUPFj (ORCPT + 30 others); Fri, 21 Jun 2019 11:05:39 -0400 Received: from frisell.zx2c4.com ([192.95.5.64]:40599 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726017AbfFUPFj (ORCPT ); Fri, 21 Jun 2019 11:05:39 -0400 Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id a8f37cd9; Fri, 21 Jun 2019 14:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:mime-version:content-transfer-encoding; s=mail; bh=f+1ZpDMIWGAfcOagOZkUXYhHHpM=; b=dXGh30j+89ZrxvGORDQl L2Ng3HBm0EPpDynKsNIEQI6JxVHN4rvF7vKc2x10SQ5OAWJUFFStMGf4gxsNS4rR ix828oEOdpltmoxaMovG2dcEataDBFKk5pfCTx+0sEks693l+5WR/ibI0jmL0Nit OfpAGIKvIdlMSylL+AzWH1gn01Shbj/jpTfFJwHhqsKYdy4UO5v/csDEA7T+QJO4 6M3gd/xMG3ivdgRqhOCOdH4BWiCcJzHdi7b2ujjA+blBHjPnXMi3YhogAun3THtx z9nX+C+XjDJNbcs+0DWkzwCUX2Vn2Bz4vWc1dMqlhQXNM+ibRbvlTEOeYYy6lpxa JA== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id bf6a32d7 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Fri, 21 Jun 2019 14:32:12 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org Cc: "Jason A. Donenfeld" , Arnd Bergmann , Thomas Gleixner Subject: [PATCH v3 1/4] timekeeping: add missing non-_ns functions for fast accessors Date: Fri, 21 Jun 2019 17:05:18 +0200 Message-Id: <20190621150521.17687-1-Jason@zx2c4.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Previously there was no analogue to get proper ktime_t versions of the fast variety of ktime invocations. This commit makes the interface uniform with the other accessors. Signed-off-by: Jason A. Donenfeld Cc: Arnd Bergmann Cc: Thomas Gleixner --- Documentation/core-api/timekeeping.rst | 7 +++- include/linux/timekeeping.h | 28 ++++++++++++-- kernel/time/timekeeping.c | 52 +++++++++++++------------- 3 files changed, 55 insertions(+), 32 deletions(-) -- 2.21.0 diff --git a/Documentation/core-api/timekeeping.rst b/Documentation/core-api/timekeeping.rst index 93cbeb9daec0..47b41e948459 100644 --- a/Documentation/core-api/timekeeping.rst +++ b/Documentation/core-api/timekeeping.rst @@ -94,7 +94,7 @@ different format depending on what is required by the user: down the seconds to the full seconds of the last timer tick using the respective reference. -Coarse and fast_ns access +Coarse and fast access ------------------------- Some additional variants exist for more specialized cases: @@ -125,6 +125,11 @@ Some additional variants exist for more specialized cases: up to several microseconds on older hardware with an external clocksource. +.. c:function:: ktime_t ktime_get_mono_fast( void ) + ktime_t ktime_get_raw_fast( void ) + ktime_t ktime_get_boottime_fast( void ) + ktime_t ktime_get_real_fast( void ) + .. c:function:: u64 ktime_get_mono_fast_ns( void ) u64 ktime_get_raw_fast_ns( void ) u64 ktime_get_boot_fast_ns( void ) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index a8ab0f143ac4..c5d360779fab 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -146,10 +146,30 @@ static inline u64 ktime_get_raw_ns(void) return ktime_to_ns(ktime_get_raw()); } -extern u64 ktime_get_mono_fast_ns(void); -extern u64 ktime_get_raw_fast_ns(void); -extern u64 ktime_get_boot_fast_ns(void); -extern u64 ktime_get_real_fast_ns(void); +extern ktime_t ktime_get_mono_fast(void); +extern ktime_t ktime_get_raw_fast(void); +extern ktime_t ktime_get_boottime_fast(void); +extern ktime_t ktime_get_real_fast(void); + +static inline u64 ktime_get_mono_fast_ns(void) +{ + return ktime_to_ns(ktime_get_mono_fast()); +} + +static inline u64 ktime_get_raw_fast_ns(void) +{ + return ktime_to_ns(ktime_get_raw_fast()); +} + +static inline u64 ktime_get_boot_fast_ns(void) +{ + return ktime_to_ns(ktime_get_boottime_fast()); +} + +static inline u64 ktime_get_real_fast_ns(void) +{ + return ktime_to_ns(ktime_get_real_fast()); +} /* * timespec64/time64_t interfaces utilizing the ktime based ones diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 44b726bab4bd..4c97c9c8c217 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -443,41 +443,40 @@ static void update_fast_timekeeper(const struct tk_read_base *tkr, * of the following timestamps. Callers need to be aware of that and * deal with it. */ -static __always_inline u64 __ktime_get_fast_ns(struct tk_fast *tkf) +static __always_inline ktime_t __ktime_get_fast(struct tk_fast *tkf) { struct tk_read_base *tkr; unsigned int seq; - u64 now; + ktime_t now; do { seq = raw_read_seqcount_latch(&tkf->seq); tkr = tkf->base + (seq & 0x01); - now = ktime_to_ns(tkr->base); - - now += timekeeping_delta_to_ns(tkr, + now = ktime_add_ns(tkr->base, + timekeeping_delta_to_ns(tkr, clocksource_delta( tk_clock_read(tkr), tkr->cycle_last, - tkr->mask)); + tkr->mask))); } while (read_seqcount_retry(&tkf->seq, seq)); return now; } -u64 ktime_get_mono_fast_ns(void) +ktime_t ktime_get_mono_fast(void) { - return __ktime_get_fast_ns(&tk_fast_mono); + return __ktime_get_fast(&tk_fast_mono); } -EXPORT_SYMBOL_GPL(ktime_get_mono_fast_ns); +EXPORT_SYMBOL_GPL(ktime_get_mono_fast); -u64 ktime_get_raw_fast_ns(void) +ktime_t ktime_get_raw_fast(void) { - return __ktime_get_fast_ns(&tk_fast_raw); + return __ktime_get_fast(&tk_fast_raw); } -EXPORT_SYMBOL_GPL(ktime_get_raw_fast_ns); +EXPORT_SYMBOL_GPL(ktime_get_raw_fast); /** - * ktime_get_boot_fast_ns - NMI safe and fast access to boot clock. + * ktime_get_boottime_fast - NMI safe and fast access to boot clock. * * To keep it NMI safe since we're accessing from tracing, we're not using a * separate timekeeper with updates to monotonic clock and boot offset @@ -497,47 +496,46 @@ EXPORT_SYMBOL_GPL(ktime_get_raw_fast_ns); * partially updated. Since the tk->offs_boot update is a rare event, this * should be a rare occurrence which postprocessing should be able to handle. */ -u64 notrace ktime_get_boot_fast_ns(void) +ktime_t notrace ktime_get_boottime_fast(void) { struct timekeeper *tk = &tk_core.timekeeper; - return (ktime_get_mono_fast_ns() + ktime_to_ns(tk->offs_boot)); + return ktime_add(ktime_get_mono_fast(), tk->offs_boot); } -EXPORT_SYMBOL_GPL(ktime_get_boot_fast_ns); +EXPORT_SYMBOL_GPL(ktime_get_boottime_fast); /* - * See comment for __ktime_get_fast_ns() vs. timestamp ordering + * See comment for __ktime_get_fast() vs. timestamp ordering */ -static __always_inline u64 __ktime_get_real_fast_ns(struct tk_fast *tkf) +static __always_inline ktime_t __ktime_get_real_fast(struct tk_fast *tkf) { struct tk_read_base *tkr; unsigned int seq; - u64 now; + ktime_t now; do { seq = raw_read_seqcount_latch(&tkf->seq); tkr = tkf->base + (seq & 0x01); - now = ktime_to_ns(tkr->base_real); - - now += timekeeping_delta_to_ns(tkr, + now = ktime_add_ns(tkr->base_real, + timekeeping_delta_to_ns(tkr, clocksource_delta( tk_clock_read(tkr), tkr->cycle_last, - tkr->mask)); + tkr->mask))); } while (read_seqcount_retry(&tkf->seq, seq)); return now; } /** - * ktime_get_real_fast_ns: - NMI safe and fast access to clock realtime. + * ktime_get_real_fast: - NMI safe and fast access to clock realtime. */ -u64 ktime_get_real_fast_ns(void) +ktime_t ktime_get_real_fast(void) { - return __ktime_get_real_fast_ns(&tk_fast_mono); + return __ktime_get_real_fast(&tk_fast_mono); } -EXPORT_SYMBOL_GPL(ktime_get_real_fast_ns); +EXPORT_SYMBOL_GPL(ktime_get_real_fast); /** * halt_fast_timekeeper - Prevent fast timekeeper from accessing clocksource.