Re: KVM PMU virtualization

Ingo Molnar
2010-02-26T11:22:26Z

* Joerg Roedel <joro@8bytes.org> wrote:

> On Fri, Feb 26, 2010 at 11:46:59AM +0100, Ingo Molnar wrote:
> >
> > * Joerg Roedel <joro@8bytes.org> wrote:
> >
> > > On Fri, Feb 26, 2010 at 11:46:34AM +0200, Avi Kivity wrote:
> > > > On 02/26/2010 10:42 AM, Ingo Molnar wrote:
> > > >> Note that the 'soft PMU' still sucks from a design POV as there's no generic
> > > >> hw interface to the PMU. So there would have to be a 'soft AMD' and a 'soft
> > > >> Intel' PMU driver at minimum.
> > > >>
> > > >
> > > > Right, this will severely limit migration domains to hosts of the same
> > > > vendor and processor generation. There is a middle ground, though,
> > > > Intel has recently moved to define an "architectural pmu" which is not
> > > > model specific. I don't know if AMD adopted it. We could offer both
> > > > options - native host capabilities, with a loss of compatibility, and
> > > > the architectural pmu, with loss of model specific counters.
> > >
> > > I only had a quick look yet on the architectural pmu from intel but it looks
> > > like it can be emulated for a guest on amd using existing features.
> >
> > AMD CPUs dont have enough events for that, they cannot do the 3 fixed events
> > in addition to the 2 generic ones.
>
> Good point. Maybe we can emulate that with some counter round-robin
> usage if the guest really uses all 5 counters.
>
> > Nor do you really want to standardize on KVM guests on returning
> > 'GenuineIntel' in CPUID, so that the various guest side OSs use the Intel PMU
> > drivers, right?
>
> Isn't there a cpuid bit indicating the availability of architectural
> perfmon?

there is, but can you rely on all guest OSs keying off their PMU drivers based
purely on the CPUID bit and not on any other CPUID aspects?

Guest OSs like ... Linux v2.6.33:

void __init init_hw_perf_events(void)
{
int err;

pr_info("Performance Events: ");

switch (boot_cpu_data.x86_vendor) {
case X86_VENDOR_INTEL:
err = intel_pmu_init();
break;
case X86_VENDOR_AMD:
err = amd_pmu_init();
break;
default:

Really, if you want to emulate a single Intel PMU driver model you need to
pretend that you are an Intel CPU, throughout. This cannot be had both ways.

Ingo