From: dongas86@gmail.com (Dong Aisheng)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] clk: imx: do not sleep if IRQ's are still disabled
Date: Tue, 7 Jun 2016 15:04:40 +0800 [thread overview]
Message-ID: <20160607070440.GA32573@shlinux2> (raw)
In-Reply-To: <alpine.DEB.2.11.1606061448010.28031@nanos>
On Mon, Jun 06, 2016 at 03:20:03PM +0200, Thomas Gleixner wrote:
> On Thu, 2 Jun 2016, Dong Aisheng wrote:
> > On Wed, Apr 27, 2016 at 12:15:00PM +0200, Thomas Gleixner wrote:
> > > Calling a function which might sleep _BEFORE_ kernel_init() is wrong. Don't
> > > try to work around such an issue by doing magic irq_disabled() checks and busy
> > > loops. Fix the call site and be done with it.
> > >
> >
> > IRQ chip and clocksource are also initialised before kernel_init()
> > which may call clk APIs like clk_prepare_enable().
> > We may not be able to guarantee those clocks are unsleepable.
> >
> > e.g.
> > For IRQ chip, the arm,gic documents the optional clocks property in
> > Documentation/devicetree/bindings/interrupt-controller/arm,gic.txt.
> > Although there seems no user currently, not sure there might be
> > a exception in the future.
> >
> > For clocksource driver, it's quite common to call clk APIs to
> > enable and get clock rate which may also cause sleep.
> > e.g. ARM twd clock in arch/arm/kernel/smp_twd.c.
> >
> > If we have to avoid the possible sleep caused by these clocks,
> > we may need to manually check it and change the related clocks
> > (e.g PLLs) from sleepable to busy loops.
> > But that is not a good solution and may also not stable when
> > clock varies.
> >
> > It looks like not easy to find a generic solution for them.
> > What's your suggestion?
>
> I think we should split the prepare callbacks up and move the handling logic
> into the core.
>
> clk_ops.prepare() Legacy callback
> clk_ops.prepare_hw() Callback which writes to the hardware
> clk_ops.prepare_done() Callback which checks whether the prepare is completed
>
> So now the core can do:
>
> clk_prepare()
> {
> /* Legacy code should go away */
> if (ops->prepare) {
> ops->prepare();
> return;
> }
>
> if (ops->prepare_hw)
> ops->prepare_hw();
>
> if (!ops->prepare_done())
> return;
>
> if (early_boot_or_suspend_resume()) {
> /*
> * Busy loop when we can't schedule in early boot,
> * suspend and resume.
> */
> while (!ops->prepare_done())
> ;
> } else {
> while (!ops->prepare_done())
> usleep(clk->prepare_delay);
> }
> }
>
> As a side effect that allows us to remove the gazillion of
>
> while (!hw_ready)
> usleep();
>
> copies all over the place and we have a single point of control where we allow
> the clocks to busy loop.
>
> Toughts?
>
Great, that looks like a possible solution.
If we doing this way there's one more question that
should we do it for other clk APIs hold by prepare_lock which
all may sleep too in theory?
e.g. clk_{set|get}_rate/clk_{set|get}_parent. (possible more)
(clk_recalc_rate/clk_round_rate may also need be considered due to
it may be called within above function.)
And it seems many exist platforms doing that work in
CLK_OF_DECLARE init function in time_init().
e.g.
drivers/clk/imx/clk-imx6ul.c
drivers/clk/rockchip/clk-rk3188.c
drivers/clk/ti/clk-44xx.c
...
Then it may need introduce a lot changes and increase many new core APIs.
Is that a problem?
> Thanks,
>
> tglx
Regards
Dong Aisheng
next prev parent reply other threads:[~2016-06-07 7:04 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-29 22:49 [PATCH 1/2] clk: imx: do not sleep if IRQ's are still disabled Stefan Agner
2016-01-29 22:49 ` [PATCH 2/2] clk: imx: return correct frequency for Ethernet PLL Stefan Agner
2016-01-29 23:35 ` [PATCH 1/2] clk: imx: do not sleep if IRQ's are still disabled Joshua Clayton
2016-01-30 1:16 ` Stephen Boyd
2016-04-26 17:04 ` Stefan Agner
2016-04-16 1:00 ` Stephen Boyd
2016-04-18 1:58 ` Shawn Guo
2016-04-21 3:45 ` Dong Aisheng
2016-04-26 1:23 ` Shawn Guo
2016-04-26 5:51 ` Dong Aisheng
2016-04-26 9:24 ` Shawn Guo
2016-04-26 9:31 ` Lucas Stach
2016-04-26 11:16 ` Dong Aisheng
2016-04-26 11:27 ` Dong Aisheng
2016-04-27 1:58 ` Shawn Guo
2016-04-27 2:45 ` Dong Aisheng
2016-04-27 2:56 ` Fabio Estevam
2016-04-27 7:28 ` Stefan Agner
2016-04-27 8:53 ` Dong Aisheng
2016-04-27 2:57 ` Dong Aisheng
2016-04-27 7:24 ` Shawn Guo
2016-04-27 7:26 ` Stefan Agner
2016-04-27 8:48 ` Dong Aisheng
2016-04-27 7:34 ` Stefan Agner
2016-04-27 8:57 ` Dong Aisheng
2016-04-27 10:15 ` Thomas Gleixner
2016-04-29 9:45 ` [RFC PATCH 1/1] clk: imx7d: move clk setting out of imx7d_clocks_init Dong Aisheng
2016-04-29 9:55 ` Dong Aisheng
2016-04-29 12:31 ` Lucas Stach
2016-04-30 2:04 ` Stefan Agner
2016-06-02 15:19 ` Dong Aisheng
2016-05-25 21:54 ` [PATCH 1/2] clk: imx: do not sleep if IRQ's are still disabled Stefan Agner
2016-06-02 14:59 ` Dong Aisheng
2016-06-06 13:20 ` Thomas Gleixner
2016-06-07 7:04 ` Dong Aisheng [this message]
2016-06-09 20:08 ` Thomas Gleixner
2016-06-09 22:14 ` Stefan Agner
2016-06-09 22:55 ` Thomas Gleixner
2016-06-12 12:24 ` Dong Aisheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160607070440.GA32573@shlinux2 \
--to=dongas86@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).