Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp964648lqt; Fri, 19 Apr 2024 16:55:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU2/5vn9iv5xcwYqNsY2yZzIALxh/9eWGstjapi+/kYmbBgTAVuj3S4Ib+/cSVVDHcM1Hr8ZMsZTZlIEtJHMximWsMxp3LRv6I70wHAIA== X-Google-Smtp-Source: AGHT+IH8UQ9VgZGkyJGQ8FZfGgG0ea9Tv+ptgh4sgycAFrciypGoTtZuLDlPvuTj6gDauTbUx8JU X-Received: by 2002:a17:906:c7d4:b0:a55:86fc:9981 with SMTP id dc20-20020a170906c7d400b00a5586fc9981mr1681395ejb.44.1713570947472; Fri, 19 Apr 2024 16:55:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713570947; cv=pass; d=google.com; s=arc-20160816; b=yJJM3DihjHtLizJIudgqEaE8mXFJ4kMol/ZLN18paVmvouPHDhaWrtie2GZih2y/Ye GnnS4ilwXm1N2yXqiJ1Gz0Yvn6aUhjmxBD/e1CjX9L7mDvuSwfRwT5tWzRYmttp3os6r woZxgkpo8PJPisiICfbxEHLGeCI7EHoWNVzSXyMjPQlU3tBvVxmF8rMNUH3GBFtIBQSz CnqydEPhlaUkOkEefjVQPN9D9LNXsESNQzpdxFx/HnyDoMWXIU6YNR8QSryMiYjS/bV1 u0nnH/xyeYIjPv4GvY1DIYW/KDWAridxJzu40BsyeQ3qC2Fm8dGhPoptEG+SuhyRinFh 6Qsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=s+P26RdA6rOcuYaFW6nv18UXAK9GchvPVnuCrGnUlMo=; fh=LlTjwD/rya8ZPEYiA0iK2jGF3J5JP425njBvMSvjwQI=; b=JtDTpWSLADFltjoyF2eiXHHbAYJhr0tD+O0nFqiFshyqymHdZTvdltXxIytn5R5z3g Ilve1Nqk9DgY7/9kYSmw/UG6mq3ta4piww52aj1wVc8fXZhi2mg2PPl751SA21S2wYPc vb1OORYY5HR8JuRDoR24k9obeHtEYT5BnrHpiWOgKbMZflbjlMfZF8mDCOauhaJhOdUw jWu2GPe8jN7dRi0CdsD5wkBFsLHBsIgVFiTXH4rO+VWPUZGDXRY5lo1OQeyCaG5MF8Rt MUt6xuYe5vUs+4eanpTLkocEP5CISIyqdrH86elmVRa9FaXS31H2gr9biwV4Xx5r04uF eUyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GIIIQnKG; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-152048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152048-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dv15-20020a170906b80f00b00a55941110f4si401682ejb.895.2024.04.19.16.55.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 16:55:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152048-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=@intel.com header.s=Intel header.b=GIIIQnKG; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-152048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152048-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 32AE01F222C8 for ; Fri, 19 Apr 2024 23:55:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65AC313E40A; Fri, 19 Apr 2024 23:53:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GIIIQnKG" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 DD47813D88F; Fri, 19 Apr 2024 23:53:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713570815; cv=none; b=Yn71VvVt2pAKcO81EAtPSocnDCVS49OoIG1G/JvhNfYVK5+9Glrmg4dyJ/AYcKAeUzJKXlFhwMZ1NdqV/7D3A8nyFIFjNgnO2QIklbJ7beLv4eOk1k1Xzcw13QXR2YCo4I9jjVusA8mh8xcWiOibM62nU9wfRK5aqceU3CcKiko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713570815; c=relaxed/simple; bh=3gbkhIO45mQhzKLsuGyPxbw/ZYuLJPO+82sN/qnNP8Y=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bd7hBdbwo/UokWgIKe1k2F8loeu6HDwwkMV4cvNbQ4oC1Qk4CM61K2dWva9nWe+6WLIuMRH3MKCUgQxNCCRbX8+ThIMCuqmyTKzxj7UM7G7E1HIgD7FmsL4XZEfmjz/ApLNP/Y0gKclsEcv49KaFNk/RWDR23wvjdxKQpanWYmc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=GIIIQnKG; arc=none smtp.client-ip=192.198.163.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713570814; x=1745106814; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=3gbkhIO45mQhzKLsuGyPxbw/ZYuLJPO+82sN/qnNP8Y=; b=GIIIQnKGbPDTOtSB+drjpBgnkEmAFUZFdBGwMfQpUkSNpBA/OlQOV/Bj NaBXbVhJJIvUPSCfmbWA5VfcXh2r1y2EFewZedDMQyUH8dGTzE+sMVopU vNYynFAZX6VvIBGjss1LL/QrnA6tcEiozTHc6vn0nYPBqiYz7xGGR3ewY KggamjN3X+3/wl6b4yXNcGSWENMErqCq+TMDfsw4AqF5L80jGGYG80wD1 hIzd7jZK2emW2g+t9uJZfSoN7KGCSQdETAxOtf43k7359wQdiWsab2XWV YYK+1TNThbsCS4eqTWQ6wqooKFvkAVDCcVT+PwP+ijFA+VV8FERfjafY6 g==; X-CSE-ConnectionGUID: +z7XL0cMT9+5Kzy26LgolQ== X-CSE-MsgGUID: 5X0FIlt9S1q1WE1BgtzIFg== X-IronPort-AV: E=McAfee;i="6600,9927,11049"; a="9051093" X-IronPort-AV: E=Sophos;i="6.07,215,1708416000"; d="scan'208";a="9051093" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2024 16:53:33 -0700 X-CSE-ConnectionGUID: 9EGboRl0SPWKp4IZ7WJR4A== X-CSE-MsgGUID: jATii7gCRUWuBg06ojTolg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,215,1708416000"; d="scan'208";a="23504137" Received: from soc-cp83kr3.jf.intel.com (HELO [10.24.10.31]) ([10.24.10.31]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2024 16:53:34 -0700 Message-ID: <2e908322-faa0-4db7-bc14-f87a9d71f577@intel.com> Date: Fri, 19 Apr 2024 16:53:32 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] KVM: selftests: Add KVM/PV clock selftest to prove timer drift correction To: David Woodhouse , 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 References: <20240408220705.7637-1-jalliste@amazon.com> <20240408220705.7637-3-jalliste@amazon.com> <3664e8ec-1fa1-48c0-a80d-546b7f6cd671@intel.com> Content-Language: en-US From: "Chen, Zide" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 4/19/2024 12:34 PM, David Woodhouse wrote: > On 19 April 2024 18:13:16 BST, "Chen, Zide" wrote: >> I'm wondering what's the underling theory that we definitely can achieve >> ±1ns accuracy? I tested it on a Sapphire Rapids @2100MHz TSC frequency, >> and I can see delta_corrected=2 in ~2% cases. > > Hm. Thanks for testing! > > So the KVM clock is based on the guest TSC. Given a delta between the guest 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. > > When set the clock with KVM_SET_CLOCK_GUEST, we are changing the values of R and r to a new point in time. Call the new ones Q and q respectively. > > 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. > > And because the *rates* are the same, they should continue to give the same results, ±1ns. > > Or such *was* my theory, at least. Thanks for the explanation. > > 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. > > Were you using frequency scaling? I can see similar ~2% failure ratio w/ or w/o commenting out configure_scaled_tsc().