Skip to contentSkip to conversation

drm/amdgpu: only move VM BOs in the LRU during validation v2

PATCH In review Christian König 4 participants 9 messages Jul 29, 2017 – Jul 31, 2017 5 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/amdgpu: only move VM BOs in the LRU during validation v2

From: Christian König <[email protected]>

This should save us a bunch of command submission overhead.

v2: move the LRU move to the right place to avoid the move for the root BO
and handle the shadow BOs as well. This turned out to be a bug fix because the move needs to happen before the kmap.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 15 +++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 58 +++++++---------------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 --
 3 files changed, 16 insertions(+), 59 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +5 -10
index cd5c08a..7fb4baa 100644
@@ -669,10 +669,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 	}
 
 error_validate:
-	if (r) {
-		amdgpu_vm_move_pt_bos_in_lru(p->adev, &fpriv->vm);
+	if (r)
 		ttm_eu_backoff_reservation(&p->ticket, &p->validated);
-	}
 
 error_free_pages:
 
@@ -720,21 +718,18 @@ static int amdgpu_cs_sync_rings(struct amdgpu_cs_parser *p)
  * If error is set than unvalidate buffer, otherwise just free memory
  * used by parsing context.
  **/
-static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error, bool backoff)
+static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
+				  bool backoff)
 {
-	struct amdgpu_fpriv *fpriv = parser->filp->driver_priv;
 	unsigned i;
 
-	if (!error) {
-		amdgpu_vm_move_pt_bos_in_lru(parser->adev, &fpriv->vm);
-
+	if (!error)
 		ttm_eu_fence_buffer_objects(&parser->ticket,
 					    &parser->validated,
 					    parser->fence);
-	} else if (backoff) {
+	else if (backoff)
 		ttm_eu_backoff_reservation(&parser->ticket,
 					   &parser->validated);
-	}
 	dma_fence_put(parser->fence);
 
 	if (parser->ctx)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +11 -47

84 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -2
index 34d9174..bac09ce 100644
@@ -220,8 +220,6 @@ void amdgpu_vm_get_pd_bo(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),
 			      void *param);
-void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
-				  struct amdgpu_vm *vm);
 int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 			struct amdgpu_vm *vm,
 			uint64_t saddr, uint64_t size);
Signature · 6 lines
2.7.4

_______________________________________________
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): 1501327923-19559-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#2 lore raw

PATCH 2/3 drm/amdgpu: only bind VM shadows after validation v2

From: Christian König <[email protected]>

No need to do this on every CS.

v2: remove all other bind, reorder code

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8 -14
index a375135..0308bb4 100644
@@ -165,6 +165,14 @@ static int amdgpu_vm_validate_level(struct amdgpu_vm_pt *parent,
 	unsigned i;
 	int r;
 
+	if (parent->bo->shadow) {
+		struct amdgpu_bo *shadow = parent->bo->shadow;
+
+		r = amdgpu_ttm_bind(&shadow->tbo, &shadow->tbo.mem);
+		if (r)
+			return r;
+	}
+
 	if (use_cpu_for_update) {
 		r = amdgpu_bo_kmap(parent->bo, NULL);
 		if (r)
@@ -1030,11 +1038,6 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
 
 		params.func = amdgpu_vm_cpu_set_ptes;
 	} else {
-		if (shadow) {
-			r = amdgpu_ttm_bind(&shadow->tbo, &shadow->tbo.mem);
-			if (r)
-				return r;
-		}
 		ring = container_of(vm->entity.sched, struct amdgpu_ring,
 				    sched);
 
@@ -1070,15 +1073,6 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
 		if (bo == NULL)
 			continue;
 
-		if (bo->shadow) {
-			struct amdgpu_bo *pt_shadow = bo->shadow;
-
-			r = amdgpu_ttm_bind(&pt_shadow->tbo,
-					    &pt_shadow->tbo.mem);
-			if (r)
-				return r;
-		}
-
 		pt = amdgpu_bo_gpu_offset(bo);
 		pt = amdgpu_gart_get_vm_pde(adev, pt);
 		if (parent->entries[pt_idx].addr == pt ||
Signature · 6 lines
2.7.4

_______________________________________________
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): 1501327923-19559-2-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#4 lore raw

Re: [PATCH 2/3] drm/amdgpu: only bind VM shadows after validation v2

Hi Christian,

If I'm reading this correctly, now you're only binding page directories, but not the leaf page tables. Is that intentional?

Regards,
Felix

Quoted 48 lines · Christian König

From: Christian König <[email protected]>

No need to do this on every CS.

v2: remove all other bind, reorder code

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8 -7
index a375135..0308bb4 100644
@@ -165,6 +165,14 @@ static int amdgpu_vm_validate_level(struct amdgpu_vm_pt *parent,
 	unsigned i;
 	int r;
 
+	if (parent->bo->shadow) {
+		struct amdgpu_bo *shadow = parent->bo->shadow;
+
+		r = amdgpu_ttm_bind(&shadow->tbo, &shadow->tbo.mem);
+		if (r)
+			return r;
+	}
+
 	if (use_cpu_for_update) {
 		r = amdgpu_bo_kmap(parent->bo, NULL);
 		if (r)
@@ -1030,11 +1038,6 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
 
 		params.func = amdgpu_vm_cpu_set_ptes;
 	} else {
-		if (shadow) {
-			r = amdgpu_ttm_bind(&shadow->tbo, &shadow->tbo.mem);
-			if (r)
-				return r;
-		}
 		ring = container_of(vm->entity.sched, struct amdgpu_ring,
 				    sched);
 
@@ -1070,15 +1073,6 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
 		if (bo == NULL)
 			continue;
 
-		if (bo->shadow) {
-			struct amdgpu_bo *pt_shadow = bo->shadow;

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_update_level(struct amdgpu_device *adev, · line 1078

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -7
-
-			r = amdgpu_ttm_bind(&pt_shadow->tbo,
-					    &pt_shadow->tbo.mem);
-			if (r)
-				return r;
-		}
-
 		pt = amdgpu_bo_gpu_offset(bo);
 		pt = amdgpu_gart_get_vm_pde(adev, pt);
 		if (parent->entries[pt_idx].addr == pt ||

_______________________________________________
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): c9977d09-4ce2-740c-df59-d1518b351c33-5C7GfCeVMHo@public.gmane.org

#6 lore raw

Re: [PATCH 2/3] drm/amdgpu: only bind VM shadows after validation v2

Am 31.07.2017 um 17:24 schrieb Felix Kuehling:

Quoted 4 lines

Hi Christian,

If I'm reading this correctly, now you're only binding page directories, but not the leaf page tables. Is that intentional?

You are not reading this correctly I think.

Leave page tables don have parent->entries==NULL and we check for that condition after the bind as far as I can see.

Regards,
Christian.

Quoted 52 lines

Regards,
Felix

Quoted 46 lines · Christian König

From: Christian König <[email protected]>

No need to do this on every CS.

v2: remove all other bind, reorder code

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 22 ++++++++--------------
  1 file changed, 8 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8 -5
index a375135..0308bb4 100644
@@ -165,6 +165,14 @@ static int amdgpu_vm_validate_level(struct amdgpu_vm_pt *parent,
  	unsigned i;
  	int r;
 
+	if (parent->bo->shadow) {
+		struct amdgpu_bo *shadow = parent->bo->shadow;
+
+		r = amdgpu_ttm_bind(&shadow->tbo, &shadow->tbo.mem);
+		if (r)
+			return r;
+	}
+
  	if (use_cpu_for_update) {
  		r = amdgpu_bo_kmap(parent->bo, NULL);
  		if (r)
@@ -1030,11 +1038,6 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
 
  		params.func = amdgpu_vm_cpu_set_ptes;
  	} else {
-		if (shadow) {
-			r = amdgpu_ttm_bind(&shadow->tbo, &shadow->tbo.mem);
-			if (r)
-				return r;
-		}
  		ring = container_of(vm->entity.sched, struct amdgpu_ring,
  				    sched);
 
@@ -1070,15 +1073,6 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
  		if (bo == NULL)
  			continue;
 
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_update_level(struct amdgpu_device *adev, · line 1078

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -9
-		if (bo->shadow) {
-			struct amdgpu_bo *pt_shadow = bo->shadow;
-
-			r = amdgpu_ttm_bind(&pt_shadow->tbo,
-					    &pt_shadow->tbo.mem);
-			if (r)
-				return r;
-		}
-
  		pt = amdgpu_bo_gpu_offset(bo);
  		pt = amdgpu_gart_get_vm_pde(adev, pt);
  		if (parent->entries[pt_idx].addr == pt ||

_______________________________________________
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): 19fb8035-2c18-2ee6-c0bc-baaabedb5b1f-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#8 lore raw

Re: [PATCH 2/3] drm/amdgpu: only bind VM shadows after validation v2

Quoted 10 lines · Christian König

Am 31.07.2017 um 17:24 schrieb Felix Kuehling:

Quoted 4 lines

Hi Christian,

If I'm reading this correctly, now you're only binding page directories, but not the leaf page tables. Is that intentional?

You are not reading this correctly I think.

Leave page tables don have parent->entries==NULL and we check for that condition after the bind as far as I can see.

Yes, I read it wrong. Never mind. Reviewed-by: Felix Kuehling <[email protected]>

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#9 lore raw

PATCH 3/3 drm/amdgpu: fix Vega10 HW config for 2MB pages

In reply to a message not in the archive

From: Christian König <[email protected]>

Those values weren't correct. This should result in quite some speedup.

---
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c +2 -2
index 408723e..6c8040e 100644
@@ -144,8 +144,8 @@ static void gfxhub_v1_0_init_cache_regs(struct amdgpu_device *adev)
 	WREG32_SOC15(GC, 0, mmVM_L2_CNTL2, tmp);
 
 	tmp = mmVM_L2_CNTL3_DEFAULT;
-	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, BANK_SELECT, 12);
-	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, L2_CACHE_BIGK_FRAGMENT_SIZE, 9);
+	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, BANK_SELECT, 9);
+	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, L2_CACHE_BIGK_FRAGMENT_SIZE, 6);
 	WREG32_SOC15(GC, 0, mmVM_L2_CNTL3, tmp);
 
 	tmp = mmVM_L2_CNTL4_DEFAULT;
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +2 -2
index ad8def3..74cb647 100644
@@ -158,8 +158,8 @@ static void mmhub_v1_0_init_cache_regs(struct amdgpu_device *adev)
 	WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL2, tmp);
 
 	tmp = mmVM_L2_CNTL3_DEFAULT;
-	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, BANK_SELECT, 12);
-	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, L2_CACHE_BIGK_FRAGMENT_SIZE, 9);
+	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, BANK_SELECT, 9);
+	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, L2_CACHE_BIGK_FRAGMENT_SIZE, 6);
 	WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL3, tmp);
 
 	tmp = mmVM_L2_CNTL4_DEFAULT;
Signature · 6 lines
2.7.4

_______________________________________________
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): 1501327923-19559-3-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

Reviewed-by Alex Deucher
#11 lore raw

RE: [PATCH 3/3] drm/amdgpu: fix Vega10 HW config for 2MB pages

Quoted 7 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Christian König
Sent: Saturday, July 29, 2017 7:32 AM
To: [email protected]
Subject: [PATCH 3/3] drm/amdgpu: fix Vega10 HW config for 2MB pages

Quoted 5 lines

From: Christian König <[email protected]>

Those values weren't correct. This should result in quite some speedup.

Series is:

Quoted 46 lines
---
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c +2 -2
index 408723e..6c8040e 100644
@@ -144,8 +144,8 @@ static void gfxhub_v1_0_init_cache_regs(struct
 amdgpu_device *adev)
 	WREG32_SOC15(GC, 0, mmVM_L2_CNTL2, tmp);
 
 	tmp = mmVM_L2_CNTL3_DEFAULT;
-	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, BANK_SELECT, 12);
-	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3,
 L2_CACHE_BIGK_FRAGMENT_SIZE, 9);
+	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, BANK_SELECT, 9);
+	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3,
 L2_CACHE_BIGK_FRAGMENT_SIZE, 6);
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c +0 -0
 	WREG32_SOC15(GC, 0, mmVM_L2_CNTL3, tmp);
 
 	tmp = mmVM_L2_CNTL4_DEFAULT;
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +2 -2
index ad8def3..74cb647 100644
@@ -158,8 +158,8 @@ static void mmhub_v1_0_init_cache_regs(struct
 amdgpu_device *adev)
 	WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL2, tmp);
 
 	tmp = mmVM_L2_CNTL3_DEFAULT;
-	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, BANK_SELECT, 12);
-	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3,
 L2_CACHE_BIGK_FRAGMENT_SIZE, 9);
+	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, BANK_SELECT, 9);
+	tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3,
 L2_CACHE_BIGK_FRAGMENT_SIZE, 6);
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +0 -1
 	WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL3, tmp);
 
 	tmp = mmVM_L2_CNTL4_DEFAULT;
--

2.7.4

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#12 lore raw
In reply to a message not in the archive

The series is Acked-by: Chunming Zhou <[email protected]>

Quoted 154 lines · Christian König

From: Christian König <[email protected]>

This should save us a bunch of command submission overhead.

v2: move the LRU move to the right place to avoid the move for the root BO
and handle the shadow BOs as well. This turned out to be a bug fix because the move needs to happen before the kmap.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 15 +++------
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 58 +++++++---------------------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 --
  3 files changed, 16 insertions(+), 59 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +5 -10
index cd5c08a..7fb4baa 100644
@@ -669,10 +669,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
  	}
 
  error_validate:
-	if (r) {
-		amdgpu_vm_move_pt_bos_in_lru(p->adev, &fpriv->vm);
+	if (r)
  		ttm_eu_backoff_reservation(&p->ticket, &p->validated);
-	}
 
  error_free_pages:
 
@@ -720,21 +718,18 @@ static int amdgpu_cs_sync_rings(struct amdgpu_cs_parser *p)
   * If error is set than unvalidate buffer, otherwise just free memory
   * used by parsing context.
   **/
-static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error, bool backoff)
+static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
+				  bool backoff)
  {
-	struct amdgpu_fpriv *fpriv = parser->filp->driver_priv;
  	unsigned i;
 
-	if (!error) {
-		amdgpu_vm_move_pt_bos_in_lru(parser->adev, &fpriv->vm);
-
+	if (!error)
  		ttm_eu_fence_buffer_objects(&parser->ticket,
  					    &parser->validated,
  					    parser->fence);
-	} else if (backoff) {
+	else if (backoff)
  		ttm_eu_backoff_reservation(&parser->ticket,
  					   &parser->validated);
-	}
  	dma_fence_put(parser->fence);
 
  	if (parser->ctx)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +11 -47
index a1d4294..a375135 100644
@@ -159,7 +159,8 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
   */
  static int amdgpu_vm_validate_level(struct amdgpu_vm_pt *parent,
  				    int (*validate)(void *, struct amdgpu_bo *),
-				    void *param, bool use_cpu_for_update)
+				    void *param, bool use_cpu_for_update,
+				    struct ttm_bo_global *glob)
  {
  	unsigned i;
  	int r;
@@ -183,12 +184,18 @@ static int amdgpu_vm_validate_level(struct amdgpu_vm_pt *parent,
  		if (r)
  			return r;
 
+		spin_lock(&glob->lru_lock);
+		ttm_bo_move_to_lru_tail(&entry->bo->tbo);
+		if (entry->bo->shadow)
+			ttm_bo_move_to_lru_tail(&entry->bo->shadow->tbo);
+		spin_unlock(&glob->lru_lock);
+
  		/*
  		 * Recurse into the sub directory. This is harmless because we
  		 * have only a maximum of 5 layers.
  		 */
  		r = amdgpu_vm_validate_level(entry, validate, param,
-					     use_cpu_for_update);
+					     use_cpu_for_update, glob);
  		if (r)
  			return r;
  	}
@@ -220,54 +227,11 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  		return 0;
 
  	return amdgpu_vm_validate_level(&vm->root, validate, param,
-					vm->use_cpu_for_update);
+					vm->use_cpu_for_update,
+					adev->mman.bdev.glob);
  }
 
  /**
- * amdgpu_vm_move_level_in_lru - move one level of PT BOs to the LRU tail
- *
- * @adev: amdgpu device instance
- * @vm: vm providing the BOs
- *
- * Move the PT BOs to the tail of the LRU.
- */
-static void amdgpu_vm_move_level_in_lru(struct amdgpu_vm_pt *parent)
-{
-	unsigned i;
-
-	if (!parent->entries)
-		return;
-
-	for (i = 0; i <= parent->last_entry_used; ++i) {
-		struct amdgpu_vm_pt *entry = &parent->entries[i];
-
-		if (!entry->bo)
-			continue;
-
-		ttm_bo_move_to_lru_tail(&entry->bo->tbo);
-		amdgpu_vm_move_level_in_lru(entry);
-	}
-}
-
-/**
- * amdgpu_vm_move_pt_bos_in_lru - move the PT BOs to the LRU tail
- *
- * @adev: amdgpu device instance
- * @vm: vm providing the BOs
- *
- * Move the PT BOs to the tail of the LRU.
- */
-void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
-				  struct amdgpu_vm *vm)
-{
-	struct ttm_bo_global *glob = adev->mman.bdev.glob;
-
-	spin_lock(&glob->lru_lock);
-	amdgpu_vm_move_level_in_lru(&vm->root);
-	spin_unlock(&glob->lru_lock);
-}
-
- /**
   * amdgpu_vm_alloc_levels - allocate the PD/PT levels
   *
   * @adev: amdgpu_device pointer
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
index 34d9174..bac09ce 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, · line 225

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -2
@@ -220,8 +220,6 @@ void amdgpu_vm_get_pd_bo(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),
  			      void *param);
-void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
-				  struct amdgpu_vm *vm);
  int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
  			struct amdgpu_vm *vm,
  			uint64_t saddr, uint64_t size);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#13 lore raw
In reply to a message not in the archive

Patches 1 and 3 are Reviewed-by: Felix Kuehling <[email protected]>

I'm not sure about Patch 2. See my comment in reply to that patch.

Regards,
Felix

Quoted 154 lines · Christian König

From: Christian König <[email protected]>

This should save us a bunch of command submission overhead.

v2: move the LRU move to the right place to avoid the move for the root BO
and handle the shadow BOs as well. This turned out to be a bug fix because the move needs to happen before the kmap.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 15 +++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 58 +++++++---------------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 --
 3 files changed, 16 insertions(+), 59 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +5 -10
index cd5c08a..7fb4baa 100644
@@ -669,10 +669,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 	}
 
 error_validate:
-	if (r) {
-		amdgpu_vm_move_pt_bos_in_lru(p->adev, &fpriv->vm);
+	if (r)
 		ttm_eu_backoff_reservation(&p->ticket, &p->validated);
-	}
 
 error_free_pages:
 
@@ -720,21 +718,18 @@ static int amdgpu_cs_sync_rings(struct amdgpu_cs_parser *p)
  * If error is set than unvalidate buffer, otherwise just free memory
  * used by parsing context.
  **/
-static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error, bool backoff)
+static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
+				  bool backoff)
 {
-	struct amdgpu_fpriv *fpriv = parser->filp->driver_priv;
 	unsigned i;
 
-	if (!error) {
-		amdgpu_vm_move_pt_bos_in_lru(parser->adev, &fpriv->vm);
-
+	if (!error)
 		ttm_eu_fence_buffer_objects(&parser->ticket,
 					    &parser->validated,
 					    parser->fence);
-	} else if (backoff) {
+	else if (backoff)
 		ttm_eu_backoff_reservation(&parser->ticket,
 					   &parser->validated);
-	}
 	dma_fence_put(parser->fence);
 
 	if (parser->ctx)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +11 -47
index a1d4294..a375135 100644
@@ -159,7 +159,8 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
  */
 static int amdgpu_vm_validate_level(struct amdgpu_vm_pt *parent,
 				    int (*validate)(void *, struct amdgpu_bo *),
-				    void *param, bool use_cpu_for_update)
+				    void *param, bool use_cpu_for_update,
+				    struct ttm_bo_global *glob)
 {
 	unsigned i;
 	int r;
@@ -183,12 +184,18 @@ static int amdgpu_vm_validate_level(struct amdgpu_vm_pt *parent,
 		if (r)
 			return r;
 
+		spin_lock(&glob->lru_lock);
+		ttm_bo_move_to_lru_tail(&entry->bo->tbo);
+		if (entry->bo->shadow)
+			ttm_bo_move_to_lru_tail(&entry->bo->shadow->tbo);
+		spin_unlock(&glob->lru_lock);
+
 		/*
 		 * Recurse into the sub directory. This is harmless because we
 		 * have only a maximum of 5 layers.
 		 */
 		r = amdgpu_vm_validate_level(entry, validate, param,
-					     use_cpu_for_update);
+					     use_cpu_for_update, glob);
 		if (r)
 			return r;
 	}
@@ -220,54 +227,11 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		return 0;
 
 	return amdgpu_vm_validate_level(&vm->root, validate, param,
-					vm->use_cpu_for_update);
+					vm->use_cpu_for_update,
+					adev->mman.bdev.glob);
 }
 
 /**
- * amdgpu_vm_move_level_in_lru - move one level of PT BOs to the LRU tail
- *
- * @adev: amdgpu device instance
- * @vm: vm providing the BOs
- *
- * Move the PT BOs to the tail of the LRU.
- */
-static void amdgpu_vm_move_level_in_lru(struct amdgpu_vm_pt *parent)
-{
-	unsigned i;
-
-	if (!parent->entries)
-		return;
-
-	for (i = 0; i <= parent->last_entry_used; ++i) {
-		struct amdgpu_vm_pt *entry = &parent->entries[i];
-
-		if (!entry->bo)
-			continue;
-
-		ttm_bo_move_to_lru_tail(&entry->bo->tbo);
-		amdgpu_vm_move_level_in_lru(entry);
-	}
-}
-
-/**
- * amdgpu_vm_move_pt_bos_in_lru - move the PT BOs to the LRU tail
- *
- * @adev: amdgpu device instance
- * @vm: vm providing the BOs
- *
- * Move the PT BOs to the tail of the LRU.
- */
-void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
-				  struct amdgpu_vm *vm)
-{
-	struct ttm_bo_global *glob = adev->mman.bdev.glob;
-
-	spin_lock(&glob->lru_lock);
-	amdgpu_vm_move_level_in_lru(&vm->root);
-	spin_unlock(&glob->lru_lock);
-}
-
- /**
  * amdgpu_vm_alloc_levels - allocate the PD/PT levels
  *
  * @adev: amdgpu_device pointer
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
index 34d9174..bac09ce 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, · line 225

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -2
@@ -220,8 +220,6 @@ void amdgpu_vm_get_pd_bo(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),
 			      void *param);
-void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
-				  struct amdgpu_vm *vm);
 int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 			struct amdgpu_vm *vm,
 			uint64_t saddr, uint64_t size);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx