From: Luiz Capitulino <lcapitulino@redhat.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
pbonzini@redhat.com, rkrcmar@redhat.com, rostedt@goodmis.org,
mhiramat@kernel.org, mtosatti@redhat.com
Subject: Re: [PATCH 4/4] kvm: x86: export TSC offset to user-space
Date: Fri, 2 Sep 2016 12:26:55 -0400 [thread overview]
Message-ID: <20160902122655.0b5d3fe5@redhat.com> (raw)
In-Reply-To: <20160902134301.GC21771@stefanha-x1.localdomain>
On Fri, 2 Sep 2016 09:43:01 -0400
Stefan Hajnoczi <stefanha@gmail.com> wrote:
> On Wed, Aug 31, 2016 at 01:05:45PM -0400, Luiz Capitulino wrote:
> > We need to retrieve a VM's TSC offset in order to use
> > the host's TSC to merge host and guest traces. This is
> > explained in detail in this thread:
> >
> > [Qemu-devel] [RFC] host and guest kernel trace merging
> > https://lists.nongnu.org/archive/html/qemu-devel/2016-03/msg00887.html
> >
> > Today, the only way to retrieve a VM's TSC offset is
> > by using the kvm_write_tsc_offset tracepoint. This has
> > a few problems. First, the tracepoint is only emitted
> > when the VM boots, which requires a reboot to get it if
> > the VM is already running. Second, tracepoints are not
> > supposed to be ABIs in case they need to be consumed by
> > user-space tools.
> >
> > This commit exports a VM's TSC offset to user-space via
> > debugfs. A new file called "tsc-offset" is created in
> > the VM's debugfs directory. For example:
> >
> > /sys/kernel/debug/kvm/51696-10/tsc-offset
> >
> > This file contains one TSC offset per line, for each
> > vCPU. For example:
> >
> > vcpu0: 18446742405270834952
> > vcpu1: 18446742405270834952
> > vcpu2: 18446742405270834952
> > vcpu3: 18446742405270834952
> >
> > There are some important observations about this
> > solution:
> >
> > - While all vCPUs TSC offsets should be equal for the
> > cases we care about (ie. stable TSC and no write to
> > the TSC MSR), I chose to follow the spec and export
> > each vCPU's TSC offset (might also be helpful for
> > debugging)
> >
> > - The TSC offset is only useful after the VM has booted
> >
> > - We'll probably need to export the TSC multiplier too.
> > However, I've been using only the TSC offset for now.
> > So, let's get this merged first and do the TSC multiplier
> > as a second step
>
> Can TSC offset changes occur at runtime?
Yes. IIRC, if the system has an unstable TSC, KVM will adjust the
TSC offset when migrating the vCPU to other cores (although
tracing with unstable TSC is not supported). Also, the guest can
write to the TSC MSR at any time (although I don't know if Linux
ever does this).
> One example is vcpu hotplug where the tracing tool would need to fetch
> the new vcpu's TSC offset after tracing has already started.
>
> Another example is if QEMU or the guest change the TSC offset while
> running. If the tracing tool doesn't notice this then trace events will have
> incorrect timestamps.
I guess that what tools like trace-cmd want to do in those cases
is to warn the user and discard the trace. A simple way of doing
this would be to re-check that the TSC offset are the same after
tracing is done. It could also use inotify, in case it works
for debugfs (never tried it myself).
next prev parent reply other threads:[~2016-09-02 16:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-31 17:05 [PATCH 0/4] kvm: export TSC offset to user-space Luiz Capitulino
2016-08-31 17:05 ` [PATCH 1/4] kvm: kvm_destroy_vm_debugfs(): check debugs_stat_data pointer Luiz Capitulino
2016-09-02 13:51 ` Paolo Bonzini
2016-08-31 17:05 ` [PATCH 2/4] kvm: kvm_create_vm_debugfs(): cleanup on error Luiz Capitulino
2016-09-02 13:53 ` Paolo Bonzini
2016-08-31 17:05 ` [PATCH 3/4] kvm: add stub for arch specific debugfs support Luiz Capitulino
2016-09-02 13:53 ` Paolo Bonzini
2016-09-03 3:34 ` Masami Hiramatsu
2016-08-31 17:05 ` [PATCH 4/4] kvm: x86: export TSC offset to user-space Luiz Capitulino
2016-09-02 13:43 ` Stefan Hajnoczi
2016-09-02 14:15 ` Steven Rostedt
2016-09-03 0:23 ` Marcelo Tosatti
2016-09-03 4:04 ` Masami Hiramatsu
2016-09-02 16:26 ` Luiz Capitulino [this message]
2016-09-02 16:29 ` Luiz Capitulino
2016-09-02 23:49 ` Marcelo Tosatti
2016-09-03 1:29 ` Luiz Capitulino
2016-09-02 17:00 ` Paolo Bonzini
2016-09-02 17:31 ` Luiz Capitulino
2016-09-05 8:10 ` Paolo Bonzini
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=20160902122655.0b5d3fe5@redhat.com \
--to=lcapitulino@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=rostedt@goodmis.org \
--cc=stefanha@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;
as well as URLs for NNTP newsgroup(s).