[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3] x86/x2apic: introduce a mixed physical/cluster mode


  • To: Roger Pau Monne <roger.pau@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 3 Nov 2023 15:10:18 +0000
  • Autocrypt: addr=andrew.cooper3@xxxxxxxxxx; keydata= xsFNBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYznTairnVsN5J+ujSTIb+OlMSJUWV4opS7WVNnxHbFTPYZVQ3erv7NKc2iVizCRZ2Kxn srM1oPXWRic8BIAdYOKOloF2300SL/bIpeD+x7h3w9B/qez7nOin5NzkxgFoaUeIal12pXSR Q354FKFoy6Vh96gc4VRqte3jw8mPuJQpfws+Pb+swvSf/i1q1+1I4jsRQQh2m6OTADHIqg2E ofTYAEh7R5HfPx0EXoEDMdRjOeKn8+vvkAwhviWXTHlG3R1QkbE5M/oywnZ83udJmi+lxjJ5 YhQ5IzomvJ16H0Bq+TLyVLO/VRksp1VR9HxCzItLNCS8PdpYYz5TC204ViycobYU65WMpzWe LFAGn8jSS25XIpqv0Y9k87dLbctKKA14Ifw2kq5OIVu2FuX+3i446JOa2vpCI9GcjCzi3oHV e00bzYiHMIl0FICrNJU0Kjho8pdo0m2uxkn6SYEpogAy9pnatUlO+erL4LqFUO7GXSdBRbw5 gNt25XTLdSFuZtMxkY3tq8MFss5QnjhehCVPEpE6y9ZjI4XB8ad1G4oBHVGK5LMsvg22PfMJ ISWFSHoF/B5+lHkCKWkFxZ0gZn33ju5n6/FOdEx4B8cMJt+cWwARAQABzSlBbmRyZXcgQ29v cGVyIDxhbmRyZXcuY29vcGVyM0BjaXRyaXguY29tPsLBegQTAQgAJAIbAwULCQgHAwUVCgkI CwUWAgMBAAIeAQIXgAUCWKD95wIZAQAKCRBlw/kGpdefo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, Community Manager <community.manager@xxxxxxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 03 Nov 2023 15:10:32 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 03/11/2023 2:45 pm, Roger Pau Monne wrote:
> The current implementation of x2APIC requires to either use Cluster Logical or

I'd suggest starting with "Xen's current ..." to make it clear that this
is our logic, not a property of x2APIC itself.

> Physical mode for all interrupts.  However the selection of Physical vs 
> Logical
> is not done at APIC setup, an APIC can be addressed both in Physical or 
> Logical
> destination modes concurrently.
>
> Introduce a new x2APIC mode called mixed, which uses Logical Cluster mode for
> IPIs, and Physical mode for external interrupts, thus attempting to use the
> best method for each interrupt type.
>
> Using Physical mode for external interrupts allows more vectors to be used, 
> and
> interrupt balancing to be more accurate.
>
> Using Logical Cluster mode for IPIs allows less accesses to the ICR register

s/less/fewer/

> when sending those, as multiple CPUs can be targeted with a single ICR 
> register
> write.
>
> A simple test calling flush_tlb_all() 10000 times in a tight loop on a 96 CPU
> box gives the following average figures:
>
> Physical mode: 26617931ns
> Mixed mode:    23865337ns
>
> So ~10% improvement versus plain Physical mode.  Note that Xen uses Cluster
> mode by default, and hence is already using the fastest way for IPI delivery 
> at
> the cost of reducing the amount of vectors available system-wide.

96 looks suspiciously like an Intel number.  In nothing else, you ought
to say which CPU is it, because microarchitecture matters.  By any
chance can we try this on one of the Bergamos, to give us a datapoint at
512?

As far as the stats go, it would be helpful to give a number for Cluster
mode too, because if it's different from Mixed mode (in this test), then
it shows an error in our reasoning.

> Make the newly introduced mode the default one.
>
> Note the printing of the APIC addressing mode done in connect_bsp_APIC() has
> been removed, as with the newly introduced mixed mode this would require more
> fine grained printing, or else would be incorrect.  The addressing mode can
> already be derived from the APIC driver in use, which is printed by different
> helpers.
>
> Suggested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

Thankyou for doing this.  It's far less invasive than I was fearing.

One real bug (which Gitlab will block on), one other suspected bug that
probably nothing will notice. Minor notes otherwise.

> diff --git a/CHANGELOG.md b/CHANGELOG.md
> index b184dde8b15f..80deba5d2550 100644
> --- a/CHANGELOG.md
> +++ b/CHANGELOG.md
> @@ -9,6 +9,8 @@ The format is based on [Keep a 
> Changelog](https://keepachangelog.com/en/1.0.0/)
>  ### Changed
>  
>  ### Added
> + - On x86 introduce a new x2APIC driver that uses Cluster Logical addressing
> +   mode for IPIs and Physical addressing mode for external interrupts.

Could I request that you copy the structure of 4.18 post-reformat, in
the hope that I don't have to repeat that patch for 4.19.

Something like

 - On x86:
   - Introduce a new ...

> diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
> index eac77573bd75..cd9286f295e5 100644
> --- a/xen/arch/x86/Kconfig
> +++ b/xen/arch/x86/Kconfig
> @@ -228,11 +228,18 @@ config XEN_ALIGN_2M
>  
>  endchoice
>  
> -config X2APIC_PHYSICAL
> -     bool "x2APIC Physical Destination mode"
> +choice
> +     prompt "x2APIC Destination mode"

"x2APIC Driver default" is going to be more meaningful to a non-expert
reading this menu entry, IMO.

> diff --git a/xen/arch/x86/genapic/x2apic.c b/xen/arch/x86/genapic/x2apic.c
> index 707deef98c27..875952adc42d 100644
> --- a/xen/arch/x86/genapic/x2apic.c
> +++ b/xen/arch/x86/genapic/x2apic.c
> @@ -180,6 +180,34 @@ static const struct genapic __initconstrel 
> apic_x2apic_cluster = {
>      .send_IPI_self = send_IPI_self_x2apic
>  };
>  
> +/*
> + * Mixed x2APIC mode: use physical for external (device) interrupts, and
> + * cluster for inter processor interrupts.  Such mode has the benefits of not
> + * sharing the vector space with all CPUs on the cluster, while still 
> allowing
> + * IPIs to be more efficiently delivered by not having to perform an ICR 
> write
> + * for each target CPU.
> + */
> +static const struct genapic __initconstrel apic_x2apic_mixed = {
> +    APIC_INIT("x2apic_mixed", NULL),

Newline here please.

> +    /*
> +     * The following fields are exclusively used by external interrupts and
> +     * hence are set to use Physical destination mode handlers.
> +     */
> +    .int_delivery_mode = dest_Fixed,
> +    .int_dest_mode = 0 /* physical delivery */,
> +    .vector_allocation_cpumask = vector_allocation_cpumask_phys,
> +    .cpu_mask_to_apicid = cpu_mask_to_apicid_phys,

And here.

> +    /*
> +     * The following fields are exclusively used by IPIs and hence are set to
> +     * use Cluster Logical destination mode handlers.  Note that 
> init_apic_ldr
> +     * is not used by IPIs, but the per-CPU fields it initializes are only 
> used
> +     * by the IPI hooks.
> +     */
> +    .init_apic_ldr = init_apic_ldr_x2apic_cluster,
> +    .send_IPI_mask = send_IPI_mask_x2apic_cluster,
> +    .send_IPI_self = send_IPI_self_x2apic

Trailing comma please.

> +};
> +
>  static int cf_check update_clusterinfo(
>      struct notifier_block *nfb, unsigned long action, void *hcpu)
>  {
> @@ -220,38 +248,56 @@ static struct notifier_block x2apic_cpu_nfb = {
>  static int8_t __initdata x2apic_phys = -1;
>  boolean_param("x2apic_phys", x2apic_phys);
>  
> +enum {
> +   unset, physical, cluster, mixed
> +} static __initdata x2apic_mode = unset;
> +
> +static int __init parse_x2apic_mode(const char *s)

cf_check

> +{
> +    if ( !cmdline_strcmp(s, "physical") )
> +        x2apic_mode = physical;
> +    else if ( !cmdline_strcmp(s, "cluster") )
> +        x2apic_mode = cluster;
> +    else if ( !cmdline_strcmp(s, "mixed") )
> +        x2apic_mode = mixed;
> +    else
> +        return EINVAL;

-EINVAL ?

> +
> +    return 0;
> +}
> +custom_param("x2apic-mode", parse_x2apic_mode);
> +
>  const struct genapic *__init apic_x2apic_probe(void)
>  {
> -    if ( x2apic_phys < 0 )
> +    /* x2apic-mode option has preference over x2apic_phys. */
> +    if ( x2apic_phys >= 0 && x2apic_mode == unset )
> +        x2apic_mode = x2apic_phys ? physical : cluster;

I know this is just a rearrangement, but IMO it's clearer to follow as:

/* Honour the legacy cmdline setting if it's the only one provided. */
if (  x2apic_mode == unset && x2apic_phys >= 0 )
    ...

There are too many x2apic's in the first comment to read what's going on
at a glance.

~Andrew



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.