From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Spoorti Doddamani <spoosd@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: Question on rdtsc instruction in guest
Date: Thu, 16 Jan 2020 15:44:10 -0800 [thread overview]
Message-ID: <20200116234410.GF20561@linux.intel.com> (raw)
In-Reply-To: <CAGKSnTgv5F_d23oRi3FHwKVw8Mij7_5g4o2FiaXwDA43KP+nng@mail.gmail.com>
On Thu, Jan 16, 2020 at 04:39:47PM -0500, Spoorti Doddamani wrote:
> Hi,
>
> I would like to know how rdtsc instruction works when executed in
> guest. The guest uses kvm-clock for timekeeping. The tsc_timestamp
> field in the shared page between the hypervisor and guest is updated
> constantly by the hypervisor. Does rdtsc instruction, when executed in
> guest, read the value from this shared page? Or does it read the
> hardware TSC MSR register? If it reads from the hardware TSC MSR
> register why do I observe different values of TSC when executed in
> host and guest? Or is the instruction emulated by the hypervisor?
On KVM, RDTSC accesses hardware directly. A VMM *can* configure RDTSC to
VM-Exit, e.g. to emulate it, but KVM does not do so (unless you get into
nested virtualization scenarios).
As to why the guest sees a different value, hardware supports a virtual
TSC via a TSC offset mechanism, i.e. RDTSC returns the "real" TSC plus an
arbitrary value (the offset) controlled by the VMM (KVM). This allows KVM
to virtualize the TSC and expose RDTSC to the guest (as opposed to
emulating RDTSC).
Recent CPUs also support TSC scaling, which essentially allows the virtual
TSC to count at a different frequency than the real TSC. This is used to
migrate VMs between physical systems with different TSC frequencies.
prev parent reply other threads:[~2020-01-16 23:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-16 21:39 Question on rdtsc instruction in guest Spoorti Doddamani
2020-01-16 23:44 ` Sean Christopherson [this message]
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=20200116234410.GF20561@linux.intel.com \
--to=sean.j.christopherson@intel.com \
--cc=kvm@vger.kernel.org \
--cc=spoosd@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox