Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp692714imm; Fri, 17 Aug 2018 05:11:31 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxyL5VlixFRFozodWtG7LpqnXcO+INCRYa0Bf7jUMj2/jxHSB4UoKj2Tbk7XdPs70eM7rnL X-Received: by 2002:a17:902:ba88:: with SMTP id k8-v6mr33424492pls.259.1534507891682; Fri, 17 Aug 2018 05:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534507891; cv=none; d=google.com; s=arc-20160816; b=B7rm30A1S1uEtPJGkYj2Sz/jz0fCiRDAPYcoqSUX+CSRNBGqY/+doMkDZZDG4UCB10 D3K8Dw3OCW2d9rNgY/k2UraToR5Y21uZ1V/IjdXlSlCNaL4p9pwaFfVEV7i8InclcDRV je43y4ZW2IdPLaU/Rq2nxWJCWxFdwFdI2Hv5YiTHVS8S2h/yjqX5LQ2DnRWouUeMSaP4 1xqggwT2Fuv7o1IHBHT4VbkIbamZASPK9N1dQxTR7WXJE6dEToGren8Du5iFqcakDRrT RjtYiQwGEmVJdOIg/rxP6sq4plQIFcbvBEqco9nQ1iWxh+iejudlZ6bRDMR2r5eSU7rS JCdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:cc:to:subject:from :arc-authentication-results; bh=DnPqOLIkNuE+m6qL0OpIpbcJKa2LY56egrR2Kf3xrOA=; b=shpl+UjKGpbp19X+rQxGvVpjuPppN2sFwVsu+amO1VkeLPSC+EOmPR9Z5DBdz3PhYT NS4xd6nAVyWuT+2ddWPcO3H2Us0dI2YBrFzcjXFedQJ/pqevaLk4THfeNIQxADx+GMLf +a2H93RgcOrU5yxrK30rng4tfiwbGdRv6HkGP1WaSoZa/yOG+HldPDGbLFG4P3qCWatK pek6XSWmaDLxuTQB8YlqFWzthMzD5aqr6Q+/Hu3ZCojbZX1D8wiUdIDvELFayi9zjIjG Rf8FrE23tVeiuaZbtzMcFPeztU1kmPiqLfmGDzlMqq7eYM8MpuP7E1uG45JAh/VAq0je FYlw== 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 e3-v6si1969549pgc.85.2018.08.17.05.11.16; Fri, 17 Aug 2018 05:11:31 -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 S1727026AbeHQPM6 (ORCPT + 99 others); Fri, 17 Aug 2018 11:12:58 -0400 Received: from mail105.syd.optusnet.com.au ([211.29.132.249]:43451 "EHLO mail105.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbeHQPM6 (ORCPT ); Fri, 17 Aug 2018 11:12:58 -0400 Received: from smtp.starsoftware.com.au (n175-33-133-183.meb2.vic.optusnet.com.au [175.33.133.183]) by mail105.syd.optusnet.com.au (Postfix) with ESMTP id 72FFA104D72D for ; Fri, 17 Aug 2018 22:09:44 +1000 (AEST) Received: from virtux64.softrans.com.au (unknown [192.168.0.6]) by smtp.starsoftware.com.au (Postfix) with ESMTP id 3600F677E164; Fri, 17 Aug 2018 22:09:44 +1000 (AEST) Received: by virtux64.softrans.com.au (Postfix, from userid 1000) id 2A36A18E01A1; Fri, 17 Aug 2018 22:09:44 +1000 (AEST) From: Matt Rickard Subject: [RESEND PATCH] x86/vdso: Handle clock_gettime(CLOCK_TAI) in vDSO To: Matt Rickard CC: LKML Message-Id: <20180817120944.2A36A18E01A1@virtux64.softrans.com.au> Date: Fri, 17 Aug 2018 22:09:44 +1000 (AEST) X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.2 cv=FNpr/6gs c=1 sm=1 tr=0 a=0SUgGFgJIhXJJGNlngNSLg==:117 a=0SUgGFgJIhXJJGNlngNSLg==:17 a=dapMudl6Dx4A:10 a=PIVNZ80yAAAA:8 a=qvPKsAL-236YqDqrpyAA:9 a=3YJQTRF3V1zcZZCg0gjL:22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Process clock_gettime(CLOCK_TAI) in vDSO. This makes the call about as fast as CLOCK_REALTIME instead of taking about four times as long. Signed-off-by: Matt Rickard --- arch/x86/entry/vdso/vclock_gettime.c | 25 +++++++++++++++++++++++++ arch/x86/entry/vsyscall/vsyscall_gtod.c | 2 ++ arch/x86/include/asm/vgtod.h | 1 + 3 files changed, 28 insertions(+) diff --git a/arch/x86/entry/vdso/vclock_gettime.c b/arch/x86/entry/vdso/vclock_gettime.c index f19856d95c60..91ed1bb2a3bb 100644 --- a/arch/x86/entry/vdso/vclock_gettime.c +++ b/arch/x86/entry/vdso/vclock_gettime.c @@ -246,6 +246,27 @@ notrace static int __always_inline do_monotonic(struct timespec *ts) return mode; } +notrace static int __always_inline do_tai(struct timespec *ts) +{ + unsigned long seq; + u64 ns; + int mode; + + do { + seq = gtod_read_begin(gtod); + mode = gtod->vclock_mode; + ts->tv_sec = gtod->tai_time_sec; + ns = gtod->wall_time_snsec; + ns += vgetsns(&mode); + ns >>= gtod->shift; + } while (unlikely(gtod_read_retry(gtod, seq))); + + ts->tv_sec += __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); + ts->tv_nsec = ns; + + return mode; +} + notrace static void do_realtime_coarse(struct timespec *ts) { unsigned long seq; @@ -277,6 +298,10 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) if (do_monotonic(ts) == VCLOCK_NONE) goto fallback; break; + case CLOCK_TAI: + if (do_tai(ts) == VCLOCK_NONE) + goto fallback; + break; case CLOCK_REALTIME_COARSE: do_realtime_coarse(ts); break; diff --git a/arch/x86/entry/vsyscall/vsyscall_gtod.c b/arch/x86/entry/vsyscall/vsyscall_gtod.c index e1216dd95c04..d61392fe17f6 100644 --- a/arch/x86/entry/vsyscall/vsyscall_gtod.c +++ b/arch/x86/entry/vsyscall/vsyscall_gtod.c @@ -53,6 +53,8 @@ void update_vsyscall(struct timekeeper *tk) vdata->monotonic_time_snsec = tk->tkr_mono.xtime_nsec + ((u64)tk->wall_to_monotonic.tv_nsec << tk->tkr_mono.shift); + vdata->tai_time_sec = tk->xtime_sec + + tk->tai_offset; while (vdata->monotonic_time_snsec >= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) { vdata->monotonic_time_snsec -= diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h index fb856c9f0449..adc9f7b20b9c 100644 --- a/arch/x86/include/asm/vgtod.h +++ b/arch/x86/include/asm/vgtod.h @@ -32,6 +32,7 @@ struct vsyscall_gtod_data { gtod_long_t wall_time_coarse_nsec; gtod_long_t monotonic_time_coarse_sec; gtod_long_t monotonic_time_coarse_nsec; + gtod_long_t tai_time_sec; int tz_minuteswest; int tz_dsttime;