MIPS: SGI-IP27: micro-optimize arch_init_irq()
cover MIPS: SGI-IP27: micro-optimize arch_init_irq()
A couple of cleanups for arch_init_irq()
This is a follow-up for [1].
Here:
- drop unused 'i' variable, as reported by kernel robot [2];
- fix typos in commit message;
- add 2nd patch to handle WARN_ON() better.
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/oe-kbuild-all/[email protected]/
Yury Norov (2):
MIPS: SGI-IP27: micro-optimize arch_init_irq()
MIPS: SGI-IP27: use WARN_ON() output
arch/mips/sgi-ip27/ip27-irq.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
Signature · 1 line
2.40.1
PATCH v2 1/2 MIPS: SGI-IP27: micro-optimize arch_init_irq()
The function sets adjusted groups of bits in hub_irq_map by using for-loops. There's a bitmap_set() function dedicated to do this.
Because [0, CPU_CALL_B_IRQ] and [NI_BRDCAST_ERR_A, MSC_PANIC_INTR] ranges belong to the same machine word, bitmap_set() would boil down to an inline wrapper in both cases, avoiding generating a loop, with the associate overhead. Effectively, it would be a compile-time:
*hub_irq_map = GENMASK() | GENMASK();
--- arch/mips/sgi-ip27/ip27-irq.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
arch/mips/sgi-ip27/ip27-irq.c +2 -6
@@ -277,7 +277,6 @@ void __init arch_init_irq(void) {struct irq_domain *domain;struct fwnode_handle *fn; -int i;mips_cpu_irq_init ();
@@ -286,11 +285,8 @@ void __init arch_init_irq(void)* Mark these as reserved right away so they won't be used accidentally * later. */ -for (i =0 ; i <=CPU_CALL_B_IRQ ; i++) -set_bit (i, hub_irq_map); - -for (i =NI_BRDCAST_ERR_A ; i <=MSC_PANIC_INTR ; i++) -set_bit (i, hub_irq_map); +bitmap_set (hub_irq_map,0 ,CPU_CALL_B_IRQ +1 ); +bitmap_set (hub_irq_map,NI_BRDCAST_ERR_A ,MSC_PANIC_INTR -NI_BRDCAST_ERR_A +1 ); fn =irq_domain_alloc_named_fwnode ("HUB" );WARN_ON (fn ==NULL );
Signature · 1 line
2.40.1
Thomas Bogendoerfer
maintainerQuoted 20 lines · Yury Norov
The function sets adjusted groups of bits in
hub_irq_mapby using for-loops. There's abitmap_set()function dedicated to do this.Because [0,
CPU_CALL_B_IRQ] and [NI_BRDCAST_ERR_A,MSC_PANIC_INTR] ranges belong to the same machine word,bitmap_set()would boil down to an inline wrapper in both cases, avoiding generating a loop, with the associate overhead. Effectively, it would be a compile-time:*hub_irq_map = GENMASK() | GENMASK();Signed-off-by Yury Norov <[email protected]>--- arch/mips/sgi-ip27/ip27-irq.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)arch/mips/sgi-ip27/ip27-irq.c +0
-0
arch/mips/sgi-ip27/ip27-irq.c void __init arch_init_irq(void) · line 280
Quoted 4 lines
arch/mips/sgi-ip27/ip27-irq.c +0
-1@@ -277,7 +277,6 @@ void __init arch_init_irq(void) {struct irq_domain *domain;struct fwnode_handle *fn; -int i;
I've already applied your first version, so I need an incremental patch, which just removes the unused variable.
Thomas.
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]
Quoted 16 lines · Thomas Bogendoerfer
Quoted 15 lines · Yury Norov
The function sets adjusted groups of bits in
hub_irq_mapby using for-loops. There's abitmap_set()function dedicated to do this.Because [0,
CPU_CALL_B_IRQ] and [NI_BRDCAST_ERR_A,MSC_PANIC_INTR] ranges belong to the same machine word,bitmap_set()would boil down to an inline wrapper in both cases, avoiding generating a loop, with the associate overhead. Effectively, it would be a compile-time:*hub_irq_map = GENMASK() | GENMASK();Signed-off-by Yury Norov <[email protected]>--- arch/mips/sgi-ip27/ip27-irq.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
Quoted 12 lines
arch/mips/sgi-ip27/ip27-irq.c void __init arch_init_irq(void) · line 280
Quoted 9 lines
arch/mips/sgi-ip27/ip27-irq.c +0
-1@@ -277,7 +277,6 @@ void __init arch_init_irq(void) {struct irq_domain *domain;struct fwnode_handle *fn; -int i;I've already applied your first version, so I need an incremental patch, which just removes the unused variable.
Sure, please find below.
From ce447fe69092c48bb59a6c4cb08ee5f9080f0ad6 Mon Sep 17 00:00:00 2001
From: Yury Norov <[email protected]>
Date: Mon, 22 Apr 2024 15:52:12 -0700
Subject: [PATCH] MIPS: SGI-IP27: fix -Wunused-variable in arch_init_irq()
Commit 40e20fbccfb722f21 (MIPS: SGI-IP27: micro-optimize arch_init_irq()) replaced a for-loop iteration with bitmap_set() calls, but didn't remove an iteration variable.
--- arch/mips/sgi-ip27/ip27-irq.c | 1 - 1 file changed, 1 deletion(-)
arch/mips/sgi-ip27/ip27-irq.c +0 -1
@@ -277,7 +277,6 @@ void __init arch_init_irq(void) {struct irq_domain *domain;struct fwnode_handle *fn; -int i;mips_cpu_irq_init ();
Signature · 1 line
2.40.1
Quoted 63 lines · Yury Norov
Quoted 16 lines · Thomas Bogendoerfer
Quoted 15 lines · Yury Norov
The function sets adjusted groups of bits in
hub_irq_mapby using for-loops. There's abitmap_set()function dedicated to do this.Because [0,
CPU_CALL_B_IRQ] and [NI_BRDCAST_ERR_A,MSC_PANIC_INTR] ranges belong to the same machine word,bitmap_set()would boil down to an inline wrapper in both cases, avoiding generating a loop, with the associate overhead. Effectively, it would be a compile-time:*hub_irq_map = GENMASK() | GENMASK();Signed-off-by Yury Norov <[email protected]>--- arch/mips/sgi-ip27/ip27-irq.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)Quoted 12 lines
arch/mips/sgi-ip27/ip27-irq.c void __init arch_init_irq(void) · line 280
Quoted 9 lines
arch/mips/sgi-ip27/ip27-irq.c +0
-1@@ -277,7 +277,6 @@ void __init arch_init_irq(void) {struct irq_domain *domain;struct fwnode_handle *fn; -int i;I've already applied your first version, so I need an incremental patch, which just removes the unused variable.
Sure, please find below.
Quoted 1 line
From
ce447fe69092c48bb59a6c4cb08ee5f9080f0ad6Mon Sep 17 00:00:00 2001From: Yury Norov <[email protected]>
Date: Mon, 22 Apr 2024 15:52:12 -0700
Subject: [PATCH] MIPS: SGI-IP27: fix -Wunused-variable inarch_init_irq()Commit
40e20fbccfb722f21(MIPS: SGI-IP27: micro-optimizearch_init_irq()) replaced a for-loop iteration withbitmap_set()calls, but didn't remove an iteration variable.Fixes 40e20fbccfb722f21 (MIPS: SGI-IP27: micro-optimize arch_init_irq())Reported-by kernel test robot <[email protected]>Signed-off-by Yury Norov <[email protected]>--- arch/mips/sgi-ip27/ip27-irq.c | 1 - 1 file changed, 1 deletion(-)arch/mips/sgi-ip27/ip27-irq.c +0
-1@@ -277,7 +277,6 @@ void __init arch_init_irq(void) {struct irq_domain *domain;struct fwnode_handle *fn; -int i;mips_cpu_irq_init ();Signature · 1 line
2.40.1
applied to mips-next.
Thomas.
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]
PATCH 2/2 MIPS: SGI-IP27: use WARN_ON() output
In reply to Yury NorovWARN_ON() propagates the result of conditional expression, and it can be used to return early in the following expression in the arch_init_irq().
This is a no-op cleanup, except that compiler may optimize the error paths better because WARN_ON() implies 'unlikely()'.
--- arch/mips/sgi-ip27/ip27-irq.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
arch/mips/sgi-ip27/ip27-irq.c +3 -4
@@ -289,13 +289,12 @@ void __init arch_init_irq(void)bitmap_set (hub_irq_map,NI_BRDCAST_ERR_A ,MSC_PANIC_INTR -NI_BRDCAST_ERR_A +1 ); fn =irq_domain_alloc_named_fwnode ("HUB" ); -WARN_ON (fn ==NULL ); -if (!fn) +if (WARN_ON (fn ==NULL ))return ; + domain =irq_domain_create_linear (fn,IP27_HUB_IRQ_COUNT , &hub_domain_ops,NULL ); -WARN_ON (domain ==NULL ); -if (!domain) +if (WARN_ON (domain ==NULL ))return ;irq_set_default_host (domain);
Signature · 1 line
2.40.1
Re: [PATCH 2/2] MIPS: SGI-IP27: use WARN_ON() output
Quoted 34 lines · Yury Norov
WARN_ON()propagates the result of conditional expression, and it can be used to return early in the following expression in thearch_init_irq().This is a no-op cleanup, except that compiler may optimize the error paths better because
WARN_ON()implies 'unlikely()'.Signed-off-by Yury Norov <[email protected]>--- arch/mips/sgi-ip27/ip27-irq.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)arch/mips/sgi-ip27/ip27-irq.c +3
-4@@ -289,13 +289,12 @@ void __init arch_init_irq(void)bitmap_set (hub_irq_map,NI_BRDCAST_ERR_A ,MSC_PANIC_INTR -NI_BRDCAST_ERR_A +1 ); fn =irq_domain_alloc_named_fwnode ("HUB" ); -WARN_ON (fn ==NULL ); -if (!fn) +if (WARN_ON (fn ==NULL ))return ; + domain =irq_domain_create_linear (fn,IP27_HUB_IRQ_COUNT , &hub_domain_ops,NULL ); -WARN_ON (domain ==NULL ); -if (!domain) +if (WARN_ON (domain ==NULL ))return ;irq_set_default_host (domain);Signature · 1 line
2.40.1
applied to mips-next.
Thomas.
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]