Skip to content

Commit 7dbc19d

Browse files
tursulindanvet
authored andcommitted
drm/i915: Extract active lookup engine to a helper
Move active engine lookup to exported i915_request_active_engine. Signed-off-by: Tvrtko Ursulin <[email protected]> Reviewed-by: Matthew Auld <[email protected]> [danvet: Slight rebase, engine->sched.lock is still called engine->active.lock.] Signed-off-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 5b0a78e commit 7dbc19d

File tree

3 files changed

+49
-33
lines changed

3 files changed

+49
-33
lines changed

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

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -386,38 +386,6 @@ static bool __cancel_engine(struct intel_engine_cs *engine)
386386
return intel_engine_pulse(engine) == 0;
387387
}
388388

389-
static bool
390-
__active_engine(struct i915_request *rq, struct intel_engine_cs **active)
391-
{
392-
struct intel_engine_cs *engine, *locked;
393-
bool ret = false;
394-
395-
/*
396-
* Serialise with __i915_request_submit() so that it sees
397-
* is-banned?, or we know the request is already inflight.
398-
*
399-
* Note that rq->engine is unstable, and so we double
400-
* check that we have acquired the lock on the final engine.
401-
*/
402-
locked = READ_ONCE(rq->engine);
403-
spin_lock_irq(&locked->active.lock);
404-
while (unlikely(locked != (engine = READ_ONCE(rq->engine)))) {
405-
spin_unlock(&locked->active.lock);
406-
locked = engine;
407-
spin_lock(&locked->active.lock);
408-
}
409-
410-
if (i915_request_is_active(rq)) {
411-
if (!__i915_request_is_complete(rq))
412-
*active = locked;
413-
ret = true;
414-
}
415-
416-
spin_unlock_irq(&locked->active.lock);
417-
418-
return ret;
419-
}
420-
421389
static struct intel_engine_cs *active_engine(struct intel_context *ce)
422390
{
423391
struct intel_engine_cs *engine = NULL;
@@ -445,7 +413,7 @@ static struct intel_engine_cs *active_engine(struct intel_context *ce)
445413
/* Check with the backend if the request is inflight */
446414
found = true;
447415
if (likely(rcu_access_pointer(rq->timeline) == ce->timeline))
448-
found = __active_engine(rq, &engine);
416+
found = i915_request_active_engine(rq, &engine);
449417

450418
i915_request_put(rq);
451419
if (found)

drivers/gpu/drm/i915/i915_request.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,50 @@ static void __i915_request_fill(struct i915_request *rq, u8 val)
244244
memset(vaddr + head, val, rq->postfix - head);
245245
}
246246

247+
/**
248+
* i915_request_active_engine
249+
* @rq: request to inspect
250+
* @active: pointer in which to return the active engine
251+
*
252+
* Fills the currently active engine to the @active pointer if the request
253+
* is active and still not completed.
254+
*
255+
* Returns true if request was active or false otherwise.
256+
*/
257+
bool
258+
i915_request_active_engine(struct i915_request *rq,
259+
struct intel_engine_cs **active)
260+
{
261+
struct intel_engine_cs *engine, *locked;
262+
bool ret = false;
263+
264+
/*
265+
* Serialise with __i915_request_submit() so that it sees
266+
* is-banned?, or we know the request is already inflight.
267+
*
268+
* Note that rq->engine is unstable, and so we double
269+
* check that we have acquired the lock on the final engine.
270+
*/
271+
locked = READ_ONCE(rq->engine);
272+
spin_lock_irq(&locked->active.lock);
273+
while (unlikely(locked != (engine = READ_ONCE(rq->engine)))) {
274+
spin_unlock(&locked->active.lock);
275+
locked = engine;
276+
spin_lock(&locked->active.lock);
277+
}
278+
279+
if (i915_request_is_active(rq)) {
280+
if (!__i915_request_is_complete(rq))
281+
*active = locked;
282+
ret = true;
283+
}
284+
285+
spin_unlock_irq(&locked->active.lock);
286+
287+
return ret;
288+
}
289+
290+
247291
static void remove_from_engine(struct i915_request *rq)
248292
{
249293
struct intel_engine_cs *engine, *locked;

drivers/gpu/drm/i915/i915_request.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,4 +627,8 @@ i915_request_active_seqno(const struct i915_request *rq)
627627
return hwsp_phys_base + hwsp_relative_offset;
628628
}
629629

630+
bool
631+
i915_request_active_engine(struct i915_request *rq,
632+
struct intel_engine_cs **active);
633+
630634
#endif /* I915_REQUEST_H */

0 commit comments

Comments
 (0)