Skip to contentSkip to conversation

thermal: replace spin_lock_irqsave by spin_lock in hard IRQ

PATCH In review Tian Tao 5 participants 5 messages Oct 21, 2020 – Oct 26, 2020

Subsystems (2)
lore
Share & tools
lore

Tian Tao

author
#0 lore raw

PATCH 1/1 thermal: replace spin_lock_irqsave by spin_lock in hard IRQ

The code has been in a irq-disabled context since it is hard IRQ. There is no necessity to do it again.

---
 drivers/thermal/rcar_thermal.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/thermal/rcar_thermal.c +2 -3
index 5c2a13b..6ae757d 100644
@@ -409,16 +409,15 @@ static irqreturn_t rcar_thermal_irq(int irq, void *data)
 {
 	struct rcar_thermal_common *common = data;
 	struct rcar_thermal_priv *priv;
-	unsigned long flags;
 	u32 status, mask;
 
-	spin_lock_irqsave(&common->lock, flags);
+	spin_lock(&common->lock);
 
 	mask	= rcar_thermal_common_read(common, INTMSK);
 	status	= rcar_thermal_common_read(common, STR);
 	rcar_thermal_common_write(common, STR, 0x000F0F0F & mask);
 
-	spin_unlock_irqrestore(&common->lock, flags);
+	spin_unlock(&common->lock);
 
 	status = status & ~mask;
 
Signature · 1 line
2.7.4
Tested-by on v1 1/1
#1 lore raw

Hi Tian,

Thanks for your work.

Quoted 4 lines · Tian Tao

The code has been in a irq-disabled context since it is hard IRQ. There is no necessity to do it again.

Quoted 30 lines
---
 drivers/thermal/rcar_thermal.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/thermal/rcar_thermal.c +2 -3
index 5c2a13b..6ae757d 100644
@@ -409,16 +409,15 @@ static irqreturn_t rcar_thermal_irq(int irq, void *data)
 {
 	struct rcar_thermal_common *common = data;
 	struct rcar_thermal_priv *priv;
-	unsigned long flags;
 	u32 status, mask;
 
-	spin_lock_irqsave(&common->lock, flags);
+	spin_lock(&common->lock);
 
 	mask	= rcar_thermal_common_read(common, INTMSK);
 	status	= rcar_thermal_common_read(common, STR);
 	rcar_thermal_common_write(common, STR, 0x000F0F0F & mask);
 
-	spin_unlock_irqrestore(&common->lock, flags);
+	spin_unlock(&common->lock);
 
 	status = status & ~mask;
 
Signature · 1 line
2.7.4
Signature · 2 lines
Regards,
Niklas Söderlund
#2 lore raw
In reply to Tian Tao

Hi Tian,

CC tglx

Quoted 4 lines · Tian Tao

The code has been in a irq-disabled context since it is hard IRQ. There is no necessity to do it again.

Thanks for your patch!

Is this also true if CONFIG_PREEMPT_RT=y, and all irq handlers execute in the context of special tasks?

Quoted 10 lines
drivers/thermal/rcar_thermal.c +0 -2
@@ -409,16 +409,15 @@ static irqreturn_t rcar_thermal_irq(int irq, void *data)
 {
        struct rcar_thermal_common *common = data;
        struct rcar_thermal_priv *priv;
-       unsigned long flags;
        u32 status, mask;
 
-       spin_lock_irqsave(&common->lock, flags);

drivers/thermal/rcar_thermal.c static irqreturn_t rcar_thermal_irq(int irq, void *data) · line 422

Quoted 10 lines
drivers/thermal/rcar_thermal.c +2 -1
+       spin_lock(&common->lock);
 
        mask    = rcar_thermal_common_read(common, INTMSK);
        status  = rcar_thermal_common_read(common, STR);
        rcar_thermal_common_write(common, STR, 0x000F0F0F & mask);
 
-       spin_unlock_irqrestore(&common->lock, flags);
+       spin_unlock(&common->lock);
 
        status = status & ~mask;

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#3 lore raw
Quoted 6 lines · Geert Uytterhoeven
Quoted 3 lines · Tian Tao

The code has been in a irq-disabled context since it is hard IRQ. There is no necessity to do it again.

Is this also true if CONFIG_PREEMPT_RT=y, and all irq handlers execute in the context of special tasks?

On RT or even on mainline with 'threadirqs' on the command line all interrupts which are not explicitly requested with IRQF_NO_THREAD run their handlers in thread context. The same applies to soft interrupts.

That means they are subject to the normal scheduler rules and no other code is going to acquire that lock from hard interrupt context either, so the irqsave() here is pointless in all cases.

Famous last words...

... unless the driver does magic things like having a hrtimer armed which expires in hard interrupt context and touches the very same lock, but that's not the case in this particular driver.

So the change itself is correct, but the change log could do with some polishing. :)

Thanks,

tglx

#4 lore raw
In reply to Tian Tao
Quoted 5 lines · Tian Tao

The code has been in a irq-disabled context since it is hard IRQ. There is no necessity to do it again.

---

Whe resending with the log improved, please fix the subject:

thermal: rcar: Replace ...

Thanks

-- Daniel

Quoted 27 lines
 drivers/thermal/rcar_thermal.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/thermal/rcar_thermal.c +2 -3
index 5c2a13b..6ae757d 100644
@@ -409,16 +409,15 @@ static irqreturn_t rcar_thermal_irq(int irq, void *data)
 {
 	struct rcar_thermal_common *common = data;
 	struct rcar_thermal_priv *priv;
-	unsigned long flags;
 	u32 status, mask;
 
-	spin_lock_irqsave(&common->lock, flags);
+	spin_lock(&common->lock);
 
 	mask	= rcar_thermal_common_read(common, INTMSK);
 	status	= rcar_thermal_common_read(common, STR);
 	rcar_thermal_common_write(common, STR, 0x000F0F0F & mask);
 
-	spin_unlock_irqrestore(&common->lock, flags);
+	spin_unlock(&common->lock);
 
 	status = status & ~mask;
 
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog