Commit fe7bcfae authored by Chris Wilson's avatar Chris Wilson

drm/i915/gt: Refactor heartbeat request construction and submission

Pull the individual strands of creating a custom heartbeat requests into
a pair of common functions. This will reduce the number of changes we
will need to make in future.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20201224160213.29521-1-chris@chris-wilson.co.uk
parent 26ebc511
...@@ -37,6 +37,18 @@ static bool next_heartbeat(struct intel_engine_cs *engine) ...@@ -37,6 +37,18 @@ static bool next_heartbeat(struct intel_engine_cs *engine)
return true; return true;
} }
static struct i915_request *
heartbeat_create(struct intel_context *ce, gfp_t gfp)
{
struct i915_request *rq;
intel_context_enter(ce);
rq = __i915_request_create(ce, gfp);
intel_context_exit(ce);
return rq;
}
static void idle_pulse(struct intel_engine_cs *engine, struct i915_request *rq) static void idle_pulse(struct intel_engine_cs *engine, struct i915_request *rq)
{ {
engine->wakeref_serial = READ_ONCE(engine->serial) + 1; engine->wakeref_serial = READ_ONCE(engine->serial) + 1;
...@@ -45,6 +57,15 @@ static void idle_pulse(struct intel_engine_cs *engine, struct i915_request *rq) ...@@ -45,6 +57,15 @@ static void idle_pulse(struct intel_engine_cs *engine, struct i915_request *rq)
engine->heartbeat.systole = i915_request_get(rq); engine->heartbeat.systole = i915_request_get(rq);
} }
static void heartbeat_commit(struct i915_request *rq,
const struct i915_sched_attr *attr)
{
idle_pulse(rq->engine, rq);
__i915_request_commit(rq);
__i915_request_queue(rq, attr);
}
static void show_heartbeat(const struct i915_request *rq, static void show_heartbeat(const struct i915_request *rq,
struct intel_engine_cs *engine) struct intel_engine_cs *engine)
{ {
...@@ -139,16 +160,11 @@ static void heartbeat(struct work_struct *wrk) ...@@ -139,16 +160,11 @@ static void heartbeat(struct work_struct *wrk)
goto out; goto out;
} }
intel_context_enter(ce); rq = heartbeat_create(ce, GFP_NOWAIT | __GFP_NOWARN);
rq = __i915_request_create(ce, GFP_NOWAIT | __GFP_NOWARN);
intel_context_exit(ce);
if (IS_ERR(rq)) if (IS_ERR(rq))
goto unlock; goto unlock;
idle_pulse(engine, rq); heartbeat_commit(rq, &attr);
__i915_request_commit(rq);
__i915_request_queue(rq, &attr);
unlock: unlock:
mutex_unlock(&ce->timeline->mutex); mutex_unlock(&ce->timeline->mutex);
...@@ -187,17 +203,13 @@ static int __intel_engine_pulse(struct intel_engine_cs *engine) ...@@ -187,17 +203,13 @@ static int __intel_engine_pulse(struct intel_engine_cs *engine)
GEM_BUG_ON(!intel_engine_has_preemption(engine)); GEM_BUG_ON(!intel_engine_has_preemption(engine));
GEM_BUG_ON(!intel_engine_pm_is_awake(engine)); GEM_BUG_ON(!intel_engine_pm_is_awake(engine));
intel_context_enter(ce); rq = heartbeat_create(ce, GFP_NOWAIT | __GFP_NOWARN);
rq = __i915_request_create(ce, GFP_NOWAIT | __GFP_NOWARN);
intel_context_exit(ce);
if (IS_ERR(rq)) if (IS_ERR(rq))
return PTR_ERR(rq); return PTR_ERR(rq);
__set_bit(I915_FENCE_FLAG_SENTINEL, &rq->fence.flags); __set_bit(I915_FENCE_FLAG_SENTINEL, &rq->fence.flags);
idle_pulse(engine, rq);
__i915_request_commit(rq); heartbeat_commit(rq, &attr);
__i915_request_queue(rq, &attr);
GEM_BUG_ON(rq->sched.attr.priority < I915_PRIORITY_BARRIER); GEM_BUG_ON(rq->sched.attr.priority < I915_PRIORITY_BARRIER);
return 0; return 0;
...@@ -273,8 +285,12 @@ int intel_engine_pulse(struct intel_engine_cs *engine) ...@@ -273,8 +285,12 @@ int intel_engine_pulse(struct intel_engine_cs *engine)
int intel_engine_flush_barriers(struct intel_engine_cs *engine) int intel_engine_flush_barriers(struct intel_engine_cs *engine)
{ {
struct i915_sched_attr attr = {
.priority = I915_USER_PRIORITY(I915_PRIORITY_MIN),
};
struct intel_context *ce = engine->kernel_context;
struct i915_request *rq; struct i915_request *rq;
int err = 0; int err;
if (llist_empty(&engine->barrier_tasks)) if (llist_empty(&engine->barrier_tasks))
return 0; return 0;
...@@ -282,15 +298,22 @@ int intel_engine_flush_barriers(struct intel_engine_cs *engine) ...@@ -282,15 +298,22 @@ int intel_engine_flush_barriers(struct intel_engine_cs *engine)
if (!intel_engine_pm_get_if_awake(engine)) if (!intel_engine_pm_get_if_awake(engine))
return 0; return 0;
rq = i915_request_create(engine->kernel_context); if (mutex_lock_interruptible(&ce->timeline->mutex)) {
err = -EINTR;
goto out_rpm;
}
rq = heartbeat_create(ce, GFP_KERNEL);
if (IS_ERR(rq)) { if (IS_ERR(rq)) {
err = PTR_ERR(rq); err = PTR_ERR(rq);
goto out_rpm; goto out_unlock;
} }
idle_pulse(engine, rq); heartbeat_commit(rq, &attr);
i915_request_add(rq);
err = 0;
out_unlock:
mutex_unlock(&ce->timeline->mutex);
out_rpm: out_rpm:
intel_engine_pm_put(engine); intel_engine_pm_put(engine);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment