linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "tip-bot2 for Thomas Gleixner" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Juergen Gross <jgross@suse.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org, maz@kernel.org
Subject: [tip: irq/core] xen/events: Implement irq distribution
Date: Sat, 12 Dec 2020 12:58:34 -0000	[thread overview]
Message-ID: <160777791448.3364.2400431156679652798.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20201210194045.457218278@linutronix.de>

The following commit has been merged into the irq/core branch of tip:

Commit-ID:     93b6adbf0420a7bd84167a4feb289cc2c1b4efca
Gitweb:        https://git.kernel.org/tip/93b6adbf0420a7bd84167a4feb289cc2c1b4efca
Author:        Thomas Gleixner <tglx@linutronix.de>
AuthorDate:    Thu, 10 Dec 2020 20:26:05 +01:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Sat, 12 Dec 2020 12:59:07 +01:00

xen/events: Implement irq distribution

Keep track of the assignments of event channels to CPUs and select the
online CPU with the least assigned channels in the affinity mask which is
handed to irq_chip::irq_set_affinity() from the core code.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Link: https://lore.kernel.org/r/20201210194045.457218278@linutronix.de

---
 drivers/xen/events/events_base.c | 76 +++++++++++++++++++++++++++----
 1 file changed, 68 insertions(+), 8 deletions(-)

diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index b352440..a803033 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -96,6 +96,7 @@ struct irq_info {
 	struct list_head eoi_list;
 	short refcnt;
 	u8 spurious_cnt;
+	u8 is_accounted;
 	enum xen_irq_type type; /* type */
 	unsigned irq;
 	evtchn_port_t evtchn;   /* event channel */
@@ -161,6 +162,9 @@ static DEFINE_PER_CPU(int [NR_VIRQS], virq_to_irq) = {[0 ... NR_VIRQS-1] = -1};
 /* IRQ <-> IPI mapping */
 static DEFINE_PER_CPU(int [XEN_NR_IPIS], ipi_to_irq) = {[0 ... XEN_NR_IPIS-1] = -1};
 
+/* Event channel distribution data */
+static atomic_t channels_on_cpu[NR_CPUS];
+
 static int **evtchn_to_irq;
 #ifdef CONFIG_X86
 static unsigned long *pirq_eoi_map;
@@ -257,6 +261,32 @@ static void set_info_for_irq(unsigned int irq, struct irq_info *info)
 		irq_set_chip_data(irq, info);
 }
 
+/* Per CPU channel accounting */
+static void channels_on_cpu_dec(struct irq_info *info)
+{
+	if (!info->is_accounted)
+		return;
+
+	info->is_accounted = 0;
+
+	if (WARN_ON_ONCE(info->cpu >= nr_cpu_ids))
+		return;
+
+	WARN_ON_ONCE(!atomic_add_unless(&channels_on_cpu[info->cpu], -1 , 0));
+}
+
+static void channels_on_cpu_inc(struct irq_info *info)
+{
+	if (WARN_ON_ONCE(info->cpu >= nr_cpu_ids))
+		return;
+
+	if (WARN_ON_ONCE(!atomic_add_unless(&channels_on_cpu[info->cpu], 1,
+					    INT_MAX)))
+		return;
+
+	info->is_accounted = 1;
+}
+
 /* Constructors for packed IRQ information. */
 static int xen_irq_info_common_setup(struct irq_info *info,
 				     unsigned irq,
@@ -339,6 +369,7 @@ static void xen_irq_info_cleanup(struct irq_info *info)
 {
 	set_evtchn_to_irq(info->evtchn, -1);
 	info->evtchn = 0;
+	channels_on_cpu_dec(info);
 }
 
 /*
@@ -449,7 +480,9 @@ static void bind_evtchn_to_cpu(evtchn_port_t evtchn, unsigned int cpu,
 
 	xen_evtchn_port_bind_to_cpu(evtchn, cpu, info->cpu);
 
+	channels_on_cpu_dec(info);
 	info->cpu = cpu;
+	channels_on_cpu_inc(info);
 }
 
 /**
@@ -622,11 +655,6 @@ static void xen_irq_init(unsigned irq)
 {
 	struct irq_info *info;
 
-#ifdef CONFIG_SMP
-	/* By default all event channels notify CPU#0. */
-	cpumask_copy(irq_get_affinity_mask(irq), cpumask_of(0));
-#endif
-
 	info = kzalloc(sizeof(*info), GFP_KERNEL);
 	if (info == NULL)
 		panic("Unable to allocate metadata for IRQ%d\n", irq);
@@ -1697,10 +1725,38 @@ static int xen_rebind_evtchn_to_cpu(evtchn_port_t evtchn, unsigned int tcpu)
 	return 0;
 }
 
+/*
+ * Find the CPU within @dest mask which has the least number of channels
+ * assigned. This is not precise as the per cpu counts can be modified
+ * concurrently.
+ */
+static unsigned int select_target_cpu(const struct cpumask *dest)
+{
+	unsigned int cpu, best_cpu = UINT_MAX, minch = UINT_MAX;
+
+	for_each_cpu_and(cpu, dest, cpu_online_mask) {
+		unsigned int curch = atomic_read(&channels_on_cpu[cpu]);
+
+		if (curch < minch) {
+			minch = curch;
+			best_cpu = cpu;
+		}
+	}
+
+	/*
+	 * Catch the unlikely case that dest contains no online CPUs. Can't
+	 * recurse.
+	 */
+	if (best_cpu == UINT_MAX)
+		return select_target_cpu(cpu_online_mask);
+
+	return best_cpu;
+}
+
 static int set_affinity_irq(struct irq_data *data, const struct cpumask *dest,
 			    bool force)
 {
-	unsigned tcpu = cpumask_first_and(dest, cpu_online_mask);
+	unsigned int tcpu = select_target_cpu(dest);
 	int ret;
 
 	ret = xen_rebind_evtchn_to_cpu(evtchn_from_irq(data->irq), tcpu);
@@ -1928,8 +1984,12 @@ void xen_irq_resume(void)
 	xen_evtchn_resume();
 
 	/* No IRQ <-> event-channel mappings. */
-	list_for_each_entry(info, &xen_irq_list_head, list)
-		info->evtchn = 0; /* zap event-channel binding */
+	list_for_each_entry(info, &xen_irq_list_head, list) {
+		/* Zap event-channel binding */
+		info->evtchn = 0;
+		/* Adjust accounting */
+		channels_on_cpu_dec(info);
+	}
 
 	clear_evtchn_to_irq_all();
 

  reply	other threads:[~2020-12-12 13:07 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-10 19:25 [patch 00/30] genirq: Treewide hunt for irq descriptor abuse and assorted fixes Thomas Gleixner
2020-12-10 19:25 ` [patch 01/30] genirq: Move irq_has_action() into core code Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 02/30] genirq: Move status flag checks to core Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-27 19:20   ` [patch 02/30] " Guenter Roeck
2021-01-11 10:14     ` Thomas Gleixner
2021-01-13 14:53     ` [tip: irq/urgent] genirq: Export irq_check_status_bit() tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 03/30] genirq: Move irq_set_lockdep_class() to core Thomas Gleixner
2020-12-11 17:53   ` Andy Shevchenko
2020-12-11 21:08     ` Thomas Gleixner
2020-12-11 22:07       ` Thomas Gleixner
2020-12-12 13:22         ` Andy Shevchenko
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 04/30] genirq: Provide irq_get_effective_affinity() Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 05/30] genirq: Annotate irq stats data races Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 06/30] parisc/irq: Simplify irq count output for /proc/interrupts Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 07/30] genirq: Make kstat_irqs() static Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 08/30] genirq: Provide kstat_irqdesc_cpu() Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 09/30] ARM: smp: Use irq_desc_kstat_cpu() in show_ipi_list() Thomas Gleixner
2020-12-11 18:08   ` Marc Zyngier
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 10/30] arm64/smp: Use irq_desc_kstat_cpu() in arch_show_interrupts() Thomas Gleixner
2020-12-11 18:08   ` Marc Zyngier
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 11/30] parisc/irq: Use irq_desc_kstat_cpu() in show_interrupts() Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 12/30] s390/irq: Use irq_desc_kstat_cpu() in show_msi_interrupt() Thomas Gleixner
2020-12-10 20:31   ` Heiko Carstens
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 13/30] drm/i915/lpe_audio: Remove pointless irq_to_desc() usage Thomas Gleixner
2020-12-10 19:48   ` [Intel-gfx] " Ville Syrjälä
2020-12-11  9:51     ` Jani Nikula
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 14/30] drm/i915/pmu: Replace open coded kstat_irqs() copy Thomas Gleixner
2020-12-11  9:54   ` Jani Nikula
2020-12-11 10:13   ` Tvrtko Ursulin
2020-12-11 12:57     ` Thomas Gleixner
2020-12-11 14:19       ` David Laight
2020-12-11 21:10         ` Thomas Gleixner
2020-12-11 22:06           ` David Laight
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 15/30] pinctrl: nomadik: Use irq_has_action() Thomas Gleixner
2020-12-12  0:45   ` Linus Walleij
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 16/30] mfd: ab8500-debugfs: Remove the racy fiddling with irq_desc Thomas Gleixner
2020-12-11  8:22   ` Linus Walleij
2020-12-11 10:04   ` Lee Jones
2020-12-11 18:12   ` Andy Shevchenko
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 17/30] NTB/msi: Use irq_has_action() Thomas Gleixner
2020-12-10 20:33   ` Logan Gunthorpe
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 18/30] PCI: xilinx-nwl: Use irq_data_get_irq_chip_data() Thomas Gleixner
2020-12-10 22:56   ` Rob Herring
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 19/30] PCI: mobiveil: " Thomas Gleixner
2020-12-10 22:56   ` Rob Herring
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:25 ` [patch 20/30] net/mlx4: Replace irq_to_desc() abuse Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-13 11:24   ` [patch 20/30] " Tariq Toukan
2020-12-10 19:25 ` [patch 21/30] net/mlx4: Use effective interrupt affinity Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-13 11:31   ` [patch 21/30] " Tariq Toukan
2020-12-10 19:25 ` [patch 22/30] net/mlx5: Replace irq_to_desc() abuse Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-13 11:34   ` [patch 22/30] " Tariq Toukan
2020-12-14 21:13   ` Saeed Mahameed
2020-12-10 19:25 ` [patch 23/30] net/mlx5: Use effective interrupt affinity Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-13 11:35   ` [patch 23/30] " Tariq Toukan
2020-12-14 20:58   ` Saeed Mahameed
2020-12-10 19:26 ` [patch 24/30] xen/events: Remove unused bind_evtchn_to_irq_lateeoi() Thomas Gleixner
2020-12-10 23:19   ` boris.ostrovsky
2020-12-11  0:04     ` Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:26 ` [patch 25/30] xen/events: Remove disfunct affinity spreading Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:26 ` [patch 26/30] xen/events: Use immediate affinity setting Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:26 ` [patch 27/30] xen/events: Only force affinity mask for percpu interrupts Thomas Gleixner
2020-12-10 23:20   ` boris.ostrovsky
2020-12-11  0:06     ` Thomas Gleixner
2020-12-11  6:17     ` Jürgen Groß
2020-12-11 10:13       ` Thomas Gleixner
2020-12-11 10:23         ` Jürgen Groß
2020-12-11 12:10     ` Jürgen Groß
2020-12-11 12:37       ` Thomas Gleixner
2020-12-11 14:29         ` boris.ostrovsky
2020-12-11 21:27           ` Thomas Gleixner
2020-12-11 22:21             ` Andrew Cooper
2020-12-11 22:56               ` Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2020-12-10 19:26 ` [patch 28/30] xen/events: Reduce irq_info::spurious_cnt storage size Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] xen/events: Reduce irq_info:: Spurious_cnt " tip-bot2 for Thomas Gleixner
2020-12-10 19:26 ` [patch 29/30] xen/events: Implement irq distribution Thomas Gleixner
2020-12-12 12:58   ` tip-bot2 for Thomas Gleixner [this message]
2020-12-10 19:26 ` [patch 30/30] genirq: Remove export of irq_to_desc() Thomas Gleixner
2020-12-12 12:58   ` [tip: irq/core] " tip-bot2 for Thomas Gleixner

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=160777791448.3364.2400431156679652798.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=boris.ostrovsky@oracle.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=sstabellini@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).