Skip to contentSkip to conversation

PM / devfreq: allow sysfs governor node to switch governor

PATCH MyungJoo Ham 2 participants 2 messages Nov 6, 2012 1 message not in the archive Device frequency (devfreq)

lore
Share & tools
lore

MyungJoo Ham

author maintainer
#0 lore raw
Quoted 4 lines
drivers/devfreq/devfreq.c +0 -0
@@ -629,6 +629,44 @@ static ssize_t show_governor(struct device *dev,
 	return sprintf(buf, "%s\n", to_devfreq(dev)->governor->name);

drivers/devfreq/devfreq.c static ssize_t show_governor(struct device *dev, · line 639

Quoted 10 lines
drivers/devfreq/devfreq.c +8 -0
 }
 
+static ssize_t store_governor(struct device *dev, struct device_attribute *attr,
+			      const char *buf, size_t count)
+{
+	struct devfreq *df = to_devfreq(dev);
+	int ret = 0;
+	struct devfreq_governor *governor;
+
+	mutex_lock(&devfreq_list_lock);

Please remove the trailing \n from buf here. When user enters "userspace", buf gets "userspace\n".

With some printks in find_devfreq_governor (printing the buf and governor names):

# echo userspace > /sys/class/devfreq/exynos4210-busfreq.0/governor
[   65.975000] [userspace
[   65.975000] ].[userspace]
[   65.980000] [userspace
[   65.980000] ].[powersave]
[   65.985000] [userspace
[   65.985000] ].[performance]
[   65.990000] [userspace
[   65.990000] ].[simple_ondemand]
[   65.995000] err no = -19
# 

Cheers,
MyungJoo

Quoted 20 lines
drivers/devfreq/devfreq.c +20 -0
+	governor = find_devfreq_governor(buf);
+	if (IS_ERR(governor)) {
+		ret = PTR_ERR(governor);
+		goto out;
+	}
+	if (df->governor == governor)
+		goto out;
+
+	if (df->governor) {
+		ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL);
+		if (ret) {
+			dev_warn(dev, "%s: Governor %s not stopped(%d)\n",
+				 __func__, df->governor->name, ret);
+			goto out;
+		}
+	}
+	df->governor = governor;
+	strncpy(df->governor_name, governor->name, DEVFREQ_NAME_LEN);
+	ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL);
+	if (ret)

drivers/devfreq/devfreq.c static ssize_t show_governor(struct device *dev, · line 669

Quoted 10 lines
drivers/devfreq/devfreq.c +10 -0
+		dev_warn(dev, "%s: Governor %s not started(%d)\n",
+			 __func__, df->governor->name, ret);
+out:
+	mutex_unlock(&devfreq_list_lock);
+
+	if (!ret)
+		ret = count;
+	return ret;
+}
+

[]

#2 lore raw
In reply to a message not in the archive
Quoted 37 lines · MyungJoo Ham

2012. 11. 6. 오후 6:02에 "MyungJoo Ham" <[email protected]>님이 작성:

Quoted 8 lines

drivers/devfreq/devfreq.c static ssize_t show_governor(struct device *dev, · line 632

Quoted 8 lines
drivers/devfreq/devfreq.c +1 -0
@@ -629,6 +629,44 @@ static ssize_t show_governor(struct device *dev,
      return sprintf(buf, "%s\n", to_devfreq(dev)->governor->name);
 }
 
+static ssize_t store_governor(struct device *dev, struct

device_attribute *attr,

Quoted 11 lines

drivers/devfreq/devfreq.c static ssize_t show_governor(struct device *dev, · line 639

Quoted 7 lines
drivers/devfreq/devfreq.c +7 -0
+                           const char *buf, size_t count)
+{
+     struct devfreq *df = to_devfreq(dev);
+     int ret = 0;
+     struct devfreq_governor *governor;
+
+     mutex_lock(&devfreq_list_lock);

Please remove the trailing \n from buf here. When user enters "userspace", buf gets "userspace\n".

Quoted 1 line

With some printks in find_devfreq_governor (printing the buf and governor

names):

Quoted 13 lines
# echo userspace > /sys/class/devfreq/exynos4210-busfreq.0/governor
[   65.975000] [userspace
[   65.975000] ].[userspace]
[   65.980000] [userspace
[   65.980000] ].[powersave]
[   65.985000] [userspace
[   65.985000] ].[performance]
[   65.990000] [userspace
[   65.990000] ].[simple_ondemand]
[   65.995000] err no = -19
#
Quoted 2 lines

Anyway this seems quite wierd. I will look more into this one in my target system.

Thanks for catching this.
:( I missed the \n (been using echo -n toooo often now grr..) What do you think of the following change to the patch?

drivers/devfreq/devfreq.c +7 -2
index 586b6fd..9a4e898 100644
@@ -614,11 +614,16 @@ static ssize_t store_governor(struct device *dev, struct device_attribute *attr,
 			      const char *buf, size_t count)
 {
 	struct devfreq *df = to_devfreq(dev);
-	int ret = 0;
+	int ret;
+	char str_governor[DEVFREQ_NAME_LEN + 1];
 	struct devfreq_governor *governor;
 
+	ret = sscanf(buf, "%" __stringify(DEVFREQ_NAME_LEN) "s", str_governor);
+	if (ret != 1)
+	        return -EINVAL;
+
 	mutex_lock(&devfreq_list_lock);
-	governor = find_devfreq_governor(buf);
+	governor = find_devfreq_governor(str_governor);
 	if (IS_ERR(governor)) {
 		ret = PTR_ERR(governor);
 		goto out;
Signature · 23 lines
Regards,
Nishanth Menon

output:
/sys/devices/platform/iva.0/devfreq/iva.0 # cat governor 
simple_ondemand
/sys/devices/platform/iva.0/devfreq/iva.0 # echo -n "userspace">governor 
/sys/devices/platform/iva.0/devfreq/iva.0 # echo -n "simple_ondeman">governor 
sh: write error: No such device
/sys/devices/platform/iva.0/devfreq/iva.0 # cat governor 
userspace
/sys/devices/platform/iva.0/devfreq/iva.0 # echo -n "simple_ondemand">governor 
/sys/devices/platform/iva.0/devfreq/iva.0 # cat governor 
simple_ondemand
/sys/devices/platform/iva.0/devfreq/iva.0 # echo "userspace">governor 
/sys/devices/platform/iva.0/devfreq/iva.0 # cat governor 
userspace
/sys/devices/platform/iva.0/devfreq/iva.0 # echo  "simple_ondemand">governor 
/sys/devices/platform/iva.0/devfreq/iva.0 # echo "userspace123123213123213123212
3123123131231">governor 
sh: write error: No such device
/sys/devices/platform/iva.0/devfreq/iva.0 # cat governor 
simple_ondemand