diff options
author | Christian König <christian.koenig@amd.com> | 2018-04-05 10:42:03 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2018-05-15 14:43:05 -0400 |
commit | 5422a28fe86f9f77480471385e0a416c27a9ca72 (patch) | |
tree | 3fda88b779e1f2505ee90ec61b9a369003e2038c /drivers/gpu/drm/amd/amdgpu | |
parent | f1018f50d48395b4a189bf8ea9af1e4441209cfd (diff) |
drm/amdgpu: fix and cleanup cpu visible VRAM handling
The detection if a BO was placed in CPU visible VRAM was incorrect.
Fix it and merge it with the correct detection in amdgpu_ttm.c
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Chunming Zhou <david1.zhou@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 21 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 19 |
3 files changed, 26 insertions, 20 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index de69ab12bb55..68af2f878bc9 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | |||
@@ -382,8 +382,7 @@ retry: | |||
382 | 382 | ||
383 | p->bytes_moved += ctx.bytes_moved; | 383 | p->bytes_moved += ctx.bytes_moved; |
384 | if (adev->gmc.visible_vram_size < adev->gmc.real_vram_size && | 384 | if (adev->gmc.visible_vram_size < adev->gmc.real_vram_size && |
385 | bo->tbo.mem.mem_type == TTM_PL_VRAM && | 385 | amdgpu_bo_in_cpu_visible_vram(bo)) |
386 | bo->tbo.mem.start < adev->gmc.visible_vram_size >> PAGE_SHIFT) | ||
387 | p->bytes_moved_vis += ctx.bytes_moved; | 386 | p->bytes_moved_vis += ctx.bytes_moved; |
388 | 387 | ||
389 | if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains && | 388 | if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains && |
@@ -437,8 +436,7 @@ static bool amdgpu_cs_try_evict(struct amdgpu_cs_parser *p, | |||
437 | /* Good we can try to move this BO somewhere else */ | 436 | /* Good we can try to move this BO somewhere else */ |
438 | update_bytes_moved_vis = | 437 | update_bytes_moved_vis = |
439 | adev->gmc.visible_vram_size < adev->gmc.real_vram_size && | 438 | adev->gmc.visible_vram_size < adev->gmc.real_vram_size && |
440 | bo->tbo.mem.mem_type == TTM_PL_VRAM && | 439 | amdgpu_bo_in_cpu_visible_vram(bo); |
441 | bo->tbo.mem.start < adev->gmc.visible_vram_size >> PAGE_SHIFT; | ||
442 | amdgpu_ttm_placement_from_domain(bo, other); | 440 | amdgpu_ttm_placement_from_domain(bo, other); |
443 | r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx); | 441 | r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx); |
444 | p->bytes_moved += ctx.bytes_moved; | 442 | p->bytes_moved += ctx.bytes_moved; |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h index 546f77cb7882..3bee13344065 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | |||
@@ -196,6 +196,27 @@ static inline bool amdgpu_bo_gpu_accessible(struct amdgpu_bo *bo) | |||
196 | } | 196 | } |
197 | 197 | ||
198 | /** | 198 | /** |
199 | * amdgpu_bo_in_cpu_visible_vram - check if BO is (partly) in visible VRAM | ||
200 | */ | ||
201 | static inline bool amdgpu_bo_in_cpu_visible_vram(struct amdgpu_bo *bo) | ||
202 | { | ||
203 | struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); | ||
204 | unsigned fpfn = adev->gmc.visible_vram_size >> PAGE_SHIFT; | ||
205 | struct drm_mm_node *node = bo->tbo.mem.mm_node; | ||
206 | unsigned long pages_left; | ||
207 | |||
208 | if (bo->tbo.mem.mem_type != TTM_PL_VRAM) | ||
209 | return false; | ||
210 | |||
211 | for (pages_left = bo->tbo.mem.num_pages; pages_left; | ||
212 | pages_left -= node->size, node++) | ||
213 | if (node->start < fpfn) | ||
214 | return true; | ||
215 | |||
216 | return false; | ||
217 | } | ||
218 | |||
219 | /** | ||
199 | * amdgpu_bo_explicit_sync - return whether the bo is explicitly synced | 220 | * amdgpu_bo_explicit_sync - return whether the bo is explicitly synced |
200 | */ | 221 | */ |
201 | static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo) | 222 | static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo) |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 205da3ff9cd0..ab73300e6c7f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | |||
@@ -223,20 +223,8 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo, | |||
223 | if (!adev->mman.buffer_funcs_enabled) { | 223 | if (!adev->mman.buffer_funcs_enabled) { |
224 | amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_CPU); | 224 | amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_CPU); |
225 | } else if (adev->gmc.visible_vram_size < adev->gmc.real_vram_size && | 225 | } else if (adev->gmc.visible_vram_size < adev->gmc.real_vram_size && |
226 | !(abo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED)) { | 226 | !(abo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) && |
227 | unsigned fpfn = adev->gmc.visible_vram_size >> PAGE_SHIFT; | 227 | amdgpu_bo_in_cpu_visible_vram(abo)) { |
228 | struct drm_mm_node *node = bo->mem.mm_node; | ||
229 | unsigned long pages_left; | ||
230 | |||
231 | for (pages_left = bo->mem.num_pages; | ||
232 | pages_left; | ||
233 | pages_left -= node->size, node++) { | ||
234 | if (node->start < fpfn) | ||
235 | break; | ||
236 | } | ||
237 | |||
238 | if (!pages_left) | ||
239 | goto gtt; | ||
240 | 228 | ||
241 | /* Try evicting to the CPU inaccessible part of VRAM | 229 | /* Try evicting to the CPU inaccessible part of VRAM |
242 | * first, but only set GTT as busy placement, so this | 230 | * first, but only set GTT as busy placement, so this |
@@ -245,12 +233,11 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo, | |||
245 | */ | 233 | */ |
246 | amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_VRAM | | 234 | amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_VRAM | |
247 | AMDGPU_GEM_DOMAIN_GTT); | 235 | AMDGPU_GEM_DOMAIN_GTT); |
248 | abo->placements[0].fpfn = fpfn; | 236 | abo->placements[0].fpfn = adev->gmc.visible_vram_size >> PAGE_SHIFT; |
249 | abo->placements[0].lpfn = 0; | 237 | abo->placements[0].lpfn = 0; |
250 | abo->placement.busy_placement = &abo->placements[1]; | 238 | abo->placement.busy_placement = &abo->placements[1]; |
251 | abo->placement.num_busy_placement = 1; | 239 | abo->placement.num_busy_placement = 1; |
252 | } else { | 240 | } else { |
253 | gtt: | ||
254 | amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT); | 241 | amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT); |
255 | } | 242 | } |
256 | break; | 243 | break; |