Commit 6c41f302 authored by Christian König's avatar Christian König Committed by Alex Deucher

drm/ttm: make unlocking in ttm_bo_cleanup_refs optional v3

Needed for the next patch.

v2: actually predicate all unlocks
v3: add some cleanups suggested by Michel.
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-and-Tested-by: default avatarMichel Dänzer <michel.daenzer@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 2a06e0a5
...@@ -486,20 +486,21 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo) ...@@ -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 bo idle, remove from delayed- and lru lists, and unref.
* If not idle, do nothing. * If not idle, do nothing.
* *
* Must be called with lru_lock and reservation held, this function * 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. * @interruptible Any sleeps should occur interruptibly.
* @no_wait_gpu Never wait for gpu. Return -EBUSY instead. * @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, static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
bool interruptible, bool interruptible, bool no_wait_gpu,
bool no_wait_gpu) bool unlock_resv)
{ {
struct ttm_bo_global *glob = bo->glob; struct ttm_bo_global *glob = bo->glob;
struct reservation_object *resv; struct reservation_object *resv;
...@@ -518,6 +519,7 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo, ...@@ -518,6 +519,7 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,
if (ret && !no_wait_gpu) { if (ret && !no_wait_gpu) {
long lret; long lret;
if (unlock_resv)
reservation_object_unlock(bo->resv); reservation_object_unlock(bo->resv);
spin_unlock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
...@@ -531,8 +533,7 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo, ...@@ -531,8 +533,7 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,
return -EBUSY; return -EBUSY;
spin_lock(&glob->lru_lock); spin_lock(&glob->lru_lock);
ret = reservation_object_trylock(bo->resv) ? 0 : -EBUSY; if (unlock_resv && !reservation_object_trylock(bo->resv)) {
/* /*
* We raced, and lost, someone else holds the reservation now, * We raced, and lost, someone else holds the reservation now,
* and is probably busy in ttm_bo_cleanup_memtype_use. * and is probably busy in ttm_bo_cleanup_memtype_use.
...@@ -541,13 +542,14 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo, ...@@ -541,13 +542,14 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,
* delayed destruction would succeed, so just return success * delayed destruction would succeed, so just return success
* here. * here.
*/ */
if (ret) {
spin_unlock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
return 0; return 0;
} }
ret = 0;
} }
if (ret || unlikely(list_empty(&bo->ddestroy))) { if (ret || unlikely(list_empty(&bo->ddestroy))) {
if (unlock_resv)
reservation_object_unlock(bo->resv); reservation_object_unlock(bo->resv);
spin_unlock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
return ret; return ret;
...@@ -559,6 +561,8 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo, ...@@ -559,6 +561,8 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,
spin_unlock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
ttm_bo_cleanup_memtype_use(bo); ttm_bo_cleanup_memtype_use(bo);
if (unlock_resv)
reservation_object_unlock(bo->resv); reservation_object_unlock(bo->resv);
return 0; return 0;
...@@ -600,8 +604,8 @@ static int ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all) ...@@ -600,8 +604,8 @@ static int ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all)
} }
if (!ret) if (!ret)
ret = ttm_bo_cleanup_refs_and_unlock(entry, false, ret = ttm_bo_cleanup_refs(entry, false, !remove_all,
!remove_all); true);
else else
spin_unlock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
...@@ -770,8 +774,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, ...@@ -770,8 +774,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
kref_get(&bo->list_kref); kref_get(&bo->list_kref);
if (!list_empty(&bo->ddestroy)) { if (!list_empty(&bo->ddestroy)) {
ret = ttm_bo_cleanup_refs_and_unlock(bo, interruptible, ret = ttm_bo_cleanup_refs(bo, interruptible, no_wait_gpu, true);
no_wait_gpu);
kref_put(&bo->list_kref, ttm_bo_release_list); kref_put(&bo->list_kref, ttm_bo_release_list);
return ret; return ret;
} }
...@@ -1735,7 +1738,7 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink) ...@@ -1735,7 +1738,7 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)
kref_get(&bo->list_kref); kref_get(&bo->list_kref);
if (!list_empty(&bo->ddestroy)) { 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); kref_put(&bo->list_kref, ttm_bo_release_list);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment