Skip to contentSkip to conversation

cpufreq: dt: disable unsupported OPPs

PATCH RESEND Superseded Lucas Stach 5 participants 22 messages Sep 30, 2014 – Oct 24, 2014

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 cpufreq: dt: disable unsupported OPPs

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

---
resend:
- no functional change, split out from the imx5 cpufreq series v2:
- rebase on top of pm/linux-next

---
 drivers/cpufreq/cpufreq-cpu0.c | 66 +++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 26 deletions(-)
drivers/cpufreq/cpufreq-cpu0.c +40 -26
index a5f8c5f5f4f4..5d73efbd0240 100644
@@ -185,6 +185,7 @@ static int cpu0_cpufreq_init(struct cpufreq_policy *policy)
 	struct device *cpu_dev;
 	struct regulator *cpu_reg;
 	struct clk *cpu_clk;
+	unsigned long min_uV = ~0, max_uV = 0;
 	unsigned int transition_latency;
 	int ret;
 
@@ -204,16 +205,10 @@ static int cpu0_cpufreq_init(struct cpufreq_policy *policy)
 	/* OPPs might be populated at runtime, don't check for error here */
 	of_init_opp_table(cpu_dev);
 
-	ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
-	if (ret) {
-		dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
-		goto out_put_node;
-	}
-
 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
 	if (!priv) {
 		ret = -ENOMEM;
-		goto out_free_table;
+		goto out_put_node;
 	}
 
 	of_property_read_u32(np, "voltage-tolerance", &priv->voltage_tolerance);
@@ -222,30 +217,49 @@ static int cpu0_cpufreq_init(struct cpufreq_policy *policy)
 		transition_latency = CPUFREQ_ETERNAL;
 
 	if (!IS_ERR(cpu_reg)) {
-		struct dev_pm_opp *opp;
-		unsigned long min_uV, max_uV;
-		int i;
-
 		/*
-		 * OPP is maintained in order of increasing frequency, and
-		 * freq_table initialised from OPP is therefore sorted in the
-		 * same order.
+		 * Disable any OPPs where the connected regulator isn't able to
+		 * provide the specified voltage and record minimum and maximum
+		 * voltage levels.
 		 */
-		for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++)
-			;
-		rcu_read_lock();
-		opp = dev_pm_opp_find_freq_exact(cpu_dev,
-				freq_table[0].frequency * 1000, true);
-		min_uV = dev_pm_opp_get_voltage(opp);
-		opp = dev_pm_opp_find_freq_exact(cpu_dev,
-				freq_table[i-1].frequency * 1000, true);
-		max_uV = dev_pm_opp_get_voltage(opp);
-		rcu_read_unlock();
+		while (1) {
+			struct dev_pm_opp *opp;
+			unsigned long opp_freq = 0, opp_uV, tol_uV;
+
+			rcu_read_lock();
+			opp = dev_pm_opp_find_freq_ceil(cpu_dev, &opp_freq);
+			if (IS_ERR(opp)) {
+				rcu_read_unlock();
+				break;
+			}
+			opp_uV = dev_pm_opp_get_voltage(opp);
+			rcu_read_unlock();
+
+			tol_uV = opp_uV * priv->voltage_tolerance / 100;
+			if (regulator_is_supported_voltage(cpu_reg, opp_uV,
+							   opp_uV + tol_uV)) {
+				if (opp_uV < min_uV)
+					min_uV = opp_uV;
+				if (opp_uV > max_uV)
+					max_uV = opp_uV;
+			} else {
+				dev_pm_opp_disable(cpu_dev, opp_freq);
+			}
+
+			opp_freq++;
+		}
+
 		ret = regulator_set_voltage_time(cpu_reg, min_uV, max_uV);
 		if (ret > 0)
 			transition_latency += ret * 1000;
 	}
 
+	ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
+	if (ret) {
+		pr_err("failed to init cpufreq table: %d\n", ret);
+		goto out_free_priv;
+	}
+
 	/*
 	 * For now, just loading the cooling device;
 	 * thermal DT code takes care of matching them.
@@ -274,9 +288,9 @@ static int cpu0_cpufreq_init(struct cpufreq_policy *policy)
 
 out_cooling_unregister:
 	cpufreq_cooling_unregister(priv->cdev);
-	kfree(priv);
-out_free_table:
 	dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table);
+out_free_priv:
+	kfree(priv);
 out_put_node:
 	of_node_put(np);
 out_put_reg_clk:
Signature · 1 line
2.1.0
#1 lore raw
Quoted 11 lines · Lucas Stach

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

---
resend:
- no functional change, split out from the imx5 cpufreq series v2:
- rebase on top of pm/linux-next

This makes sense to me, but I need ACKs from people who are more familiar with OPPs in general.

Quoted 114 lines
---
 drivers/cpufreq/cpufreq-cpu0.c | 66 +++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 26 deletions(-)
drivers/cpufreq/cpufreq-cpu0.c +40 -26
index a5f8c5f5f4f4..5d73efbd0240 100644
@@ -185,6 +185,7 @@ static int cpu0_cpufreq_init(struct cpufreq_policy *policy)
 	struct device *cpu_dev;
 	struct regulator *cpu_reg;
 	struct clk *cpu_clk;
+	unsigned long min_uV = ~0, max_uV = 0;
 	unsigned int transition_latency;
 	int ret;
 
@@ -204,16 +205,10 @@ static int cpu0_cpufreq_init(struct cpufreq_policy *policy)
 	/* OPPs might be populated at runtime, don't check for error here */
 	of_init_opp_table(cpu_dev);
 
-	ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
-	if (ret) {
-		dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
-		goto out_put_node;
-	}
-
 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
 	if (!priv) {
 		ret = -ENOMEM;
-		goto out_free_table;
+		goto out_put_node;
 	}
 
 	of_property_read_u32(np, "voltage-tolerance", &priv->voltage_tolerance);
@@ -222,30 +217,49 @@ static int cpu0_cpufreq_init(struct cpufreq_policy *policy)
 		transition_latency = CPUFREQ_ETERNAL;
 
 	if (!IS_ERR(cpu_reg)) {
-		struct dev_pm_opp *opp;
-		unsigned long min_uV, max_uV;
-		int i;
-
 		/*
-		 * OPP is maintained in order of increasing frequency, and
-		 * freq_table initialised from OPP is therefore sorted in the
-		 * same order.
+		 * Disable any OPPs where the connected regulator isn't able to
+		 * provide the specified voltage and record minimum and maximum
+		 * voltage levels.
 		 */
-		for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++)
-			;
-		rcu_read_lock();
-		opp = dev_pm_opp_find_freq_exact(cpu_dev,
-				freq_table[0].frequency * 1000, true);
-		min_uV = dev_pm_opp_get_voltage(opp);
-		opp = dev_pm_opp_find_freq_exact(cpu_dev,
-				freq_table[i-1].frequency * 1000, true);
-		max_uV = dev_pm_opp_get_voltage(opp);
-		rcu_read_unlock();
+		while (1) {
+			struct dev_pm_opp *opp;
+			unsigned long opp_freq = 0, opp_uV, tol_uV;
+
+			rcu_read_lock();
+			opp = dev_pm_opp_find_freq_ceil(cpu_dev, &opp_freq);
+			if (IS_ERR(opp)) {
+				rcu_read_unlock();
+				break;
+			}
+			opp_uV = dev_pm_opp_get_voltage(opp);
+			rcu_read_unlock();
+
+			tol_uV = opp_uV * priv->voltage_tolerance / 100;
+			if (regulator_is_supported_voltage(cpu_reg, opp_uV,
+							   opp_uV + tol_uV)) {
+				if (opp_uV < min_uV)
+					min_uV = opp_uV;
+				if (opp_uV > max_uV)
+					max_uV = opp_uV;
+			} else {
+				dev_pm_opp_disable(cpu_dev, opp_freq);
+			}
+
+			opp_freq++;
+		}
+
 		ret = regulator_set_voltage_time(cpu_reg, min_uV, max_uV);
 		if (ret > 0)
 			transition_latency += ret * 1000;
 	}
 
+	ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
+	if (ret) {
+		pr_err("failed to init cpufreq table: %d\n", ret);
+		goto out_free_priv;
+	}
+
 	/*
 	 * For now, just loading the cooling device;
 	 * thermal DT code takes care of matching them.
@@ -274,9 +288,9 @@ static int cpu0_cpufreq_init(struct cpufreq_policy *policy)
 
 out_cooling_unregister:
 	cpufreq_cooling_unregister(priv->cdev);
-	kfree(priv);
-out_free_table:
 	dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table);
+out_free_priv:
+	kfree(priv);
 out_put_node:
 	of_node_put(np);
 out_put_reg_clk:
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
maintainer
#2 lore raw
Quoted 13 lines · Rafael J. Wysocki
Quoted 11 lines · Lucas Stach

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

---
resend:
- no functional change, split out from the imx5 cpufreq series v2:
- rebase on top of pm/linux-next

Quoted 2 lines

This makes sense to me, but I need ACKs from people who are more familiar with OPPs in general.

@Rafael: Where is this gone?

http://permalink.gmane.org/gmane.linux.power-management.general/49384

I am quite sure you applied this.. Have you dropped this while playing with branches ?

#3 lore raw
Quoted 14 lines · Viresh Kumar
Quoted 13 lines · Rafael J. Wysocki
Quoted 11 lines · Lucas Stach

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

---
resend:
- no functional change, split out from the imx5 cpufreq series v2:
- rebase on top of pm/linux-next

Quoted 8 lines
Quoted 2 lines

This makes sense to me, but I need ACKs from people who are more familiar with OPPs in general.

@Rafael: Where is this gone?

http://permalink.gmane.org/gmane.linux.power-management.general/49384

I am quite sure you applied this..

Yes, I did.

Quoted 1 line

Have you dropped this while playing with branches ?

I dropped it temporarily, because I wanted to fold

https://patchwork.kernel.org/patch/4983431/

into it, but then forgot to re-apply it.

Would you mind sending it again with the fix folded in for me?

Rafael

maintainer
#4 lore raw
Quoted 1 line · Rafael J. Wysocki

Would you mind sending it again with the fix folded in for me?

Done.

#5 lore raw

Am Donnerstag, den 02.10.2014, 10:54 +0530 schrieb Viresh Kumar:

Quoted 4 lines · Rafael J. Wysocki
Quoted 1 line

Would you mind sending it again with the fix folded in for me?

Done.

I don't know how it makes sense to fold the fix into this patch. It has nothing to do with the rename.
If you want to fold the fix in the relevant patch this would be "cpufreq: cpu0: Move per-cluster initialization code to ->init()"

Regards,
Lucas

Signature · 2 lines
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |
#6 lore raw
Quoted 10 lines · Lucas Stach

Am Donnerstag, den 02.10.2014, 10:54 +0530 schrieb Viresh Kumar:

Quoted 4 lines · Rafael J. Wysocki
Quoted 1 line

Would you mind sending it again with the fix folded in for me?

Done.

I don't know how it makes sense to fold the fix into this patch. It has nothing to do with the rename.
If you want to fold the fix in the relevant patch this would be "cpufreq: cpu0: Move per-cluster initialization code to ->init()"

OK, my confusion, sorry about that.

I'll take the original version of the Viresh's patch and the fix on top of that separately, then.

That said, it would help if the information about when things broke was there in the fix' chanelog.

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#7 lore raw
In reply to Viresh Kumar
Quoted 14 lines · Viresh Kumar
Quoted 13 lines · Rafael J. Wysocki
Quoted 11 lines · Lucas Stach

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

---
resend:
- no functional change, split out from the imx5 cpufreq series v2:
- rebase on top of pm/linux-next

Quoted 6 lines
Quoted 2 lines

This makes sense to me, but I need ACKs from people who are more familiar with OPPs in general.

@Rafael: Where is this gone?

http://permalink.gmane.org/gmane.linux.power-management.general/49384

OK, since this has been restored, what am I supposed to do with the $subject patch?

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
maintainer
#8 lore raw
Quoted 2 lines · Rafael J. Wysocki

OK, since this has been restored, what am I supposed to do with the $subject patch?

Yeah, so the patch looked fine to me. If this can still be applied without Lucas required to resend it, please add my Ack and apply it :)

#9 lore raw
Quoted 6 lines · Viresh Kumar
Quoted 2 lines · Rafael J. Wysocki

OK, since this has been restored, what am I supposed to do with the $subject patch?

Yeah, so the patch looked fine to me. If this can still be applied without Lucas required to resend it, please add my Ack and apply it :)

No, it didn't apply for me cleanly.

Lucas, can you please rebase this on top of the current Linus' tree and resend?

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#10 lore raw

PATCH RESEND 1/1 cpufreq: dt: disable unsupported OPPs

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

---
resend 2:
- no functional change, rebase against latest Linus tree
- added Viresh's ack
resend:
- no functional change, split out from the imx5 cpufreq series v2:
- rebase on top of pm/linux-next

---
 drivers/cpufreq/cpufreq-dt.c | 66 +++++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 26 deletions(-)
drivers/cpufreq/cpufreq-dt.c +40 -26
index 6bbb8b913446..4485c8eccdc2 100644
@@ -185,6 +185,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 	struct device *cpu_dev;
 	struct regulator *cpu_reg;
 	struct clk *cpu_clk;
+	unsigned long min_uV = ~0, max_uV = 0;
 	unsigned int transition_latency;
 	int ret;
 
@@ -204,16 +205,10 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 	/* OPPs might be populated at runtime, don't check for error here */
 	of_init_opp_table(cpu_dev);
 
-	ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
-	if (ret) {
-		dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
-		goto out_put_node;
-	}
-
 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
 	if (!priv) {
 		ret = -ENOMEM;
-		goto out_free_table;
+		goto out_put_node;
 	}
 
 	of_property_read_u32(np, "voltage-tolerance", &priv->voltage_tolerance);
@@ -222,30 +217,49 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 		transition_latency = CPUFREQ_ETERNAL;
 
 	if (!IS_ERR(cpu_reg)) {
-		struct dev_pm_opp *opp;
-		unsigned long min_uV, max_uV;
-		int i;
-
 		/*
-		 * OPP is maintained in order of increasing frequency, and
-		 * freq_table initialised from OPP is therefore sorted in the
-		 * same order.
+		 * Disable any OPPs where the connected regulator isn't able to
+		 * provide the specified voltage and record minimum and maximum
+		 * voltage levels.
 		 */
-		for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++)
-			;
-		rcu_read_lock();
-		opp = dev_pm_opp_find_freq_exact(cpu_dev,
-				freq_table[0].frequency * 1000, true);
-		min_uV = dev_pm_opp_get_voltage(opp);
-		opp = dev_pm_opp_find_freq_exact(cpu_dev,
-				freq_table[i-1].frequency * 1000, true);
-		max_uV = dev_pm_opp_get_voltage(opp);
-		rcu_read_unlock();
+		while (1) {
+			struct dev_pm_opp *opp;
+			unsigned long opp_freq = 0, opp_uV, tol_uV;
+
+			rcu_read_lock();
+			opp = dev_pm_opp_find_freq_ceil(cpu_dev, &opp_freq);
+			if (IS_ERR(opp)) {
+				rcu_read_unlock();
+				break;
+			}
+			opp_uV = dev_pm_opp_get_voltage(opp);
+			rcu_read_unlock();
+
+			tol_uV = opp_uV * priv->voltage_tolerance / 100;
+			if (regulator_is_supported_voltage(cpu_reg, opp_uV,
+							   opp_uV + tol_uV)) {
+				if (opp_uV < min_uV)
+					min_uV = opp_uV;
+				if (opp_uV > max_uV)
+					max_uV = opp_uV;
+			} else {
+				dev_pm_opp_disable(cpu_dev, opp_freq);
+			}
+
+			opp_freq++;
+		}
+
 		ret = regulator_set_voltage_time(cpu_reg, min_uV, max_uV);
 		if (ret > 0)
 			transition_latency += ret * 1000;
 	}
 
+	ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
+	if (ret) {
+		pr_err("failed to init cpufreq table: %d\n", ret);
+		goto out_free_priv;
+	}
+
 	/*
 	 * For now, just loading the cooling device;
 	 * thermal DT code takes care of matching them.
@@ -275,9 +289,9 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 
 out_cooling_unregister:
 	cpufreq_cooling_unregister(priv->cdev);
-	kfree(priv);
-out_free_table:
 	dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table);
+out_free_priv:
+	kfree(priv);
 out_put_node:
 	of_node_put(np);
 out_put_reg_clk:
Signature · 1 line
2.1.1
#11 lore raw
Quoted 7 lines · Lucas Stach

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

Applied, thanks!

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#12 lore raw

Hi Rafael, Lucas,

Quoted 10 lines · Rafael J. Wysocki
Quoted 7 lines · Lucas Stach

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

Applied, thanks!

This commit
(http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id×bbd4cd0359d781b67c9e621d4bbfd1bb2f3783)
causes a boot regression on r8a7791/koelsch. It hangs after:

TCP: cubic registered
Initializing XFRM netlink socket
NET: Registered protocol family 17
NET: Registered protocol family 15
ata1: link resume succeeded after 1 retries
ata1: SATA link down (SStatus 0 SControl 300)
random: nonblocking pool is initialized

With more debugging, it seems to end up in an infinite loop calling runtime_{suspend,resume}():

    cpufreq-dt cpufreq-dt: pm_clk_notify() 4
    i2c-sh_mobile e60b0000.i2c: pm_clk_resume()
    MSTP i2c6 ON
    i2c-sh_mobile e60b0000.i2c: pm_clk_suspend()
    MSTP i2c6 OFF
    i2c-sh_mobile e60b0000.i2c: pm_clk_resume()
    MSTP i2c6 ON
    i2c-sh_mobile e60b0000.i2c: pm_clk_suspend()
    MSTP i2c6 OFF
    i2c-sh_mobile e60b0000.i2c: pm_clk_resume()
    MSTP i2c6 ON
    i2c-sh_mobile e60b0000.i2c: pm_clk_suspend()
    MSTP i2c6 OFF
    i2c-sh_mobile e60b0000.i2c: pm_clk_resume()
    MSTP i2c6 ON
    i2c-sh_mobile e60b0000.i2c: pm_clk_suspend()
    MSTP i2c6 OFF
    i2c-sh_mobile e60b0000.i2c: pm_clk_resume()
    ...

Reverting this commit fixes the issue, and makes the boot continue with:

cpufreq: __cpufreq_add_dev: CPU0: Running at unlisted freq: 1300000 KHz
cpufreq: __cpufreq_add_dev: CPU0: Unlisted initial frequency
changed to: 1312500 KHz
cpu cpu1: failed to get cpu-2 clock: 1
cpufreq_dt: cpufreq_init: Failed to allocate resources: -2

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#13 lore raw

Hi Geert,

Am Donnerstag, den 23.10.2014, 11:19 +0200 schrieb Geert Uytterhoeven:

Quoted 49 lines

Hi Rafael, Lucas,

Quoted 10 lines · Rafael J. Wysocki
Quoted 7 lines · Lucas Stach

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

Applied, thanks!

This commit
(http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id=d7bbd4cd0359d781b67c9e621d4bbfd1bb2f3783)
causes a boot regression on r8a7791/koelsch. It hangs after:

TCP: cubic registered
Initializing XFRM netlink socket
NET: Registered protocol family 17
NET: Registered protocol family 15
ata1: link resume succeeded after 1 retries
ata1: SATA link down (SStatus 0 SControl 300)
random: nonblocking pool is initialized

With more debugging, it seems to end up in an infinite loop calling runtime_{suspend,resume}():

    cpufreq-dt cpufreq-dt: pm_clk_notify() 4
    i2c-sh_mobile e60b0000.i2c: pm_clk_resume()
    MSTP i2c6 ON
    i2c-sh_mobile e60b0000.i2c: pm_clk_suspend()
    MSTP i2c6 OFF
    i2c-sh_mobile e60b0000.i2c: pm_clk_resume()
    MSTP i2c6 ON
    i2c-sh_mobile e60b0000.i2c: pm_clk_suspend()
    MSTP i2c6 OFF
    i2c-sh_mobile e60b0000.i2c: pm_clk_resume()
    MSTP i2c6 ON
    i2c-sh_mobile e60b0000.i2c: pm_clk_suspend()
    MSTP i2c6 OFF
    i2c-sh_mobile e60b0000.i2c: pm_clk_resume()
    MSTP i2c6 ON
    i2c-sh_mobile e60b0000.i2c: pm_clk_suspend()
    MSTP i2c6 OFF
    i2c-sh_mobile e60b0000.i2c: pm_clk_resume()
    ...
Quoted 8 lines

Reverting this commit fixes the issue, and makes the boot continue with:

cpufreq: __cpufreq_add_dev: CPU0: Running at unlisted freq: 1300000 KHz
cpufreq: __cpufreq_add_dev: CPU0: Unlisted initial frequency
changed to: 1312500 KHz
cpu cpu1: failed to get cpu-2 clock: 1
cpufreq_dt: cpufreq_init: Failed to allocate resources: -2

Urgh, thanks for the report. Am I right that for koelsch you do reference a regulator supply for the cpu, but don't actually have a driver for it, so a dummy regulator gets plugged in there?

Regards,
Lucas

Signature · 2 lines
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |
#14 lore raw

Hi Lucas,

Quoted 34 lines · Lucas Stach

Am Donnerstag, den 23.10.2014, 11:19 +0200 schrieb Geert Uytterhoeven:

Quoted 24 lines · Rafael J. Wysocki
Quoted 10 lines · Lucas Stach
Quoted 7 lines

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

Applied, thanks!

This commit
(http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id×bbd4cd0359d781b67c9e621d4bbfd1bb2f3783)
causes a boot regression on r8a7791/koelsch. It hangs after:

TCP: cubic registered
Initializing XFRM netlink socket
NET: Registered protocol family 17
NET: Registered protocol family 15
ata1: link resume succeeded after 1 retries
ata1: SATA link down (SStatus 0 SControl 300)
random: nonblocking pool is initialized

Quoted 8 lines

Reverting this commit fixes the issue, and makes the boot continue with:

cpufreq: __cpufreq_add_dev: CPU0: Running at unlisted freq: 1300000 KHz
cpufreq: __cpufreq_add_dev: CPU0: Unlisted initial frequency
changed to: 1312500 KHz
cpu cpu1: failed to get cpu-2 clock: 1
cpufreq_dt: cpufreq_init: Failed to allocate resources: -2

Quoted 3 lines

Urgh, thanks for the report. Am I right that for koelsch you do reference a regulator supply for the cpu, but don't actually have a driver for it, so a dummy regulator gets plugged in there?

arch/arm/boot/dts/r8a7791-koelsch.dts has:

&cpu0 {
        cpu0-supply = <&vdd_dvfs>;
};
&i2c6 {
        status = "okay";
        clock-frequency = <100000>;

        vdd_dvfs: regulator@68 {
                compatible = "dlg,da9210";
                reg = <0x68>;

                regulator-min-microvolt = <1000000>;
                regulator-max-microvolt = <1000000>;
                regulator-boot-on;
                regulator-always-on;
        };
};

CONFIG_REGULATOR_DA9210=y

and the driver does seem to run:

    DA9210: 1000 mV at 4600 mA

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#15 lore raw

Am Donnerstag, den 23.10.2014, 16:43 +0200 schrieb Geert Uytterhoeven:

Quoted 62 lines

Hi Lucas,

Quoted 34 lines · Lucas Stach

Am Donnerstag, den 23.10.2014, 11:19 +0200 schrieb Geert Uytterhoeven:

Quoted 24 lines · Rafael J. Wysocki
Quoted 10 lines · Lucas Stach
Quoted 7 lines

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

Applied, thanks!

This commit
(http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id×bbd4cd0359d781b67c9e621d4bbfd1bb2f3783)
causes a boot regression on r8a7791/koelsch. It hangs after:

TCP: cubic registered
Initializing XFRM netlink socket
NET: Registered protocol family 17
NET: Registered protocol family 15
ata1: link resume succeeded after 1 retries
ata1: SATA link down (SStatus 0 SControl 300)
random: nonblocking pool is initialized

Quoted 8 lines

Reverting this commit fixes the issue, and makes the boot continue with:

cpufreq: __cpufreq_add_dev: CPU0: Running at unlisted freq: 1300000 KHz
cpufreq: __cpufreq_add_dev: CPU0: Unlisted initial frequency
changed to: 1312500 KHz
cpu cpu1: failed to get cpu-2 clock: 1
cpufreq_dt: cpufreq_init: Failed to allocate resources: -2

Quoted 3 lines

Urgh, thanks for the report. Am I right that for koelsch you do reference a regulator supply for the cpu, but don't actually have a driver for it, so a dummy regulator gets plugged in there?

arch/arm/boot/dts/r8a7791-koelsch.dts has:

&cpu0 {
        cpu0-supply = <&vdd_dvfs>;
};
&i2c6 {
        status = "okay";
        clock-frequency = <100000>;

        vdd_dvfs: regulator@68 {
                compatible = "dlg,da9210";
                reg = <0x68>;

                regulator-min-microvolt = <1000000>;
                regulator-max-microvolt = <1000000>;
                regulator-boot-on;
                regulator-always-on;
        };
};
Quoted 6 lines

CONFIG_REGULATOR_DA9210=y

and the driver does seem to run:

    DA9210: 1000 mV at 4600 mA

Ah right, I misread your initial report. So the issue doesn't seem to be directly related to the cpufreq-dt driver but seems to be located somewhere deeper down the chain. The fact that this change triggers the bug may be a hint here. The only thing which is new in the change is that it tries to get the supported voltage from the regulator. As the regulator can not change its voltage (min_uV = max_uV) this translates directly to a get_voltage() which in turn only tries to read a register of the i2c chip via regmap.

So it seems that somehow the i2c transaction fails and things spin indefinitely there. Maybe this gives a clue on how to debug this further.

Regards,
Lucas

Signature · 2 lines
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |
#16 lore raw
Quoted 78 lines · Lucas Stach

Am Donnerstag, den 23.10.2014, 16:43 +0200 schrieb Geert Uytterhoeven:

Quoted 62 lines

Hi Lucas,

Quoted 34 lines · Lucas Stach

Am Donnerstag, den 23.10.2014, 11:19 +0200 schrieb Geert Uytterhoeven:

Quoted 24 lines · Rafael J. Wysocki
Quoted 10 lines · Lucas Stach
Quoted 7 lines

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

Applied, thanks!

This commit
(http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id=d7bbd4cd0359d781b67c9e621d4bbfd1bb2f3783)
causes a boot regression on r8a7791/koelsch. It hangs after:

TCP: cubic registered
Initializing XFRM netlink socket
NET: Registered protocol family 17
NET: Registered protocol family 15
ata1: link resume succeeded after 1 retries
ata1: SATA link down (SStatus 0 SControl 300)
random: nonblocking pool is initialized

Quoted 8 lines

Reverting this commit fixes the issue, and makes the boot continue with:

cpufreq: __cpufreq_add_dev: CPU0: Running at unlisted freq: 1300000 KHz
cpufreq: __cpufreq_add_dev: CPU0: Unlisted initial frequency
changed to: 1312500 KHz
cpu cpu1: failed to get cpu-2 clock: 1
cpufreq_dt: cpufreq_init: Failed to allocate resources: -2

Quoted 3 lines

Urgh, thanks for the report. Am I right that for koelsch you do reference a regulator supply for the cpu, but don't actually have a driver for it, so a dummy regulator gets plugged in there?

arch/arm/boot/dts/r8a7791-koelsch.dts has:

&cpu0 {
        cpu0-supply = <&vdd_dvfs>;
};
&i2c6 {
        status = "okay";
        clock-frequency = <100000>;

        vdd_dvfs: regulator@68 {
                compatible = "dlg,da9210";
                reg = <0x68>;

                regulator-min-microvolt = <1000000>;
                regulator-max-microvolt = <1000000>;
                regulator-boot-on;
                regulator-always-on;
        };
};
Quoted 6 lines

CONFIG_REGULATOR_DA9210=y

and the driver does seem to run:

    DA9210: 1000 mV at 4600 mA

Ah right, I misread your initial report. So the issue doesn't seem to be directly related to the cpufreq-dt driver but seems to be located somewhere deeper down the chain. The fact that this change triggers the bug may be a hint here. The only thing which is new in the change is that it tries to get the supported voltage from the regulator. As the regulator can not change its voltage (min_uV == max_uV) this translates directly to a get_voltage() which in turn only tries to read a register of the i2c chip via regmap.

Quoted 3 lines

So it seems that somehow the i2c transaction fails and things spin indefinitely there. Maybe this gives a clue on how to debug this further.

Well, I've dropped the patch for now. The underlying issue needs to be fixed before we can apply it again.

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#17 lore raw

++Inami-san, author of recent CPUFreq patches.

Quoted 87 lines · Rafael J. Wysocki
Quoted 78 lines · Lucas Stach

Am Donnerstag, den 23.10.2014, 16:43 +0200 schrieb Geert Uytterhoeven:

Quoted 62 lines

Hi Lucas,

Quoted 34 lines · Lucas Stach

Am Donnerstag, den 23.10.2014, 11:19 +0200 schrieb Geert Uytterhoeven:

Quoted 24 lines · Rafael J. Wysocki
Quoted 10 lines · Lucas Stach
Quoted 7 lines

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

Applied, thanks!

This commit
(http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id=d7bbd4cd0359d781b67c9e621d4bbfd1bb2f3783)
causes a boot regression on r8a7791/koelsch. It hangs after:

TCP: cubic registered
Initializing XFRM netlink socket
NET: Registered protocol family 17
NET: Registered protocol family 15
ata1: link resume succeeded after 1 retries
ata1: SATA link down (SStatus 0 SControl 300)
random: nonblocking pool is initialized

Quoted 8 lines

Reverting this commit fixes the issue, and makes the boot continue with:

cpufreq: __cpufreq_add_dev: CPU0: Running at unlisted freq: 1300000 KHz
cpufreq: __cpufreq_add_dev: CPU0: Unlisted initial frequency
changed to: 1312500 KHz
cpu cpu1: failed to get cpu-2 clock: 1
cpufreq_dt: cpufreq_init: Failed to allocate resources: -2

Quoted 3 lines

Urgh, thanks for the report. Am I right that for koelsch you do reference a regulator supply for the cpu, but don't actually have a driver for it, so a dummy regulator gets plugged in there?

arch/arm/boot/dts/r8a7791-koelsch.dts has:

&cpu0 {
        cpu0-supply = <&vdd_dvfs>;
};
&i2c6 {
        status = "okay";
        clock-frequency = <100000>;

        vdd_dvfs: regulator@68 {
                compatible = "dlg,da9210";
                reg = <0x68>;

                regulator-min-microvolt = <1000000>;
                regulator-max-microvolt = <1000000>;
                regulator-boot-on;
                regulator-always-on;
        };
};
Quoted 6 lines

CONFIG_REGULATOR_DA9210=y

and the driver does seem to run:

    DA9210: 1000 mV at 4600 mA

Ah right, I misread your initial report. So the issue doesn't seem to be directly related to the cpufreq-dt driver but seems to be located somewhere deeper down the chain. The fact that this change triggers the bug may be a hint here. The only thing which is new in the change is that it tries to get the supported voltage from the regulator. As the regulator can not change its voltage (min_uV == max_uV) this translates directly to a get_voltage() which in turn only tries to read a register of the i2c chip via regmap.

Quoted 3 lines

So it seems that somehow the i2c transaction fails and things spin indefinitely there. Maybe this gives a clue on how to debug this further.

Well, I've dropped the patch for now. The underlying issue needs to be fixed before we can apply it again.

Signature · 2 lines
Best regards,
KHIEM Nguyen
#18 lore raw
In reply to Geert Uytterhoeven

Geert,

Am Donnerstag, den 23.10.2014, 16:43 +0200 schrieb Geert Uytterhoeven:

Quoted 37 lines

Hi Lucas,

Quoted 34 lines · Lucas Stach

Am Donnerstag, den 23.10.2014, 11:19 +0200 schrieb Geert Uytterhoeven:

Quoted 32 lines · Rafael J. Wysocki
Quoted 10 lines · Lucas Stach
Quoted 7 lines

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

Applied, thanks!

This commit
(http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id×bbd4cd0359d781b67c9e621d4bbfd1bb2f3783)
causes a boot regression on r8a7791/koelsch. It hangs after:

TCP: cubic registered
Initializing XFRM netlink socket
NET: Registered protocol family 17
NET: Registered protocol family 15
ata1: link resume succeeded after 1 retries
ata1: SATA link down (SStatus 0 SControl 300)
random: nonblocking pool is initialized

Reverting this commit fixes the issue, and makes the boot continue with:

cpufreq: __cpufreq_add_dev: CPU0: Running at unlisted freq: 1300000 KHz
cpufreq: __cpufreq_add_dev: CPU0: Unlisted initial frequency
changed to: 1312500 KHz
cpu cpu1: failed to get cpu-2 clock: 1
cpufreq_dt: cpufreq_init: Failed to allocate resources: -2

I thought a bit more about about this to make sure this isn't a fault on my side, but can't seem to make any sense out of this. Can you please print out the value of opp_freq in each iteration of the while loop and also the return value of regulator_is_supported_voltage()? This would help me a lot to understand what's happening here.

Thanks,
Lucas

Signature · 2 lines
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |
#19 lore raw

Hi Lucas,

Quoted 35 lines · Lucas Stach

Am Donnerstag, den 23.10.2014, 16:43 +0200 schrieb Geert Uytterhoeven:

Quoted 26 lines · Lucas Stach
Quoted 24 lines

Am Donnerstag, den 23.10.2014, 11:19 +0200 schrieb Geert Uytterhoeven:

Quoted 23 lines · Rafael J. Wysocki
Quoted 10 lines · Lucas Stach
Quoted 7 lines

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

Applied, thanks!

This commit
(http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id×bbd4cd0359d781b67c9e621d4bbfd1bb2f3783)
causes a boot regression on r8a7791/koelsch. It hangs after:

TCP: cubic registered
Initializing XFRM netlink socket
NET: Registered protocol family 17
NET: Registered protocol family 15
ata1: link resume succeeded after 1 retries
ata1: SATA link down (SStatus 0 SControl 300)
random: nonblocking pool is initialized

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Reverting this commit fixes the issue, and makes the boot continue with:

cpufreq: __cpufreq_add_dev: CPU0: Running at unlisted freq: 1300000 KHz
cpufreq: __cpufreq_add_dev: CPU0: Unlisted initial frequency
changed to: 1312500 KHz
cpu cpu1: failed to get cpu-2 clock: 1
cpufreq_dt: cpufreq_init: Failed to allocate resources: -2

Quoted 5 lines

I thought a bit more about about this to make sure this isn't a fault on my side, but can't seem to make any sense out of this. Can you please print out the value of opp_freq in each iteration of the while loop and also the return value of regulator_is_supported_voltage()? This would help me a lot to understand what's happening here.

It gets into an infinite loop doing:

    cpufreq_dt: cpufreq_init:232: opp_freq = 0
    cpufreq_dt: cpufreq_init:240: opp_freq = 375000000
    cpufreq_dt: cpufreq_init:247: [ 1000000, 1010000 ] is supported     cpufreq_dt: cpufreq_init:258: opp_freq = 375000001

    ...

The loop is only aborted if dev_pm_opp_find_freq_ceil() returns an error, but that never happens.

I think it should try the next frequency on each subsequent iteration, right? So I came up with the fix below. After that it behaves better:

    cpufreq_dt: cpufreq_init:233: opp_freq = 0
    cpufreq_dt: cpufreq_init:241: opp_freq = 375000000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 375000001
    cpufreq_dt: cpufreq_init:233: opp_freq = 375000001
    cpufreq_dt: cpufreq_init:241: opp_freq = 750000000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 750000001
    cpufreq_dt: cpufreq_init:233: opp_freq = 750000001
    cpufreq_dt: cpufreq_init:241: opp_freq = 937500000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 937500001
    cpufreq_dt: cpufreq_init:233: opp_freq = 937500001
    cpufreq_dt: cpufreq_init:241: opp_freq = 1125000000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 1125000001
    cpufreq_dt: cpufreq_init:233: opp_freq = 1125000001
    cpufreq_dt: cpufreq_init:241: opp_freq = 1312500000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 1312500001
    cpufreq_dt: cpufreq_init:233: opp_freq = 1312500001
    cpufreq_dt: cpufreq_init:241: opp_freq = 1500000000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 1500000001
    cpufreq_dt: cpufreq_init:233: opp_freq = 1500000001
    cpufreq_dt: cpufreq_init:237: Error -34 => break

From e5f401eee8b316587fc385cac7acdd92b33adec7 Mon Sep 17 00:00:00 2001
From: Geert Uytterhoeven <[email protected]>
Date: Fri, 24 Oct 2014 14:23:14 +0200
Subject: [PATCH] cpufreq: dt: Don't reset opp_freq in subsequent loop
iterations

opp_freq is incremented at the end of the loop, to find the next supported frequency, but this is overturned by its re-initialization in next iteration, causing an infinite loop.

Move the initialization of opp_freq outside the loop to fix this.

Fixes d7bbd4cd0359d781 ("cpufreq: dt: disable unsupported OPPs")
---
 drivers/cpufreq/cpufreq-dt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq-dt.c +3 -1
index f6e39a2e324ffc87..2f25958053778ad1 100644
@@ -219,6 +219,8 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 		transition_latency = CPUFREQ_ETERNAL;
 
 	if (!IS_ERR(cpu_reg)) {
+		unsigned long opp_freq = 0;
+
 		/*
 		 * Disable any OPPs where the connected regulator isn't able to
 		 * provide the specified voltage and record minimum and maximum
@@ -226,7 +228,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 		 */
 		while (1) {
 			struct dev_pm_opp *opp;
-			unsigned long opp_freq = 0, opp_uV, tol_uV;
+			unsigned long opp_uV, tol_uV;
 
 			rcu_read_lock();
 			opp = dev_pm_opp_find_freq_ceil(cpu_dev, &opp_freq);
Signature · 12 lines
1.9.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds
#20 lore raw

Am Freitag, den 24.10.2014, 14:30 +0200 schrieb Geert Uytterhoeven:

Quoted 128 lines

Hi Lucas,

Quoted 35 lines · Lucas Stach

Am Donnerstag, den 23.10.2014, 16:43 +0200 schrieb Geert Uytterhoeven:

Quoted 26 lines · Lucas Stach
Quoted 24 lines

Am Donnerstag, den 23.10.2014, 11:19 +0200 schrieb Geert Uytterhoeven:

Quoted 23 lines · Rafael J. Wysocki
Quoted 10 lines · Lucas Stach
Quoted 7 lines

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

Applied, thanks!

This commit
(http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id=d7bbd4cd0359d781b67c9e621d4bbfd1bb2f3783)
causes a boot regression on r8a7791/koelsch. It hangs after:

TCP: cubic registered
Initializing XFRM netlink socket
NET: Registered protocol family 17
NET: Registered protocol family 15
ata1: link resume succeeded after 1 retries
ata1: SATA link down (SStatus 0 SControl 300)
random: nonblocking pool is initialized

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Reverting this commit fixes the issue, and makes the boot continue with:

cpufreq: __cpufreq_add_dev: CPU0: Running at unlisted freq: 1300000 KHz
cpufreq: __cpufreq_add_dev: CPU0: Unlisted initial frequency
changed to: 1312500 KHz
cpu cpu1: failed to get cpu-2 clock: 1
cpufreq_dt: cpufreq_init: Failed to allocate resources: -2

Quoted 5 lines

I thought a bit more about about this to make sure this isn't a fault on my side, but can't seem to make any sense out of this. Can you please print out the value of opp_freq in each iteration of the while loop and also the return value of regulator_is_supported_voltage()? This would help me a lot to understand what's happening here.

It gets into an infinite loop doing:

    cpufreq_dt: cpufreq_init:232: opp_freq = 0
    cpufreq_dt: cpufreq_init:240: opp_freq = 375000000
    cpufreq_dt: cpufreq_init:247: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:258: opp_freq = 375000001
    ...

The loop is only aborted if dev_pm_opp_find_freq_ceil() returns an error, but that never happens.

I think it should try the next frequency on each subsequent iteration, right? So I came up with the fix below. After that it behaves better:

    cpufreq_dt: cpufreq_init:233: opp_freq = 0
    cpufreq_dt: cpufreq_init:241: opp_freq = 375000000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 375000001
    cpufreq_dt: cpufreq_init:233: opp_freq = 375000001
    cpufreq_dt: cpufreq_init:241: opp_freq = 750000000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 750000001
    cpufreq_dt: cpufreq_init:233: opp_freq = 750000001
    cpufreq_dt: cpufreq_init:241: opp_freq = 937500000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 937500001
    cpufreq_dt: cpufreq_init:233: opp_freq = 937500001
    cpufreq_dt: cpufreq_init:241: opp_freq = 1125000000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 1125000001
    cpufreq_dt: cpufreq_init:233: opp_freq = 1125000001
    cpufreq_dt: cpufreq_init:241: opp_freq = 1312500000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 1312500001
    cpufreq_dt: cpufreq_init:233: opp_freq = 1312500001
    cpufreq_dt: cpufreq_init:241: opp_freq = 1500000000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 1500000001
    cpufreq_dt: cpufreq_init:233: opp_freq = 1500000001
    cpufreq_dt: cpufreq_init:237: Error -34 => break

From e5f401eee8b316587fc385cac7acdd92b33adec7 Mon Sep 17 00:00:00 2001
From: Geert Uytterhoeven <[email protected]>
Date: Fri, 24 Oct 2014 14:23:14 +0200
Subject: [PATCH] cpufreq: dt: Don't reset opp_freq in subsequent loop
iterations

opp_freq is incremented at the end of the loop, to find the next supported frequency, but this is overturned by its re-initialization in next iteration, causing an infinite loop.

Move the initialization of opp_freq outside the loop to fix this.

Fixes d7bbd4cd0359d781 ("cpufreq: dt: disable unsupported OPPs")
---
 drivers/cpufreq/cpufreq-dt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq-dt.c +3 -1
index f6e39a2e324ffc87..2f25958053778ad1 100644
@@ -219,6 +219,8 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 		transition_latency = CPUFREQ_ETERNAL;
 
 	if (!IS_ERR(cpu_reg)) {
+		unsigned long opp_freq = 0;
+
 		/*
 		 * Disable any OPPs where the connected regulator isn't able to
 		 * provide the specified voltage and record minimum and maximum
@@ -226,7 +228,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 		 */
 		while (1) {
 			struct dev_pm_opp *opp;
-			unsigned long opp_freq = 0, opp_uV, tol_uV;
+			unsigned long opp_uV, tol_uV;
 
 			rcu_read_lock();
 			opp = dev_pm_opp_find_freq_ceil(cpu_dev, &opp_freq);
Signature · 1 line
1.9.1

*puts on brown paper bag*

Right, the fixed behavior with your patch was clearly the intention, which may be the cause it didn't see when staring at the code. I remember moving the variable initialization at one point, but somehow this slipped through my testing. Thanks for hunting it down.

Rafael, how do we handle this? Are you going to reapply the patch together with this fix, or want me to send an updated version with this fix included?

Regards,
Lucas

Signature · 2 lines
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |
#21 lore raw
Quoted 129 lines · Lucas Stach

Am Freitag, den 24.10.2014, 14:30 +0200 schrieb Geert Uytterhoeven:

Quoted 117 lines

Hi Lucas,

Quoted 35 lines · Lucas Stach

Am Donnerstag, den 23.10.2014, 16:43 +0200 schrieb Geert Uytterhoeven:

Quoted 26 lines · Lucas Stach
Quoted 24 lines

Am Donnerstag, den 23.10.2014, 11:19 +0200 schrieb Geert Uytterhoeven:

Quoted 23 lines · Rafael J. Wysocki
Quoted 10 lines · Lucas Stach
Quoted 7 lines

If the regulator connected to the CPU voltage plane doesn't support an OPP specified voltage with the acceptable tolerance it's better to just disable the OPP instead of constantly failing the voltage scaling later on.

Applied, thanks!

This commit
(http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id×bbd4cd0359d781b67c9e621d4bbfd1bb2f3783)
causes a boot regression on r8a7791/koelsch. It hangs after:

TCP: cubic registered
Initializing XFRM netlink socket
NET: Registered protocol family 17
NET: Registered protocol family 15
ata1: link resume succeeded after 1 retries
ata1: SATA link down (SStatus 0 SControl 300)
random: nonblocking pool is initialized

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Reverting this commit fixes the issue, and makes the boot continue with:

cpufreq: __cpufreq_add_dev: CPU0: Running at unlisted freq: 1300000 KHz
cpufreq: __cpufreq_add_dev: CPU0: Unlisted initial frequency
changed to: 1312500 KHz
cpu cpu1: failed to get cpu-2 clock: 1
cpufreq_dt: cpufreq_init: Failed to allocate resources: -2

Quoted 5 lines

I thought a bit more about about this to make sure this isn't a fault on my side, but can't seem to make any sense out of this. Can you please print out the value of opp_freq in each iteration of the while loop and also the return value of regulator_is_supported_voltage()? This would help me a lot to understand what's happening here.

It gets into an infinite loop doing:

    cpufreq_dt: cpufreq_init:232: opp_freq = 0
    cpufreq_dt: cpufreq_init:240: opp_freq = 375000000
    cpufreq_dt: cpufreq_init:247: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:258: opp_freq = 375000001
    ...

The loop is only aborted if dev_pm_opp_find_freq_ceil() returns an error, but that never happens.

I think it should try the next frequency on each subsequent iteration, right? So I came up with the fix below. After that it behaves better:

    cpufreq_dt: cpufreq_init:233: opp_freq = 0
    cpufreq_dt: cpufreq_init:241: opp_freq = 375000000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 375000001
    cpufreq_dt: cpufreq_init:233: opp_freq = 375000001
    cpufreq_dt: cpufreq_init:241: opp_freq = 750000000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 750000001
    cpufreq_dt: cpufreq_init:233: opp_freq = 750000001
    cpufreq_dt: cpufreq_init:241: opp_freq = 937500000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 937500001
    cpufreq_dt: cpufreq_init:233: opp_freq = 937500001
    cpufreq_dt: cpufreq_init:241: opp_freq = 1125000000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 1125000001
    cpufreq_dt: cpufreq_init:233: opp_freq = 1125000001
    cpufreq_dt: cpufreq_init:241: opp_freq = 1312500000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 1312500001
    cpufreq_dt: cpufreq_init:233: opp_freq = 1312500001
    cpufreq_dt: cpufreq_init:241: opp_freq = 1500000000
    cpufreq_dt: cpufreq_init:248: [ 1000000, 1010000 ] is supported
    cpufreq_dt: cpufreq_init:259: opp_freq = 1500000001
    cpufreq_dt: cpufreq_init:233: opp_freq = 1500000001
    cpufreq_dt: cpufreq_init:237: Error -34 => break

From e5f401eee8b316587fc385cac7acdd92b33adec7 Mon Sep 17 00:00:00 2001
From: Geert Uytterhoeven <[email protected]>
Date: Fri, 24 Oct 2014 14:23:14 +0200
Subject: [PATCH] cpufreq: dt: Don't reset opp_freq in subsequent loop
iterations

opp_freq is incremented at the end of the loop, to find the next supported frequency, but this is overturned by its re-initialization in next iteration, causing an infinite loop.

Move the initialization of opp_freq outside the loop to fix this.

Fixes d7bbd4cd0359d781 ("cpufreq: dt: disable unsupported OPPs")
---
 drivers/cpufreq/cpufreq-dt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq-dt.c +2 -0
index f6e39a2e324ffc87..2f25958053778ad1 100644
@@ -219,6 +219,8 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 		transition_latency = CPUFREQ_ETERNAL;
 
 	if (!IS_ERR(cpu_reg)) {
+		unsigned long opp_freq = 0;
+
 		/*
 		 * Disable any OPPs where the connected regulator isn't able to
 		 * provide the specified voltage and record minimum and maximum

drivers/cpufreq/cpufreq-dt.c static int cpufreq_init(struct cpufreq_policy *policy) · line 234

Quoted 8 lines
drivers/cpufreq/cpufreq-dt.c +1 -1
@@ -226,7 +228,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 		 */
 		while (1) {
 			struct dev_pm_opp *opp;
-			unsigned long opp_freq = 0, opp_uV, tol_uV;
+			unsigned long opp_uV, tol_uV;
 
 			rcu_read_lock();
 			opp = dev_pm_opp_find_freq_ceil(cpu_dev, &opp_freq);

*puts on brown paper bag*

Quoted 8 lines

Right, the fixed behavior with your patch was clearly the intention, which may be the cause it didn't see when staring at the code. I remember moving the variable initialization at one point, but somehow this slipped through my testing. Thanks for hunting it down.

Rafael, how do we handle this? Are you going to reapply the patch together with this fix, or want me to send an updated version with this fix included?

An update, please. Plus say in the changelog that this includes a fix from Geert.

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.