[Intel-gfx] [PATCH 16/18] drm/i915/preemption: Select timeout when scheduling

2018-04-09 Thread Chris Wilson
The choice of preemption timeout is determined by the context from which
we trigger the preemption, as such allow the caller to specify the
desired timeout.

Effectively the other choice would be to use the shortest timeout along
the dependency chain. However, given that we would have already
triggered preemption for the dependency chain, we can assume that no
preemption along that chain is more important than the current request,
ergo we need only consider the current timeout. Realising this, we can
then pass control of the preemption timeout to the caller for greater
flexibility.

Signed-off-by: Chris Wilson 
---
 drivers/gpu/drm/i915/i915_gem.c|   2 +-
 drivers/gpu/drm/i915/i915_request.c|   2 +-
 drivers/gpu/drm/i915/intel_lrc.c   |   5 +-
 drivers/gpu/drm/i915/intel_ringbuffer.h|   6 +-
 drivers/gpu/drm/i915/selftests/intel_lrc.c | 106 -
 5 files changed, 114 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index cec52bbd1b41..e8c1a077e223 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -576,7 +576,7 @@ static void __fence_set_priority(struct dma_fence *fence, 
int prio)
 
rcu_read_lock();
if (engine->schedule)
-   engine->schedule(rq, prio);
+   engine->schedule(rq, prio, 0);
rcu_read_unlock();
 }
 
diff --git a/drivers/gpu/drm/i915/i915_request.c 
b/drivers/gpu/drm/i915/i915_request.c
index 629f3e860592..ddb829ef 100644
--- a/drivers/gpu/drm/i915/i915_request.c
+++ b/drivers/gpu/drm/i915/i915_request.c
@@ -1062,7 +1062,7 @@ void __i915_request_add(struct i915_request *request, 
bool flush_caches)
 */
rcu_read_lock();
if (engine->schedule)
-   engine->schedule(request, request->ctx->priority);
+   engine->schedule(request, request->ctx->priority, 0);
rcu_read_unlock();
 
local_bh_disable();
diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
index 4f1e985b3cdb..877340afb63d 100644
--- a/drivers/gpu/drm/i915/intel_lrc.c
+++ b/drivers/gpu/drm/i915/intel_lrc.c
@@ -1260,7 +1260,8 @@ pt_lock_engine(struct i915_priotree *pt, struct 
intel_engine_cs *locked)
return engine;
 }
 
-static void execlists_schedule(struct i915_request *request, int prio)
+static void execlists_schedule(struct i915_request *request,
+  int prio, unsigned int timeout)
 {
struct intel_engine_cs *engine;
struct i915_dependency *dep, *p;
@@ -1356,7 +1357,7 @@ static void execlists_schedule(struct i915_request 
*request, int prio)
 
if (prio > engine->execlists.queue_priority &&
i915_sw_fence_done(&pt_to_request(pt)->submit))
-   __submit_queue(engine, prio, 0);
+   __submit_queue(engine, prio, timeout);
}
 
spin_unlock_irq(&engine->timeline->lock);
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h 
b/drivers/gpu/drm/i915/intel_ringbuffer.h
index 25147a877518..04d25d1d4c2f 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -463,13 +463,15 @@ struct intel_engine_cs {
 */
void(*submit_request)(struct i915_request *rq);
 
-   /* Call when the priority on a request has changed and it and its
+   /*
+* Call when the priority on a request has changed and it and its
 * dependencies may need rescheduling. Note the request itself may
 * not be ready to run!
 *
 * Called under the struct_mutex.
 */
-   void(*schedule)(struct i915_request *request, int priority);
+   void(*schedule)(struct i915_request *request,
+   int priority, unsigned int timeout);
 
/*
 * Cancel all requests on the hardware, or queued for execution.
diff --git a/drivers/gpu/drm/i915/selftests/intel_lrc.c 
b/drivers/gpu/drm/i915/selftests/intel_lrc.c
index 72d2770e5d71..5e4d6d07fff5 100644
--- a/drivers/gpu/drm/i915/selftests/intel_lrc.c
+++ b/drivers/gpu/drm/i915/selftests/intel_lrc.c
@@ -458,7 +458,7 @@ static int live_late_preempt(void *arg)
goto err_wedged;
}
 
-   engine->schedule(rq, I915_PRIORITY_MAX);
+   engine->schedule(rq, I915_PRIORITY_MAX, 0);
 
if (!wait_for_spinner(&spin_hi, rq)) {
pr_err("High priority context failed to preempt the low 
priority context\n");
@@ -677,6 +677,109 @@ static int live_preempt_reset(void *arg)
return err;
 }
 
+static int live_late_preempt_timeout(void *arg)
+{
+   struct drm_i915_private *i915 = arg;
+   struct i915_gem_context *ctx_hi, *ctx_lo;
+   struct spinner spin_hi, spin_lo;
+   struct intel_engine_cs *engine;
+   enum intel_engine_id id;
+   int 

[Intel-gfx] [PATCH 16/18] drm/i915/preemption: Select timeout when scheduling

2018-03-30 Thread Chris Wilson
The choice of preemption timeout is determined by the context from which
we trigger the preemption, as such allow the caller to specify the
desired timeout.

Effectively the other choice would be to use the shortest timeout along
the dependency chain. However, given that we would have already
triggered preemption for the dependency chain, we can assume that no
preemption along that chain is more important than the current request,
ergo we need only consider the current timeout. Realising this, we can
then pass control of the preemption timeout to the caller for greater
flexibility.

Signed-off-by: Chris Wilson 
---
 drivers/gpu/drm/i915/i915_gem.c|   2 +-
 drivers/gpu/drm/i915/i915_request.c|   2 +-
 drivers/gpu/drm/i915/intel_lrc.c   |   5 +-
 drivers/gpu/drm/i915/intel_ringbuffer.h|   6 +-
 drivers/gpu/drm/i915/selftests/intel_lrc.c | 106 -
 5 files changed, 114 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index a866fe304de1..a860d501134e 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -482,7 +482,7 @@ static void __fence_set_priority(struct dma_fence *fence, 
int prio)
 
rcu_read_lock();
if (engine->schedule)
-   engine->schedule(rq, prio);
+   engine->schedule(rq, prio, 0);
rcu_read_unlock();
 }
 
diff --git a/drivers/gpu/drm/i915/i915_request.c 
b/drivers/gpu/drm/i915/i915_request.c
index 585242831974..cdda3ebd51e2 100644
--- a/drivers/gpu/drm/i915/i915_request.c
+++ b/drivers/gpu/drm/i915/i915_request.c
@@ -1108,7 +1108,7 @@ void __i915_request_add(struct i915_request *request, 
bool flush_caches)
 */
rcu_read_lock();
if (engine->schedule)
-   engine->schedule(request, request->ctx->priority);
+   engine->schedule(request, request->ctx->priority, 0);
rcu_read_unlock();
 
local_bh_disable();
diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
index fea275f718f5..06a4815f5f31 100644
--- a/drivers/gpu/drm/i915/intel_lrc.c
+++ b/drivers/gpu/drm/i915/intel_lrc.c
@@ -1240,7 +1240,8 @@ pt_lock_engine(struct i915_priotree *pt, struct 
intel_engine_cs *locked)
return engine;
 }
 
-static void execlists_schedule(struct i915_request *request, int prio)
+static void execlists_schedule(struct i915_request *request,
+  int prio, unsigned int timeout)
 {
struct intel_engine_cs *engine;
struct i915_dependency *dep, *p;
@@ -1336,7 +1337,7 @@ static void execlists_schedule(struct i915_request 
*request, int prio)
 
if (prio > engine->execlists.queue_priority &&
i915_sw_fence_done(&pt_to_request(pt)->submit))
-   __submit_queue(engine, prio, 0);
+   __submit_queue(engine, prio, timeout);
}
 
spin_unlock_irq(&engine->timeline->lock);
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h 
b/drivers/gpu/drm/i915/intel_ringbuffer.h
index 80c303bb54c8..1e85123534a8 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -463,13 +463,15 @@ struct intel_engine_cs {
 */
void(*submit_request)(struct i915_request *rq);
 
-   /* Call when the priority on a request has changed and it and its
+   /*
+* Call when the priority on a request has changed and it and its
 * dependencies may need rescheduling. Note the request itself may
 * not be ready to run!
 *
 * Called under the struct_mutex.
 */
-   void(*schedule)(struct i915_request *request, int priority);
+   void(*schedule)(struct i915_request *request,
+   int priority, unsigned int timeout);
 
/*
 * Cancel all requests on the hardware, or queued for execution.
diff --git a/drivers/gpu/drm/i915/selftests/intel_lrc.c 
b/drivers/gpu/drm/i915/selftests/intel_lrc.c
index cd97a6461ec7..1970a4658c5c 100644
--- a/drivers/gpu/drm/i915/selftests/intel_lrc.c
+++ b/drivers/gpu/drm/i915/selftests/intel_lrc.c
@@ -457,7 +457,7 @@ static int live_late_preempt(void *arg)
goto err_wedged;
}
 
-   engine->schedule(rq, I915_PRIORITY_MAX);
+   engine->schedule(rq, I915_PRIORITY_MAX, 0);
 
if (!wait_for_spinner(&spin_hi, rq)) {
pr_err("High priority context failed to preempt the low 
priority context\n");
@@ -680,6 +680,109 @@ static int live_preempt_reset(void *arg)
return err;
 }
 
+static int live_late_preempt_timeout(void *arg)
+{
+   struct drm_i915_private *i915 = arg;
+   struct i915_gem_context *ctx_hi, *ctx_lo;
+   struct spinner spin_hi, spin_lo;
+   struct intel_engine_cs *engine;
+   enum intel_engine_id id;
+