Skip to contentSkip to conversation

tunables: check usb autosuspend support before add

PATCH In review Nanley Chery 2 participants 3 messages Aug 25, 2014 – Sep 30, 2014

lore
Share & tools
lore

Nanley Chery

author
#0 lore raw

PATCH v2 1/1 tunables: check usb autosuspend support before add

Some usb devices do not have drivers that support autosuspend. These drivers should not be added to the list of tunables, because toggling their good/bad value does nothing.

Signed-off-by Nanley Chery <nanleychery(a)gmail.com>

---

Fixed the issue in the previous patch that allowed returning between opendir and closedir (thanks Sergey). Also improve detection of interface folders.

 src/tuning/tuningusb.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
src/tuning/tuningusb.cpp +19 -0
index 27a6dca..d2a0c11 100644
@@ -28,6 +28,7 @@
 #include "unistd.h"
 #include "tuningusb.h"
 #include <string.h>
+#include <dirent.h>
 #include <utility>
 #include <iostream>
 #include <fstream>
@@ -117,6 +118,7 @@ static void add_usb_callback(const char *d_name)
 {
 	class usb_tunable *usb;
 	char filename[4096];
+	DIR *dir;
 
 	sprintf(filename, "/sys/bus/usb/devices/%s/power/control", d_name);
 	if (access(filename, R_OK) != 0)
@@ -126,6 +128,23 @@ static void add_usb_callback(const char *d_name)
 	if (access(filename, R_OK)!=0)
 		return;
 
+	/* every interface of this device should support autosuspend */
+	sprintf(filename, "/sys/bus/usb/devices/%s", d_name);
+	if ((dir = opendir(filename))) {
+		struct dirent *entry;
+		while ((entry = readdir(dir))) {
+			/* dirname: <busnum>-<devnum>...:<config num>-<interface num> */
+			if (!isdigit(entry->d_name[0]))
+				continue;
+			sprintf(filename, "/sys/bus/usb/devices/%s/%s/supports_autosuspend", d_name, entry->d_name);
+			if (access(filename, R_OK) == 0 && read_sysfs(filename) == 0)
+				break;
+		}
+		closedir(dir);
+		if (entry)
+			return;
+	}
+
 	sprintf(filename, "/sys/bus/usb/devices/%s", d_name);
 	usb = new class usb_tunable(filename, d_name);
 	all_tunables.push_back(usb);
Signature · 1 line
2.0.4
#1 lore raw
Quoted 63 lines

Some usb devices do not have drivers that support autosuspend. These drivers should not be added to the list of tunables, because toggling their good/bad value does nothing.

Signed-off-by Nanley Chery <nanleychery(a)gmail.com>

---

Fixed the issue in the previous patch that allowed returning between opendir and closedir (thanks Sergey). Also improve detection of interface folders.

 src/tuning/tuningusb.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
src/tuning/tuningusb.cpp +19 -0
index 27a6dca..d2a0c11 100644
@@ -28,6 +28,7 @@
 #include "unistd.h"
 #include "tuningusb.h"
 #include <string.h>
+#include <dirent.h>
 #include <utility>
 #include <iostream>
 #include <fstream>
@@ -117,6 +118,7 @@ static void add_usb_callback(const char *d_name)
 {
 	class usb_tunable *usb;
 	char filename[4096];
+	DIR *dir;
 
 	sprintf(filename, "/sys/bus/usb/devices/%s/power/control", d_name);
 	if (access(filename, R_OK) != 0)
@@ -126,6 +128,23 @@ static void add_usb_callback(const char *d_name)
 	if (access(filename, R_OK)!=0)
 		return;
 
+	/* every interface of this device should support autosuspend */
+	sprintf(filename, "/sys/bus/usb/devices/%s", d_name);
+	if ((dir = opendir(filename))) {
+		struct dirent *entry;
+		while ((entry = readdir(dir))) {
+			/* dirname: <busnum>-<devnum>...:<config num>-<interface num> */
+			if (!isdigit(entry->d_name[0]))
+				continue;
+			sprintf(filename, "/sys/bus/usb/devices/%s/%s/supports_autosuspend",
 d_name, entry->d_name);
+			if (access(filename, R_OK) == 0 && read_sysfs(filename) == 0)
+				break;
+		}
+		closedir(dir);
+		if (entry)
+			return;
+	}
+
 	sprintf(filename, "/sys/bus/usb/devices/%s", d_name);
 	usb = new class usb_tunable(filename, d_name);

all_tunables.push_back(usb);
--
2.0.4

Quoted 5 lines

_______________________________________________
PowerTop mailing list
PowerTop(a)lists.01.org
https://lists.01.org/mailman/listinfo/powertop

Nanley,

Thank you very much for sending you patch. It was up-streamed today.

Alexandra.

author
#2 lore raw

Hello Alexandra,

Thank you for accepting this patch.

Nanley

Quoted 78 lines · Alexandra Yates
Quoted 36 lines

Some usb devices do not have drivers that support autosuspend. These drivers should not be added to the list of tunables, because toggling their good/bad value does nothing.

Signed-off-by Nanley Chery <nanleychery(a)gmail.com>

---

Fixed the issue in the previous patch that allowed returning between opendir and closedir (thanks Sergey). Also improve detection of interface folders.

 src/tuning/tuningusb.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
src/tuning/tuningusb.cpp +2 -0
index 27a6dca..d2a0c11 100644
@@ -28,6 +28,7 @@
 #include "unistd.h"
 #include "tuningusb.h"
 #include <string.h>
+#include <dirent.h>
 #include <utility>
 #include <iostream>
 #include <fstream>
@@ -117,6 +118,7 @@ static void add_usb_callback(const char *d_name)
 {
      class usb_tunable *usb;
      char filename[4096];
+     DIR *dir;
 
      sprintf(filename, "/sys/bus/usb/devices/%s/power/control", d_name);
      if (access(filename, R_OK) != 0)

src/tuning/tuningusb.cpp static void add_usb_callback(const char *d_name) · line 136

Quoted 9 lines
src/tuning/tuningusb.cpp +6 -0
@@ -126,6 +128,23 @@ static void add_usb_callback(const char *d_name)
      if (access(filename, R_OK)!=0)
              return;
 
+     /* every interface of this device should support autosuspend */
+     sprintf(filename, "/sys/bus/usb/devices/%s", d_name);
+     if ((dir = opendir(filename))) {
+             struct dirent *entry;
+             while ((entry = readdir(dir))) {
+                     /* dirname: <busnum>-<devnum>...:<config

num>-<interface num> */

src/tuning/tuningusb.cpp static void add_usb_callback(const char *d_name)

Quoted 3 lines
src/tuning/tuningusb.cpp +3 -0
+                     if (!isdigit(entry->d_name[0]))
+                             continue;
+                     sprintf(filename,

"/sys/bus/usb/devices/%s/%s/supports_autosuspend",

src/tuning/tuningusb.cpp static void add_usb_callback(const char *d_name) · line 141

Quoted 2 lines
src/tuning/tuningusb.cpp +1 -0
 d_name, entry->d_name);
+                     if (access(filename, R_OK) == 0 &&

read_sysfs(filename) == 0)

Quoted 10 lines
src/tuning/tuningusb.cpp +7 -0
+                             break;
+             }
+             closedir(dir);
+             if (entry)
+                     return;
+     }
+
      sprintf(filename, "/sys/bus/usb/devices/%s", d_name);
      usb = new class usb_tunable(filename, d_name);
      all_tunables.push_back(usb);
Quoted 8 lines

--
2.0.4

_______________________________________________
PowerTop mailing list
PowerTop(a)lists.01.org
https://lists.01.org/mailman/listinfo/powertop

Nanley,

Thank you very much for sending you patch. It was up-streamed today.

Alexandra.