From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752936AbcIBNnH (ORCPT ); Fri, 2 Sep 2016 09:43:07 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:33120 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751496AbcIBNnF (ORCPT ); Fri, 2 Sep 2016 09:43:05 -0400 Date: Fri, 2 Sep 2016 09:43:01 -0400 From: Stefan Hajnoczi To: Luiz Capitulino 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 Message-ID: <20160902134301.GC21771@stefanha-x1.localdomain> References: <1472663145-1835-1-git-send-email-lcapitulino@redhat.com> <1472663145-1835-5-git-send-email-lcapitulino@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Bu8it7iiRSEf40bY" Content-Disposition: inline In-Reply-To: <1472663145-1835-5-git-send-email-lcapitulino@redhat.com> User-Agent: Mutt/1.7.0 (2016-08-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --Bu8it7iiRSEf40bY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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: >=20 > [Qemu-devel] [RFC] host and guest kernel trace merging > https://lists.nongnu.org/archive/html/qemu-devel/2016-03/msg00887.html >=20 > 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. >=20 > 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: >=20 > /sys/kernel/debug/kvm/51696-10/tsc-offset >=20 > This file contains one TSC offset per line, for each > vCPU. For example: >=20 > vcpu0: 18446742405270834952 > vcpu1: 18446742405270834952 > vcpu2: 18446742405270834952 > vcpu3: 18446742405270834952 >=20 > There are some important observations about this > solution: >=20 > - 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) >=20 > - The TSC offset is only useful after the VM has booted >=20 > - 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? 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 ha= ve incorrect timestamps. Stefan --Bu8it7iiRSEf40bY Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJXyYHlAAoJEJykq7OBq3PIkI0H/0Xk44ZvfrwQ6BWorMWZkgm7 hsquU56Ut26GBJLUma4TYE010spe7zMsiMjfLYv1zXXV3Js0JvN/GYmc+DQsnWp2 jy0nvUp+oRPVpwNWqq3jbyCl55PBF37RzgYRZDJysQ2B/pnEumejQkAr0WStsSuh y69S+G+rg64SQyQT9qQK0lhD9obHP66ecI/IcMWbyn4CC0OIgZ6+ZTdcZg4llTew bYg872Lg5UdjaNnwORTBLg037asSrPeDOr2Nr5C0opS/0cMqL0zg9zMn/sYi1JS5 ZQjCwPthXpQOE7KfOS4GNvLj6/bwNoGORbf1e2Qi5Hb5/JZweg+nTZTgAbJ55xQ= =ONmX -----END PGP SIGNATURE----- --Bu8it7iiRSEf40bY--