All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/amdgpu: Don't change preferred domian when fallback GTT v2
@ 2018-03-19  8:19 Chunming Zhou
       [not found] ` <20180319081913.878-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Chunming Zhou @ 2018-03-19  8:19 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w, Chunming Zhou

v2: add sanity checking

Change-Id: I2cf672ad36b8b4cc1a6b2e704f786bf6a155d9ce
Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c    |  5 -----
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 15 +++++++++++++--
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 6e6570ff9f8b..660f5e44b1a5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -85,11 +85,6 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 				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);
 		}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index b3310219e0ac..6e714c015a79 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -371,6 +371,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
 	enum ttm_bo_type type;
 	unsigned long page_align;
 	size_t acc_size;
+	u32 setting_domain;
 	int r;
 
 	page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
@@ -440,13 +441,23 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
 #endif
 
 	bo->tbo.bdev = &adev->mman.bdev;
-	amdgpu_ttm_placement_from_domain(bo, domain);
+	setting_domain = bo->preferred_domains;
+retry:
+	amdgpu_ttm_placement_from_domain(bo, setting_domain);
 
 	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, type,
 				 &bo->placement, page_align, &ctx, acc_size,
 				 sg, resv, &amdgpu_ttm_bo_destroy);
-	if (unlikely(r != 0))
+	if (unlikely(r != 0)) {
+		if (r != -ERESTARTSYS &&
+		    (ctx.flags & TTM_OPT_FLAG_ALLOW_RES_EVICT) == 0 &&
+		    setting_domain != bo->allowed_domains &&
+		    type == ttm_bo_type_device){
+			setting_domain = bo->allowed_domains;
+			goto retry;
+		}
 		return r;
+	}
 
 	if (adev->gmc.visible_vram_size < adev->gmc.real_vram_size &&
 	    bo->tbo.mem.mem_type == TTM_PL_VRAM &&
-- 
2.14.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] drm/amdgpu: validate fallback BOs
       [not found] ` <20180319081913.878-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
@ 2018-03-19  8:19   ` Chunming Zhou
  2018-03-19  9:43   ` [PATCH 1/2] drm/amdgpu: Don't change preferred domian when fallback GTT v2 Christian König
  1 sibling, 0 replies; 3+ messages in thread
From: Chunming Zhou @ 2018-03-19  8:19 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w, Chunming Zhou

issue:
Game F1 performance drops 13% when per vm bo is enabled.

root cause:
if some BOs are fallback to allowed domain, they will never be validated if no eviction happens,
that means they always exist in allowed domain.

Fix:
maintain a per vm allowed domain BOs list, then try to validated them with perferred domain.

Change-Id: I4335470bf867b46ac93c8e2531eac3f8ba9ac2da
Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 15 +++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 49 ++++++++++++++++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  7 ++++-
 3 files changed, 63 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 383bf2d31c92..7509b6bd2047 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -359,7 +359,7 @@ void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
 }
 
 static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,
-				 struct amdgpu_bo *bo)
+				 struct amdgpu_bo *bo, bool *allowed)
 {
 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
 	struct ttm_operation_ctx ctx = {
@@ -374,6 +374,8 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,
 	if (bo->pin_count)
 		return 0;
 
+	if (allowed)
+		*allowed = false;
 	/* Don't move this buffer if we have depleted our allowance
 	 * to move it. Don't move anything if the threshold is zero.
 	 */
@@ -396,6 +398,9 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,
 	}
 
 retry:
+	if (domain != bo->preferred_domains && domain == bo->allowed_domains &&
+	    allowed)
+		*allowed = true;
 	amdgpu_ttm_placement_from_domain(bo, domain);
 	r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
 
@@ -479,19 +484,19 @@ static bool amdgpu_cs_try_evict(struct amdgpu_cs_parser *p,
 	return false;
 }
 
-static int amdgpu_cs_validate(void *param, struct amdgpu_bo *bo)
+static int amdgpu_cs_validate(void *param, struct amdgpu_bo *bo, bool *allowed)
 {
 	struct amdgpu_cs_parser *p = param;
 	int r;
 
 	do {
-		r = amdgpu_cs_bo_validate(p, bo);
+		r = amdgpu_cs_bo_validate(p, bo, allowed);
 	} while (r == -ENOMEM && amdgpu_cs_try_evict(p, bo));
 	if (r)
 		return r;
 
 	if (bo->shadow)
-		r = amdgpu_cs_bo_validate(p, bo->shadow);
+		r = amdgpu_cs_bo_validate(p, bo->shadow, NULL);
 
 	return r;
 }
@@ -528,7 +533,7 @@ static int amdgpu_cs_list_validate(struct amdgpu_cs_parser *p,
 		if (p->evictable == lobj)
 			p->evictable = NULL;
 
-		r = amdgpu_cs_validate(p, bo);
+		r = amdgpu_cs_validate(p, bo, NULL);
 		if (r)
 			return r;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index e9a41dd05345..365e8dca05f5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -186,6 +186,35 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
 	list_add(&entry->tv.head, validated);
 }
 
+static int amdgpu_vm_try_validate_allowed(struct amdgpu_device *adev,
+					  struct amdgpu_vm *vm,
+					  int (*validate)(void *p,
+							  struct amdgpu_bo *bo,
+							  bool *allowed),
+					  void *param)
+{
+	struct amdgpu_vm_bo_base *bo_base, *tmp;
+	int r;
+	bool allowed;
+
+	spin_lock(&vm->status_lock);
+	list_for_each_entry_safe(bo_base, tmp, &vm->allowed_domain,
+				 allowed_domain_list) {
+		spin_unlock(&vm->status_lock);
+		r = validate(param, bo_base->bo, &allowed);
+		if (r)
+			return r;
+		spin_lock(&vm->status_lock);
+		if (!allowed)
+			list_del_init(&bo_base->allowed_domain_list);
+		if (bo_base->bo->tbo.type != ttm_bo_type_kernel)
+			list_move(&bo_base->vm_status, &vm->moved);
+		else
+			list_move(&bo_base->vm_status, &vm->relocated);
+	}
+	spin_unlock(&vm->status_lock);
+	return 0;
+}
 /**
  * amdgpu_vm_validate_pt_bos - validate the page table BOs
  *
@@ -197,16 +226,19 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
  * Validate the page table BOs on command submission if neccessary.
  */
 int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
-			      int (*validate)(void *p, struct amdgpu_bo *bo),
+			      int (*validate)(void *p, struct amdgpu_bo *bo,
+					      bool *allowed),
 			      void *param)
 {
 	struct ttm_bo_global *glob = adev->mman.bdev.glob;
+	LIST_HEAD(tmp_allowed);
 	int r;
 
 	spin_lock(&vm->status_lock);
 	while (!list_empty(&vm->evicted)) {
 		struct amdgpu_vm_bo_base *bo_base;
 		struct amdgpu_bo *bo;
+		bool allowed = false;
 
 		bo_base = list_first_entry(&vm->evicted,
 					   struct amdgpu_vm_bo_base,
@@ -216,7 +248,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		bo = bo_base->bo;
 		BUG_ON(!bo);
 		if (bo->parent) {
-			r = validate(param, bo);
+			r = validate(param, bo, &allowed);
 			if (r)
 				return r;
 
@@ -235,6 +267,10 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		}
 
 		spin_lock(&vm->status_lock);
+		if (allowed)
+			list_add_tail(&bo_base->allowed_domain_list,
+				      &tmp_allowed);
+
 		if (bo->tbo.type != ttm_bo_type_kernel)
 			list_move(&bo_base->vm_status, &vm->moved);
 		else
@@ -242,6 +278,12 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	}
 	spin_unlock(&vm->status_lock);
 
+	r = amdgpu_vm_try_validate_allowed(adev, vm, validate, param);
+	if (r)
+		return r;
+	spin_lock(&vm->status_lock);
+	list_splice_init(&tmp_allowed, &vm->allowed_domain);
+	spin_unlock(&vm->status_lock);
 	return 0;
 }
 
@@ -1868,6 +1910,7 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
 	bo_va->base.bo = bo;
 	INIT_LIST_HEAD(&bo_va->base.bo_list);
 	INIT_LIST_HEAD(&bo_va->base.vm_status);
+	INIT_LIST_HEAD(&bo_va->base.allowed_domain_list);
 
 	bo_va->ref_count = 1;
 	INIT_LIST_HEAD(&bo_va->valids);
@@ -2237,6 +2280,7 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
 
 	spin_lock(&vm->status_lock);
 	list_del(&bo_va->base.vm_status);
+	list_del(&bo_va->base.allowed_domain_list);
 	spin_unlock(&vm->status_lock);
 
 	list_for_each_entry_safe(mapping, next, &bo_va->valids, list) {
@@ -2409,6 +2453,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	for (i = 0; i < AMDGPU_MAX_VMHUBS; i++)
 		vm->reserved_vmid[i] = NULL;
 	spin_lock_init(&vm->status_lock);
+	INIT_LIST_HEAD(&vm->allowed_domain);
 	INIT_LIST_HEAD(&vm->evicted);
 	INIT_LIST_HEAD(&vm->relocated);
 	INIT_LIST_HEAD(&vm->moved);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index cf2c667ee538..54c39d3ea6d8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -149,6 +149,7 @@ struct amdgpu_vm_bo_base {
 
 	/* protected by spinlock */
 	struct list_head		vm_status;
+	struct list_head		allowed_domain_list;
 
 	/* protected by the BO being reserved */
 	bool				moved;
@@ -177,6 +178,9 @@ struct amdgpu_vm {
 	/* protecting invalidated */
 	spinlock_t		status_lock;
 
+	/* per vm bo is validated to allowed domain */
+	struct list_head	allowed_domain;
+
 	/* BOs who needs a validation */
 	struct list_head	evicted;
 
@@ -266,7 +270,8 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
 			 struct amdgpu_bo_list_entry *entry);
 bool amdgpu_vm_ready(struct amdgpu_vm *vm);
 int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
-			      int (*callback)(void *p, struct amdgpu_bo *bo),
+			      int (*callback)(void *p, struct amdgpu_bo *bo,
+					      bool *allowed),
 			      void *param);
 int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 			struct amdgpu_vm *vm,
-- 
2.14.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] drm/amdgpu: Don't change preferred domian when fallback GTT v2
       [not found] ` <20180319081913.878-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
  2018-03-19  8:19   ` [PATCH 2/2] drm/amdgpu: validate fallback BOs Chunming Zhou
@ 2018-03-19  9:43   ` Christian König
  1 sibling, 0 replies; 3+ messages in thread
From: Christian König @ 2018-03-19  9:43 UTC (permalink / raw)
  To: Chunming Zhou, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 19.03.2018 um 09:19 schrieb Chunming Zhou:
> v2: add sanity checking
>
> Change-Id: I2cf672ad36b8b4cc1a6b2e704f786bf6a155d9ce
> Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c    |  5 -----
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 15 +++++++++++++--
>   2 files changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index 6e6570ff9f8b..660f5e44b1a5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -85,11 +85,6 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
>   				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);
>   		}
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index b3310219e0ac..6e714c015a79 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -371,6 +371,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
>   	enum ttm_bo_type type;
>   	unsigned long page_align;
>   	size_t acc_size;
> +	u32 setting_domain;
>   	int r;
>   
>   	page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
> @@ -440,13 +441,23 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
>   #endif
>   
>   	bo->tbo.bdev = &adev->mman.bdev;
> -	amdgpu_ttm_placement_from_domain(bo, domain);
> +	setting_domain = bo->preferred_domains;
> +retry:
> +	amdgpu_ttm_placement_from_domain(bo, setting_domain);
>   
>   	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, type,
>   				 &bo->placement, page_align, &ctx, acc_size,
>   				 sg, resv, &amdgpu_ttm_bo_destroy);
> -	if (unlikely(r != 0))
> +	if (unlikely(r != 0)) {
> +		if (r != -ERESTARTSYS &&
> +		    (ctx.flags & TTM_OPT_FLAG_ALLOW_RES_EVICT) == 0 &&
> +		    setting_domain != bo->allowed_domains &&
> +		    type == ttm_bo_type_device){
> +			setting_domain = bo->allowed_domains;
> +			goto retry;
> +		}
>   		return r;
> +	}

That still doesn't looks good to me, please just open code it as I 
suggested.

Additional to that why do you check TTM_OPT_FLAG_ALLOW_RES_EVICT here? 
That doesn't seems to make sense.

Regards,
Christian.

>   
>   	if (adev->gmc.visible_vram_size < adev->gmc.real_vram_size &&
>   	    bo->tbo.mem.mem_type == TTM_PL_VRAM &&

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-19  9:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-19  8:19 [PATCH 1/2] drm/amdgpu: Don't change preferred domian when fallback GTT v2 Chunming Zhou
     [not found] ` <20180319081913.878-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
2018-03-19  8:19   ` [PATCH 2/2] drm/amdgpu: validate fallback BOs Chunming Zhou
2018-03-19  9:43   ` [PATCH 1/2] drm/amdgpu: Don't change preferred domian when fallback GTT v2 Christian König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.