[PATCH 6/6] drm/vc4: use new ww_mutex_(un)lock_for_each macros

Christian König ckoenig.leichtzumerken at gmail.com
Fri Jun 14 12:41:25 UTC 2019


Use the provided macros instead of implementing deadlock handling on our own.

Signed-off-by: Christian König <christian.koenig at amd.com>
---
 drivers/gpu/drm/vc4/vc4_gem.c | 56 ++++++++---------------------------
 1 file changed, 13 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_gem.c b/drivers/gpu/drm/vc4/vc4_gem.c
index d9311be32a4f..628b3a8bcf6a 100644
--- a/drivers/gpu/drm/vc4/vc4_gem.c
+++ b/drivers/gpu/drm/vc4/vc4_gem.c
@@ -584,53 +584,17 @@ vc4_lock_bo_reservations(struct drm_device *dev,
 			 struct vc4_exec_info *exec,
 			 struct ww_acquire_ctx *acquire_ctx)
 {
-	int contended_lock = -1;
-	int i, ret;
+	struct ww_mutex *contended;
 	struct drm_gem_object *bo;
+	int i, ret;
 
 	ww_acquire_init(acquire_ctx, &reservation_ww_class);
 
-retry:
-	if (contended_lock != -1) {
-		bo = &exec->bo[contended_lock]->base;
-		ret = ww_mutex_lock_slow_interruptible(&bo->resv->lock,
-						       acquire_ctx);
-		if (ret) {
-			ww_acquire_done(acquire_ctx);
-			return ret;
-		}
-	}
-
-	for (i = 0; i < exec->bo_count; i++) {
-		if (i == contended_lock)
-			continue;
-
-		bo = &exec->bo[i]->base;
-
-		ret = ww_mutex_lock_interruptible(&bo->resv->lock, acquire_ctx);
-		if (ret) {
-			int j;
-
-			for (j = 0; j < i; j++) {
-				bo = &exec->bo[j]->base;
-				ww_mutex_unlock(&bo->resv->lock);
-			}
-
-			if (contended_lock != -1 && contended_lock >= i) {
-				bo = &exec->bo[contended_lock]->base;
-
-				ww_mutex_unlock(&bo->resv->lock);
-			}
-
-			if (ret == -EDEADLK) {
-				contended_lock = i;
-				goto retry;
-			}
-
-			ww_acquire_done(acquire_ctx);
-			return ret;
-		}
-	}
+	ww_mutex_lock_for_each(for (i = 0; i < exec->bo_count; i++),
+			       &exec->bo[i]->base.resv->lock, contended, ret,
+			       true, acquire_ctx)
+		if (ret)
+			goto error;
 
 	ww_acquire_done(acquire_ctx);
 
@@ -648,6 +612,12 @@ vc4_lock_bo_reservations(struct drm_device *dev,
 	}
 
 	return 0;
+
+error:
+	ww_mutex_unlock_for_each(for (i = 0; i < exec->bo_count; i++),
+				 &exec->bo[i]->base.resv->lock, contended);
+	ww_acquire_done(acquire_ctx);
+	return ret;
 }
 
 /* Queues a struct vc4_exec_info for execution.  If no job is
-- 
2.17.1



More information about the etnaviv mailing list