Received: by 10.213.65.68 with SMTP id h4csp47073imn; Thu, 15 Mar 2018 09:07:43 -0700 (PDT) X-Google-Smtp-Source: AG47ELuijh1ubomez1R8OvFrLZ+b8tWfZBfLC3N+al3as2XOgGuN50noAD1gGgHdn8NntRbdbHpg X-Received: by 2002:a17:902:8349:: with SMTP id z9-v6mr8671178pln.163.1521130063184; Thu, 15 Mar 2018 09:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521130063; cv=none; d=google.com; s=arc-20160816; b=ejdh4qKp0ElPALrNBnzFds7yY2d/pWmsWqMrgXI16/DjoeMm/KW9yW0YIIYQozwJCe NzqHnYjLn+jkq7dOc9OlHa915eGNZ2UmXIq82lMceKtMpnBkHGpA2aPu04lfw2REwPgp Z+AdCCMPulH7DCbgLSnfiCi44mj5Gc5OsZqoxyc+AhUxN7c26eG7gH41tlgkxb9+F4ub sCk4zokqcZvIiYyWPii+/t6EKWjd+7qDz+G7AHrTsRPhnjLrMWahO1e7s7kfbFLAXKgi ipw6O9pyqEtgirQWg3JxF9ii7JdlZac/oTkceiIoLYDnZngfuJAiIaHVxjmuMngbg+9g fwdw== 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=7aIDzbqjqSeybdAotb7L1W99D0ftr/8gB9zAeJekSn0=; b=Qi7T0PU0wICTA7g9wGlI0ua/pRu8sckuYtf50t2FM7Y3YzcFLV2IxcRIG9ydJM+Der dv4dR8UBe8cCoBFlAjaAmstF5dA8Mr45DMT77dPZD4VaVAW6TPhj3vZ+SZMbERsOsyr0 I9lDQKL9bXzpFtOpEKMhE2KbfpD/ZSC7qvXr8nlcQ+kxL1yG3YbWUCFRSG17EeWAyIfq f0zEUKRU2icLrhel/ACikCZnTHu+N9v0UuJoZpfRT4o/9Bf03x3nMZOGogEj0jWmVPop IdocANS9CfGHtnzlZBDb6/succgs+5+lzABK086SszZGmt5WWW8CK3VZkABZPYMlUGM5 gyAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=snV9qqzj; 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 c23si939311pfe.54.2018.03.15.09.07.27; Thu, 15 Mar 2018 09:07:43 -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=snV9qqzj; 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 S932978AbeCOQFk (ORCPT + 99 others); Thu, 15 Mar 2018 12:05:40 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:50402 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932926AbeCOQBD (ORCPT ); Thu, 15 Mar 2018 12:01:03 -0400 Received: by mail-wm0-f65.google.com with SMTP id w128so11495379wmw.0 for ; Thu, 15 Mar 2018 09:01:02 -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=7aIDzbqjqSeybdAotb7L1W99D0ftr/8gB9zAeJekSn0=; b=snV9qqzjpfYs4vn6DqmEatgI3m7+jEzBPTxBPOIiRtTusQ+xQkCArDMrrr3Ed5Ubxj 7QY1+tli5gtK2t+FlRnBNX9Cx6YCWhL828kvFlWeIJNSnS8w1JDqDi8vfDe2XxtAKw5D L8P2WfomLLChoAjsXwho1mOhGnG/Wv8B8ezDHlK7TBmEEyqC3zPknhOHAbjgTcsU8eAb o6e+hJ1U08EjmWNHmCG3gmfo08lHkt73T8g1f7wY4JF+t/UFzrbKmuL+CfPwlYWTqXv1 y2MYSxuIfvT/F1Dr06+BzN87A8jEx4mgGr9+y21AEDTx9cH4B3F44Dtn2t18LFoNJ5sH 1h9w== 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=7aIDzbqjqSeybdAotb7L1W99D0ftr/8gB9zAeJekSn0=; b=r1YILFDo2lROdLLPBkgz0hI4MITNWPn6wKsqttSb8fTJkLhmUmWo8xMjM0nsYCx0lF OxnOlQAs6XCpfDDKid7Irv1/HxBCx2rJLItJLqHetf22Rqlk2g83z5CKig2mEM1yrIIo xF5XRK8gWJJjnBTC87LH7IO+RRfsaYbBt99rDQPEdpms4xlBAK2JTGYOZze2svHKm5ed 9550ouRjBVdJK4qVYPFnt/lnuCMfCCVHx2RZD2+qLiD9c0L4Ya+VVES/VLWmay9i1diJ NTeL5P0bQw7vnwMEbP7kKd8Tu6E4sN+dyYpw0wZkIKRnCx+xjqJQJbRO1n6iLYKevbkX bnFQ== X-Gm-Message-State: AElRT7HhzR1AM9N1oIUBT+SCRmmmMNmC5BqNOWfOX+221OoMssh+vyNb N4X//ToGat1Mdug8M8BcD9QbOBOL X-Received: by 10.80.218.75 with SMTP id a11mr9180418edk.74.1521129661409; Thu, 15 Mar 2018 09:01:01 -0700 (PDT) Received: from localhost.localdomain ([83.147.149.202]) by smtp.gmail.com with ESMTPSA id z7sm2508306edb.46.2018.03.15.09.00.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Mar 2018 09:01:00 -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 2/3] x86/vdso: on Intel, VDSO should handle CLOCK_MONOTONIC_RAW Date: Thu, 15 Mar 2018 16:00:47 +0000 Message-Id: <1521129648-20889-3-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 fbc7371..2c46675 100644 --- a/arch/x86/entry/vdso/vclock_gettime.c +++ b/arch/x86/entry/vdso/vclock_gettime.c @@ -184,10 +184,9 @@ notrace static u64 vread_tsc(void) notrace static u64 vread_tsc_raw(void) { - u64 tsc + u64 tsc = (gtod->has_rdtscp ? rdtscp((void *)0) : rdtsc_ordered()) , last = gtod->raw_cycle_last; - tsc = rdtsc_ordered(); if (likely(tsc >= last)) return tsc; asm volatile (""); diff --git a/arch/x86/entry/vsyscall/vsyscall_gtod.c b/arch/x86/entry/vsyscall/vsyscall_gtod.c index 5af7093..0327a95 100644 --- a/arch/x86/entry/vsyscall/vsyscall_gtod.c +++ b/arch/x86/entry/vsyscall/vsyscall_gtod.c @@ -16,6 +16,9 @@ #include #include #include +#include + +extern unsigned int tsc_khz; int vclocks_used __read_mostly; @@ -49,6 +52,7 @@ void update_vsyscall(struct timekeeper *tk) vdata->raw_mask = tk->tkr_raw.mask; vdata->raw_mult = tk->tkr_raw.mult; vdata->raw_shift = tk->tkr_raw.shift; + vdata->has_rdtscp = static_cpu_has(X86_FEATURE_RDTSCP); vdata->wall_time_sec = tk->xtime_sec; vdata->wall_time_snsec = tk->tkr_mono.xtime_nsec; diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 30df295..a5ff704 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -218,6 +218,37 @@ static __always_inline unsigned long long rdtsc_ordered(void) return rdtsc(); } +/** + * rdtscp() - read the current TSC and (optionally) CPU number, with built-in + * cancellation point replacing barrier - only available + * if static_cpu_has(X86_FEATURE_RDTSCP) . + * returns: The 64-bit Time Stamp Counter (TSC) value. + * Optionally, 'cpu_out' can be non-null, and on return it will contain + * the number (Intel CPU ID) of the CPU that the task is currently running on. + * As does EAX_EDT_RET, this uses the "open-coded asm" style to + * force the compiler + assembler to always use (eax, edx, ecx) registers, + * NOT whole (rax, rdx, rcx) on x86_64 , because only 32-bit + * variables are used - exactly the same code should be generated + * for this instruction on 32-bit as on 64-bit when this asm stanza is used. + * See: SDM , Vol #2, RDTSCP instruction. + */ +static __always_inline u64 rdtscp(u32 *cpu_out) +{ + u32 tsc_lo, tsc_hi, tsc_cpu; + + asm volatile + ("rdtscp" + : "=a" (tsc_lo) + , "=d" (tsc_hi) + , "=c" (tsc_cpu) + ); // : eax, edx, ecx used - NOT rax, rdx, rcx + if (unlikely(cpu_out != ((void *)0))) + *cpu_out = tsc_cpu; + return ((((u64)tsc_hi) << 32) | + (((u64)tsc_lo) & 0x0ffffffffULL) + ); +} + /* Deprecated, keep it for a cycle for easier merging: */ #define rdtscll(now) do { (now) = rdtsc_ordered(); } while (0) diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h index 24e4d45..e7e4804 100644 --- a/arch/x86/include/asm/vgtod.h +++ b/arch/x86/include/asm/vgtod.h @@ -26,6 +26,7 @@ struct vsyscall_gtod_data { u64 raw_mask; u32 raw_mult; u32 raw_shift; + u32 has_rdtscp; /* open coded 'struct timespec' */ u64 wall_time_snsec;