[Intel-gfx] [PATCH v2 3/3] drm/i915: Remove (struct_mutex) locking for busy-ioctl

Chris Wilson chris at chris-wilson.co.uk
Wed Dec 23 05:35:56 PST 2015


By applying the same logic as for wait-ioctl, we can query whether a
request has completed without holding struct_mutex. The biggest impact
system-wide is removing the flush_active and the contention that causes.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem.c | 53 +++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 3e331f7e9d74..80810d5b5caf 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -3591,37 +3591,38 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,
 {
 	struct drm_i915_gem_busy *args = data;
 	struct drm_i915_gem_object *obj;
-	int ret;
-
-	ret = i915_mutex_lock_interruptible(dev);
-	if (ret)
-		return ret;
 
 	obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
-	if (&obj->base == NULL) {
-		ret = -ENOENT;
-		goto unlock;
-	}
+	if (&obj->base == NULL)
+		return -ENOENT;
 
-	/* Count all active objects as busy, even if they are currently not used
-	 * by the gpu. Users of this interface expect objects to eventually
-	 * become non-busy without any further actions, therefore emit any
-	 * necessary flushes here.
-	 */
-	ret = i915_gem_object_flush_active(obj);
-	if (ret)
-		goto unref;
+	args->busy = 0;
+	if (obj->active) { /* XXX READ_ONCE(obj->flags) */
+		struct drm_i915_gem_request *req;
+		int i;
 
-	BUILD_BUG_ON(I915_NUM_RINGS > 16);
-	args->busy = obj->active << 16;
-	if (obj->last_write.request)
-		args->busy |= obj->last_write.request->engine->id;
+		BUILD_BUG_ON(I915_NUM_RINGS > 16);
+		rcu_read_lock();
+		for (i = 0; i < I915_NUM_RINGS; i++) {
+			req = i915_gem_active_get_request_rcu(&obj->last_read[i]);
+			if (req == NULL)
+				continue;
 
-unref:
-	drm_gem_object_unreference(&obj->base);
-unlock:
-	mutex_unlock(&dev->struct_mutex);
-	return ret;
+			if (i915_gem_request_completed(req))
+				args->busy |= 1 << (16 + i);
+			i915_gem_request_put(req);
+		}
+
+		req = i915_gem_active_get_request_rcu(&obj->last_write);
+		if (req) {
+			args->busy |= req->engine->id;
+			i915_gem_request_put(req);
+		}
+		rcu_read_unlock();
+	}
+
+	drm_gem_object_unreference_unlocked(&obj->base);
+	return 0;
 }
 
 int
-- 
2.6.4



More information about the Intel-gfx mailing list