Skip to contentSkip to conversation

OPP: Check for bandwidth values before creating icc paths

PATCH In review Sibi Sankar 2 participants 9 messages May 27, 2020 – Jun 1, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 OPP: Check for bandwidth values before creating icc paths

Prevent the core from creating and voting on icc paths when the opp-table does not have the bandwidth values populated. Currently this check is performed on the first OPP node.

---
 drivers/opp/of.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/opp/of.c +15 -0
index 61fce1284f012..95cf6f1312765 100644
@@ -338,6 +338,21 @@ int dev_pm_opp_of_find_icc_paths(struct device *dev,
 	struct device_node *np;
 	int ret = 0, i, count, num_paths;
 	struct icc_path **paths;
+	struct property *prop;
+
+	/* Check for bandwidth values on the first OPP node */
+	if (opp_table && opp_table->np) {
+		np = of_get_next_available_child(opp_table->np, NULL);
+		if (!np) {
+			dev_err(dev, "Empty OPP table\n");
+			return 0;
+		}
+
+		prop = of_find_property(np, "opp-peak-kBps", NULL);
+		of_node_put(np);
+		if (!prop || !prop->length)
+			return 0;
+	}
 
 	np = of_node_get(dev->of_node);
 	if (!np)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw
Quoted 22 lines · Sibi Sankar

Prevent the core from creating and voting on icc paths when the opp-table does not have the bandwidth values populated. Currently this check is performed on the first OPP node.

---
 drivers/opp/of.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/opp/of.c +5 -0
index 61fce1284f012..95cf6f1312765 100644
@@ -338,6 +338,21 @@ int dev_pm_opp_of_find_icc_paths(struct device *dev,
 	struct device_node *np;
 	int ret = 0, i, count, num_paths;
 	struct icc_path **paths;
+	struct property *prop;
+
+	/* Check for bandwidth values on the first OPP node */
+	if (opp_table && opp_table->np) {
+		np = of_get_next_available_child(opp_table->np, NULL);

drivers/opp/of.c int dev_pm_opp_of_find_icc_paths(struct device *dev, · line 355

Quoted 10 lines
drivers/opp/of.c +10 -0
+		if (!np) {
+			dev_err(dev, "Empty OPP table\n");
+			return 0;
+		}
+
+		prop = of_find_property(np, "opp-peak-kBps", NULL);
+		of_node_put(np);
+		if (!prop || !prop->length)
+			return 0;
+	}

This doesn't support the call made from cpufreq-dt driver. Pushed this, please give this a try:

From: Sibi Sankar <[email protected]>
Date: Thu, 28 May 2020 00:54:18 +0530
Subject: [PATCH] opp: Don't parse icc paths unnecessarily

The DT node of the device may contain interconnect paths while the OPP table doesn't have the bandwidth values. There is no need to parse the paths in such cases.

[ Viresh: Support the case of !opp_table and massaged changelog ]
---
 drivers/opp/of.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
drivers/opp/of.c +44 -1
index 61fce1284f01..8c1bf01f0e50 100644
@@ -332,13 +332,56 @@ static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
 	return ret;
 }
 
+static int _bandwidth_supported(struct device *dev, struct opp_table *opp_table)
+{
+	struct device_node *np, *opp_np;
+	struct property *prop;
+
+	if (!opp_table) {
+		np = of_node_get(dev->of_node);
+		if (!np)
+			return -ENODEV;
+
+		opp_np = _opp_of_get_opp_desc_node(np, 0);
+		of_node_put(np);
+
+		/* Lets not fail in case we are parsing opp-v1 bindings */
+		if (!opp_np)
+			return 0;
+	} else {
+		opp_np = of_node_get(opp_table->np);
+	}
+
+	/* Checking only first OPP is sufficient */
+	np = of_get_next_available_child(opp_np, NULL);
+	if (!np) {
+		dev_err(dev, "OPP table empty\n");
+		return -EINVAL;
+	}
+	of_node_put(opp_np);
+
+	prop = of_find_property(np, "opp-peak-kBps", NULL);
+	of_node_put(np);
+
+	if (!prop || !prop->length)
+		return 0;
+
+	return 1;
+}
+
 int dev_pm_opp_of_find_icc_paths(struct device *dev,
 				 struct opp_table *opp_table)
 {
 	struct device_node *np;
-	int ret = 0, i, count, num_paths;
+	int ret, i, count, num_paths;
 	struct icc_path **paths;
 
+	ret = _bandwidth_supported(dev, opp_table);
+	if (ret <= 0)
+		return ret;
+
+	ret = 0;
+
 	np = of_node_get(dev->of_node);
 	if (!np)
 		return 0;
Signature · 1 line
viresh
author Tested-by Reviewed-by
#2 lore raw
Quoted 29 lines · Viresh Kumar
Quoted 28 lines · Sibi Sankar

Prevent the core from creating and voting on icc paths when the opp-table does not have the bandwidth values populated. Currently this check is performed on the first OPP node.

---
 drivers/opp/of.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/opp/of.c +10 -0
index 61fce1284f012..95cf6f1312765 100644
@@ -338,6 +338,21 @@ int dev_pm_opp_of_find_icc_paths(struct device 
 *dev,
 	struct device_node *np;
 	int ret = 0, i, count, num_paths;
 	struct icc_path **paths;
+	struct property *prop;
+
+	/* Check for bandwidth values on the first OPP node */
+	if (opp_table && opp_table->np) {
+		np = of_get_next_available_child(opp_table->np, NULL);
+		if (!np) {
+			dev_err(dev, "Empty OPP table\n");
+			return 0;
+		}
+
Quoted 8 lines

drivers/opp/of.c static int _of_opp_alloc_required_opps(struct opp_table *opp_table, · line 370

Quoted 5 lines
drivers/opp/of.c +5 -0
+		prop = of_find_property(np, "opp-peak-kBps", NULL);
+		of_node_put(np);
+		if (!prop || !prop->length)
+			return 0;
+	}

This doesn't support the call made from cpufreq-dt driver. Pushed this, please give this a try:

Viresh,
Thanks for the patch!

Quoted 34 lines

From: Sibi Sankar <[email protected]>
Date: Thu, 28 May 2020 00:54:18 +0530
Subject: [PATCH] opp: Don't parse icc paths unnecessarily

The DT node of the device may contain interconnect paths while the OPP table doesn't have the bandwidth values. There is no need to parse the paths in such cases.

[ Viresh: Support the case of !opp_table and massaged changelog ]
---
 drivers/opp/of.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
drivers/opp/of.c +8 -0
index 61fce1284f01..8c1bf01f0e50 100644
@@ -332,13 +332,56 @@ static int _of_opp_alloc_required_opps(struct
 opp_table *opp_table,
 	return ret;
 }
 
+static int _bandwidth_supported(struct device *dev, struct opp_table
 *opp_table)
+{
+	struct device_node *np, *opp_np;
+	struct property *prop;
+
+	if (!opp_table) {
+		np = of_node_get(dev->of_node);
+		if (!np)

drivers/opp/of.c static int _of_opp_alloc_required_opps(struct · line 354

Quoted 10 lines
drivers/opp/of.c +10 -0
+			return -ENODEV;
+
+		opp_np = _opp_of_get_opp_desc_node(np, 0);
+		of_node_put(np);
+
+		/* Lets not fail in case we are parsing opp-v1 bindings */
+		if (!opp_np)
+			return 0;
+	} else {
+		opp_np = of_node_get(opp_table->np);

opp_np needs to be subjected
to NULL check as well. Lets
move "if (!opp_np)" to outside
the if/else. With the above
change in place:

Quoted 36 lines
drivers/opp/of.c +26 -1
+	}
+
+	/* Checking only first OPP is sufficient */
+	np = of_get_next_available_child(opp_np, NULL);
+	if (!np) {
+		dev_err(dev, "OPP table empty\n");
+		return -EINVAL;
+	}
+	of_node_put(opp_np);
+
+	prop = of_find_property(np, "opp-peak-kBps", NULL);
+	of_node_put(np);
+
+	if (!prop || !prop->length)
+		return 0;
+
+	return 1;
+}
+
 int dev_pm_opp_of_find_icc_paths(struct device *dev,
 				 struct opp_table *opp_table)
 {
 	struct device_node *np;
-	int ret = 0, i, count, num_paths;
+	int ret, i, count, num_paths;
 	struct icc_path **paths;
 
+	ret = _bandwidth_supported(dev, opp_table);
+	if (ret <= 0)
+		return ret;
+
+	ret = 0;
+
 	np = of_node_get(dev->of_node);
drivers/opp/of.c +0 -0
 	if (!np)
 		return 0;
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project.
#3 lore raw
Quoted 2 lines · Sibi Sankar

opp_np needs to be subjected
to NULL check as well.

No, it isn't. It should already be valid and is set by the OPP core. Actually we don't need to do of_node_get(opp_table->np) and just use np, I did that to not have a special case while putting the resource.

Quoted 2 lines

Thanks.

Signature · 1 line
viresh
#4 lore raw
Quoted 8 lines · Viresh Kumar
Quoted 2 lines · Sibi Sankar

opp_np needs to be subjected
to NULL check as well.

No, it isn't. It should already be valid and is set by the OPP core. Actually we don't need to do of_node_get(opp_table->np) and just use np, I did that to not have a special case while putting the resource.

I should have phrased it differently.
opp_np needs to be checked to deal
with cases where devices don't have
"operating-points-v2" associated with
it.

drivers/opp/of.c +4 -4
index a5d87ca0ab571..06976d14e6ccb 100644
@@ -344,14 +344,14 @@ static int _bandwidth_supported(struct device *dev, struct opp_table *opp_table)
 
                opp_np = _opp_of_get_opp_desc_node(np, 0);
                of_node_put(np);
-
-               /* Lets not fail in case we are parsing opp-v1 bindings */
-               if (!opp_np)
-                       return 0;
        } else {
                opp_np = of_node_get(opp_table->np);
        }
 
+       /* Lets not fail in case we are parsing opp-v1 bindings */
+       if (!opp_np)
+               return 0;
+
 

sdhci_msm 7c4000.sdhci: OPP table empty
sdhci_msm 7c4000.sdhci: _allocate_opp_table: Error finding interconnect paths: -22

I see the following errors without
the check.

Quoted 4 lines
Quoted 2 lines

Thanks.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project.
#5 lore raw
Quoted 42 lines · Sibi Sankar
Quoted 8 lines · Viresh Kumar
Quoted 2 lines · Sibi Sankar

opp_np needs to be subjected
to NULL check as well.

No, it isn't. It should already be valid and is set by the OPP core. Actually we don't need to do of_node_get(opp_table->np) and just use np, I did that to not have a special case while putting the resource.

I should have phrased it differently. opp_np needs to be checked to deal with cases where devices don't have "operating-points-v2" associated with it.

drivers/opp/of.c +4 -4
index a5d87ca0ab571..06976d14e6ccb 100644
@@ -344,14 +344,14 @@ static int _bandwidth_supported(struct device *dev,
 struct opp_table *opp_table)
 
                opp_np = _opp_of_get_opp_desc_node(np, 0);
                of_node_put(np);
-
-               /* Lets not fail in case we are parsing opp-v1 bindings */
-               if (!opp_np)
-                       return 0;
        } else {
                opp_np = of_node_get(opp_table->np);
        }
 
+       /* Lets not fail in case we are parsing opp-v1 bindings */
+       if (!opp_np)
+               return 0;
+
 

sdhci_msm 7c4000.sdhci: OPP table empty
sdhci_msm 7c4000.sdhci: _allocate_opp_table: Error finding interconnect
paths: -22

Quoted 2 lines

I see the following errors without the check.

My reply unfortunately only considered the case where this routine was called from within the opp table. Are you testing it for the case where you are adding OPPs dynamically from the code ?

Signature · 1 line
viresh
#6 lore raw
Quoted 45 lines · Viresh Kumar
Quoted 44 lines · Sibi Sankar
Quoted 8 lines · Viresh Kumar
Quoted 2 lines · Sibi Sankar

opp_np needs to be subjected
to NULL check as well.

No, it isn't. It should already be valid and is set by the OPP core. Actually we don't need to do of_node_get(opp_table->np) and just use np, I did that to not have a special case while putting the resource.

I should have phrased it differently. opp_np needs to be checked to deal with cases where devices don't have "operating-points-v2" associated with it.

drivers/opp/of.c +0 -2
index a5d87ca0ab571..06976d14e6ccb 100644
@@ -344,14 +344,14 @@ static int _bandwidth_supported(struct device 
 *dev,
 struct opp_table *opp_table)
 
                opp_np = _opp_of_get_opp_desc_node(np, 0);
                of_node_put(np);
-
-               /* Lets not fail in case we are parsing opp-v1 

bindings */

drivers/opp/of.c +4 -2
-               if (!opp_np)
-                       return 0;
        } else {
                opp_np = of_node_get(opp_table->np);
        }
 
+       /* Lets not fail in case we are parsing opp-v1 bindings */
+       if (!opp_np)
+               return 0;
+

sdhci_msm 7c4000.sdhci: OPP table empty
sdhci_msm 7c4000.sdhci: _allocate_opp_table: Error finding interconnect
paths: -22

Quoted 6 lines
Quoted 2 lines

I see the following errors without the check.

My reply unfortunately only considered the case where this routine was called from within the opp table. Are you testing it for the case where you are adding OPPs dynamically from the code ?

Yeah dev_pm_opp_add/dev_pm_opp_set_clkname
or pretty much any api doing a
dev_pm_opp_get_opp_table without
a opp_table node associated with
it will run into this issue.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project.
#7 lore raw
Quoted 5 lines · Sibi Sankar

Yeah dev_pm_opp_add/dev_pm_opp_set_clkname
or pretty much any api doing a
dev_pm_opp_get_opp_table without
a opp_table node associated with
it will run into this issue.

Not sure if what you wrote now is correct, the problem shouldn't happen from within dev_pm_opp_set_clkname() but only when we try to do bw thing.

Anyway, I have pushed the change already.

Signature · 1 line
viresh
#8 lore raw
Quoted 7 lines · Viresh Kumar
Quoted 5 lines · Sibi Sankar

Yeah dev_pm_opp_add/dev_pm_opp_set_clkname
or pretty much any api doing a
dev_pm_opp_get_opp_table without
a opp_table node associated with
it will run into this issue.

Quoted 5 lines

Not sure if what you wrote now is correct, the problem shouldn't happen from within dev_pm_opp_set_clkname() but only when we try to do bw thing.

Anyway, I have pushed the change already.

cool, thanks!

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project.