Re: [PATCH] x86/irq: Precompute nr_legacy_irqs() for performance optimization

From: Jiri Slaby

Date: Thu Nov 06 2025 - 01:44:41 EST


Hi,

On 01. 11. 25, 12:26, ray wrote:
Precompute the return value of nr_legacy_irqs() in init_ISA_irqs(),
init_IRQ(), and native_init_IRQ() functions to avoid repeated function
calls in loops, improving performance.

Changes made:
- Precompute nr_legacy_irqs() return value in three functions
- Use local variables instead of function calls in loops
- Maintain original logic unchanged

Signed-off-by: ray <veidongray@xxxxxx>

Is this how you sign legal documents?

index 6ab9eac64670..bb7cbf99f65c 100644
--- a/arch/x86/kernel/irqinit.c
+++ b/arch/x86/kernel/irqinit.c

...
@@ -66,7 +66,9 @@ void __init init_ISA_irqs(void)
legacy_pic->init(0);
- for (i = 0; i < nr_legacy_irqs(); i++) {
+ nr_legacy = nr_legacy_irqs();
+
+ for (i = 0; i < nr_legacy; i++) {

nr_legacy_irqs() is a static inline, so this was not a call per se. Instead, this resolves to 2 memory reads. Is the change worth it at all, provided these are NOT a fast path?

@@ -106,7 +112,9 @@ void __init native_init_IRQ(void)
lapic_assign_system_vectors();
- if (!acpi_ioapic && !of_ioapic && nr_legacy_irqs()) {
+ nr_legacy = nr_legacy_irqs();
+
+ if (!acpi_ioapic && !of_ioapic && nr_legacy) {

What's the added value in here at all?

thanks,
--
js
suse labs