>From 61174dd44618bbfcb035484a44435b7ed4df86a5 Mon Sep 17 00:00:00 2001 From: Chunming Zhou Date: Wed, 24 Apr 2019 11:35:29 +0800 Subject: [PATCH] drm/amdgpu: wait memory idle when fb is pinned fail heavy gpu job execution could occupy memory long time, which could lead to other user fail to get memory. Change-Id: I3857c4b99859c9d2f354cf2c486dbacb8520d0ed Signed-off-by: Chunming Zhou --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index a5cacf846e1b..8577b629a640 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -4093,6 +4093,8 @@ static const struct drm_plane_funcs dm_plane_funcs = { .atomic_destroy_state = dm_drm_plane_destroy_state, }; +/* 100s default to wait for pin fb */ +#define DM_PIN_MEM_TIMEOUT 100000000000ULL static int dm_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_state *new_state) { @@ -4103,6 +4105,7 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane, struct dm_plane_state *dm_plane_state_new, *dm_plane_state_old; uint64_t tiling_flags; uint32_t domain; + u64 timeout = nsecs_to_jiffies64(DM_PIN_MEM_TIMEOUT); int r; dm_plane_state_old = to_dm_plane_state(plane->state); @@ -4117,6 +4120,8 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane, obj = new_state->fb->obj[0]; rbo = gem_to_amdgpu_bo(obj); adev = amdgpu_ttm_adev(rbo->tbo.bdev); + +retry: r = amdgpu_bo_reserve(rbo, false); if (unlikely(r != 0)) return r; @@ -4131,8 +4136,18 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane, if (r != -ERESTARTSYS) DRM_ERROR("Failed to pin framebuffer with error %d\n", r); amdgpu_bo_unreserve(rbo); + if (r == -ENOMEM) { + set_current_state(TASK_INTERRUPTIBLE); + if (timeout == 0) + return r; + if (signal_pending(current)) + return r; + timeout = schedule_timeout(timeout); + goto retry; + } return r; } + __set_current_state(TASK_RUNNING); r = amdgpu_ttm_alloc_gart(&rbo->tbo); if (unlikely(r != 0)) { -- 2.17.1