From: skannan@codeaurora.org (Saravana Kannan)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH RFC] clk: add support for automatic parent handling
Date: Thu, 21 Apr 2011 21:54:03 -0700 [thread overview]
Message-ID: <4DB109EB.6000709@codeaurora.org> (raw)
In-Reply-To: <alpine.LFD.2.02.1104211632240.3323@ionos>
On 04/21/2011 08:38 AM, Thomas Gleixner wrote:
> On Thu, 21 Apr 2011, Sascha Hauer wrote:
>> On Thu, Apr 21, 2011 at 11:21:53AM +0200, Thomas Gleixner wrote:
>> That's why I tried to sort out some common patterns (divider, gates,
>> muxes) and put them into drivers/clk for other people to use it. It's
>> enough to build a whole clock tree out of it (except plls and special
>> stuff). All things you mentioned which are missing in the common clock
>> stuff can be added without touching the i.MX specific parts. You want
>> the framework (once it actually is one) to handle the parents? just move
>> the parent handling out of drivers/clk/clk-[divider|mux|gate].c to
>> drivers/clk/clk.c. Refcounting shall be fixed? do so in
>> drivers/clk/clkdev.c.
>
> The point is that we want to do stuff like that now - BEFORE anyone
> starts using struct clk and the helper functions.
>
>> I didn't say that the patches I posted shall be moved upstream as-is. I
>> only wanted to show how a clock tree can look like when we sort out
>> common patterns.
>
> We really want to get some sensible functionality for starting.
>
> So what I can see now from the discussion is that we should at least
> add the following fields to struct clk:
>
> unsigned long flags;
> unsigned long rate;
> struct clk *parent;
> unsigned int users;
>
> Add the parent propagation to the clk_enable disable prepare unprepare
> functions.
>
> And we should add right away:
>
> struct hlist_head childs;
> struct hlist_node node;
>
> Plus infrastructure to register clocks with the parent. Advanced
> things like bottom up propagation of clock rate changes is something
> we can do later, but we really want to make proper registration a
> required change for users of the new stuff.
>
> That brings in another question and this really needs to be answered
> now: Locking
>
> I'm pushing hard on this because I know that retrofitting proper
> locking schemes is going to be a nightmare.
>
> You already have a lock nesting problem when you do parent
> propagation. With your code you do the parent propagation in the child
> callback under the prepare_mutex or the enable_lock.
>
> This is going to end up in lockdep being quite unhappy unless you want
> tons of different lock classes for this stuff. i.e.
>
> clk_prepare(clk2)
> mutex_lock(clk2->mutex);
> clk->prepare(clk);
> clk_prepare(clk1)
> mutex_lock(clk1->mutex);
>
> And you _CANNOT_ call clk1->prepare() from your clk2 prepare function
> as it would forgo the serialization and the prepare refcounting. And
> this kind of scheme is going to be even more problematic if you do
> bottom up propagation because you will run into lock inversion.
>
> I seriously doubt that the fine grained per clock locking is going to
> work out at all.
>
> How do you protect changes to the tree hierarchy against a traversal
> of a concurrent clk->prepare... propagation? Not at all, because you
> CANNOT. And you cannot use RCU for this either.
>
> So what's the point of the per clk locks? I can't see one at all.
>
> All those callbacks are not high frequency called functions, so if you
> want to make this a true framework which deals with tons of
> interesting stuff like propagation, reparenting and rate changes from
> bottom up then there is only one way to do that: global serialization.
>
> There is no way around that. Everything else is going to be the
> locking hell and racy all over the place.
We (MSM guys) had to go thru this thought process when we did some
internal reorg of the clock code. Per clock locks prevent us from
slowing down clock manipulation of some fast clocks when there is
another call going on to manipulate slow clocks. There are some clocks
that are not controlled by writing to registers directly and they are
extremely slow compared to the usual set of clocks.
One thing we did to handle the locking issue was to have a lock per
"class" of clocks. For example, we had one lock for clocks controlled by
writing to registers, one lock for voting clocks that just do
aggregation and one lock for these extremely slow clocks. Since each
class of clocks are generally implemented in their own file, having one
lock per class was just a matter of declaring a static-global lock
inside the file and grabbing it before you do any transaction.
For example, there are some clocks that need to disable all the children
before changing their rate. So, what happens if someone calls
clk_enable() on the child when the parent is going thru a set rate
process. Since both these will grab the same "fast clocks lock", we
don't have any problems.
(Just read Colin's email)
As Colin said in his email, a global lock is less of an issue with the
clk_prepare/unprepare() APIs now in place. But even among
prepare/unprepare or enable/disable, some clocks might take much longer
than others. For example, prepare for a clock might just need enabling a
PLL, but for another clock it might need enabling a PLL and increasing
some voltage. If the voltage control is going to go thru I2C, then it's
going to be pretty bad for the other clock doing the prepare.
I think if we have the parent/child relationship captured in the generic
framework, we might be able to get away with per clock locking if we
always make sure we grab the locks in a top-down or bottom-up fashion.
We could even throw in some flags if we know that a clock will have a
stable parent (one that doesn't change rates or need to lock children)
to reduce how deep we have to traverse the tree.
-Saravana
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
next prev parent reply other threads:[~2011-04-22 4:54 UTC|newest]
Thread overview: 157+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-15 19:08 [RFC] sanitizing crazy clock data files Sascha Hauer
2011-04-15 19:08 ` [PATCH 01/10] Add a common struct clk Sascha Hauer
2011-04-21 19:48 ` Thomas Gleixner
2011-04-22 0:28 ` Richard Zhao
2011-04-22 9:23 ` Thomas Gleixner
2011-04-23 14:08 ` Richard Zhao
2011-04-23 15:30 ` Thomas Gleixner
2011-04-24 2:54 ` Richard Zhao
2011-04-24 7:20 ` Linus Walleij
2011-04-24 9:55 ` Richard Zhao
2011-04-22 4:57 ` Saravana Kannan
2011-04-22 9:13 ` Thomas Gleixner
2011-04-29 10:09 ` Russell King - ARM Linux
2011-04-29 10:45 ` Thomas Gleixner
2011-04-29 10:58 ` Tony Lindgren
2011-04-29 11:01 ` Russell King - ARM Linux
2011-04-30 18:30 ` Pavel Machek
2011-04-30 8:06 ` Linus Walleij
2011-04-30 9:01 ` Russell King - ARM Linux
2011-04-30 16:30 ` Linus Walleij
2011-05-01 20:33 ` Rob Herring
2011-05-02 1:09 ` Jeremy Kerr
2011-05-02 3:09 ` Rob Herring
2011-05-02 3:40 ` Jeremy Kerr
2011-05-02 16:30 ` Rob Herring
2011-05-02 22:36 ` Russell King - ARM Linux
2011-05-03 0:22 ` Saravana Kannan
2011-05-04 6:40 ` Sascha Hauer
2011-05-04 18:33 ` Saravana Kannan
2011-05-04 23:35 ` Paul Walmsley
2011-05-10 20:06 ` Saravana Kannan
2011-05-02 16:55 ` David Brown
2011-05-02 17:31 ` Stephen Boyd
2011-04-15 19:08 ` [PATCH 02/10] clk: Generic support for fixed-rate clocks Sascha Hauer
2011-04-15 19:08 ` [PATCH 03/10] clk: Make NULL a valid clock again Sascha Hauer
2011-04-19 0:53 ` Jeremy Kerr
2011-04-19 6:25 ` Sascha Hauer
2011-04-20 12:53 ` Uwe Kleine-König
2011-04-15 19:08 ` [PATCH 04/10] clk: implement parent pass through functions Sascha Hauer
2011-04-18 9:25 ` Uwe Kleine-König
2011-04-18 9:48 ` Sascha Hauer
2011-04-19 17:20 ` Stephen Boyd
2011-04-19 17:53 ` Sascha Hauer
2011-04-19 19:09 ` Uwe Kleine-König
2011-04-19 20:58 ` Sascha Hauer
2011-04-19 21:54 ` Thomas Gleixner
2011-04-20 7:16 ` Uwe Kleine-König
2011-04-20 8:34 ` Thomas Gleixner
2011-04-20 14:07 ` [PATCH RFC] clk: add support for automatic parent handling Uwe Kleine-König
2011-04-20 16:16 ` Thomas Gleixner
2011-04-20 18:59 ` Uwe Kleine-König
2011-04-20 19:52 ` Thomas Gleixner
2011-04-21 6:58 ` Saravana Kannan
2011-04-21 10:33 ` Thomas Gleixner
2011-04-21 19:22 ` torbenh
2011-04-23 23:26 ` Benjamin Herrenschmidt
2011-04-21 7:22 ` Uwe Kleine-König
2011-04-21 9:12 ` Thomas Gleixner
2011-04-21 10:31 ` Mark Brown
2011-04-21 11:42 ` Tony Lindgren
2011-04-21 14:52 ` Thomas Gleixner
2011-04-22 7:09 ` Tony Lindgren
2011-04-22 8:22 ` Thomas Gleixner
2011-04-21 14:29 ` Thomas Gleixner
2011-04-29 10:37 ` Russell King - ARM Linux
2011-04-29 11:01 ` Thomas Gleixner
2011-04-29 11:06 ` Russell King - ARM Linux
2011-04-29 12:13 ` Thomas Gleixner
2011-04-29 13:26 ` Russell King - ARM Linux
2011-04-29 15:31 ` Thomas Gleixner
2011-04-29 22:07 ` Russell King - ARM Linux
2011-04-29 22:16 ` Thomas Gleixner
2011-04-29 22:19 ` Russell King - ARM Linux
2011-04-29 22:47 ` Thomas Gleixner
2011-04-30 14:27 ` torbenh
2011-05-03 6:35 ` Colin Cross
2011-05-05 8:35 ` torbenh
2011-05-03 2:44 ` Saravana Kannan
2011-05-03 2:46 ` Saravana Kannan
2011-04-21 10:13 ` Mark Brown
2011-04-21 11:39 ` Tony Lindgren
2011-04-21 7:42 ` Sascha Hauer
2011-04-21 9:21 ` Thomas Gleixner
2011-04-21 11:50 ` Mark Brown
2011-04-21 12:20 ` Thomas Gleixner
2011-04-21 12:35 ` Mark Brown
2011-04-25 2:03 ` Richard Zhao
2011-04-25 10:57 ` Mark Brown
2011-04-25 14:41 ` Richard Zhao
2011-04-25 14:44 ` Mark Brown
2011-04-29 10:49 ` Russell King - ARM Linux
2011-04-29 11:11 ` Thomas Gleixner
2011-04-29 11:38 ` Russell King - ARM Linux
2011-04-29 12:19 ` Thomas Gleixner
2011-04-29 13:27 ` Russell King - ARM Linux
2011-04-29 15:47 ` Thomas Gleixner
2011-04-21 12:06 ` Sascha Hauer
2011-04-21 15:38 ` Thomas Gleixner
2011-04-22 0:23 ` Colin Cross
2011-04-22 9:51 ` Thomas Gleixner
2011-04-22 16:14 ` Thomas Gleixner
2011-04-22 16:39 ` Colin Cross
2011-04-22 16:57 ` Thomas Gleixner
2011-04-22 22:26 ` Saravana Kannan
2011-04-22 22:55 ` Thomas Gleixner
2011-04-23 0:48 ` Saravana Kannan
2011-04-23 23:34 ` Benjamin Herrenschmidt
2011-04-22 4:54 ` Saravana Kannan [this message]
2011-04-22 9:06 ` Thomas Gleixner
2011-04-29 10:30 ` Russell King - ARM Linux
2011-04-29 10:51 ` Thomas Gleixner
2011-04-29 10:56 ` Russell King - ARM Linux
2011-04-24 9:45 ` Richard Zhao
2011-04-24 20:14 ` Uwe Kleine-König
2011-04-29 10:20 ` [PATCH 04/10] clk: implement parent pass through functions Russell King - ARM Linux
2011-04-15 19:08 ` [PATCH 05/10] clk: Add support for simple dividers Sascha Hauer
2011-04-18 9:49 ` Uwe Kleine-König
2011-04-18 10:07 ` Sascha Hauer
2011-04-19 2:45 ` Saravana Kannan
2011-04-19 7:32 ` Uwe Kleine-König
2011-04-19 8:55 ` Saravana Kannan
2011-04-19 9:31 ` Sascha Hauer
2011-04-19 22:28 ` Saravana Kannan
2011-04-20 6:36 ` Sascha Hauer
2011-04-20 21:45 ` Saravana Kannan
2011-04-21 7:39 ` Uwe Kleine-König
2011-04-28 15:14 ` Russell King - ARM Linux
2011-05-03 3:37 ` Saravana Kannan
2011-05-03 7:12 ` Uwe Kleine-König
2011-04-28 15:22 ` Russell King - ARM Linux
2011-05-02 7:58 ` Sascha Hauer
2011-04-18 22:40 ` Stephen Boyd
2011-04-19 0:32 ` Jeremy Kerr
2011-04-19 5:41 ` Stephen Boyd
2011-04-24 13:48 ` Richard Zhao
2011-04-25 18:51 ` Sascha Hauer
2011-04-26 1:54 ` Richard Zhao
2011-04-15 19:08 ` [PATCH 06/10] clk: Add support for a generic clock multiplexer Sascha Hauer
2011-04-18 13:15 ` Uwe Kleine-König
2011-04-18 13:33 ` Sascha Hauer
2011-04-18 13:54 ` Uwe Kleine-König
2011-04-18 17:54 ` Stephen Boyd
2011-04-18 18:34 ` Russell King - ARM Linux
2011-04-18 18:41 ` Russell King - ARM Linux
2011-04-18 18:46 ` Stephen Boyd
2011-04-15 19:08 ` [PATCH 07/10] ARM i.MX: Support for clock building blocks Sascha Hauer
2011-04-15 19:08 ` [PATCH 08/10] ARM i.MX: Add generic support for pllv2 Sascha Hauer
2011-04-15 19:08 ` [PATCH 09/10] ARM i.MX51/53: reimplement clock support Sascha Hauer
2011-04-15 19:08 ` [PATCH 10/10] ARM i.MX51/53: remove old " Sascha Hauer
2011-04-15 19:36 ` [RFC] sanitizing crazy clock data files Russell King - ARM Linux
2011-04-15 20:12 ` Sascha Hauer
2011-04-15 20:25 ` Russell King - ARM Linux
2011-04-15 20:28 ` Russell King - ARM Linux
2011-04-15 20:49 ` Uwe Kleine-König
2011-04-18 4:07 ` Shawn Guo
2011-04-15 20:45 ` Uwe Kleine-König
2011-04-18 7:42 ` Sascha Hauer
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=4DB109EB.6000709@codeaurora.org \
--to=skannan@codeaurora.org \
--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).