本文参考的内核版本为v6.0

Motivation

virtual IPI fastpath

1
2
3
4
vmx_vcpu_run
└── vmx_exit_handlers_fastpath
└── handle_fastpath_set_msr_irqoff
└── handle_fastpath_set_x2apic_icr_irqoff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
* The fast path for frequent and performance sensitive wrmsr emulation,
* i.e. the sending of IPI, sending IPI early in the VM-Exit flow reduces
* the latency of virtual IPI by avoiding the expensive bits of transitioning
* from guest to host, e.g. reacquiring KVM's SRCU lock. In contrast to the
* other cases which must be called after interrupts are enabled on the host.
*/
static int handle_fastpath_set_x2apic_icr_irqoff(struct kvm_vcpu *vcpu, u64 data)
{
if (!lapic_in_kernel(vcpu) || !apic_x2apic_mode(vcpu->arch.apic))
return 1;

if (((data & APIC_SHORT_MASK) == APIC_DEST_NOSHORT) &&
((data & APIC_DEST_MASK) == APIC_DEST_PHYSICAL) &&
((data & APIC_MODE_MASK) == APIC_DM_FIXED) &&
((u32)(data >> 32) != X2APIC_BROADCAST))
return kvm_x2apic_icr_write(vcpu->arch.apic, data);

return 1;
}

virtual TSC-Deadline timer fastpath

KVM: X86: TSCDEADLINE MSR emulation fastpath

1
2
3
4
5
vmx_vcpu_run
└── vmx_exit_handlers_fastpath
└── handle_fastpath_set_msr_irqoff
└── handle_fastpath_set_tscdeadline
└── kvm_set_lapic_tscdeadline_msr

KVM: VMX: Handle preemption timer fastpath
该patch优化的是使用preemption timer模拟lapic timer的case

1
2
3
vmx_vcpu_run
└── vmx_exit_handlers_fastpath
└── handle_fastpath_preemption_timer


参考资料:

  1. KVM Latency and Scalability Performance Tuning
  2. KVM: VMX: FIXED+PHYSICAL mode single target IPI fastpath
  3. KVM: VMX: Tscdeadline timer emulation fastpath