heavy P2M lock contention on guest HPET counter reads
Hi,
with 40+ vCPU Win2012R2 guests we're observing apparent guest live locks. The 'd' debug key reveals more than half of the vCPU-s doing an inlined HPET main counter read from KeQueryPerformanceCounter(), resulting in all of them racing for the lock at the beginning of __get_gfn_type_access(). Assuming it is really necessary to always take the write lock (rather than just the read one) here, would it perhaps be reasonable to introduce a bypass in hvm_hap_nested_page_fault() for the HPET page similar to the LAPIC one?
Thanks, Jan
Quoted 11 lines · Jan Beulich
Hi,
with 40+ vCPU Win2012R2 guests we're observing apparent guest live locks. The 'd' debug key reveals more than half of the vCPU-s doing an inlined HPET main counter read from
KeQueryPerformanceCounter(), resulting in all of them racing for the lock at the beginning of__get_gfn_type_access(). Assuming it is really necessary to always take the write lock (rather than just the read one) here, would it perhaps be reasonable to introduce a bypass inhvm_hap_nested_page_fault()for the HPET page similar to the LAPIC one?
Quoted 1 line
Thanks, Jan
We have received similar concerns about the emulation overhead of the vhpet, but not with a guest that size.
One complication is that the HPET can optionally be emulated by qemu based on an HVMPARAM, so the fastpath has to consider creating an ioreq. (Frankly, I think this ability is completely mad, and I doubt anyone would notice if it ceased to work. There is no reason to use qemu's emulation in preference to Xen's, especially as Xen's emulatator was copied from qemu at some point in the past)
Have you enabled with viridian extensions? Providing the TSC enlightenments should cause Windows to completely ignore the vhpet.
~Andrew
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 30.07.14 at 12:29, <[email protected]> wrote:
One complication is that the HPET can optionally be emulated by qemu based on an HVMPARAM, so the fastpath has to consider creating an ioreq. (Frankly, I think this ability is completely mad, and I doubt anyone would notice if it ceased to work. There is no reason to use qemu's emulation in preference to Xen's, especially as Xen's emulatator was copied from qemu at some point in the past)
No, we wouldn't need to care about that mode. For one, the qemu path should be unreachable for a well behaved guest, since with "hpet=0" there's no ACPI table advertising a HPET. And then, even if it was reachable (e.g. due to a guest guessing/probing it), I don't think we need to be concerned about that path's performance.
Quoted 2 lines
Have you enabled with viridian extensions? Providing the TSC enlightenments should cause Windows to completely ignore the vhpet.
I'm told this flag doesn't make any difference, albeit I'll have them double check.
Jan
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 30.07.14 at 12:08, <[email protected]> wrote:
with 40+ vCPU Win2012R2 guests we're observing apparent guest live locks. The 'd' debug key reveals more than half of the vCPU-s doing an inlined HPET main counter read from
KeQueryPerformanceCounter(), resulting in all of them racing for the lock at the beginning of__get_gfn_type_access(). Assuming it is really necessary to always take the write lock (rather than just the read one) here, would it perhaps be reasonable to introduce a bypass inhvm_hap_nested_page_fault()for the HPET page similar to the LAPIC one?
Like this (for 4.4, if it matters, and with no tester feedback yet), raising the question whether we shouldn't just do this for all internal MMIO handlers.
xen/arch/x86/hvm/hvm.c +8 -3
@@ -1523,11 +1523,16 @@ int hvm_hap_nested_page_fault(paddr_t gp } } -/* For the benefit of 32-bit WinXP (& older Windows) on AMD CPUs, -* a fast path for LAPIC accesses, skipping the p2m lookup. */ +/* +* For the benefit of 32-bit WinXP (& older Windows) on AMD CPUs, +* a fast path for LAPIC accesses, skipping the p2m lookup. +* Similarly for newer Windows (like Server 2012) a fast path for +* HPET accesses. +*/ if ( !nestedhvm_vcpu_in_guestmode (v) &&is_hvm_vcpu (v) - && gfn ==PFN_DOWN (vlapic_base_address (vcpu_vlapic (v))) ) + && (gfn ==PFN_DOWN (vlapic_base_address (vcpu_vlapic (v))) + || hpet_mmio_handler.check_handler (v, gpa)) ) {if ( !handle_mmio () )hvm_inject_hw_exception (TRAP_gp_fault,0 );
Quoted 25 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 30.07.14 at 12:08, <[email protected]> wrote:
with 40+ vCPU Win2012R2 guests we're observing apparent guest live locks. The 'd' debug key reveals more than half of the vCPU-s doing an inlined HPET main counter read from
KeQueryPerformanceCounter(), resulting in all of them racing for the lock at the beginning of__get_gfn_type_access(). Assuming it is really necessary to always take the write lock (rather than just the read one) here, would itperhaps
Quoted 2 lines
be reasonable to introduce a bypass in
hvm_hap_nested_page_fault()for the HPET page similar to the LAPIC one?Like this (for 4.4, if it matters, and with no tester feedback yet), raising the question whether we shouldn't just do this for all internal MMIO handlers.
xen/arch/x86/hvm/hvm.c +2
-2@@ -1523,11 +1523,16 @@ int hvm_hap_nested_page_fault(paddr_t gp } } -/* For the benefit of 32-bit WinXP (& older Windows) on AMD CPUs, -* a fast path for LAPIC accesses, skipping the p2m lookup. */ +/* +* For the benefit of 32-bit WinXP (& older Windows) on AMD CPUs,
xen/arch/x86/hvm/hvm.c int hvm_hap_nested_page_fault(paddr_t gp · line 1536
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +6
-1+* a fast path for LAPIC accesses, skipping the p2m lookup. +* Similarly for newer Windows (like Server 2012) a fast path for +* HPET accesses. +*/ if ( !nestedhvm_vcpu_in_guestmode (v) &&is_hvm_vcpu (v) - && gfn ==PFN_DOWN (vlapic_base_address (vcpu_vlapic (v))) ) + && (gfn ==PFN_DOWN (vlapic_base_address (vcpu_vlapic (v))) + || hpet_mmio_handler.check_handler (v, gpa)) )
This is reasonable. I suggest knee-capping the open coding and moving this block into its own little inline function (e.g. try_shortcut_hvm_mmio). I think soon enough we may run into the next Xen-implemented mmio range that is getting pounded. In any case it will do for better-looking code. Roughly:
int try_shortcut_hvm_mmio(struct vcpu *v, paddr_t gpa)
{
int i;
if ( nestedhvm_vcpu_in_guestmode(v)
|| !is_hvm_vcpu(v))
return 0;
for ( i = 0; i < HVM_MMIO_HANDLER_NR; i++ )
if ( hvm_mmio_handlers[i]->check_handler(v, gpa) )
return 1;
}Having said that, I don't know off the top of my head that is obviously correct to shortcut the p2m lookup for msix table and iommu. I think so, but...
Andres
{xen/arch/x86/hvm/hvm.c int hvm_hap_nested_page_fault(paddr_t gp · line 1538
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +0
-0if ( !handle_mmio () )hvm_inject_hw_exception (TRAP_gp_fault,0 );
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 30.07.14 at 20:15, <[email protected]> wrote:
Having said that, I don't know off the top of my head that is obviously correct to shortcut the p2m lookup for msix table and iommu. I think so, but...
All internal MMIO ranges are what you'd call "positively decoded" on real hardware, i.e. they ought to supersede any other address decoding rules anyway. Since they're also not associated with possibly varying MFNs, the P2M lookup on them is simply pointless, and short-circuiting them is imo at once making better guarantees towards consistent behavior.
Jan
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 30.07.14 at 20:15, <[email protected]> wrote:
Having said that, I don't know off the top of my head that is obviously correct to shortcut the p2m lookup for msix table and iommu. I think so, but...
Quoted 7 lines
All internal MMIO ranges are what you'd call "positively decoded" on real hardware, i.e. they ought to supersede any other address decoding rules anyway. Since they're also not associated with possibly varying MFNs, the P2M lookup on them is simply pointless, and short-circuiting them is imo at once making better guarantees towards consistent behavior.
Ok. Good. However: this is a very hot path. I wonder if this iteration can be made more efficient (i.e sort the resulting mmio regions and do binary search).
Andres
Quoted 4 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 02.08.14 at 04:33, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 30.07.14 at 20:15, <[email protected]> wrote:
Having said that, I don't know off the top of my head that is obviously correct to shortcut the p2m lookup for msix table and iommu. I think so, but...
Quoted 7 lines
All internal MMIO ranges are what you'd call "positively decoded" on real hardware, i.e. they ought to supersede any other address decoding rules anyway. Since they're also not associated with possibly varying MFNs, the P2M lookup on them is simply pointless, and short-circuiting them is imo at once making better guarantees towards consistent behavior.
Quoted 3 lines
Ok. Good. However: this is a very hot path. I wonder if this iteration can be made more efficient (i.e sort the resulting mmio regions and do binary search).
How much more efficient would a binary search be for currently five handlers? Furthermore, ->check_handler() involves more than just an address range comparison in at least some of the cases.
Jan
Quoted 17 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 02.08.14 at 04:33, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 30.07.14 at 20:15, <[email protected]> wrote:
Having said that, I don't know off the top of my head that is
obviously
Quoted 1 line
Quoted 1 line
Quoted 1 line
correct to shortcut the p2m lookup for msix table and iommu. I think
so,
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
but...
All internal MMIO ranges are what you'd call "positively decoded" on real hardware, i.e. they ought to supersede any other address decoding rules anyway. Since they're also not associated with possibly varying MFNs, the P2M lookup on them is simply pointless, and short-circuiting them is imo at once making better guarantees towards consistent behavior.
Quoted 9 lines
Quoted 1 line
Ok. Good. However: this is a very hot path. I wonder if this iteration
can
Quoted 2 lines
be made more efficient (i.e sort the resulting mmio regions and do binary search).
How much more efficient would a binary search be for currently five handlers? Furthermore, ->check_handler() involves more than just an address range comparison in at least some of the cases.
Not much more efficient, given the almost zero odds of having more than five mmio handlers that can skip p2m lookup.
The only better performant option seems open-coding. Given the sensitivity of the path, I'd say stick with the original plan with two open coded if's (blatant backtrack!)
Let me know if you'd rather we follow the route I laid out here.
Thanks
Andres
Quoted 3 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel