[i-g-t,2/2] gem_wsim: Mark contexts as non-persistent
diff mbox series

Message ID 20200306143850.673-2-tvrtko.ursulin@linux.intel.com
State New
Headers show
Series
  • [i-g-t,1/2] gem_wsim: Fix calibration for special VCS engine name
Related show

Commit Message

Tvrtko Ursulin March 6, 2020, 2:38 p.m. UTC
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

We want to mark workload contexts as non-persistent if possible so that we
do not have to worry about leaving long (or infinite!) batches running
post exit.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 benchmarks/gem_wsim.c | 50 ++++++++++++++++++++++++++++++++++++-------
 1 file changed, 42 insertions(+), 8 deletions(-)

Patch
diff mbox series

diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c
index c196b25317ce..7cb8ea5b18ba 100644
--- a/benchmarks/gem_wsim.c
+++ b/benchmarks/gem_wsim.c
@@ -1431,16 +1431,48 @@  alloc_step_batch(struct workload *wrk, struct w_step *w, unsigned int flags)
 #endif
 }
 
-static void __ctx_set_prio(uint32_t ctx_id, unsigned int prio)
+static bool has_persistence(int i915)
 {
-	struct drm_i915_gem_context_param param = {
-		.ctx_id = ctx_id,
-		.param = I915_CONTEXT_PARAM_PRIORITY,
-		.value = prio,
+	struct drm_i915_gem_context_param p = {
+		.param = I915_CONTEXT_PARAM_PERSISTENCE,
 	};
+	uint64_t saved;
+
+	if (__gem_context_get_param(i915, &p))
+		return false;
+
+	saved = p.value;
+	p.value = 0;
+	if (__gem_context_set_param(i915, &p))
+		return false;
+
+	p.value = saved;
+	return __gem_context_set_param(i915, &p) == 0;
+}
+
+static bool __has_persistence;
+
+static void __configure_context(uint32_t ctx_id, unsigned int prio)
+{
+	if (prio) {
+		struct drm_i915_gem_context_param param = {
+			.ctx_id = ctx_id,
+			.param = I915_CONTEXT_PARAM_PRIORITY,
+			.value = prio,
+		};
 
-	if (prio)
 		gem_context_set_param(fd, &param);
+	}
+
+	/* Mark as non-persistent if supported. */
+	if (__has_persistence) {
+		struct drm_i915_gem_context_param param = {
+			.ctx_id = ctx_id,
+			.param = I915_CONTEXT_PARAM_PERSISTENCE,
+		};
+
+		gem_context_set_param(fd, &param);
+	}
 }
 
 static int __vm_destroy(int i915, uint32_t vm_id)
@@ -1743,7 +1775,7 @@  prepare_workload(unsigned int id, struct workload *wrk, unsigned int flags)
 			ctx_vcs ^= 1;
 		}
 
-		__ctx_set_prio(ctx_id, wrk->prio);
+		__configure_context(ctx_id, wrk->prio);
 
 		/*
 		 * Do we need a separate context to satisfy this workloads which
@@ -1772,7 +1804,7 @@  prepare_workload(unsigned int id, struct workload *wrk, unsigned int flags)
 			ctx_id = args.ctx_id;
 			wrk->ctx_list[i + 1].id = args.ctx_id;
 
-			__ctx_set_prio(ctx_id, wrk->prio);
+			__configure_context(ctx_id, wrk->prio);
 		}
 
 		if (ctx->engine_map) {
@@ -3280,6 +3312,8 @@  int main(int argc, char **argv)
 	fd = __drm_open_driver(DRIVER_INTEL);
 	igt_require(fd);
 
+	__has_persistence = has_persistence(fd);
+
 	intel_register_access_init(&mmio_data, intel_get_pci_device(), false, fd);
 
 	init_clocks();