Skip to contentSkip to conversation

sparc64: Avoid irqsave/restore on vio.lock if in_softirq()

PATCH Superseded Sowmini Varadhan 3 participants 6 messages Oct 21, 2014 – Oct 22, 2014

Subsystems (3)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 3/4 sparc64: Avoid irqsave/restore on vio.lock if in_softirq()

For NAPIfied drivers , there is no need to synchronize by doing irqsave/restore on vio.lock in the I/O path.

---
 arch/sparc/kernel/viohs.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/sparc/kernel/viohs.c +5 -3
index 7ef081a..d731586 100644
@@ -747,10 +747,11 @@ EXPORT_SYMBOL(vio_ldc_free);
 
 void vio_port_up(struct vio_driver_state *vio)
 {
-	unsigned long flags;
+	unsigned long flags = 0;
 	int err, state;
 
-	spin_lock_irqsave(&vio->lock, flags);
+	if (!in_softirq())
+		spin_lock_irqsave(&vio->lock, flags);
 
 	state = ldc_state(vio->lp);
 
@@ -777,7 +778,8 @@ void vio_port_up(struct vio_driver_state *vio)
 		mod_timer(&vio->timer, expires);
 	}
 
-	spin_unlock_irqrestore(&vio->lock, flags);
+	if (!in_softirq())
+		spin_unlock_irqrestore(&vio->lock, flags);
 }
 EXPORT_SYMBOL(vio_port_up);
 
Signature · 1 line
1.8.4.2
#1 lore raw

Hi Sowmini,

Quoted 14 lines · Sowmini Varadhan

For NAPIfied drivers , there is no need to synchronize by doing irqsave/restore on vio.lock in the I/O path.

---
 arch/sparc/kernel/viohs.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/sparc/kernel/viohs.c +0 -0
index 7ef081a..d731586 100644

arch/sparc/kernel/viohs.c EXPORT_SYMBOL(vio_ldc_free); · line 750

Quoted 5 lines
arch/sparc/kernel/viohs.c +1 -1
@@ -747,10 +747,11 @@ EXPORT_SYMBOL(vio_ldc_free);
 
 void vio_port_up(struct vio_driver_state *vio)
 {
-       unsigned long flags;
+       unsigned long flags = 0;

Is gcc not smart enough to know that this variable isn't used before it's set? (I assume it isn't used elsewhere in this function)

Quoted 9 lines
arch/sparc/kernel/viohs.c +2 -1
        int err, state;
 
-       spin_lock_irqsave(&vio->lock, flags);
+       if (!in_softirq())
+               spin_lock_irqsave(&vio->lock, flags);
 
        state = ldc_state(vio->lp);
 

arch/sparc/kernel/viohs.c void vio_port_up(struct vio_driver_state *vio) · line 784

Quoted 8 lines
arch/sparc/kernel/viohs.c +2 -1
@@ -777,7 +778,8 @@ void vio_port_up(struct vio_driver_state *vio)
                mod_timer(&vio->timer, expires);
        }
 
-       spin_unlock_irqrestore(&vio->lock, flags);
+       if (!in_softirq())
+               spin_unlock_irqrestore(&vio->lock, flags);
 }
 EXPORT_SYMBOL(vio_port_up);

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#2 lore raw
Quoted 7 lines · Julian Calaby

arch/sparc/kernel/viohs.c EXPORT_SYMBOL(vio_ldc_free); · line 750

Quoted 4 lines

void vio_port_up(struct vio_driver_state *vio)
{

arch/sparc/kernel/viohs.c +1 -1
-       unsigned long flags;
+       unsigned long flags = 0;

Is gcc not smart enough to know that this variable isn't used before it's set? (I assume it isn't used elsewhere in this function)

No, it's not used elsewhere in the function, and yes, I too was surprised by the build warning, which is why I initialized it as above.

--Sowmini

#3 lore raw

Hi Sowmini,

Quoted 6 lines · Sowmini Varadhan
Quoted 5 lines · Julian Calaby
Quoted 4 lines

void vio_port_up(struct vio_driver_state *vio)
{

arch/sparc/kernel/viohs.c +1 -1
-       unsigned long flags;
+       unsigned long flags = 0;
Quoted 6 lines
Quoted 2 lines

Is gcc not smart enough to know that this variable isn't used before it's set? (I assume it isn't used elsewhere in this function)

No, it's not used elsewhere in the function, and yes, I too was surprised by the build warning, which is why I initialized it as above.

Ok, fair enough then.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#4 lore raw
In reply to Julian Calaby
Quoted 19 lines · Julian Calaby

Hi Sowmini,

Quoted 15 lines · Sowmini Varadhan

For NAPIfied drivers , there is no need to synchronize by doing irqsave/restore on vio.lock in the I/O path.

---
 arch/sparc/kernel/viohs.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/sparc/kernel/viohs.c +0 -0
index 7ef081a..d731586 100644
@@ -747,10 +747,11 @@ EXPORT_SYMBOL(vio_ldc_free);
 
Quoted 7 lines

arch/sparc/kernel/viohs.c EXPORT_SYMBOL(vio_ldc_free); · line 750

Quoted 4 lines
arch/sparc/kernel/viohs.c +1 -1
 void vio_port_up(struct vio_driver_state *vio)
 {
-       unsigned long flags;
+       unsigned long flags = 0;

Is gcc not smart enough to know that this variable isn't used before it's set? (I assume it isn't used elsewhere in this function)

It probably assumes in_softirq() might evaluate differently in the each case.

Quoted 21 lines
Quoted 10 lines
arch/sparc/kernel/viohs.c +2 -1
        int err, state;
 
-       spin_lock_irqsave(&vio->lock, flags);
+       if (!in_softirq())
+               spin_lock_irqsave(&vio->lock, flags);
 
        state = ldc_state(vio->lp);
 

arch/sparc/kernel/viohs.c void vio_port_up(struct vio_driver_state *vio) · line 784

Quoted 8 lines
arch/sparc/kernel/viohs.c +2 -1
@@ -777,7 +778,8 @@ void vio_port_up(struct vio_driver_state *vio)
                mod_timer(&vio->timer, expires);
        }
 
-       spin_unlock_irqrestore(&vio->lock, flags);
+       if (!in_softirq())
+               spin_unlock_irqrestore(&vio->lock, flags);
 }
 EXPORT_SYMBOL(vio_port_up);

Thanks,

#5 lore raw
Quoted 6 lines · Dave Kleikamp
Quoted 3 lines

Is gcc not smart enough to know that this variable isn't used before it's set? (I assume it isn't used elsewhere in this function)

It probably assumes in_softirq() might evaluate differently in the each case.

yes, that's what I suspected too. I suppose it is possible from the compiler's point of view that something in between might change the result of in_softirq() so that we may be using an uninit variable in the second call.

anyway, the warning was annoying, and would only numb the user into ignoring other real issues, so I figured I might as well silence the warning.

--Sowmini