Received: by 10.213.65.68 with SMTP id h4csp46946imn; Thu, 15 Mar 2018 09:07:28 -0700 (PDT) X-Google-Smtp-Source: AG47ELvy7BSJouTzk0KW5j7h4vqA14xRQ4TzGS9a1cHMR0M3SQcJsc3+hrwyehZgejNo99nrbOzD X-Received: by 10.98.59.208 with SMTP id w77mr5227978pfj.59.1521130048531; Thu, 15 Mar 2018 09:07:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521130048; cv=none; d=google.com; s=arc-20160816; b=1DIMqAm14yAzVUtnRQPpe7OuR9AHqN63Je00glUV1OCOkM3DHBPnSnVtU+nHOng0qz yftNqM4aIQlk4MjxAH2gSdHtJDftgfOkkmQzb6HFhUP/u+EvXVE/IHSv9MyNRbLxQJZQ 11zbN1EqHQbpaJxBnFtzAaGTpv6bjmY346QN2/TKeN7yMyJXE9uFAvQeE30cqgtLbTQY zmnCyywTILyQtSqSKwMsTS73khZ7F9HkuWmMLlFduG+coyntBwPxcDDy1JGyIoNtNSsi XJLlzWuoAhoEu0SQND8b8AF8T85A8zbJTDMVTwHe3TsA5kGi3VfSsXeqic6Fw+f0H5pC D5vQ== 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:dkim-signature:arc-authentication-results; bh=vDlc6v880lr2VJDM68UXHXvY6Hhr1dpgYCvHOfj7+wI=; b=G8lcJUL3Grp+BuRtx5hTCJ9rm7Ps2EgAgvBn7SsJBdPxA2ckzc9ew+M5PMRnGwxFdF ihH0/iI8/h9x9meuJYHhGYlg8X0qS4Y77N5X5aHPfC27ZrKu/gwnuFIxVyeUdYqq2bOL EtJmUrm8FPB0AlwU6wpe5kH0O5LP9Y1zGg+55BhXR3XbITa515/ewdmFHisulLmckhOb eHdrrfeM0R2nWKMrJJv8htefdZFI0WNkzlT2ArAWFo+THk2uWfdFwSmTD6VcQwp5CPXp Gjo7iTxpL0favZf60HqE3oFPmVhRJtnCGvxOrrOrduLjlFhSj36AevN1BK1W2OZ3iSkC Bjpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TOeUVPSs; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f33-v6si4233637plb.482.2018.03.15.09.07.13; Thu, 15 Mar 2018 09:07: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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TOeUVPSs; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932962AbeCOQBH (ORCPT + 99 others); Thu, 15 Mar 2018 12:01:07 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33842 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932922AbeCOQBB (ORCPT ); Thu, 15 Mar 2018 12:01:01 -0400 Received: by mail-wm0-f66.google.com with SMTP id a20so23766045wmd.1 for ; Thu, 15 Mar 2018 09:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vDlc6v880lr2VJDM68UXHXvY6Hhr1dpgYCvHOfj7+wI=; b=TOeUVPSs2yGtOFkpKFOVRwPidvpAJw5PrSo2Dv6xc+dXWD2h2CAAMBq/Z18CpcEplJ vE4VpzCZlp5dfvroRl/Z5FzqwKDMNW1kz6cvfBJRfOlFYoLrybtF4RxMOdo2ZhSRx08Z 26Dp+85MLyqgcohFEhPlihUAgJYehUmi1gDZX01/A+a3Hl/1lOucWAGUKWucUR4ttAwN qWZ20zEH6fp9vDRFlCADPsbBdGtXLng477F7KowzePgQ+dlwglXiFzNGocy3/yINHyBB phHdzOWeF9S0qSdOIwZ20iLMruye2LVXaRgS4xjkhanq4Sj7tfKpFx+Dg66b0GAHtOmo 2fzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vDlc6v880lr2VJDM68UXHXvY6Hhr1dpgYCvHOfj7+wI=; b=obvSpyi3XPzt84cruXYF7f6vzRzoRUumw7qpb8O9APPjrI/Z0VxxOM/DKrgQQhZuVc lsR9ikKOk+9ovW62WtfqSDSwej0y90rS6V156XefiksSZedlHQeRkzzfJmwNp1nKj8ax tzCmvJWkwnEhIFg0E+PLekMVD7I9yVlxkGOXc8RI5aumeLAjx5rk6cWOVgHBOt0jBZHy Tc/ds+bLZvDcN/LmhnojL/5xmB6sFEBhgFe5Q+yeSHf2xYDyJTVJtbXe1+5DKiK0E/Op SFGAvAnAsESAouQYsuOzepRvwguEnojioCw/ZF6ZFipGWC+xDq1kbDpVT+aGbH1fRjG0 /TGA== X-Gm-Message-State: AElRT7E9WN6gMJrTeMY5r08LMYuoa6dkM8+tz7V8U2x1hS7reRPgUOtp Vj4YMFfhzgPuGnVUw2ysU81baCoU X-Received: by 10.80.232.1 with SMTP id e1mr9579514edn.257.1521129659146; Thu, 15 Mar 2018 09:00:59 -0700 (PDT) Received: from localhost.localdomain ([83.147.149.202]) by smtp.gmail.com with ESMTPSA id z7sm2508306edb.46.2018.03.15.09.00.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Mar 2018 09:00:58 -0700 (PDT) From: jason.vas.dias@gmail.com To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, tglx@linutronix.de, mingo@kernel.org, peterz@infradead.org, andi@firstfloor.org Subject: [PATCH v4.16-rc5 1/3] x86/vdso: on Intel, VDSO should handle CLOCK_MONOTONIC_RAW Date: Thu, 15 Mar 2018 16:00:46 +0000 Message-Id: <1521129648-20889-2-git-send-email-jason.vas.dias@gmail.com> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1521129648-20889-1-git-send-email-jason.vas.dias@gmail.com> References: <1521129648-20889-1-git-send-email-jason.vas.dias@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org diff --git a/arch/x86/entry/vdso/vclock_gettime.c b/arch/x86/entry/vdso/vclock_gettime.c index f19856d..fbc7371 100644 --- a/arch/x86/entry/vdso/vclock_gettime.c +++ b/arch/x86/entry/vdso/vclock_gettime.c @@ -182,6 +182,18 @@ notrace static u64 vread_tsc(void) return last; } +notrace static u64 vread_tsc_raw(void) +{ + u64 tsc + , last = gtod->raw_cycle_last; + + tsc = rdtsc_ordered(); + if (likely(tsc >= last)) + return tsc; + asm volatile (""); + return last; +} + notrace static inline u64 vgetsns(int *mode) { u64 v; @@ -203,6 +215,27 @@ notrace static inline u64 vgetsns(int *mode) return v * gtod->mult; } +notrace static inline u64 vgetsns_raw(int *mode) +{ + u64 v; + cycles_t cycles; + + if (gtod->vclock_mode == VCLOCK_TSC) + cycles = vread_tsc_raw(); +#ifdef CONFIG_PARAVIRT_CLOCK + else if (gtod->vclock_mode == VCLOCK_PVCLOCK) + cycles = vread_pvclock(mode); +#endif +#ifdef CONFIG_HYPERV_TSCPAGE + else if (gtod->vclock_mode == VCLOCK_HVCLOCK) + cycles = vread_hvclock(mode); +#endif + else + return 0; + v = (cycles - gtod->raw_cycle_last) & gtod->raw_mask; + return v * gtod->raw_mult; +} + /* Code size doesn't matter (vdso is 4k anyway) and this is faster. */ notrace static int __always_inline do_realtime(struct timespec *ts) { @@ -246,6 +279,27 @@ notrace static int __always_inline do_monotonic(struct timespec *ts) return mode; } +notrace static __always_inline int do_monotonic_raw(struct timespec *ts) +{ + unsigned long seq; + u64 ns; + int mode; + + do { + seq = gtod_read_begin(gtod); + mode = gtod->vclock_mode; + ts->tv_sec = gtod->monotonic_time_raw_sec; + ns = gtod->monotonic_time_raw_nsec; + ns += vgetsns_raw(&mode); + ns >>= gtod->raw_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 +331,10 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) if (do_monotonic(ts) == VCLOCK_NONE) goto fallback; break; + case CLOCK_MONOTONIC_RAW: + if (do_monotonic_raw(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 e1216dd..5af7093 100644 --- a/arch/x86/entry/vsyscall/vsyscall_gtod.c +++ b/arch/x86/entry/vsyscall/vsyscall_gtod.c @@ -45,6 +45,11 @@ void update_vsyscall(struct timekeeper *tk) vdata->mult = tk->tkr_mono.mult; vdata->shift = tk->tkr_mono.shift; + vdata->raw_cycle_last = tk->tkr_raw.cycle_last; + vdata->raw_mask = tk->tkr_raw.mask; + vdata->raw_mult = tk->tkr_raw.mult; + vdata->raw_shift = tk->tkr_raw.shift; + vdata->wall_time_sec = tk->xtime_sec; vdata->wall_time_snsec = tk->tkr_mono.xtime_nsec; @@ -74,5 +79,8 @@ void update_vsyscall(struct timekeeper *tk) vdata->monotonic_time_coarse_sec++; } + vdata->monotonic_time_raw_sec = tk->raw_sec; + vdata->monotonic_time_raw_nsec = tk->tkr_raw.xtime_nsec; + gtod_write_end(vdata); } diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h index fb856c9..24e4d45 100644 --- a/arch/x86/include/asm/vgtod.h +++ b/arch/x86/include/asm/vgtod.h @@ -22,6 +22,10 @@ struct vsyscall_gtod_data { u64 mask; u32 mult; u32 shift; + u64 raw_cycle_last; + u64 raw_mask; + u32 raw_mult; + u32 raw_shift; /* open coded 'struct timespec' */ u64 wall_time_snsec; @@ -32,6 +36,8 @@ 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 monotonic_time_raw_sec; + gtod_long_t monotonic_time_raw_nsec; int tz_minuteswest; int tz_dsttime;