mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Russell King <linux@armlinux.org.uk>,
	linux-kernel@vger.kernel.org,
	Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH v2 21/22] genirq: Switch to irq_get_nr_irqs()
Date: Tue,  8 Oct 2024 13:26:00 -0700	[thread overview]
Message-ID: <20241008202601.3737326-22-bvanassche@acm.org> (raw)
In-Reply-To: <20241008202601.3737326-1-bvanassche@acm.org>

Use the irq_get_nr_irqs() function instead of the global variable
'nr_irqs'. Cache the result of this function in a local variable in
order not to rely on CSE (common subexpression elimination). This patch
prepares for changing 'nr_irqs' from an exported global variable into a
variable with file scope.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 include/linux/irqnr.h  | 33 +++++++++++++++++++--------------
 kernel/irq/irqdomain.c |  2 +-
 kernel/irq/proc.c      |  3 ++-
 3 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/include/linux/irqnr.h b/include/linux/irqnr.h
index 7419b807b71b..a33088d27c54 100644
--- a/include/linux/irqnr.h
+++ b/include/linux/irqnr.h
@@ -11,26 +11,31 @@ unsigned int irq_set_nr_irqs(unsigned int nr);
 extern struct irq_desc *irq_to_desc(unsigned int irq);
 unsigned int irq_get_next_irq(unsigned int offset);
 
-# define for_each_irq_desc(irq, desc)					\
-	for (irq = 0, desc = irq_to_desc(irq); irq < nr_irqs;		\
-	     irq++, desc = irq_to_desc(irq))				\
-		if (!desc)						\
-			;						\
-		else
-
+#define for_each_irq_desc(irq, desc)                                      \
+	for (unsigned int __nr_irqs__ = irq_get_nr_irqs(); __nr_irqs__;   \
+	     __nr_irqs__ = 0)                                             \
+		for (irq = 0, desc = irq_to_desc(irq); irq < __nr_irqs__; \
+		     irq++, desc = irq_to_desc(irq))                      \
+			if (!desc)                                        \
+				;                                         \
+			else
 
 # define for_each_irq_desc_reverse(irq, desc)				\
-	for (irq = nr_irqs - 1, desc = irq_to_desc(irq); irq >= 0;	\
-	     irq--, desc = irq_to_desc(irq))				\
+	for (irq = irq_get_nr_irqs() - 1, desc = irq_to_desc(irq);	\
+	     irq >= 0; irq--, desc = irq_to_desc(irq))			\
 		if (!desc)						\
 			;						\
 		else
 
-# define for_each_active_irq(irq)			\
-	for (irq = irq_get_next_irq(0); irq < nr_irqs;	\
-	     irq = irq_get_next_irq(irq + 1))
+#define for_each_active_irq(irq)                                        \
+	for (unsigned int __nr_irqs__ = irq_get_nr_irqs(); __nr_irqs__; \
+	     __nr_irqs__ = 0)                                           \
+		for (irq = irq_get_next_irq(0); irq < __nr_irqs__;      \
+		     irq = irq_get_next_irq(irq + 1))
 
-#define for_each_irq_nr(irq)                   \
-       for (irq = 0; irq < nr_irqs; irq++)
+#define for_each_irq_nr(irq)                                            \
+	for (unsigned int __nr_irqs__ = irq_get_nr_irqs(); __nr_irqs__; \
+	     __nr_irqs__ = 0)                                           \
+		for (irq = 0; irq < __nr_irqs__; irq++)
 
 #endif
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index e0bff21f30e0..ec6d8e72d980 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -1225,7 +1225,7 @@ int irq_domain_alloc_descs(int virq, unsigned int cnt, irq_hw_number_t hwirq,
 		virq = __irq_alloc_descs(virq, virq, cnt, node, THIS_MODULE,
 					 affinity);
 	} else {
-		hint = hwirq % nr_irqs;
+		hint = hwirq % irq_get_nr_irqs();
 		if (hint == 0)
 			hint++;
 		virq = __irq_alloc_descs(-1, hint, cnt, node, THIS_MODULE,
diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c
index 9081ada81c3d..d226282c5b66 100644
--- a/kernel/irq/proc.c
+++ b/kernel/irq/proc.c
@@ -457,11 +457,12 @@ int __weak arch_show_interrupts(struct seq_file *p, int prec)
 }
 
 #ifndef ACTUAL_NR_IRQS
-# define ACTUAL_NR_IRQS nr_irqs
+# define ACTUAL_NR_IRQS irq_get_nr_irqs()
 #endif
 
 int show_interrupts(struct seq_file *p, void *v)
 {
+	const unsigned int nr_irqs = irq_get_nr_irqs();
 	static int prec;
 
 	int i = *(loff_t *) v, j;

  parent reply	other threads:[~2024-10-08 20:26 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08 20:25 [PATCH v2 00/21] Reduce the scope of 'nr_irqs' Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 01/22] genirq: Introduce irq_get_nr_irqs() and irq_set_nr_irqs() Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 02/22] ARM: Switch to irq_get_nr_irqs() / irq_set_nr_irqs() Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 03/22] LoongArch: Switch to irq_set_nr_irqs() Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 04/22] powerpc/cell: Switch to irq_get_nr_irqs() Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 05/22] s390/irq: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 06/22] x86/acpi: Switch to irq_get_nr_irqs() and irq_set_nr_irqs() Bart Van Assche
2024-10-09  9:07   ` Thomas Gleixner
2024-10-08 20:25 ` [PATCH v2 07/22] hpet: Switch to irq_get_nr_irqs() Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 08/22] net: 3com: 3c59x: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 09/22] net: hamradio: baycom_ser_fdx: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 10/22] net: hamradio: scc: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 11/22] scsi: aha152x: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 12/22] serial: core: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 13/22] serial: 8250: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 14/22] serial: amba-pl010: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 15/22] serial: amba-pl011: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 16/22] serial: cpm_uart: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 17/22] serial: ucc_uart: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 18/22] sh: intc: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 19/22] xen/events: " Bart Van Assche
2024-10-08 20:25 ` [PATCH v2 20/22] fs/procfs: " Bart Van Assche
2024-10-08 20:26 ` Bart Van Assche [this message]
2024-10-08 20:26 ` [PATCH v2 22/22] genirq: Unexport nr_irqs Bart Van Assche

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=20241008202601.3737326-22-bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --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®