diff mbox

[v7,1/2] provide lock-less versions of clk_{enable|disable}

Message ID 1481302773-14181-1-git-send-email-abailon@baylibre.com
State New
Headers show

Commit Message

Alexandre Bailon Dec. 9, 2016, 4:59 p.m. UTC
Rename __clk_{enable|disble} in davinci_clk_{enable|disable}.
davinci_clk_{enable|disable} is a lock-less version of
clk_{enable|disable}.
This is useful to recursively enable clock without doing recursive call
to clk_enable(), which would cause a recursive locking issue.
The lock-less version could be used by example by the usb20 phy clock,
that need to enable the usb20 clock before to start.

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>

Suggested-by: David Lechner <david@lechnology.com>
---
 arch/arm/mach-davinci/clock.c | 12 ++++++------
 arch/arm/mach-davinci/clock.h |  2 ++
 2 files changed, 8 insertions(+), 6 deletions(-)

-- 
2.7.3


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Comments

Uwe Kleine-König Dec. 9, 2016, 6:54 p.m. UTC | #1
Hello,

On Fri, Dec 09, 2016 at 05:59:32PM +0100, Alexandre Bailon wrote:
> Rename __clk_{enable|disble} in davinci_clk_{enable|disable}.

> davinci_clk_{enable|disable} is a lock-less version of

> clk_{enable|disable}.

> This is useful to recursively enable clock without doing recursive call

> to clk_enable(), which would cause a recursive locking issue.

> The lock-less version could be used by example by the usb20 phy clock,

> that need to enable the usb20 clock before to start.


I wouldn't call that lock-less. The difference is that the newly exposed
funcion requires the caller to already hold the lock. So maybe a better
name would be clk_enable_locked.

Would it be more sensible to convert davinci to common-clk?

Best regards
Uwe

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Sekhar Nori Dec. 12, 2016, 9:02 a.m. UTC | #2
Hi Uwe,

On Saturday 10 December 2016 12:24 AM, Uwe Kleine-König wrote:
> Hello,

> 

> On Fri, Dec 09, 2016 at 05:59:32PM +0100, Alexandre Bailon wrote:

>> Rename __clk_{enable|disble} in davinci_clk_{enable|disable}.

>> davinci_clk_{enable|disable} is a lock-less version of

>> clk_{enable|disable}.

>> This is useful to recursively enable clock without doing recursive call

>> to clk_enable(), which would cause a recursive locking issue.

>> The lock-less version could be used by example by the usb20 phy clock,

>> that need to enable the usb20 clock before to start.

> 

> I wouldn't call that lock-less. The difference is that the newly exposed

> funcion requires the caller to already hold the lock. So maybe a better


Right.

> name would be clk_enable_locked.


I am not sure the new name you propose is much clearer. Unless I am
missing an obvious naming pattern in kernel. Besides, I want to have the
"davinci_" prefix for consistency with how other mach-davinci internal
functions are named. FWIW, the equivalent function in common-clk is
called clk_core_enable().

> 

> Would it be more sensible to convert davinci to common-clk?


Yes, but there is no work going on on that and AFAIK, know one is
planning on working on it too. These patches are needed anyway since we
need to fix the existing issue on v4.10

Thanks,
Sekhar


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Alexandre Bailon Dec. 12, 2016, 10:27 a.m. UTC | #3
On 12/12/2016 10:02 AM, Sekhar Nori wrote:
> Hi Uwe,

> 

> On Saturday 10 December 2016 12:24 AM, Uwe Kleine-König wrote:

>> Hello,

>>

>> On Fri, Dec 09, 2016 at 05:59:32PM +0100, Alexandre Bailon wrote:

>>> Rename __clk_{enable|disble} in davinci_clk_{enable|disable}.

>>> davinci_clk_{enable|disable} is a lock-less version of

>>> clk_{enable|disable}.

>>> This is useful to recursively enable clock without doing recursive call

>>> to clk_enable(), which would cause a recursive locking issue.

>>> The lock-less version could be used by example by the usb20 phy clock,

>>> that need to enable the usb20 clock before to start.

>>

>> I wouldn't call that lock-less. The difference is that the newly exposed

>> funcion requires the caller to already hold the lock. So maybe a better

> 

> Right.

Is it enough to update the commit message or should I also update the
patch title?
If so, could you suggest one because I don't know how to describe it
shortly.

Thanks,
Alexandre


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
David Lechner Dec. 16, 2016, 8:41 p.m. UTC | #4
On 12/12/2016 04:27 AM, Alexandre Bailon wrote:
> On 12/12/2016 10:02 AM, Sekhar Nori wrote:

>> Hi Uwe,

>>

>> On Saturday 10 December 2016 12:24 AM, Uwe Kleine-König wrote:

>>> Hello,

>>>

>>> On Fri, Dec 09, 2016 at 05:59:32PM +0100, Alexandre Bailon wrote:

>>>> Rename __clk_{enable|disble} in davinci_clk_{enable|disable}.

>>>> davinci_clk_{enable|disable} is a lock-less version of

>>>> clk_{enable|disable}.

>>>> This is useful to recursively enable clock without doing recursive call

>>>> to clk_enable(), which would cause a recursive locking issue.

>>>> The lock-less version could be used by example by the usb20 phy clock,

>>>> that need to enable the usb20 clock before to start.

>>>

>>> I wouldn't call that lock-less. The difference is that the newly exposed

>>> funcion requires the caller to already hold the lock. So maybe a better

>>

>> Right.

> Is it enough to update the commit message or should I also update the

> patch title?

> If so, could you suggest one because I don't know how to describe it

> shortly.


How about... "ARM: davinci: Make __clk_{enable,disable} functions public"





>

> Thanks,

> Alexandre

>



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Sekhar Nori Dec. 18, 2016, 3:51 p.m. UTC | #5
On Saturday 17 December 2016 02:11 AM, David Lechner wrote:
> On 12/12/2016 04:27 AM, Alexandre Bailon wrote:

>> On 12/12/2016 10:02 AM, Sekhar Nori wrote:

>>> Hi Uwe,

>>>

>>> On Saturday 10 December 2016 12:24 AM, Uwe Kleine-König wrote:

>>>> Hello,

>>>>

>>>> On Fri, Dec 09, 2016 at 05:59:32PM +0100, Alexandre Bailon wrote:

>>>>> Rename __clk_{enable|disble} in davinci_clk_{enable|disable}.

>>>>> davinci_clk_{enable|disable} is a lock-less version of

>>>>> clk_{enable|disable}.

>>>>> This is useful to recursively enable clock without doing recursive

>>>>> call

>>>>> to clk_enable(), which would cause a recursive locking issue.

>>>>> The lock-less version could be used by example by the usb20 phy clock,

>>>>> that need to enable the usb20 clock before to start.

>>>>

>>>> I wouldn't call that lock-less. The difference is that the newly

>>>> exposed

>>>> funcion requires the caller to already hold the lock. So maybe a better

>>>

>>> Right.

>> Is it enough to update the commit message or should I also update the

>> patch title?

>> If so, could you suggest one because I don't know how to describe it

>> shortly.

> 

> How about... "ARM: davinci: Make __clk_{enable,disable} functions public"


Looks fine to me, here is the updated subject line and commit text. No
need to resend just for this, I can adjust when applying.

"
ARM: davinci: Make __clk_{enable,disable} functions public

In some cases, there is a need to enable a clock as part of clock
enable callback of a different clock. For example, USB 2.0 PHY clock
enable requires USB 2.0 clock to be enabled. In this case, it is safe to
instead call  __clk_enable() since the clock framework lock is already
taken. calling clk_enable() causes recursive locking error.

A similar case arises in the clock disable path.

To enable such usage, make __clk_{enable,disable} functions publicly
available outside of clock.c. Also, call them
davinci_clk_{enable|disable} now to be consistent with how other
davinci-specific clock functions are named.

Note that these functions are not exported to drivers. They are meant
for usage in platform specific clock management code.
"

Thanks,
Sekhar

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Sekhar Nori Jan. 2, 2017, 10:43 a.m. UTC | #6
On Sunday 18 December 2016 09:21 PM, Sekhar Nori wrote:
> ARM: davinci: Make __clk_{enable,disable} functions public

> 

> In some cases, there is a need to enable a clock as part of clock

> enable callback of a different clock. For example, USB 2.0 PHY clock

> enable requires USB 2.0 clock to be enabled. In this case, it is safe to

> instead call  __clk_enable() since the clock framework lock is already

> taken. calling clk_enable() causes recursive locking error.

> 

> A similar case arises in the clock disable path.

> 

> To enable such usage, make __clk_{enable,disable} functions publicly

> available outside of clock.c. Also, call them

> davinci_clk_{enable|disable} now to be consistent with how other

> davinci-specific clock functions are named.

> 

> Note that these functions are not exported to drivers. They are meant

> for usage in platform specific clock management code.


Applied to 'fixes' with above commit text.

Thanks,
Sekhar

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
diff mbox

Patch

diff --git a/arch/arm/mach-davinci/clock.c b/arch/arm/mach-davinci/clock.c
index df42c93..f5dce9b 100644
--- a/arch/arm/mach-davinci/clock.c
+++ b/arch/arm/mach-davinci/clock.c
@@ -31,10 +31,10 @@  static LIST_HEAD(clocks);
 static DEFINE_MUTEX(clocks_mutex);
 static DEFINE_SPINLOCK(clockfw_lock);
 
-static void __clk_enable(struct clk *clk)
+void davinci_clk_enable(struct clk *clk)
 {
 	if (clk->parent)
-		__clk_enable(clk->parent);
+		davinci_clk_enable(clk->parent);
 	if (clk->usecount++ == 0) {
 		if (clk->flags & CLK_PSC)
 			davinci_psc_config(clk->domain, clk->gpsc, clk->lpsc,
@@ -44,7 +44,7 @@  static void __clk_enable(struct clk *clk)
 	}
 }
 
-static void __clk_disable(struct clk *clk)
+void davinci_clk_disable(struct clk *clk)
 {
 	if (WARN_ON(clk->usecount == 0))
 		return;
@@ -56,7 +56,7 @@  static void __clk_disable(struct clk *clk)
 			clk->clk_disable(clk);
 	}
 	if (clk->parent)
-		__clk_disable(clk->parent);
+		davinci_clk_disable(clk->parent);
 }
 
 int davinci_clk_reset(struct clk *clk, bool reset)
@@ -103,7 +103,7 @@  int clk_enable(struct clk *clk)
 		return -EINVAL;
 
 	spin_lock_irqsave(&clockfw_lock, flags);
-	__clk_enable(clk);
+	davinci_clk_enable(clk);
 	spin_unlock_irqrestore(&clockfw_lock, flags);
 
 	return 0;
@@ -118,7 +118,7 @@  void clk_disable(struct clk *clk)
 		return;
 
 	spin_lock_irqsave(&clockfw_lock, flags);
-	__clk_disable(clk);
+	davinci_clk_disable(clk);
 	spin_unlock_irqrestore(&clockfw_lock, flags);
 }
 EXPORT_SYMBOL(clk_disable);
diff --git a/arch/arm/mach-davinci/clock.h b/arch/arm/mach-davinci/clock.h
index e2a5437..fa2b837 100644
--- a/arch/arm/mach-davinci/clock.h
+++ b/arch/arm/mach-davinci/clock.h
@@ -132,6 +132,8 @@  int davinci_set_sysclk_rate(struct clk *clk, unsigned long rate);
 int davinci_set_refclk_rate(unsigned long rate);
 int davinci_simple_set_rate(struct clk *clk, unsigned long rate);
 int davinci_clk_reset(struct clk *clk, bool reset);
+void davinci_clk_enable(struct clk *clk);
+void davinci_clk_disable(struct clk *clk);
 
 extern struct platform_device davinci_wdt_device;
 extern void davinci_watchdog_reset(struct platform_device *);