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.