[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] x86/time: improve TSC / CPU freq calibration accuracy


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Wed, 12 Jan 2022 11:53:06 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5l9J2lg5o7tkoD47AqwNEXWwXLyR2HjIq7FsqYHIWlI=; b=JU4PxXqEYYD47ht7St/+jCHdPKXpw+FELRmDbvyCtyzwPjTKVAJzNx2cWfi/YdiIpLI4gV+gtsR+U97iBQ6Gak4G2G+MokV/6MkYcW1h6aEkjnrM9G8DmFBGGyW+WDaiLaJF8n64Al0KcKKyKiMsmfnrEoAMwkheLVSW6eeTLONgqvpNE321C6w7XCtRKXoOk8DSPbqBL3og5vsVrmBcvj7jFcnr6N9b3lRCehgHG0aZBBMJrYGN64/CWbBMI6Mw2FkpIw2Mlhy7rIV3XnyJ2tnmcG+N/3b4kccy1yQ1BIDUvzMim4ZMITE3xgr7Y8dCndot9n0dSDs9zCdrIwao0w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zga+ZLR7XnYjLXOSITT7GZSzZ5tVHOI8r7imu6Zc9nK5oIHj4t+P/23Z8rD7IxtHiy3/omI3KjL9+ocPPPAMgh0CCQfuDgwkCosIIbPRnPiX7r+am3o4fPvHQFNfDGHWn7lXdsmwCgDtfaSqktjatsD+YGs+KwXuh4ORLOXnunGzV+vlzmZXE8P5yRgiXd9/WeUMu4lPTScHsCOa4i9AijprCF1eg6QYYPTBBqlLHcJDmlwynrRuwDUKpP8YyuHs9cO+yj6bEuOyCikJPdZT8rfxMmFpQsiMTraf7ADTHsEPgUaMB0KBnRT+pSHsRE7dG2hbXktfpDkVMznYj97dQA==
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Wed, 12 Jan 2022 10:54:35 +0000
  • Ironport-data: A9a23:ixFZb6rtc7/HDTWWvNP5BMcol3xeBmL+YhIvgKrLsJaIsI4StFCzt garIBmDOq2NM2GkfY9xboyy8U8OuJWGz4IwSQJvrHo0Ey9H+ZuZCYyVIHmrMnLJJKUvbq7GA +byyDXkBJppJpMJjk71atANlZT4vE2xbuKU5NTsY0idfic5Dndx4f5fs7Rh2NQw2IHjW1rlV e7a+KUzBnf0g1aYDUpMg06zgEsHUCPa4W5wUvQWPJinjXeG/5UnJMt3yZKZdhMUdrJ8DO+iL 9sv+Znilo/vE7XBPfv++lrzWhVirrc/pmFigFIOM0SpqkAqSiDfTs/XnRfTAKtao2zhojx/9 DlCnYGfZwgoL/PGo7sMWR1SGi59DIMYwJaSdBBTseTLp6HHW37lwvEoB0AqJ4wIvO1wBAmi9 9RBdmpLNErawbvrnvTrEYGAhex6RCXvFJkYtXx6iynQEN4tQIzZQrWM7thdtNs1rp4XRq6EN 5FDAdZpRBqdRhl0K3wcNL4nuPr2jFv5KydCi03A8MLb5ECMlVcsgdABKuH9ZdiiVchT2EGCq Qru72n/Rx0XKtGb4T6E6W63wP/CmzvhX4AfH6H+8eRl6HWRzGEODBwdVXOgvOK0zEW5Xrpix 1c8o3R06/JorQryE4e7D0bQTGO4UgA0RvV+HOwrtgu2lbve5wyQCWs1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EYSGIK8foSgzPIYurIouP3iZxA7N22pxwGLXAIV0gj1XYANu/yKDwJeOAsP+teKH Pz3Lsim9L2Ek5nEfhTS0N1FNTrlpnurtbLcBQGDxko5E2nii6p0qfzF1y90g0FWz1C7L8++S yd+jaJq5mLgrWe8FvxxmXT55NZlJ/IzcZCPtWFjowwJi/3ggilSYx9U/mpvSwzosuo9FE2+e O86SsIDoBW0Tf8b2u1qRzi103J1ysv0WbrzRuijX7qsaXCNUQHIvsEobgcXgrS6kImst05+r lMxXilu51eCg6FtDjh5vDTPisa2HackD4Hq6o+nnZfWYwRZPt6tooE5n5YF58GAWbT9J0nKu 9zF8vRjcwmPm9yV0qp/lWH/ebcHUjaRny9Mwo/U42uonRrdUlCvgolLJd1pAZEyHo/I6M0kN gsfJ4Y0I2mdfVmHp6VMt1xNfdfOla9MS4kD1jiU2gPNJt3ck4l+KSHqInc2omRCek1Jd0J6d P8bG8=
  • Ironport-sdr: hYUiELqElar3FKtYoadYCEK3YtpDZAGTKVUl+/D8uZLB1EjrWztIqr7UXzFLjDE3aKDGpAyOGi nF4ScYP/+ptWkLVg1Hv1pnn8je2W7ZGHY6kOn4e+pPFPzClBNHeX/DN4X1jhyBlTEj3W/VJd+V P5EIAdjxm9ENO6IXRdasg1Me54kR/mznvjc5irzX1QkW9fa0xWHkb6R+sPeJng9kt1OHjYwb0V fsj/MnKsQhdCA2wfQ0cway0aGf9eslqp2eKa3JVm8r0H3TVpaYD/gBi0rDnc6/obGr+2xlLvQ8 5xSLKoVlaKP3+ZT+2+fL+1qG
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Wed, Jan 12, 2022 at 09:56:12AM +0100, Jan Beulich wrote:
> While the problem report was for extreme errors, even smaller ones would
> better be avoided: The calculated period to run calibration loops over
> can (and usually will) be shorter than the actual time elapsed between
> first and last platform timer and TSC reads. Adjust values returned from
> the init functions accordingly.
> 
> On a Skylake system I've tested this on accuracy (using HPET) went from
> detecting in some cases more than 220kHz too high a value to about
> ±2kHz. On other systems (or on this system, but with PMTMR) the original
> error range was much smaller, with less (in some cases only very little)
> improvement.
> 
> Reported-by: James Dingwall <james-xen@xxxxxxxxxxxxxx>
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

> ---
> There's still a time window for the issue to occur between the final
> HPET/PMTMR read and the following TSC read. Improving this will be the
> subject of yet another patch.
> 
> TBD: Accuracy could be slightly further improved by using a (to be
>      introduced) rounding variant of muldiv64().

I'm unsure we care that much about such fine grained accuracy here.

> TBD: I'm not entirely sure how useful the conditional is - there
>      shouldn't be any inaccuracy from the division when actual equals
>      target (upon entry to the conditional), as then the divisor is
>      what the original value was just multiplied by. And as per the
>      logic in the callers actual can't be smaller than target.

Right, it's just overhead to do the muldiv64 if target == actual.

> TBD: I'm also no longer sure that the helper function is warranted
>      anymore. It started out with more contents, but is now
>      effectively only the [conditional] muldiv64() invocation.

Don't have a strong opinion, I'm fine with the helper, or else I would
likely request that the call to muldiv64 is not placed together with
the return in order to avoid overly long lines.

> 
> I'm afraid I don't see a way to deal with the same issue in init_pit().
> In particular the (multiple) specs I have to hand don't make clear
> whether the counter would continue counting after having reached zero.
> Obviously it wouldn't help to check this on a few systems, as their
> behavior could still be implementation specific.

We could likely set the counter to the maximum value it can hold
and then perform reads in a loop (like it's done for HPET or the PM
timers) and stop when start - target is reached. Not a great solution
either.

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.