aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoger He <Hongbo.He@amd.com>2017-12-21 04:42:53 -0500
committerAlex Deucher <alexander.deucher@amd.com>2017-12-28 09:48:20 -0500
commitdc947770cf3400dd07ed2e2b7b9acb4f96d5137f (patch)
tree1b9a022f5a9719be858af07e69d747468844de06
parentd5769ba315d8ffcf6eeb90b6d7c99d3143547ddb (diff)
drm/ttm: enable swapout for reserved BOs during allocation
if the bo shares same reservation object then not lock it again at swapout time to make it possible to swap out. v2: refine the commmit message 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.c15
-rw-r--r--drivers/gpu/drm/ttm/ttm_memory.c12
-rw-r--r--include/drm/ttm/ttm_bo_api.h3
3 files changed, 21 insertions, 9 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index ac2ab20ba9b2..2eb71ffe95a6 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1699,18 +1699,20 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);
1699 * A buffer object shrink method that tries to swap out the first 1699 * A buffer object shrink method that tries to swap out the first
1700 * buffer object on the bo_global::swap_lru list. 1700 * buffer object on the bo_global::swap_lru list.
1701 */ 1701 */
1702int ttm_bo_swapout(struct ttm_bo_global *glob) 1702int ttm_bo_swapout(struct ttm_bo_global *glob, struct ttm_operation_ctx *ctx)
1703{ 1703{
1704 struct ttm_buffer_object *bo; 1704 struct ttm_buffer_object *bo;
1705 int ret = -EBUSY; 1705 int ret = -EBUSY;
1706 bool locked;
1706 unsigned i; 1707 unsigned i;
1707 1708
1708 spin_lock(&glob->lru_lock); 1709 spin_lock(&glob->lru_lock);
1709 for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { 1710 for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
1710 list_for_each_entry(bo, &glob->swap_lru[i], swap) { 1711 list_for_each_entry(bo, &glob->swap_lru[i], swap) {
1711 ret = reservation_object_trylock(bo->resv) ? 0 : -EBUSY; 1712 if (ttm_bo_evict_swapout_allowable(bo, ctx, &locked)) {
1712 if (!ret) 1713 ret = 0;
1713 break; 1714 break;
1715 }
1714 } 1716 }
1715 if (!ret) 1717 if (!ret)
1716 break; 1718 break;
@@ -1786,7 +1788,12 @@ EXPORT_SYMBOL(ttm_bo_swapout);
1786 1788
1787void ttm_bo_swapout_all(struct ttm_bo_device *bdev) 1789void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
1788{ 1790{
1789 while (ttm_bo_swapout(bdev->glob) == 0) 1791 struct ttm_operation_ctx ctx = {
1792 .interruptible = false,
1793 .no_wait_gpu = false
1794 };
1795
1796 while (ttm_bo_swapout(bdev->glob, &ctx) == 0)
1790 ; 1797 ;
1791} 1798}
1792EXPORT_SYMBOL(ttm_bo_swapout_all); 1799EXPORT_SYMBOL(ttm_bo_swapout_all);
diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
index 102b326d3c42..aa0c38136958 100644
--- a/drivers/gpu/drm/ttm/ttm_memory.c
+++ b/drivers/gpu/drm/ttm/ttm_memory.c
@@ -211,7 +211,7 @@ static bool ttm_zones_above_swap_target(struct ttm_mem_global *glob,
211 */ 211 */
212 212
213static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq, 213static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
214 uint64_t extra) 214 uint64_t extra, struct ttm_operation_ctx *ctx)
215{ 215{
216 int ret; 216 int ret;
217 217
@@ -219,7 +219,7 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
219 219
220 while (ttm_zones_above_swap_target(glob, from_wq, extra)) { 220 while (ttm_zones_above_swap_target(glob, from_wq, extra)) {
221 spin_unlock(&glob->lock); 221 spin_unlock(&glob->lock);
222 ret = ttm_bo_swapout(glob->bo_glob); 222 ret = ttm_bo_swapout(glob->bo_glob, ctx);
223 spin_lock(&glob->lock); 223 spin_lock(&glob->lock);
224 if (unlikely(ret != 0)) 224 if (unlikely(ret != 0))
225 break; 225 break;
@@ -230,10 +230,14 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
230 230
231static void ttm_shrink_work(struct work_struct *work) 231static void ttm_shrink_work(struct work_struct *work)
232{ 232{
233 struct ttm_operation_ctx ctx = {
234 .interruptible = false,
235 .no_wait_gpu = false
236 };
233 struct ttm_mem_global *glob = 237 struct ttm_mem_global *glob =
234 container_of(work, struct ttm_mem_global, work); 238 container_of(work, struct ttm_mem_global, work);
235 239
236 ttm_shrink(glob, true, 0ULL); 240 ttm_shrink(glob, true, 0ULL, &ctx);
237} 241}
238 242
239static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob, 243static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
@@ -520,7 +524,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
520 return -ENOMEM; 524 return -ENOMEM;
521 if (unlikely(count-- == 0)) 525 if (unlikely(count-- == 0))
522 return -ENOMEM; 526 return -ENOMEM;
523 ttm_shrink(glob, false, memory + (memory >> 2) + 16); 527 ttm_shrink(glob, false, memory + (memory >> 2) + 16, ctx);
524 } 528 }
525 529
526 return 0; 530 return 0;
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 24a8db7bebb1..f1c74c22248b 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -752,7 +752,8 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
752 const char __user *wbuf, char __user *rbuf, 752 const char __user *wbuf, char __user *rbuf,
753 size_t count, loff_t *f_pos, bool write); 753 size_t count, loff_t *f_pos, bool write);
754 754
755int ttm_bo_swapout(struct ttm_bo_global *glob); 755int ttm_bo_swapout(struct ttm_bo_global *glob,
756 struct ttm_operation_ctx *ctx);
756void ttm_bo_swapout_all(struct ttm_bo_device *bdev); 757void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
757int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo); 758int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
758#endif 759#endif