Commit d1cee2d3 authored by Matthew Brost's avatar Matthew Brost Committed by John Harrison

drm/i915: Move active request tracking to a vfunc

Move active request tracking to a backend vfunc rather than assuming all
backends want to do this in the manner. In the of case execlists /
ring submission the tracking is on the physical engine while with GuC
submission it is on the context.
Signed-off-by: default avatarMatthew Brost <matthew.brost@intel.com>
Reviewed-by: default avatarJohn Harrison <John.C.Harrison@Intel.com>
Signed-off-by: default avatarJohn Harrison <John.C.Harrison@Intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210727002348.97202-8-matthew.brost@intel.com
parent 27466222
...@@ -393,6 +393,9 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine) ...@@ -393,6 +393,9 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
spin_lock_init(&ce->guc_state.lock); spin_lock_init(&ce->guc_state.lock);
INIT_LIST_HEAD(&ce->guc_state.fences); INIT_LIST_HEAD(&ce->guc_state.fences);
spin_lock_init(&ce->guc_active.lock);
INIT_LIST_HEAD(&ce->guc_active.requests);
ce->guc_id = GUC_INVALID_LRC_ID; ce->guc_id = GUC_INVALID_LRC_ID;
INIT_LIST_HEAD(&ce->guc_id_link); INIT_LIST_HEAD(&ce->guc_id_link);
......
...@@ -162,6 +162,13 @@ struct intel_context { ...@@ -162,6 +162,13 @@ struct intel_context {
struct list_head fences; struct list_head fences;
} guc_state; } guc_state;
struct {
/** lock: protects everything in guc_active */
spinlock_t lock;
/** requests: active requests on this context */
struct list_head requests;
} guc_active;
/* GuC scheduling state flags that do not require a lock. */ /* GuC scheduling state flags that do not require a lock. */
atomic_t guc_sched_state_no_lock; atomic_t guc_sched_state_no_lock;
......
...@@ -414,6 +414,12 @@ struct intel_engine_cs { ...@@ -414,6 +414,12 @@ struct intel_engine_cs {
void (*release)(struct intel_engine_cs *engine); void (*release)(struct intel_engine_cs *engine);
/*
* Add / remove request from engine active tracking
*/
void (*add_active_request)(struct i915_request *rq);
void (*remove_active_request)(struct i915_request *rq);
struct intel_engine_execlists execlists; struct intel_engine_execlists execlists;
/* /*
......
...@@ -3157,6 +3157,42 @@ static void execlists_park(struct intel_engine_cs *engine) ...@@ -3157,6 +3157,42 @@ static void execlists_park(struct intel_engine_cs *engine)
cancel_timer(&engine->execlists.preempt); cancel_timer(&engine->execlists.preempt);
} }
static void add_to_engine(struct i915_request *rq)
{
lockdep_assert_held(&rq->engine->sched_engine->lock);
list_move_tail(&rq->sched.link, &rq->engine->sched_engine->requests);
}
static void remove_from_engine(struct i915_request *rq)
{
struct intel_engine_cs *engine, *locked;
/*
* Virtual engines complicate acquiring the engine timeline lock,
* as their rq->engine pointer is not stable until under that
* engine lock. The simple ploy we use is to take the lock then
* check that the rq still belongs to the newly locked engine.
*/
locked = READ_ONCE(rq->engine);
spin_lock_irq(&locked->sched_engine->lock);
while (unlikely(locked != (engine = READ_ONCE(rq->engine)))) {
spin_unlock(&locked->sched_engine->lock);
spin_lock(&engine->sched_engine->lock);
locked = engine;
}
list_del_init(&rq->sched.link);
clear_bit(I915_FENCE_FLAG_PQUEUE, &rq->fence.flags);
clear_bit(I915_FENCE_FLAG_HOLD, &rq->fence.flags);
/* Prevent further __await_execution() registering a cb, then flush */
set_bit(I915_FENCE_FLAG_ACTIVE, &rq->fence.flags);
spin_unlock_irq(&locked->sched_engine->lock);
i915_request_notify_execute_cb_imm(rq);
}
static bool can_preempt(struct intel_engine_cs *engine) static bool can_preempt(struct intel_engine_cs *engine)
{ {
if (GRAPHICS_VER(engine->i915) > 8) if (GRAPHICS_VER(engine->i915) > 8)
...@@ -3251,6 +3287,8 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine) ...@@ -3251,6 +3287,8 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine)
engine->cops = &execlists_context_ops; engine->cops = &execlists_context_ops;
engine->request_alloc = execlists_request_alloc; engine->request_alloc = execlists_request_alloc;
engine->add_active_request = add_to_engine;
engine->remove_active_request = remove_from_engine;
engine->reset.prepare = execlists_reset_prepare; engine->reset.prepare = execlists_reset_prepare;
engine->reset.rewind = execlists_reset_rewind; engine->reset.rewind = execlists_reset_rewind;
...@@ -3847,6 +3885,8 @@ execlists_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ...@@ -3847,6 +3885,8 @@ execlists_create_virtual(struct intel_engine_cs **siblings, unsigned int count)
"v%dx%d", ve->base.class, count); "v%dx%d", ve->base.class, count);
ve->base.context_size = sibling->context_size; ve->base.context_size = sibling->context_size;
ve->base.add_active_request = sibling->add_active_request;
ve->base.remove_active_request = sibling->remove_active_request;
ve->base.emit_bb_start = sibling->emit_bb_start; ve->base.emit_bb_start = sibling->emit_bb_start;
ve->base.emit_flush = sibling->emit_flush; ve->base.emit_flush = sibling->emit_flush;
ve->base.emit_init_breadcrumb = sibling->emit_init_breadcrumb; ve->base.emit_init_breadcrumb = sibling->emit_init_breadcrumb;
......
...@@ -1047,6 +1047,25 @@ static void setup_irq(struct intel_engine_cs *engine) ...@@ -1047,6 +1047,25 @@ static void setup_irq(struct intel_engine_cs *engine)
} }
} }
static void add_to_engine(struct i915_request *rq)
{
lockdep_assert_held(&rq->engine->sched_engine->lock);
list_move_tail(&rq->sched.link, &rq->engine->sched_engine->requests);
}
static void remove_from_engine(struct i915_request *rq)
{
spin_lock_irq(&rq->engine->sched_engine->lock);
list_del_init(&rq->sched.link);
/* Prevent further __await_execution() registering a cb, then flush */
set_bit(I915_FENCE_FLAG_ACTIVE, &rq->fence.flags);
spin_unlock_irq(&rq->engine->sched_engine->lock);
i915_request_notify_execute_cb_imm(rq);
}
static void setup_common(struct intel_engine_cs *engine) static void setup_common(struct intel_engine_cs *engine)
{ {
struct drm_i915_private *i915 = engine->i915; struct drm_i915_private *i915 = engine->i915;
...@@ -1064,6 +1083,9 @@ static void setup_common(struct intel_engine_cs *engine) ...@@ -1064,6 +1083,9 @@ static void setup_common(struct intel_engine_cs *engine)
engine->reset.cancel = reset_cancel; engine->reset.cancel = reset_cancel;
engine->reset.finish = reset_finish; engine->reset.finish = reset_finish;
engine->add_active_request = add_to_engine;
engine->remove_active_request = remove_from_engine;
engine->cops = &ring_context_ops; engine->cops = &ring_context_ops;
engine->request_alloc = ring_request_alloc; engine->request_alloc = ring_request_alloc;
......
...@@ -235,6 +235,34 @@ static void mock_submit_request(struct i915_request *request) ...@@ -235,6 +235,34 @@ static void mock_submit_request(struct i915_request *request)
spin_unlock_irqrestore(&engine->hw_lock, flags); spin_unlock_irqrestore(&engine->hw_lock, flags);
} }
static void mock_add_to_engine(struct i915_request *rq)
{
lockdep_assert_held(&rq->engine->sched_engine->lock);
list_move_tail(&rq->sched.link, &rq->engine->sched_engine->requests);
}
static void mock_remove_from_engine(struct i915_request *rq)
{
struct intel_engine_cs *engine, *locked;
/*
* Virtual engines complicate acquiring the engine timeline lock,
* as their rq->engine pointer is not stable until under that
* engine lock. The simple ploy we use is to take the lock then
* check that the rq still belongs to the newly locked engine.
*/
locked = READ_ONCE(rq->engine);
spin_lock_irq(&locked->sched_engine->lock);
while (unlikely(locked != (engine = READ_ONCE(rq->engine)))) {
spin_unlock(&locked->sched_engine->lock);
spin_lock(&engine->sched_engine->lock);
locked = engine;
}
list_del_init(&rq->sched.link);
spin_unlock_irq(&locked->sched_engine->lock);
}
static void mock_reset_prepare(struct intel_engine_cs *engine) static void mock_reset_prepare(struct intel_engine_cs *engine)
{ {
} }
...@@ -321,6 +349,8 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, ...@@ -321,6 +349,8 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915,
engine->base.emit_flush = mock_emit_flush; engine->base.emit_flush = mock_emit_flush;
engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb; engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb;
engine->base.submit_request = mock_submit_request; engine->base.submit_request = mock_submit_request;
engine->base.add_active_request = mock_add_to_engine;
engine->base.remove_active_request = mock_remove_from_engine;
engine->base.reset.prepare = mock_reset_prepare; engine->base.reset.prepare = mock_reset_prepare;
engine->base.reset.rewind = mock_reset_rewind; engine->base.reset.rewind = mock_reset_rewind;
......
...@@ -1159,6 +1159,33 @@ static int guc_context_alloc(struct intel_context *ce) ...@@ -1159,6 +1159,33 @@ static int guc_context_alloc(struct intel_context *ce)
return lrc_alloc(ce, ce->engine); return lrc_alloc(ce, ce->engine);
} }
static void add_to_context(struct i915_request *rq)
{
struct intel_context *ce = rq->context;
spin_lock(&ce->guc_active.lock);
list_move_tail(&rq->sched.link, &ce->guc_active.requests);
spin_unlock(&ce->guc_active.lock);
}
static void remove_from_context(struct i915_request *rq)
{
struct intel_context *ce = rq->context;
spin_lock_irq(&ce->guc_active.lock);
list_del_init(&rq->sched.link);
clear_bit(I915_FENCE_FLAG_PQUEUE, &rq->fence.flags);
/* Prevent further __await_execution() registering a cb, then flush */
set_bit(I915_FENCE_FLAG_ACTIVE, &rq->fence.flags);
spin_unlock_irq(&ce->guc_active.lock);
atomic_dec(&ce->guc_id_ref);
i915_request_notify_execute_cb_imm(rq);
}
static const struct intel_context_ops guc_context_ops = { static const struct intel_context_ops guc_context_ops = {
.alloc = guc_context_alloc, .alloc = guc_context_alloc,
...@@ -1568,6 +1595,8 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) ...@@ -1568,6 +1595,8 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine)
engine->cops = &guc_context_ops; engine->cops = &guc_context_ops;
engine->request_alloc = guc_request_alloc; engine->request_alloc = guc_request_alloc;
engine->add_active_request = add_to_context;
engine->remove_active_request = remove_from_context;
engine->sched_engine->schedule = i915_schedule; engine->sched_engine->schedule = i915_schedule;
...@@ -1932,6 +1961,10 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ...@@ -1932,6 +1961,10 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count)
"v%dx%d", ve->base.class, count); "v%dx%d", ve->base.class, count);
ve->base.context_size = sibling->context_size; ve->base.context_size = sibling->context_size;
ve->base.add_active_request =
sibling->add_active_request;
ve->base.remove_active_request =
sibling->remove_active_request;
ve->base.emit_bb_start = sibling->emit_bb_start; ve->base.emit_bb_start = sibling->emit_bb_start;
ve->base.emit_flush = sibling->emit_flush; ve->base.emit_flush = sibling->emit_flush;
ve->base.emit_init_breadcrumb = ve->base.emit_init_breadcrumb =
......
...@@ -182,7 +182,7 @@ static bool irq_work_imm(struct irq_work *wrk) ...@@ -182,7 +182,7 @@ static bool irq_work_imm(struct irq_work *wrk)
return false; return false;
} }
static void __notify_execute_cb_imm(struct i915_request *rq) void i915_request_notify_execute_cb_imm(struct i915_request *rq)
{ {
__notify_execute_cb(rq, irq_work_imm); __notify_execute_cb(rq, irq_work_imm);
} }
...@@ -256,37 +256,6 @@ i915_request_active_engine(struct i915_request *rq, ...@@ -256,37 +256,6 @@ i915_request_active_engine(struct i915_request *rq,
return ret; return ret;
} }
static void remove_from_engine(struct i915_request *rq)
{
struct intel_engine_cs *engine, *locked;
/*
* Virtual engines complicate acquiring the engine timeline lock,
* as their rq->engine pointer is not stable until under that
* engine lock. The simple ploy we use is to take the lock then
* check that the rq still belongs to the newly locked engine.
*/
locked = READ_ONCE(rq->engine);
spin_lock_irq(&locked->sched_engine->lock);
while (unlikely(locked != (engine = READ_ONCE(rq->engine)))) {
spin_unlock(&locked->sched_engine->lock);
spin_lock(&engine->sched_engine->lock);
locked = engine;
}
list_del_init(&rq->sched.link);
clear_bit(I915_FENCE_FLAG_PQUEUE, &rq->fence.flags);
clear_bit(I915_FENCE_FLAG_HOLD, &rq->fence.flags);
/* Prevent further __await_execution() registering a cb, then flush */
set_bit(I915_FENCE_FLAG_ACTIVE, &rq->fence.flags);
spin_unlock_irq(&locked->sched_engine->lock);
__notify_execute_cb_imm(rq);
}
static void __rq_init_watchdog(struct i915_request *rq) static void __rq_init_watchdog(struct i915_request *rq)
{ {
rq->watchdog.timer.function = NULL; rq->watchdog.timer.function = NULL;
...@@ -383,9 +352,7 @@ bool i915_request_retire(struct i915_request *rq) ...@@ -383,9 +352,7 @@ bool i915_request_retire(struct i915_request *rq)
* after removing the breadcrumb and signaling it, so that we do not * after removing the breadcrumb and signaling it, so that we do not
* inadvertently attach the breadcrumb to a completed request. * inadvertently attach the breadcrumb to a completed request.
*/ */
if (!list_empty(&rq->sched.link)) rq->engine->remove_active_request(rq);
remove_from_engine(rq);
atomic_dec(&rq->context->guc_id_ref);
GEM_BUG_ON(!llist_empty(&rq->execute_cb)); GEM_BUG_ON(!llist_empty(&rq->execute_cb));
__list_del_entry(&rq->link); /* poison neither prev/next (RCU walks) */ __list_del_entry(&rq->link); /* poison neither prev/next (RCU walks) */
...@@ -516,7 +483,7 @@ __await_execution(struct i915_request *rq, ...@@ -516,7 +483,7 @@ __await_execution(struct i915_request *rq,
if (llist_add(&cb->work.node.llist, &signal->execute_cb)) { if (llist_add(&cb->work.node.llist, &signal->execute_cb)) {
if (i915_request_is_active(signal) || if (i915_request_is_active(signal) ||
__request_in_flight(signal)) __request_in_flight(signal))
__notify_execute_cb_imm(signal); i915_request_notify_execute_cb_imm(signal);
} }
return 0; return 0;
...@@ -655,7 +622,7 @@ bool __i915_request_submit(struct i915_request *request) ...@@ -655,7 +622,7 @@ bool __i915_request_submit(struct i915_request *request)
result = true; result = true;
GEM_BUG_ON(test_bit(I915_FENCE_FLAG_ACTIVE, &request->fence.flags)); GEM_BUG_ON(test_bit(I915_FENCE_FLAG_ACTIVE, &request->fence.flags));
list_move_tail(&request->sched.link, &engine->sched_engine->requests); engine->add_active_request(request);
active: active:
clear_bit(I915_FENCE_FLAG_PQUEUE, &request->fence.flags); clear_bit(I915_FENCE_FLAG_PQUEUE, &request->fence.flags);
set_bit(I915_FENCE_FLAG_ACTIVE, &request->fence.flags); set_bit(I915_FENCE_FLAG_ACTIVE, &request->fence.flags);
......
...@@ -647,4 +647,6 @@ bool ...@@ -647,4 +647,6 @@ bool
i915_request_active_engine(struct i915_request *rq, i915_request_active_engine(struct i915_request *rq,
struct intel_engine_cs **active); struct intel_engine_cs **active);
void i915_request_notify_execute_cb_imm(struct i915_request *rq);
#endif /* I915_REQUEST_H */ #endif /* I915_REQUEST_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment