[PATCH 09/49] drm/i915: Simplify releasing context reference

Chris Wilson chris at chris-wilson.co.uk
Wed Dec 7 11:30:18 UTC 2016


A few users only take the struct_mutex in order to release a reference
to a context. We can expose a kref_put_mutex() wrapper in order to
simplify these users, and optimise taking of the mutex to the final
unref.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_drv.h  |  7 +++++++
 drivers/gpu/drm/i915/i915_perf.c | 16 ++++------------
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 58cc83b7c0c6..375a749316da 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -3318,6 +3318,13 @@ static inline void i915_gem_context_put(struct i915_gem_context *ctx)
 	kref_put(&ctx->ref, i915_gem_context_free);
 }
 
+static inline void i915_gem_context_put_unlocked(struct i915_gem_context *ctx)
+{
+	kref_put_mutex(&ctx->ref,
+		       i915_gem_context_free,
+		       &ctx->i915->drm.struct_mutex);
+}
+
 static inline struct intel_timeline *
 i915_gem_context_lookup_timeline(struct i915_gem_context *ctx,
 				 struct intel_engine_cs *engine)
diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index cfe4152212b9..ee6271fe96de 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -1298,8 +1298,6 @@ static long i915_perf_ioctl(struct file *file,
 
 static void i915_perf_destroy_locked(struct i915_perf_stream *stream)
 {
-	struct drm_i915_private *dev_priv = stream->dev_priv;
-
 	if (stream->enabled)
 		i915_perf_disable_locked(stream);
 
@@ -1308,11 +1306,8 @@ static void i915_perf_destroy_locked(struct i915_perf_stream *stream)
 
 	list_del(&stream->link);
 
-	if (stream->ctx) {
-		mutex_lock(&dev_priv->drm.struct_mutex);
-		i915_gem_context_put(stream->ctx);
-		mutex_unlock(&dev_priv->drm.struct_mutex);
-	}
+	if (stream->ctx)
+		i915_gem_context_put_unlocked(stream->ctx);
 
 	kfree(stream);
 }
@@ -1446,11 +1441,8 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv,
 err_alloc:
 	kfree(stream);
 err_ctx:
-	if (specific_ctx) {
-		mutex_lock(&dev_priv->drm.struct_mutex);
-		i915_gem_context_put(specific_ctx);
-		mutex_unlock(&dev_priv->drm.struct_mutex);
-	}
+	if (specific_ctx)
+		i915_gem_context_put_unlocked(specific_ctx);
 err:
 	return ret;
 }
-- 
2.11.0



More information about the Intel-gfx-trybot mailing list