Skip to contentSkip to conversation

drm/amdgpu: pin_size fixes

PATCH In review Michel Dänzer 3 participants 12 messages Jun 15, 2018 – Jun 18, 2018 7 messages not in the archive

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

cover drm/amdgpu: pin_size fixes

From: Michel Dänzer <[email protected]>

I came up with the fixes in patches 1 & 3 while looking into
https://bugs.freedesktop.org/106872 . It's not clear that these will be enough to fix that, but they are moving in the right direction anyway.

Patch 2 is refactoring in preparation for patch 3.

Patch 4 is separate so that patches 1-3 can be backported to older kernels which don't have amdgpu_gmc_vram_full_visible.

Michel Dänzer (4):
drm/amdgpu: Update pin_size values before unpinning BO drm/amdgpu: Refactor amdgpu_vram_mgr_bo_invisible_size helper drm/amdgpu: Make amdgpu_vram_mgr_bo_invisible_size always accurate drm/amdgpu: Use gmc_vram_full_visible in vram_mgr_bo_invisible_size

 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c   | 24 ++++++-------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h      |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 38 ++++++++++++++++++++
 3 files changed, 49 insertions(+), 14 deletions(-)
Signature · 6 lines
2.17.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): 20180615144230.18480-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org

#2 lore raw

PATCH 1/4 drm/amdgpu: Update pin_size values before unpinning BO

From: Michel Dänzer <[email protected]>

At least in theory, ttm_bo_validate may move the BO, in which case the pin_size accounting would be inconsistent with when the BO was pinned.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +8 -10
index f5b0b180a6cc..210e7631f4b7 100644
@@ -969,15 +969,6 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)
 	bo->pin_count--;
 	if (bo->pin_count)
 		return 0;
-	for (i = 0; i < bo->placement.num_placement; i++) {
-		bo->placements[i].lpfn = 0;
-		bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
-	}
-	r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
-	if (unlikely(r)) {
-		dev_err(adev->dev, "%p validate failed for unpin\n", bo);
-		goto error;
-	}
 
 	if (bo->tbo.mem.mem_type == TTM_PL_VRAM) {
 		adev->vram_pin_size -= amdgpu_bo_size(bo);
@@ -987,7 +978,14 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)
 		adev->gart_pin_size -= amdgpu_bo_size(bo);
 	}
 
-error:
+	for (i = 0; i < bo->placement.num_placement; i++) {
+		bo->placements[i].lpfn = 0;
+		bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
+	}
+	r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
+	if (unlikely(r))
+		dev_err(adev->dev, "%p validate failed for unpin\n", bo);
+
 	return r;
 }
 
Signature · 6 lines
2.17.1

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

PATCH 2/4 drm/amdgpu: Refactor amdgpu_vram_mgr_bo_invisible_size helper

In reply to a message not in the archive

From: Michel Dänzer <[email protected]>

Preparation for the following fix, no functional change intended.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c   |  6 ++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h      |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 16 ++++++++++++++++
 3 files changed, 19 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -4
index 210e7631f4b7..512f59836436 100644
@@ -918,8 +918,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
 	domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
 	if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
 		adev->vram_pin_size += amdgpu_bo_size(bo);
-		if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
-			adev->invisible_pin_size += amdgpu_bo_size(bo);
+		adev->invisible_pin_size += amdgpu_vram_mgr_bo_invisible_size(bo);
 	} else if (domain == AMDGPU_GEM_DOMAIN_GTT) {
 		adev->gart_pin_size += amdgpu_bo_size(bo);
 	}
@@ -972,8 +971,7 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)
 
 	if (bo->tbo.mem.mem_type == TTM_PL_VRAM) {
 		adev->vram_pin_size -= amdgpu_bo_size(bo);
-		if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
-			adev->invisible_pin_size -= amdgpu_bo_size(bo);
+		adev->invisible_pin_size -= amdgpu_vram_mgr_bo_invisible_size(bo);
 	} else if (bo->tbo.mem.mem_type == TTM_PL_TT) {
 		adev->gart_pin_size -= amdgpu_bo_size(bo);
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +1 -0
index e969c879d87e..e5da4654b630 100644
@@ -73,6 +73,7 @@ bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_mem_reg *mem);
 uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man);
 int amdgpu_gtt_mgr_recover(struct ttm_mem_type_manager *man);
 
+u64 amdgpu_vram_mgr_bo_invisible_size(struct amdgpu_bo *bo);
 uint64_t amdgpu_vram_mgr_usage(struct ttm_mem_type_manager *man);
 uint64_t amdgpu_vram_mgr_vis_usage(struct ttm_mem_type_manager *man);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +16 -0
index 9c47e860e5e6..491fd0a789f7 100644
@@ -96,6 +96,22 @@ static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev,
 		adev->gmc.visible_vram_size : end) - start;
 }
 
+/**
+ * amdgpu_vram_mgr_bo_invisible_size - CPU invisible BO size
+ *
+ * @bo: &amdgpu_bo buffer object
+ *
+ * Returns:
+ * How much of the given &amdgpu_bo buffer object lies in CPU invisible VRAM.
+ */
+u64 amdgpu_vram_mgr_bo_invisible_size(struct amdgpu_bo *bo)
+{
+	if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
+		return amdgpu_bo_size(bo);
+
+	return 0;
+}
+
 /**
  * amdgpu_vram_mgr_new - allocate new ranges
  *
Signature · 6 lines
2.17.1

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

PATCH 3/4 drm/amdgpu: Make amdgpu_vram_mgr_bo_invisible_size always accurate

In reply to a message not in the archive

From: Michel Dänzer <[email protected]>

Even BOs with AMDGPU_GEM_CREATE_NO_CPU_ACCESS may end up at least partially in CPU visible VRAM, in particular when all VRAM is visible.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 26 ++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +24 -2
index 491fd0a789f7..9b34df7017f0 100644
@@ -106,10 +106,32 @@ static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev,
  */
 u64 amdgpu_vram_mgr_bo_invisible_size(struct amdgpu_bo *bo)
 {
-	if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	struct amdgpu_vram_mgr *mgr = adev->mman.bdev.man[TTM_PL_VRAM].priv;
+	struct ttm_mem_reg *mem = &bo->tbo.mem;
+	struct drm_mm_node *nodes = mem->mm_node;
+	unsigned pages = mem->num_pages;
+	u64 usage = 0;
+
+	if (adev->gmc.visible_vram_size == adev->gmc.real_vram_size)
+		return 0;
+
+	if (mem->start >= adev->gmc.visible_vram_size >> PAGE_SHIFT)
 		return amdgpu_bo_size(bo);
 
-	return 0;
+	if (!nodes)
+		return 0;
+
+	spin_lock(&mgr->lock);
+	while (pages) {
+		pages -= nodes->size;
+		usage += nodes->size << PAGE_SHIFT;
+		usage -= amdgpu_vram_mgr_vis_size(adev, nodes);
+		++nodes;
+	}
+	spin_unlock(&mgr->lock);
+
+	return usage;
 }
 
 /**
Signature · 6 lines
2.17.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): 20180615144230.18480-4-michel-otUistvHUpPR7s880joybQ@public.gmane.org

#6 lore raw

Re: [PATCH 3/4] drm/amdgpu: Make amdgpu_vram_mgr_bo_invisible_size always accurate

Am 15.06.2018 um 16:42 schrieb Michel Dänzer:

Quoted 19 lines

From: Michel Dänzer <[email protected]>

Even BOs with AMDGPU_GEM_CREATE_NO_CPU_ACCESS may end up at least partially in CPU visible VRAM, in particular when all VRAM is visible.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 26 ++++++++++++++++++--
  1 file changed, 24 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +0 -0
index 491fd0a789f7..9b34df7017f0 100644
@@ -106,10 +106,32 @@ static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev,
   */
  u64 amdgpu_vram_mgr_bo_invisible_size(struct amdgpu_bo *bo)
  {

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, · line 117

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +9 -1
-	if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	struct amdgpu_vram_mgr *mgr = adev->mman.bdev.man[TTM_PL_VRAM].priv;
+	struct ttm_mem_reg *mem = &bo->tbo.mem;
+	struct drm_mm_node *nodes = mem->mm_node;
+	unsigned pages = mem->num_pages;
+	u64 usage = 0;
+
+	if (adev->gmc.visible_vram_size == adev->gmc.real_vram_size)
+		return 0;

Andrey just added a helper for that into amdgpu_gmc.h.

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, · line 125

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +6 -1
+
+	if (mem->start >= adev->gmc.visible_vram_size >> PAGE_SHIFT)
  		return amdgpu_bo_size(bo);
 
-	return 0;
+	if (!nodes)
+		return 0;
+
+	spin_lock(&mgr->lock);

I actually don't see any need to grab the lock here.

Apart from that looks like a good cleanup to me,
Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, · line 137

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +9 -0
+	while (pages) {
+		pages -= nodes->size;
+		usage += nodes->size << PAGE_SHIFT;
+		usage -= amdgpu_vram_mgr_vis_size(adev, nodes);
+		++nodes;
+	}
+	spin_unlock(&mgr->lock);
+
+	return usage;
  }
 
  /**

_______________________________________________
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): 093bbd7a-02cd-068f-a53a-2d4f1c5b3084-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#8 lore raw

Re: [PATCH 3/4] drm/amdgpu: Make amdgpu_vram_mgr_bo_invisible_size always accurate

Quoted 26 lines · Christian König

Am 15.06.2018 um 16:42 schrieb Michel Dänzer:

Quoted 25 lines

From: Michel Dänzer <[email protected]>

Even BOs with AMDGPU_GEM_CREATE_NO_CPU_ACCESS may end up at least partially in CPU visible VRAM, in particular when all VRAM is visible.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 26 ++++++++++++++++++--

  1 file changed, 24 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +3 -1
index 491fd0a789f7..9b34df7017f0 100644
@@ -106,10 +106,32 @@ static u64 amdgpu_vram_mgr_vis_size(struct
 amdgpu_device *adev,
    */
   u64 amdgpu_vram_mgr_bo_invisible_size(struct amdgpu_bo *bo)
   {
-    if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
+    struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+    struct amdgpu_vram_mgr *mgr = adev->mman.bdev.man[TTM_PL_VRAM].priv;
+    struct ttm_mem_reg *mem = &bo->tbo.mem;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, · line 117

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +6 -0
+    struct drm_mm_node *nodes = mem->mm_node;
+    unsigned pages = mem->num_pages;
+    u64 usage = 0;
+
+    if (adev->gmc.visible_vram_size == adev->gmc.real_vram_size)
+        return 0;

Andrey just added a helper for that into amdgpu_gmc.h.

Yep, see patch 4 and the cover letter. :)

Quoted 10 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, · line 125

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +6 -0
+
+    if (mem->start >= adev->gmc.visible_vram_size >> PAGE_SHIFT)
           return amdgpu_bo_size(bo);
   -    return 0;
+    if (!nodes)
+        return 0;
+
+    spin_lock(&mgr->lock);

I actually don't see any need to grab the lock here.

Ah, so amdgpu_vram_mgr_del only grabs it for drm_mm_remove_node?

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
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): 098df480-3db3-485f-8e39-4ebf8201b3a0-otUistvHUpPR7s880joybQ@public.gmane.org

#10 lore raw

Re: [PATCH 3/4] drm/amdgpu: Make amdgpu_vram_mgr_bo_invisible_size always accurate

Am 15.06.2018 um 17:14 schrieb Michel Dänzer:

Quoted 34 lines · Christian König
Quoted 25 lines

Am 15.06.2018 um 16:42 schrieb Michel Dänzer:

Quoted 24 lines

From: Michel Dänzer <[email protected]>

Even BOs with AMDGPU_GEM_CREATE_NO_CPU_ACCESS may end up at least partially in CPU visible VRAM, in particular when all VRAM is visible.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 26 ++++++++++++++++++--
   1 file changed, 24 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +2 -1
index 491fd0a789f7..9b34df7017f0 100644
@@ -106,10 +106,32 @@ static u64 amdgpu_vram_mgr_vis_size(struct
 amdgpu_device *adev,
    */
   u64 amdgpu_vram_mgr_bo_invisible_size(struct amdgpu_bo *bo)
   {
-    if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
+    struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+    struct amdgpu_vram_mgr *mgr = adev->mman.bdev.man[TTM_PL_VRAM].priv;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, · line 117

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +7 -0
+    struct ttm_mem_reg *mem = &bo->tbo.mem;
+    struct drm_mm_node *nodes = mem->mm_node;
+    unsigned pages = mem->num_pages;
+    u64 usage = 0;
+
+    if (adev->gmc.visible_vram_size == adev->gmc.real_vram_size)
+        return 0;

Andrey just added a helper for that into amdgpu_gmc.h.

Quoted 1 line

Yep, see patch 4 and the cover letter. :)

Yeah, seen that after hitting send :)

Quoted 10 lines
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, · line 125

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +6 -0
+
+    if (mem->start >= adev->gmc.visible_vram_size >> PAGE_SHIFT)
           return amdgpu_bo_size(bo);
   -    return 0;
+    if (!nodes)
+        return 0;
+
+    spin_lock(&mgr->lock);

I actually don't see any need to grab the lock here.

Ah, so amdgpu_vram_mgr_del only grabs it for drm_mm_remove_node?

Yes, exactly.

Christian.
_______________________________________________
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): b94d92e5-908d-534a-907a-ad97124b22ec-5C7GfCeVMHo@public.gmane.org

#12 lore raw

Re: [PATCH 3/4] drm/amdgpu: Make amdgpu_vram_mgr_bo_invisible_size always accurate

Quoted 13 lines · Christian König

Am 15.06.2018 um 17:14 schrieb Michel Dänzer:

Quoted 12 lines · Christian König
Quoted 11 lines

Am 15.06.2018 um 16:42 schrieb Michel Dänzer:

Quoted 8 lines

+
+    if (mem->start >= adev->gmc.visible_vram_size >> PAGE_SHIFT) return amdgpu_bo_size(bo);
   -    return 0;
+    if (!nodes)
+        return 0;
+
+    spin_lock(&mgr->lock);

I actually don't see any need to grab the lock here.

Quoted 3 lines
Quoted 1 line

Ah, so amdgpu_vram_mgr_del only grabs it for drm_mm_remove_node?

Yes, exactly.

Will drop it in v2, thanks!

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
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): 3140ef24-f8c9-5863-ff44-4c83192eabb1-otUistvHUpPR7s880joybQ@public.gmane.org

#14 lore raw

Re: [PATCH 3/4] drm/amdgpu: Make amdgpu_vram_mgr_bo_invisible_size always accurate

Am 15.06.2018 um 17:19 schrieb Michel Dänzer:

Quoted 13 lines · Christian König
Quoted 12 lines

Am 15.06.2018 um 17:14 schrieb Michel Dänzer:

Quoted 11 lines · Christian König
Quoted 10 lines

Am 15.06.2018 um 16:42 schrieb Michel Dänzer:

Review

Quoted 8 lines
(quoted diff) +6 -0
+
+    if (mem->start >= adev->gmc.visible_vram_size >> PAGE_SHIFT)
            return amdgpu_bo_size(bo);
    -    return 0;
+    if (!nodes)
+        return 0;
+
+    spin_lock(&mgr->lock);

I actually don't see any need to grab the lock here.

Quoted 3 lines
Quoted 2 lines
Quoted 1 line

Ah, so amdgpu_vram_mgr_del only grabs it for drm_mm_remove_node?

Yes, exactly.

Will drop it in v2, thanks!

Haven't seeen v2 yet, but with that lock removed the whole series is Reviewed-by: Christian König <[email protected]>.

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

#15 lore raw

PATCH v2 3/4 drm/amdgpu: Make amdgpu_vram_mgr_bo_invisible_size always accurate

In reply to a message not in the archive

From: Michel Dänzer <[email protected]>

Even BOs with AMDGPU_GEM_CREATE_NO_CPU_ACCESS may end up at least partially in CPU visible VRAM, in particular when all VRAM is visible.

v2:
* Don't take VRAM mgr spinlock, not needed (Christian König)
* Make loop logic simpler and clearer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +18 -2
index ae0049c6c52c..b6333f92ba45 100644
@@ -106,10 +106,26 @@ static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev,
  */
 u64 amdgpu_vram_mgr_bo_invisible_size(struct amdgpu_bo *bo)
 {
-	if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	struct ttm_mem_reg *mem = &bo->tbo.mem;
+	struct drm_mm_node *nodes = mem->mm_node;
+	unsigned pages = mem->num_pages;
+	u64 usage = 0;
+
+	if (adev->gmc.visible_vram_size == adev->gmc.real_vram_size)
+		return 0;
+
+	if (mem->start >= adev->gmc.visible_vram_size >> PAGE_SHIFT)
 		return amdgpu_bo_size(bo);
 
-	return 0;
+	while (nodes && pages) {
+		usage += nodes->size << PAGE_SHIFT;
+		usage -= amdgpu_vram_mgr_vis_size(adev, nodes);
+		pages -= nodes->size;
+		++nodes;
+	}
+
+	return usage;
 }
 
 /**
Signature · 6 lines
2.17.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): 20180618165233.5718-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org

Reviewed-by
#17 lore raw

Re: [PATCH v2 3/4] drm/amdgpu: Make amdgpu_vram_mgr_bo_invisible_size always accurate

Am 18.06.2018 um 18:52 schrieb Michel Dänzer:

Quoted 11 lines

From: Michel Dänzer <[email protected]>

Even BOs with AMDGPU_GEM_CREATE_NO_CPU_ACCESS may end up at least partially in CPU visible VRAM, in particular when all VRAM is visible.

v2:
* Don't take VRAM mgr spinlock, not needed (Christian König)
* Make loop logic simpler and clearer.

Quoted 27 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 20 ++++++++++++++++++--
  1 file changed, 18 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +11 -2
index ae0049c6c52c..b6333f92ba45 100644
@@ -106,10 +106,26 @@ static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev,
   */
  u64 amdgpu_vram_mgr_bo_invisible_size(struct amdgpu_bo *bo)
  {
-	if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	struct ttm_mem_reg *mem = &bo->tbo.mem;
+	struct drm_mm_node *nodes = mem->mm_node;
+	unsigned pages = mem->num_pages;
+	u64 usage = 0;
+
+	if (adev->gmc.visible_vram_size == adev->gmc.real_vram_size)
+		return 0;
+
+	if (mem->start >= adev->gmc.visible_vram_size >> PAGE_SHIFT)
  		return amdgpu_bo_size(bo);
 
-	return 0;
+	while (nodes && pages) {

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, · line 131

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +7 -0
+		usage += nodes->size << PAGE_SHIFT;
+		usage -= amdgpu_vram_mgr_vis_size(adev, nodes);
+		pages -= nodes->size;
+		++nodes;
+	}
+
+	return usage;
  }
 
  /**

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

#18 lore raw

PATCH 4/4 drm/amdgpu: Use gmc_vram_full_visible in vram_mgr_bo_invisible_size

In reply to a message not in the archive

From: Michel Dänzer <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1 -1
index 9b34df7017f0..9814e9aab317 100644
@@ -113,7 +113,7 @@ u64 amdgpu_vram_mgr_bo_invisible_size(struct amdgpu_bo *bo)
 	unsigned pages = mem->num_pages;
 	u64 usage = 0;
 
-	if (adev->gmc.visible_vram_size == adev->gmc.real_vram_size)
+	if (amdgpu_gmc_vram_full_visible(&adev->gmc))
 		return 0;
 
 	if (mem->start >= adev->gmc.visible_vram_size >> PAGE_SHIFT)
Signature · 6 lines
2.17.1

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