clk: at91: avoid sleeping early
Subsystems (2)
Alexandre Belloni
maintainerPATCH 1/1 clk: at91: avoid sleeping early
It is not allowed to sleep to early in the boot process and this may lead to kernel issues if the bootloader didn't prepare the slow clock and main clock.
This results in the following error and dump stack on the AriettaG25:
bad: scheduling from the idle thread!
Ensure it is possible to sleep, else simply have a delay.
---
Note that this was already discussed a while ago and Arnd said this approach was reasonable:
https://lore.kernel.org/lkml/6120818.MyeJZ74hYa@wuerfel/
drivers/clk/at91/clk-main.c | 5 ++++- drivers/clk/at91/sckc.c | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-)
drivers/clk/at91/clk-main.c +4 -1
@@ -293,7 +293,10 @@ static int clk_main_probe_frequency(struct regmap *regmap)regmap_read (regmap,AT91_CKGR_MCFR , &mcfr);if (mcfr &AT91_PMC_MAINRDY )return 0 ; -usleep_range (MAINF_LOOP_MIN_WAIT ,MAINF_LOOP_MAX_WAIT ); +if (system_state <SYSTEM_RUNNING ) +udelay (MAINF_LOOP_MIN_WAIT ); +else +usleep_range (MAINF_LOOP_MIN_WAIT ,MAINF_LOOP_MAX_WAIT ); }while (time_before (prep_time, timeout));return -ETIMEDOUT ;
drivers/clk/at91/sckc.c +16 -4
@@ -76,7 +76,10 @@ static int clk_slow_osc_prepare(struct clk_hw *hw)writel (tmp | osc->bits->cr_osc32en, sckcr); -usleep_range (osc->startup_usec, osc->startup_usec +1 ); +if (system_state <SYSTEM_RUNNING ) +udelay (osc->startup_usec); +else +usleep_range (osc->startup_usec, osc->startup_usec +1 );return 0 ; }
@@ -187,7 +190,10 @@ static int clk_slow_rc_osc_prepare(struct clk_hw *hw)writel (readl (sckcr) | osc->bits->cr_rcen, sckcr); -usleep_range (osc->startup_usec, osc->startup_usec +1 ); +if (system_state <SYSTEM_RUNNING ) +udelay (osc->startup_usec); +else +usleep_range (osc->startup_usec, osc->startup_usec +1 );return 0 ; }
@@ -288,7 +294,10 @@ static int clk_sam9x5_slow_set_parent(struct clk_hw *hw, u8 index)writel (tmp, sckcr); -usleep_range (SLOWCK_SW_TIME_USEC ,SLOWCK_SW_TIME_USEC +1 ); +if (system_state <SYSTEM_RUNNING ) +udelay (SLOWCK_SW_TIME_USEC ); +else +usleep_range (SLOWCK_SW_TIME_USEC ,SLOWCK_SW_TIME_USEC +1 );return 0 ; }
@@ -533,7 +542,10 @@ static int clk_sama5d4_slow_osc_prepare(struct clk_hw *hw)return 0 ; } -usleep_range (osc->startup_usec, osc->startup_usec +1 ); +if (system_state <SYSTEM_RUNNING ) +udelay (osc->startup_usec); +else +usleep_range (osc->startup_usec, osc->startup_usec +1 ); osc->prepared = true;return 0 ;
Signature · 1 line
2.21.0
Stephen Boyd
maintainerQuoting Alexandre Belloni (2019-09-20 08:39:06)
Quoted 9 lines
It is not allowed to sleep to early in the boot process and this may lead to kernel issues if the bootloader didn't prepare the slow clock and main clock.
This results in the following error and dump stack on the AriettaG25:
bad: scheduling from the idle thread!Ensure it is possible to sleep, else simply have a delay.
Quoted 7 lines
Reported-by Uwe Kleine-König <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>---
Note that this was already discussed a while ago and Arnd said this approach was reasonable:
https://lore.kernel.org/lkml/6120818.MyeJZ74hYa@wuerfel/
Does this need a Fixes: tag?
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Alexandre Belloni
maintainerQuoted 14 lines · Stephen Boyd
Quoting Alexandre Belloni (2019-09-20 08:39:06)
Quoted 13 lines
It is not allowed to sleep to early in the boot process and this may lead to kernel issues if the bootloader didn't prepare the slow clock and main clock.
This results in the following error and dump stack on the AriettaG25:
bad: scheduling from the idle thread!Ensure it is possible to sleep, else simply have a delay.
Reported-by Uwe Kleine-König <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>---
Quoted 6 lines
Quoted 3 lines
Note that this was already discussed a while ago and Arnd said this approach was reasonable:
https://lore.kernel.org/lkml/6120818.MyeJZ74hYa@wuerfel/Does this need a Fixes: tag?
I'm not sure how far this can get backported
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 11 lines · Alexandre Belloni
It is not allowed to sleep to early in the boot process and this may lead to kernel issues if the bootloader didn't prepare the slow clock and main clock.
This results in the following error and dump stack on the AriettaG25:
bad: scheduling from the idle thread!Ensure it is possible to sleep, else simply have a delay.
Reported-by Uwe Kleine-König <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>
See below for a comment.
Quoted 13 lines
Note that this was already discussed a while ago and Arnd said this approach was reasonable:
https://lore.kernel.org/lkml/6120818.MyeJZ74hYa@wuerfel/drivers/clk/at91/clk-main.c | 5 ++++- drivers/clk/at91/sckc.c | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-)drivers/clk/at91/clk-main.c +0
-0
drivers/clk/at91/clk-main.c static int clk_main_probe_frequency(struct regmap *regmap) · line 299
Quoted 8 lines
drivers/clk/at91/clk-main.c +4
-1@@ -293,7 +293,10 @@ static int clk_main_probe_frequency(struct regmap *regmap)regmap_read (regmap,AT91_CKGR_MCFR , &mcfr);if (mcfr &AT91_PMC_MAINRDY )return 0 ; -usleep_range (MAINF_LOOP_MIN_WAIT ,MAINF_LOOP_MAX_WAIT ); +if (system_state <SYSTEM_RUNNING ) +udelay (MAINF_LOOP_MIN_WAIT ); +else +usleep_range (MAINF_LOOP_MIN_WAIT ,MAINF_LOOP_MAX_WAIT );
Given that this construct is introduced several times, I wonder if we want something like:
static inline void early_usleep_range(unsigned long min, unsigned long max)
{
if (system_state < SYSTEM_RUNNING)
udelay(min);
else
usleep_range(min, max);
}Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Stephen Boyd
maintainerQuoting Uwe (2019-09-24 05:21:47)
Quoted 26 lines · Alexandre Belloni
Quoted 13 lines
Note that this was already discussed a while ago and Arnd said this approach was reasonable:
https://lore.kernel.org/lkml/6120818.MyeJZ74hYa@wuerfel/drivers/clk/at91/clk-main.c | 5 ++++- drivers/clk/at91/sckc.c | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-)drivers/clk/at91/clk-main.c +0
-0drivers/clk/at91/clk-main.c static int clk_main_probe_frequency(struct regmap *regmap) · line 299
Quoted 8 lines
drivers/clk/at91/clk-main.c +4
-1@@ -293,7 +293,10 @@ static int clk_main_probe_frequency(struct regmap *regmap)regmap_read (regmap,AT91_CKGR_MCFR , &mcfr);if (mcfr &AT91_PMC_MAINRDY )return 0 ; -usleep_range (MAINF_LOOP_MIN_WAIT ,MAINF_LOOP_MAX_WAIT ); +if (system_state <SYSTEM_RUNNING ) +udelay (MAINF_LOOP_MIN_WAIT ); +else +usleep_range (MAINF_LOOP_MIN_WAIT ,MAINF_LOOP_MAX_WAIT );Given that this construct is introduced several times, I wonder if we want something like:
Quoted 8 lines
static inline void early_usleep_range(unsigned long min, unsigned long max)
{
if (system_state < SYSTEM_RUNNING)
udelay(min);
else
usleep_range(min, max);
}Maybe, but I think the intent is to not encourage this behavior? So providing a wrapper will make it "easy" and then we'll have to tell users to stop calling it. Another idea would be to make usleep_range() "do the right thing" and call udelay if the system isn't running. And another idea from tlgx[1] is to pull the delay logic into another clk op that we can call to see when the enable or prepare is done. That may be possible by introducing another clk_ops callback that when present indicates we should sleep or delay for so much time while waiting for the prepare or enable to complete.
[1] https://lkml.kernel.org/r/alpine.DEB.2.11.1606061448010.28031@nanos
Alexandre Belloni
maintainerQuoted 46 lines · Stephen Boyd
Quoting Uwe (2019-09-24 05:21:47)
Quoted 26 lines · Alexandre Belloni
Quoted 13 lines
Note that this was already discussed a while ago and Arnd said this approach was reasonable:
https://lore.kernel.org/lkml/6120818.MyeJZ74hYa@wuerfel/drivers/clk/at91/clk-main.c | 5 ++++- drivers/clk/at91/sckc.c | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-)drivers/clk/at91/clk-main.c +0
-0drivers/clk/at91/clk-main.c static int clk_main_probe_frequency(struct regmap *regmap) · line 299
Quoted 8 lines
drivers/clk/at91/clk-main.c +4
-1@@ -293,7 +293,10 @@ static int clk_main_probe_frequency(struct regmap *regmap)regmap_read (regmap,AT91_CKGR_MCFR , &mcfr);if (mcfr &AT91_PMC_MAINRDY )return 0 ; -usleep_range (MAINF_LOOP_MIN_WAIT ,MAINF_LOOP_MAX_WAIT ); +if (system_state <SYSTEM_RUNNING ) +udelay (MAINF_LOOP_MIN_WAIT ); +else +usleep_range (MAINF_LOOP_MIN_WAIT ,MAINF_LOOP_MAX_WAIT );Given that this construct is introduced several times, I wonder if we want something like:
Quoted 8 lines
static inline void early_usleep_range(unsigned long min, unsigned long max) { if (system_state < SYSTEM_RUNNING) udelay(min); else usleep_range(min, max); }Maybe, but I think the intent is to not encourage this behavior? So providing a wrapper will make it "easy" and then we'll have to tell users to stop calling it. Another idea would be to make
usleep_range()"do the right thing" and call udelay if the system isn't running. And another idea from tlgx[1] is to pull the delay logic into another clk op that we can call to see when the enable or prepare is done. That may be possible by introducing anotherclk_opscallback that when present indicates we should sleep or delay for so much time while waiting for the prepare or enable to complete.
Quoted 2 lines
[1] https://lkml.kernel.org/r/alpine.DEB.2.11.1606061448010.28031@nanos
Do you want me to implement that now or are you planning to apply the patch in the meantime ?
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Stephen Boyd
maintainerQuoting Alexandre Belloni (2019-10-05 13:05:21)
Quoted 47 lines · Stephen Boyd
Quoted 46 lines
Quoting Uwe (2019-09-24 05:21:47)
Quoted 26 lines · Alexandre Belloni
Quoted 13 lines
Note that this was already discussed a while ago and Arnd said this approach was reasonable:
https://lore.kernel.org/lkml/6120818.MyeJZ74hYa@wuerfel/drivers/clk/at91/clk-main.c | 5 ++++- drivers/clk/at91/sckc.c | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-)drivers/clk/at91/clk-main.c +0
-0drivers/clk/at91/clk-main.c static int clk_main_probe_frequency(struct regmap *regmap) · line 299
Quoted 8 lines
drivers/clk/at91/clk-main.c +4
-1@@ -293,7 +293,10 @@ static int clk_main_probe_frequency(struct regmap *regmap)regmap_read (regmap,AT91_CKGR_MCFR , &mcfr);if (mcfr &AT91_PMC_MAINRDY )return 0 ; -usleep_range (MAINF_LOOP_MIN_WAIT ,MAINF_LOOP_MAX_WAIT ); +if (system_state <SYSTEM_RUNNING ) +udelay (MAINF_LOOP_MIN_WAIT ); +else +usleep_range (MAINF_LOOP_MIN_WAIT ,MAINF_LOOP_MAX_WAIT );Given that this construct is introduced several times, I wonder if we want something like:
Quoted 8 lines
static inline void early_usleep_range(unsigned long min, unsigned long max) { if (system_state < SYSTEM_RUNNING) udelay(min); else usleep_range(min, max); }Maybe, but I think the intent is to not encourage this behavior? So providing a wrapper will make it "easy" and then we'll have to tell users to stop calling it. Another idea would be to make
usleep_range()"do the right thing" and call udelay if the system isn't running. And another idea from tlgx[1] is to pull the delay logic into another clk op that we can call to see when the enable or prepare is done. That may be possible by introducing anotherclk_opscallback that when present indicates we should sleep or delay for so much time while waiting for the prepare or enable to complete.
Quoted 7 lines
Quoted 2 lines
[1] https://lkml.kernel.org/r/alpine.DEB.2.11.1606061448010.28031@nanos
Do you want me to implement that now or are you planning to apply the patch in the meantime ?
I'll just apply this for now to clk-fixes and merge it up next week. It would be great to do the other idea though, as a long term effort to reduce all the busy loop code we have in clk drivers. No worries, I'll put it on the todo list.