Skip to contentSkip to conversation

Simplify hunting for drm card sysfs root

PATCH In review Tvrtko Ursulin 4 participants 9 messages Nov 28, 2017 – Nov 29, 2017 Library code

lore
Share & tools
lore
#0 lore raw

cover Simplify hunting for drm card sysfs root

From: Tvrtko Ursulin <[email protected]>

Short series to clean up the code and bit.

Thanks to Lionel for pointing out the convenient /sys/dev/char/<major>:<minor> symlink.

Tvrtko Ursulin (3):
lib/igt_sysfs: Remove support for finding sysfs path with no device
opened
lib/igt_sysfs: igt_sysfs_path only works for master nodes lib/igt_sysfs: Simplify igt_sysfs_path

 lib/igt_sysfs.c | 47 ++++++++++++++++-------------------------------
 1 file changed, 16 insertions(+), 31 deletions(-)
Signature · 6 lines
2.14.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 1/3 lib/igt_sysfs: Remove support for finding sysfs path with no device opened

From: Tvrtko Ursulin <[email protected]>

It looks like no callers actually use this so remove it to simplify.

---
 lib/igt_sysfs.c | 39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)
lib/igt_sysfs.c +16 -23
index e7c67dae3a13..dd057dc04947 100644
@@ -102,33 +102,26 @@ char *igt_sysfs_path(int device, char *path, int pathlen, int *idx)
 {
 	struct stat st;
 
-	if (device != -1 && (fstat(device, &st) || !S_ISCHR(st.st_mode)))
+	if (device < 0 || fstat(device, &st) || !S_ISCHR(st.st_mode))
 		return NULL;
 
 	for (int n = 0; n < 16; n++) {
 		int len = snprintf(path, pathlen, "/sys/class/drm/card%d", n);
-		if (device != -1) {
-			FILE *file;
-			int ret, maj, min;
-
-			sprintf(path + len, "/dev");
-			file = fopen(path, "r");
-			if (!file)
-				continue;
-
-			ret = fscanf(file, "%d:%d", &maj, &min);
-			fclose(file);
-
-			if (ret != 2 ||
-			    major(st.st_rdev) != maj ||
-			    minor(st.st_rdev) != min)
-				continue;
-		} else {
-			/* Bleh. Search for intel */
-			sprintf(path + len, "/error");
-			if (stat(path, &st))
-				continue;
-		}
+		int ret, maj, min;
+		FILE *file;
+
+		sprintf(path + len, "/dev");
+		file = fopen(path, "r");
+		if (!file)
+			continue;
+
+		ret = fscanf(file, "%d:%d", &maj, &min);
+		fclose(file);
+
+		if (ret != 2 ||
+			major(st.st_rdev) != maj ||
+			minor(st.st_rdev) != min)
+			continue;
 
 		path[len] = '\0';
 		if (idx)
Signature · 6 lines
2.14.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

Re: [PATCH i-g-t 1/3] lib/igt_sysfs: Remove support for finding sysfs path with no device opened

Quoting Tvrtko Ursulin (2017-11-28 18:09:55)

Quoted 3 lines

From: Tvrtko Ursulin <[email protected]>

It looks like no callers actually use this so remove it to simplify.

We just added more users to the equivalent for debugfs, and accepting -1 here was simply to have consistency with our debugfs api.

If that makes any difference, principle of least surprise or something. -Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw

PATCH 2/3 lib/igt_sysfs: igt_sysfs_path only works for master nodes

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

DRM code defines the minor range for master nodes as 0-63, so express that explicitly near the top of the function.

---
 lib/igt_sysfs.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/igt_sysfs.c +4 -0
index dd057dc04947..f0fef8d434ef 100644
@@ -105,6 +105,10 @@ char *igt_sysfs_path(int device, char *path, int pathlen, int *idx)
 	if (device < 0 || fstat(device, &st) || !S_ISCHR(st.st_mode))
 		return NULL;
 
+	/* Only support master nodes. */
+	if (minor(st.st_rdev) >= 64)
+		return NULL;
+
 	for (int n = 0; n < 16; n++) {
 		int len = snprintf(path, pathlen, "/sys/class/drm/card%d", n);
 		int ret, maj, min;
Signature · 6 lines
2.14.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

Re: [PATCH i-g-t 2/3] lib/igt_sysfs: igt_sysfs_path only works for master nodes

Quoting Tvrtko Ursulin (2017-11-28 18:09:56)

Quoted 4 lines

From: Tvrtko Ursulin <[email protected]>

DRM code defines the minor range for master nodes as 0-63, so express that explicitly near the top of the function.

We do use rendernodes, so we had better support them correctly. I thought the premise of /sys/dev/char/$maj:$min/ was that it would work with render as well as master nodes.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw

Re: [PATCH i-g-t 2/3] lib/igt_sysfs: igt_sysfs_path only works for master nodes

Quoted 9 lines · Chris Wilson

Quoting Tvrtko Ursulin (2017-11-28 18:09:56)

Quoted 4 lines

From: Tvrtko Ursulin <[email protected]>

DRM code defines the minor range for master nodes as 0-63, so express that explicitly near the top of the function.

We do use rendernodes, so we had better support them correctly. I thought the premise of /sys/dev/char/$maj:$min/ was that it would work with render as well as master nodes.

It's doable, but since the current code does not support them I did not feel the responsibility to extend the functionality in that way.

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#6 lore raw

PATCH 3/3 lib/igt_sysfs: Simplify igt_sysfs_path

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

There is no need to iterate over /sys/class/drm/card* directories looking for the one which matches our major and minor, when we can directly find the right one via the /sys/dev/char/<major>:<minor> symlink.

---
 lib/igt_sysfs.c | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)
lib/igt_sysfs.c +12 -24
index f0fef8d434ef..a4a87711ed0c 100644
@@ -100,40 +100,28 @@ static int writeN(int fd, const char *buf, int len)
  */
 char *igt_sysfs_path(int device, char *path, int pathlen, int *idx)
 {
+	unsigned int maj, min;
 	struct stat st;
+	int len;
 
 	if (device < 0 || fstat(device, &st) || !S_ISCHR(st.st_mode))
 		return NULL;
 
+	maj = major(st.st_rdev);
+	min = minor(st.st_rdev);
+
 	/* Only support master nodes. */
-	if (minor(st.st_rdev) >= 64)
+	if (min >= 64)
 		return NULL;
 
-	for (int n = 0; n < 16; n++) {
-		int len = snprintf(path, pathlen, "/sys/class/drm/card%d", n);
-		int ret, maj, min;
-		FILE *file;
-
-		sprintf(path + len, "/dev");
-		file = fopen(path, "r");
-		if (!file)
-			continue;
-
-		ret = fscanf(file, "%d:%d", &maj, &min);
-		fclose(file);
-
-		if (ret != 2 ||
-			major(st.st_rdev) != maj ||
-			minor(st.st_rdev) != min)
-			continue;
+	len = snprintf(path, pathlen, "/sys/dev/char/%u:%u", maj, min);
+	if (len == pathlen)
+		return NULL;
 
-		path[len] = '\0';
-		if (idx)
-			*idx = n;
-		return path;
-	}
+	if (idx)
+		*idx = min;
 
-	return NULL;
+	return path;
 }
 
 /**
Signature · 6 lines
2.14.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

✓ Fi.CI.BAT: success for Simplify hunting for drm card sysfs root

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: Simplify hunting for drm card sysfs root
URL : https://patchwork.freedesktop.org/series/34559/
State : success

== Summary ==

IGT patchset tested on top of latest successful build 380cc811486ba3fefbe3ebe4761afa7e169dcd3e tests/perf_pmu: Sync invalid-init with i915 changes

with latest DRM-Tip kernel build CI_DRM_3402
514443844882 drm-tip: 2017y-11m-28d-17h-04m-56s UTC integration manifest

No testlist changes.

Test kms_pipe_crc_basic:

        Subgroup suspend-read-crc-pipe-b:
                pass       -> INCOMPLETE (fi-snb-2520m) fdo#103713

fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713

fi-bdw-5557u     total:288  pass:267  dwarn:0   dfail:0   fail:0   skip:21  time:446s
fi-bdw-gvtdvm    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:449s
fi-blb-e6850     total:288  pass:223  dwarn:1   dfail:0   fail:0   skip:64  time:382s
fi-bsw-n3050     total:288  pass:242  dwarn:0   dfail:0   fail:0   skip:46  time:521s
fi-bwr-2160      total:288  pass:183  dwarn:0   dfail:0   fail:0   skip:105 time:278s
fi-bxt-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:500s
fi-bxt-j4205     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:504s
fi-byt-j1900     total:288  pass:253  dwarn:0   dfail:0   fail:0   skip:35  time:483s
fi-byt-n2820     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:475s
fi-elk-e7500     total:288  pass:229  dwarn:0   dfail:0   fail:0   skip:59  time:426s
fi-gdg-551       total:288  pass:178  dwarn:1   dfail:0   fail:1   skip:108 time:269s
fi-glk-1         total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:539s
fi-hsw-4770      total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:374s
fi-hsw-4770r     total:288  pass:224  dwarn:0   dfail:0   fail:0   skip:64  time:262s
fi-ivb-3520m     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:480s
fi-kbl-7500u     total:288  pass:263  dwarn:1   dfail:0   fail:0   skip:24  time:484s
fi-kbl-7560u     total:288  pass:269  dwarn:0   dfail:0   fail:0   skip:19  time:525s
fi-kbl-7567u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:478s
fi-kbl-r         total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:531s
fi-skl-6260u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:452s
fi-skl-6600u     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:538s
fi-skl-6700hq    total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:568s
fi-skl-6700k     total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:517s
fi-skl-6770hq    total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:518s
fi-skl-gvtdvm    total:288  pass:265  dwarn:0   dfail:0   fail:0   skip:23  time:451s
fi-snb-2520m     total:245  pass:211  dwarn:0   dfail:0   fail:0   skip:33 
fi-snb-2600      total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:421s
Blacklisted hosts:
fi-cfl-s2        total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:602s
fi-cnl-y         total:217  pass:196  dwarn:0   dfail:0   fail:0   skip:20 
fi-glk-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:490s

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_560/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw

✓ Fi.CI.IGT: success for Simplify hunting for drm card sysfs root

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: Simplify hunting for drm card sysfs root
URL : https://patchwork.freedesktop.org/series/34559/
State : success

== Summary ==

Blacklisted hosts:

shard-hsw        total:2661 pass:1524 dwarn:11  dfail:0   fail:10  skip:1116 time:9265s
shard-kbl        total:2325 pass:1553 dwarn:19  dfail:15  fail:13  skip:716 time:8743s
shard-snb        total:2508 pass:1216 dwarn:15  dfail:7   fail:5   skip:1260 time:7103s

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_560/shards.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx