Skip to content

Commit

Permalink
drm/i915: Add timeline barrier support
Browse files Browse the repository at this point in the history
Timeline barrier allows serialization between different timelines.

After calling i915_timeline_set_barrier with a request, all following
submissions on this timeline will be set up as depending on this request,
or barrier. Once the barrier has been completed it automatically gets
cleared and things continue as normal.

This facility will be used by the upcoming context SSEU code.

v2:
 * Assert barrier has been retired on timeline_fini. (Chris Wilson)
 * Fix mock_timeline.

v3:
 * Improved comment language. (Chris Wilson)

v4:
 * Maintain ordering with previous barriers set on the timeline.

v5:
 * Rebase.

Signed-off-by: Tvrtko Ursulin <[email protected]>
Suggested-by: Chris Wilson <[email protected]>
Cc: Chris Wilson <[email protected]>
Reviewed-by: Chris Wilson <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
  • Loading branch information
tursulin authored and evadot committed May 7, 2020
1 parent 74409fd commit d11af3a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
17 changes: 17 additions & 0 deletions drivers/gpu/drm/i915/i915_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,19 @@ i915_request_alloc_slow(struct intel_context *ce)
return kmem_cache_alloc(ce->gem_context->i915->requests, GFP_KERNEL);
}

static int add_barrier(struct i915_request *rq, struct i915_gem_active *active)
{
struct i915_request *barrier =
i915_gem_active_raw(active, &rq->i915->drm.struct_mutex);

return barrier ? i915_request_await_dma_fence(rq, &barrier->fence) : 0;
}

static int add_timeline_barrier(struct i915_request *rq)
{
return add_barrier(rq, &rq->timeline->barrier);
}

/**
* i915_request_alloc - allocate a request structure
*
Expand Down Expand Up @@ -681,6 +694,10 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx)
*/
rq->head = rq->ring->emit;

ret = add_timeline_barrier(rq);
if (ret)
goto err_unwind;

ret = engine->request_alloc(rq);
if (ret)
goto err_unwind;
Expand Down
21 changes: 21 additions & 0 deletions drivers/gpu/drm/i915/i915_timeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ int i915_timeline_init(struct drm_i915_private *i915,

spin_lock_init(&timeline->lock);

init_request_active(&timeline->barrier, NULL);
init_request_active(&timeline->last_request, NULL);
INIT_LIST_HEAD(&timeline->requests);

Expand Down Expand Up @@ -239,6 +240,7 @@ void i915_timeline_fini(struct i915_timeline *timeline)
{
GEM_BUG_ON(timeline->pin_count);
GEM_BUG_ON(!list_empty(&timeline->requests));
GEM_BUG_ON(i915_gem_active_isset(&timeline->barrier));

i915_syncmap_free(&timeline->sync);
hwsp_free(timeline);
Expand Down Expand Up @@ -313,6 +315,25 @@ void i915_timeline_unpin(struct i915_timeline *tl)
__i915_vma_unpin(tl->hwsp_ggtt);
}

int i915_timeline_set_barrier(struct i915_timeline *tl, struct i915_request *rq)
{
struct i915_request *old;
int err;

lockdep_assert_held(&rq->i915->drm.struct_mutex);

/* Must maintain ordering wrt existing barriers */
old = i915_gem_active_raw(&tl->barrier, &rq->i915->drm.struct_mutex);
if (old) {
err = i915_request_await_dma_fence(rq, &old->fence);
if (err)
return err;
}

i915_gem_active_set(&tl->barrier, rq);
return 0;
}

void __i915_timeline_free(struct kref *kref)
{
struct i915_timeline *timeline =
Expand Down
22 changes: 22 additions & 0 deletions drivers/gpu/drm/i915/i915_timeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ struct i915_timeline {
*/
struct i915_syncmap *sync;

/**
* Barrier provides the ability to serialize ordering between different
* timelines.
*
* Users can call i915_timeline_set_barrier which will make all
* subsequent submissions to this timeline be executed only after the
* barrier has been completed.
*/
struct i915_gem_active barrier;

struct list_head link;
const char *name;
struct drm_i915_private *i915;
Expand Down Expand Up @@ -157,4 +167,16 @@ void i915_timelines_init(struct drm_i915_private *i915);
void i915_timelines_park(struct drm_i915_private *i915);
void i915_timelines_fini(struct drm_i915_private *i915);

/**
* i915_timeline_set_barrier - orders submission between different timelines
* @timeline: timeline to set the barrier on
* @rq: request after which new submissions can proceed
*
* Sets the passed in request as the serialization point for all subsequent
* submissions on @timeline. Subsequent requests will not be submitted to GPU
* until the barrier has been completed.
*/
int i915_timeline_set_barrier(struct i915_timeline *timeline,
struct i915_request *rq);

#endif

0 comments on commit d11af3a

Please sign in to comment.