mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Eric Dumazet <edumazet@google.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Borislav Petkov <bp@suse.de>
Subject: Re: [PATCH] x86/apic: reduce cache line misses in __x2apic_send_IPI_mask()
Date: Fri, 15 Oct 2021 15:26:00 +0200	[thread overview]
Message-ID: <YWmBaNoMGMZOACoT@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <CANn89iL5mmbVojrUC4GHKC+0WSxzs_obqbt=rn2S_cmkddAriQ@mail.gmail.com>

On Wed, Oct 13, 2021 at 11:02:46AM -0700, Eric Dumazet wrote:
> On Tue, Oct 12, 2021 at 5:46 AM Peter Zijlstra <peterz@infradead.org> wrote:
> 
> > I'm really conflicted about this. On the one hand, yes absolutely. On
> > the other hand, urgh, code ugly :-)
> 
> That was indeed some ugly hack.
> 
> I cooked this more generic patch instead, I am currently testing it.
> (generic as : we no longer disable hard irqs, regardless of some CONFIG option )
> 
> diff --git a/arch/x86/kernel/apic/x2apic_cluster.c
> b/arch/x86/kernel/apic/x2apic_cluster.c
> index e696e22d0531976f7cba72ed17443592eac72c13..7ad81467ce33349dee1ceaf0cefc8375d60213f6
> 100644
> --- a/arch/x86/kernel/apic/x2apic_cluster.c
> +++ b/arch/x86/kernel/apic/x2apic_cluster.c
> @@ -22,7 +22,10 @@ struct cluster_mask {
>   */
>  static u32 *x86_cpu_to_logical_apicid __read_mostly;
> 
> -static DEFINE_PER_CPU(cpumask_var_t, ipi_mask);

This might maybe do with a comment explaining where the 3 comes from.
Also see below.

> +#define IPI_NEST_MAX 3
> +static DEFINE_PER_CPU(cpumask_var_t, ipi_mask[IPI_NEST_MAX]);
> +static DEFINE_PER_CPU(int, ipi_nest_level);
> +
>  static DEFINE_PER_CPU_READ_MOSTLY(struct cluster_mask *, cluster_masks);
>  static struct cluster_mask *cluster_hotplug_mask;
> 
> @@ -45,14 +48,18 @@ __x2apic_send_IPI_mask(const struct cpumask *mask,
> int vector, int apic_dest)
>  {
>         unsigned int cpu, clustercpu;
>         struct cpumask *tmpmsk;
> -       unsigned long flags;
> +       int nest_level;
>         u32 dest;
> 
>         /* x2apic MSRs are special and need a special fence: */
>         weak_wrmsr_fence();
> -       local_irq_save(flags);
> 
> -       tmpmsk = this_cpu_cpumask_var_ptr(ipi_mask);
> +       preempt_disable();
> +       nest_level = this_cpu_inc_return(ipi_nest_level) - 1;
> +       if (WARN_ON_ONCE(nest_level >= IPI_NEST_MAX))
> +               goto end;

So this matches the: task, softirq, irq nesting and realistically won't
trigger I suppose, but that WARN is not giving me warm and fuzzies, just
not sending the IPI is terrible behaviour if we ever do hit this.

I think I would prefer to trip x2apic_send_IPI_all() over sending too
few IPIs.

That *might* in some distant future kill some NOHZ_FULL userspace, but
at least it won't make the system grind to a halt as a missing IPI can.

Thomas, any opinions there?

> +
> +       tmpmsk = this_cpu_cpumask_var_ptr(ipi_mask[nest_level]);
>         cpumask_copy(tmpmsk, mask);
>         /* If IPI should not be sent to self, clear current CPU */
>         if (apic_dest != APIC_DEST_ALLINC)
> @@ -74,7 +81,9 @@ __x2apic_send_IPI_mask(const struct cpumask *mask,
> int vector, int apic_dest)
>                 cpumask_andnot(tmpmsk, tmpmsk, &cmsk->mask);
>         }
> 
> -       local_irq_restore(flags);
> +end:
> +       this_cpu_dec(ipi_nest_level);
> +       preempt_enable();
>  }
> 
>  static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector)

      reply	other threads:[~2021-10-15 13:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07  3:17 Eric Dumazet
2021-10-07  7:29 ` Peter Zijlstra
2021-10-07 14:04   ` Eric Dumazet
2021-10-07 14:06     ` Peter Zijlstra
2021-10-07 14:13       ` Eric Dumazet
2021-10-07 22:13         ` Eric Dumazet
2021-10-12 12:45           ` Peter Zijlstra
2021-10-13 18:02             ` Eric Dumazet
2021-10-15 13:26               ` Peter Zijlstra [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YWmBaNoMGMZOACoT@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bp@suse.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®