drm/i915: Keep contexts pinned until after the next kernel context switch

We need to keep the context image pinned in memory until after the GPU
has finished writing into it. Since it continues to write as we signal
the final breadcrumb, we need to keep it pinned until the request after
it is complete. Currently we know the order in which requests execute on
each engine, and so to remove that presumption we need to identify a
request/context-switch we know must occur after our completion. Any
request queued after the signal must imply a context switch, for
simplicity we use a fresh request from the kernel context.

The sequence of operations for keeping the context pinned until saved is:

 - On context activation, we preallocate a node for each physical engine
   the context may operate on. This is to avoid allocations during
   unpinning, which may be from inside FS_RECLAIM context (aka the
   shrinker)

 - On context deactivation on retirement of the last active request (which
   is before we know the context has been saved), we add the
   preallocated node onto a barrier list on each engine

 - On engine idling, we emit a switch to kernel context. When this
   switch completes, we know that all previous contexts must have been
   saved, and so on retiring this request we can finally unpin all the
   contexts that were marked as deactivated prior to the switch.

We can enhance this in future by flushing all the idle contexts on a
regular heartbeat pulse of a switch to kernel context, which will also
be used to check for hung engines.

v2: intel_context_active_acquire/_release

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Reviewed-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190614164606.15633-1-chris@chris-wilson.co.uk
This commit is contained in:
Chris Wilson
2019-06-14 17:46:04 +01:00
parent 58a111f03a
commit ce476c80b8
20 changed files with 219 additions and 195 deletions

View File

@@ -157,6 +157,7 @@ void i915_active_init(struct drm_i915_private *i915,
ref->retire = retire;
ref->tree = RB_ROOT;
i915_active_request_init(&ref->last, NULL, last_retire);
init_llist_head(&ref->barriers);
ref->count = 0;
}
@@ -263,6 +264,83 @@ void i915_active_fini(struct i915_active *ref)
}
#endif
int i915_active_acquire_preallocate_barrier(struct i915_active *ref,
struct intel_engine_cs *engine)
{
struct drm_i915_private *i915 = engine->i915;
unsigned long tmp;
int err = 0;
GEM_BUG_ON(!engine->mask);
for_each_engine_masked(engine, i915, engine->mask, tmp) {
struct intel_context *kctx = engine->kernel_context;
struct active_node *node;
node = kmem_cache_alloc(global.slab_cache, GFP_KERNEL);
if (unlikely(!node)) {
err = -ENOMEM;
break;
}
i915_active_request_init(&node->base,
(void *)engine, node_retire);
node->timeline = kctx->ring->timeline->fence_context;
node->ref = ref;
ref->count++;
llist_add((struct llist_node *)&node->base.link,
&ref->barriers);
}
return err;
}
void i915_active_acquire_barrier(struct i915_active *ref)
{
struct llist_node *pos, *next;
i915_active_acquire(ref);
llist_for_each_safe(pos, next, llist_del_all(&ref->barriers)) {
struct intel_engine_cs *engine;
struct active_node *node;
struct rb_node **p, *parent;
node = container_of((struct list_head *)pos,
typeof(*node), base.link);
engine = (void *)rcu_access_pointer(node->base.request);
RCU_INIT_POINTER(node->base.request, ERR_PTR(-EAGAIN));
parent = NULL;
p = &ref->tree.rb_node;
while (*p) {
parent = *p;
if (rb_entry(parent,
struct active_node,
node)->timeline < node->timeline)
p = &parent->rb_right;
else
p = &parent->rb_left;
}
rb_link_node(&node->node, parent, p);
rb_insert_color(&node->node, &ref->tree);
llist_add((struct llist_node *)&node->base.link,
&engine->barrier_tasks);
}
i915_active_release(ref);
}
void i915_request_add_barriers(struct i915_request *rq)
{
struct intel_engine_cs *engine = rq->engine;
struct llist_node *node, *next;
llist_for_each_safe(node, next, llist_del_all(&engine->barrier_tasks))
list_add_tail((struct list_head *)node, &rq->active_list);
}
int i915_active_request_set(struct i915_active_request *active,
struct i915_request *rq)
{