public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* Re: VT-x and Performance counter interrupt in KVM mode
@ 2007-03-27 16:35 Stephane Eranian
       [not found] ` <20070327163515.GE11818-HU54gidqsKnWxDs0y9d3MAC/G2K4zDHf@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Stephane Eranian @ 2007-03-27 16:35 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f; +Cc: Stephane Eranian

Hi Avi,

> 
> Shobha Ranganathan wrote:
> > I am trying to capture in vmx.c the hardware
> > performance counter(PMU) interrupt of a i386 Linux
> > kernel running with perfmon on a Core 2 Duo machine
> > running with kvm-15. host is running kvm with VT-x in
> > x86-64 mode.
> >
> > The PMU interrupt is programmed in the APIC LVT entry
> > (set to 0xee)by the guest OS. 
> 
> On stock kvm, the guest os programs a virtual apic that lives in qemu, 
> not the real apic, so it would never cause any interrupt.  Are you 
> running with a modified kvm that allows the guest to touch the real apic?
> 

The Performance counters (PMU) cannot be fully virtualized, they need to
run on the actual MSR registers. The PMU interrupt is controlled by the
local APIC. To get overflow-based sampling to work in a guest, we need to
allow the PMU to interrupt. Supposing we have allowed wrmsr,rdmsr to the
PMU registers, the guest perfmon will setup the virtual APIC and virtual
IDT as it normally would on real HW. VT-x takes care of the IDT but not
of the APIC. The guest never touches the real APIC, qemu handles this.
However if the host kernel is running perfmon, it does already have the
actual APIC programmed for the PMU.

In this configuration, the host perfmon interrupt driver catches the PMU
interrupt generated while running in non-root VMX mode. At that point, there
is a VM-exit. I have now been able to track down the type of exit in this
case. You have a VM-exit for an external interrupt, which is fine, however
the intr_info (VM_EXIT_INTR_INFO) is 0x0, in other words, VT-x does not give
you any good info as to why you exited. As soon as you leave the VM_RESUME code,
you branch to the host perfmon interrupt handler.

In any case, the current solution I have for this is sort of hybrid because
you rely on the host APIC to be programmed correctly, and then you need
communication between the host perfmon code and the KVM kernel code to be
able to inject the PMU interrupt back into the guest. Another solution I have
experimented is for the host perfmon to notify the user level qemu APIC code
(SIGIO) which then issues the right KVM_INTERRUPT ioctl(), but that is slow
and has some rce condition with the guest.

The timer interrupt, also normally controlled by the APIC, is managed differently
and can be fully virtualized by qemu using Linux timers. The PMU cannot be
virtualized that way.

At this point, even if you had APIC emulation in KVM (kernel), I am not sure
this would solve this issue. I think I can live with having back communication
between the host perfmon and KVM.

Any better ideas?

> > Similarly, an IDT entry
> > connects the interrupt vector to the interrupt
> > handler.
> > I am not able to catch, in kvm, the PMU interrupt
> > happening in VMX non-root mode. It does not seem to
> > appear in the VM-exit interruption information nor in
> > the IDT-vectoring information. It does not seem to
> > be caught by any of the exit handlers yet the host PMU
> > interrupt handler catches it which is not what we
> > want.
> >
> > Any idea on what is going on with this interrupt?
> >   
> 
> It looks completely normal, assuming the host also programmed the timer 
> to the same vector.  Look in qemu/hw/apic.c to find your missing interrupt.
> 

-- 
-Stephane

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 7+ messages in thread
* VT-x and Performance counter interrupt in KVM mode
@ 2007-03-21  4:58 Shobha Ranganathan
       [not found] ` <826581.57009.qm-jpo5DsbaTqqB9c0Qi4KiSl5cfvJIxWXgQQ4Iyu8u01E@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Shobha Ranganathan @ 2007-03-21  4:58 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

I am trying to capture in vmx.c the hardware
performance counter(PMU) interrupt of a i386 Linux
kernel running with perfmon on a Core 2 Duo machine
running with kvm-15. host is running kvm with VT-x in
x86-64 mode.

The PMU interrupt is programmed in the APIC LVT entry
(set to 0xee)by the guest OS. Similarly, an IDT entry
connects the interrupt vector to the interrupt
handler.
I am not able to catch, in kvm, the PMU interrupt
happening in VMX non-root mode. It does not seem to
appear in the VM-exit interruption information nor in
the IDT-vectoring information. It does not seem to
be caught by any of the exit handlers yet the host PMU
interrupt handler catches it which is not what we
want.

Any idea on what is going on with this interrupt?

Thanks
shobha



 
____________________________________________________________________________________
Expecting? Get great news right away with email Auto-Check. 
Try the Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-03-28 16:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-27 16:35 VT-x and Performance counter interrupt in KVM mode Stephane Eranian
     [not found] ` <20070327163515.GE11818-HU54gidqsKnWxDs0y9d3MAC/G2K4zDHf@public.gmane.org>
2007-03-27 17:10   ` Avi Kivity
     [not found]     ` <46095022.2030209-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-03-28 15:41       ` Stephane Eranian
     [not found]         ` <20070328154155.GB12647-HU54gidqsKnWxDs0y9d3MAC/G2K4zDHf@public.gmane.org>
2007-03-28 16:03           ` Avi Kivity
  -- strict thread matches above, loose matches on Subject: below --
2007-03-21  4:58 Shobha Ranganathan
     [not found] ` <826581.57009.qm-jpo5DsbaTqqB9c0Qi4KiSl5cfvJIxWXgQQ4Iyu8u01E@public.gmane.org>
2007-03-21  7:23   ` Avi Kivity
2007-03-21  7:25   ` Dor Laor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox