Skip to contentSkip to conversation

confirm USB autosuspend support before adding as tunable

PATCH Superseded Nanley Chery 2 participants 3 messages Aug 24, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nanley Chery

author
#0 lore raw

cover confirm USB autosuspend support before adding as tunable

Make sure that a USB device supports autosuspend before we add it to the list of tunables. This problem was discovered downstream in the Debian bug 664455. If the device does not support autosuspend, its settings cannot be toggled.

The algorithm used to determine autosuspend susport is the same one found in the usb-pm-tools program. A USB device is added if every one of its interfaces supports autosuspend.

Nanley Chery (1):
tunables: check usb autosuspend support before add

 src/tuning/tuningusb.cpp | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
Signature · 1 line
2.0.4
author
#1 lore raw

PATCH 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>
---
 src/tuning/tuningusb.cpp | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
src/tuning/tuningusb.cpp +20 -0
index 27a6dca..ee86335 100644
@@ -28,6 +28,7 @@
 #include "unistd.h"
 #include "tuningusb.h"
 #include <string.h>
+#include <dirent.h>
 #include <utility>
 #include <iostream>
 #include <fstream>
@@ -126,6 +127,25 @@ 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);
+	DIR *dir = opendir(filename);
+	if (!dir)
+		return;
+	while (1) {
+		struct dirent *entry = readdir(dir);
+		if (!entry)
+			break;
+		if (entry->d_name[0] == '.')
+			continue;
+		sprintf(filename, "/sys/bus/usb/devices/%s/%s/supports_autosuspend", d_name, entry->d_name);
+		bool intf_path_found;
+		bool intf_supports_auto = read_sysfs(filename, &intf_path_found);
+		if (intf_path_found && !intf_supports_auto)
+			return;
+	}
+	closedir(dir);
+
 	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
#2 lore raw

Re: [Powertop] [PATCH 1/1] tunables: check usb autosuspend support before add

Quoted 25 lines · Nanley Chery
---
 src/tuning/tuningusb.cpp | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
src/tuning/tuningusb.cpp +6 -0
index 27a6dca..ee86335 100644
@@ -28,6 +28,7 @@
 #include "unistd.h"
 #include "tuningusb.h"
 #include <string.h>
+#include <dirent.h>
 #include <utility>
 #include <iostream>
 #include <fstream>
@@ -126,6 +127,25 @@ 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);
+	DIR *dir = opendir(filename);
+	if (!dir)
+		return;

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

Quoted 10 lines
src/tuning/tuningusb.cpp +10 -0
+	while (1) {
+		struct dirent *entry = readdir(dir);
+		if (!entry)
+			break;
+		if (entry->d_name[0] == '.')
+			continue;
+		sprintf(filename, "/sys/bus/usb/devices/%s/%s/supports_autosuspend", d_name, entry->d_name);
+		bool intf_path_found;
+		bool intf_supports_auto = read_sysfs(filename, &intf_path_found);
+		if (intf_path_found && !intf_supports_auto)

return; with dir open?

please consider to use process_directory() from lib.cpp

	-ss
Quoted 14 lines
src/tuning/tuningusb.cpp +3 -0
+	}
+	closedir(dir);
+
 	sprintf(filename, "/sys/bus/usb/devices/%s", d_name);
 	usb = new class usb_tunable(filename, d_name);
 	all_tunables.push_back(usb);
Signature · 6 lines
2.0.4

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