Skip to content

Commit e362b7c

Browse files
arunpravin24alexdeucher
authored andcommitted
drm/amdgpu: Modify the contiguous flags behaviour
Now we have two flags for contiguous VRAM buffer allocation. If the application request for AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS, it would set the ttm place TTM_PL_FLAG_CONTIGUOUS flag in the buffer's placement function. This patch will change the default behaviour of the two flags. When we set AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS - This means contiguous is not mandatory. - we will try to allocate the contiguous buffer. Say if the allocation fails, we fallback to allocate the individual pages. When we setTTM_PL_FLAG_CONTIGUOUS - This means contiguous allocation is mandatory. - we are setting this in amdgpu_bo_pin_restricted() before bo validation and check this flag in the vram manager file. - if this is set, we should allocate the buffer pages contiguously. the allocation fails, we return -ENOSPC. v2: - keep the mem_flags and bo->flags check as is(Christian) - place the TTM_PL_FLAG_CONTIGUOUS flag setting into the amdgpu_bo_pin_restricted function placement range iteration loop(Christian) - rename find_pages with amdgpu_vram_mgr_calculate_pages_per_block (Christian) - Keep the kernel BO allocation as is(Christain) - If BO pin vram allocation failed, we need to return -ENOSPC as RDMA cannot work with scattered VRAM pages(Philip) v3(Christian): - keep contiguous flag handling outside of pages_per_block calculation - remove the hacky implementation in contiguous flag error handling code v4(Christian): - use any variable and return value for non-contiguous fallback v5: rebase to amd-staging-drm-next branch Signed-off-by: Arunpravin Paneer Selvam <[email protected]> Suggested-by: Christian König <[email protected]> Reviewed-by: Christian König <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent f851b07 commit e362b7c

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain)
153153
else
154154
places[c].flags |= TTM_PL_FLAG_TOPDOWN;
155155

156-
if (flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS)
156+
if (abo->tbo.type == ttm_bo_type_kernel &&
157+
flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS)
157158
places[c].flags |= TTM_PL_FLAG_CONTIGUOUS;
159+
158160
c++;
159161
}
160162

@@ -967,6 +969,10 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
967969
if (!bo->placements[i].lpfn ||
968970
(lpfn && lpfn < bo->placements[i].lpfn))
969971
bo->placements[i].lpfn = lpfn;
972+
973+
if (bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS &&
974+
bo->placements[i].mem_type == TTM_PL_VRAM)
975+
bo->placements[i].flags |= TTM_PL_FLAG_CONTIGUOUS;
970976
}
971977

972978
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
450450
{
451451
struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
452452
struct amdgpu_device *adev = to_amdgpu_device(mgr);
453+
struct amdgpu_bo *bo = ttm_to_amdgpu_bo(tbo);
453454
u64 vis_usage = 0, max_bytes, min_block_size;
454455
struct amdgpu_vram_mgr_resource *vres;
455456
u64 size, remaining_size, lpfn, fpfn;
@@ -468,7 +469,7 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
468469
if (tbo->type != ttm_bo_type_kernel)
469470
max_bytes -= AMDGPU_VM_RESERVED_VRAM;
470471

471-
if (place->flags & TTM_PL_FLAG_CONTIGUOUS) {
472+
if (bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS) {
472473
pages_per_block = ~0ul;
473474
} else {
474475
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
@@ -477,7 +478,7 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
477478
/* default to 2MB */
478479
pages_per_block = 2UL << (20UL - PAGE_SHIFT);
479480
#endif
480-
pages_per_block = max_t(uint32_t, pages_per_block,
481+
pages_per_block = max_t(u32, pages_per_block,
481482
tbo->page_alignment);
482483
}
483484

@@ -498,7 +499,7 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
498499
if (place->flags & TTM_PL_FLAG_TOPDOWN)
499500
vres->flags |= DRM_BUDDY_TOPDOWN_ALLOCATION;
500501

501-
if (place->flags & TTM_PL_FLAG_CONTIGUOUS)
502+
if (bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS)
502503
vres->flags |= DRM_BUDDY_CONTIGUOUS_ALLOCATION;
503504

504505
if (fpfn || lpfn != mgr->mm.size)
@@ -514,21 +515,31 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
514515
else
515516
min_block_size = mgr->default_page_size;
516517

517-
BUG_ON(min_block_size < mm->chunk_size);
518-
519518
/* Limit maximum size to 2GiB due to SG table limitations */
520519
size = min(remaining_size, 2ULL << 30);
521520

522521
if ((size >= (u64)pages_per_block << PAGE_SHIFT) &&
523-
!(size & (((u64)pages_per_block << PAGE_SHIFT) - 1)))
522+
!(size & (((u64)pages_per_block << PAGE_SHIFT) - 1)))
524523
min_block_size = (u64)pages_per_block << PAGE_SHIFT;
525524

525+
BUG_ON(min_block_size < mm->chunk_size);
526+
526527
r = drm_buddy_alloc_blocks(mm, fpfn,
527528
lpfn,
528529
size,
529530
min_block_size,
530531
&vres->blocks,
531532
vres->flags);
533+
534+
if (unlikely(r == -ENOSPC) && pages_per_block == ~0ul &&
535+
!(place->flags & TTM_PL_FLAG_CONTIGUOUS)) {
536+
vres->flags &= ~DRM_BUDDY_CONTIGUOUS_ALLOCATION;
537+
pages_per_block = max_t(u32, 2UL << (20UL - PAGE_SHIFT),
538+
tbo->page_alignment);
539+
540+
continue;
541+
}
542+
532543
if (unlikely(r))
533544
goto error_free_blocks;
534545

0 commit comments

Comments
 (0)