drm/amdgpu: Don't change preferred domian when fallback GTT v6
Subsystems (3)
PATCH 1/2 drm/amdgpu: Don't change preferred domian when fallback GTT v6
v2: add sanity checking
v3: make code open
v4: also handle visible to invisible fallback
v5: Since two fallback cases, re-use goto retry
v6: avoid bo is unref when retry, and only user BO can fallback
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 16 ++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 37 +++++++++++++++++++----------- 2 files changed, 26 insertions(+), 27 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -14
@@ -56,23 +56,11 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, alignment =PAGE_SIZE ; } -retry: r =amdgpu_bo_create (adev, size, alignment, initial_domain, flags, type, resv, &bo);if (r) { -if (r != -ERESTARTSYS ) { -if (flags &AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ) { - flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ; - goto retry; - } - -if (initial_domain ==AMDGPU_GEM_DOMAIN_VRAM ) { - initial_domain |=AMDGPU_GEM_DOMAIN_GTT ; - goto retry; - } -DRM_DEBUG ("Failed to allocate GEM object (%ld, %d, %u, %d)\n" , - size, initial_domain, alignment, r); - } +DRM_DEBUG ("Failed to allocate GEM object (%ld, %d, %u, %d)\n" , + size, initial_domain, alignment, r);return r; } *obj = &bo->gem_base;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +24 -13
@@ -352,6 +352,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,struct amdgpu_bo *bo;unsigned long page_align;size_t acc_size; +u32 domains, preferred_domains, allowed_domains;int r; page_align =roundup (byte_align,PAGE_SIZE ) >>PAGE_SHIFT ;
@@ -365,22 +366,24 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size, acc_size =ttm_bo_dma_acc_size (&adev->mman.bdev, size,sizeof (struct amdgpu_bo )); + preferred_domains = domain & (AMDGPU_GEM_DOMAIN_VRAM | +AMDGPU_GEM_DOMAIN_GTT | +AMDGPU_GEM_DOMAIN_CPU | +AMDGPU_GEM_DOMAIN_GDS | +AMDGPU_GEM_DOMAIN_GWS | +AMDGPU_GEM_DOMAIN_OA ); + allowed_domains = preferred_domains; +if (type != ttm_bo_type_kernel && + allowed_domains ==AMDGPU_GEM_DOMAIN_VRAM ) + allowed_domains |=AMDGPU_GEM_DOMAIN_GTT ; + domains = preferred_domains; +retry: bo =kzalloc (sizeof (struct amdgpu_bo ),GFP_KERNEL );if (bo ==NULL )return -ENOMEM ;drm_gem_private_object_init (adev->ddev, &bo->gem_base, size);INIT_LIST_HEAD (&bo->shadow_list);INIT_LIST_HEAD (&bo->va); - bo->preferred_domains = domain & (AMDGPU_GEM_DOMAIN_VRAM | -AMDGPU_GEM_DOMAIN_GTT | -AMDGPU_GEM_DOMAIN_CPU | -AMDGPU_GEM_DOMAIN_GDS | -AMDGPU_GEM_DOMAIN_GWS | -AMDGPU_GEM_DOMAIN_OA ); - bo->allowed_domains = bo->preferred_domains; -if (type != ttm_bo_type_kernel && - bo->allowed_domains ==AMDGPU_GEM_DOMAIN_VRAM ) - bo->allowed_domains |=AMDGPU_GEM_DOMAIN_GTT ; bo->flags = flags;
@@ -413,12 +416,20 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,#endif bo->tbo.bdev = &adev->mman.bdev; -amdgpu_ttm_placement_from_domain (bo, domain); - +amdgpu_ttm_placement_from_domain (bo, domains); r =ttm_bo_init_reserved (&adev->mman.bdev, &bo->tbo, size, type, &bo->placement, page_align, &ctx, acc_size,NULL , resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r && r != -ERESTARTSYS ) && type == ttm_bo_type_device) { +if (flags &AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ) { + flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ; + goto retry; + }else if (domains != allowed_domains) { + domains = allowed_domains; + goto retry; + } + } +if (unlikely (r))return r; if (adev->gmc.visible_vram_size < adev->gmc.real_vram_size &&
Signature · 6 lines
2.14.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 2/2 drm/amdgpu: add new bo flag that indicates BOs don't need fallback
user cases:
1. KFD wraps amdgpu_bo_create, they have no fallback case which is different with amdgpu_gem_object_create.
since upstream branch has no amdgpu_amdkfd_gpuvm.c, which need KFD guys add this flag to __alloc_memory_of_gpu:
+ flags |= AMDGPU_GEM_CREATE_NO_FALLBACK;
2. UMD can specify this flag for their allocation as well if they like.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++- include/uapi/drm/amdgpu_drm.h | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -1
@@ -386,7 +386,8 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p, bo->tbo.mem.start < adev->gmc.visible_vram_size >> PAGE_SHIFT) p->bytes_moved_vis += ctx.bytes_moved; -if (unlikely (r == -ENOMEM ) && domain != bo->allowed_domains) { +if (unlikely (r == -ENOMEM ) && domain != bo->allowed_domains && + !(bo->flags &AMDGPU_GEM_CREATE_NO_FALLBACK )) { domain = bo->allowed_domains; goto retry; }
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
@@ -420,7 +420,8 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size, r =ttm_bo_init_reserved (&adev->mman.bdev, &bo->tbo, size, type, &bo->placement, page_align, &ctx, acc_size,NULL , resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r && r != -ERESTARTSYS ) && type == ttm_bo_type_device) { +if (unlikely (r && r != -ERESTARTSYS ) && type == ttm_bo_type_device && + !(flags &AMDGPU_GEM_CREATE_NO_FALLBACK )) {if (flags &AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ) { flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ; goto retry;
include/uapi/drm/amdgpu_drm.h +2 -0
@@ -98,6 +98,8 @@ extern "C" {#define AMDGPU_GEM_CREATE_VM_ALWAYS_VALID (1 << 6)/* Flag that BO sharing will be explicitly synchronized */ #define AMDGPU_GEM_CREATE_EXPLICIT_SYNC (1 << 7) +/* Flag that BO doesn't need fallback */ +#define AMDGPU_GEM_CREATE_NO_FALLBACK (1 << 8)struct drm_amdgpu_gem_create_in {/** the requested memory size */
Signature · 6 lines
2.14.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 2/2] drm/amdgpu: add new bo flag that indicates BOs don't need fallback
The series is Acked-by: Felix Kuehling <[email protected]>
Thanks,
Felix
Quoted 50 lines · Chunming Zhou
user cases:
1. KFD wrapsamdgpu_bo_create, they have no fallback case which is different withamdgpu_gem_object_create.
since upstream branch has noamdgpu_amdkfd_gpuvm.c, which need KFD guys add this flag to__alloc_memory_of_gpu:
+ flags |=AMDGPU_GEM_CREATE_NO_FALLBACK;
2. UMD can specify this flag for their allocation as well if they like.Change-Id Id3ac1a0bdd48633328d0b22c4c057fab4e94d0b3Signed-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++- include/uapi/drm/amdgpu_drm.h | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2
-1@@ -386,7 +386,8 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p, bo->tbo.mem.start < adev->gmc.visible_vram_size >> PAGE_SHIFT) p->bytes_moved_vis += ctx.bytes_moved; -if (unlikely (r == -ENOMEM ) && domain != bo->allowed_domains) { +if (unlikely (r == -ENOMEM ) && domain != bo->allowed_domains && + !(bo->flags &AMDGPU_GEM_CREATE_NO_FALLBACK )) { domain = bo->allowed_domains; goto retry; }drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-1@@ -420,7 +420,8 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size, r =ttm_bo_init_reserved (&adev->mman.bdev, &bo->tbo, size, type, &bo->placement, page_align, &ctx, acc_size,NULL , resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r && r != -ERESTARTSYS ) && type == ttm_bo_type_device) { +if (unlikely (r && r != -ERESTARTSYS ) && type == ttm_bo_type_device && + !(flags &AMDGPU_GEM_CREATE_NO_FALLBACK )) {if (flags &AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ) { flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ; goto retry;include/uapi/drm/amdgpu_drm.h +0
-0
include/uapi/drm/amdgpu_drm.h extern "C" { · line 105
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h +2
-0@@ -98,6 +98,8 @@ extern "C" {#define AMDGPU_GEM_CREATE_VM_ALWAYS_VALID (1 << 6)/* Flag that BO sharing will be explicitly synchronized */ #define AMDGPU_GEM_CREATE_EXPLICIT_SYNC (1 << 7) +/* Flag that BO doesn't need fallback */ +#define AMDGPU_GEM_CREATE_NO_FALLBACK (1 << 8)struct drm_amdgpu_gem_create_in {/** the requested memory size */
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 2/2] drm/amdgpu: add new bo flag that indicates BOs don't need fallback
In reply to a message not in the archiveAm 03.04.2018 um 11:24 schrieb Chunming Zhou:
Quoted 7 lines
user cases:
1. KFD wrapsamdgpu_bo_create, they have no fallback case which is different withamdgpu_gem_object_create.
since upstream branch has noamdgpu_amdkfd_gpuvm.c, which need KFD guys add this flag to__alloc_memory_of_gpu:
+ flags |=AMDGPU_GEM_CREATE_NO_FALLBACK;
2. UMD can specify this flag for their allocation as well if they like.
Please drop the second comment, we currently block the UMD from using this flag.
Quoted 15 lines
Change-Id Id3ac1a0bdd48633328d0b22c4c057fab4e94d0b3Signed-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++- include/uapi/drm/amdgpu_drm.h | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p, · line 390
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2
-1@@ -386,7 +386,8 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p, bo->tbo.mem.start < adev->gmc.visible_vram_size >> PAGE_SHIFT) p->bytes_moved_vis += ctx.bytes_moved; -if (unlikely (r == -ENOMEM ) && domain != bo->allowed_domains) { +if (unlikely (r == -ENOMEM ) && domain != bo->allowed_domains && + !(bo->flags &AMDGPU_GEM_CREATE_NO_FALLBACK )) {
Please drop that change, we can control BO placement purely using the preferred/allowed domains here.
Apart from that the patch looks good to me,
Christian.
Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0
-0domain = bo->allowed_domains; goto retry; }drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-1@@ -420,7 +420,8 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size, r =ttm_bo_init_reserved (&adev->mman.bdev, &bo->tbo, size, type, &bo->placement, page_align, &ctx, acc_size,NULL , resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r && r != -ERESTARTSYS ) && type == ttm_bo_type_device) { +if (unlikely (r && r != -ERESTARTSYS ) && type == ttm_bo_type_device && + !(flags &AMDGPU_GEM_CREATE_NO_FALLBACK )) {if (flags &AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ) { flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ; goto retry;include/uapi/drm/amdgpu_drm.h +0
-0
include/uapi/drm/amdgpu_drm.h extern "C" { · line 105
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h +2
-0@@ -98,6 +98,8 @@ extern "C" {#define AMDGPU_GEM_CREATE_VM_ALWAYS_VALID (1 << 6)/* Flag that BO sharing will be explicitly synchronized */ #define AMDGPU_GEM_CREATE_EXPLICIT_SYNC (1 << 7) +/* Flag that BO doesn't need fallback */ +#define AMDGPU_GEM_CREATE_NO_FALLBACK (1 << 8)struct drm_amdgpu_gem_create_in {/** the requested memory size */
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx