[igt-dev] [CI i-g-t] lib/ioctl_wrappers: Handle PREAD/PWRITE ioctls not supported in gem_read/write

Ashutosh Dixit ashutosh.dixit at intel.com
Mon Aug 31 22:52:06 UTC 2020


FOR CI ONLY. PLEASE DON'T REVIEW.

Trial patch to replace PREAD/PWRITE ioctls with mmap + memcpy in
gem_read/write.

Signed-off-by: Ashutosh Dixit <ashutosh.dixit at intel.com>
---
 lib/ioctl_wrappers.c | 61 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 2 deletions(-)

diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 3781286d8..b8e7118da 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -55,6 +55,7 @@
 #include "igt_debugfs.h"
 #include "igt_sysfs.h"
 #include "config.h"
+#include "i915/gem_mman.h"
 
 #ifdef HAVE_VALGRIND
 #include <valgrind/valgrind.h>
@@ -340,6 +341,11 @@ int __gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint6
 	return err;
 }
 
+static bool is_cache_coherent(int fd, uint32_t handle)
+{
+	return gem_get_caching(fd, handle) != I915_CACHING_NONE;
+}
+
 /**
  * gem_write:
  * @fd: open i915 drm file descriptor
@@ -353,7 +359,34 @@ int __gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint6
  */
 void gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint64_t length)
 {
-	igt_assert_eq(__gem_write(fd, handle, offset, buf, length), 0);
+	void *map = NULL;
+
+	if (is_cache_coherent(fd, handle)) {
+		map = __gem_mmap_offset__cpu(fd, handle, 0, offset + length,
+					     PROT_READ | PROT_WRITE);
+		if (!map)
+			map = __gem_mmap__cpu(fd, handle, 0, offset + length,
+					      PROT_READ | PROT_WRITE);
+
+		if (map)
+			gem_set_domain(fd, handle,
+				       I915_GEM_DOMAIN_CPU,
+				       I915_GEM_DOMAIN_CPU);
+	}
+
+	if (!map) {
+		map = __gem_mmap_offset__wc(fd, handle, 0, offset + length,
+					    PROT_READ | PROT_WRITE);
+		if (!map)
+			map = gem_mmap__wc(fd, handle, 0, offset + length,
+					   PROT_READ | PROT_WRITE);
+
+		gem_set_domain(fd, handle,
+			       I915_GEM_DOMAIN_WC, I915_GEM_DOMAIN_WC);
+	}
+
+	memcpy(map + offset, buf, length);
+	munmap(map, offset + length);
 }
 
 int __gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length)
@@ -385,7 +418,31 @@ int __gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t len
  */
 void gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length)
 {
-	igt_assert_eq(__gem_read(fd, handle, offset, buf, length), 0);
+	void *map = NULL;
+
+	if (gem_has_llc(fd) || is_cache_coherent(fd, handle)) {
+		map = __gem_mmap_offset__cpu(fd, handle, 0,
+					     offset + length, PROT_READ);
+		if (!map)
+			map = __gem_mmap__cpu(fd, handle, 0, offset + length,
+					      PROT_READ);
+
+		if (map)
+			gem_set_domain(fd, handle, I915_GEM_DOMAIN_CPU, 0);
+	}
+
+	if (!map) {
+		map = __gem_mmap_offset__wc(fd, handle, 0, offset + length,
+					    PROT_READ);
+		if (!map)
+			map = gem_mmap__wc(fd, handle, 0, offset + length,
+					   PROT_READ);
+
+		gem_set_domain(fd, handle, I915_GEM_DOMAIN_WC, 0);
+	}
+
+	memcpy(buf, map + offset, length);
+	munmap(map, offset + length);
 }
 
 int __gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write)
-- 
2.27.0.112.g101b3204f3



More information about the igt-dev mailing list