[PATCH 5/5] drm/i915: Add locking to intel_context_unpin
Maarten Lankhorst
maarten.lankhorst at linux.intel.com
Tue Jun 29 14:33:52 UTC 2021
Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
---
drivers/gpu/drm/i915/gt/intel_context.c | 68 ++++++++++++++++++++++---
drivers/gpu/drm/i915/gt/intel_context.h | 7 +--
2 files changed, 63 insertions(+), 12 deletions(-)
diff --git a/drivers/gpu/drm/i915/gt/intel_context.c b/drivers/gpu/drm/i915/gt/intel_context.c
index b630c1968794..b27731ce8c11 100644
--- a/drivers/gpu/drm/i915/gt/intel_context.c
+++ b/drivers/gpu/drm/i915/gt/intel_context.c
@@ -286,11 +286,8 @@ int __intel_context_do_pin(struct intel_context *ce)
return err;
}
-void intel_context_unpin(struct intel_context *ce)
+static void __intel_context_unpin(struct intel_context *ce)
{
- if (!atomic_dec_and_test(&ce->pin_count))
- return;
-
CE_TRACE(ce, "unpin\n");
ce->ops->unpin(ce);
@@ -305,16 +302,75 @@ void intel_context_unpin(struct intel_context *ce)
intel_context_put(ce);
}
+void intel_context_unpin(struct intel_context *ce)
+{
+ if (!atomic_dec_and_test(&ce->pin_count))
+ return;
+
+ __intel_context_unpin(ce);
+}
+
+void intel_context_unpin_unlocked(struct intel_context *ce)
+{
+ struct i915_gem_ww_ctx ww;
+ int err;
+
+ if (!atomic_dec_and_test(&ce->pin_count))
+ return;
+
+ i915_gem_ww_ctx_init(&ww, false);
+retry:
+ err = i915_gem_object_lock(ce->timeline->hwsp_ggtt->obj, &ww);
+ if (!err && ce->ring->vma->obj)
+ err = i915_gem_object_lock(ce->ring->vma->obj, &ww);
+ if (!err && ce->state)
+ err = i915_gem_object_lock(ce->state->obj, &ww);
+
+ if (!err)
+ __intel_context_unpin(ce);
+
+ if (err == -EDEADLK) {
+ err = i915_gem_ww_ctx_backoff(&ww);
+ if (!err)
+ goto retry;
+ }
+ i915_gem_ww_ctx_fini(&ww);
+
+ GEM_WARN_ON(err);
+}
+
static void __intel_context_retire(struct i915_active *active)
{
struct intel_context *ce = container_of(active, typeof(*ce), active);
+ struct i915_gem_ww_ctx ww;
+ int err;
CE_TRACE(ce, "retire runtime: { total:%lluns, avg:%lluns }\n",
intel_context_get_total_runtime_ns(ce),
intel_context_get_avg_runtime_ns(ce));
set_bit(CONTEXT_VALID_BIT, &ce->flags);
- intel_context_post_unpin(ce);
+
+ i915_gem_ww_ctx_init(&ww, false);
+retry:
+ err = i915_gem_object_lock(ce->timeline->hwsp_ggtt->obj, &ww);
+ if (!err && ce->ring->vma->obj)
+ err = i915_gem_object_lock(ce->ring->vma->obj, &ww);
+ if (!err && ce->state)
+ err = i915_gem_object_lock(ce->state->obj, &ww);
+
+ if (!err)
+ intel_context_post_unpin(ce);
+
+ if (err == -EDEADLK) {
+ err = i915_gem_ww_ctx_backoff(&ww);
+ if (!err)
+ goto retry;
+ }
+ i915_gem_ww_ctx_fini(&ww);
+
+ GEM_WARN_ON(err);
+
intel_context_put(ce);
}
@@ -363,7 +419,7 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
mutex_init(&ce->alloc_mutex);
i915_active_init(&ce->active,
- __intel_context_active, __intel_context_retire, 0);
+ __intel_context_active, __intel_context_retire, I915_ACTIVE_RETIRE_SLEEPS);
}
void intel_context_fini(struct intel_context *ce)
diff --git a/drivers/gpu/drm/i915/gt/intel_context.h b/drivers/gpu/drm/i915/gt/intel_context.h
index 4cf6901fcb81..45fea2e82637 100644
--- a/drivers/gpu/drm/i915/gt/intel_context.h
+++ b/drivers/gpu/drm/i915/gt/intel_context.h
@@ -116,13 +116,8 @@ static inline int intel_context_pin_ww(struct intel_context *ce,
return __intel_context_do_pin_ww(ce, ww);
}
-static inline void __intel_context_pin(struct intel_context *ce)
-{
- GEM_BUG_ON(!intel_context_is_pinned(ce));
- atomic_inc(&ce->pin_count);
-}
-
void intel_context_unpin(struct intel_context *ce);
+void intel_context_unpin_unlocked(struct intel_context *ce);
void intel_context_enter_engine(struct intel_context *ce);
void intel_context_exit_engine(struct intel_context *ce);
--
2.31.0
More information about the Intel-gfx-trybot
mailing list