]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/ttm: use ttm_resource_unevictable() to replace pin_count and swapped
authorZhaoyu Liu <liuzhaoyu.zackary@bytedance.com>
Sun, 26 Jan 2025 09:32:56 +0000 (17:32 +0800)
committerChristian König <christian.koenig@amd.com>
Mon, 10 Feb 2025 12:39:03 +0000 (13:39 +0100)
TTM always uses pin_count and ttm_resource_is_swapped() together to
determine whether a BO is unevictable.
Now use ttm_resource_unevictable() to replace them.

Signed-off-by: Zhaoyu Liu <liuzhaoyu.zackary@bytedance.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250126093256.GA688734@bytedance
Signed-off-by: Christian König <christian.koenig@amd.com>
drivers/gpu/drm/ttm/ttm_resource.c

index 1644beb7a745919bbdcc9ab94f35a0bc76dc77e5..7e5a60c5581396cf321ba45fe3acbe3cbfc4e8b0 100644 (file)
@@ -269,11 +269,16 @@ static bool ttm_resource_is_swapped(struct ttm_resource *res, struct ttm_buffer_
        return ttm_tt_is_swapped(bo->ttm);
 }
 
+static bool ttm_resource_unevictable(struct ttm_resource *res, struct ttm_buffer_object *bo)
+{
+       return bo->pin_count || ttm_resource_is_swapped(res, bo);
+}
+
 /* Add the resource to a bulk move if the BO is configured for it */
 void ttm_resource_add_bulk_move(struct ttm_resource *res,
                                struct ttm_buffer_object *bo)
 {
-       if (bo->bulk_move && !bo->pin_count && !ttm_resource_is_swapped(res, bo))
+       if (bo->bulk_move && !ttm_resource_unevictable(res, bo))
                ttm_lru_bulk_move_add(bo->bulk_move, res);
 }
 
@@ -281,7 +286,7 @@ void ttm_resource_add_bulk_move(struct ttm_resource *res,
 void ttm_resource_del_bulk_move(struct ttm_resource *res,
                                struct ttm_buffer_object *bo)
 {
-       if (bo->bulk_move && !bo->pin_count && !ttm_resource_is_swapped(res, bo))
+       if (bo->bulk_move && !ttm_resource_unevictable(res, bo))
                ttm_lru_bulk_move_del(bo->bulk_move, res);
 }
 
@@ -293,10 +298,10 @@ void ttm_resource_move_to_lru_tail(struct ttm_resource *res)
 
        lockdep_assert_held(&bo->bdev->lru_lock);
 
-       if (bo->pin_count || ttm_resource_is_swapped(res, bo)) {
+       if (ttm_resource_unevictable(res, bo)) {
                list_move_tail(&res->lru.link, &bdev->unevictable);
 
-       } else  if (bo->bulk_move) {
+       } else if (bo->bulk_move) {
                struct ttm_lru_bulk_move_pos *pos =
                        ttm_lru_bulk_move_pos(bo->bulk_move, res);
 
@@ -335,7 +340,7 @@ void ttm_resource_init(struct ttm_buffer_object *bo,
 
        man = ttm_manager_type(bo->bdev, place->mem_type);
        spin_lock(&bo->bdev->lru_lock);
-       if (bo->pin_count || ttm_resource_is_swapped(res, bo))
+       if (ttm_resource_unevictable(res, bo))
                list_add_tail(&res->lru.link, &bo->bdev->unevictable);
        else
                list_add_tail(&res->lru.link, &man->lru[bo->priority]);