Skip to contentSkip to conversation

igt/gem_ringfill: Adds ringbuffer full preemption test

PATCH In review Antonio Argenziano 4 participants 5 messages Aug 24, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 igt/gem_ringfill: Adds ringbuffer full preemption test

The testcase added here, stimulates this scenario where a high priority request is sent while another process keeps submitting requests and filling its ringbuffer.

From RFC (Chris):
- Use two FDs, one for each priority submission.
- Move from gem_ringfill to gem_exec_schedule.
- Bound processes to same cpu and wake with signals.

Cc Chris Wilson <[email protected]>
---
 tests/gem_exec_schedule.c | 113 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 112 insertions(+), 1 deletion(-)
tests/gem_exec_schedule.c +112 -1
index f2847863..476626e6 100644
@@ -21,7 +21,12 @@
  * IN THE SOFTWARE.
  */
 
+#define _GNU_SOURCE
+#include <sched.h>
+#include <signal.h>
+
 #include <sys/poll.h>
+#include <sys/ioctl.h>
 
 #include "igt.h"
 #include "igt_vgem.h"
@@ -39,6 +44,15 @@
 
 IGT_TEST_DESCRIPTION("Check that we can control the order of execution");
 
+static void alarm_handler(int sig)
+{
+}
+
+static int __execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
+{
+	return ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf);
+}
+
 static int __ctx_set_priority(int fd, uint32_t ctx, int prio)
 {
 	struct local_i915_gem_context_param param;
@@ -659,6 +673,95 @@ static bool has_scheduler(int fd)
 	return has > 0;
 }
 
+static void bind_to_cpu(int cpu)
+{
+	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+	cpu_set_t allowed;
+
+	CPU_ZERO(&allowed);
+	CPU_SET(cpu % ncpus, &allowed);
+	igt_assert(sched_setaffinity(getpid(), sizeof(cpu_set_t), &allowed) == 0);
+}
+
+static void setup_timer(int timeout)
+{
+	struct itimerval itv;
+	struct sigaction sa = { .sa_handler = alarm_handler };
+
+	sigaction(SIGALRM, &sa, NULL);
+	itv.it_interval.tv_sec = 0;
+	itv.it_interval.tv_usec = 100;
+	itv.it_value.tv_sec = 0;
+	itv.it_value.tv_usec = timeout * 1000;
+	setitimer(ITIMER_REAL, &itv, NULL);
+}
+
+/*
+ * This test checks that is possible for a high priority request to trigger a
+ * preemption if another context has filled its ringbuffer.
+ * The aim of the test is to make sure that high priority requests cannot be
+ * stalled by low priority tasks.
+ * */
+static void preempt_while_ringbuffer_full(int fd, uint32_t engine)
+{
+	uint32_t hp_fd;
+	uint32_t hp_ctx, lp_ctx;
+	struct drm_i915_gem_exec_object2 obj, hp_obj;
+	struct drm_i915_gem_execbuffer2 execbuf;
+
+	const unsigned timeout = 10; /*ms*/
+	const uint32_t bbe = MI_BATCH_BUFFER_END;
+
+	hp_fd = drm_open_driver(DRIVER_INTEL);
+
+	memset(&execbuf, 0, sizeof(execbuf));
+	memset(&obj, 0, sizeof(obj));
+	memset(&hp_obj, 0, sizeof(hp_obj));
+
+	lp_ctx = gem_context_create(fd);
+	ctx_set_priority(fd, lp_ctx, -MAX_PRIO);
+
+	hp_ctx = gem_context_create(hp_fd);
+	ctx_set_priority(hp_fd, hp_ctx, MAX_PRIO);
+
+	hp_obj.handle =  gem_create(fd, 4096);
+	gem_write(fd, hp_obj.handle, 0, &bbe, sizeof(bbe));
+
+	obj.handle =  gem_create(fd, 4096);
+	gem_write(fd, obj.handle, 0, &bbe, sizeof(bbe));
+
+	execbuf.buffers_ptr = to_user_pointer(&obj);
+	execbuf.flags = engine;
+	execbuf.buffer_count = 1;
+	execbuf.rsvd1 = lp_ctx;
+
+	/*Stall execution and fill ring*/
+	igt_spin_batch_new(fd, lp_ctx, engine, 0);
+
+	setup_timer(timeout);
+	while (__execbuf(fd, &execbuf) == 0)
+		;
+
+	/* steal cpu */
+	bind_to_cpu(0);
+	igt_fork(child, 1) {
+		/* this child is forced to wait for parent to sleep */
+		execbuf.buffers_ptr = to_user_pointer(&hp_obj);
+		execbuf.rsvd1 = hp_ctx;
+		setup_timer(timeout);
+		if (__execbuf(fd, &execbuf)) {
+			igt_assert_f(0, "Failed High priority submission.\n");
+			igt_terminate_spin_batches();
+		}
+	}
+
+	/* process sleeps waiting for space to free, releasing child */
+	setup_timer(2*timeout);
+	__execbuf(fd, &execbuf);
+	igt_terminate_spin_batches();
+	igt_waitchildren();
+}
+
 igt_main
 {
 	const struct intel_execution_engine *e;
@@ -669,7 +772,7 @@ igt_main
 	igt_fixture {
 		fd = drm_open_driver_master(DRIVER_INTEL);
 		igt_require_gem(fd);
-		gem_require_mmap_wc(fd);
+		//gem_require_mmap_wc(fd);
 		igt_fork_hang_detector(fd);
 	}
 
@@ -731,6 +834,14 @@ igt_main
 		}
 	}
 
+	igt_subtest_group {
+			for (e = intel_execution_engines; e->name; e++) {
+				igt_subtest_f("preempt-while-full-%s", e->name) {
+					preempt_while_ringbuffer_full(fd, e->exec_id | e->flags);
+				}
+			}
+	}
+
 	igt_fixture {
 		igt_stop_hang_detector();
 		close(fd);
Signature · 6 lines
2.14.1

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

✗ Fi.CI.BAT: failure for igt/gem_ringfill: Adds ringbuffer full preemption test

== Series Details ==

== Series Details ==

Series: igt/gem_ringfill: Adds ringbuffer full preemption test
URL : https://patchwork.freedesktop.org/series/29252/
State : failure

== Summary ==

IGT patchset build failed on latest successful build 7552c5af1f43386424085c32bca3cbd0cb0dfe48 intel-ci: Add fast chamelium tests to the fast-feedback list

make all-recursive
Making all in lib
make all-recursive
Making all in .
Making all in tests
make[4]: Nothing to be done for 'all'.
Making all in man
make[2]: Nothing to be done for 'all'.
Making all in tools
Making all in null_state_gen
make[3]: Nothing to be done for 'all'.
Making all in registers
make[3]: Nothing to be done for 'all'.
make[3]: Nothing to be done for 'all-am'.
Making all in scripts
make[2]: Nothing to be done for 'all'.
Making all in benchmarks
make[2]: Nothing to be done for 'all'.
Making all in tests
Making all in intel-ci
make[3]: Nothing to be done for 'all'.

  CCLD     gem_bad_batch
  CCLD     gem_hang
  CCLD     gem_bad_blit
  CCLD     gem_bad_address
  CCLD     gem_non_secure_batch
  CCLD     gem_stress
  CCLD     core_auth
  CCLD     core_get_client_auth
  CCLD     core_getclient
  CCLD     core_getstats
  CCLD     core_getversion
  CCLD     core_prop_blob
  CCLD     core_setmaster_vs_auth
  CCLD     debugfs_test
  CCLD     drm_import_export
  CCLD     drm_mm
  CCLD     drm_read
  CCLD     drm_vma_limiter
  CCLD     drm_vma_limiter_cached
  CCLD     drm_vma_limiter_cpu
  CCLD     drm_vma_limiter_gtt
  CCLD     drv_getparams_basic
  CCLD     drv_hangman
  CCLD     drv_missed_irq
  CCLD     drv_module_reload
  CCLD     drv_selftest
  CCLD     drv_suspend
  CCLD     gem_bad_length
  CCLD     gem_bad_reloc
  CCLD     gem_basic
  CCLD     gem_busy
  CCLD     gem_caching
  CCLD     gem_close_race
  CCLD     gem_concurrent_blit
  CCLD     gem_cpu_reloc
  CCLD     gem_create
  CCLD     gem_cs_prefetch
  CCLD     gem_cs_tlb
  CCLD     gem_ctx_bad_destroy
  CCLD     gem_ctx_bad_exec
  CCLD     gem_ctx_basic
  CCLD     gem_ctx_create
  CCLD     gem_ctx_exec
  CCLD     gem_ctx_param
  CCLD     gem_ctx_switch
  CCLD     gem_ctx_thrash
  CCLD     gem_double_irq_loop
  CCLD     gem_eio
  CCLD     gem_evict_alignment
  CCLD     gem_evict_everything
  CCLD     gem_exec_alignment
  CCLD     gem_exec_async
  CCLD     gem_exec_await
  CCLD     gem_exec_bad_domains
  CCLD     gem_exec_basic
  CCLD     gem_exec_big
  CCLD     gem_exec_blt
  CCLD     gem_exec_capture
  CCLD     gem_exec_create
  CCLD     gem_exec_faulting_reloc
  CCLD     gem_exec_fence
  CCLD     gem_exec_flush
  CCLD     gem_exec_gttfill
  CCLD     gem_exec_latency
  CCLD     gem_exec_lut_handle
  CCLD     gem_exec_nop
  CCLD     gem_exec_parallel
  CCLD     gem_exec_params
  CCLD     gem_exec_parse
  CCLD     gem_exec_reloc
  CCLD     gem_exec_reuse
  CC       gem_exec_schedule.o

Makefile:3922: recipe for target 'gem_exec_schedule.o' failed Makefile:4407: recipe for target 'all-recursive' failed Makefile:530: recipe for target 'all-recursive' failed Makefile:462: recipe for target 'all' failed

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

#2 lore raw

Re: ✗ Fi.CI.BAT: failure for igt/gem_ringfill: Adds ringbuffer full preemption test

Quoting Patchwork (2017-08-24 01:29:29)

Quoted 5 lines

== Series Details ==

Series: igt/gem_ringfill: Adds ringbuffer full preemption test
URL : https://patchwork.freedesktop.org/series/29252/
State : failure

What I had in mind was

From f009cc1a2c6564d4a1683dccaf9e9a7d192c1f61 Mon Sep 17 00:00:00 2001
From: Chris Wilson <[email protected]>
Date: Thu, 24 Aug 2017 12:16:17 +0100
Subject: [PATCH igt] pi-ringfull

---
 tests/gem_exec_schedule.c | 194 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 193 insertions(+), 1 deletion(-)
tests/gem_exec_schedule.c +193 -1
index c48f8850..928b7047 100644
@@ -21,12 +21,16 @@
  * IN THE SOFTWARE.
  */
 
+#include "config.h"
+
 #include <sys/poll.h>
 #include <sys/ioctl.h>
+#include <sched.h>
 
 #include "igt.h"
 #include "igt_vgem.h"
 #include "igt_rand.h"
+#include "igt_sysfs.h"
 
 #define LOCAL_PARAM_HAS_SCHEDULER 41
 #define LOCAL_CONTEXT_PARAM_PRIORITY 6
@@ -596,7 +600,10 @@ static void alarm_handler(int sig)
 
 static int __execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
 {
-	return ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf);
+	int err = 0;
+	if (ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf))
+		err = -errno;
+	return err;
 }
 
 static unsigned int measure_ring_size(int fd, unsigned int ring)
@@ -811,6 +818,133 @@ static void reorder_wide(int fd, unsigned ring)
 	gem_close(fd, target);
 }
 
+static void bind_to_cpu(int cpu)
+{
+	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+	struct sched_param rt = {.sched_priority = 99 };
+	cpu_set_t allowed;
+
+	igt_assert(sched_setscheduler(getpid(), SCHED_RR | SCHED_RESET_ON_FORK, &rt) == 0);
+
+	CPU_ZERO(&allowed);
+	CPU_SET(cpu % ncpus, &allowed);
+	igt_assert(sched_setaffinity(getpid(), sizeof(cpu_set_t), &allowed) == 0);
+}
+
+static void test_pi_ringfull(int fd, unsigned int engine)
+{
+	const uint32_t bbe = MI_BATCH_BUFFER_END;
+	struct sigaction sa = { .sa_handler = alarm_handler };
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 obj[2];
+	unsigned int last, count;
+	struct itimerval itv;
+	struct cork c;
+	bool *result;
+
+	result = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
+	igt_assert(result != MAP_FAILED);
+
+	memset(&execbuf, 0, sizeof(execbuf));
+	memset(&obj, 0, sizeof(obj));
+
+	obj[1].handle = gem_create(fd, 4096);
+	gem_write(fd, obj[1].handle, 0, &bbe, sizeof(bbe));
+
+	execbuf.buffers_ptr = to_user_pointer(&obj[1]);
+	execbuf.buffer_count = 1;
+	execbuf.flags = engine;
+	execbuf.rsvd1 = gem_context_create(fd);
+	ctx_set_priority(fd, execbuf.rsvd1, -MAX_PRIO);
+
+	gem_execbuf(fd, &execbuf);
+	gem_sync(fd, obj[1].handle);
+
+	/* Fill the low-priority ring */
+	plug(fd, &c);
+	obj[0].handle = c.handle;
+
+	execbuf.buffers_ptr = to_user_pointer(obj);
+	execbuf.buffer_count = 2;
+
+	sigaction(SIGALRM, &sa, NULL);
+	itv.it_interval.tv_sec = 0;
+	itv.it_interval.tv_usec = 100;
+	itv.it_value.tv_sec = 0;
+	itv.it_value.tv_usec = 1000;
+	setitimer(ITIMER_REAL, &itv, NULL);
+
+	last = -1;
+	count = 0;
+	do {
+		if (__execbuf(fd, &execbuf) == 0) {
+			count++;
+			continue;
+		}
+
+		if (last == count)
+			break;
+
+		last = count;
+	} while (1);
+	igt_debug("Filled low-priority ring with %d batches\n", count);
+
+	memset(&itv, 0, sizeof(itv));
+	setitimer(ITIMER_REAL, &itv, NULL);
+
+	execbuf.buffers_ptr = to_user_pointer(&obj[1]);
+	execbuf.buffer_count = 1;
+
+	/* both parent + child on the same cpu, only parent is RT */
+	bind_to_cpu(0);
+
+	igt_fork(child, 1) {
+		result[0] = true;
+
+		igt_debug("Creating HP context\n");
+		execbuf.rsvd1 = gem_context_create(fd);
+		ctx_set_priority(fd, execbuf.rsvd1, MAX_PRIO);
+
+		kill(getppid(), SIGALRM);
+		sched_yield();
+		result[1] = true;
+
+		itv.it_value.tv_sec = 0;
+		itv.it_value.tv_usec = 10000;
+		setitimer(ITIMER_REAL, &itv, NULL);
+
+		/* Since we are the high priority task, we expect to be
+		 * able to add ourselves to *our* ring without interruption.
+		 */
+		igt_debug("HP child executing\n");
+		result[2] = __execbuf(fd, &execbuf) == 0;
+		gem_context_destroy(fd, execbuf.rsvd1);
+	}
+
+	/* Relinquish CPU just to allow child to create a context */
+	sleep(1);
+	igt_assert_f(result[0], "HP context (child) not created");
+	igt_assert_f(!result[1], "Child released too early!\n");
+
+	/* Parent sleeps waiting for ringspace, releasing child */
+	itv.it_value.tv_sec = 0;
+	itv.it_value.tv_usec = 50000;
+	setitimer(ITIMER_REAL, &itv, NULL);
+	igt_debug("LP parent executing\n");
+	igt_assert_eq(__execbuf(fd, &execbuf), -EINTR);
+	igt_assert_f(result[1], "Child was not released!\n");
+	igt_assert_f(result[2],
+		     "High priority child unable to submit within 10ms\n");
+
+	unplug(&c);
+	igt_waitchildren();
+
+	gem_context_destroy(fd, execbuf.rsvd1);
+	gem_close(fd, obj[1].handle);
+	gem_close(fd, obj[0].handle);
+	munmap(result, 4096);
+}
+
 static bool has_scheduler(int fd)
 {
 	drm_i915_getparam_t gp;
@@ -823,15 +957,52 @@ static bool has_scheduler(int fd)
 	return has > 0;
 }
 
+#define HAVE_EXECLISTS 0x1
+#define HAVE_GUC 0x2
+static unsigned print_welcome(int fd)
+{
+	unsigned flags = 0;
+	bool active;
+	int dir;
+
+	dir = igt_sysfs_open_parameters(fd);
+	if (dir < 0)
+		return 0;
+
+	active = igt_sysfs_get_boolean(dir, "enable_guc_submission");
+	if (active) {
+		igt_info("Using GuC submission\n");
+		flags |= HAVE_GUC | HAVE_EXECLISTS;
+		goto out;
+	}
+
+	active = igt_sysfs_get_boolean(dir, "enable_execlists");
+	if (active) {
+		igt_info("Using Execlists submission\n");
+		flags |= HAVE_EXECLISTS;
+		goto out;
+	}
+
+	active = igt_sysfs_get_boolean(dir, "semaphores");
+	igt_info("Using Legacy submission%s\n",
+		 active ? ", with semaphores" : "");
+
+out:
+	close(dir);
+	return flags;
+}
+
 igt_main
 {
 	const struct intel_execution_engine *e;
+	unsigned int caps = 0;
 	int fd = -1;
 
 	igt_skip_on_simulation();
 
 	igt_fixture {
 		fd = drm_open_driver_master(DRIVER_INTEL);
+		caps = print_welcome(fd);
 		igt_require_gem(fd);
 		gem_require_mmap_wc(fd);
 		igt_fork_hang_detector(fd);
@@ -901,6 +1072,27 @@ igt_main
 		}
 	}
 
+	igt_subtest_group {
+		igt_fixture {
+			igt_require(has_scheduler(fd));
+			ctx_has_priority(fd);
+
+		       	/* need separate rings */
+			igt_require(caps & HAVE_EXECLISTS);
+		}
+
+		for (e = intel_execution_engines; e->name; e++) {
+			igt_subtest_group {
+				igt_fixture {
+					gem_require_ring(fd, e->exec_id | e->flags);
+				}
+
+				igt_subtest_f("pi-ringfull-%s", e->name)
+					test_pi_ringfull(fd, e->exec_id | e->flags);
+			}
+		}
+	}
+
 	igt_fixture {
 		igt_stop_hang_detector();
 		close(fd);

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

#3 lore raw
In reply to Antonio Argenziano
Quoted 3 lines · Antonio Argenziano

The testcase added here, stimulates this scenario where a high priority request is sent while another process keeps submitting requests and filling its ringbuffer.

s/stimulates/simulates

You're no longer changing igt/gem_ringfill, please adjust the subject accordingly.
It would be nice to describe that this test will always fail for now, because of the struct_mutex contention.

Quoted 33 lines

From RFC (Chris):
- Use two FDs, one for each priority submission.
- Move from gem_ringfill to gem_exec_schedule.
- Bound processes to same cpu and wake with signals.

Cc Chris Wilson <[email protected]>
---
 tests/gem_exec_schedule.c | 113 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 112 insertions(+), 1 deletion(-)
tests/gem_exec_schedule.c +5 -0
index f2847863..476626e6 100644
@@ -21,7 +21,12 @@
  * IN THE SOFTWARE.
  */
 
+#define _GNU_SOURCE
+#include <sched.h>
+#include <signal.h>
+
 #include <sys/poll.h>
+#include <sys/ioctl.h>
 
 #include "igt.h"
 #include "igt_vgem.h"
@@ -39,6 +44,15 @@
 
 IGT_TEST_DESCRIPTION("Check that we can control the order of execution");

tests/gem_exec_schedule.c line 55

Quoted 10 lines
tests/gem_exec_schedule.c +9 -0
 
+static void alarm_handler(int sig)
+{
+}
+
+static int __execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
+{
+	return ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf);
+}
+

So... __gem_execbuf?

Quoted 5 lines
tests/gem_exec_schedule.c +0 -0
 static int __ctx_set_priority(int fd, uint32_t ctx, int prio)
 {
 	struct local_i915_gem_context_param param;
@@ -659,6 +673,95 @@ static bool has_scheduler(int fd)
 	return has > 0;

tests/gem_exec_schedule.c static bool has_scheduler(int fd) · line 683

Quoted 10 lines
tests/gem_exec_schedule.c +8 -0
 }
 
+static void bind_to_cpu(int cpu)
+{
+	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+	cpu_set_t allowed;
+
+	CPU_ZERO(&allowed);
+	CPU_SET(cpu % ncpus, &allowed);
+	igt_assert(sched_setaffinity(getpid(), sizeof(cpu_set_t), &allowed) == 0);

We need to make sure that the child is not running before parent blocks in the last execbuf - meaning that we probably want to make the parent (but not the child) realtime. (see email from Chris)

tests/gem_exec_schedule.c static bool has_scheduler(int fd) · line 693

Quoted 10 lines
tests/gem_exec_schedule.c +10 -0
+}
+
+static void setup_timer(int timeout)
+{
+	struct itimerval itv;
+	struct sigaction sa = { .sa_handler = alarm_handler };
+
+	sigaction(SIGALRM, &sa, NULL);
+	itv.it_interval.tv_sec = 0;
+	itv.it_interval.tv_usec = 100;

Using this interval doesn't allow fork to complete on my machine. But we should probably disable the timer across fork anyway.

Quoted 12 lines
tests/gem_exec_schedule.c +12 -0
+	itv.it_value.tv_sec = 0;
+	itv.it_value.tv_usec = timeout * 1000;
+	setitimer(ITIMER_REAL, &itv, NULL);
+}
+
+/*
+ * This test checks that is possible for a high priority request to trigger a
+ * preemption if another context has filled its ringbuffer.
+ * The aim of the test is to make sure that high priority requests cannot be
+ * stalled by low priority tasks.
+ * */
+static void preempt_while_ringbuffer_full(int fd, uint32_t engine)

tests/gem_exec_schedule.c static bool has_scheduler(int fd) · line 715

Quoted 10 lines
tests/gem_exec_schedule.c +10 -0
+{
+	uint32_t hp_fd;
+	uint32_t hp_ctx, lp_ctx;
+	struct drm_i915_gem_exec_object2 obj, hp_obj;
+	struct drm_i915_gem_execbuffer2 execbuf;
+
+	const unsigned timeout = 10; /*ms*/
+	const uint32_t bbe = MI_BATCH_BUFFER_END;
+
+	hp_fd = drm_open_driver(DRIVER_INTEL);

Why the extra FD if we're going to use non-default contexts anyway?

Quoted 13 lines
tests/gem_exec_schedule.c +13 -0
+
+	memset(&execbuf, 0, sizeof(execbuf));
+	memset(&obj, 0, sizeof(obj));
+	memset(&hp_obj, 0, sizeof(hp_obj));
+
+	lp_ctx = gem_context_create(fd);
+	ctx_set_priority(fd, lp_ctx, -MAX_PRIO);
+
+	hp_ctx = gem_context_create(hp_fd);
+	ctx_set_priority(hp_fd, hp_ctx, MAX_PRIO);
+
+	hp_obj.handle =  gem_create(fd, 4096);
+	gem_write(fd, hp_obj.handle, 0, &bbe, sizeof(bbe));

tests/gem_exec_schedule.c static bool has_scheduler(int fd) · line 738

Quoted 10 lines
tests/gem_exec_schedule.c +10 -0
+
+	obj.handle =  gem_create(fd, 4096);
+	gem_write(fd, obj.handle, 0, &bbe, sizeof(bbe));
+
+	execbuf.buffers_ptr = to_user_pointer(&obj);
+	execbuf.flags = engine;
+	execbuf.buffer_count = 1;
+	execbuf.rsvd1 = lp_ctx;
+
+	/*Stall execution and fill ring*/

Malformed comment.

tests/gem_exec_schedule.c static bool has_scheduler(int fd) · line 745

Quoted 7 lines
tests/gem_exec_schedule.c +7 -0
+	igt_spin_batch_new(fd, lp_ctx, engine, 0);
+
+	setup_timer(timeout);
+	while (__execbuf(fd, &execbuf) == 0)
+		;
+
+	/* steal cpu */

Description of what exactly are we doing here and what we're expecting to happen would save reader a couple of a-ha! moments.

Quoted 23 lines
tests/gem_exec_schedule.c +19 -0
+	bind_to_cpu(0);
+	igt_fork(child, 1) {
+		/* this child is forced to wait for parent to sleep */
+		execbuf.buffers_ptr = to_user_pointer(&hp_obj);
+		execbuf.rsvd1 = hp_ctx;
+		setup_timer(timeout);
+		if (__execbuf(fd, &execbuf)) {
+			igt_assert_f(0, "Failed High priority submission.\n");
+			igt_terminate_spin_batches();
+		}
+	}
+
+	/* process sleeps waiting for space to free, releasing child */
+	setup_timer(2*timeout);
+	__execbuf(fd, &execbuf);
+	igt_terminate_spin_batches();
+	igt_waitchildren();
+}
+
 igt_main
 {
 	const struct intel_execution_engine *e;

tests/gem_exec_schedule.c igt_main · line 775

Quoted 5 lines
tests/gem_exec_schedule.c +1 -1
@@ -669,7 +772,7 @@ igt_main
 	igt_fixture {
 		fd = drm_open_driver_master(DRIVER_INTEL);
 		igt_require_gem(fd);
-		gem_require_mmap_wc(fd);
+		//gem_require_mmap_wc(fd);

????

tests/gem_exec_schedule.c igt_main · line 839

Quoted 10 lines
tests/gem_exec_schedule.c +3 -0
 		igt_fork_hang_detector(fd);
 	}
 
@@ -731,6 +834,14 @@ igt_main
 		}
 	}
 
+	igt_subtest_group {
+			for (e = intel_execution_engines; e->name; e++) {
+				igt_subtest_f("preempt-while-full-%s", e->name) {

gem_require_ring()
We also need to make sure that we're skipping on legacy_ringbuffer (!enable_execlists). Today that's taken care of by has_scheduler, but that may not be true in the future.

-Michał

Quoted 15 lines
tests/gem_exec_schedule.c +5 -0
+					preempt_while_ringbuffer_full(fd, e->exec_id | e->flags);
+				}
+			}
+	}
+
 	igt_fixture {
 		igt_stop_hang_detector();
 		close(fd);
Signature · 6 lines
2.14.1

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

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

#4 lore raw

Quoting Michał Winiarski (2017-08-24 13:13:30)

Quoted 11 lines

tests/gem_exec_schedule.c line 55

Quoted 9 lines
tests/gem_exec_schedule.c +9 -0
+static void alarm_handler(int sig)
+{
+}
+
+static int __execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
+{
+     return ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf);
+}
+

So... __gem_execbuf?

__gem_execbuf() eats EINTR, which we need to break out of the loop.

Quoted 21 lines
Quoted 6 lines

static int __ctx_set_priority(int fd, uint32_t ctx, int prio)

 {
      struct local_i915_gem_context_param param;
tests/gem_exec_schedule.c +0 -0
@@ -659,6 +673,95 @@ static bool has_scheduler(int fd)
      return has > 0;

tests/gem_exec_schedule.c static bool has_scheduler(int fd) · line 683

Quoted 10 lines
tests/gem_exec_schedule.c +8 -0
 }
 
+static void bind_to_cpu(int cpu)
+{
+     const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+     cpu_set_t allowed;
+
+     CPU_ZERO(&allowed);
+     CPU_SET(cpu % ncpus, &allowed);
+     igt_assert(sched_setaffinity(getpid(), sizeof(cpu_set_t), &allowed) == 0);

We need to make sure that the child is not running before parent blocks in the last execbuf - meaning that we probably want to make the parent (but not the child) realtime. (see email from Chris)

Quoted 12 lines

tests/gem_exec_schedule.c static bool has_scheduler(int fd) · line 693

Quoted 10 lines
tests/gem_exec_schedule.c +10 -0
+}
+
+static void setup_timer(int timeout)
+{
+     struct itimerval itv;
+     struct sigaction sa = { .sa_handler = alarm_handler };
+
+     sigaction(SIGALRM, &sa, NULL);
+     itv.it_interval.tv_sec = 0;
+     itv.it_interval.tv_usec = 100;

Using this interval doesn't allow fork to complete on my machine.

(Because it gets caught in EINTR hell, I presume.)

Quoted 18 lines

But we should probably disable the timer across fork anyway.

Quoted 16 lines
tests/gem_exec_schedule.c +16 -0
+     itv.it_value.tv_sec = 0;
+     itv.it_value.tv_usec = timeout * 1000;
+     setitimer(ITIMER_REAL, &itv, NULL);
+}
+
+/*
+ * This test checks that is possible for a high priority request to trigger a
+ * preemption if another context has filled its ringbuffer.
+ * The aim of the test is to make sure that high priority requests cannot be
+ * stalled by low priority tasks.
+ * */
+static void preempt_while_ringbuffer_full(int fd, uint32_t engine)
+{
+     uint32_t hp_fd;
+     uint32_t hp_ctx, lp_ctx;
+     struct drm_i915_gem_exec_object2 obj, hp_obj;
Quoted 8 lines

tests/gem_exec_schedule.c static bool has_scheduler(int fd) · line 715

Quoted 6 lines
tests/gem_exec_schedule.c +6 -0
+     struct drm_i915_gem_execbuffer2 execbuf;
+
+     const unsigned timeout = 10; /*ms*/
+     const uint32_t bbe = MI_BATCH_BUFFER_END;
+
+     hp_fd = drm_open_driver(DRIVER_INTEL);

Why the extra FD if we're going to use non-default contexts anyway?

I actually suggested the extra isolation. It depends on tracking down all permutations and possible mutex interactions. For starters, we don't need the extra fd as we can demonstrate the inversion just with two contexts. But we need to design a framework to find all of these before the client/user does.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx