Re: RFC: paravirtualizing perf_clock

From: Peter Zijlstra
Date: Mon Oct 28 2013 - 09:16:12 EST

On Sun, Oct 27, 2013 at 07:27:27PM -0600, David Ahern wrote:
> Often when debugging performance problems in a virtualized environment you
> need to correlate what is happening in the guest with what is happening in
> the host. To correlate events you need a common time basis (or the ability
> to directly correlate the two).
> The attached patch paravirtualizes perf_clock, pulling the timestamps in VMs
> from the host using an MSR read if the option is available (exposed via KVM
> feature flag). I realize this is not the correct end code but it illustrates
> what I would like to see -- host and guests using the same perf_clock so
> timestamps directly correlate.
> Any suggestions on how to do this and without impacting performance. I
> noticed the MSR path seems to take about twice as long as the current
> implementation (which I believe results in rdtsc in the VM for x86 with
> stable TSC).

So assuming all the TSCs are in fact stable; you could implement this by
syncing up the guest TSC to the host TSC on guest boot. I don't think
anything _should_ rely on the absolute TSC value.

Of course you then also need to make sure the host and guest tsc
multipliers (cyc2ns) are identical, you can play games with
cyc2ns_offset if you're brave.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at