thermal: rcar_gen3_thermal: fix IRQ issues
Subsystems (2)
v3 cover thermal: rcar_gen3_thermal: fix IRQ issues
There are issues with interrupt handling in rcar_gen3_thermal driver.
Currently IRQ is remain enabled after .remove, later if device is probed, IRQ is requested before .thermal_init, this may cause IRQ function be triggered but not able to clear IRQ status, thus cause system to hang.
Since the irq line isn't shared between different devices, so the proper interrupt type flag should be IRQF_ONESHOT.
This patch-set fix these interrupt handling retated issues.
---
v3: fix to use correct code base
remove unused "flag" variable in rcar_gen3_thermal_irq
v2: use irq type IRQF_ONESHOT instead of IRQF_SHARED
disable interrupt in .remove
v1: initial version
Jiada Wang (2):
thermal: rcar_gen3_thermal: fix interrupt type
thermal: rcar_gen3_thermal: disable interrupt in .remove
Jiada Wang (2):
thermal: rcar_gen3_thermal: fix interrupt type
thermal: rcar_gen3_thermal: disable interrupt in .remove
drivers/thermal/rcar_gen3_thermal.c | 37 +++++++---------------------- 1 file changed, 9 insertions(+), 28 deletions(-)
Signature · 1 line
2.19.2
PATCH v3 1/2 thermal: rcar_gen3_thermal: fix interrupt type
Currently IRQF_SHARED type interrupt line is allocated, but it is not appropriate, as the interrupt line isn't shared between different devices, instead IRQF_ONESHOT is the proper type.
By changing interrupt type to IRQF_ONESHOT, now irq handler is no longer needed, as clear of interrupt status can be done in threaded interrupt context.
Because IRQF_ONESHOT type interrupt line is kept disabled until the threaded handler has been run, so there is no need to protect read/write of REG_GEN3_IRQSTR with lock.
--- drivers/thermal/rcar_gen3_thermal.c | 34 +++++------------------------ 1 file changed, 6 insertions(+), 28 deletions(-)
drivers/thermal/rcar_gen3_thermal.c +6 -28
@@ -231,39 +231,17 @@ static void rcar_thermal_irq_set(struct rcar_gen3_thermal_priv *priv, bool on)static irqreturn_t rcar_gen3_thermal_irq (int irq,void *data) {struct rcar_gen3_thermal_priv *priv = data; +int i;u32 status; -int i, ret =IRQ_HANDLED ; -spin_lock (&priv->lock);for (i =0 ; i < priv->num_tscs; i++) { status =rcar_gen3_thermal_read (priv->tscs[i],REG_GEN3_IRQSTR );rcar_gen3_thermal_write (priv->tscs[i],REG_GEN3_IRQSTR ,0 );if (status) - ret =IRQ_WAKE_THREAD ; +thermal_zone_device_update (priv->tscs[i]->zone, +THERMAL_EVENT_UNSPECIFIED ); } -if (ret ==IRQ_WAKE_THREAD ) -rcar_thermal_irq_set (priv, false); - -spin_unlock (&priv->lock); - -return ret; -} - -static irqreturn_t rcar_gen3_thermal_irq_thread (int irq,void *data) -{ -struct rcar_gen3_thermal_priv *priv = data; -unsigned long flags; -int i; - -for (i =0 ; i < priv->num_tscs; i++) -thermal_zone_device_update (priv->tscs[i]->zone, -THERMAL_EVENT_UNSPECIFIED ); - -spin_lock_irqsave (&priv->lock, flags); -rcar_thermal_irq_set (priv, true); -spin_unlock_irqrestore (&priv->lock, flags); -return IRQ_HANDLED ; }
@@ -390,9 +368,9 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)if (!irqname)return -ENOMEM ; - ret =devm_request_threaded_irq (dev, irq, rcar_gen3_thermal_irq, - rcar_gen3_thermal_irq_thread, -IRQF_SHARED , irqname, priv); + ret =devm_request_threaded_irq (dev, irq,NULL , + rcar_gen3_thermal_irq, +IRQF_ONESHOT , irqname, priv);if (ret)return ret; }
Signature · 1 line
2.19.2
Re: [PATCH v3 1/2] thermal: rcar_gen3_thermal: fix interrupt type
Hi Jiada,
Quoted 22 lines · Jiada Wang
Currently
IRQF_SHAREDtype interrupt line is allocated, but it is not appropriate, as the interrupt line isn't shared between different devices, insteadIRQF_ONESHOTis the proper type.By changing interrupt type to
IRQF_ONESHOT, now irq handler is no longer needed, as clear of interrupt status can be done in threaded interrupt context.Because
IRQF_ONESHOTtype interrupt line is kept disabled until the threaded handler has been run, so there is no need to protect read/write ofREG_GEN3_IRQSTRwith lock.Signed-off-by Jiada Wang <[email protected]>--- drivers/thermal/rcar_gen3_thermal.c | 34 +++++------------------------ 1 file changed, 6 insertions(+), 28 deletions(-)drivers/thermal/rcar_gen3_thermal.c +0
-0
drivers/thermal/rcar_gen3_thermal.c static void rcar_thermal_irq_set(struct rcar_gen3_thermal_priv *priv, bool on) · line 235
Quoted 6 lines
drivers/thermal/rcar_gen3_thermal.c +1
-1@@ -231,39 +231,17 @@ static void rcar_thermal_irq_set(struct rcar_gen3_thermal_priv *priv, bool on)static irqreturn_t rcar_gen3_thermal_irq (int irq,void *data) {struct rcar_gen3_thermal_priv *priv = data; +int i;u32 status; -int i, ret =IRQ_HANDLED ;
nit: why not keeping 'int i' on the same line?
Quoted 2 lines
drivers/thermal/rcar_gen3_thermal.c +0
-1-spin_lock (&priv->lock);
[..]
Quoted 1 line
drivers/thermal/rcar_gen3_thermal.c +0
-1-spin_unlock (&priv->lock);
[..]
Quoted 1 line
drivers/thermal/rcar_gen3_thermal.c +0
-1-spin_lock_irqsave (&priv->lock, flags);
[..]
drivers/thermal/rcar_gen3_thermal.c static void rcar_thermal_irq_set(struct rcar_gen3_thermal_priv *priv, bool on) · line 265
Quoted 1 line
drivers/thermal/rcar_gen3_thermal.c +0
-1-spin_unlock_irqrestore (&priv->lock, flags);
[..]
FWIW, after applying the patch, the 'spinlock_t lock' member of 'struct rcar_gen3_thermal_priv' is no longer used in the driver, except to initialize it in probe. Is there any usage expected in future or should it be zapped?
Signature · 2 lines
Best regards, Eugeniu.
Re: [PATCH v3 1/2] thermal: rcar_gen3_thermal: fix interrupt type
In reply to Jiada WangQuoted 8 lines · Jiada Wang
Currently
IRQF_SHAREDtype interrupt line is allocated, but it is not appropriate, as the interrupt line isn't shared between different devices, insteadIRQF_ONESHOTis the proper type.By changing interrupt type to
IRQF_ONESHOT, now irq handler is no longer needed, as clear of interrupt status can be done in threaded interrupt context.
Quoted 5 lines
Because
IRQF_ONESHOTtype interrupt line is kept disabled until the threaded handler has been run, so there is no need to protect read/write ofREG_GEN3_IRQSTRwith lock.Signed-off-by Jiada Wang <[email protected]>
Quoted 65 lines
--- drivers/thermal/rcar_gen3_thermal.c | 34 +++++------------------------ 1 file changed, 6 insertions(+), 28 deletions(-)drivers/thermal/rcar_gen3_thermal.c +6
-28@@ -231,39 +231,17 @@ static void rcar_thermal_irq_set(struct rcar_gen3_thermal_priv *priv, bool on)static irqreturn_t rcar_gen3_thermal_irq (int irq,void *data) {struct rcar_gen3_thermal_priv *priv = data; +int i;u32 status; -int i, ret =IRQ_HANDLED ; -spin_lock (&priv->lock);for (i =0 ; i < priv->num_tscs; i++) { status =rcar_gen3_thermal_read (priv->tscs[i],REG_GEN3_IRQSTR );rcar_gen3_thermal_write (priv->tscs[i],REG_GEN3_IRQSTR ,0 );if (status) - ret =IRQ_WAKE_THREAD ; +thermal_zone_device_update (priv->tscs[i]->zone, +THERMAL_EVENT_UNSPECIFIED ); } -if (ret ==IRQ_WAKE_THREAD ) -rcar_thermal_irq_set (priv, false); - -spin_unlock (&priv->lock); - -return ret; -} - -static irqreturn_t rcar_gen3_thermal_irq_thread (int irq,void *data) -{ -struct rcar_gen3_thermal_priv *priv = data; -unsigned long flags; -int i; - -for (i =0 ; i < priv->num_tscs; i++) -thermal_zone_device_update (priv->tscs[i]->zone, -THERMAL_EVENT_UNSPECIFIED ); - -spin_lock_irqsave (&priv->lock, flags); -rcar_thermal_irq_set (priv, true); -spin_unlock_irqrestore (&priv->lock, flags); -return IRQ_HANDLED ; }@@ -390,9 +368,9 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)if (!irqname)return -ENOMEM ; - ret =devm_request_threaded_irq (dev, irq, rcar_gen3_thermal_irq, - rcar_gen3_thermal_irq_thread, -IRQF_SHARED , irqname, priv); + ret =devm_request_threaded_irq (dev, irq,NULL , + rcar_gen3_thermal_irq, +IRQF_ONESHOT , irqname, priv);if (ret)return ret; }
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
PATCH v3 2/2 thermal: rcar_gen3_thermal: disable interrupt in .remove
In reply to Jiada WangCurrently IRQ is remain enabled after .remove, later if device is probed, IRQ is requested before .thermal_init, this may cause IRQ function be called before device is initialized.
this patch by disable interrupt in .remove, to ensure irq function only be called after device is fully initialized.
--- drivers/thermal/rcar_gen3_thermal.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/thermal/rcar_gen3_thermal.c +3 -0
@@ -309,6 +309,9 @@ MODULE_DEVICE_TABLE(of, rcar_gen3_thermal_dt_ids);static int rcar_gen3_thermal_remove (struct platform_device *pdev) {struct device *dev = &pdev->dev; +struct rcar_gen3_thermal_priv *priv =dev_get_drvdata (dev); + +rcar_thermal_irq_set (priv, false);pm_runtime_put (dev);pm_runtime_disable (dev);
Signature · 1 line
2.19.2
Re: [PATCH v3 2/2] thermal: rcar_gen3_thermal: disable interrupt in .remove
Quoted 1 line · Jiada Wang
Currently IRQ is remain enabled after .remove, later if device is probed,
IRQ remains enabled.
Quoted 4 lines
IRQ is requested before .thermal_init, this may cause IRQ function be called before device is initialized.
this patch by disable interrupt in .remove, to ensure irq function
s/by disable/disables/.
Quoted 3 lines
only be called after device is fully initialized.
Signed-off-by Jiada Wang <[email protected]>
[...]
MBR, Sergei
Hi Jiada,
Quoted 6 lines · Jiada Wang
There are issues with interrupt handling in
rcar_gen3_thermaldriver.Currently IRQ is remain enabled after .remove, later if device is probed, IRQ is requested before .thermal_init, this may cause IRQ function be triggered but not able to clear IRQ status, thus cause system to hang.
Quoted 8 lines
Since the irq line isn't shared between different devices, so the proper interrupt type flag should be
IRQF_ONESHOT.This patch-set fix these interrupt handling retated issues.
---
v3: fix to use correct code base
remove unused "flag" variable inrcar_gen3_thermal_irq
[..]
Based on below:
- basic functional testing [1]
- 40 min of loading and unloading the driver in a loop doesn't trigger the original problem (soft lockup)
[1] Basic functional testing on H3-ES2.0-ULCB-KF-M06:
rcar-gen3:~# T0=/sys/devices/virtual/thermal/thermal_zone0/temp
rcar-gen3:~# T1=/sys/devices/virtual/thermal/thermal_zone1/temp
rcar-gen3:~# T2=/sys/devices/virtual/thermal/thermal_zone2/temp
rcar-gen3:~# stress-ng --cpu 16 --timeout 60s &
[1] 2300
rcar-gen3:~# stress-ng: info: [2300] dispatching hogs: 16 cpu
rcar-gen3:~# for i in $(seq 1 24); do \
cat $T0 $T1 $T2 | tr '\n' ' '; echo; sleep 5; \
done
31500 37500 34500
32000 37500 34500
32500 38000 35000
33500 39500 36500
34000 39500 36500
35000 40500 37500
35500 41000 38000
36000 42000 38500
36500 42000 39000
37500 43000 40000
stress-ng: info: [2300] successful run completed in 60.55s
[1]+ Done stress-ng --cpu 16 --timeout 60s
37500 42500 39000
37500 41500 39000
37000 41000 38000
36500 40500 38000
36000 40000 37000
35500 39500 36500
35500 40000 36000
35000 39500 35500
35000 39500 36000
34500 38000 35500
34500 39000 35500
34000 38500 35000
34000 37500 35500
33500 38000 35500 Signature · 2 lines
Best regards, Eugeniu.