Skip to contentSkip to conversation

ARM: imx: clk-pllv3: move the timeout just before the comparison

PATCH New Peter Chen 4 participants 5 messages Jul 14, 2013 – Jul 15, 2013

Subsystems (3)
lore
Share & tools
lore

Peter Chen

author
#0 lore raw

PATCH 1/1 ARM: imx: clk-pllv3: move the timeout just before the comparison

It can let the timeout value be more precise.

---
 arch/arm/mach-imx/clk-pllv3.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/arm/mach-imx/clk-pllv3.c +2 -1
index a9fad5f..e2c026f 100644
@@ -48,7 +48,7 @@ struct clk_pllv3 {
 static int clk_pllv3_prepare(struct clk_hw *hw)
 {
 	struct clk_pllv3 *pll = to_clk_pllv3(hw);
-	unsigned long timeout = jiffies + msecs_to_jiffies(10);
+	unsigned long timeout;
 	u32 val;
 
 	val = readl_relaxed(pll->base);
@@ -59,6 +59,7 @@ static int clk_pllv3_prepare(struct clk_hw *hw)
 		val &= ~BM_PLL_POWER;
 	writel_relaxed(val, pll->base);
 
+	timeout = jiffies + msecs_to_jiffies(10);
 	/* Wait for PLL to lock */
 	while (!(readl_relaxed(pll->base) & BM_PLL_LOCK))
 		if (time_after(jiffies, timeout))
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 1/1 ARM: imx: clk-pllv3: move the timeout just before the comparison

Quoted 3 lines · Peter Chen

It can let the timeout value be more precise.

Whoever applies this patch, can you make the ? an ? (or at least "oe")?

Peter, does this fix anything for you? Would be nice to mention that in the commit log.

Best regards
Uwe

Quoted 31 lines
---
 arch/arm/mach-imx/clk-pllv3.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/arm/mach-imx/clk-pllv3.c +2 -1
index a9fad5f..e2c026f 100644
@@ -48,7 +48,7 @@ struct clk_pllv3 {
 static int clk_pllv3_prepare(struct clk_hw *hw)
 {
 	struct clk_pllv3 *pll = to_clk_pllv3(hw);
-	unsigned long timeout = jiffies + msecs_to_jiffies(10);
+	unsigned long timeout;
 	u32 val;
 
 	val = readl_relaxed(pll->base);
@@ -59,6 +59,7 @@ static int clk_pllv3_prepare(struct clk_hw *hw)
 		val &= ~BM_PLL_POWER;
 	writel_relaxed(val, pll->base);
 
+	timeout = jiffies + msecs_to_jiffies(10);
 	/* Wait for PLL to lock */
 	while (!(readl_relaxed(pll->base) & BM_PLL_LOCK))
 		if (time_after(jiffies, timeout))
Signature · 1 line
1.7.0.4
Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#2 lore raw

PATCH 1/1 ARM: imx: clk-pllv3: move the timeout just before the comparison

Quoted 5 lines · Uwe Kleine-K?nig
Quoted 3 lines · Peter Chen

It can let the timeout value be more precise.

Whoever applies this patch, can you make the ? an ? (or at least "oe")?

Oh, sorry.

Quoted 3 lines

Peter, does this fix anything for you? Would be nice to mention that in the commit log.

The root cause of this PLL lock timeout problem is:

http://marc.info/?l=linux-arm-kernel&m=137109340222931&w=2

If causes the jiffies is not precise sometimes. This commit is just an improvement.

Quoted 36 lines
Quoted 31 lines
---
 arch/arm/mach-imx/clk-pllv3.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/arm/mach-imx/clk-pllv3.c +2 -1
index a9fad5f..e2c026f 100644
@@ -48,7 +48,7 @@ struct clk_pllv3 {
 static int clk_pllv3_prepare(struct clk_hw *hw)
 {
 	struct clk_pllv3 *pll = to_clk_pllv3(hw);
-	unsigned long timeout = jiffies + msecs_to_jiffies(10);
+	unsigned long timeout;
 	u32 val;
 
 	val = readl_relaxed(pll->base);
@@ -59,6 +59,7 @@ static int clk_pllv3_prepare(struct clk_hw *hw)
 		val &= ~BM_PLL_POWER;
 	writel_relaxed(val, pll->base);
 
+	timeout = jiffies + msecs_to_jiffies(10);
 	/* Wait for PLL to lock */
 	while (!(readl_relaxed(pll->base) & BM_PLL_LOCK))
 		if (time_after(jiffies, timeout))
Signature · 1 line
1.7.0.4
Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Signature · 2 lines
Best Regards,
Peter Chen
reviewer
#3 lore raw

PATCH 1/1 ARM: imx: clk-pllv3: move the timeout just before the comparison

Hi Peter,

Quoted 6 lines · Peter Chen

The root cause of this PLL lock timeout problem is:

http://marc.info/?l=linux-arm-kernel&m=137109340222931&w=2

If causes the jiffies is not precise sometimes. This commit is just an improvement.

Your commit log does not explain what it improves, and why/how it improves things.

Please provide a better description in the commit log.

maintainer
#4 lore raw

PATCH 1/1 ARM: imx: clk-pllv3: move the timeout just before the comparison

In reply to Peter Chen
Quoted 22 lines · Peter Chen

It can let the timeout value be more precise.

---
 arch/arm/mach-imx/clk-pllv3.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/arm/mach-imx/clk-pllv3.c +1 -1
index a9fad5f..e2c026f 100644
@@ -48,7 +48,7 @@ struct clk_pllv3 {
 static int clk_pllv3_prepare(struct clk_hw *hw)
 {
 	struct clk_pllv3 *pll = to_clk_pllv3(hw);
-	unsigned long timeout = jiffies + msecs_to_jiffies(10);
+	unsigned long timeout;
 	u32 val;
 
 	val = readl_relaxed(pll->base);

arch/arm/mach-imx/clk-pllv3.c static int clk_pllv3_prepare(struct clk_hw *hw) · line 65

Quoted 7 lines
arch/arm/mach-imx/clk-pllv3.c +1 -0
@@ -59,6 +59,7 @@ static int clk_pllv3_prepare(struct clk_hw *hw)
 		val &= ~BM_PLL_POWER;
 	writel_relaxed(val, pll->base);
 
+	timeout = jiffies + msecs_to_jiffies(10);
 	/* Wait for PLL to lock */
 	while (!(readl_relaxed(pll->base) & BM_PLL_LOCK))
 		if (time_after(jiffies, timeout))

For a proper timeout loop you have to check the condition once after the timeout, like this:

	while (1) {
		if (condition)
			break;
		if (time_after())
			break;
	}

	if (condition)
		res = OK;
	else
		res = -ETIMEDOUT;

Otherwise you risk being scheduled away after checking the condition but before checking the timeout.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |