[Intel-gfx] [PATCH] drm/i915: extract common ce->pin_count check

Daniele Ceraolo Spurio daniele.ceraolospurio at intel.com
Mon Oct 1 20:46:56 UTC 2018


We already have it coded 3 times and a 4th one is coming for the GuC
path in an upcoming patch, so let's move it to a common place.

Cc: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Michal Wajdeczko <michal.wajdeczko at intel.com>
Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
---
 drivers/gpu/drm/i915/i915_gem_context.h      |  8 +++++++-
 drivers/gpu/drm/i915/intel_lrc.c             | 10 ++--------
 drivers/gpu/drm/i915/intel_ringbuffer.c      | 10 ++--------
 drivers/gpu/drm/i915/intel_ringbuffer.h      |  3 ++-
 drivers/gpu/drm/i915/selftests/mock_engine.c | 13 +++++--------
 5 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_context.h b/drivers/gpu/drm/i915/i915_gem_context.h
index 08165f6a0a84..5309004f8f8a 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.h
+++ b/drivers/gpu/drm/i915/i915_gem_context.h
@@ -302,7 +302,13 @@ to_intel_context(struct i915_gem_context *ctx,
 static inline struct intel_context *
 intel_context_pin(struct i915_gem_context *ctx, struct intel_engine_cs *engine)
 {
-	return engine->context_pin(engine, ctx);
+	struct intel_context *ce = to_intel_context(ctx, engine);
+
+	if (likely(ce->pin_count++))
+		return ce;
+	GEM_BUG_ON(!ce->pin_count); /* no overflow please! */
+
+	return engine->context_pin(engine, ctx, ce);
 }
 
 static inline void __intel_context_pin(struct intel_context *ce)
diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
index 4ee00f531153..a97f455361f6 100644
--- a/drivers/gpu/drm/i915/intel_lrc.c
+++ b/drivers/gpu/drm/i915/intel_lrc.c
@@ -1422,19 +1422,13 @@ static const struct intel_context_ops execlists_context_ops = {
 
 static struct intel_context *
 execlists_context_pin(struct intel_engine_cs *engine,
-		      struct i915_gem_context *ctx)
+		      struct i915_gem_context *ctx,
+		      struct intel_context *ce)
 {
-	struct intel_context *ce = to_intel_context(ctx, engine);
-
 	lockdep_assert_held(&ctx->i915->drm.struct_mutex);
 	GEM_BUG_ON(!ctx->ppgtt);
 
-	if (likely(ce->pin_count++))
-		return ce;
-	GEM_BUG_ON(!ce->pin_count); /* no overflow please! */
-
 	ce->ops = &execlists_context_ops;
-
 	return __execlists_context_pin(engine, ctx, ce);
 }
 
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index c092d5099ebf..a82564c50496 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -1386,18 +1386,12 @@ static const struct intel_context_ops ring_context_ops = {
 
 static struct intel_context *
 intel_ring_context_pin(struct intel_engine_cs *engine,
-		       struct i915_gem_context *ctx)
+		       struct i915_gem_context *ctx,
+		       struct intel_context *ce)
 {
-	struct intel_context *ce = to_intel_context(ctx, engine);
-
 	lockdep_assert_held(&ctx->i915->drm.struct_mutex);
 
-	if (likely(ce->pin_count++))
-		return ce;
-	GEM_BUG_ON(!ce->pin_count); /* no overflow please! */
-
 	ce->ops = &ring_context_ops;
-
 	return __ring_context_pin(engine, ctx, ce);
 }
 
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h
index 1534de5bb852..91973bd9003c 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -473,7 +473,8 @@ struct intel_engine_cs {
 	void		(*set_default_submission)(struct intel_engine_cs *engine);
 
 	struct intel_context *(*context_pin)(struct intel_engine_cs *engine,
-					     struct i915_gem_context *ctx);
+					     struct i915_gem_context *ctx,
+					     struct intel_context *ce);
 
 	int		(*request_alloc)(struct i915_request *rq);
 	int		(*init_context)(struct i915_request *rq);
diff --git a/drivers/gpu/drm/i915/selftests/mock_engine.c b/drivers/gpu/drm/i915/selftests/mock_engine.c
index 22a73da45ad5..4d5103634a2b 100644
--- a/drivers/gpu/drm/i915/selftests/mock_engine.c
+++ b/drivers/gpu/drm/i915/selftests/mock_engine.c
@@ -89,15 +89,12 @@ static const struct intel_context_ops mock_context_ops = {
 
 static struct intel_context *
 mock_context_pin(struct intel_engine_cs *engine,
-		 struct i915_gem_context *ctx)
+		 struct i915_gem_context *ctx,
+		 struct intel_context *ce)
 {
-	struct intel_context *ce = to_intel_context(ctx, engine);
-
-	if (!ce->pin_count++) {
-		i915_gem_context_get(ctx);
-		ce->ring = engine->buffer;
-		ce->ops = &mock_context_ops;
-	}
+	i915_gem_context_get(ctx);
+	ce->ring = engine->buffer;
+	ce->ops = &mock_context_ops;
 
 	return ce;
 }
-- 
2.19.0



More information about the Intel-gfx mailing list