From patchwork Fri Apr 27 13:40:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 134622 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp739280lji; Fri, 27 Apr 2018 06:41:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqI/LJ/+Z6WYU/sDgIzJmrrduo3+aatKP2E3kbYoXGeQg+CDxO77iyJ830NX1HgT+CQ2t96 X-Received: by 2002:a17:902:8f95:: with SMTP id z21-v6mr2387693plo.304.1524836499948; Fri, 27 Apr 2018 06:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524836499; cv=none; d=google.com; s=arc-20160816; b=cmVy9PfsY52dEQ1zhEEN0fzE98qrhHd11BNZYAz+RtWxhGnpbMPslZYLIRXFh6HnUh V6ZNb/JZX/ZUwCYId/V9peMpx5fPNv2dkWnios8OyUtabmGZcY1jTyQn8uCHqNs/G1Uu 9Zb/bUihcRxnO2Bd20fR35ZzcZIl02oj+lhsOwXfkH/XhJPb2rYcLp/9902wKvBuX/Hb T4X0dW5pnyMnkjoezrAEhGEPzgAWIMepKrzpLEyWJ6xMEG+tnNkBsUoOu9LdhWSoctgg zgvWo+rVkRPDtEAYCp8VZkzsb4d6wRv0lKi2KUqDZtIKgbWuvmEXr97ow53qMSLot5dU waYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=/10cQkfNKDcMTh+sGhkL3qtdyZdu0n6XfG1Xx7Tsa60=; b=Ttp+zh3cWQrJ37pab+TarDruIT0imkRR7fqidi5sP7rwsQ7CWfUlo65508BTVyU6RD ICau/SVOX/sqzRRXAYkc75KRVbeChfTVaVp5p6hFf6eouz2lrE4PyfOCot4f/81kRBhQ mhAqVHoNENMVy9XoU6yoX1cXhuq/9r2Bf4GX6NRNSNuXiYRj/enz+BBS3pLC9Z8UB+39 RTQ/hwM3cXKiNxqahvH2uwyS76JrjEyaoTEgmZdagQgjHtRNEq9SqMxPMw1GFntk2mBV BUvummdAlXrWX6zQp/aLF+78Zq722o2/n+NlvQLweBCh0EtZD25MCYlOCVoSEghbLOWO /iFg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j28si1326852pfe.337.2018.04.27.06.41.39; Fri, 27 Apr 2018 06:41:39 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932814AbeD0NlY (ORCPT + 29 others); Fri, 27 Apr 2018 09:41:24 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:42809 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932678AbeD0Nkb (ORCPT ); Fri, 27 Apr 2018 09:40:31 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPA (Nemesis) id 0Lmyqm-1eki523qSS-00h2Yn; Fri, 27 Apr 2018 15:40:21 +0200 From: Arnd Bergmann To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, Stephen Boyd , John Stultz , y2038@lists.linaro.org, Arnd Bergmann Subject: [PATCH 1/5] timekeeping: Remove timespec64 hack Date: Fri, 27 Apr 2018 15:40:12 +0200 Message-Id: <20180427134016.2525989-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180427134016.2525989-1-arnd@arndb.de> References: <20180427134016.2525989-1-arnd@arndb.de> X-Provags-ID: V03:K1:ta0UUbZTuZ+9MsfOwrA5oLOyLJcPbkv8upcObDV9YL+TJ/AbOW8 lN7pWpomTmHDhQu2ErEZbBRIbJJ6MbRmRcMy0Ri64J+NqIb0TUJNVdEYVxmSwq+Re/wOVk2 xosxU10K7tp/X6eNKsJ6ifrJgwm/VwNtaM8PJSXRWpQf9sYjx5E9c/+igZD27hOu9GvfY/f /oLxIbeiSw9E/TdYTwELQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:HhFSUw9orQo=:yBaNIRaFfoyaRcreqGxyIR h6nfdctfS+zJZVedUd2zrEZtQKFA5DW7HXONPDIriG5ItIxUj97I7gbeoBdCERSJ0Qsw3pZ9z M1YltIbJIU4LWbSAmJ7MwgcTFRiSr9EvVvdTy7DVkCBCArIgsQGOhDVkA3LHwwOcRtwmiCTFX Q7RfFxr5lVN+chAqESHJdTtNecFGwZWy3Y0w300j0/kzTl9ZgyZB5A9SaFBfGhrYA6A2W52pG L0QQ+ZELTlCGvxPTSVnEuiFG96Jt0PFQdcG1VbNI4gBqFDuuwlp0qKb4XklyiaSPpPPE/IEPV UOIa0k9Be0aL85wFecBcfXAWXNkC6s616WGbmOKTOqRmZ1rFXgE38UqpKfVdtTJs0+aSwVytm gHtCU6VpwU9cFbhVnnyZMi0iLx1yVIyTQ6w54qCRpRqolzuL9+4JlhsyiymChrHXh4Si8GGuM c38TfaHpVJktCl0dC7/bus67AdBZXlAnzQk4Tl82jYVMUli7hZoWLTSiVX1sld9he2wmEiR9E dUwkEXvEfXL8K3d4i6HX38vtEWc3VIecgdx8fWE7bX8Af9w4A0P2gJKiFB6bL2urjcvZ6SNUA nPC2eFflJERnmCkQULUpIcgyb7qDK8uZb2bhBJU8+v8B5cbz9rk5lMP/hh5j8uAfOQ6E1ji54 XmMzf6xEQ/wKoZiiyJWnM271ZQeG8ppHP418++FZGop6TiPxvVkXo12QFTBi1LqONKrc= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At this point, we have converted most of the kernel to use timespec64 consistently in place of timespec, so it seems it's time to make timespec64 the native structure and define timespec in terms of that one on 64-bit architectures. Starting with gcc-5, the compiler can completely optimize away the timespec_to_timespec64 and timespec64_to_timespec functions on 64-bit architectures. With older compilers, we introduce a couple of extra copies of local variables, but those are easily avoided by using the timespec64 based interfaces consistently, as we do in most of the important code paths already. The main upside of removing the hack is that printing the tv_sec field of a timespec64 structure can now use the %lld format string on all architectures without a cast to time64_t. Without this patch, the field is a 'long' type and would have to be printed using %ld on 64-bit architectures. Signed-off-by: Arnd Bergmann --- include/linux/time32.h | 18 +++-------------- include/linux/time64.h | 7 ------- include/linux/timekeeping32.h | 45 ------------------------------------------- kernel/time/time.c | 2 -- 4 files changed, 3 insertions(+), 69 deletions(-) -- 2.9.0 diff --git a/include/linux/time32.h b/include/linux/time32.h index d2bcd4377b56..0b14f936100a 100644 --- a/include/linux/time32.h +++ b/include/linux/time32.h @@ -18,25 +18,14 @@ /* timespec64 is defined as timespec here */ static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) { - return ts64; + return *(const struct timespec *)&ts64; } static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) { - return ts; + return *(const struct timespec64 *)&ts; } -# define timespec_equal timespec64_equal -# define timespec_compare timespec64_compare -# define set_normalized_timespec set_normalized_timespec64 -# define timespec_add timespec64_add -# define timespec_sub timespec64_sub -# define timespec_valid timespec64_valid -# define timespec_valid_strict timespec64_valid_strict -# define timespec_to_ns timespec64_to_ns -# define ns_to_timespec ns_to_timespec64 -# define timespec_add_ns timespec64_add_ns - #else static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) { @@ -55,6 +44,7 @@ static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) ret.tv_nsec = ts.tv_nsec; return ret; } +#endif static inline int timespec_equal(const struct timespec *a, const struct timespec *b) @@ -159,8 +149,6 @@ static __always_inline void timespec_add_ns(struct timespec *a, u64 ns) a->tv_nsec = ns; } -#endif - /** * time_to_tm - converts the calendar time to local broken-down time * diff --git a/include/linux/time64.h b/include/linux/time64.h index 0d96887ba4e0..0a7b2f79cec7 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -16,11 +16,6 @@ typedef __u64 timeu64_t; #include -#if __BITS_PER_LONG == 64 -/* this trick allows us to optimize out timespec64_to_timespec */ -# define timespec64 timespec -#define itimerspec64 itimerspec -#else struct timespec64 { time64_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ @@ -31,8 +26,6 @@ struct itimerspec64 { struct timespec64 it_value; }; -#endif - /* Parameters used to convert the timespec values: */ #define MSEC_PER_SEC 1000L #define USEC_PER_MSEC 1000L diff --git a/include/linux/timekeeping32.h b/include/linux/timekeeping32.h index 3616b4becb59..4ea45d0df1d4 100644 --- a/include/linux/timekeeping32.h +++ b/include/linux/timekeeping32.h @@ -16,50 +16,6 @@ static inline struct timespec current_kernel_time(void) return timespec64_to_timespec(now); } -#if BITS_PER_LONG == 64 -/** - * Deprecated. Use do_settimeofday64(). - */ -static inline int do_settimeofday(const struct timespec *ts) -{ - return do_settimeofday64(ts); -} - -static inline int __getnstimeofday(struct timespec *ts) -{ - return __getnstimeofday64(ts); -} - -static inline void getnstimeofday(struct timespec *ts) -{ - getnstimeofday64(ts); -} - -static inline void ktime_get_ts(struct timespec *ts) -{ - ktime_get_ts64(ts); -} - -static inline void ktime_get_real_ts(struct timespec *ts) -{ - getnstimeofday64(ts); -} - -static inline void getrawmonotonic(struct timespec *ts) -{ - getrawmonotonic64(ts); -} - -static inline struct timespec get_monotonic_coarse(void) -{ - return get_monotonic_coarse64(); -} - -static inline void getboottime(struct timespec *ts) -{ - return getboottime64(ts); -} -#else /** * Deprecated. Use do_settimeofday64(). */ @@ -124,7 +80,6 @@ static inline void getboottime(struct timespec *ts) getboottime64(&ts64); *ts = timespec64_to_timespec(ts64); } -#endif /* * Timespec interfaces utilizing the ktime based ones diff --git a/kernel/time/time.c b/kernel/time/time.c index 3ddf10b6523c..8e4f3fd2f84b 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -407,7 +407,6 @@ time64_t mktime64(const unsigned int year0, const unsigned int mon0, } EXPORT_SYMBOL(mktime64); -#if __BITS_PER_LONG == 32 /** * set_normalized_timespec - set timespec sec and nsec parts and normalize * @@ -468,7 +467,6 @@ struct timespec ns_to_timespec(const s64 nsec) return ts; } EXPORT_SYMBOL(ns_to_timespec); -#endif /** * ns_to_timeval - Convert nanoseconds to timeval From patchwork Fri Apr 27 13:40:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 134618 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp738495lji; Fri, 27 Apr 2018 06:40:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpNL63AVIYsbkChiW4YS1cANmeIRExn5Wy6/30KcS/NOb37y7NrNC1G7m842eBA+w47FGfm X-Received: by 10.98.185.23 with SMTP id z23mr2259361pfe.180.1524836449915; Fri, 27 Apr 2018 06:40:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524836449; cv=none; d=google.com; s=arc-20160816; b=POpscVHlRZsO94O6PzUsC0P2GknM2W8Mzj4Ogyb+uBYR1gzJp/3f+dWZYwvVwbq1PS oPTYvp5OdwRPStnbY5mMkzU+pWtb/CRqJDSWXswq1V4tFEiDTNRWsvm/1EJgEVuMCNjG CqLjM95mGfUfUQ8fgiHVvB/Ea/rtHQO/yLlFv8ibIeCxZ2bzzHOLtpOVHqS27+FKyyT2 ajJI1QfXuyYcXzo5tpqgRQpAZ3gKzJovGnpetDnXSA8QVbH+ZVlhPkctygWhvGB2sLJA Y9rYKBNLBxd2juWk75sGSRZfcpGQYHPizyalWhBKp7+s5Sf9pNKggqSMfHLDOjWi2B5J Nb0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=QCrtMWoPHCWTisOcW2dUTm5WjbAV6pUfMLAT1cbQigU=; b=TYRtsYGzkxzMzB+wt8Ho6kR3/RjpKP353B8JH60s/bs3ksOvo4DTSivtjLvmcZ6EEm jE+Gu2+nnMEmrFlAXeCaxtSdlRKuwbcRaq2ZIXBfj1xwmgP1U6gWrjtlHm0XW/+qOkHx sedvIWM3E8haJzla5a0eE2zVGZjJ61HK1omFFJm8hU7ITCc2KFDjEADKAXEs79mYHuUv wiu0qkkhHDC6C8vzmtH1NXW725XjwLt8zYtxJtWevQ/fNZpRxyRKwH0iQpbN4vgPapuN Ulv2q/c/tQRXHBit2dC8N+yCyMb8Io2cf2sctXC1z0GyvE8w0/yZj8ZM5fsnw8Tc771W DDJw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b19-v6si1315233pls.482.2018.04.27.06.40.49; Fri, 27 Apr 2018 06:40:49 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932768AbeD0Nke (ORCPT + 29 others); Fri, 27 Apr 2018 09:40:34 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:47699 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932613AbeD0Nkb (ORCPT ); Fri, 27 Apr 2018 09:40:31 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPA (Nemesis) id 0McAfD-1euoEs0iRD-00JciU; Fri, 27 Apr 2018 15:40:21 +0200 From: Arnd Bergmann To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, Stephen Boyd , John Stultz , y2038@lists.linaro.org, Arnd Bergmann Subject: [PATCH 2/5] timekeeping: Clean up ktime_get_real_ts64 Date: Fri, 27 Apr 2018 15:40:13 +0200 Message-Id: <20180427134016.2525989-3-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180427134016.2525989-1-arnd@arndb.de> References: <20180427134016.2525989-1-arnd@arndb.de> X-Provags-ID: V03:K1:CUjooTKXS2gtWcdDmypDT2d412ozPmM7npSccz7hzQ+nE6sj2qN KGXw1YliY1G9K4Ce9409D34tJ8uPH//3cwg6zJL5QQ1wMeMtU4qK+dhD5Aa7zztPjUJZwXk EI6NJAcIkfy0qtdSgq5MDPKMYAf+Yl8Yziv7034yxehD7Qamfm9ermdf3JChJaLJAyiuW4e naEUNyw+di5Z4NRWLC0cg== X-UI-Out-Filterresults: notjunk:1; V01:K0:I054Y2QP0Ds=:iY17+7Q7f6k6es3JmLjTzF SzLSipvY/LoIfRCUmdpYNS2VKkH9c3LK94U+sau5yVVm/IEjjrbitszkhJHoYxBzrQpJFXLpq 68PTy9UAzwL6+M66Nk3o2sjYU+zkJyEjNCXPTnmbYODKQ3BnmW5sfroaSBa2hxeCVvNP9AAaA djVWK5Uqm9CUNmKS7wwwPPmnR8uvgzIebiKYKOJbbhmGyMVgWHvZyyWqVrZkbSCf/7hyT9/B9 yAAPo0SupMJTa/pCsRW2OiAttKuH8jU4uSM9a8c+lV681zy1/94sDwGUb2MxbN6eZ2YIF/jCh Lke0BC2O73Ux6DTr+5mPL7ydurC7IWFLvDsHQVlncKbFqDmv/cOp7KdChq/Mtfkui5bWfPeGl g6NFcxB+asuK6AlBBRCQkUzj9XSF6EHR9mhD3DrQh4HDENf7QCT1c/WxqQ8zSvpolOR3t7piS vjawCzLHGbUGcG54SHDJ4d6f8XCbhaKSm9xh0PLyC2WASvhOMzqZFd68fHJsRU0wrtwYlaY2+ rW8O7VPrJHlk/Z9k6OeGncp51gSWP5dqwgCxUZhbfG9dqVHzdav7UXCtbMZbenuqHUoShKgYu NC4OzeBbj7Jp3hU0qEWmfw+EJnTYBkczLrKiVsK65ZRiBaU3zWZEZ76hrkpRDyvDWCjgCzTP/ ukNCANSjeXovoG4sSTRWLKBUmRVOlv/29O7txNlaQb8pBPqG3IOExar5AvHII/DuK3JA= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In a move to make ktime_get_*() the preferred driver interface into the timekeeping code, sanitizes ktime_get_real_ts64() to be a proper exported symbol rather than an alias for getnstimeofday64(). The internal __getnstimeofday64() is no longer used, so remove that and merge it into ktime_get_real_ts64(). Signed-off-by: Arnd Bergmann --- include/linux/timekeeping.h | 8 +++++--- include/linux/timekeeping32.h | 13 ++----------- kernel/time/timekeeping.c | 31 ++++++------------------------- 3 files changed, 13 insertions(+), 39 deletions(-) -- 2.9.0 diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 588a0e4b1ab9..415dae6bf1f5 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -30,15 +30,13 @@ struct timespec64 current_kernel_time64(void); struct timespec64 get_monotonic_coarse64(void); extern void getrawmonotonic64(struct timespec64 *ts); extern void ktime_get_ts64(struct timespec64 *ts); +extern void ktime_get_real_ts64(struct timespec64 *tv); extern time64_t ktime_get_seconds(void); extern time64_t __ktime_get_real_seconds(void); extern time64_t ktime_get_real_seconds(void); -extern int __getnstimeofday64(struct timespec64 *tv); -extern void getnstimeofday64(struct timespec64 *tv); extern void getboottime64(struct timespec64 *ts); -#define ktime_get_real_ts64(ts) getnstimeofday64(ts) /* * ktime_t based interfaces @@ -210,5 +208,9 @@ extern void read_persistent_clock64(struct timespec64 *ts); extern void read_boot_clock64(struct timespec64 *ts); extern int update_persistent_clock64(struct timespec64 now); +/* + * deprecated aliases, don't use in new code + */ +#define getnstimeofday64(ts) ktime_get_real_ts64(ts) #endif diff --git a/include/linux/timekeeping32.h b/include/linux/timekeeping32.h index 4ea45d0df1d4..5abff52d07fd 100644 --- a/include/linux/timekeeping32.h +++ b/include/linux/timekeeping32.h @@ -27,20 +27,11 @@ static inline int do_settimeofday(const struct timespec *ts) return do_settimeofday64(&ts64); } -static inline int __getnstimeofday(struct timespec *ts) -{ - struct timespec64 ts64; - int ret = __getnstimeofday64(&ts64); - - *ts = timespec64_to_timespec(ts64); - return ret; -} - static inline void getnstimeofday(struct timespec *ts) { struct timespec64 ts64; - getnstimeofday64(&ts64); + ktime_get_real_ts64(&ts64); *ts = timespec64_to_timespec(ts64); } @@ -56,7 +47,7 @@ static inline void ktime_get_real_ts(struct timespec *ts) { struct timespec64 ts64; - getnstimeofday64(&ts64); + ktime_get_real_ts64(&ts64); *ts = timespec64_to_timespec(ts64); } diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 49cbceef5deb..7bbc7a6e6095 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -705,18 +705,19 @@ static void timekeeping_forward_now(struct timekeeper *tk) } /** - * __getnstimeofday64 - Returns the time of day in a timespec64. + * ktime_get_real_ts64 - Returns the time of day in a timespec64. * @ts: pointer to the timespec to be set * - * Updates the time of day in the timespec. - * Returns 0 on success, or -ve when suspended (timespec will be undefined). + * Returns the time of day in a timespec64 (WARN if suspended). */ -int __getnstimeofday64(struct timespec64 *ts) +void ktime_get_real_ts64(struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; unsigned long seq; u64 nsecs; + WARN_ON(timekeeping_suspended); + do { seq = read_seqcount_begin(&tk_core.seq); @@ -727,28 +728,8 @@ int __getnstimeofday64(struct timespec64 *ts) ts->tv_nsec = 0; timespec64_add_ns(ts, nsecs); - - /* - * Do not bail out early, in case there were callers still using - * the value, even in the face of the WARN_ON. - */ - if (unlikely(timekeeping_suspended)) - return -EAGAIN; - return 0; -} -EXPORT_SYMBOL(__getnstimeofday64); - -/** - * getnstimeofday64 - Returns the time of day in a timespec64. - * @ts: pointer to the timespec64 to be set - * - * Returns the time of day in a timespec64 (WARN if suspended). - */ -void getnstimeofday64(struct timespec64 *ts) -{ - WARN_ON(__getnstimeofday64(ts)); } -EXPORT_SYMBOL(getnstimeofday64); +EXPORT_SYMBOL(ktime_get_real_ts64); ktime_t ktime_get(void) { From patchwork Fri Apr 27 13:40:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 134620 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp738683lji; Fri, 27 Apr 2018 06:41:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq8bh/irkvW0Okepvn3qQwbwMXTH4e0OCkLw+bHthLygKcOzhoo3tXr+ByuAuO8T7Bi70pi X-Received: by 2002:a17:902:ea:: with SMTP id a97-v6mr2342548pla.28.1524836462976; Fri, 27 Apr 2018 06:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524836462; cv=none; d=google.com; s=arc-20160816; b=EiTAMARPUQvi3xOzLw6N1WgK7mWlspsybgVki5VGbz4nwBqrOjfOM47agJP8tpa8+l MRKz5DW5giWAay70xe1QamJhOY3PVnf2AHwCOnCzUoIFXiG7lk3XwtEv5GtuXxhivr88 gJo5TPF3H5E7zDJWpFNoQ8SEUjy+W5L9dX7PsrqOlAggbthWA1nFrwnTcUHtjSJOQKju LNRI5POXIOCe+TvcnxCd9baii0jKWWFWZZDQQKCP1Z6rMEElqOWEyZvTaxM4UuP+ZGjK ZC9SpBfDL2PZJkfI5cz+igtSVVS8lR0pXMpppeDyfJaThHJhbGFEaxhzFq5x++6YhtSD n2YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=AYRUoIgtq8ZOkdDiX5Zf3TJwP1FCKMWzD2ryuSCw/g4=; b=zDE22szEHvSw05Z4or24lqqDKB/qyXxoh3tLVpDQ2AYycTqNTyZBff+GR1qozjISu0 /cDAYEduh5/na/gzn5Dt0jovBgs5tf0lNqzuau2KR4LGDQ5AGH64fkEaymIxC/JvstEK 5mx4VFppilFu7n5RyzDqLIQ31YXLs8gv0TNewECI9khJ6ucA2FHm2gfX5Qu3577SUkyS UVKBCaY/pTAKLyQlW0Uu9rFCCz8e9sdD0xd8/K8MBvvo8soguR6q9JC9NcuW1yOuvGNo +NxMLPrIADnZIPffJd3et9ku9REPwM+6tugaSki0lw1jdf5SOnMK/kH/iIaOf24E8vsP mAGQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u186-v6si1270212pgc.67.2018.04.27.06.41.02; Fri, 27 Apr 2018 06:41:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758454AbeD0Nk7 (ORCPT + 29 others); Fri, 27 Apr 2018 09:40:59 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:47429 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932686AbeD0Nkc (ORCPT ); Fri, 27 Apr 2018 09:40:32 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPA (Nemesis) id 0Le9A8-1ebsOP1m04-00psGT; Fri, 27 Apr 2018 15:40:21 +0200 From: Arnd Bergmann To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, Stephen Boyd , John Stultz , y2038@lists.linaro.org, Arnd Bergmann Subject: [PATCH 3/5] timekeeping: Standardize on ktime_get_*() naming Date: Fri, 27 Apr 2018 15:40:14 +0200 Message-Id: <20180427134016.2525989-4-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180427134016.2525989-1-arnd@arndb.de> References: <20180427134016.2525989-1-arnd@arndb.de> X-Provags-ID: V03:K1:l8yFmMGyxNrpnpcCuR0HaaKEo/1YgcJlEmIN48mbDRDQFmXKSd9 jDP3bnGRItMBHwS/lcVdv9o+Ii7vyAV1NfYsiyYbAK7bgCg4gOhcuxkBlyDef56a6P5JDTB C+v5v2I/bd50DEbmB1r/Y+V7TmASxqEeqOgstgF0w9NPt5e3O9JRbqXjWrD86xVcs1QtznJ Vrs/KRilqsJfDxLyd0grA== X-UI-Out-Filterresults: notjunk:1; V01:K0:HZOMufFobjQ=:IU8qrnDRTORZ9kG6rMJt61 LFDvMRJ+LR4KKraTD2VKYjNwE8yYydEBU1eW6vVq329yQzPtPuEaWNkgbSIoqQYiiQf1Dr1H0 cdiNzC+zBwt0OMhJsbMN93mVuRckr8rRixep+ISVv3a969HvqKmUYQG+dph1uH2HxGuLeTkr/ 7OvIzZctzOfFcXGi1gbOLV3EiyW7j79XWo74JelXoZXgZrXqBXuB8oLWLE6YtkKwqw1/xoFGV /Uk0flwX3pYabuu6iJ5DNf5qeoxi7OY7zundqNrgaOLQsF2A6a+zvICExK6uI3rTkjwM/wXT/ a9AiGqZzT7exDEYjbBcKSYCB4T9a0p/F4rE7W5YTyMhJ+hFmjTPoX/Hx1GdlAxiYM6xvNF0Wq XHREdMnKYOxYnwFWdGj/xaF19atlIrPWwXktmD8uuboKPZ80WUxOcuYT459GG3I6d122RieZO j9d1iFNrDxkUTDfavMbHB+ijzBfDDJFaJjmS63D7SKO9pD4p5N7Ql+pPABw5F9W8E5OpwwrOG bMJ8q05YY1Ms65w/wx8dHllSU7nNvHf3WtClg64CN/Zw5PgNzH9pTnO5+I//Pgntp5xG5F4Cu 5N78UADX7uJwSp9JOb08XwgZO++64W+/RwYa5FYLBUx+A2aNbTH0eES7SkrdJaLBJErUL8V1n xDt/3OqCyTXiCghVLps3erT5U61aw2+uvBj/tTuZ4Pdbrq4wU2A8A1WaqosVwLZbts4Q= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current_kernel_time64, get_monotonic_coarse64, getrawmonotonic64, get_monotonic_boottime64 and timekeeping_clocktai64 interfaces have rather inconsistent naming, and they differ in the calling conventions by passing the output either by reference or as a return value. Rename them to ktime_get_coarse_real_ts64, ktime_get_coarse_ts64, ktime_get_raw_ts64, ktime_get_boottime_ts64 and ktime_get_clocktai_ts64 respectively, and provide the interfaces with macros or inline functions as needed. Signed-off-by: Arnd Bergmann --- include/linux/timekeeping.h | 43 ++++++++++++++++++++++++++++++++----------- include/linux/timekeeping32.h | 14 ++++++++++---- kernel/time/timekeeping.c | 23 +++++++++-------------- 3 files changed, 51 insertions(+), 29 deletions(-) -- 2.9.0 diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 415dae6bf1f5..3ef9791d7d75 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -19,25 +19,25 @@ extern void xtime_update(unsigned long ticks); extern int do_settimeofday64(const struct timespec64 *ts); extern int do_sys_settimeofday64(const struct timespec64 *tv, const struct timezone *tz); -/* - * Kernel time accessors - */ -struct timespec64 current_kernel_time64(void); /* * timespec64 based interfaces */ -struct timespec64 get_monotonic_coarse64(void); -extern void getrawmonotonic64(struct timespec64 *ts); +extern void ktime_get_raw_ts64(struct timespec64 *ts); extern void ktime_get_ts64(struct timespec64 *ts); extern void ktime_get_real_ts64(struct timespec64 *tv); +extern void ktime_get_coarse_ts64(struct timespec64 *ts); +extern void ktime_get_coarse_real_ts64(struct timespec64 *ts); + +void getboottime64(struct timespec64 *ts); + +/* + * time64_t base interfaces + */ extern time64_t ktime_get_seconds(void); extern time64_t __ktime_get_real_seconds(void); extern time64_t ktime_get_real_seconds(void); -extern void getboottime64(struct timespec64 *ts); - - /* * ktime_t based interfaces */ @@ -123,12 +123,12 @@ extern u64 ktime_get_real_fast_ns(void); /* * timespec64 interfaces utilizing the ktime based ones */ -static inline void get_monotonic_boottime64(struct timespec64 *ts) +static inline void ktime_get_boottime_ts64(struct timespec64 *ts) { *ts = ktime_to_timespec64(ktime_get_boottime()); } -static inline void timekeeping_clocktai64(struct timespec64 *ts) +static inline void ktime_get_clocktai_ts64(struct timespec64 *ts) { *ts = ktime_to_timespec64(ktime_get_clocktai()); } @@ -212,5 +212,26 @@ extern int update_persistent_clock64(struct timespec64 now); * deprecated aliases, don't use in new code */ #define getnstimeofday64(ts) ktime_get_real_ts64(ts) +#define get_monotonic_boottime64(ts) ktime_get_boottime_ts64(ts) +#define getrawmonotonic64(ts) ktime_get_raw_ts64(ts) +#define timekeeping_clocktai64(ts) ktime_get_clocktai_ts64(ts) + +static inline struct timespec64 current_kernel_time64(void) +{ + struct timespec64 ts; + + ktime_get_coarse_real_ts64(&ts); + + return ts; +} + +static inline struct timespec64 get_monotonic_coarse64(void) +{ + struct timespec64 ts; + + ktime_get_coarse_ts64(&ts); + + return ts; +} #endif diff --git a/include/linux/timekeeping32.h b/include/linux/timekeeping32.h index 5abff52d07fd..8762c2f45f8b 100644 --- a/include/linux/timekeeping32.h +++ b/include/linux/timekeeping32.h @@ -11,9 +11,11 @@ unsigned long get_seconds(void); static inline struct timespec current_kernel_time(void) { - struct timespec64 now = current_kernel_time64(); + struct timespec64 ts64; + + ktime_get_coarse_real_ts64(&ts64); - return timespec64_to_timespec(now); + return timespec64_to_timespec(ts64); } /** @@ -55,13 +57,17 @@ static inline void getrawmonotonic(struct timespec *ts) { struct timespec64 ts64; - getrawmonotonic64(&ts64); + ktime_get_raw_ts64(&ts64); *ts = timespec64_to_timespec(ts64); } static inline struct timespec get_monotonic_coarse(void) { - return timespec64_to_timespec(get_monotonic_coarse64()); + struct timespec64 ts64; + + ktime_get_coarse_ts64(&ts64); + + return timespec64_to_timespec(ts64); } static inline void getboottime(struct timespec *ts) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 7bbc7a6e6095..ed9b74ec9c0b 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1391,12 +1391,12 @@ int timekeeping_notify(struct clocksource *clock) } /** - * getrawmonotonic64 - Returns the raw monotonic time in a timespec + * ktime_get_raw_ts64 - Returns the raw monotonic time in a timespec * @ts: pointer to the timespec64 to be set * * Returns the raw monotonic time (completely un-modified by ntp) */ -void getrawmonotonic64(struct timespec64 *ts) +void ktime_get_raw_ts64(struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; unsigned long seq; @@ -1412,7 +1412,7 @@ void getrawmonotonic64(struct timespec64 *ts) ts->tv_nsec = 0; timespec64_add_ns(ts, nsecs); } -EXPORT_SYMBOL(getrawmonotonic64); +EXPORT_SYMBOL(ktime_get_raw_ts64); /** @@ -2114,23 +2114,20 @@ unsigned long get_seconds(void) } EXPORT_SYMBOL(get_seconds); -struct timespec64 current_kernel_time64(void) +void ktime_get_coarse_real_ts64(struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; - struct timespec64 now; unsigned long seq; do { seq = read_seqcount_begin(&tk_core.seq); - now = tk_xtime(tk); + *ts = tk_xtime(tk); } while (read_seqcount_retry(&tk_core.seq, seq)); - - return now; } -EXPORT_SYMBOL(current_kernel_time64); +EXPORT_SYMBOL(ktime_get_coarse_real_ts64); -struct timespec64 get_monotonic_coarse64(void) +void ktime_get_coarse_ts64(struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; struct timespec64 now, mono; @@ -2143,12 +2140,10 @@ struct timespec64 get_monotonic_coarse64(void) mono = tk->wall_to_monotonic; } while (read_seqcount_retry(&tk_core.seq, seq)); - set_normalized_timespec64(&now, now.tv_sec + mono.tv_sec, + set_normalized_timespec64(ts, now.tv_sec + mono.tv_sec, now.tv_nsec + mono.tv_nsec); - - return now; } -EXPORT_SYMBOL(get_monotonic_coarse64); +EXPORT_SYMBOL(ktime_get_coarse_ts64); /* * Must hold jiffies_lock From patchwork Fri Apr 27 13:40:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 134619 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp738648lji; Fri, 27 Apr 2018 06:41:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoswl3PezqA27eQ4mmTGSlDYr+c3aOBRkU3Wp2nL+maUdtoO0gXCbO2eg+KbF9qsNJU4RPe X-Received: by 2002:a63:ab45:: with SMTP id k5-v6mr1671pgp.199.1524836460776; Fri, 27 Apr 2018 06:41:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524836460; cv=none; d=google.com; s=arc-20160816; b=dVmIAiAs5CkJ2wn+iGZV0r2Z41Llr7xTB2S7wRnBI+Oy46ZeDvT6EOIuSwkQrjSTx7 tJiTKFY0Yv2qGBk1lOkDJc5qVe7AzKdnnc/lZ2xBo3RAOt6d7YDRyiT5oH1G5FRU5Ijm AUSV+X4ojyzoAJta1XI9/DWihuUYHAO1rZ8qaU0pwv4cajpUBsyOgsfVB/ZrsGdwqqa9 ouL/T6k1X5x6d/6nOhwIrYtLSYvY1Hj1PQkwksj/mqrNpoukGHiavSFXTC6a3xR4lLIH Z88dUOhgr+BwTNyX7Ne7W5cYuluS83Xe5I63/RVy9fV59QHGdQOdnHVQdx4w1NfsWPp7 O4Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=hkcgUUUkayhusUpioFAkQp+Anwrl0X+snrIAL5kEcUs=; b=l9ybv1yqa7/kM8JJyUrydmfUYYH0BfZ4nbeZZgsRisxuFCDcATFXjySGMymQ/nVO8Z 8WLzHm5dt7rJq7Na1EsFaaydpWL4TTZS/KoYQ/ngWkgF471w6npow1mShIDOeMBiHs1R pyWgmbzWrFPhEKXPasVzfqj2AyF2IosBIfkOoqHZSEFI2JdkT7UB3u7uGsBk9kdtK7/s OuEhFDsThECByxZSvctvuubT1jYnSj7o7CQY6wlwP/4fs+T7/hcr6qbKCsgqtuECNPqS SJscJhPxSQ2asENXFghjT2a0HDUbvJ5E1uLmwkZxdP4+jMz0S4U2/KwKPEleHKGBjjO1 N0wA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u186-v6si1270212pgc.67.2018.04.27.06.41.00; Fri, 27 Apr 2018 06:41:00 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758427AbeD0Nk6 (ORCPT + 29 others); Fri, 27 Apr 2018 09:40:58 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:49771 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932728AbeD0Nkc (ORCPT ); Fri, 27 Apr 2018 09:40:32 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPA (Nemesis) id 0M0e7e-1eODNb2qnm-00usDH; Fri, 27 Apr 2018 15:40:21 +0200 From: Arnd Bergmann To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, Stephen Boyd , John Stultz , y2038@lists.linaro.org, Arnd Bergmann Subject: [PATCH 4/5] timekeeping: Add ktime_get_coarse_with_offset Date: Fri, 27 Apr 2018 15:40:15 +0200 Message-Id: <20180427134016.2525989-5-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180427134016.2525989-1-arnd@arndb.de> References: <20180427134016.2525989-1-arnd@arndb.de> X-Provags-ID: V03:K1:RZWbfBd495UtIPPmKrvnzN/a9HzJiJ80X6Y8lzzcCpZJ0v+dV35 S/63rgDRKFOqGpm1o7y626SW6rEDVoAd19NhWAfYtriTogYDiwUe4yQbeCfE0qUcJ9aJH4r bD8+GdqQ1sSrdu9Qq3MjZNDvWiokRmcjmP3LvM17hrWizL9MDeg/fzQHiZJyOKbn5Px3N/g EPNkKdUxtPqLVNQu06nsQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:y+Dh7RdS9eY=:Q4L63o5WT/0FT+v4JitE3o o7qb5MZ12vnoRbB4Yx2mAM5GI3EjE+qBR+kidZl+uLzmcvo2KDnkBIl/I5zjq1bzIHeTyNM0C 5gCDgi2iu8XS3RDWQ021IiMWWm7N8rYHhyqFopnqGLduq4zNOHAoXhKdYlEpxqxwF9OVM6GG0 xnlpZlUhxFZ33+JiKBLCgN/LkkyyP7BLFrFC8NB5rvYrqPKu8SesgOP5qVy2hPe8pGC4GHFHq XbLRihNA9ro9Dfq9UxQrtXdGFECDmbLH02wOXGIoMMYbGppooudhsc085eoq5ZQKqyz9O5jbI NOIAoxcAeI6Bh/swrctrBTwtOQTyZISxM46uWaK/mxuO7JqNBH6YApCJEnjUBSS2qf1sMW8Qu NDnxMI8jSX941tzKwzBgjIdeHRwZOXZ7zoujr5oBY4JpmKf0a3RBCZyCrR344oQ//bjRBkjDE /MSqEIQ+lfpRI2kPbvGEptiygwmuQBxU9pbx6MkccYo8j0jHFMSZwyRxgizJCXa042cSjdYAP 6mstjF3EmOnBJCEXzldmZaCtKngFSCYX32Kj1FbtiwAsCsrr7UAo2f89gpX150WgWIeASAWDE Ch6u53i3DEUYel0pknJYjbqeRDONFLJnMsT71jRtZrdXIalcq91pa/fRiGrlt7Nw0UpvwQCga GNhayqBvE3acTYvM+4pEylijAGbkbjmEA3i1dtQj5myHdD/Q5Mv+8HzmQw19P3lhFOHQ= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- include/linux/timekeeping.h | 16 ++++++++++++++++ kernel/time/timekeeping.c | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) -- 2.9.0 diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 3ef9791d7d75..42f71f4b658a 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -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); @@ -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 * @@ -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 */ @@ -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 */ diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index ed9b74ec9c0b..4786df904c22 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -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. From patchwork Fri Apr 27 13:40:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 134621 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp739105lji; Fri, 27 Apr 2018 06:41:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpJtI7UwidHhnPMHM7jpRNSnCe2hwLne9SUQRVBkxUFQ09GuHgVlVmQsJo6dbMamkGYbi/W X-Received: by 2002:a17:902:b209:: with SMTP id t9-v6mr2379209plr.105.1524836488783; Fri, 27 Apr 2018 06:41:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524836488; cv=none; d=google.com; s=arc-20160816; b=y8E+PIj+Ba1HmDGY+hzDKd1AX9VEQ4tbeCrZtz+NwzY8N6d1jFtRiTd7IJysewLIUk CTv7iAt/Jux2bATUtBzSsXj9LV9x7jEkP2CxXL+5XFllZ7m0enHrqOdAnFUKR9sPegGD ZQ0apv3QCTRbJbJau00l/Apjzw1kGBcZohJZ0tDpBfP9o4gkPcdPsRpI733I37QIrnMG yFAUJfiLr6pu/tOzmjF1hM/IDA3yHVGrcukvTH6FKJJ1Ga2l8e91/VHgJ9qJ8qg5h+De M7QoLARMrR7bCgwIxm4ufrDkoHjq98QhLN6uYIqBhQtt64uFwyPBu7IYr568AoagL+fF cYgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=mk5YpSsyBDAkRzi8iew3T0+V7LxKJNs3Xs6uJZMH14k=; b=MapTPJzSKefOrYzaU+Uch2HuCKQ5vKLP2mZuOvD7DKTMTr8QLTid1iEYlXj8Xrhpcr uOQeISsWI8VtZ2pFioWBFGLp4fHPc2a/CEaB+SeGPjYQEWfOoaNyc05YCp8SELm2cR/U PKQmdyJ0vemTwY6Tibh9nDWqCeWaX2qAWrRNI/LM6trWBZewKwCrk46Hr5saLpFlbxcQ KgG2VLhTkZLOJZZfVP2+Xq08cm/nBmfL+KjUPdacCOwUxbLHi3QMmsteam2qClz8ysoq APrNpeRXD0w08hHGfRC01C92/lqY5CU7Hy/w9cHm+jKQDpUDKsvbtrOfv4zqvFegSkzo QL+g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j28si1326852pfe.337.2018.04.27.06.41.28; Fri, 27 Apr 2018 06:41:28 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932830AbeD0NlZ (ORCPT + 29 others); Fri, 27 Apr 2018 09:41:25 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:50563 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932666AbeD0Nkb (ORCPT ); Fri, 27 Apr 2018 09:40:31 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPA (Nemesis) id 0MTcE0-1elh2L3sZc-00QWsT; Fri, 27 Apr 2018 15:40:22 +0200 From: Arnd Bergmann To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, Stephen Boyd , John Stultz , y2038@lists.linaro.org, Arnd Bergmann Subject: [PATCH 5/5] timekeeping: Add more coarse clocktai/boottime interfaces Date: Fri, 27 Apr 2018 15:40:16 +0200 Message-Id: <20180427134016.2525989-6-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180427134016.2525989-1-arnd@arndb.de> References: <20180427134016.2525989-1-arnd@arndb.de> X-Provags-ID: V03:K1:uonBy91dvbuMWIj/ldRXQtdvkjZzO/hIlRcXmhW1mUizriMiMPA GFsdZ7d4EMf/2MWspTb99iulTlDts7EAqBQYgEbo7VrDShmyr+jNOJYEuJuJh3AwbRKmOs9 1h46DT+S4NaDauOmh/WnSZclNm43XaM+JD7dpImAIx+vmS4ZBYocfrUhcPTAPBWdGgx5Lm+ mkLppwOtklC6aLNHGK6Mg== X-UI-Out-Filterresults: notjunk:1; V01:K0:EF0DKsAPUBM=:thJXz+QNOYMTDmMuZx3Ge/ NCqH1OMDohWDyJdJvD/gXnn7ELSV6Yg8puy1IchZERkuzsfaWY1mQYCQoZOtiy1LhOmxLcry4 0B9Cgc+IwBpqocePQ1JKtRp3V0id58jBRuSTeK0iR6B7ZHzLDyyfJAJSrbskJwE4boe+/qmEl 5nXeRqS2GBtNXxY9+rieDCunF4Lkz1H9DMD+kqvPIy3A4SOfsaT6g8J/GbxaJ87EA61JUlTpA hg+HWPzW4oa7C2dCy7+d16Dr00ezcvTdTn3hjVD/hBc4n71j9KU3t8bhehgb0JKusdbuPLIzl WOCr5MJTMFNC3CRloou5Ac8MtFy1VDbHpbFKlGf0zzrL8tPsraGXZCHnxPPSse3WdH35gKLzK cauuGqQolCk5hK1axoOv1FumRQ8OYjUDMR7Vip2pm38bFCRlGgNCx8UlsrkpRdT5M+PPMHmBZ gCg+AntKA//2qcZW0qO8E0HpVmWehhetIFxkQIdlnoR2Bn3TyIrEY+MWv4kShrGs/gbWvx2Bv qWMsQPWm1Z93e1yuf2PeE0sXBVn8iO7qpzYobe1hdLcU9TBCT/4kpOAiFBvpiSF2YL3/4D/ew uhvd2146gjNg1FnyICxRVv56GPjUMcooNSaQkfQ8fP4YaKkykTDCCUa7lOSAOIjGRNdmfWc1N G94Pxc4J8DQpROd6LGTcA1QBU4TPicYCjAseeZaQIzcHyYwWJm1oL2KUGFnylciFw4vI= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The set of APIs we provide has a few holes for coarse times, e.g. we provide ktime_get_coarse_boottime() and ktime_get_boottime_ts64(), but not the combination of the two. This adds four new functions: ktime_get_coarse_boottime_ts64() ktime_get_boottime_seconds() ktime_get_coarse_clocktai_ts64() ktime_get_clocktai_seconds() to fill in some of the missing pieces. I have missed only the ktime_get_boottime_seconds() accessor in a few occasions in the past, but it seems better to just provide all four together, as there is very little cost to having them. Signed-off-by: Arnd Bergmann --- include/linux/timekeeping.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) -- 2.9.0 diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 42f71f4b658a..86bc2026efce 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -137,18 +137,40 @@ extern u64 ktime_get_boot_fast_ns(void); extern u64 ktime_get_real_fast_ns(void); /* - * timespec64 interfaces utilizing the ktime based ones + * timespec64/time64_t interfaces utilizing the ktime based ones + * for API completeness, these could be implemented more efficiently + * if needed. */ static inline void ktime_get_boottime_ts64(struct timespec64 *ts) { *ts = ktime_to_timespec64(ktime_get_boottime()); } +static inline void ktime_get_coarse_boottime_ts64(struct timespec64 *ts) +{ + *ts = ktime_to_timespec64(ktime_get_coarse_boottime()); +} + +static inline time64_t ktime_get_boottime_seconds(void) +{ + return ktime_divns(ktime_get_coarse_boottime(), NSEC_PER_SEC); +} + static inline void ktime_get_clocktai_ts64(struct timespec64 *ts) { *ts = ktime_to_timespec64(ktime_get_clocktai()); } +static inline void ktime_get_coarse_clocktai_ts64(struct timespec64 *ts) +{ + *ts = ktime_to_timespec64(ktime_get_coarse_clocktai()); +} + +static inline time64_t ktime_get_clocktai_seconds(void) +{ + return ktime_divns(ktime_get_coarse_clocktai(), NSEC_PER_SEC); +} + /* * RTC specific */