Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp975069lqt; Fri, 19 Apr 2024 17:21:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXH+DyRYvGacyKEkyJ7RGmLbwY7hMrXTb2oC64QDx9ftr3EdniWmX/GCrp0bz/2o4ORAvY2wkND5IC8gZcY752lEI5eHETY3ZYf43/u2A== X-Google-Smtp-Source: AGHT+IHhHpdbp9aQPDcFMVQEsCbaNLsAYvw2mCX5rQyJBaN9/tq9pZdIT3z8/J/V0VfU7xmVq4ov X-Received: by 2002:a17:906:591:b0:a55:201f:75a with SMTP id 17-20020a170906059100b00a55201f075amr2151354ejn.33.1713572502339; Fri, 19 Apr 2024 17:21:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713572502; cv=pass; d=google.com; s=arc-20160816; b=R8e2Hzo5PfTCvEheGzxhC6LGo07M+1cgu4lea6Gkac0Ev37BLvzMQnEwtUzUjbf7BQ uM0CwT+4eboQifUoqFIIB2ZMUHxMKuK7YOXuF40tDvchtSh6VvCOJHYfqkrKE7Wd8C6q RP/y58y8cOdM6Fl8B11jPc154vXo9hWdiYsUh9edBii6PBdjI6ldNceak5YcrzMUPvfH DHUrwGbIGzXm6AW49s/XI0cJ1sD7vX98SK8FUd2l0eaAWD7yhgE6UWeLol1SoXjM4FLH ub/D9kuPShA3ofgqPIlad8Z4Kdby5GousV3o3izYoKFl6l5KvSpZ7Sdenv327d7DXYJW U3zA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:references:in-reply-to :user-agent:subject:cc:to:from:date:dkim-signature; bh=A8n0J4h+vxWU70gw6aLE6thR3YCxol3CBu+SGEyLGxQ=; fh=J5pW6WJHWec2ONVwStzzB82ingpCTyWaBAcdYhTTvQE=; b=DftgLtUl6anv4aeJ0a8fzFP3sCYV7nnBDRPKD/roJoIO7cNBldgmYkyl44UMxG5CNW 8P3ReY2j6fW8vXHeNsvoaIZpb6FAKFmCx9jb4Sa4HIo6EfNJO4IpFFsJj5yb+KW3gNU3 IppZKFUtKDj6KnmWSAUy0a9bo+RRDObVkzJZPN9RKPgnJiUi3P/0aewL6MiDymoM8EBq NkDM9aCa8P2FVGMZyJBIG/ueafAHZpc8yRGiG78NS0qDIb8CZ+qSBYQejaI+RbfTUtcd Ggv8jARrkbio15W+Km1+F0w7vBF0BXeSOxRXtz/2rSJtoGoeJHuCFA+R8W0D0nqAQPft 0E6w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=PMit3UJV; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-151907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151907-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u14-20020a17090657ce00b00a52262d88dfsi2691977ejr.480.2024.04.19.17.21.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 17:21:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=PMit3UJV; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-151907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151907-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CFA9E1F222F8 for ; Fri, 19 Apr 2024 19:35:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C32613C9B4; Fri, 19 Apr 2024 19:34:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="PMit3UJV" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03B7F1C10; Fri, 19 Apr 2024 19:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713555290; cv=none; b=omY8UFD0Hoz3Isf10YeBRQkMbe2+59+dUTAZD/UMkSYBC9Y5FxavHRJcdcrTSGM0MmzIPXkOFA5/OXNrhEXfU1RCtpLLqta44Sa+2eLvz78gT5f3jU3tcN0oOCOLAY+ZIODjy17JiBpE16R7zXmV9DtsSFTC8SzjabD91J2R1Zc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713555290; c=relaxed/simple; bh=A8n0J4h+vxWU70gw6aLE6thR3YCxol3CBu+SGEyLGxQ=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=lTHUUXQxC3VXI8VSgsjKUoxqNJE5JmLwVZiz69z4hCYFRgm8jCCKKydtLTuIEBWpACgzG8yqjGIQrjMscVy/L9qI+zwoAUvl2AxUtuDSx5l4y9rydVB2y4EAqL+NVboiAwCJo7bih5vFdAReaXFXXNNkD45PSue+b7k+GbWXiyg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=casper.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=PMit3UJV; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=casper.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:References:In-Reply-To:Subject:CC:To:From:Date:Sender :Reply-To:Content-ID:Content-Description; bh=A8n0J4h+vxWU70gw6aLE6thR3YCxol3CBu+SGEyLGxQ=; b=PMit3UJVifZl7GZqHAeVlXqJqp XMzMboZhtuwi8PqPnR/lQeQPWZA/oG3+taObZoT1jdqPVuoZq7fSNPbEwjYj0qEzXyS16id00fG8m 3dQIdg3fm88DswLD+UOSoSAAeDjXgpiT+hwz+QhG5Jskz3fsyPr0YI9BCZZYpWcfj82i8dK6jc5wQ DLvTqnt2mbrWLbUL/XX/je8pjlOQf5MyLbN4qj/vUDtP17DfhJF3K/HnEWm+TEsVSUg2W5U3GKKBb RYmHjLFV/Jyp1Few4SZ6TZdrT9JdrUERap8+RmoYO+pyLXvy7OjluquH9B6uXDd+2Bl7TkpjNu35Y vBB3ogpw==; Received: from [2a00:23ee:1548:3009:99e7:ae19:af82:c4cc] (helo=[IPv6:::1]) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxu0J-00000008NdL-1uH7; Fri, 19 Apr 2024 19:34:35 +0000 Date: Fri, 19 Apr 2024 20:34:34 +0100 From: David Woodhouse To: "Chen, Zide" , Jack Allister , Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Shuah Khan CC: Paul Durrant , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: =?US-ASCII?Q?Re=3A_=5BPATCH_2/2=5D_KVM=3A_selftests=3A_Add_KVM/PV_c?= =?US-ASCII?Q?lock_selftest_to_prove_timer_drift_correction?= User-Agent: K-9 Mail for Android In-Reply-To: <3664e8ec-1fa1-48c0-a80d-546b7f6cd671@intel.com> References: <20240408220705.7637-1-jalliste@amazon.com> <20240408220705.7637-3-jalliste@amazon.com> <3664e8ec-1fa1-48c0-a80d-546b7f6cd671@intel.com> Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html On 19 April 2024 18:13:16 BST, "Chen, Zide" wrote= : >I'm wondering what's the underling theory that we definitely can achieve >=C2=B11ns accuracy? I tested it on a Sapphire Rapids @2100MHz TSC frequen= cy, >and I can see delta_corrected=3D2 in ~2% cases=2E Hm=2E Thanks for testing! So the KVM clock is based on the guest TSC=2E Given a delta between the gu= est TSC T and some reference point in time R, the KVM clock is expressed as= a(T-R)+r, where little r is the value of the KVM clock when the guest TSC = was R, and (a) is the rate of the guest TSC=2E When set the clock with KVM_SET_CLOCK_GUEST, we are changing the values of= R and r to a new point in time=2E Call the new ones Q and q respectively= =2E But we calculate precisely (within 1ns at least) what the KVM clock would = have been with the *old* formula, and adjust our new offset (q) so that at = our new reference TSC value Q, the formulae give exactly the same result=2E And because the *rates* are the same, they should continue to give the sam= e results, =C2=B11ns=2E Or such *was* my theory, at least=2E=20 Would be interesting to see it disproven with actual numbers for the old+n= ew pvclock structs, so I can understand where the logic goes wrong=2E Were you using frequency scaling?