All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Muhammad Usama Anjum <usama.anjum@collabora.com>,
	Jonathan Corbet <corbet@lwn.net>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	"Guilherme G. Piccoli" <gpiccoli@igalia.com>
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>,
	Steven Noonan <steven@uplinklabs.net>,
	kernel@collabora.com
Subject: Re: Direct rdtsc call side-effect
Date: Thu, 01 Jun 2023 20:20:39 +0200	[thread overview]
Message-ID: <87h6rrdoy0.ffs@tglx> (raw)
In-Reply-To: <87mt1jeax1.ffs@tglx>

On Thu, Jun 01 2023 at 12:26, Thomas Gleixner wrote:
> On Thu, Jun 01 2023 at 13:45, Muhammad Usama Anjum wrote:
>> We are thinking of saving and restoring the timestamp counter at suspend
>> and resume time respectively.

I assume you talk about suspend to disk here, right? Suspend to RAM
definitely does not have the problem at least not on any halfways
contemporary CPU.

>>  In theory it can work on Intel because of
>> TSC_ADJUST register. But it'll never work on AMD until:
>> * AMD supports the same kind of adjust register. (AMD has said that the
>> adjust register cannot be implemented in their firmware. They'll have to
>> add it to their hardware.)
>> * by manual synchronization in kernel (I know you don't like this idea. But
>> there is something Windows is doing to save/restore and sync the TSC)
>
> Synchronizing TSC by writing the TSC MSR is fragile as hell. This has
> been tried so often and never reliably passed all synchronization tests
> on a wide range of systems.
>
> It kinda works on single socket, but not on larger systems.

Here is an example where it falls flat on its nose.

 One of the early Ryzen laptops had a broken BIOS which came up with
 unsynchronized TSCs. I tried to fix that up, but couldn't get it to sync
 on all CPUs because for some stupid reason the TSC write got
 arbritrarily delayed (assumably by SMI/SMM).

 After the vendor fixed the BIOS, I tried again and the problem
 persisted.

 So on such a machine the 'fixup time' mechanism would simply render an
 otherwise perfectly fine TSC unusable for timekeeping.

We asked both Intel and AMD to add TSC_ADJUST probably 15 years
ago. Intel added it with some HSW variants (IIRC) and since SKL all CPUs
have it. I don't know why AMD thought it's not required. That could have
spared a gazillion of bugzilla entries vs. the early Ryzen machines.

Thanks,

        tglx


  reply	other threads:[~2023-06-01 18:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-01  8:45 Direct rdtsc call side-effect Muhammad Usama Anjum
2023-06-01  8:56 ` Peter Zijlstra
2023-06-01  8:58   ` Peter Zijlstra
2023-06-01 10:31   ` Thomas Gleixner
2023-06-01 10:26 ` Thomas Gleixner
2023-06-01 18:20   ` Thomas Gleixner [this message]
2023-06-01 19:07     ` Steven Noonan
2023-06-01 19:31       ` H. Peter Anvin
2023-06-01 20:10       ` Thomas Gleixner
2023-06-01 20:13         ` Thomas Gleixner
2023-06-01 20:31       ` Peter Zijlstra
2023-06-01 21:41         ` Steven Noonan
2023-06-02  6:45           ` Peter Zijlstra
2023-06-05 10:27   ` David Laight
2023-06-05 14:43     ` Thomas Gleixner
2023-06-05 15:54       ` David Laight
2023-06-05 16:32         ` H. Peter Anvin
2023-06-06  8:23           ` David Laight
2023-06-09  0:14             ` H. Peter Anvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h6rrdoy0.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=gpiccoli@igalia.com \
    --cc=hpa@zytor.com \
    --cc=kernel@collabora.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=steven@uplinklabs.net \
    --cc=usama.anjum@collabora.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.