Skip to content

Commit 52d7f16

Browse files
committed
drm/i915: Stop tracking timeline->inflight_seqnos
In commit 9b6586a ("drm/i915: Keep a global seqno per-engine"), we moved from a global inflight counter to per-engine counters in the hope that will be easy to run concurrently in future. However, with the advent of the desire to move requests between engines, we do need a global counter to preserve the semantics that no engine wraps in the middle of a submit. (Although this semantic is now only required for gen7 semaphore support, which only supports greater-then comparisons!) v2: Keep a global counter of all requests ever submitted and force the reset when it wraps. References: 9b6586a ("drm/i915: Keep a global seqno per-engine") Signed-off-by: Chris Wilson <[email protected]> Cc: Tvrtko Ursulin <[email protected]> Reviewed-by: Tvrtko Ursulin <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 5692251 commit 52d7f16

File tree

5 files changed

+22
-28
lines changed

5 files changed

+22
-28
lines changed

drivers/gpu/drm/i915/i915_debugfs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,10 +1340,9 @@ static int i915_hangcheck_info(struct seq_file *m, void *unused)
13401340
struct rb_node *rb;
13411341

13421342
seq_printf(m, "%s:\n", engine->name);
1343-
seq_printf(m, "\tseqno = %x [current %x, last %x], inflight %d\n",
1343+
seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
13441344
engine->hangcheck.seqno, seqno[id],
1345-
intel_engine_last_submit(engine),
1346-
engine->timeline->inflight_seqnos);
1345+
intel_engine_last_submit(engine));
13471346
seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
13481347
yesno(intel_engine_has_waiter(engine)),
13491348
yesno(test_bit(engine->id,

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,7 @@ struct drm_i915_private {
20622062
struct list_head timelines;
20632063
struct i915_gem_timeline global_timeline;
20642064
u32 active_requests;
2065+
u32 request_serial;
20652066

20662067
/**
20672068
* Is the GPU currently considered idle, or busy executing

drivers/gpu/drm/i915/i915_gem_timeline.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ struct intel_timeline {
3737
u64 fence_context;
3838
u32 seqno;
3939

40-
/**
41-
* Count of outstanding requests, from the time they are constructed
42-
* to the moment they are retired. Loosely coupled to hardware.
43-
*/
44-
u32 inflight_seqnos;
45-
4640
spinlock_t lock;
4741

4842
/**

drivers/gpu/drm/i915/i915_request.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ static int reset_all_global_seqno(struct drm_i915_private *i915, u32 seqno)
241241
sizeof(timeline->engine[id].global_sync));
242242
}
243243

244+
i915->gt.request_serial = seqno;
244245
return 0;
245246
}
246247

@@ -257,18 +258,22 @@ int i915_gem_set_global_seqno(struct drm_device *dev, u32 seqno)
257258
return reset_all_global_seqno(i915, seqno - 1);
258259
}
259260

260-
static int reserve_engine(struct intel_engine_cs *engine)
261+
static int reserve_gt(struct drm_i915_private *i915)
261262
{
262-
struct drm_i915_private *i915 = engine->i915;
263-
u32 active = ++engine->timeline->inflight_seqnos;
264-
u32 seqno = engine->timeline->seqno;
265263
int ret;
266264

267-
/* Reservation is fine until we need to wrap around */
268-
if (unlikely(add_overflows(seqno, active))) {
265+
/*
266+
* Reservation is fine until we may need to wrap around
267+
*
268+
* By incrementing the serial for every request, we know that no
269+
* individual engine may exceed that serial (as each is reset to 0
270+
* on any wrap). This protects even the most pessimistic of migrations
271+
* of every request from all engines onto just one.
272+
*/
273+
while (unlikely(++i915->gt.request_serial == 0)) {
269274
ret = reset_all_global_seqno(i915, 0);
270275
if (ret) {
271-
engine->timeline->inflight_seqnos--;
276+
i915->gt.request_serial--;
272277
return ret;
273278
}
274279
}
@@ -279,15 +284,10 @@ static int reserve_engine(struct intel_engine_cs *engine)
279284
return 0;
280285
}
281286

282-
static void unreserve_engine(struct intel_engine_cs *engine)
287+
static void unreserve_gt(struct drm_i915_private *i915)
283288
{
284-
struct drm_i915_private *i915 = engine->i915;
285-
286289
if (!--i915->gt.active_requests)
287290
i915_gem_park(i915);
288-
289-
GEM_BUG_ON(!engine->timeline->inflight_seqnos);
290-
engine->timeline->inflight_seqnos--;
291291
}
292292

293293
void i915_gem_retire_noop(struct i915_gem_active *active,
@@ -362,7 +362,6 @@ static void i915_request_retire(struct i915_request *request)
362362
list_del_init(&request->link);
363363
spin_unlock_irq(&engine->timeline->lock);
364364

365-
unreserve_engine(request->engine);
366365
advance_ring(request);
367366

368367
free_capture_list(request);
@@ -424,6 +423,8 @@ static void i915_request_retire(struct i915_request *request)
424423
}
425424
spin_unlock_irq(&request->lock);
426425

426+
unreserve_gt(request->i915);
427+
427428
i915_sched_node_fini(request->i915, &request->sched);
428429
i915_request_put(request);
429430
}
@@ -642,7 +643,7 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx)
642643
return ERR_CAST(ring);
643644
GEM_BUG_ON(!ring);
644645

645-
ret = reserve_engine(engine);
646+
ret = reserve_gt(i915);
646647
if (ret)
647648
goto err_unpin;
648649

@@ -784,7 +785,7 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx)
784785

785786
kmem_cache_free(i915->requests, rq);
786787
err_unreserve:
787-
unreserve_engine(engine);
788+
unreserve_gt(i915);
788789
err_unpin:
789790
engine->context_unpin(engine, ctx);
790791
return ERR_PTR(ret);

drivers/gpu/drm/i915/intel_engine_cs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,12 +1321,11 @@ void intel_engine_dump(struct intel_engine_cs *engine,
13211321
if (i915_terminally_wedged(&engine->i915->gpu_error))
13221322
drm_printf(m, "*** WEDGED ***\n");
13231323

1324-
drm_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms], inflight %d\n",
1324+
drm_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms]\n",
13251325
intel_engine_get_seqno(engine),
13261326
intel_engine_last_submit(engine),
13271327
engine->hangcheck.seqno,
1328-
jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp),
1329-
engine->timeline->inflight_seqnos);
1328+
jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp));
13301329
drm_printf(m, "\tReset count: %d (global %d)\n",
13311330
i915_reset_engine_count(error, engine),
13321331
i915_reset_count(error));

0 commit comments

Comments
 (0)