On Thu, Oct 31, 2024 at 04:29:52PM -0700, Sean Christopherson wrote: > > > Unless your VM doesn't need a timer and doesn't need interrupts of > > > any kind, emulating the local APIC in userspace is going to be much > > > less performant. > > > > Do you have any performance numbers? > > Heh, nope. I actually tried to grab some, mostly out of curiosity again, but > recent (last few years) versions of QEMU don't even support a userspace APIC. > > A single EOI is a great example though. On a remotely modern CPU, an in-kernel > APIC allows KVM to enable hardware acceleration so that the EOI is virtualized by > hardware, i.e. doesn't take a VM-Exit and so the latency is basically the same as > a native EOI (tens of cycles, maybe less). > > With a userspace APIC, the roundtrip to userspace to emulate the EOI is measured > in tens of thousands of cycles. IIRC, last I played around with userspace exits > the average turnaround time was ~50k cycles. That sound a lot so I did some quick benchmarking. An exit is around 1400 TSC cycles on my AMD laptop, instruction emulation takes 1200 and going to user-level needs at least 6200. Not terribly slow but still room for optimizations. INSTR CPUID 1394 RDMSR 1550 MMIO APIC 2609 IOAPIC 2800 HPET 9426 PIO PIC 1804 UART 8011