Skip to contentSkip to conversation

PM / devfreq: Add sysfs node to expose available frequencies

PATCH Superseded Nishanth Menon 2 participants 4 messages Oct 25, 2012 – Oct 26, 2012 Device frequency (devfreq)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / devfreq: Add sysfs node to expose available frequencies

devfreq governors such as ondemand are controlled by a min and max frequency, while governors like userspace governor allow us to set a specific frequency.
However, for the same specific device, depending on the SoC, the available frequencies can vary.

So expose the available frequencies as a snapshot over sysfs to allow informed decisions.

This was inspired by cpufreq framework's equivalent for similar usage sysfs node: scaling_available_frequencies.

Cc Rajagopal Venkat <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Kevin Hilman <[email protected]>

---
Applies on top of Rafael's linux-next branch:
git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
linux-next b960e9a Merge branch 'pm-sleep-next' into linux-next

Example output from Beagleboard XM (3730) using a dummy test driver
http://pastebin.pandaboard.org/index.php/view/85100576 :

/sys/devices/platform/iva.0/devfreq/iva.0 # cat available_frequencies 260000000 520000000 660000000

 Documentation/ABI/testing/sysfs-class-devfreq |    9 +++++++++
 drivers/devfreq/devfreq.c                     |   26 +++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
Documentation/ABI/testing/sysfs-class-devfreq +9 -0
index e6cf08e..e672ccb 100644
@@ -51,3 +51,12 @@ Description:
 		The /sys/class/devfreq/.../userspace/set_freq shows and
 		sets the requested frequency for the devfreq object if
 		userspace governor is in effect.
+
+What:		/sys/class/devfreq/.../available_frequencies
+Date:		October 2012
+Contact:	Nishanth Menon <[email protected]>
+Description:
+		The /sys/class/devfreq/.../available_frequencies shows
+		the available frequencies of the corresponding devfreq object.
+		This is a snapshot of available frequencies and not limited
+		by the min/max frequency restrictions.
drivers/devfreq/devfreq.c +26 -0
index d02ee7e..2f6ad6b 100644
@@ -571,9 +571,35 @@ static ssize_t show_max_freq(struct device *dev, struct device_attribute *attr,
 	return sprintf(buf, "%lu\n", to_devfreq(dev)->max_freq);
 }
 
+static ssize_t show_available_freqs(struct device *d,
+				    struct device_attribute *attr,
+				    char *buf)
+{
+	struct devfreq *df = to_devfreq(d);
+	struct device *dev = df->dev.parent;
+	struct opp *opp;
+	ssize_t count = 0;
+	unsigned long freq = 0;
+
+	rcu_read_lock();
+	do {
+		opp = opp_find_freq_ceil(dev, &freq);
+		if (IS_ERR(opp))
+			break;
+
+		count += sprintf(&buf[count], "%lu ", freq);
+		freq++;
+	} while (1);
+	rcu_read_unlock();
+	count += sprintf(&buf[count], "\n");
+
+	return count;
+}
+
 static struct device_attribute devfreq_attrs[] = {
 	__ATTR(governor, S_IRUGO, show_governor, NULL),
 	__ATTR(cur_freq, S_IRUGO, show_freq, NULL),
+	__ATTR(available_frequencies, S_IRUGO, show_available_freqs, NULL),
 	__ATTR(target_freq, S_IRUGO, show_target_freq, NULL),
 	__ATTR(polling_interval, S_IRUGO | S_IWUSR, show_polling_interval,
 	       store_polling_interval),
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 72 lines · Nishanth Menon

devfreq governors such as ondemand are controlled by a min and max frequency, while governors like userspace governor allow us to set a specific frequency.
However, for the same specific device, depending on the SoC, the available frequencies can vary.

So expose the available frequencies as a snapshot over sysfs to allow informed decisions.

This was inspired by cpufreq framework's equivalent for similar usage sysfs node: scaling_available_frequencies.

Cc Rajagopal Venkat <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Kevin Hilman <[email protected]>

---
Applies on top of Rafael's linux-next branch:
git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
linux-next b960e9a Merge branch 'pm-sleep-next' into linux-next

Example output from Beagleboard XM (3730) using a dummy test driver
http://pastebin.pandaboard.org/index.php/view/85100576 :

/sys/devices/platform/iva.0/devfreq/iva.0 # cat available_frequencies 260000000 520000000 660000000

 Documentation/ABI/testing/sysfs-class-devfreq |    9 +++++++++
 drivers/devfreq/devfreq.c                     |   26 +++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
Documentation/ABI/testing/sysfs-class-devfreq +9 -0
index e6cf08e..e672ccb 100644
@@ -51,3 +51,12 @@ Description:
 		The /sys/class/devfreq/.../userspace/set_freq shows and
 		sets the requested frequency for the devfreq object if
 		userspace governor is in effect.
+
+What:		/sys/class/devfreq/.../available_frequencies
+Date:		October 2012
+Contact:	Nishanth Menon <[email protected]>
+Description:
+		The /sys/class/devfreq/.../available_frequencies shows
+		the available frequencies of the corresponding devfreq object.
+		This is a snapshot of available frequencies and not limited
+		by the min/max frequency restrictions.
drivers/devfreq/devfreq.c +11 -0
index d02ee7e..2f6ad6b 100644
@@ -571,9 +571,35 @@ static ssize_t show_max_freq(struct device *dev, struct device_attribute *attr,
 	return sprintf(buf, "%lu\n", to_devfreq(dev)->max_freq);
 }
 
+static ssize_t show_available_freqs(struct device *d,
+				    struct device_attribute *attr,
+				    char *buf)
+{
+	struct devfreq *df = to_devfreq(d);
+	struct device *dev = df->dev.parent;
+	struct opp *opp;
+	ssize_t count = 0;
+	unsigned long freq = 0;
+
+	rcu_read_lock();

drivers/devfreq/devfreq.c static ssize_t show_max_freq(struct device *dev, struct device_attribute *attr, · line 594

Quoted 10 lines
drivers/devfreq/devfreq.c +10 -0
+	do {
+		opp = opp_find_freq_ceil(dev, &freq);
+		if (IS_ERR(opp))
+			break;
+
+		count += sprintf(&buf[count], "%lu ", freq);
+		freq++;
+	} while (1);
+	rcu_read_unlock();
+	count += sprintf(&buf[count], "\n");

Care to avoid printing the tailing space?

Rafael

Quoted 12 lines
drivers/devfreq/devfreq.c +5 -0
+
+	return count;
+}
+
 static struct device_attribute devfreq_attrs[] = {
 	__ATTR(governor, S_IRUGO, show_governor, NULL),
 	__ATTR(cur_freq, S_IRUGO, show_freq, NULL),
+	__ATTR(available_frequencies, S_IRUGO, show_available_freqs, NULL),
 	__ATTR(target_freq, S_IRUGO, show_target_freq, NULL),
 	__ATTR(polling_interval, S_IRUGO | S_IWUSR, show_polling_interval,
 	       store_polling_interval),
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#2 lore raw
Quoted 1 line · Rafael J. Wysocki

On Thursday, October 25, 2012 06:32:43 PM Nishanth Menon wrote:

[..]

Quoted 15 lines
Quoted 15 lines
drivers/devfreq/devfreq.c +15 -0
+static ssize_t show_available_freqs(struct device *d,
+				    struct device_attribute *attr,
+				    char *buf)
+{
+	struct devfreq *df = to_devfreq(d);
+	struct device *dev = df->dev.parent;
+	struct opp *opp;
+	ssize_t count = 0;
+	unsigned long freq = 0;
+
+	rcu_read_lock();
+	do {
+		opp = opp_find_freq_ceil(dev, &freq);
+		if (IS_ERR(opp))
+			break;
Quoted 8 lines

drivers/devfreq/devfreq.c static ssize_t show_max_freq(struct device *dev, struct device_attribute *attr, · line 594

Quoted 6 lines
drivers/devfreq/devfreq.c +6 -0
+
+		count += sprintf(&buf[count], "%lu ", freq);
+		freq++;
+	} while (1);
+	rcu_read_unlock();
+	count += sprintf(&buf[count], "\n");

Care to avoid printing the tailing space?

count -= count ? 1 : 0;
count += sprintf(&buf[count], "\n");
should take care of empty list and the trailing space. Sounds reasonable?

Signature · 2 lines
Regards,
Nishanth Menon
#3 lore raw
Quoted 26 lines · Nishanth Menon
Quoted 1 line · Rafael J. Wysocki

On Thursday, October 25, 2012 06:32:43 PM Nishanth Menon wrote:

[..]

Quoted 15 lines
Quoted 15 lines
drivers/devfreq/devfreq.c +15 -0
+static ssize_t show_available_freqs(struct device *d,
+				    struct device_attribute *attr,
+				    char *buf)
+{
+	struct devfreq *df = to_devfreq(d);
+	struct device *dev = df->dev.parent;
+	struct opp *opp;
+	ssize_t count = 0;
+	unsigned long freq = 0;
+
+	rcu_read_lock();
+	do {
+		opp = opp_find_freq_ceil(dev, &freq);
+		if (IS_ERR(opp))
+			break;
Quoted 8 lines

drivers/devfreq/devfreq.c static ssize_t show_max_freq(struct device *dev, struct device_attribute *attr, · line 594

Quoted 6 lines
drivers/devfreq/devfreq.c +6 -0
+
+		count += sprintf(&buf[count], "%lu ", freq);
+		freq++;
+	} while (1);
+	rcu_read_unlock();
+	count += sprintf(&buf[count], "\n");

Care to avoid printing the tailing space?

Quoted 1 line

count -= count ? 1 : 0;

What about

if (count)
count--;

instead?

Quoted 2 lines

count += sprintf(&buf[count], "\n");
should take care of empty list and the trailing space. Sounds reasonable?

Thanks,
Rafael

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