[PATCH 6/7] drm/ttm: use ttm_bo_lru_for_each_reserved_guarded in evict_all
Christian König
ckoenig.leichtzumerken at gmail.com
Wed Jul 16 16:04:25 UTC 2025
Use the for_each loop to evict all BOs of an resource manager as well.
Greately simplifying the handling and finally allows us to
remove ttm_bo_evict_first().
Signed-off-by: Christian König <christian.koenig at amd.com>
---
drivers/gpu/drm/ttm/ttm_bo.c | 51 +-----------------------------
drivers/gpu/drm/ttm/ttm_resource.c | 17 ++++++----
include/drm/ttm/ttm_bo.h | 1 +
3 files changed, 13 insertions(+), 56 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 87e81e36bbd4..5d5fffcf16c0 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -359,8 +359,7 @@ static int ttm_bo_bounce_temp_buffer(struct ttm_buffer_object *bo,
return 0;
}
-static int ttm_bo_evict(struct ttm_buffer_object *bo,
- struct ttm_operation_ctx *ctx)
+int ttm_bo_evict(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx)
{
struct ttm_device *bdev = bo->bdev;
struct ttm_resource *evict_mem;
@@ -446,54 +445,6 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
}
EXPORT_SYMBOL(ttm_bo_eviction_valuable);
-/**
- * ttm_bo_evict_first() - Evict the first bo on the manager's LRU list.
- * @bdev: The ttm device.
- * @man: The manager whose bo to evict.
- * @ctx: The TTM operation ctx governing the eviction.
- *
- * Return: 0 if successful or the resource disappeared. Negative error code on error.
- */
-int ttm_bo_evict_first(struct ttm_device *bdev, struct ttm_resource_manager *man,
- struct ttm_operation_ctx *ctx)
-{
- struct ttm_resource_cursor cursor;
- struct ttm_buffer_object *bo;
- struct ttm_resource *res;
- unsigned int mem_type;
- int ret = 0;
-
- spin_lock(&bdev->lru_lock);
- ttm_resource_cursor_init(&cursor, man);
- res = ttm_resource_manager_first(&cursor);
- ttm_resource_cursor_fini(&cursor);
- if (!res) {
- ret = -ENOENT;
- goto out_no_ref;
- }
- bo = res->bo;
- if (!ttm_bo_get_unless_zero(bo))
- goto out_no_ref;
- mem_type = res->mem_type;
- spin_unlock(&bdev->lru_lock);
- ret = ttm_bo_reserve(bo, ctx->interruptible, ctx->no_wait_gpu, NULL);
- if (ret)
- goto out_no_lock;
- if (!bo->resource || bo->resource->mem_type != mem_type)
- goto out_bo_moved;
-
- ret = ttm_bo_evict(bo, ctx);
-out_bo_moved:
- dma_resv_unlock(bo->base.resv);
-out_no_lock:
- ttm_bo_put(bo);
- return ret;
-
-out_no_ref:
- spin_unlock(&bdev->lru_lock);
- return ret;
-}
-
/**
* struct ttm_bo_evict_walk - Parameters for the evict walk.
*/
diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index e2c82ad07eb4..9ee5a9f444f0 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -546,20 +546,25 @@ EXPORT_SYMBOL(ttm_resource_manager_init);
int ttm_resource_manager_evict_all(struct ttm_device *bdev,
struct ttm_resource_manager *man)
{
+ struct ttm_bo_lru_cursor cursor;
+ struct ttm_buffer_object *bo;
struct ttm_operation_ctx ctx = {
.interruptible = false,
.no_wait_gpu = false,
};
+ struct ttm_lru_walk_arg arg = {
+ .ctx = &ctx,
+ .trylock_only = true
+ };
struct dma_fence *fence;
int ret;
- do {
- ret = ttm_bo_evict_first(bdev, man, &ctx);
+ ttm_bo_lru_for_each_reserved_guarded(&cursor, man, &arg, bo) {
+ ret = ttm_bo_evict(bo, &ctx);
+ if (ret)
+ return ret;
cond_resched();
- } while (!ret);
-
- if (ret && ret != -ENOENT)
- return ret;
+ }
spin_lock(&man->move_lock);
fence = dma_fence_get(man->move);
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 6e85f9e207ad..2eaed0780d21 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -379,6 +379,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
void ttm_bo_fini(struct ttm_buffer_object *bo);
void ttm_bo_set_bulk_move(struct ttm_buffer_object *bo,
struct ttm_lru_bulk_move *bulk);
+int ttm_bo_evict(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx);
bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
const struct ttm_place *place);
int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo,
--
2.43.0
More information about the Intel-xe
mailing list