Skip to content

Commit 75d0a7f

Browse files
committed
drm/i915: Lift timeline into intel_context
Move the timeline from being inside the intel_ring to intel_context itself. This saves much pointer dancing and makes the relations of the context to its timeline much clearer. Signed-off-by: Chris Wilson <[email protected]> Reviewed-by: Matthew Auld <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 48ae397 commit 75d0a7f

15 files changed

+140
-135
lines changed

drivers/gpu/drm/i915/gem/i915_gem_context.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,29 @@ static void __assign_ppgtt(struct i915_gem_context *ctx,
489489
i915_vm_put(vm);
490490
}
491491

492+
static void __set_timeline(struct intel_timeline **dst,
493+
struct intel_timeline *src)
494+
{
495+
struct intel_timeline *old = *dst;
496+
497+
*dst = src ? intel_timeline_get(src) : NULL;
498+
499+
if (old)
500+
intel_timeline_put(old);
501+
}
502+
503+
static void __apply_timeline(struct intel_context *ce, void *timeline)
504+
{
505+
__set_timeline(&ce->timeline, timeline);
506+
}
507+
508+
static void __assign_timeline(struct i915_gem_context *ctx,
509+
struct intel_timeline *timeline)
510+
{
511+
__set_timeline(&ctx->timeline, timeline);
512+
context_apply_all(ctx, __apply_timeline, timeline);
513+
}
514+
492515
static struct i915_gem_context *
493516
i915_gem_create_context(struct drm_i915_private *dev_priv, unsigned int flags)
494517
{
@@ -531,7 +554,8 @@ i915_gem_create_context(struct drm_i915_private *dev_priv, unsigned int flags)
531554
return ERR_CAST(timeline);
532555
}
533556

534-
ctx->timeline = timeline;
557+
__assign_timeline(ctx, timeline);
558+
intel_timeline_put(timeline);
535559
}
536560

537561
trace_i915_context_create(ctx);
@@ -1931,13 +1955,8 @@ static int clone_sseu(struct i915_gem_context *dst,
19311955
static int clone_timeline(struct i915_gem_context *dst,
19321956
struct i915_gem_context *src)
19331957
{
1934-
if (src->timeline) {
1935-
GEM_BUG_ON(src->timeline == dst->timeline);
1936-
1937-
if (dst->timeline)
1938-
intel_timeline_put(dst->timeline);
1939-
dst->timeline = intel_timeline_get(src->timeline);
1940-
}
1958+
if (src->timeline)
1959+
__assign_timeline(dst, src->timeline);
19411960

19421961
return 0;
19431962
}

drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,7 @@ static int eb_pin_context(struct i915_execbuffer *eb, struct intel_context *ce)
21822182
static void eb_unpin_context(struct i915_execbuffer *eb)
21832183
{
21842184
struct intel_context *ce = eb->context;
2185-
struct intel_timeline *tl = ce->ring->timeline;
2185+
struct intel_timeline *tl = ce->timeline;
21862186

21872187
mutex_lock(&tl->mutex);
21882188
intel_context_exit(ce);

drivers/gpu/drm/i915/gt/intel_context.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int __intel_context_do_pin(struct intel_context *ce)
6868
goto err;
6969

7070
GEM_TRACE("%s context:%llx pin ring:{head:%04x, tail:%04x}\n",
71-
ce->engine->name, ce->ring->timeline->fence_context,
71+
ce->engine->name, ce->timeline->fence_context,
7272
ce->ring->head, ce->ring->tail);
7373

7474
i915_gem_context_get(ce->gem_context); /* for ctx->ppgtt */
@@ -98,7 +98,7 @@ void intel_context_unpin(struct intel_context *ce)
9898

9999
if (likely(atomic_dec_and_test(&ce->pin_count))) {
100100
GEM_TRACE("%s context:%llx retire\n",
101-
ce->engine->name, ce->ring->timeline->fence_context);
101+
ce->engine->name, ce->timeline->fence_context);
102102

103103
ce->ops->unpin(ce);
104104

@@ -143,11 +143,12 @@ static void __intel_context_retire(struct i915_active *active)
143143
struct intel_context *ce = container_of(active, typeof(*ce), active);
144144

145145
GEM_TRACE("%s context:%llx retire\n",
146-
ce->engine->name, ce->ring->timeline->fence_context);
146+
ce->engine->name, ce->timeline->fence_context);
147147

148148
if (ce->state)
149149
__context_unpin_state(ce->state);
150150

151+
intel_timeline_unpin(ce->timeline);
151152
intel_ring_unpin(ce->ring);
152153
intel_context_put(ce);
153154
}
@@ -163,15 +164,21 @@ static int __intel_context_active(struct i915_active *active)
163164
if (err)
164165
goto err_put;
165166

167+
err = intel_timeline_pin(ce->timeline);
168+
if (err)
169+
goto err_ring;
170+
166171
if (!ce->state)
167172
return 0;
168173

169174
err = __context_pin_state(ce->state);
170175
if (err)
171-
goto err_ring;
176+
goto err_timeline;
172177

173178
return 0;
174179

180+
err_timeline:
181+
intel_timeline_unpin(ce->timeline);
175182
err_ring:
176183
intel_ring_unpin(ce->ring);
177184
err_put:
@@ -218,6 +225,8 @@ intel_context_init(struct intel_context *ce,
218225

219226
ce->gem_context = ctx;
220227
ce->vm = i915_vm_get(ctx->vm ?: &engine->gt->ggtt->vm);
228+
if (ctx->timeline)
229+
ce->timeline = intel_timeline_get(ctx->timeline);
221230

222231
ce->engine = engine;
223232
ce->ops = engine->cops;
@@ -235,6 +244,8 @@ intel_context_init(struct intel_context *ce,
235244

236245
void intel_context_fini(struct intel_context *ce)
237246
{
247+
if (ce->timeline)
248+
intel_timeline_put(ce->timeline);
238249
i915_vm_put(ce->vm);
239250

240251
mutex_destroy(&ce->pin_mutex);
@@ -279,7 +290,7 @@ void intel_context_exit_engine(struct intel_context *ce)
279290
int intel_context_prepare_remote_request(struct intel_context *ce,
280291
struct i915_request *rq)
281292
{
282-
struct intel_timeline *tl = ce->ring->timeline;
293+
struct intel_timeline *tl = ce->timeline;
283294
int err;
284295

285296
/* Only suitable for use in remotely modifying this context */

drivers/gpu/drm/i915/gt/intel_context.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ static inline void intel_context_put(struct intel_context *ce)
120120

121121
static inline int __must_check
122122
intel_context_timeline_lock(struct intel_context *ce)
123-
__acquires(&ce->ring->timeline->mutex)
123+
__acquires(&ce->timeline->mutex)
124124
{
125-
return mutex_lock_interruptible(&ce->ring->timeline->mutex);
125+
return mutex_lock_interruptible(&ce->timeline->mutex);
126126
}
127127

128128
static inline void intel_context_timeline_unlock(struct intel_context *ce)
129-
__releases(&ce->ring->timeline->mutex)
129+
__releases(&ce->timeline->mutex)
130130
{
131-
mutex_unlock(&ce->ring->timeline->mutex);
131+
mutex_unlock(&ce->timeline->mutex);
132132
}
133133

134134
int intel_context_prepare_remote_request(struct intel_context *ce,

drivers/gpu/drm/i915/gt/intel_context_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct intel_context {
5353

5454
struct i915_vma *state;
5555
struct intel_ring *ring;
56+
struct intel_timeline *timeline;
5657

5758
unsigned long flags;
5859
#define CONTEXT_ALLOC_BIT 0

drivers/gpu/drm/i915/gt/intel_engine.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ intel_write_status_page(struct intel_engine_cs *engine, int reg, u32 value)
196196
#define CNL_HWS_CSB_WRITE_INDEX 0x2f
197197

198198
struct intel_ring *
199-
intel_engine_create_ring(struct intel_engine_cs *engine,
200-
struct intel_timeline *timeline,
201-
int size);
199+
intel_engine_create_ring(struct intel_engine_cs *engine, int size);
202200
int intel_ring_pin(struct intel_ring *ring);
203201
void intel_ring_reset(struct intel_ring *ring, u32 tail);
204202
unsigned int intel_ring_update_space(struct intel_ring *ring);

drivers/gpu/drm/i915/gt/intel_engine_cs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,6 @@ static int measure_breadcrumb_dw(struct intel_engine_cs *engine)
680680
goto out_frame;
681681

682682
INIT_LIST_HEAD(&frame->ring.request_list);
683-
frame->ring.timeline = &frame->timeline;
684683
frame->ring.vaddr = frame->cs;
685684
frame->ring.size = sizeof(frame->cs);
686685
frame->ring.effective_size = frame->ring.size;

drivers/gpu/drm/i915/gt/intel_engine_types.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ struct intel_ring {
6969
struct i915_vma *vma;
7070
void *vaddr;
7171

72-
struct intel_timeline *timeline;
7372
struct list_head request_list;
7473
struct list_head active_link;
7574

@@ -286,8 +285,6 @@ struct intel_engine_cs {
286285

287286
struct intel_sseu sseu;
288287

289-
struct intel_ring *buffer;
290-
291288
struct {
292289
spinlock_t lock;
293290
struct list_head requests;
@@ -306,6 +303,11 @@ struct intel_engine_cs {
306303
struct drm_i915_gem_object *default_state;
307304
void *pinned_default_state;
308305

306+
struct {
307+
struct intel_ring *ring;
308+
struct intel_timeline *timeline;
309+
} legacy;
310+
309311
/* Rather than have every client wait upon all user interrupts,
310312
* with the herd waking after every interrupt and each doing the
311313
* heavyweight seqno dance, we delegate the task (of being the

drivers/gpu/drm/i915/gt/intel_lrc.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,9 +2821,6 @@ logical_ring_default_irqs(struct intel_engine_cs *engine)
28212821

28222822
int intel_execlists_submission_setup(struct intel_engine_cs *engine)
28232823
{
2824-
/* Intentionally left blank. */
2825-
engine->buffer = NULL;
2826-
28272824
tasklet_init(&engine->execlists.tasklet,
28282825
execlists_submission_tasklet, (unsigned long)engine);
28292826
timer_setup(&engine->execlists.timer, execlists_submission_timer, 0);
@@ -3071,23 +3068,13 @@ populate_lr_context(struct intel_context *ce,
30713068
return ret;
30723069
}
30733070

3074-
static struct intel_timeline *
3075-
get_timeline(struct i915_gem_context *ctx, struct intel_gt *gt)
3076-
{
3077-
if (ctx->timeline)
3078-
return intel_timeline_get(ctx->timeline);
3079-
else
3080-
return intel_timeline_create(gt, NULL);
3081-
}
3082-
30833071
static int __execlists_context_alloc(struct intel_context *ce,
30843072
struct intel_engine_cs *engine)
30853073
{
30863074
struct drm_i915_gem_object *ctx_obj;
3075+
struct intel_ring *ring;
30873076
struct i915_vma *vma;
30883077
u32 context_size;
3089-
struct intel_ring *ring;
3090-
struct intel_timeline *timeline;
30913078
int ret;
30923079

30933080
GEM_BUG_ON(ce->state);
@@ -3109,15 +3096,19 @@ static int __execlists_context_alloc(struct intel_context *ce,
31093096
goto error_deref_obj;
31103097
}
31113098

3112-
timeline = get_timeline(ce->gem_context, engine->gt);
3113-
if (IS_ERR(timeline)) {
3114-
ret = PTR_ERR(timeline);
3115-
goto error_deref_obj;
3099+
if (!ce->timeline) {
3100+
struct intel_timeline *tl;
3101+
3102+
tl = intel_timeline_create(engine->gt, NULL);
3103+
if (IS_ERR(tl)) {
3104+
ret = PTR_ERR(tl);
3105+
goto error_deref_obj;
3106+
}
3107+
3108+
ce->timeline = tl;
31163109
}
31173110

3118-
ring = intel_engine_create_ring(engine, timeline,
3119-
(unsigned long)ce->ring);
3120-
intel_timeline_put(timeline);
3111+
ring = intel_engine_create_ring(engine, (unsigned long)ce->ring);
31213112
if (IS_ERR(ring)) {
31223113
ret = PTR_ERR(ring);
31233114
goto error_deref_obj;

0 commit comments

Comments
 (0)