linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: christer@weinigel.se (Christer Weinigel)
To: linux-arm-kernel@lists.infradead.org
Subject: Locking in the clk API
Date: Sat, 15 Jan 2011 15:02:25 +0100	[thread overview]
Message-ID: <4D31A8F1.4080301@weinigel.se> (raw)
In-Reply-To: <20110112090301.GS11039@n2100.arm.linux.org.uk>

On 01/12/2011 10:03 AM, Russell King - ARM Linux wrote:

> That never has been, and that is called for the _system_ going into
> suspend.  That's not what I'm talking about.  I'm talking about drivers
> doing their own power management in response to (a) their knowledge of
> how the device behaves and (b) in response to the user state they know.
>
> In the case of a UART, that means enabling the clock when the user opens
> the device and turning it off when the user closes the device - and in
> the case of the UART being used as the system console, enabled when
> printk calls it, disabled when finished outputting the message.

 >

> The latter is a case where you're called in atomic context.


This feels a bit like perfect being the enemy of good.

On platforms that need to sleep to enable the UART clock, configuring 
the UART as the kernel console should be equivalent to userspace opening 
the UART device, i.e. enable the clock.  At least to me that feels like 
an acceptable tradeoff, and if I wanted to save the last bit of power 
I'll have to refrain from using UART as the kernel console.

If both printk to the console and disabling the clock is really really 
neccesary, add a clk_enable_busywait, but that will be a bit of a hack.


> Another case - a storage device.  While you may receive open/close calls,
> these are meaningless for power management - you'll receive an open call
> when you mount a filesystem, and a close call when you finally unmount it.
> That doesn't mean it's going to be used.  Your request handler will
> generally run in an atomic context, so in order to do dynamic power
> saving you need to be able to enable/disable clocks in that context.



> A touchscreen controller which you communicate with over a dedicated bus.
> The touchscreen controller doesn't require the host to be constantly
> clocked - it only needs to be clocked when communicating with the
> touchscreen.  The touchscreen controller raises an interrupt for service.
> You'd want to enable the clock in the interrupt handler to communicate
> with the device and turn it off afterwards.


Both of these feel like they should use a call such as clk_get_atomic 
and be able to handle EWOULDBLOCK/EAGAIN (or whatever error code is used 
to indicate that it would have to sleep) and delegate to a worker thread 
to enable the clock.  To catch uses of plain clk_enable from atomic 
contects, add a WARN_ON/BUG_ON(in_atomic()).  It won't catch everything, 
but would help a bit at least.

Someone suggested splitting clk_enable into a part that can sleep and a 
part that can't, would that be workable?  I.e. extend clk_get so that it 
knows what requirements the driver has on the clock.  So a driver that does:

     clk_get(dev, "my_clk", CLK_CANSLEEP);

must then either use clk_enable from contexts which can sleep or use 
clk_enable_atomic and be able to handle EWOULDBLOCK.

A driver which can't handle EWOULDBLOCK would do:

     clk_get(dev, "my_clk", CLK_ATOMIC)

informing the clock subsystem that clk_enable_atomic must always 
succeed.  If the clock source driver can't do that it has to enable the 
clock at clk_get time instead of at clk_enable time.  If a clock 
requires a potentially slow PLL setup which needs to sleep but can gate 
the clock atomically, do the PLL setup from clk_get and the gating from 
clk_enable.  This means that a clock might be on when it strictly isn't 
necessary, but at least it will be correct and assuming that Peter Mundt 
is correct in saying that the sleeping clock case is a corner case this 
will usually not be a problem.

For the corner cases where someone ports a driver that uses CLK_ATOMIC 
to a system with sleeping clocks and wants the last bit of power saving, 
the burden is on that someone to add EWOULDBLOCK support to the driver.

Regarding the other functions in the clock API, generic code in 
clk_disable_atomic could check if it is a sleeping clock and based on 
that call clk_disable directly or delegate the call to a worker thread. 
  All other functions should be able to sleep, with the possible 
exception of clk_get_rate which could be useful so that a driver can 
check if the clock is running at the correct rate from atomic context 
and delegate to a worker thread to change the clock rate if it is not.

To avoid unnecessary code churn it might be better to say that plain 
clk_enable is the atomic variant and if it is a sleeping clock it will 
be enbled at the time plain clk_get is called.  People who want to use 
sleeping clocks can then modify a driver at a time to use 
clk_get_cansleep and clk_enable_cansleep.  But I must say that the name 
clk_enable_atomic feels a lot cleaner.

   /Christer

  reply	other threads:[~2011-01-15 14:02 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
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 [this message]
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=4D31A8F1.4080301@weinigel.se \
    --to=christer@weinigel.se \
    --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).