x86: enable x2APIC mode regardless of interrupt remapping support
cover x86: enable x2APIC mode regardless of interrupt remapping support
Hello,
The following series aims to allow enabling x2APIC mode without interrupt remapping support. The main usage of this would be in virtualized environments, that usually provide x2APIC support but not interrupt remapping.
See the last patch for some performance numbers of using x2APIC over xAPIC when running Xen in pvshim mode.
Thanks, Roger.
Roger Pau Monne (3):
x86/ioapic: only use dest32 with x2apic and interrupt remapping
enabled
x86/smp: check APIC ID on AP bringup
x86/apic: allow enabling x2APIC mode regardless of interrupt remapping
xen/arch/x86/apic.c | 94 +++++++++++++++++++++--------------------- xen/arch/x86/io_apic.c | 12 +++--- xen/arch/x86/smpboot.c | 7 ++++ 3 files changed, 59 insertions(+), 54 deletions(-)
Signature · 7 lines
2.24.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/3 x86/ioapic: only use dest32 with x2apic and interrupt remapping enabled
The IO-APIC code assumes that x2apic being enabled also implies interrupt remapping being enabled, and hence will use the 32bit destination field in the IO-APIC entry.
This is safe now, but there's no reason to not enable x2APIC even without interrupt remapping, and hence the IO-APIC code needs to use the 32 bit destination field only when both interrupt remapping and x2APIC are enabled.
--- xen/arch/x86/io_apic.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
xen/arch/x86/io_apic.c +6 -6
@@ -964,7 +964,7 @@ static hw_irq_controller ioapic_edge_type;#define IOAPIC_LEVEL 1#define SET_DEST (ent, mode, val) do { \ - if (x2apic_enabled) \ + if (x2apic_enabled && iommu_intremap) \ (ent).dest.dest32 = (val); \ else \ (ent).dest.mode.mode##_dest = (val); \
@@ -1194,14 +1194,14 @@ static void /*__init*/ __print_IO_APIC(bool boot)printk (KERN_DEBUG ".... IRQ redirection table:\n" );printk (KERN_DEBUG " NR %s Msk Trg IRR Pol Stat DstM DelM Vec\n" , - x2apic_enabled ?" DestID" :"Dst" ); + (x2apic_enabled && iommu_intremap) ?" DestID" :"Dst" );for (i =0 ; i <= reg_01.bits.entries; i++) {struct IO_APIC_route_entry entry; entry =ioapic_read_entry (apic, i,0 ); -if ( x2apic_enabled ) +if ( x2apic_enabled && iommu_intremap )printk (KERN_DEBUG " %02x %08x" , i, entry.dest.dest32);else printk(KERN_DEBUG " %02x %02x ", i,
@@ -2504,9 +2504,9 @@ void dump_ioapic_irq_info(void) rte.dest_mode ?'L' :'P' , rte.delivery_status, rte.polarity, rte.irr, rte.trigger ?'L' :'E' , rte.mask, - x2apic_enabled ?8 :2 , - x2apic_enabled ? rte.dest.dest32 - : rte.dest.logical.logical_dest); + (x2apic_enabled && iommu_intremap) ?8 :2 , + (x2apic_enabled && iommu_intremap) ? + rte.dest.dest32 : rte.dest.logical.logical_dest);if ( entry->next ==0 )break ;
Signature · 7 lines
2.24.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/3 x86/smp: check APIC ID on AP bringup
In reply to Roger Pau MonneCheck that the processor to be woken up APIC ID is addressable in the current APIC mode.
Note that in practice systems with APIC IDs > 255 should already have x2APIC enabled by the firmware, and hence this is mostly a safety belt.
--- xen/arch/x86/smpboot.c | 7 +++++++ 1 file changed, 7 insertions(+)
xen/arch/x86/smpboot.c +7 -0
@@ -1315,6 +1315,13 @@ int __cpu_up(unsigned int cpu)if ( (apicid = x86_cpu_to_apicid[cpu]) ==BAD_APICID )return -ENODEV ; +if ( (!x2apic_enabled || !iommu_intremap) && (apicid >>8 ) ) + { +printk ("Processor with APIC ID %u cannot be onlined in xAPIC mode " +"or without interrupt remapping\n" , apicid); +return -EINVAL ; + } +if ( (ret =do_boot_cpu (apicid, cpu)) !=0 )return ret;
Signature · 7 lines
2.24.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/3 x86/apic: allow enabling x2APIC mode regardless of interrupt remapping
In reply to Roger Pau Monnex2APIC mode doesn't mandate interrupt remapping, and hence can be enabled independently. This patch enables x2APIC when available, regardless of whether there's interrupt remapping support.
This is beneficial specially when running on virtualized environments, since it reduces the amount of vmexits. For example when sending an IPI in xAPIC mode Xen performs at least 3 different accesses to the APIC MMIO region, while when using x2APIC mode a single wrmsr is used.
The following numbers are from a lock profiling of a Xen PV shim running a Linux PV kernel with 32 vCPUs and xAPIC mode:
(XEN) Global lock flush_lock: addr=ffff82d0804af1c0, lockval=03190319, not locked
(XEN) lock:656153(892606463454), block:602183(9495067321843)
Average lock time: 1360363ns
Average block time: 15767743ns
While the following are from the same configuration but with the shim using x2APIC mode:
(XEN) Global lock flush_lock: addr=ffff82d0804b01c0, lockval=1adb1adb, not locked
(XEN) lock:1841883(1375128998543), block:1658716(10193054890781)
Average lock time: 746588ns
Average block time: 6145147ns
Enabling x2APIC has halved the average lock time, thus reducing contention.
--- xen/arch/x86/apic.c | 94 ++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 48 deletions(-)
xen/arch/x86/apic.c +46 -48
@@ -492,7 +492,8 @@ static void __enable_x2apic(void)static void resume_x2apic (void ) { -iommu_enable_x2apic (); +if (iommu_supports_x2apic () ) +iommu_enable_x2apic ();__enable_x2apic (); }
@@ -695,7 +696,8 @@ int lapic_suspend(void)local_irq_save (flags);disable_local_APIC (); -iommu_disable_x2apic (); +if (iommu_supports_x2apic () ) +iommu_disable_x2apic ();local_irq_restore (flags);return 0 ; }
@@ -875,56 +877,49 @@ void __init x2apic_bsp_setup(void)printk ("x2APIC: Already enabled by BIOS: Ignoring cmdline disable.\n" ); } -if ( !iommu_supports_x2apic () ) +if (iommu_supports_x2apic () ) { -if ( !x2apic_enabled ) +if ( (ioapic_entries =alloc_ioapic_entries ()) ==NULL ) { -printk ("Not enabling x2APIC: depends on IOMMU support\n" ); -return ; +printk ("Allocate ioapic_entries failed\n" ); + goto out; } -panic ("x2APIC: already enabled by BIOS, but no IOMMU support\n" ); - } - -if ( (ioapic_entries =alloc_ioapic_entries ()) ==NULL ) - { -printk ("Allocate ioapic_entries failed\n" ); - goto out; - } -if (save_IO_APIC_setup (ioapic_entries) ) - { -printk ("Saving IO-APIC state failed\n" ); - goto out; - } +if (save_IO_APIC_setup (ioapic_entries) ) + { +printk ("Saving IO-APIC state failed\n" ); + goto out; + } -mask_8259A (); -mask_IO_APIC_setup (ioapic_entries); +mask_8259A (); +mask_IO_APIC_setup (ioapic_entries); -switch (iommu_enable_x2apic () ) - { -case 0 : - intremap_enabled = true; -break ; -case -ENXIO :/* ACPI_DMAR_X2APIC_OPT_OUT set */ -if ( !x2apic_enabled ) +switch (iommu_enable_x2apic () ) { -printk ("Not enabling x2APIC (upon firmware request)\n" ); +case 0 : + intremap_enabled = true; +break ; +case -ENXIO :/* ACPI_DMAR_X2APIC_OPT_OUT set */ +if ( !x2apic_enabled ) + { +printk ("Not enabling x2APIC (upon firmware request)\n" ); + intremap_enabled = false; + goto restore_out; + } +/* fall through */ +default : +if ( x2apic_enabled ) +panic ("Interrupt remapping could not be enabled while " +"x2APIC is already enabled by BIOS\n" ); + +printk (XENLOG_ERR +"Failed to enable Interrupt Remapping: Will not enable x2APIC.\n" ); intremap_enabled = false; goto restore_out; } -/* fall through */ -default : -if ( x2apic_enabled ) -panic ("Interrupt remapping could not be enabled while " -"x2APIC is already enabled by BIOS\n" ); - -printk (XENLOG_ERR -"Failed to enable Interrupt Remapping: Will not enable x2APIC.\n" ); - intremap_enabled = false; - goto restore_out; - } - force_iommu =1 ; + force_iommu =1 ; + }if ( !x2apic_enabled ) {
@@ -938,13 +933,16 @@ void __init x2apic_bsp_setup(void)printk ("Switched to APIC driver %s\n" , genapic.name); restore_out: -/* -* NB: do not use raw mode when restoring entries if the iommu has been -* enabled during the process, because the entries need to be translated -* and added to the remapping table in that case. -*/ -restore_IO_APIC_setup (ioapic_entries, !intremap_enabled); -unmask_8259A (); +if (iommu_supports_x2apic () ) + { +/* +* NB: do not use raw mode when restoring entries if the iommu has been +* enabled during the process, because the entries need to be translated +* and added to the remapping table in that case. +*/ +restore_IO_APIC_setup (ioapic_entries, !intremap_enabled); +unmask_8259A (); + } out:if ( ioapic_entries )
Signature · 7 lines
2.24.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel