aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoger He <Hongbo.He@amd.com>2017-12-21 04:42:52 -0500
committerAlex Deucher <alexander.deucher@amd.com>2017-12-28 09:48:20 -0500
commitd5769ba315d8ffcf6eeb90b6d7c99d3143547ddb (patch)
treea5c2b53415d9f7369bcf10bb689292a91d95c58c
parent993baf15560d2e8153f715cec677e6576b35662e (diff)
drm/ttm: add new function to check if bo is allowable to evict or swapout
extract a function as ttm_bo_evict_swapout_allowable since eviction and swapout can share same logic. v2: modify commit message and add description in the code Reviewed-by: Thomas Hellström <thellstrom@vmware.com> Reviewed-by: Christian König <christian.koenig@amd.com> Reviewed-by: Chuming Zhou <david1.zhou@amd.com> Signed-off-by: Roger He <Hongbo.He@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index b3a71acad6a8..ac2ab20ba9b2 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -708,6 +708,34 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
708} 708}
709EXPORT_SYMBOL(ttm_bo_eviction_valuable); 709EXPORT_SYMBOL(ttm_bo_eviction_valuable);
710 710
711/**
712 * Check the target bo is allowable to be evicted or swapout, including cases:
713 *
714 * a. if share same reservation object with ctx->resv, have assumption
715 * reservation objects should already be locked, so not lock again and
716 * return true directly when either the opreation allow_reserved_eviction
717 * or the target bo already is in delayed free list;
718 *
719 * b. Otherwise, trylock it.
720 */
721static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo,
722 struct ttm_operation_ctx *ctx, bool *locked)
723{
724 bool ret = false;
725
726 *locked = false;
727 if (bo->resv == ctx->resv) {
728 reservation_object_assert_held(bo->resv);
729 if (ctx->allow_reserved_eviction || !list_empty(&bo->ddestroy))
730 ret = true;
731 } else {
732 *locked = reservation_object_trylock(bo->resv);
733 ret = *locked;
734 }
735
736 return ret;
737}
738
711static int ttm_mem_evict_first(struct ttm_bo_device *bdev, 739static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
712 uint32_t mem_type, 740 uint32_t mem_type,
713 const struct ttm_place *place, 741 const struct ttm_place *place,
@@ -723,21 +751,13 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
723 spin_lock(&glob->lru_lock); 751 spin_lock(&glob->lru_lock);
724 for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { 752 for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
725 list_for_each_entry(bo, &man->lru[i], lru) { 753 list_for_each_entry(bo, &man->lru[i], lru) {
726 if (bo->resv == ctx->resv) { 754 if (!ttm_bo_evict_swapout_allowable(bo, ctx, &locked))
727 if (!ctx->allow_reserved_eviction && 755 continue;
728 list_empty(&bo->ddestroy))
729 continue;
730 } else {
731 locked = reservation_object_trylock(bo->resv);
732 if (!locked)
733 continue;
734 }
735 756
736 if (place && !bdev->driver->eviction_valuable(bo, 757 if (place && !bdev->driver->eviction_valuable(bo,
737 place)) { 758 place)) {
738 if (locked) 759 if (locked)
739 reservation_object_unlock(bo->resv); 760 reservation_object_unlock(bo->resv);
740 locked = false;
741 continue; 761 continue;
742 } 762 }
743 break; 763 break;