linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Russell King - ARM Linux <linux@arm.linux.org.uk>
Cc: Jeremy Kerr <jeremy.kerr@canonical.com>,
	Ben Herrenchmidt <benh@kernel.crashing.org>,
	Richard Cochran <richardcochran@gmail.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 1/2] Add a common struct clk
Date: Fri, 7 Jan 2011 10:40:42 +0100	[thread overview]
Message-ID: <20110107094042.GA25121@pengutronix.de> (raw)
In-Reply-To: <20110107003205.GL31708@n2100.arm.linux.org.uk>

Hello Russell,

On Fri, Jan 07, 2011 at 12:32:05AM +0000, Russell King - ARM Linux wrote:
> On Fri, Jan 07, 2011 at 08:10:20AM +0800, Jeremy Kerr wrote:
> > Hi Richard,
> > 
> > > > > +struct clk {
> > > > > +	const struct clk_ops	*ops;
> > > > > +	unsigned int		enable_count;
> > > > > +	int			flags;
> > > > > +	union {
> > > > > +		struct mutex	mutex;
> > > > > +		spinlock_t	spinlock;
> > > > > +	} lock;
> > > > > +};
> > > > 
> > > > Here you have a "polymorphic" lock, where the clock instance knows
> > > > which type it is supposed to be.  I got flak from David Miller and
> > > > 
> > > > others trying to do the same thing with the mdio_bus:
> > > >    http://kerneltrap.org/mailarchive/linux-netdev/2010/7/6/6280618
> > > > 
> > > > The criticism, applied to your case, is that the clk_enable() caller
> > > > cannot know whether it is safe to make the call or not. I was told,
> > > > "there has got to be a better way."
> > > 
> > > Note that this is not "new".  Currently there is no convention available
> > > if clk_enable sleeps or not.  See e.g.
> > > http://thread.gmane.org/gmane.linux.ports.arm.kernel/100744
> > 
> > As Uwe says, the common clock does not change these semantics; I would prefer 
> > to keep the driver API changes at a minimum with these patches.
> > 
> > But yes, it would be a good idea to:
> > 
> >  * introduce clk_enable_atomic, which requires clk->flags & CLK_ATOMIC
> > 
> >  * add might_sleep to clk_enable(), encouraging clk uses in atomic contexts
> >    to switch to clk_enable_atomic.
> > 
> > We'd still be able to handle CLK_ATOMIC clocks in clk_enable(), so the 
> > enforcement only needs to be one-way.
> 
> I think the atomic stuff should be the norm through and through - otherwise
> we're going to end up with problems in drivers where they use the _atomic()
> stuff, but the clocks behind are coded to sleep.
> 
> I hate the GPIO APIs for doing this _cansleep crap as the decision of
> whether to use the _cansleep or normal APIs normally can't be made at
> the time when the API is used, but sometime later.  Many people just use
> the non-_cansleep versions irrespective of the context they're in -
> which is unnecessarily restrictive - consider what happens if you then
> have that driver use a GPIO on an I2C peripheral...
I'd prefer it the other way around, too.  (That is an atomic
gpio_set_value_atomic and a sleeping gpio_set_value.)  So if someone
uses the wrong one it's more likely that (s)he notices it.  Other than
that I agree that not having to do this would be preferable.

When applying the clk_enable_atomic stuff to the amba-pl011 driver (see
link above), I would just get a different error (clk_enable_atomic would
return -ESOMETHING instead of a backtrace about sleeping in atomic
context).  Hmm, not very useful.

On the other hand fixing the clk API to the sleeping or non-sleeping
approach has disadvantages, too:

 - sleeping
   doesn't allow enabling a clk in atomic context which (e.g. in the
   case of amba-pl011) provides maximal power saving.
 - atomic
   some clocks need long to become enabled, so long critical sections
   are introduced

Having a maxtracer for the clk_enable/disable functions would be great
to get some numbers.  I volunteer to try to add something like that to
the common clk thing when it is merged.  (Yes, I still think that
merging Jeremy's patches for .38 is good.)

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

  reply	other threads:[~2011-01-07  9:40 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-05  3:51 [PATCH 0/2] Common struct clk implementation, v10 Jeremy Kerr
2011-01-05  3:51 ` [PATCH 2/2] clk: Generic support for fixed-rate clocks Jeremy Kerr
2011-01-05  3:51 ` [PATCH 1/2] Add a common struct clk Jeremy Kerr
2011-01-06 16:07   ` Richard Cochran
2011-01-06 20:11     ` Uwe Kleine-König
2011-01-07  0:10       ` Jeremy Kerr
2011-01-07  0:32         ` Russell King - ARM Linux
2011-01-07  9:40           ` Uwe Kleine-König [this message]
2011-01-08 13:15   ` Sascha Hauer
2011-01-10  2:43     ` Jeremy Kerr
2011-01-10 10:41       ` Sascha Hauer
2011-01-10 11:00         ` Russell King - ARM Linux
2011-01-11  0:54           ` Jeremy Kerr
2011-01-16  7:26             ` Grant Likely
2011-01-16 20:41               ` Ryan Mallon
2011-01-16 21:07                 ` Uwe Kleine-König
2011-01-16 21:39                   ` Ryan Mallon
2011-01-11 10:16   ` Sascha Hauer
2011-01-11 10:27     ` Jeremy Kerr
2011-01-11 11:22       ` Sascha Hauer
2011-01-18  8:44         ` Paul Mundt
2011-01-18  9:21           ` Sascha Hauer
2011-01-18  9:23             ` Paul Mundt
2011-01-18 12:21   ` Russell King - ARM Linux
  -- strict thread matches above, loose matches on Subject: below --
2011-03-03  6:40 [PATCH 0/2] Common struct clk implementation, v14 Jeremy Kerr
2011-03-03  6:40 ` [PATCH 1/2] Add a common struct clk Jeremy Kerr
2011-04-14 12:49   ` Tony Lindgren
2011-02-21  2:50 [PATCH 0/2] Common struct clk implementation, v13 Jeremy Kerr
2011-02-21  2:50 ` [PATCH 1/2] Add a common struct clk Jeremy Kerr
2011-02-22 20:17   ` Uwe Kleine-König
2011-02-23  2:49     ` Jeremy Kerr
2010-12-08  2:08 [PATCH 0/2] Common struct clk implementation, v8 Jeremy Kerr
2010-12-08  2:08 ` [PATCH 1/2] Add a common struct clk Jeremy Kerr
2010-12-08  2:05 Jeremy Kerr
2010-12-08 10:21 ` Uwe Kleine-König
2010-12-10  1:58   ` Jeremy Kerr
2010-07-12  2:37 [PATCH 0/2] Common struct clk implementation, v6 Jeremy Kerr
2010-07-12  2:37 ` [PATCH 1/2] Add a common struct clk Jeremy Kerr
2010-06-21  5:35 [PATCH 0/2] Common struct clk implementation, v5 Jeremy Kerr
2010-06-21  5:35 ` [PATCH 1/2] Add a common struct clk Jeremy Kerr
2010-06-22  4:43   ` Baruch Siach
2010-07-05  2:33   ` MyungJoo Ham
2010-07-12  2: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=20110107094042.GA25121@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=benh@kernel.crashing.org \
    --cc=jeremy.kerr@canonical.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=richardcochran@gmail.com \
    /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).