From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1D4A96E049 for ; Tue, 1 Sep 2020 05:52:15 +0000 (UTC) From: Ashutosh Dixit Date: Mon, 31 Aug 2020 22:52:00 -0400 Message-Id: <20200901025200.18406-1-ashutosh.dixit@intel.com> MIME-Version: 1.0 Subject: [igt-dev] [CI i-g-t] lib/ioctl_wrappers: Handle PREAD/PWRITE ioctls not supported in gem_read/write List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" To: igt-dev@lists.freedesktop.org List-ID: 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 --- lib/ioctl_wrappers.c | 65 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c index 3781286d8..7c985fe41 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 @@ -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,36 @@ 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); + + if (map) + gem_set_domain(fd, handle, + I915_GEM_DOMAIN_WC, I915_GEM_DOMAIN_WC); + } + + igt_assert(map); + 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 +420,33 @@ 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); + + if (map) + gem_set_domain(fd, handle, I915_GEM_DOMAIN_WC, 0); + } + + igt_assert(map); + 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 _______________________________________________ igt-dev mailing list igt-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/igt-dev