From: u.kleine-koenig@pengutronix.de (Uwe Kleine-König)
To: linux-arm-kernel@lists.infradead.org
Subject: Locking in the clk API
Date: Tue, 11 Jan 2011 11:39:29 +0100 [thread overview]
Message-ID: <20110111103929.GN24920@pengutronix.de> (raw)
In-Reply-To: <201101111744.59712.jeremy.kerr@canonical.com>
Hi,
On Tue, Jan 11, 2011 at 05:44:59PM +0800, Jeremy Kerr wrote:
> > I object to this as one of the purposes behind the clk API is to allow
> > power savings to be made, and unless we can perform clk enable/disable
> > from atomic contexts, the best you can do is enable the clock when the
> > device is probed and disable it when it's released.
> >
> > [...]
> >
> > Sometimes the only point that you know you need the clock enabled is when
> > your driver has already been called in an atomic context.
>
> .. provided that the enable (and subsequent things that depend on the clock
> signal to be valid) can't be deferred; I'm not sure how often this will be
> possible.
>
> So, it sounds like the best approach is to provide an atomic clk_enable. I
> agree with Sascha that the clk_enable and clk_enable_atomic polarity makes the
> most sense, so how about:
>
> int clk_enable(struct clk *clk)
> {
> might_sleep();
>
> [...]
> }
>
> int clk_enable_atomic(struct clk *clk)
> {
> BUG_ON(!(clk->flags & CLK_ATOMIC));
>
> [...]
> }
>
> Paul: even though you mention that the atomic clocks are the usual case, I
> think that this way around illustrates the atomic 'restriction' at the call
> site more clearly. When the drivers don't care about the atomicity,
> clk_enable() is fine. When drivers do need an atomic clock,
> clk_enable_atomic() shows this requirement.
I agree that we should try to make the clk api easy and consistent. So
if we can go the atomic way we should in my opinion.
On i.mx the roots in the clk hierarchy are plls, so it would be nice to
know how long it takes to enable these.
Back when I implemented clk support for ns921x I had a clock that made
me think that a sleeping implementation would be the way to go. I don't
remember the exact details. (It was the rtc clk.)
A quick look into Digi's BSP (digiEL-5.0) shows they implemented
something I suggested earlier here:
static int clk_enable_haslocknchange(struct clk *clk)
{
int ret = 0;
assert_spin_locked(&clk_lock);
BUG_ON(!test_bit(CLK_FLAG_CHANGESTATE, &clk->flags));
if (clk->usage++ == 0) {
if (clk->parent) {
ret = clk_enable_haslock(clk->parent);
if (ret)
goto err_enable_parent;
}
spin_unlock(&clk_lock);
if (clk->endisable)
ret = clk->endisable(clk, 1);
spin_lock(&clk_lock);
if (ret) {
clk_disable_parent_haslock(clk);
err_enable_parent:
clk->usage = 0;
}
}
return ret;
}
static int clk_enable_haslock(struct clk *clk)
{
int ret;
assert_spin_locked(&clk_lock);
if (__test_and_set_bit(CLK_FLAG_CHANGESTATE, &clk->flags))
return -EBUSY;
ret = clk_enable_haslocknchange(clk);
clear_bit(CLK_FLAG_CHANGESTATE, &clk->flags);
return ret;
}
int clk_enable(struct clk *clk)
{
...
spin_lock_irqsave(&clk_lock, flags);
ret = clk_enable_haslock(clk);
spin_unlock_irqrestore(&clk_lock, flags);
return ret;
}
I think the idea is nice. At least it allows with a single lock to
implement both, sleeping and atomic clks without the need to mark the
atomicity in a global flag.
In the meantime Sascha checked on mx51 how long it takes to enable one
of the three PLLs: 50us. Is this fast enough to accept disabled irqs
that long?
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | http://www.pengutronix.de/ |
next prev parent reply other threads:[~2011-01-11 10:39 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-11 2:16 Locking in the clk API Jeremy Kerr
2011-01-11 3:15 ` Paul Mundt
2011-01-11 4:11 ` Jeremy Kerr
2011-01-11 4:54 ` Paul Mundt
2011-01-20 16:32 ` Ben Dooks
2011-01-20 18:57 ` Russell King - ARM Linux
2011-01-21 3:43 ` Saravana Kannan
2011-01-21 9:31 ` Russell King - ARM Linux
2011-01-11 9:03 ` Sascha Hauer
2011-01-11 9:28 ` Russell King - ARM Linux
2011-01-11 14:34 ` Pavel Machek
2011-01-20 16:29 ` Ben Dooks
2011-01-20 18:56 ` Russell King - ARM Linux
2011-01-20 21:30 ` Nicolas Pitre
2011-01-21 2:06 ` Dima Zavin
2011-01-21 4:12 ` Saravana Kannan
2011-01-21 9:32 ` Russell King - ARM Linux
2011-01-22 1:53 ` Saravana Kannan
2011-01-22 2:24 ` Colin Cross
2011-01-22 2:56 ` Saravana Kannan
2011-01-22 9:15 ` Russell King - ARM Linux
2011-01-24 19:31 ` Saravana Kannan
2011-01-21 21:03 ` Dima Zavin
2011-01-21 21:53 ` Nicolas Pitre
2011-01-21 22:02 ` Russell King - ARM Linux
2011-01-21 22:28 ` Colin Cross
2011-01-21 23:21 ` Benjamin Herrenschmidt
2011-01-21 23:50 ` Nicolas Pitre
2011-01-22 1:35 ` Saravana Kannan
2011-01-22 2:22 ` Colin Cross
2011-01-21 22:29 ` Nicolas Pitre
2011-01-21 23:28 ` Bryan Huntsman
2011-01-11 9:16 ` Russell King - ARM Linux
2011-01-11 9:44 ` Jeremy Kerr
2011-01-11 10:13 ` Paul Mundt
2011-01-11 10:30 ` Jeremy Kerr
2011-01-11 12:18 ` Paul Mundt
2011-01-11 13:52 ` Uwe Kleine-König
2011-01-11 14:35 ` Jeremy Kerr
2011-01-12 3:25 ` Saravana Kannan
2011-01-12 7:40 ` Uwe Kleine-König
2011-01-12 1:54 ` Saravana Kannan
2011-01-12 2:25 ` Paul Mundt
2011-01-20 16:57 ` Ben Dooks
2011-01-20 16:53 ` Ben Dooks
2011-01-20 16:40 ` Ben Dooks
2011-01-11 10:39 ` Uwe Kleine-König [this message]
2011-01-11 10:47 ` Russell King - ARM Linux
2011-01-11 10:56 ` Uwe Kleine-König
2011-01-11 11:15 ` Richard Zhao
2011-01-20 17:02 ` Ben Dooks
2011-01-20 19:08 ` Russell King - ARM Linux
2011-01-21 0:09 ` Jassi Brar
2011-01-21 4:47 ` Jassi Brar
2011-01-21 9:39 ` Russell King - ARM Linux
2011-01-21 10:11 ` Jassi Brar
2011-01-22 4:08 ` Richard Zhao
2011-01-22 5:30 ` Jassi Brar
2011-01-21 7:16 ` Saravana Kannan
2011-01-21 9:40 ` Russell King - ARM Linux
2011-01-22 1:47 ` Saravana Kannan
2011-01-27 4:34 ` Saravana Kannan
2011-01-27 8:54 ` Russell King - ARM Linux
2011-01-27 20:30 ` Saravana Kannan
2011-01-27 20:43 ` Russell King - ARM Linux
2011-01-27 21:07 ` Alan Cox
2011-01-27 21:11 ` Russell King - ARM Linux
2011-01-27 21:15 ` Russell King - ARM Linux
2011-01-28 3:29 ` Saravana Kannan
2011-01-28 3:27 ` Saravana Kannan
2011-01-11 12:11 ` Jassi Brar
2011-01-12 2:56 ` Saravana Kannan
2011-01-12 9:03 ` Russell King - ARM Linux
2011-01-15 14:02 ` Christer Weinigel
2011-01-15 14:53 ` Russell King - ARM Linux
2011-01-15 15:03 ` Uwe Kleine-König
2011-01-15 15:15 ` Russell King - ARM Linux
2011-01-15 16:03 ` Uwe Kleine-König
2011-01-15 16:21 ` Russell King - ARM Linux
2011-01-15 16:31 ` Uwe Kleine-König
2011-01-16 6:59 ` Grant Likely
2011-01-15 17:07 ` Christer Weinigel
2011-01-15 17:20 ` Russell King - ARM Linux
2011-01-15 17:44 ` Christer Weinigel
2011-01-15 20:30 ` Russell King - ARM Linux
2011-01-17 1:19 ` Jeremy Kerr
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=20110111103929.GN24920@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--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).