summaryrefslogtreecommitdiff
path: root/lib/igt_aux.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-03-08 13:09:00 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2017-03-10 12:51:16 +0000
commite8eb9afd4c53e67d834f520a42a641adb874a463 (patch)
treefd8b98d66685e4f0dfd097d39b51bdf92e116311 /lib/igt_aux.c
parentdf75b388f915c813e69b3139e16c45ffe956c58b (diff)
igt: Exercise the shrinker
Introduce a new fork helper that spawns a process that just repeatedly calls i915_gem_shrink_all() and watch what happens as we try to use objects that have been shrunk. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib/igt_aux.c')
-rw-r--r--lib/igt_aux.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 5117dbec..7ee279a3 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -349,6 +349,45 @@ void igt_stop_signal_helper(void)
sig_stat = 0;
}
+static struct igt_helper_process shrink_helper;
+static void __attribute__((noreturn)) shrink_helper_process(pid_t pid)
+{
+ while (1) {
+ igt_drop_caches_set(DROP_SHRINK_ALL);
+ usleep(1000 * 1000 / 50);
+ if (kill(pid, 0)) /* Parent has died, so must we. */
+ exit(0);
+ }
+}
+
+/**
+ * igt_fork_shrink_helper:
+ *
+ * Fork a child process using #igt_fork_helper to force all available objects
+ * to be paged out (via i915_gem_shrink()).
+ *
+ * This is useful to exercise swapping paths, without requiring us to hit swap.
+ *
+ * This should only be used from an igt_fixture.
+ */
+void igt_fork_shrink_helper(void)
+{
+ assert(!igt_only_list_subtests());
+ igt_require(igt_drop_caches_has(DROP_SHRINK_ALL));
+ igt_fork_helper(&shrink_helper)
+ shrink_helper_process(getppid());
+}
+
+/**
+ * igt_stop_shrink_helper:
+ *
+ * Stops the child process spawned with igt_fork_shrink_helper().
+ */
+void igt_stop_shrink_helper(void)
+{
+ igt_stop_helper(&shrink_helper);
+}
+
#if HAVE_UDEV
#include <libudev.h>