Skip to contentSkip to conversation

clocksource/drivers/timer-mediatek: optimize systimer irq clear flow on shutdown

PATCH Applied Fengquan Chen 4 participants 7 messages Apr 9, 2021 – Aug 26, 2021

Subsystems (2)

v4 of 5 Applied Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 clocksource/drivers/timer-mediatek: optimize systimer irq clear flow on shutdown

Fengquan Chen (1):
[v4, 1/1] clocksource/drivers/timer-mediatek: optimize systimer irq clear flow on shutdown

 drivers/clocksource/timer-mediatek.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
1.8.1.1.dirty
#1 lore raw

PATCH v4 1/1 clocksource/drivers/timer-mediatek: optimize systimer irq clear flow on shutdown

mtk_syst_clkevt_shutdown is called after irq disabled in suspend flow, clear any pending systimer irq when shutdown to avoid suspend aborted due to timer irq pending

Also as for systimer in mediatek socs, there must be firstly enable timer before clear systimer irq

Fixes e3af677607d9("clocksource/drivers/timer-mediatek: Add support for system timer")
---
 drivers/clocksource/timer-mediatek.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/clocksource/timer-mediatek.c +6 -2
index 9318edc..6461fd3 100644
@@ -60,9 +60,9 @@
  * SYST_CON_EN: Clock enable. Shall be set to
  *   - Start timer countdown.
  *   - Allow timeout ticks being updated.
- *   - Allow changing interrupt functions.
+ *   - Allow changing interrupt status,like clear irq pending.
  *
- * SYST_CON_IRQ_EN: Set to allow interrupt.
+ * SYST_CON_IRQ_EN: Set to enable interrupt.
  *
  * SYST_CON_IRQ_CLR: Set to clear interrupt.
  */
@@ -75,6 +75,7 @@
 static void mtk_syst_ack_irq(struct timer_of *to)
 {
 	/* Clear and disable interrupt */
+	writel(SYST_CON_EN, SYST_CON_REG(to));
 	writel(SYST_CON_IRQ_CLR | SYST_CON_EN, SYST_CON_REG(to));
 }
 
@@ -111,6 +112,9 @@ static int mtk_syst_clkevt_next_event(unsigned long ticks,
 
 static int mtk_syst_clkevt_shutdown(struct clock_event_device *clkevt)
 {
+	/* Clear any irq */
+	mtk_syst_ack_irq(to_timer_of(clkevt));
+
 	/* Disable timer */
 	writel(0, SYST_CON_REG(to_timer_of(clkevt)));
 
Signature · 1 line
1.8.1.1.dirty
Tested-by on v4 1/1
#2 lore raw
Quoted 11 lines · Fengquan Chen

mtk_syst_clkevt_shutdown is called after irq disabled in suspend flow, clear any pending systimer irq when shutdown to avoid suspend aborted due to timer irq pending

Also as for systimer in mediatek socs, there must be firstly enable timer before clear systimer irq

Fixes e3af677607d9("clocksource/drivers/timer-mediatek: Add support for system timer")

Tested on a mt8183 device. This patch solves an issue that device would hang on resume during genpd_resume_noirq:

[  724.342834] mtk-smi-larb 17010000.larb: genpd_resume_noirq+0x0/0xd0
returned 0 after 976593 usecs
[  724.351721] mtk-smi-larb 1a001000.larb: calling
genpd_resume_noirq+0x0/0xd0 @ 6629, parent: soc
[  736.845047] Kernel panic - not syncing: Watchdog detected hard
LOCKUP on cpu 3
[  736.852268] CPU: 2 PID: 0 Comm: swapper/2 Tainted: G        W
  5.10.26 #17
[  736.859743] Hardware name: MediaTek krane sku176 board (DT)
[  736.865309] Call trace:
[  736.867756]  dump_backtrace+0x0/0x1bc
[  736.871415]  show_stack+0x20/0x2c
[  736.874728]  dump_stack+0xc0/0x11c
[  736.878124]  panic+0x174/0x378
[  736.881178]  watchdog_check_hardlockup+0x11c/0x124
[  736.885963]  watchdog_timer_fn+0x70/0x274

<snip>

Quoted 41 lines
---
 drivers/clocksource/timer-mediatek.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/clocksource/timer-mediatek.c +6 -3
index 9318edc..6461fd3 100644
@@ -60,9 +60,9 @@
  * SYST_CON_EN: Clock enable. Shall be set to
  *   - Start timer countdown.
  *   - Allow timeout ticks being updated.
- *   - Allow changing interrupt functions.
+ *   - Allow changing interrupt status,like clear irq pending.
  *
- * SYST_CON_IRQ_EN: Set to allow interrupt.
+ * SYST_CON_IRQ_EN: Set to enable interrupt.
  *
  * SYST_CON_IRQ_CLR: Set to clear interrupt.
  */
@@ -75,6 +75,7 @@
 static void mtk_syst_ack_irq(struct timer_of *to)
 {
        /* Clear and disable interrupt */
+       writel(SYST_CON_EN, SYST_CON_REG(to));
        writel(SYST_CON_IRQ_CLR | SYST_CON_EN, SYST_CON_REG(to));
 }
 
@@ -111,6 +112,9 @@ static int mtk_syst_clkevt_next_event(unsigned long ticks,
 
 static int mtk_syst_clkevt_shutdown(struct clock_event_device *clkevt)
 {
+       /* Clear any irq */
+       mtk_syst_ack_irq(to_timer_of(clkevt));
+
        /* Disable timer */
        writel(0, SYST_CON_REG(to_timer_of(clkevt)));
 
--

1.8.1.1.dirty

#3 lore raw
In reply to Fengquan Chen
Quoted 31 lines · Fengquan Chen

mtk_syst_clkevt_shutdown is called after irq disabled in suspend flow, clear any pending systimer irq when shutdown to avoid suspend aborted due to timer irq pending

Also as for systimer in mediatek socs, there must be firstly enable timer before clear systimer irq

Fixes e3af677607d9("clocksource/drivers/timer-mediatek: Add support for system timer")
---
 drivers/clocksource/timer-mediatek.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/clocksource/timer-mediatek.c +2 -2
index 9318edc..6461fd3 100644
@@ -60,9 +60,9 @@
  * SYST_CON_EN: Clock enable. Shall be set to
  *   - Start timer countdown.
  *   - Allow timeout ticks being updated.
- *   - Allow changing interrupt functions.
+ *   - Allow changing interrupt status,like clear irq pending.
  *
- * SYST_CON_IRQ_EN: Set to allow interrupt.
+ * SYST_CON_IRQ_EN: Set to enable interrupt.
  *
  * SYST_CON_IRQ_CLR: Set to clear interrupt.
  */

drivers/clocksource/timer-mediatek.c line 80

Quoted 6 lines
drivers/clocksource/timer-mediatek.c +1 -0
@@ -75,6 +75,7 @@
 static void mtk_syst_ack_irq(struct timer_of *to)
 {
 	/* Clear and disable interrupt */
+	writel(SYST_CON_EN, SYST_CON_REG(to));
 	writel(SYST_CON_IRQ_CLR | SYST_CON_EN, SYST_CON_REG(to));
 }

IIRC, there is a hardware issue here. If it is the case, please describe it and refer to an errata if any.

Also Evan Benn commented your code and asked a couple of questions [1], please answer before reposting a new version.

Comments ignored == patch ignored

drivers/clocksource/timer-mediatek.c static int mtk_syst_clkevt_next_event(unsigned long ticks, · line 119

Quoted 9 lines
drivers/clocksource/timer-mediatek.c +3 -0
@@ -111,6 +112,9 @@ static int mtk_syst_clkevt_next_event(unsigned long ticks,
 
 static int mtk_syst_clkevt_shutdown(struct clock_event_device *clkevt)
 {
+	/* Clear any irq */
+	mtk_syst_ack_irq(to_timer_of(clkevt));
+
 	/* Disable timer */
 	writel(0, SYST_CON_REG(to_timer_of(clkevt)));

Please check out the patch sent by Evan Benn [2], if you agree, ack it.

Thanks

-- Daniel

[1] https://patchwork.kernel.org/comment/24059277/
[2]
https://lore.kernel.org/linux-arm-kernel/20210412132200.v3.1.I1d9917047de06715da16e1620759f703fcfdcbcb@changeid/

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
#4 lore raw
Quoted 33 lines · Daniel Lezcano
Quoted 32 lines · Fengquan Chen

mtk_syst_clkevt_shutdown is called after irq disabled in suspend flow, clear any pending systimer irq when shutdown to avoid suspend aborted due to timer irq pending

Also as for systimer in mediatek socs, there must be firstly enable timer before clear systimer irq

Fixes e3af677607d9("clocksource/drivers/timer-mediatek: Add support for system timer")
---
 drivers/clocksource/timer-mediatek.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/clocksource/timer-mediatek.c +2 -2
index 9318edc..6461fd3 100644
@@ -60,9 +60,9 @@
  * SYST_CON_EN: Clock enable. Shall be set to
  *   - Start timer countdown.
  *   - Allow timeout ticks being updated.
- *   - Allow changing interrupt functions.
+ *   - Allow changing interrupt status,like clear irq pending.
  *
- * SYST_CON_IRQ_EN: Set to allow interrupt.
+ * SYST_CON_IRQ_EN: Set to enable interrupt.
  *
  * SYST_CON_IRQ_CLR: Set to clear interrupt.
  */
@@ -75,6 +75,7 @@
 static void mtk_syst_ack_irq(struct timer_of *to)
Quoted 8 lines

drivers/clocksource/timer-mediatek.c line 80

Quoted 5 lines
drivers/clocksource/timer-mediatek.c +1 -0
 {
 	/* Clear and disable interrupt */
+	writel(SYST_CON_EN, SYST_CON_REG(to));
 	writel(SYST_CON_IRQ_CLR | SYST_CON_EN, SYST_CON_REG(to));
 }

IIRC, there is a hardware issue here. If it is the case, please describe it and refer to an errata if any.

Thanks for review.
here is just a hw config flow limitation, not a bug.

Quoted 5 lines

Also Evan Benn commented your code and asked a couple of questions [1], please answer before reposting a new version.

Comments ignored == patch ignored

Thanks. i have answered by mail before, but it didn't uploaded to the list. has been uploaded ok now.

Quoted 13 lines

drivers/clocksource/timer-mediatek.c static int mtk_syst_clkevt_next_event(unsigned long ticks, · line 119

Quoted 10 lines
drivers/clocksource/timer-mediatek.c +3 -0
@@ -111,6 +112,9 @@ static int mtk_syst_clkevt_next_event(unsigned long ticks,
 
 static int mtk_syst_clkevt_shutdown(struct clock_event_device *clkevt)
 {
+	/* Clear any irq */
+	mtk_syst_ack_irq(to_timer_of(clkevt));
+
 	/* Disable timer */
 	writel(0, SYST_CON_REG(to_timer_of(clkevt)));

Please check out the patch sent by Evan Benn [2], if you agree, ack it.

Thanks

agree

Quoted 8 lines

Thanks

-- Daniel

[1] https://patchwork.kernel.org/comment/24059277/
[2]
https://lore.kernel.org/linux-arm-kernel/20210412132200.v3.1.I1d9917047de06715da16e1620759f703fcfdcbcb@changeid/

#5 lore raw

hi Daniel,

Gentle pin for this patch.

Thanks
Best Regards
Fengquan

Quoted 82 lines · Fengquan Chen
Quoted 33 lines · Daniel Lezcano
Quoted 32 lines · Fengquan Chen

mtk_syst_clkevt_shutdown is called after irq disabled in suspend flow, clear any pending systimer irq when shutdown to avoid suspend aborted due to timer irq pending

Also as for systimer in mediatek socs, there must be firstly enable timer before clear systimer irq

Fixes e3af677607d9("clocksource/drivers/timer-mediatek: Add support for system timer")
---
 drivers/clocksource/timer-mediatek.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/clocksource/timer-mediatek.c +2 -2
index 9318edc..6461fd3 100644
@@ -60,9 +60,9 @@
  * SYST_CON_EN: Clock enable. Shall be set to
  *   - Start timer countdown.
  *   - Allow timeout ticks being updated.
- *   - Allow changing interrupt functions.
+ *   - Allow changing interrupt status,like clear irq pending.
  *
- * SYST_CON_IRQ_EN: Set to allow interrupt.
+ * SYST_CON_IRQ_EN: Set to enable interrupt.
  *
  * SYST_CON_IRQ_CLR: Set to clear interrupt.
  */
@@ -75,6 +75,7 @@
 static void mtk_syst_ack_irq(struct timer_of *to)
Quoted 8 lines

drivers/clocksource/timer-mediatek.c line 80

Quoted 5 lines
drivers/clocksource/timer-mediatek.c +1 -0
 {
 	/* Clear and disable interrupt */
+	writel(SYST_CON_EN, SYST_CON_REG(to));
 	writel(SYST_CON_IRQ_CLR | SYST_CON_EN, SYST_CON_REG(to));
 }

IIRC, there is a hardware issue here. If it is the case, please describe it and refer to an errata if any.

Thanks for review.
here is just a hw config flow limitation, not a bug.

Quoted 5 lines

Also Evan Benn commented your code and asked a couple of questions [1], please answer before reposting a new version.

Comments ignored == patch ignored

Thanks. i have answered by mail before, but it didn't uploaded to the list. has been uploaded ok now.

Quoted 13 lines

drivers/clocksource/timer-mediatek.c static int mtk_syst_clkevt_next_event(unsigned long ticks, · line 119

Quoted 10 lines
drivers/clocksource/timer-mediatek.c +3 -0
@@ -111,6 +112,9 @@ static int mtk_syst_clkevt_next_event(unsigned long ticks,
 
 static int mtk_syst_clkevt_shutdown(struct clock_event_device *clkevt)
 {
+	/* Clear any irq */
+	mtk_syst_ack_irq(to_timer_of(clkevt));
+
 	/* Disable timer */
 	writel(0, SYST_CON_REG(to_timer_of(clkevt)));

Please check out the patch sent by Evan Benn [2], if you agree, ack it.

Thanks

agree

Quoted 8 lines

Thanks

-- Daniel

[1] https://patchwork.kernel.org/comment/24059277/
[2]
https://lore.kernel.org/linux-arm-kernel/20210412132200.v3.1.I1d9917047de06715da16e1620759f703fcfdcbcb@changeid/

merge bot Applied
#6 lore raw

[tip: timers/core] clocksource/drivers/mediatek: Optimize systimer irq clear flow on shutdown

In reply to Fengquan Chen
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     ce9570657d45d6387a68d7f419fe70d085200a2f
Gitweb:        https://git.kernel.org/tip/ce9570657d45d6387a68d7f419fe70d085200a2f
Author:        Fengquan Chen <[email protected]>
AuthorDate:    Fri, 09 Apr 2021 17:22:42 +08:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Sat, 14 Aug 2021 02:44:35 +02:00

clocksource/drivers/mediatek: Optimize systimer irq clear flow on shutdown

mtk_syst_clkevt_shutdown is called after irq disabled in suspend flow, clear any pending systimer irq when shutdown to avoid suspend aborted due to timer irq pending

Also as for systimer in mediatek socs, there must be firstly enable timer before clear systimer irq

Fixes e3af677607d9("clocksource/drivers/timer-mediatek: Add support for system timer")
---
 drivers/clocksource/timer-mediatek.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/clocksource/timer-mediatek.c +6 -2
index ab63b95..7bcb4a3 100644
@@ -60,9 +60,9 @@
  * SYST_CON_EN: Clock enable. Shall be set to
  *   - Start timer countdown.
  *   - Allow timeout ticks being updated.
- *   - Allow changing interrupt functions.
+ *   - Allow changing interrupt status,like clear irq pending.
  *
- * SYST_CON_IRQ_EN: Set to allow interrupt.
+ * SYST_CON_IRQ_EN: Set to enable interrupt.
  *
  * SYST_CON_IRQ_CLR: Set to clear interrupt.
  */
@@ -75,6 +75,7 @@ static void __iomem *gpt_sched_reg __read_mostly;
 static void mtk_syst_ack_irq(struct timer_of *to)
 {
 	/* Clear and disable interrupt */
+	writel(SYST_CON_EN, SYST_CON_REG(to));
 	writel(SYST_CON_IRQ_CLR | SYST_CON_EN, SYST_CON_REG(to));
 }
 
@@ -111,6 +112,9 @@ static int mtk_syst_clkevt_next_event(unsigned long ticks,
 
 static int mtk_syst_clkevt_shutdown(struct clock_event_device *clkevt)
 {
+	/* Clear any irq */
+	mtk_syst_ack_irq(to_timer_of(clkevt));
+
 	/* Disable timer */
 	writel(0, SYST_CON_REG(to_timer_of(clkevt)));