Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp870609lqt; Fri, 19 Apr 2024 13:01:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXkVQ7J67fzFcACYhUwtIL/chw0EeLHhRlKGRy8QCqHcoyw17vBwnC8jujGXjeM7EP63j3bg9v5Tout+PcI+IsI1WxtjY7cl/fZVK311A== X-Google-Smtp-Source: AGHT+IGm9PmtBgwm5/q8vAn8I9duUPjC+WHhbGfZn596U6hncl3pm3Q0G1AfDiO3cG+GxP60tHal X-Received: by 2002:a50:ab51:0:b0:56d:ee61:6874 with SMTP id t17-20020a50ab51000000b0056dee616874mr2276060edc.20.1713556899683; Fri, 19 Apr 2024 13:01:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713556899; cv=pass; d=google.com; s=arc-20160816; b=w52+PH/z4ZShffBJD8A5RVUoAIJwe7iAcA8KWdLWD84mNjL9MkjCaIoPpl/5Ve1/MK RYEvuMSs32EnO33pQdFDer0/JnpffM2MaBYq9I5Le9LHe4kiQT1vfSYRm3dNYfSSJj4x IlCS8+XJTp0VH7iVz62VmXTc+bg5EscXUdAo9ehLP6IXS8th9ZYtzQk2vsa7Kmf5bdhQ R7FYHI4Xj7jsASi6qAVz2WEdchckuRw4SJyBzFcoMptlV8Yfma2u5BsoMG/mcMChSTjl jjdMUfSn/XN1oB4hTcGLmP7ZYDEIB69AEgCni7as9ay9RFmZePPR+RSaMsqU+ro1RbpB vK6A== 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=TRulkkAOvsGRfjsQewped+Ly0aSe8u9aY8qD+MMGqPI=; fh=J5pW6WJHWec2ONVwStzzB82ingpCTyWaBAcdYhTTvQE=; b=V1urCxdqFa8sPVZdCcnTCz4Dd8nRE9DbmlH51ZkLYkthLKzmsGG/iauwF5KRVaGk7H hmEMMVN2ufr1MX8qGh5lXHm5hMni7JM93zZsOCXYkw1mfbsdb1oPLUJDfvKI09qpbpCI IEwj2ezT/dq/uebmQAwj9KJoT9p98P15Q4xeQ5rihZq3zneN5nfa/CGmceNgjzk2iy+i kPt+ElnIjR2e7UV9CfGuMaiqfzzfGnMYJ6gZ2OUT57hblg3rfupkOwyq5uW2Hl7ricR5 bDIfE8ge2G++/nvRf67ngSEYx/OveqdgXGh6DcEJ4noKa1S3KEt1v01sBfXLtcFZbm0a tavQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=CNTgdd1M; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-151880-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151880-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 df21-20020a05640230b500b00570102e80edsi2448141edb.40.2024.04.19.13.01.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 13:01:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151880-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=CNTgdd1M; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-151880-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151880-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 ABBC51F22931 for ; Fri, 19 Apr 2024 18:45:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65790130AC9; Fri, 19 Apr 2024 18:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="CNTgdd1M" 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 BBD50225CF; Fri, 19 Apr 2024 18:45:40 +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=1713552345; cv=none; b=Bqk3fd+PQkfb900tSbCjDE5TdLkkj083tqHd/5e61p1ypxi/tkFoDJxv7E282GcoPozT7VKiKto+3SrktjQCkAHs5od4qHxver/7VTQGkbTGE4yQHestBKDaC1HDSmXGDJDh1ret6sXgZ4Es8QiuWJK0xqjNnuo2a0TrQnPp7m4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713552345; c=relaxed/simple; bh=TRulkkAOvsGRfjsQewped+Ly0aSe8u9aY8qD+MMGqPI=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=reNkSt69FBGMWu1R0xiTajG18SwZp+SLm7uCnNeV93msOXgx3qe/Nm7IRTo/xy0L+4usZlO3LMaiymgtmlWu6GBZscV92XJKpoAdDTyMBR1WEToM3Ul3Jo1i+lAylHUxoxBlyLfPLCRJbcrFmxux8f2Zcd98oUbzWLgtRGWmOIA= 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=CNTgdd1M; 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=TRulkkAOvsGRfjsQewped+Ly0aSe8u9aY8qD+MMGqPI=; b=CNTgdd1MuSz3QNZBgNyK++zRA8 IJCzl9muTPkk0MydVImRTa0dpivKn7Dbi1kcYJH3iJzoWJZBE0lG6owXlMrn99Ek6WSIT8Vhuxiwn 8n3toDSKggCO04GXUpRkuvZRnoKujay3W9tIqazCJTtqsiwCrYwUdEPQW8XRCDw5TTrDYD2cjfhXf QLHOpGNeKBvSxoEK/VM7RHlNPAs2wkvlCCrO6pGiG8fRHUlNcT58B08uI5I6xvr52LVhiJ0ychxPy 9kBjqE02y5l4F6PhemUgLGn2HgJWe8BmPp21xtRCiekrbuCg2mGo8DV8OB/s/ZdQMZjYS5Yqu9VVy 4AMVwlag==; Received: from [154.49.97.68] (helo=[127.0.0.1]) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxtEg-00000008IaG-2MiK; Fri, 19 Apr 2024 18:45:23 +0000 Date: Fri, 19 Apr 2024 19:43:43 +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: <17F1A2E9-6BAD-40E7-ACDD-B110CFC124B3@infradead.org> References: <20240408220705.7637-1-jalliste@amazon.com> <20240408220705.7637-3-jalliste@amazon.com> <3664e8ec-1fa1-48c0-a80d-546b7f6cd671@intel.com> <17F1A2E9-6BAD-40E7-ACDD-B110CFC124B3@infradead.org> Message-ID: <65FF4D51-05A8-42E0-9D07-6E42913CC75E@infradead.org> 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 19:40:06 BST, David Woodhouse wrot= e: >On 19 April 2024 18:13:16 BST, "Chen, Zide" wro= te: >>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 freque= ncy, >>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 g= uest TSC T and some reference point in time R, the KVM clock is expressed a= s 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 o= f 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 sa= me 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+= new pvclock structs, so I can understand where the logic goes wrong=2E > >Were you using frequency scaling? > Oh, also please could you test the updated version I posted yesterday, fro= m https://git=2Einfradead=2Eorg/?p=3Dusers/dwmw2/linux=2Egit;a=3Dshortlog;h= =3Drefs/heads/clocks