Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3503036imm; Fri, 19 Oct 2018 11:41:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV61C+bFYoJ1UsYWkNz9jT8Me03fkLbYrbtSyEYrmZ7z3g2A/h/24DWkNgn4OfBye/wrTqg9O X-Received: by 2002:a63:9dca:: with SMTP id i193-v6mr2063073pgd.98.1539974463843; Fri, 19 Oct 2018 11:41:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539974463; cv=none; d=google.com; s=arc-20160816; b=0OsiLJtXEDdXnmEcqs6RQ/n9JwliXEuZOFVieY6GYLEcEbeD8EvfIgFnlscQHQx/3N SiNldzgx82+yYSmBGt6Y6C54PrwPq+lRmHYz6OQ3u68zHF5cSD5XBRSDfpS/7OQXGh9U RnQ/MZw8TqqFNDfGGH5MtTsmeeg7rSY6iliGcE25lzB4r+/u5x+qHjbr9mtWTx+yo0pL Zcl00G+7QsfuwQTY0rimnOexnOiRzQi1b3/NzJVR+hgDlb/DtNz8scT9Vpw3CUYJWvvl 0bB3Yc84lzY3dBLsfMcsZeOq/2JKd8LfpHIHoyoZTxTmx/hygGdQQTl3Ljf5ODUew3Vz BdAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=SplUevsLp+LzH2TY51KDNrpqIc/UWNggz6hbVrJ44lE=; b=dKBCdXn/IbM2OKpYNHZaAKuEvR+8vL0Ui1ZmuDGBDxLwxlV6Myxnqes+xDrMq1Jph5 cj+LI1U2ngQQdXa7TfodiOoBDpEqoikzzkg94g8ZZ5zPAGJTrc4w9DgcDfiXgv4RyZ0o 7wvgnyrVkobuaz5TQn5RIK/zzpIGetNLDtdTDoOAncljteXzyHvx4sAouJjr50F7ZoMy HMT97GFVCTDM46sPZ1BRQYE81G5EqUgiDmzlt4dJZcodaymWKOsrPGb6ZOOfLmHo9Lgk kHaxjR0uNq4y9WkmpaYFGMM+BuvQMqHjHgAlLhVejKvn6BTxnntwTeckpLSS2bFzCz7F 6fEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q7acS+6x; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 74-v6si26568596pga.231.2018.10.19.11.40.47; Fri, 19 Oct 2018 11:41:03 -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=@linaro.org header.s=google header.b=Q7acS+6x; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727846AbeJTCqn (ORCPT + 99 others); Fri, 19 Oct 2018 22:46:43 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37676 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727329AbeJTCqm (ORCPT ); Fri, 19 Oct 2018 22:46:42 -0400 Received: by mail-wm1-f68.google.com with SMTP id 185-v6so4608636wmt.2 for ; Fri, 19 Oct 2018 11:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=SplUevsLp+LzH2TY51KDNrpqIc/UWNggz6hbVrJ44lE=; b=Q7acS+6xp5kQrDbx+EYJ1oqSjQiMn3oOc28hAVG3Hjs3jC6J6dmX9W5xMP5aS1ckdz E4Krpap5y8c2UcAjkEabgXj+5XNXxFZCsbBQZLDfrhzqas0Pyx/dT16QV12rYpURO6xv xCwCWMNwyn8+0hceEM8bgan61Ub0AupoD4Oh8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=SplUevsLp+LzH2TY51KDNrpqIc/UWNggz6hbVrJ44lE=; b=s0LsJt98i2I3VhP+uuABmOvgiga/NC64MN5XqUUznPIayqU56WJA1/lGmkR62YkuTj Nf4nXkHVWkN1XSvGn/5f3YM5GZjoIIZMNASDGkpj+qv/t0sfTugQU4O7Jwh25S02sHPJ MO46yYWHka/1oR48Mvt6WJOXekoqoPrYi7SgoDFvwKODH/ua14jFD4ScQ1E7DvoKejt8 NWaX+t7Vvw+WJERuYlzC5xK+eJDTo3pcu9qzQsr2f21Exsce7swRBuK26cEsTzAxfNu2 SxiHWJIYaPif1LnzijmrULdX3jUArtOgiILP3H3bAdzM2jX0EVPbi4XvSc8iiloJ19if i7sw== X-Gm-Message-State: ABuFfoiSMuD4mOIJB3nvuQyL4/vEaBLFZQIS73vz/UYs5FySg4lRiiO+ NBK7TD1gTZ9FrcTWZYiSvIPbOh4S+6ScsHF+ncp5oA== X-Received: by 2002:a1c:2984:: with SMTP id p126-v6mr6390766wmp.5.1539974364033; Fri, 19 Oct 2018 11:39:24 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:b485:0:0:0:0:0 with HTTP; Fri, 19 Oct 2018 11:39:23 -0700 (PDT) In-Reply-To: References: <20181015160945.5993-1-christopher.s.hall@intel.com> From: John Stultz Date: Fri, 19 Oct 2018 11:39:23 -0700 Message-ID: Subject: Re: TSC to Mono-raw Drift To: Thomas Gleixner Cc: Christopher Hall , "H. Peter Anvin" , linux-rt-users , jesus.sanchez-palencia@intel.com, gavin.hindman@intel.com, liam.r.girdwood@intel.com, Peter Zijlstra , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 19, 2018 at 11:34 AM, John Stultz wrote: > On Fri, Oct 19, 2018 at 8:25 AM, Thomas Gleixner wrote: >> Christopher, >> >> Please Cc LKML on such issues in the future. >> >> On Mon, 15 Oct 2018, Christopher Hall wrote: >> >> Leaving context around for new readers: >> >>> Problem Statement: >>> >>> The TSC clocksource mult/shift values are derived from CPUID[15H], but the >>> monotonic raw clock value is not equal to TSC in nominal nanoseconds, i.e. >>> the timekeeping code is not accurately transforming TSC ticks to nominal >>> nanoseconds based on CPUID[15H}. >>> >>> The included code calculates the drift between nominal TSC nanoseconds and >>> the monotonic raw clock. >>> >>> Background: >>> >>> Starting with 6th generation Intel CPUs, the TSC is "phase locked" to the >>> Always Running Timer (ART). The relation between TSC and ART is read from >>> CPUID[15H]. Details of the TSC-ART relation are in the "Invariant >>> Timekeeping" section of the SDM. >>> >>> CPUID[15H].ECX returns the nominal frequency of ART (or crystal frequency). >>> CPU feature TSC_KNOWN_FREQ indicates that tsc_khz (tsc.c) is derived from >>> CPUID[15H]. The calculation is in tsc.c:native_calibrate_tsc(). >>> >>> When the TSC clocksource is selected, the timekeeping code uses mult/shift >>> values to transform TSC into nanoseconds. The mult/shift value is determined >>> using tsc_khz. >>> >>> Example Output: >>> >>> Running for 3 seconds trial 1 >>> Scaled TSC delta: 3000328845 >>> Monotonic raw delta: 3000329117 >>> Ran for 3 seconds with 272 ns skew >>> >>> Running for 3 seconds trial 2 >>> Scaled TSC delta: 3000295209 >>> Monotonic raw delta: 3000295482 >>> Ran for 3 seconds with 273 ns skew >>> >>> Running for 3 seconds trial 3 >>> Scaled TSC delta: 3000262870 >>> Monotonic raw delta: 3000263142 >>> Ran for 3 seconds with 272 ns skew >>> >>> Running for 300 seconds trial 4 >>> Scaled TSC delta: 300000281725 >>> Monotonic raw delta: 300000308905 >>> Ran for 300 seconds with 27180 ns skew >>> >>> The skew between tsc and monotonic raw is about 91 PPB. >>> >>> System Information: >>> >>> CPU model string: Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz >>> Kernel version tested: 4.14.71-rt44 >>> NOTE: The skew seems to be insensitive to kernel version after >>> introduction of TSC_KNOWN_FREQ capability >>> >>> >From CPUID[15H]: >>> Time Stamp Counter/Core Crystal Clock Information (0x15): >>> TSC/clock ratio = 276/2 >>> nominal core crystal clock = 24000000 Hz (table lookup) >>> >>> TSC kHz used to calculate mult/shift value: 3312000 > > So, just to understand, your saying the problem that we calculate a > tsc_khz value before calculating the mult/shift and the intermediate > step is losing some precision? > > Or is the cause from something else? The other potential cause here might be just that when we calculate the mult/shift pair, we select a shift small enough that avoids the multiplication from overflowing if we have a long timerval. So there is liklely always some granularity error converting to mult/shift pair. thanks -john