drm/ttm: make unlocking in ttm_bo_cleanup_refs optional v2
Subsystems (3)
PATCH 1/2 drm/ttm: make unlocking in ttm_bo_cleanup_refs optional v2
Needed for the next patch.
v2: actually predicate all unlocks
Signed-off-by Christian König <[email protected]>
--- drivers/gpu/drm/ttm/ttm_bo.c | 59 +++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 26 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +33 -26
@@ -486,20 +486,21 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo) }/** -* function ttm_bo_cleanup_refs_and_unlock +* function ttm_bo_cleanup_refs * If bo idle, remove from delayed- and lru lists, and unref. * If not idle, do nothing. * * Must be called with lru_lock and reservation held, this function -* will drop both before returning. +* will drop the lru lock and optionally the reservation lock before returning. * * @interruptible Any sleeps should occur interruptibly. * @no_wait_gpu Never wait for gpu. Return -EBUSY instead. +* @unlock_resv Unlock the reservation lock as well. */ -static int ttm_bo_cleanup_refs_and_unlock (struct ttm_buffer_object *bo, -bool interruptible, -bool no_wait_gpu) +static int ttm_bo_cleanup_refs (struct ttm_buffer_object *bo, +bool interruptible,bool no_wait_gpu, +bool unlock_resv) {struct ttm_bo_global *glob = bo->glob;struct reservation_object *resv;
@@ -518,7 +519,8 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,if (ret && !no_wait_gpu) {long lret; -reservation_object_unlock (bo->resv); +if (unlock_resv) +reservation_object_unlock (bo->resv);spin_unlock (&glob->lru_lock); lret = reservation_object_wait_timeout_rcu(resv, true,
@@ -531,24 +533,28 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,return -EBUSY ;spin_lock (&glob->lru_lock); - ret =reservation_object_trylock (bo->resv) ?0 : -EBUSY ; - -/* -* We raced, and lost, someone else holds the reservation now, -* and is probably busy in ttm_bo_cleanup_memtype_use. -* -* Even if it's not the case, because we finished waiting any -* delayed destruction would succeed, so just return success -* here. -*/ -if (ret) { -spin_unlock (&glob->lru_lock); -return 0 ; +if (unlock_resv) { + ret =reservation_object_trylock (bo->resv) ?0 : -EBUSY ; +/* +* We raced, and lost, someone else holds the reservation now, +* and is probably busy in ttm_bo_cleanup_memtype_use. +* +* Even if it's not the case, because we finished waiting any +* delayed destruction would succeed, so just return success +* here. +*/ +if (ret) { +spin_unlock (&glob->lru_lock); +return 0 ; + } + }else { + ret =0 ; } }if (ret ||unlikely (list_empty (&bo->ddestroy))) { -reservation_object_unlock (bo->resv); +if (unlock_resv) +reservation_object_unlock (bo->resv);spin_unlock (&glob->lru_lock);return ret; }
@@ -559,7 +565,9 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,spin_unlock (&glob->lru_lock);ttm_bo_cleanup_memtype_use (bo); -reservation_object_unlock (bo->resv); + +if (unlock_resv) +reservation_object_unlock (bo->resv);return 0 ; }
@@ -600,8 +608,8 @@ static int ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all) }if (!ret) - ret =ttm_bo_cleanup_refs_and_unlock (entry, false, - !remove_all); + ret =ttm_bo_cleanup_refs (entry, false, !remove_all, + true);else spin_unlock (&glob->lru_lock);
@@ -770,8 +778,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,kref_get (&bo->list_kref);if (!list_empty (&bo->ddestroy)) { - ret =ttm_bo_cleanup_refs_and_unlock (bo, interruptible, - no_wait_gpu); + ret =ttm_bo_cleanup_refs (bo, interruptible, no_wait_gpu, true);kref_put (&bo->list_kref, ttm_bo_release_list);return ret; }
@@ -1735,7 +1742,7 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)kref_get (&bo->list_kref);if (!list_empty (&bo->ddestroy)) { - ret =ttm_bo_cleanup_refs_and_unlock (bo, false, false); + ret =ttm_bo_cleanup_refs (bo, false, false, true);kref_put (&bo->list_kref, ttm_bo_release_list);return ret; }
Signature · 6 lines
2.11.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20171112153120.16028-1-christian.koenig-5C7GfCeVMHo@public.gmane.org
PATCH 2/2 drm/ttm: optimize ttm_mem_evict_first v3
Deleted BOs with the same reservation object can be reaped even if they can't be reserved.
v2: rebase and we still need to remove/add the BO from/to the LRU.
v3: fix remove/add one more time, cleanup the logic a bit
Signed-off-by Christian König <[email protected]>
--- drivers/gpu/drm/ttm/ttm_bo.c | 55 +++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 21 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +34 -21
@@ -738,47 +738,58 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,EXPORT_SYMBOL (ttm_bo_eviction_valuable);static int ttm_mem_evict_first (struct ttm_bo_device *bdev, -uint32_t mem_type, -const struct ttm_place *place, -bool interruptible, -bool no_wait_gpu) +struct reservation_object *resv, +uint32_t mem_type, +const struct ttm_place *place, +bool interruptible, +bool no_wait_gpu) {struct ttm_bo_global *glob = bdev->glob;struct ttm_mem_type_manager *man = &bdev->man[mem_type]; -struct ttm_buffer_object *bo; -int ret = -EBUSY ; +struct ttm_buffer_object *bo =NULL ; +bool locked = false;unsigned i; +int ret;spin_lock (&glob->lru_lock);for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {list_for_each_entry (bo, &man->lru[i], lru) { - ret =reservation_object_trylock (bo->resv) ?0 : -EBUSY ; -if (ret) -continue ; +if (bo->resv == resv) { +if (list_empty (&bo->ddestroy)) +continue ; + +break ; + }else { + locked =reservation_object_trylock (bo->resv); +if (!locked) +continue ; + }if (place && !bdev->driver->eviction_valuable (bo, place)) { -reservation_object_unlock (bo->resv); - ret = -EBUSY ; +if (locked) +reservation_object_unlock (bo->resv);continue ; } -break ; } -if (!ret) +if (&bo->lru != &man->lru[i])break ; +else + bo =NULL ; } -if (ret) { +if (!bo) {spin_unlock (&glob->lru_lock); -return ret; +return -EBUSY ; }kref_get (&bo->list_kref);if (!list_empty (&bo->ddestroy)) { - ret =ttm_bo_cleanup_refs (bo, interruptible, no_wait_gpu, true); + ret =ttm_bo_cleanup_refs (bo, interruptible, no_wait_gpu, + locked);kref_put (&bo->list_kref, ttm_bo_release_list);return ret; }
@@ -786,10 +797,11 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,ttm_bo_del_from_lru (bo);spin_unlock (&glob->lru_lock); -BUG_ON (ret !=0 ); - ret =ttm_bo_evict (bo, interruptible, no_wait_gpu); -ttm_bo_unreserve (bo); +if (locked) +ttm_bo_unreserve (bo); +else +ttm_bo_add_to_lru (bo);kref_put (&bo->list_kref, ttm_bo_release_list);return ret;
@@ -853,7 +865,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,return ret;if (mem->mm_node)break ; - ret =ttm_mem_evict_first (bdev, mem_type, place, + ret =ttm_mem_evict_first (bdev, bo->resv, mem_type, place, interruptible, no_wait_gpu);if (unlikely (ret !=0 ))return ret;
@@ -1356,7 +1368,8 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {while (!list_empty (&man->lru[i])) {spin_unlock (&glob->lru_lock); - ret =ttm_mem_evict_first (bdev, mem_type,NULL , false, false); + ret =ttm_mem_evict_first (bdev,NULL , mem_type,NULL , + false, false);if (ret)return ret;spin_lock (&glob->lru_lock);
Signature · 6 lines
2.11.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx