Skip to contentSkip to conversation

r8169: Use napi_schedule_irqoff()

PATCH Superseded Matt Vollrath 2 participants 5 messages Apr 12

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 r8169: Use napi_schedule_irqoff()

napi_schedule() masks hard interrupts while doing its work, which is redundant when called from an interrupt handler where hard interrupts are already masked. Use napi_schedule_irqoff() instead to bypass this redundant masking. This is an optimization.

Tested on a Lenovo RTL8168h/8111h.

---
 drivers/net/ethernet/realtek/r8169_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/realtek/r8169_main.c +1 -1
index 791277e750ba..4c0ad0de3410 100644
@@ -4873,7 +4873,7 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
 		phy_mac_interrupt(tp->phydev);
 
 	rtl_irq_disable(tp);
-	napi_schedule(&tp->napi);
+	napi_schedule_irqoff(&tp->napi);
 out:
 	rtl_ack_events(tp, status);
 
Signature · 5 lines
2.43.0

Changes:
v2:
* CC the maintainers, make the CI board green
maintainer
#1 lore raw
Quoted 17 lines · Matt Vollrath

napi_schedule() masks hard interrupts while doing its work, which is redundant when called from an interrupt handler where hard interrupts are already masked. Use napi_schedule_irqoff() instead to bypass this redundant masking. This is an optimization.

Tested on a Lenovo RTL8168h/8111h.

---
 drivers/net/ethernet/realtek/r8169_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 791277e750ba..4c0ad0de3410 100644

drivers/net/ethernet/realtek/r8169_main.c static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) · line 4879

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -1
@@ -4873,7 +4873,7 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
 		phy_mac_interrupt(tp->phydev);
 
 	rtl_irq_disable(tp);
-	napi_schedule(&tp->napi);
+	napi_schedule_irqoff(&tp->napi);
 out:
 	rtl_ack_events(tp, status);
 

Not using napi_schedule_irqoff() here is intentional, see 2734a24e6e5d18522fbf599135c59b82ec9b2c9e.

#2 lore raw
Quoted 8 lines · Heiner Kallweit
Quoted 7 lines · Matt Vollrath
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 791277e750ba..4c0ad0de3410 100644
@@ -4873,7 +4873,7 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
  		phy_mac_interrupt(tp->phydev);
 
Quoted 9 lines

drivers/net/ethernet/realtek/r8169_main.c static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) · line 4879

Quoted 6 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -1
  	rtl_irq_disable(tp);
-	napi_schedule(&tp->napi);
+	napi_schedule_irqoff(&tp->napi);
  out:
  	rtl_ack_events(tp, status);
 

Not using napi_schedule_irqoff() here is intentional, see 2734a24e6e5d18522fbf599135c59b82ec9b2c9e.

I see, thank you Heiner. Seems like it could work if legacy interrupts went to a separate handler, but not worth the complexity for this small optimization. mv

#3 lore raw
In reply to Heiner Kallweit
Quoted 8 lines · Heiner Kallweit
Quoted 7 lines · Matt Vollrath
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 791277e750ba..4c0ad0de3410 100644
@@ -4873,7 +4873,7 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
  		phy_mac_interrupt(tp->phydev);
 
Quoted 9 lines

drivers/net/ethernet/realtek/r8169_main.c static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) · line 4879

Quoted 6 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -1
  	rtl_irq_disable(tp);
-	napi_schedule(&tp->napi);
+	napi_schedule_irqoff(&tp->napi);
  out:
  	rtl_ack_events(tp, status);
 

Not using napi_schedule_irqoff() here is intentional, see 2734a24e6e5d18522fbf599135c59b82ec9b2c9e.

It looks like forced threading was fixed after your fix to mitigate the issue of forced threading not masking interrupts.

see 81e2073c175b887398e5bca6c004efa89983f58d

If I understand correctly, this should make napi_schedule_irqoff() safe in any interrupt handler.

maintainer Reviewed-by
#4 lore raw
Quoted 18 lines · Matt Vollrath
Quoted 16 lines · Heiner Kallweit
Quoted 9 lines · Matt Vollrath
drivers/net/ethernet/realtek/r8169_main.c +1 -1
index 791277e750ba..4c0ad0de3410 100644
@@ -4873,7 +4873,7 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
           phy_mac_interrupt(tp->phydev);
         rtl_irq_disable(tp);
-    napi_schedule(&tp->napi);
+    napi_schedule_irqoff(&tp->napi);
Quoted 3 lines

  out:
      rtl_ack_events(tp, status);

Not using napi_schedule_irqoff() here is intentional, see 2734a24e6e5d18522fbf599135c59b82ec9b2c9e.

Quoted 9 lines

It looks like forced threading was fixed after your fix to mitigate the issue of forced threading not masking interrupts.

see 81e2073c175b887398e5bca6c004efa89983f58d

If I understand correctly, this should make napi_schedule_irqoff() safe in any interrupt handler.

I think 8380c81d5c4fced6f4397795a5ae65758272bbfd needs to be mentioned too, because only with this change your patch is safe under PREEMPT_RT. Best extend the commit message based on our discussion. With that one: