Received: by 10.213.65.68 with SMTP id h4csp748467imn; Tue, 13 Mar 2018 21:23:24 -0700 (PDT) X-Google-Smtp-Source: AG47ELuZWYkBTPASXvQuW/NlYKtTIN2IQTPBVhCCYaV+ZANpWjasIitGcdphNPba+cueYGNGqnzf X-Received: by 10.99.107.6 with SMTP id g6mr2526690pgc.109.1521001404444; Tue, 13 Mar 2018 21:23:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521001404; cv=none; d=google.com; s=arc-20160816; b=HUlY/bqpspTjTXZl2xIWD7pvoTutoPEXURG2uug+ejbWkZuM/Go+GGTidJkK2s0v49 xFqDphCsgWBBX47xThOAahGr8iPxaa/minjzi/Jk4HEmFc14vbISZHY/WnEhWllVqEWK AI1NctzZ8ziqwsdIbKj6EDRDG7Nfzssyl9zzp+mAN0Jr7+sjLJ3suBIXPizGshqR+GPI lpx8JIx559bXs9cY6/ZSIuqms852LOgYsXhKyHE5eVuS5htK9LHA2AzBqiXTkzmOZSlB ne7VIMCYiR/RhnRu05fh4/Jivslx7B0Z28CFwe5OH1Ps79j3sOWTpOTbyINcZfbI+XE5 CBVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=aL+hMe9LCNxitIv7RwP1q8c7B/hPIsUx9bExDzsqugw=; b=crhAUuhyOpk5XFXXQP3OBudTQ0NFCewEOvIop6/sRxlHfNunb8Wod/z8VzMn/V0ADU zi1tlMoWhZiY8V7OejX8j2ufPmSd60fHIX95ISU9tndVu64ZfU8nLsJ3NdQZvG2SQvkA 5wLEIjKctIlv+v+/9ezVWVuv8xctgv3OxmqdYUlMQ2Pf+ejHPUcpfIhRlOZ8HUsQA0co r0teMhfvwIf9AfKskA/g5UeHPrqfflKwpCtzA1hikD+uCLcFETVR3mDwqDlxRWXYzC+N oyT3HHcVrjgcv8Wrs6PQ1Go+My9+lbyTgrpHTQKWet3xAbFdoQe0U0g9rK0gV2vQbbbN UkWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SFsYwk+v; 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 s3si1386130pfi.32.2018.03.13.21.23.10; Tue, 13 Mar 2018 21:23:24 -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=SFsYwk+v; 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 S1751413AbeCNEUf (ORCPT + 99 others); Wed, 14 Mar 2018 00:20:35 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:54124 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750852AbeCNEUe (ORCPT ); Wed, 14 Mar 2018 00:20:34 -0400 Received: by mail-wm0-f66.google.com with SMTP id e194so1379288wmd.3 for ; Tue, 13 Mar 2018 21:20:33 -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; bh=aL+hMe9LCNxitIv7RwP1q8c7B/hPIsUx9bExDzsqugw=; b=SFsYwk+vFmnch7qJ6X4YZwxdGmaVBX/t1pkCunpKHU97mTNkaMeaFRyUxEldQWmFum OVjlnkPwFPYL7ZLHzGXh4FZqG0ndxc8PmxiaAaJB2NoC7G1SVnNbPgHhedjNkh+MsowX CheNz3YBBgbn1WZEZ8If5G/JdYA9xQZCh5tEHT3LdBOYaOGUC9S9cpnzLlQj0x6FzSsU nzImIvJBtEF0wvHJo/ssq6SO1F+RYWHLZtxKZklyT4qWlL2sb+/9djSzT9ybSzyi6Rz7 dC2f87qaT83ahqAMy9jkK3QOQD1LcU92zsqyTiWbkiS6CEk8O1hIKAHIzwZ/zlseJs0W +6fQ== 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; bh=aL+hMe9LCNxitIv7RwP1q8c7B/hPIsUx9bExDzsqugw=; b=aBtzF0IO7wsTJSbr3LnVLqOwJwqKFzB4tt6Mq4xBkCvn68msXSXZtBzLIK8YzeqbAR /RQ5tefsd/1pBmH9W/iTFZOvRZHvV4oJJinQXMHP+8oKg+55JQstvoJs8nWRKGC/HQUO pwTT8ebKI3uHCZjHVtPVMa6iiGLvNeP+9+5D1O/LHPAEgL8DAvJz8ZKGBX+CvBroYxxh bioF5ZdZjbu9qWbOaVVxugk1rjpUAON2YAHemdp/kAgbMueXX8KhN9UNIK7sBb68AnO3 xB/rKWaE9xogQmUa/vicPVnaAsb0wT/sMOTgcroMYwCMknwLcDRdAbZjHK5/h4bkzdxo DYoA== X-Gm-Message-State: AElRT7EVgL2Xa0LVHrb2hfH7wZ1qizBXStTfy8EdJZvJcZqGVZvsLVN6 HS/0V0OkV+/23GYbDczexeTZR4/R X-Received: by 10.80.222.207 with SMTP id d15mr3059043edl.76.1521001232502; Tue, 13 Mar 2018 21:20:32 -0700 (PDT) Received: from localhost.localdomain ([109.125.16.62]) by smtp.gmail.com with ESMTPSA id b10sm1335818edk.32.2018.03.13.21.20.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Mar 2018 21:20:31 -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 (3)] x86/vdso: on Intel, VDSO should handle CLOCK_MONOTONIC_RAW Date: Wed, 14 Mar 2018 04:20:19 +0000 Message-Id: <1521001222-10712-1-git-send-email-jason.vas.dias@gmail.com> X-Mailer: git-send-email 2.8.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the VDSO does not handle clock_gettime( CLOCK_MONOTONIC_RAW, &ts ) on Intel / AMD - it calls vdso_fallback_gettime() for this clock, which issues a syscall, having an unacceptably high latency (minimum measurable time or time between measurements) of 300-700ns on 2 2.8-3.9ghz Haswell x86_64 Family'_'Model : 06_3C machines under various versions of Linux. Sometimes, particularly when correlating elapsed time to performance counter values, user-space code needs to know elapsed time from the perspective of the CPU no matter how "hot" / fast or "cold" / slow it might be running wrt NTP / PTP "real" time; when code needs this, the latencies associated with a syscall are often unacceptably high. I reported this as Bug #198161 : 'https://bugzilla.kernel.org/show_bug.cgi?id=198961' and in previous posts with subjects matching 'CLOCK_MONOTONIC_RAW' . This patch handles CLOCK_MONOTONIC_RAW clock_gettime() in the VDSO , by exporting the raw clock calibration, last cycles, last xtime_nsec, and last raw_sec value in the vsyscall_gtod_data during vsyscall_update() . Now the new do_monotonic_raw() function in the vDSO has a latency of @ 24ns on average, and the test program: tools/testing/selftest/timers/inconsistency-check.c succeeds with arguments: '-c 4 -t 120' or any arbitrary -t value. The patch is against Linus' latest 4.16-rc5 tree, current HEAD of : git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git . This patch affects only files: arch/x86/include/asm/vgtod.h arch/x86/entry/vdso/vclock_gettime.c arch/x86/entry/vdso/vdso.lds.S arch/x86/entry/vdso/vdsox32.lds.S arch/x86/entry/vdso/vdso32/vdso32.lds.S arch/x86/entry/vsyscall/vsyscall_gtod.c There are 3 patches in the series : Patch #1 makes the VDSO handle clock_gettime(CLOCK_MONOTONIC_RAW) with rdtsc_ordered() Patch #2 makes the VDSO handle clock_gettime(CLOCK_MONOTONIC_RAW) with a new rdtscp() function in msr.h Patch #3 makes the VDSO export TSC calibration data via a new function in the vDSO: unsigned int __vdso_linux_tsc_calibration ( struct linux_tsc_calibration *tsc_cal ) that user code can optionally call. Patches #2 & #3 should be considered "optional" . Patch #2 makes clock_gettime(CLOCK_MONOTONIC_RAW) calls have @ half the latency of clock_gettime(CLOCK_MONOTONIC) calls. I think something like Patch #3 is necessary to export TSC calibration data to user-space TSC readers. Best Regards, Jason Vas Dias