Skip to contentSkip to conversation

drm/ttm: remove allow_errors from ttm_bo_force_list_clean

PATCH In review Christian König 2 participants 3 messages Jul 5, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/ttm: remove allow_errors from ttm_bo_force_list_clean

From: Christian König <[email protected]>

That is completely nonsense. If we blindly continue we would end up in an endless loop trying to evict the same BOs over and over again.

---
 drivers/gpu/drm/ttm/ttm_bo.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +9 -17
index e340d0d6..66c50ad 100644
@@ -1283,7 +1283,7 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
 EXPORT_SYMBOL(ttm_bo_create);
 
 static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
-					unsigned mem_type, bool allow_errors)
+				   unsigned mem_type)
 {
 	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
 	struct ttm_bo_global *glob = bdev->glob;
@@ -1298,13 +1298,8 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
 	while (!list_empty(&man->lru)) {
 		spin_unlock(&glob->lru_lock);
 		ret = ttm_mem_evict_first(bdev, mem_type, NULL, false, false);
-		if (ret) {
-			if (allow_errors) {
-				return ret;
-			} else {
-				pr_err("Cleanup eviction failed\n");
-			}
-		}
+		if (ret)
+			return ret;
 		spin_lock(&glob->lru_lock);
 	}
 	spin_unlock(&glob->lru_lock);
@@ -1316,13 +1311,8 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
 	if (fence) {
 		ret = fence_wait(fence, false);
 		fence_put(fence);
-		if (ret) {
-			if (allow_errors) {
-				return ret;
-			} else {
-				pr_err("Cleanup eviction failed\n");
-			}
-		}
+		if (ret)
+			return ret;
 	}
 
 	return 0;
@@ -1351,7 +1341,9 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 
 	ret = 0;
 	if (mem_type > 0) {
-		ttm_bo_force_list_clean(bdev, mem_type, false);
+		ret = ttm_bo_force_list_clean(bdev, mem_type);
+		if (ret)
+			pr_err("Cleanup eviction failed (%d)\n", ret);
 
 		ret = (*man->func->takedown)(man);
 	}
@@ -1374,7 +1366,7 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 		return 0;
 	}
 
-	return ttm_bo_force_list_clean(bdev, mem_type, true);
+	return ttm_bo_force_list_clean(bdev, mem_type);
 }
 EXPORT_SYMBOL(ttm_bo_evict_mm);
 
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/2 drm/ttm: use RCU to pipeline evictions

From: Christian König <[email protected]>

Could be faster on the read path.

---
 drivers/gpu/drm/ttm/ttm_bo.c      | 16 ++++++++++------
 drivers/gpu/drm/ttm/ttm_bo_util.c |  8 +++++---
 2 files changed, 15 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +10 -6
index 66c50ad..7e30f3b 100644
@@ -797,9 +797,11 @@ static int ttm_bo_add_move_fence(struct ttm_buffer_object *bo,
 	struct fence *fence;
 	int ret;
 
-	spin_lock(&man->move_lock);
-	fence = fence_get(man->move);
-	spin_unlock(&man->move_lock);
+	rcu_read_lock();
+	do
+		fence = rcu_dereference(man->move);
+	while (unlikely(fence && !fence_get_rcu(fence)));
+	rcu_read_unlock();
 
 	if (fence) {
 		reservation_object_add_shared_fence(bo->resv, fence);
@@ -1304,9 +1306,11 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
 	}
 	spin_unlock(&glob->lru_lock);
 
-	spin_lock(&man->move_lock);
-	fence = fence_get(man->move);
-	spin_unlock(&man->move_lock);
+	rcu_read_lock();
+	do
+		fence = rcu_dereference(man->move);
+	while (unlikely(fence && !fence_get_rcu(fence)));
+	rcu_read_unlock();
 
 	if (fence) {
 		ret = fence_wait(fence, false);
drivers/gpu/drm/ttm/ttm_bo_util.c +5 -3
index 4da0e78..fcd2431 100644
@@ -746,6 +746,7 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
 		ttm_bo_unref(&ghost_obj);
 
 	} else if (from->flags & TTM_MEMTYPE_FLAG_FIXED) {
+		struct fence *old;
 
 		/**
 		 * BO doesn't have a TTM we need to bind/unbind. Just remember
@@ -753,9 +754,10 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
 		 */
 
 		spin_lock(&from->move_lock);
-		if (!from->move || fence_is_later(fence, from->move)) {
-			fence_put(from->move);
-			from->move = fence_get(fence);
+		old = rcu_dereference_protected(from->move, 1);
+		if (!old || fence_is_later(fence, old)) {
+			rcu_assign_pointer(from->move, fence_get(fence));
+			fence_put(old);
 		}
 		spin_unlock(&from->move_lock);
 
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/ttm: use RCU to pipeline evictions

Quoted 5 lines · Christian König

From: Christian König <[email protected]>

Could be faster on the read path.

Just one style nit pick below. Beyond that, the series is:

Quoted 10 lines
---
 drivers/gpu/drm/ttm/ttm_bo.c      | 16 ++++++++++------
 drivers/gpu/drm/ttm/ttm_bo_util.c |  8 +++++---
 2 files changed, 15 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
index 66c50ad..7e30f3b 100644

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_add_move_fence(struct ttm_buffer_object *bo, · line 803

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +4 -3
@@ -797,9 +797,11 @@ static int ttm_bo_add_move_fence(struct ttm_buffer_object *bo,
        struct fence *fence;
        int ret;
 
-       spin_lock(&man->move_lock);
-       fence = fence_get(man->move);
-       spin_unlock(&man->move_lock);
+       rcu_read_lock();
+       do
+               fence = rcu_dereference(man->move);
+       while (unlikely(fence && !fence_get_rcu(fence)));

I generally like to see parens with do/while loops.

Quoted 5 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
+       rcu_read_unlock();
 
        if (fence) {
                reservation_object_add_shared_fence(bo->resv, fence);

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev, · line 1312

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +4 -3
@@ -1304,9 +1306,11 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
        }
        spin_unlock(&glob->lru_lock);
 
-       spin_lock(&man->move_lock);
-       fence = fence_get(man->move);
-       spin_unlock(&man->move_lock);
+       rcu_read_lock();
+       do
+               fence = rcu_dereference(man->move);
+       while (unlikely(fence && !fence_get_rcu(fence)));

Same here.

Quoted 33 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
+       rcu_read_unlock();
 
        if (fence) {
                ret = fence_wait(fence, false);
drivers/gpu/drm/ttm/ttm_bo_util.c +5 -4
index 4da0e78..fcd2431 100644
@@ -746,6 +746,7 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
                ttm_bo_unref(&ghost_obj);
 
        } else if (from->flags & TTM_MEMTYPE_FLAG_FIXED) {
+               struct fence *old;
 
                /**
                 * BO doesn't have a TTM we need to bind/unbind. Just remember
@@ -753,9 +754,10 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
                 */
 
                spin_lock(&from->move_lock);
-               if (!from->move || fence_is_later(fence, from->move)) {
-                       fence_put(from->move);
-                       from->move = fence_get(fence);
+               old = rcu_dereference_protected(from->move, 1);
+               if (!old || fence_is_later(fence, old)) {
+                       rcu_assign_pointer(from->move, fence_get(fence));
+                       fence_put(old);
                }
                spin_unlock(&from->move_lock);
 
--

2.5.0

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel