[igt-dev] [PATCH i-g-t 2/2] lib/i915: Replace size to pointer to size in __gem_create()

Chris Wilson chris at chris-wilson.co.uk
Mon Jan 11 11:55:12 UTC 2021


From: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>

Sometimes we're interested how much memory were allocated within
i915 driver so we have to change function prototype/implementation
to the pointer to the size.

As __gem_create() has few users change is simple and non-intrusive.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Andrzej Turko <andrzej.turko at linux.intel.com>
Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 lib/i915/gem.h                 |  2 +-
 lib/i915/gem_create.c          |  7 ++++---
 tests/i915/gem_fd_exhaustion.c |  5 +++--
 tests/i915/gem_softpin.c       | 15 ++++-----------
 4 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/lib/i915/gem.h b/lib/i915/gem.h
index 9178b773c..bd23a2776 100644
--- a/lib/i915/gem.h
+++ b/lib/i915/gem.h
@@ -32,7 +32,7 @@ void gem_quiescent_gpu(int i915);
 
 int gem_reopen_driver(int i915);
 
-int __gem_create(int fd, uint64_t size, uint32_t *handle);
+int __gem_create(int fd, uint64_t *size, uint32_t *handle);
 uint32_t gem_create(int fd, uint64_t size);
 
 #endif /* I915_GEM_H */
diff --git a/lib/i915/gem_create.c b/lib/i915/gem_create.c
index fa2ca1e37..a8c1a5813 100644
--- a/lib/i915/gem_create.c
+++ b/lib/i915/gem_create.c
@@ -10,15 +10,16 @@
 #include "igt_core.h"
 #include "ioctl_wrappers.h"
 
-int __gem_create(int fd, uint64_t size, uint32_t *handle)
+int __gem_create(int fd, uint64_t *size, uint32_t *handle)
 {
 	struct drm_i915_gem_create create = {
-		.size = size,
+		.size = *size,
 	};
 	int err = 0;
 
 	if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) == 0) {
 		*handle = create.handle;
+		*size = create.size;
 	} else {
 		err = -errno;
 		igt_assume(err != 0);
@@ -42,7 +43,7 @@ uint32_t gem_create(int fd, uint64_t size)
 {
 	uint32_t handle;
 
-	igt_assert_eq(__gem_create(fd, size, &handle), 0);
+	igt_assert_eq(__gem_create(fd, &size, &handle), 0);
 
 	return handle;
 }
diff --git a/tests/i915/gem_fd_exhaustion.c b/tests/i915/gem_fd_exhaustion.c
index 37c84e6c0..13e8a23a0 100644
--- a/tests/i915/gem_fd_exhaustion.c
+++ b/tests/i915/gem_fd_exhaustion.c
@@ -48,14 +48,15 @@ igt_simple_main
 
 		for (int i = 0; ; i++) {
 			int leak = open("/dev/null", O_RDONLY);
+			uint64_t size = 4096;
 			uint32_t handle;
 
-			if (__gem_create(fd, 4096, &handle) == 0)
+			if (__gem_create(fd, &size, &handle) == 0)
 				gem_close(fd, handle);
 
 			if (leak < 0) {
 				igt_info("fd exhaustion after %i rounds.\n", i);
-				igt_assert(__gem_create(fd, 4096,
+				igt_assert(__gem_create(fd, &size,
 							&handle) < 0);
 				break;
 			}
diff --git a/tests/i915/gem_softpin.c b/tests/i915/gem_softpin.c
index 516accc8f..b2514c99b 100644
--- a/tests/i915/gem_softpin.c
+++ b/tests/i915/gem_softpin.c
@@ -102,19 +102,12 @@ static void test_invalid(int fd)
 static uint32_t batch_create(int i915, uint64_t *sz)
 {
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
-	struct drm_i915_gem_create create = {
-		.size = sizeof(bbe),
-	};
-
-	if (igt_ioctl(i915, DRM_IOCTL_I915_GEM_CREATE, &create)) {
-		igt_assert_eq(errno, 0);
-		return 0;
-	}
+	uint32_t handle;
 
-	gem_write(i915, create.handle, 0, &bbe, sizeof(bbe));
+	igt_assert_eq(__gem_create(i915, sz, &handle), 0);
+	gem_write(i915, handle, 0, &bbe, sizeof(bbe));
 
-	*sz = create.size;
-	return create.handle;
+	return handle;
 }
 
 static void test_zero(int i915)
-- 
2.30.0



More information about the igt-dev mailing list