Fork and remap the same object into a new process space under a new file
descriptor. Principally to check list management and find scaling issues
in using such lists.

Signed-off-by: Chris Wilson <[email protected]>
Cc: Abdiel Janulgue <[email protected]>
---
 tests/i915/gem_mmap_gtt.c | 72 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 1 deletion(-)

diff --git a/tests/i915/gem_mmap_gtt.c b/tests/i915/gem_mmap_gtt.c
index a5f9d934e..756940ca4 100644
--- a/tests/i915/gem_mmap_gtt.c
+++ b/tests/i915/gem_mmap_gtt.c
@@ -34,8 +34,9 @@
 #include <inttypes.h>
 #include <pthread.h>
 #include <errno.h>
-#include <sys/stat.h>
 #include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
 #include "drm.h"
 
 #include "igt.h"
@@ -323,6 +324,73 @@ test_pf_nonblock(int i915)
        igt_spin_free(i915, spin);
 }
 
+static void
+test_fork_bomb(int i915)
+{
+       uint32_t *control;
+       uint32_t handle;
+       int dmabuf;
+
+       /* Rebind the same object into many different process adress spaces. */
+
+       control = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
+       igt_assert(control != MAP_FAILED);
+
+       handle = gem_create(i915, 4096);
+       dmabuf = prime_handle_to_fd(i915, handle);
+       gem_close(i915, handle);
+
+       igt_fork(child, 1) {
+               int fd[512];
+
+               atomic_fetch_add(&control[1], 1);
+               while (!READ_ONCE(control[0])) {
+                       int children;
+
+                       atomic_fetch_add(&control[2], 1);
+
+                       for (int i = 0; i < ARRAY_SIZE(fd); i++) {
+                               fd[i] = gem_reopen_driver(i915);
+
+                               handle = prime_fd_to_handle(fd[i], dmabuf);
+                               gem_mmap__gtt(fd[i], handle, 4096, PROT_WRITE);
+                               gem_close(fd[i], handle);
+
+                               /* leave the fd + mmap for process cleanup */
+                       }
+
+                       for (children = 0; children < 2; children++) {
+                               if (fork() > 0) { /* child */
+                                       atomic_fetch_add(&control[1], 1);
+                                       for (int i = 0; i < ARRAY_SIZE(fd); i++)
+                                               close(fd[i]);
+                                       break;
+                               }
+                       }
+                       if (children == 2) { /* parent */
+                               sched_yield();
+                               break;
+                       }
+               }
+               atomic_fetch_add(&control[1], -1);
+       }
+
+       sleep(30);
+
+       *control = 1;
+       igt_waitchildren();
+
+       while (READ_ONCE(control[1])) {
+               int status = 0;
+               wait(&status);
+       }
+
+       igt_info("Spawned %d children\n", control[2]);
+
+       close(dmabuf);
+       munmap(control, 4096);
+}
+
 static void
 test_isolation(int i915)
 {
@@ -1097,6 +1165,8 @@ igt_main
                test_flink_race(fd);
        igt_subtest("pf-nonblock")
                test_pf_nonblock(fd);
+       igt_subtest("fork-bomb")
+               test_fork_bomb(fd);
 
        igt_subtest("basic-small-bo")
                test_huge_bo(fd, -1, I915_TILING_NONE);
-- 
2.24.0

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

Reply via email to