linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: lethal@linux-sh.org (Paul Mundt)
To: linux-arm-kernel@lists.infradead.org
Subject: Locking in the clk API
Date: Tue, 11 Jan 2011 13:54:23 +0900	[thread overview]
Message-ID: <20110111045423.GP3760@linux-sh.org> (raw)
In-Reply-To: <201101111211.30172.jeremy.kerr@canonical.com>

Hi Jeremy,

On Tue, Jan 11, 2011 at 12:11:29PM +0800, Jeremy Kerr wrote:
> > This looks like a complete disaster, and is also completely inconsistent
> > with how the API is being used by the vast majority of users today.
> 
> I've been basing this on the mxc clock code, which acquires a mutex for all 
> clk_enable()s. This may not be representative of the majority of clock usage.
> 
> From a quick search there are a few other cases of non-atomic clock usage:
> 
> tcc:		clk_enable() acquires a global clocks_mutex
> tegra:	has a clk_enable_cansleep()
> davinci: clk_set_parent() aquires a global clocks_mutex
> 
> Excluding the davinci code (we won't worry about set_parent for now...), if we 
> can port mxc and tcc to a sleepable clk_enable, perhaps we could just go with 
> purely atomic operations.
> 
> We'd still need some method of using sleeping clocks though. How about making 
> clk_enable() BUG if the clock is not atomic, and add clk_enable_cansleep() for 
> the cases where clk->ops.enable may sleep.
> 
Yes, that sounds reasonable. I don't particularly care for the atomic
flag on the clock however since that's really the default behaviour for
almost everyone at the moment. On the other hand, the mutex API will
already blow up if someone tries to grab it within atomic context (with
the _trylock exception). Still, making the API explicit and tossing in a
might_sleep() or so will at least help figure out which assumptions are
being made and/or violated.

> Do we need something similar for other parts of the API? (clk_set_rate?)
> 
I suppose that's an inevitable thing at least in terms of keeping the API
balanced and consistent.

One other thing to be aware of is that the clkdev code maintains its own
list mutex, so the addition and deletion of clkdev lookups in addition to
the clkdev-backed clk_get() will all be sleepable. It would however be
possible to back a one-shot atomic-safe clk_get() with a mutex_trylock()
for the common cases, but it's not entirely obvious that it would be
worth the complexity it would introduce.

If you're going to do this work it would also be helpful to spell out the
locking semantics within linux/clk.h at the same time (it might even be
worthwhile doing this incrementally and getting all of the platforms
in-line before attempting to consolidate things too aggressively), as
it's apparent from the cases you cite there are at least a couple of
boards that aren't quite in line with what everyone else is doing.

In general we have to accept that the dynamic creation, deletion, and
looking up of clocks is going to be a sleepable case, and the rest will
likely have to be split out in to _cansleep and default atomic-safe
variants.

set_rate/parent and friends likewise are done atomically for some and
sleepable for others, so it doesn't seem like there's going to be much
choice other than simply splitting out the API for these cases.

Also, I'm not sure if you've noticed yet or not, but note that there is
now a drivers/clk due to the shuffling of the clkdev code, so you may
want to piggyback on top of this instead of using the top-level kernel/

  reply	other threads:[~2011-01-11  4:54 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 [this message]
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
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=20110111045423.GP3760@linux-sh.org \
    --to=lethal@linux-sh.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).