Skip to contentSkip to conversation

PM / devfreq: Use freq_table for available_frequencies

PATCH MyungJoo Ham 2 participants 3 messages Apr 28, 2014 – May 5, 2014 Arm Qualcomm mailing list

lore
Share & tools
lore
#0 lore raw
Quoted 32 lines

Some devices use freq_table instead of OPP. For those devices, the available_frequencies file shows up empty. Fix that by using freq_table to generate the available_frequencies data when it's available.

OPP find frequency APIs also skips frequencies that have been temporarily disabled (say, due to thermal, etc). Since available_frequencies is supposed to show the entire list of available frequencies without taking temporary limits into consideration, preference is given to freq_table when available.

---
 drivers/devfreq/devfreq.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/devfreq/devfreq.c +1 -5
index 2042ec3..527cbe2 100644
@@ -912,20 +912,27 @@ static ssize_t available_frequencies_show(struct device *d,
 	struct devfreq *df = to_devfreq(d);
 	struct device *dev = df->dev.parent;
 	struct dev_pm_opp *opp;
+	unsigned int i = 0;
 	ssize_t count = 0;
 	unsigned long freq = 0;
 
-	rcu_read_lock();
-	do {
-		opp = dev_pm_opp_find_freq_ceil(dev, &freq);
-		if (IS_ERR(opp))
-			break;

drivers/devfreq/devfreq.c static ssize_t available_frequencies_show(struct device *d, · line 922

Quoted 10 lines
drivers/devfreq/devfreq.c +4 -6
-
-		count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
-				   "%lu ", freq);
-		freq++;
-	} while (1);
-	rcu_read_unlock();
+	if (df->profile->freq_table) {
+		for (i = 0; i < df->profile->max_state; i++)
+			count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
+					   "%u ", df->profile->freq_table[i]);

You are hereby changing the semmantics of the original available_frequencies node.

When a frequency/voltage pair has been disabled (opp_disable), probably by opp_disable(), the frequency is no more "available". However, when the driver author supplied freq_table as well as OPP in order to see the statistics, the node will behave differently.

Please do not affect the current users as long as it does not give additional benefit or fix a bug.

Cheers,
MyungJoo.

Quoted 20 lines
drivers/devfreq/devfreq.c +13 -0
+	} else {
+		rcu_read_lock();
+		do {
+			opp = dev_pm_opp_find_freq_ceil(dev, &freq);
+			if (IS_ERR(opp))
+				break;
+
+			count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
+					   "%lu ", freq);
+			freq++;
+		} while (1);
+		rcu_read_unlock();
+	}
 
 	/* Truncate the trailing space */
 	if (count)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#1 lore raw
Quoted 46 lines · MyungJoo Ham
Quoted 32 lines

Some devices use freq_table instead of OPP. For those devices, the available_frequencies file shows up empty. Fix that by using freq_table to generate the available_frequencies data when it's available.

OPP find frequency APIs also skips frequencies that have been temporarily disabled (say, due to thermal, etc). Since available_frequencies is supposed to show the entire list of available frequencies without taking temporary limits into consideration, preference is given to freq_table when available.

---
  drivers/devfreq/devfreq.c | 29 ++++++++++++++++++-----------
  1 file changed, 18 insertions(+), 11 deletions(-)
drivers/devfreq/devfreq.c +1 -5
index 2042ec3..527cbe2 100644
@@ -912,20 +912,27 @@ static ssize_t available_frequencies_show(struct device *d,
  	struct devfreq *df = to_devfreq(d);
  	struct device *dev = df->dev.parent;
  	struct dev_pm_opp *opp;
+	unsigned int i = 0;
  	ssize_t count = 0;
  	unsigned long freq = 0;
 
-	rcu_read_lock();
-	do {
-		opp = dev_pm_opp_find_freq_ceil(dev, &freq);
-		if (IS_ERR(opp))
-			break;

drivers/devfreq/devfreq.c static ssize_t available_frequencies_show(struct device *d, · line 922

Quoted 10 lines
drivers/devfreq/devfreq.c +4 -6
-
-		count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
-				   "%lu ", freq);
-		freq++;
-	} while (1);
-	rcu_read_unlock();
+	if (df->profile->freq_table) {
+		for (i = 0; i < df->profile->max_state; i++)
+			count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
+					   "%u ", df->profile->freq_table[i]);

You are hereby changing the semmantics of the original available_frequencies node.

Quoted 7 lines

When a frequency/voltage pair has been disabled (opp_disable), probably by opp_disable(), the frequency is no more "available". However, when the driver author supplied freq_table as well as OPP in order to see the statistics, the node will behave differently.

Please do not affect the current users as long as it does not give additional benefit or fix a bug.

I was actually trying to stick with the semantics as it was documented. The documentation for this file says it'll show frequencies that are not allowed by the current min/max settings either. To me, an OPP disable seems similar to some frequencies "disabled" by min/max settings.

Giving preference to OPP is not a hard change to do, but it seems to go againsts the documented semantics.

Thoughts?

-Saravana

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#2 lore raw
Quoted 17 lines · Saravana Kannan
Quoted 10 lines · MyungJoo Ham

You are hereby changing the semmantics of the original available_frequencies node.

When a frequency/voltage pair has been disabled (opp_disable), probably by opp_disable(), the frequency is no more "available". However, when the driver author supplied freq_table as well as OPP in order to see the statistics, the node will behave differently.

Please do not affect the current users as long as it does not give additional benefit or fix a bug.

I was actually trying to stick with the semantics as it was documented. The documentation for this file says it'll show frequencies that are not allowed by the current min/max settings either. To me, an OPP disable seems similar to some frequencies "disabled" by min/max settings.

Quoted 4 lines

Giving preference to OPP is not a hard change to do, but it seems to go againsts the documented semantics.

Thoughts?

I'll send out another patch like you wanted -- with OPP being given preference over freq_table when listing frequencies.

But I would still like to hear your thoughts. As of today, there's no clean way to get the complete list of available frequencies that would give a consistent output irrespective of the temporary limits/conditions imposed by thermal, current limiting, etc. The round about way is to cat trans_stat and parse the frequencies from that.

That's why I was trying to give preference to freq_table.

Thanks,
Saravana

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation