AT91 slow clock mode regression/fixes, improvement proposal
Hello Wenyou,
You worked recently on AT91 slow clock mode in the linux4sam/linux-at91 master branch, however I am seeing regressions on a AT91SAM9G35-EK board concerning the following commit-id:
e0c8ba9b0ec3154e87da747098ee56e96ca3cee6
pm: at91: pm_slowclock: move disable/enable PLLB out of the route
cc4dc9885103af3b3262f7ac2b6aa887df1618b3
pm: at91: pm_slowclock: improvement to disable the UTMI PLL
About cc4dc9885103af3b3262f7ac2b6aa887df1618b3:
The assembly look wrong for me, it seems you can't have two following labels with the same identifier, so:
/* Turn on UTMI PLL */
cmp flag, #1
bne 1f
(...)
1:
(...)
1:wait_pllblock
Is actually jumping to wait_pllblock before enabling PLLB instead of skipping UTMI PLL. Unfortunately the compiler does not warn about that.
About e0c8ba9b0ec3154e87da747098ee56e96ca3cee6:
I have mixed feeling about moving the PLL enabling from slow clock mode to master clock mode. Starting PLL is almost all about waiting, waiting, and waiting until they are stable enough to be used, the few CPU instructions required to switch ON the PLL is nothing compared to the wait time.
To be sure I benchmarked the required time to set up the UTMI PLL (using a GPIO + scope) on my AT91SAM9G35-CM module in both slow clock and master clock mode, I found out the required time to start up the PLL is, as expected, -exactly- the same.
But, previously, we were waiting with the CPU in slow clock mode, when the CPU power consumption is very very low, now we are waiting when the CPU is in full speed, which is worse.
Or, I am missing something ?
Anyway, if we wait for the PLL in master clock mode we *MUST* increase the PLL timeout a lot, with the current code I guess we are leaving the resume code when the PLL are not yet ready at all since we are only waiting out of a 1000 iteration loop on master clock.
(Note that I didn't get fooled by that and I disabled the timeout when I checked the UPLL start time.)
Furthermore, it looks like MCKRDY_TIMEOUT set to 1000 is not enough, my board crashes in about 1 wake up to 10 with this value and works perfectly fine with 4000.
I have attached a patch that do the following:
* Increase MCKRDY_TIMEOUT from 1000 to 4000 so my board don't crash.
* Fix the assembly on the "Turn on UTMI PLL" part
* Increase timeouts for PLLB and UPLL
However I still disagree with this patch (this is why I didn't do a pull request ;-), I am proposing doing a patch set that:
* Increase MCKRDY_TIMEOUT from 1000 to 4000 so my board don't crash, I would be happy to have a feed back on this with your boards ;-)
* Fix the assembly on the "Turn on UTMI PLL" part
* Move back PLLB and UPLL to slow clock mode to save power
What do you think ?
I have also mixed feeling about those timeouts, is it really useful in the wild ? We don't event catch the timeout event to do something else if it happens, we still switch to the master clock whatever happened or even worse we continue even if AT91_PMC_MCKRDY isn't set? which is why I am having hard fault. In my opinion this is the watchdog job to handle those cases cleanly, there is nothing much we can do if something fail other than waiting a watchdog reset.
(Yeah, I know the watchdog is hard to use with sleep mode on AT91 chip, I have a work in progress about using the RTC to wake up before the watchdog expire to clear the watchdog and go back to sleep as fast as possible without resuming all the devices. It works, but I am still not happy at all with what I did for now.)
Therefore I am also proposing to remove all the timeout.
By the way, I don't know for other AT91 boards (or without DT, or something else), but the UTMI PLL suspend/resume seem unnecessary for me, the USB driver is already disabling the USB PLL when suspending, could you confirm ?
Regards,
Sylvain
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-AT91-PM-slow-clock-mode-fixes.patch
Type: text/x-diff
Size: 1769 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141218/2a3e922f/attachment-0001.bin>
Hello,
Quoted 14 lines · Sylvain Rochet
About
e0c8ba9b0ec3154e87da747098ee56e96ca3cee6:I have mixed feeling about moving the PLL enabling from slow clock mode to master clock mode. Starting PLL is almost all about waiting, waiting, and waiting until they are stable enough to be used, the few CPU instructions required to switch ON the PLL is nothing compared to the wait time.
To be sure I benchmarked the required time to set up the UTMI PLL (using a GPIO + scope) on my AT91SAM9G35-CM module in both slow clock and master clock mode, I found out the required time to start up the PLL is, as expected, -exactly- the same.
Quoted 5 lines
But, previously, we were waiting with the CPU in slow clock mode, when the CPU power consumption is very very low, now we are waiting when the CPU is in full speed, which is worse.
Or, I am missing something ?
Responding myself on this point, just did further mesurements, and... well, this can be discarded. I didn't notice at first that PLL startup time are only about to take ~500 us, which is a negligible amount of time and is actually a bit faster (just a bit) on master clock. I really should have checked the timing as well with PLL start up disabled, sorry :)
Sylvain
Hi Sylvain,
Quoted 36 lines
-----Original Message-----
From: Sylvain Rochet [mailto:sylvain.rochet at finsecur.com]
Sent: Friday, December 19, 2014 4:39 AM
To: Yang, Wenyou; Ferre, Nicolas; Desroches, Ludovic; Alexandre Belloni; Maxime Ripard
Cc: linux-arm-kernel at lists.infradead.org
Subject: AT91 slow clock mode regression/fixes, improvement proposalHello Wenyou,
You worked recently on AT91 slow clock mode in the linux4sam/linux-at91 master branch, however I am seeing regressions on a AT91SAM9G35-EK board concerning the following commit-id:
e0c8ba9b0ec3154e87da747098ee56e96ca3cee6
pm: at91:pm_slowclock: move disable/enable PLLB out of the route
cc4dc9885103af3b3262f7ac2b6aa887df1618b3
pm: at91:pm_slowclock: improvement to disable the UTMI PLLAbout
cc4dc9885103af3b3262f7ac2b6aa887df1618b3:The assembly look wrong for me, it seems you can't have two following labels with the same identifier, so:
/* Turn on UTMI PLL */
cmp flag, #1
bne 1f
(...)
1:
(...)
1:wait_pllblock
Quoted 2 lines
Is actually jumping to
wait_pllblockbefore enabling PLLB instead of skipping UTMI PLL. Unfortunately the compiler does not warn about that.
Thanks. I will check it
Quoted 28 lines
About
e0c8ba9b0ec3154e87da747098ee56e96ca3cee6:I have mixed feeling about moving the PLL enabling from slow clock mode to master clock mode. Starting PLL is almost all about waiting, waiting, and waiting until they are stable enough to be used, the few CPU instructions required to switch ON the PLL is nothing compared to the wait time.
To be sure I benchmarked the required time to set up the UTMI PLL (using a GPIO + scope) on my AT91SAM9G35-CM module in both slow clock and master clock mode, I found out the required time to start up the PLL is, as expected, -exactly- the same.
But, previously, we were waiting with the CPU in slow clock mode, when the CPU power consumption is very very low, now we are waiting when the CPU is in full speed, which is worse.
Or, I am missing something ?
Anyway, if we wait for the PLL in master clock mode we *MUST* increase the PLL timeout a lot, with the current code I guess we are leaving the resume code when the PLL are not yet ready at all since we are only waiting out of a 1000 iteration loop on master clock.
Quoted 8 lines
(Note that I didn't get fooled by that and I disabled the timeout when I checked the UPLL start time.)
Furthermore, it looks like
MCKRDY_TIMEOUTset to 1000 is not enough, my board crashes in about 1 wake up to 10 with this value and works perfectly fine with 4000.
I also encountered this issue.
Moreover the Main Crystal Oscillator Startup Time seems not enough too, not sure, I am confirming it.
Quoted 28 lines
I have attached a patch that do the following:
* Increase
MCKRDY_TIMEOUTfrom 1000 to 4000 so my board don't crash.
* Fix the assembly on the "Turn on UTMI PLL" part
* Increase timeouts for PLLB and UPLLHowever I still disagree with this patch (this is why I didn't do a pull request ;-), I am proposing doing a patch set that:
* Increase
MCKRDY_TIMEOUTfrom 1000 to 4000 so my board don't crash, I would be happy to have a feed back on this with your boards ;-)
* Fix the assembly on the "Turn on UTMI PLL" part
* Move back PLLB and UPLL to slow clock mode to save powerWhat do you think ?
I have also mixed feeling about those timeouts, is it really useful in the wild ? We don't event catch the timeout event to do something else if it happens, we still switch to the master clock whatever happened or even worse we continue even if
AT91_PMC_MCKRDYisn't set? which is why I am having hard fault. In my opinion this is the watchdog job to handle those cases cleanly, there is nothing much we can do if something fail other than waiting a watchdog reset.
Quoted 7 lines
(Yeah, I know the watchdog is hard to use with sleep mode on AT91 chip, I have a work in progress about using the RTC to wake up before the watchdog expire to clear the watchdog and go back to sleep as fast as possible without resuming all the devices. It works, but I am still not happy at all with what I did for now.)
Therefore I am also proposing to remove all the timeout.
Good idea, but I still worry the deadlock without timeout. Maybe increasing timeout is better.
Quoted 6 lines
By the way, I don't know for other AT91 boards (or without DT, or something else), but the UTMI PLL suspend/resume seem unnecessary for me, the USB driver is already disabling the USB PLL when suspending, could you confirm ?
Yes, I agree.
Remove disabling the PLLB code as well.
Quoted 5 lines
Regards,
Sylvain
Best Regards,
Wenyou Yang
PATCH 1/1 pm: at91: pm_slowclock: improve reliability of suspend/resume
Assume USB PLL and PLL B are already stopped before entering sleep mode, print a warning if this isn't the case.
Removed timeout on XTAL, PLL lock and Master Clock Ready, hang if something went wrong instead of continuing in unknown condition. There is not much we can do if a PLL lock never ends, we are running in SRAM and we will not be able to connect back the sdram or ddram in order to be able to fire up a message or just panic.
As a bonus, not decounting the timeout register in slow clock mode reduce cumulated suspend time and resume time from ~17ms to ~15ms.
--- arch/arm/mach-at91/pm.c | 12 +++++ arch/arm/mach-at91/pm_slowclock.S | 101 ++------------------------------------ 2 files changed, 16 insertions(+), 97 deletions(-)
arch/arm/mach-at91/pm.c +12 -0
@@ -168,6 +168,18 @@ static int at91_pm_verify_clocks(void) } } +/* Drivers should have previously suspended USB PLL */ +if (at91_pmc_read (AT91_CKGR_UCKR ) &AT91_PMC_UPLLEN ) { +pr_err ("AT91: PM - Suspend-to-RAM with USB PLL running\n" ); +return 0 ; + } + +/* Drivers should have previously suspended PLL B */ +if (at91_pmc_read (AT91_PMC_SR ) &AT91_PMC_LOCKB ) { +pr_err ("AT91: PM - Suspend-to-RAM with PLL B running\n" ); +return 0 ; + } +return 1 ; }#endif
arch/arm/mach-at91/pm_slowclock.S +4 -97
160 lines not on this page · raw message
Signature · 1 line
2.1.3
Hello Wenyou,
Quoted 5 lines · Wenyou
Quoted 3 lines
Is actually jumping to
wait_pllblockbefore enabling PLLB instead of skipping UTMI PLL. Unfortunately the compiler does not warn about that.Thanks. I will check it
Fixed in proposed patch (UPLL code removed).
Quoted 5 lines
Quoted 3 lines
Furthermore, it looks like
MCKRDY_TIMEOUTset to 1000 is not enough, my board crashes in about 1 wake up to 10 with this value and works perfectly fine with 4000.I also encountered this issue.
Fixed in proposed patch, since we don't timeout anymore.
Quoted 2 lines
Moreover the Main Crystal Oscillator Startup Time seems not enough too, not sure, I am confirming it.
This is OK for me, CKGR_MOR.MOSCXTST is set to 8: (1/32768)*8*8 = 1.95 ms
I checked with a scope on XTAL of the AT91SAM9G35-CM module, 2 ms is about twice enough waiting time.
Quoted 4 lines
Quoted 1 line
Therefore I am also proposing to remove all the timeout.
Good idea, but I still worry the deadlock without timeout. Maybe increasing timeout is better.
This is just a test request patch, I am first trying without timeout to get some feedback. It works well for me, at least, but this isn't convicing myself enough :-)
Quoted 5 lines
Quoted 4 lines
By the way, I don't know for other AT91 boards (or without DT, or something else), but the UTMI PLL suspend/resume seem unnecessary for me, the USB driver is already disabling the USB PLL when suspending, could you confirm ?
Yes, I agree.
Removed.
Quoted 1 line
Remove disabling the PLLB code as well.
Done, but my SoC don't have a PLLB, so I can't check myself, could you check if "AT91: PM - Suspend-to-RAM with PLL B running" does not fire on PLL B enabled board ?
Regards,
Sylvain
Hi Sylvain,
Quoted 11 lines · Wenyou
Quoted 5 lines
Quoted 3 lines
Is actually jumping to
wait_pllblockbefore enabling PLLB instead of skipping UTMI PLL. Unfortunately the compiler does not warn about that.Thanks. I will check it
Fixed in proposed patch (UPLL code removed).
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Furthermore, it looks like
MCKRDY_TIMEOUTset to 1000 is not enough, my board crashes in about 1 wake up to 10 with this value and works perfectly fine with 4000.I also encountered this issue.
Fixed in proposed patch, since we don't timeout anymore.
I am verifying this patch. I still insist on remain the timeout.
Quoted 9 lines
Quoted 4 lines
Moreover the Main Crystal Oscillator Startup Time seems not enough too, not sure, I am confirming it.
This is OK for me, CKGR_MOR.MOSCXTST is set to 8: (1/32768)*8*8 = 1.95 ms
I checked with a scope on XTAL of the AT91SAM9G35-CM module, 2 ms is about twice enough waiting time.
Yes, you are right. Thanks.
Quoted 18 lines
Quoted 6 lines
Quoted 3 lines
Therefore I am also proposing to remove all the timeout.
Good idea, but I still worry the deadlock without timeout. Maybe increasing timeout is better.
This is just a test request patch, I am first trying without timeout to get some feedback. It works well for me, at least, but this isn't convicing myself enough :-)
Quoted 5 lines
Quoted 4 lines
By the way, I don't know for other AT91 boards (or without DT, or something else), but the UTMI PLL suspend/resume seem unnecessary for me, the USB driver is already disabling the USB PLL when suspending, could you confirm ?
Yes, I agree.
Quoted 8 lines
Removed.
Quoted 1 line
Remove disabling the PLLB code as well.
Done, but my SoC don't have a PLLB, so I can't check myself, could you check if "AT91: PM - Suspend-to-RAM with PLL B running" does not fire on PLL B enabled board ?
I will check.
Quoted 4 lines
Regards,
Sylvain
Best Regard,
Wenyou Yang
Hello Wenyou,
Quoted 11 lines · Wenyou
Quoted 9 lines · Wenyou
Quoted 6 lines
Quoted 4 lines
Furthermore, it looks like
MCKRDY_TIMEOUTset to 1000 is not enough, my board crashes in about 1 wake up to 10 with this value and works perfectly fine with 4000.I also encountered this issue.
Fixed in proposed patch, since we don't timeout anymore.
I am verifying this patch. I still insist on remain the timeout.
Master Clock Ready is a special case, you need a timeout value which is fine at slow clock and master clock, that is, a timeout value which is fine despite the 10^4 difference in order of magnitude. I just don't know what to do, a fine timeout value for master clock is an almost infinite timeout on slow clock.
By the way, my board suspended and resumed every 2 seconds this week-end, which is about 110k suspend+wake up cycles and didn't reset on watchdog, which is quite a good news :-)
Regards,
Sylvain
Hi Sylvain,
Quoted 9 lines
Quoted 7 lines
Furthermore, it looks like
MCKRDY_TIMEOUTset to 1000 is notQuoted 4 lines
Quoted 2 lines
enough, my board crashes in about 1 wake up to 10 with this value and works perfectly fine with 4000.
I also encountered this issue.
Fixed in proposed patch, since we don't timeout anymore.
I am verifying this patch. I still insist on remain the timeout.
Verified OK.
Thanks.
I remembered you said this patch is not formal. Now, would you like send a formal one?
Best Regards,
Wenyou Yang
PATCH 1/1 pm: at91: pm_slowclock: improve reliability of suspend/resume
Assume USB PLL and PLL B are already stopped before entering sleep mode, print a warning if this isn't the case.
Removed timeout on XTAL, PLL lock and Master Clock Ready, hang if something went wrong instead of continuing in unknown condition. There is not much we can do if a PLL lock never ends, we are running in SRAM and we will not be able to connect back the sdram or ddram in order to be able to fire up a message or just panic.
As a bonus, not decounting the timeout register in slow clock mode reduce cumulated suspend time and resume time from ~17ms to ~15ms.
--- arch/arm/mach-at91/pm.c | 12 +++++ arch/arm/mach-at91/pm_slowclock.S | 101 ++------------------------------------ 2 files changed, 16 insertions(+), 97 deletions(-)
arch/arm/mach-at91/pm.c +12 -0
@@ -168,6 +168,18 @@ static int at91_pm_verify_clocks(void) } } +/* Drivers should have previously suspended USB PLL */ +if (at91_pmc_read (AT91_CKGR_UCKR ) &AT91_PMC_UPLLEN ) { +pr_err ("AT91: PM - Suspend-to-RAM with USB PLL running\n" ); +return 0 ; + } + +/* Drivers should have previously suspended PLL B */ +if (at91_pmc_read (AT91_PMC_SR ) &AT91_PMC_LOCKB ) { +pr_err ("AT91: PM - Suspend-to-RAM with PLL B running\n" ); +return 0 ; + } +return 1 ; }#endif
arch/arm/mach-at91/pm_slowclock.S +4 -97
160 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 1/1 pm: at91: pm_slowclock: improve reliability of suspend/resume
In reply to Yang, WenyouAssume USB PLL and PLL B are already stopped before entering sleep mode, print a warning if this isn't the case.
Removed timeout on XTAL, PLL lock and Master Clock Ready, hang if something went wrong instead of continuing in unknown condition. There is not much we can do if a PLL lock never ends, we are running in SRAM and we will not be able to connect back the sdram or ddram in order to be able to fire up a message or just panic.
As a bonus, not decounting the timeout register in slow clock mode reduce cumulated suspend time and resume time from ~17ms to ~15ms.
--- arch/arm/mach-at91/pm.c | 12 ++++++++ arch/arm/mach-at91/pm_slowclock.S | 62 ++------------------------------------- 2 files changed, 15 insertions(+), 59 deletions(-)
arch/arm/mach-at91/pm.c +12 -0
@@ -98,6 +98,18 @@ static int at91_pm_verify_clocks(void) } } +/* Drivers should have previously suspended USB PLL */ +if (at91_pmc_read (AT91_CKGR_UCKR ) &AT91_PMC_UPLLEN ) { +pr_err ("AT91: PM - Suspend-to-RAM with USB PLL running\n" ); +return 0 ; + } + +/* Drivers should have previously suspended PLL B */ +if (at91_pmc_read (AT91_PMC_SR ) &AT91_PMC_LOCKB ) { +pr_err ("AT91: PM - Suspend-to-RAM with PLL B running\n" ); +return 0 ; + } +return 1 ; }
arch/arm/mach-at91/pm_slowclock.S +3 -59
110 lines not on this page · raw message
Signature · 1 line
2.1.4
Hello Wenyou,
Quoted 3 lines · Wenyou
I remembered you said this patch is not formal. Now, would you like send a formal one?
Here it is, the first one is based on linux-at91/linux-3.10-at91 branch, the second one is rebased on linux-3.18 (Is this the right way when playing with multiple branch?).
By the way, Wenyou fixed some bugs in the linux-3.10-at91 branch about slow clock mode which should IMHO be merged and pushed to other branches.
Regards,
Sylvain
Hi Sylvain,
Quoted 15 lines
-----Original Message-----
From: Sylvain Rochet [mailto:sylvain.rochet at finsecur.com]
Sent: Tuesday, January 06, 2015 10:25 PM
To: Yang, Wenyou
Cc: Ferre, Nicolas; Desroches, Ludovic; 'Alexandre Belloni'; 'Maxime Ripard'; 'linux-arm-kernel at lists.infradead.org'
Subject: Re: AT91 slow clock mode regression/fixes, improvement proposalHello Wenyou,
Quoted 3 lines · Wenyou
I remembered you said this patch is not formal. Now, would you like send a formal one?
Quoted 6 lines
Here it is, the first one is based on linux-at91/linux-3.10-at91 branch, the second one is rebased on linux-3.18 (Is this the right way when playing with multiple branch?).
By the way, Wenyou fixed some bugs in the linux-3.10-at91 branch about slow clock mode which should IMHO be merged and pushed to other branches.
Yes, I will push to the mainline after verification passed.
Thank you very much.
Quoted 3 lines
Regards,
Sylvain
Best Regagrds,
Wenyou Yang
Hi,
Quoted 10 lines · Sylvain Rochet
Hello Wenyou,
Quoted 3 lines · Wenyou
I remembered you said this patch is not formal. Now, would you like send a formal one?
Here it is, the first one is based on linux-at91/linux-3.10-at91 branch, the second one is rebased on linux-3.18 (Is this the right way when playing with multiple branch?).
You can include that kind of information after the --- marker in the patch so that it is clearer.
Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com