Skip to contentSkip to conversation

drm/amdgpu: reverse PDBs order

PATCH In review Chunming Zhou 4 participants 11 messages Dec 8, 2017 – Dec 11, 2017 7 messages not in the archive

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

PATCH 1/2 drm/amdgpu: reverse PDBs order

The hiberachy of page table is as below, which aligns hw names. PDB2->PDB1->PDB0->PTB, accordingly:
level3 --- PDB2
level2 --- PDB1
level1 --- PDB0
level0 --- PTB

Change-Id I2d748e5e96cffe18294c104c4b192d910b2f8e6b
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 37 ++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +24 -13
index 3ecdbdfb04dd..8904ccf78fc9 100644
@@ -148,8 +148,8 @@ struct amdgpu_prt_cb {
 static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
 				      unsigned level)
 {
-	if (level != adev->vm_manager.num_level)
-		return 9 * (adev->vm_manager.num_level - level - 1) +
+	if (level != 0)
+		return 9 * (level - 1) +
 			adev->vm_manager.block_size;
 	else
 		/* For the page tables on the leaves */
@@ -162,20 +162,27 @@ static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
  * @adev: amdgpu_device pointer
  *
  * Calculate the number of entries in a page directory or page table.
+ * The hiberachy of page table is as below, which aligns hw names.
+ * PDB2->PDB1->PDB0->PTB, accordingly:
+ * level3 --- PDB2
+ * level2 --- PDB1
+ * level1 --- PDB0
+ * level0 --- PTB
  */
 static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
 				      unsigned level)
 {
-	unsigned shift = amdgpu_vm_level_shift(adev, 0);
+	unsigned shift = amdgpu_vm_level_shift(adev,
+					       adev->vm_manager.num_level);
 
-	if (level == 0)
+	if (level == adev->vm_manager.num_level)
 		/* For the root directory */
 		return round_up(adev->vm_manager.max_pfn, 1 << shift) >> shift;
-	else if (level != adev->vm_manager.num_level)
+	else if (level != 0)
 		/* Everything in between */
 		return 512;
 	else
-		/* For the page tables on the leaves */
+		/* For the page tables on the leaves(PTB) */
 		return AMDGPU_VM_PTE_COUNT(adev);
 }
 
@@ -312,6 +319,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 	u64 flags;
 	uint64_t init_value = 0;
 
+	BUG_ON(level > adev->vm_manager.num_level);
+
 	if (!parent->entries) {
 		unsigned num_entries = amdgpu_vm_num_entries(adev, level);
 
@@ -332,7 +341,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 	if (to > parent->last_entry_used)
 		parent->last_entry_used = to;
 
-	++level;
+	level--;
 	saddr = saddr & ((1 << shift) - 1);
 	eaddr = eaddr & ((1 << shift) - 1);
 
@@ -346,7 +355,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 
 	if (vm->pte_support_ats) {
 		init_value = AMDGPU_PTE_DEFAULT_ATC;
-		if (level != adev->vm_manager.num_level - 1)
+		/* != PDB0 */
+		if (level != 1)
 			init_value |= AMDGPU_PDE_PTE;
 
 	}
@@ -389,7 +399,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 			entry->addr = 0;
 		}
 
-		if (level < adev->vm_manager.num_level) {
+		if (level > 0) {
 			uint64_t sub_saddr = (pt_idx == from) ? saddr : 0;
 			uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
 				((1 << shift) - 1);
@@ -435,7 +445,8 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 	saddr /= AMDGPU_GPU_PAGE_SIZE;
 	eaddr /= AMDGPU_GPU_PAGE_SIZE;
 
-	return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr, 0);
+	return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
+				      adev->vm_manager.num_level);
 }
 
 /**
@@ -1319,19 +1330,19 @@ void amdgpu_vm_get_entry(struct amdgpu_pte_update_params *p, uint64_t addr,
 			 struct amdgpu_vm_pt **entry,
 			 struct amdgpu_vm_pt **parent)
 {
-	unsigned level = 0;
+	unsigned level = p->adev->vm_manager.num_level;
 
 	*parent = NULL;
 	*entry = &p->vm->root;
 	while ((*entry)->entries) {
-		unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level++);
+		unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level--);
 
 		idx %= amdgpu_bo_size((*entry)->base.bo) / 8;
 		*parent = *entry;
 		*entry = &(*entry)->entries[idx];
 	}
 
-	if (level != p->adev->vm_manager.num_level)
+	if (level != 0)
 		*entry = NULL;
 }
 
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]

#2 lore raw

PATCH 2/2 drm/amdgpu: fix pte index calculation

Change-Id I40ecf31ad4b51022a2c0c076ae45188b6e9d63de
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -2
index 8904ccf78fc9..affe64e42cef 100644
@@ -1335,11 +1335,13 @@ void amdgpu_vm_get_entry(struct amdgpu_pte_update_params *p, uint64_t addr,
 	*parent = NULL;
 	*entry = &p->vm->root;
 	while ((*entry)->entries) {
-		unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level--);
+		unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level);
 
-		idx %= amdgpu_bo_size((*entry)->base.bo) / 8;
+		idx %= amdgpu_vm_num_entries(p->adev, level);
 		*parent = *entry;
 		*entry = &(*entry)->entries[idx];
+		if (level)
+			level--;
 	}
 
 	if (level != 0)
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]

#4 lore raw

Re: [PATCH 2/2] drm/amdgpu: fix pte index calculation

What is wrong with the old approach?

I would rather say that the address should be limited by the level shift instead. This way we avoid the modulo altogether.

Christian.

Am 08.12.2017 um 11:56 schrieb Chunming Zhou:

Quoted 16 lines
Change-Id I40ecf31ad4b51022a2c0c076ae45188b6e9d63de
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
index 8904ccf78fc9..affe64e42cef 100644
@@ -1335,11 +1335,13 @@ void amdgpu_vm_get_entry(struct amdgpu_pte_update_params *p, uint64_t addr,
  	*parent = NULL;
  	*entry = &p->vm->root;
  	while ((*entry)->entries) {
-		unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level--);
+		unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level);

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_get_entry(struct amdgpu_pte_update_params *p, uint64_t addr, · line 1347

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -1
 
-		idx %= amdgpu_bo_size((*entry)->base.bo) / 8;
+		idx %= amdgpu_vm_num_entries(p->adev, level);
  		*parent = *entry;
  		*entry = &(*entry)->entries[idx];
+		if (level)
+			level--;
  	}
 
  	if (level != 0)

_______________________________________________
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): 32026195-0596-404f-deb5-018d16c19a75-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#6 lore raw

Re: [PATCH 2/2] drm/amdgpu: fix pte index calculation

Quoted 1 line · Christian König

What is wrong with the old approach?

When the num entries are less than one page(512), the old approach will result in error. e.g. when we enable translate further feature, the ptb will only have 32 entries with 64KB---16 * 4KB selection.

Quoted 2 lines

I would rather say that the address should be limited by the level shift instead. This way we avoid the modulo altogether.

already in your patch set.

Regards,
David Zhou

Quoted 21 lines

Christian.

Am 08.12.2017 um 11:56 schrieb Chunming Zhou:

Quoted 17 lines
Change-Id I40ecf31ad4b51022a2c0c076ae45188b6e9d63de

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 ++++--

  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
index 8904ccf78fc9..affe64e42cef 100644
@@ -1335,11 +1335,13 @@ void amdgpu_vm_get_entry(struct 
 amdgpu_pte_update_params *p, uint64_t addr,
       *parent = NULL;
       *entry = &p->vm->root;
       while ((*entry)->entries) {
-        unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level--);
+        unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level);
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_get_entry(struct amdgpu_pte_update_params *p, uint64_t addr, · line 1347

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -0
   -        idx %= amdgpu_bo_size((*entry)->base.bo) / 8;
+        idx %= amdgpu_vm_num_entries(p->adev, level);
           *parent = *entry;
           *entry = &(*entry)->entries[idx];
+        if (level)
+            level--;
       }
         if (level != 0)

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

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

Am 08.12.2017 um 11:56 schrieb Chunming Zhou:

Quoted 9 lines

The hiberachy of page table is as below, which aligns hw names. PDB2->PDB1->PDB0->PTB, accordingly:
level3 --- PDB2
level2 --- PDB1
level1 --- PDB0
level0 --- PTB

Change-Id I2d748e5e96cffe18294c104c4b192d910b2f8e6b

Yeah, thought about that as well. But I'm not sure if that is a good idea or not.

Quoted 61 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 37 ++++++++++++++++++++++------------
  1 file changed, 24 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +15 -6
index 3ecdbdfb04dd..8904ccf78fc9 100644
@@ -148,8 +148,8 @@ struct amdgpu_prt_cb {
  static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
  				      unsigned level)
  {
-	if (level != adev->vm_manager.num_level)
-		return 9 * (adev->vm_manager.num_level - level - 1) +
+	if (level != 0)
+		return 9 * (level - 1) +
  			adev->vm_manager.block_size;
  	else
  		/* For the page tables on the leaves */
@@ -162,20 +162,27 @@ static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
   * @adev: amdgpu_device pointer
   *
   * Calculate the number of entries in a page directory or page table.
+ * The hiberachy of page table is as below, which aligns hw names.
+ * PDB2->PDB1->PDB0->PTB, accordingly:
+ * level3 --- PDB2
+ * level2 --- PDB1
+ * level1 --- PDB0
+ * level0 --- PTB
   */
  static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
  				      unsigned level)
  {
-	unsigned shift = amdgpu_vm_level_shift(adev, 0);
+	unsigned shift = amdgpu_vm_level_shift(adev,
+					       adev->vm_manager.num_level);
 
-	if (level == 0)
+	if (level == adev->vm_manager.num_level)
  		/* For the root directory */
  		return round_up(adev->vm_manager.max_pfn, 1 << shift) >> shift;
-	else if (level != adev->vm_manager.num_level)
+	else if (level != 0)
  		/* Everything in between */
  		return 512;
  	else
-		/* For the page tables on the leaves */
+		/* For the page tables on the leaves(PTB) */
  		return AMDGPU_VM_PTE_COUNT(adev);
  }
 
@@ -312,6 +319,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
  	u64 flags;
  	uint64_t init_value = 0;
 
+	BUG_ON(level > adev->vm_manager.num_level);
+
  	if (!parent->entries) {
  		unsigned num_entries = amdgpu_vm_num_entries(adev, level);
 

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

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -332,7 +341,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
  	if (to > parent->last_entry_used)
  		parent->last_entry_used = to;
 
-	++level;
+	level--;

Post decrement/increment please.

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

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -1
  	saddr = saddr & ((1 << shift) - 1);
  	eaddr = eaddr & ((1 << shift) - 1);
 
@@ -346,7 +355,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 
  	if (vm->pte_support_ats) {
  		init_value = AMDGPU_PTE_DEFAULT_ATC;
-		if (level != adev->vm_manager.num_level - 1)

BTW: If I'm not completely mistaken that code is incorrect and should rather be "level != adev->vm_manager.num_level".

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

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -0
+		/* != PDB0 */
+		if (level != 1)

Which would that make it level != 0.

Regards,
Christian.

Quoted 35 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5 -4
  			init_value |= AMDGPU_PDE_PTE;
 
  	}
@@ -389,7 +399,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
  			entry->addr = 0;
  		}
 
-		if (level < adev->vm_manager.num_level) {
+		if (level > 0) {
  			uint64_t sub_saddr = (pt_idx == from) ? saddr : 0;
  			uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
  				((1 << shift) - 1);
@@ -435,7 +445,8 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
  	saddr /= AMDGPU_GPU_PAGE_SIZE;
  	eaddr /= AMDGPU_GPU_PAGE_SIZE;
 
-	return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr, 0);
+	return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
+				      adev->vm_manager.num_level);
  }
 
  /**
@@ -1319,19 +1330,19 @@ void amdgpu_vm_get_entry(struct amdgpu_pte_update_params *p, uint64_t addr,
  			 struct amdgpu_vm_pt **entry,
  			 struct amdgpu_vm_pt **parent)
  {
-	unsigned level = 0;
+	unsigned level = p->adev->vm_manager.num_level;
 
  	*parent = NULL;
  	*entry = &p->vm->root;
  	while ((*entry)->entries) {
-		unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level++);
+		unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level--);
 

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_get_entry(struct amdgpu_pte_update_params *p, uint64_t addr, · line 1348

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
  		idx %= amdgpu_bo_size((*entry)->base.bo) / 8;
  		*parent = *entry;
  		*entry = &(*entry)->entries[idx];
  	}
 
-	if (level != p->adev->vm_manager.num_level)
+	if (level != 0)
  		*entry = NULL;
  }
 

_______________________________________________
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): 957cec12-f5a6-16db-12d3-e3c39638afa6-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#9 lore raw
Quoted 8 lines · Christian König

Am 08.12.2017 um 11:56 schrieb Chunming Zhou:

Quoted 7 lines

The hiberachy of page table is as below, which aligns hw names. PDB2->PDB1->PDB0->PTB, accordingly:
level3 --- PDB2
level2 --- PDB1
level1 --- PDB0
level0 --- PTB

Quoted 4 lines
Quoted 2 lines
Change-Id I2d748e5e96cffe18294c104c4b192d910b2f8e6b

Yeah, thought about that as well. But I'm not sure if that is a good idea or not.

We should correct the confusing PDB0 concept, even spec directly uses it.

Quoted 58 lines
Quoted 58 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 37
++++++++++++++++++++++------------

  1 file changed, 24 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -2
index 3ecdbdfb04dd..8904ccf78fc9 100644
@@ -148,8 +148,8 @@ struct amdgpu_prt_cb {
   static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
                         unsigned level)
   {
-    if (level != adev->vm_manager.num_level)
-        return 9 * (adev->vm_manager.num_level - level - 1) +
+    if (level != 0)
+        return 9 * (level - 1) +
               adev->vm_manager.block_size;

      else
          /* For the page tables on the leaves */

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10 -2
@@ -162,20 +162,27 @@ static unsigned amdgpu_vm_level_shift(struct 
 amdgpu_device *adev,
    * @adev: amdgpu_device pointer
    *
    * Calculate the number of entries in a page directory or page table.
+ * The hiberachy of page table is as below, which aligns hw names.
+ * PDB2->PDB1->PDB0->PTB, accordingly:
+ * level3 --- PDB2
+ * level2 --- PDB1
+ * level1 --- PDB0
+ * level0 --- PTB
    */
   static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
                         unsigned level)
   {
-    unsigned shift = amdgpu_vm_level_shift(adev, 0);
+    unsigned shift = amdgpu_vm_level_shift(adev,
+                           adev->vm_manager.num_level);
   -    if (level == 0)
+    if (level == adev->vm_manager.num_level)
           /* For the root directory */
           return round_up(adev->vm_manager.max_pfn, 1 << shift) >> shift;
-    else if (level != adev->vm_manager.num_level)
+    else if (level != 0)
           /* Everything in between */
           return 512;

      else
-        /* For the page tables on the leaves */
+        /* For the page tables on the leaves(PTB) */
          return AMDGPU_VM_PTE_COUNT(adev);
  }
  @@ -312,6 +319,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, u64 flags;
      uint64_t init_value = 0;
  +    BUG_ON(level > adev->vm_manager.num_level);
+
      if (!parent->entries) {

Quoted 8 lines
Quoted 6 lines

          unsigned num_entries = amdgpu_vm_num_entries(adev, level); @@ -332,7 +341,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, if (to > parent->last_entry_used)
          parent->last_entry_used = to;
  -    ++level;
+    level--;

Post decrement/increment please.

it's OK, but what the difference of level--; and --level; is? which isn't in expression, but in alone line.

Quoted 9 lines
Quoted 7 lines

      saddr = saddr & ((1 << shift) - 1);
      eaddr = eaddr & ((1 << shift) - 1);
  @@ -346,7 +355,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, if (vm->pte_support_ats) {
          init_value = AMDGPU_PTE_DEFAULT_ATC;
-        if (level != adev->vm_manager.num_level - 1)

BTW: If I'm not completely mistaken that code is incorrect and should rather be "level != adev->vm_manager.num_level".

will separate a fix patch.

Regards,
David Zhou

Quoted 40 lines
Quoted 3 lines

+        /* != PDB0 */
+        if (level != 1)

Which would that make it level != 0.

Regards,
Christian.

Quoted 31 lines

              init_value |= AMDGPU_PDE_PTE;
        }

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -0
@@ -389,7 +399,7 @@ static int amdgpu_vm_alloc_levels(struct 
 amdgpu_device *adev,
               entry->addr = 0;
           }
   -        if (level < adev->vm_manager.num_level) {
+        if (level > 0) {
               uint64_t sub_saddr = (pt_idx == from) ? saddr : 0;

              uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
                  ((1 << shift) - 1);

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -2
@@ -435,7 +445,8 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
       saddr /= AMDGPU_GPU_PAGE_SIZE;
       eaddr /= AMDGPU_GPU_PAGE_SIZE;
   -    return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr, 0);
+    return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
+                      adev->vm_manager.num_level);
   }
     /**
@@ -1319,19 +1330,19 @@ void amdgpu_vm_get_entry(struct 
 amdgpu_pte_update_params *p, uint64_t addr,
                struct amdgpu_vm_pt **entry,
                struct amdgpu_vm_pt **parent)
   {
-    unsigned level = 0;
+    unsigned level = p->adev->vm_manager.num_level;
         *parent = NULL;
       *entry = &p->vm->root;
       while ((*entry)->entries) {
-        unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level++);
+        unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level--);
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_get_entry(struct amdgpu_pte_update_params *p, uint64_t addr, · line 1347

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -0
             idx %= amdgpu_bo_size((*entry)->base.bo) / 8;
           *parent = *entry;
           *entry = &(*entry)->entries[idx];
       }
   -    if (level != p->adev->vm_manager.num_level)
+    if (level != 0)
           *entry = NULL;
   }

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

#10 lore raw
In reply to a message not in the archive
Quoted 6 lines · Chunming Zhou

The hiberachy of page table is as below, which aligns hw names. PDB2->PDB1->PDB0->PTB, accordingly:
level3 --- PDB2
level2 --- PDB1
level1 --- PDB0
level0 --- PTB

What's the advantage of this change? It's not clear from the commit message.

Alex

Quoted 127 lines
Change-Id I2d748e5e96cffe18294c104c4b192d910b2f8e6b
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 37 ++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +24 -14
index 3ecdbdfb04dd..8904ccf78fc9 100644
@@ -148,8 +148,8 @@ struct amdgpu_prt_cb {
 static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
                                      unsigned level)
 {
-       if (level != adev->vm_manager.num_level)
-               return 9 * (adev->vm_manager.num_level - level - 1) +
+       if (level != 0)
+               return 9 * (level - 1) +
                        adev->vm_manager.block_size;
        else
                /* For the page tables on the leaves */
@@ -162,20 +162,27 @@ static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
  * @adev: amdgpu_device pointer
  *
  * Calculate the number of entries in a page directory or page table.
+ * The hiberachy of page table is as below, which aligns hw names.
+ * PDB2->PDB1->PDB0->PTB, accordingly:
+ * level3 --- PDB2
+ * level2 --- PDB1
+ * level1 --- PDB0
+ * level0 --- PTB
  */
 static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
                                      unsigned level)
 {
-       unsigned shift = amdgpu_vm_level_shift(adev, 0);
+       unsigned shift = amdgpu_vm_level_shift(adev,
+                                              adev->vm_manager.num_level);
 
-       if (level == 0)
+       if (level == adev->vm_manager.num_level)
                /* For the root directory */
                return round_up(adev->vm_manager.max_pfn, 1 << shift) >> shift;
-       else if (level != adev->vm_manager.num_level)
+       else if (level != 0)
                /* Everything in between */
                return 512;
        else
-               /* For the page tables on the leaves */
+               /* For the page tables on the leaves(PTB) */
                return AMDGPU_VM_PTE_COUNT(adev);
 }
 
@@ -312,6 +319,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
        u64 flags;
        uint64_t init_value = 0;
 
+       BUG_ON(level > adev->vm_manager.num_level);
+
        if (!parent->entries) {
                unsigned num_entries = amdgpu_vm_num_entries(adev, level);
 
@@ -332,7 +341,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
        if (to > parent->last_entry_used)
                parent->last_entry_used = to;
 
-       ++level;
+       level--;
        saddr = saddr & ((1 << shift) - 1);
        eaddr = eaddr & ((1 << shift) - 1);
 
@@ -346,7 +355,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 
        if (vm->pte_support_ats) {
                init_value = AMDGPU_PTE_DEFAULT_ATC;
-               if (level != adev->vm_manager.num_level - 1)
+               /* != PDB0 */
+               if (level != 1)
                        init_value |= AMDGPU_PDE_PTE;
 
        }
@@ -389,7 +399,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
                        entry->addr = 0;
                }
 
-               if (level < adev->vm_manager.num_level) {
+               if (level > 0) {
                        uint64_t sub_saddr = (pt_idx == from) ? saddr : 0;
                        uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
                                ((1 << shift) - 1);
@@ -435,7 +445,8 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
        saddr /= AMDGPU_GPU_PAGE_SIZE;
        eaddr /= AMDGPU_GPU_PAGE_SIZE;
 
-       return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr, 0);
+       return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
+                                     adev->vm_manager.num_level);
 }
 
 /**
@@ -1319,19 +1330,19 @@ void amdgpu_vm_get_entry(struct amdgpu_pte_update_params *p, uint64_t addr,
                         struct amdgpu_vm_pt **entry,
                         struct amdgpu_vm_pt **parent)
 {
-       unsigned level = 0;
+       unsigned level = p->adev->vm_manager.num_level;
 
        *parent = NULL;
        *entry = &p->vm->root;
        while ((*entry)->entries) {
-               unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level++);
+               unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level--);
 
                idx %= amdgpu_bo_size((*entry)->base.bo) / 8;
                *parent = *entry;
                *entry = &(*entry)->entries[idx];
        }
 
-       if (level != p->adev->vm_manager.num_level)
+       if (level != 0)
                *entry = NULL;
 }
 
--

2.14.1

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

A message that is not in the archive (sent off-list or not yet received): CADnq5_NmHKLi1kSa6NDC4feoHUZcmViML9eQvEX_M9UW-8Azww-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#12 lore raw

Am 08.12.2017 um 15:58 schrieb Alex Deucher:

Quoted 8 lines · Chunming Zhou
Quoted 6 lines

The hiberachy of page table is as below, which aligns hw names. PDB2->PDB1->PDB0->PTB, accordingly:
level3 --- PDB2
level2 --- PDB1
level1 --- PDB0
level0 --- PTB

What's the advantage of this change? It's not clear from the commit message.

Well you align a bit better with how our hardware guys tend to describe the levels.

But level0 becomes PTB and level1 becomes PDB0 etc..., so I don't think we win much here.

Christian.

Quoted 129 lines

Alex

Quoted 126 lines
Change-Id I2d748e5e96cffe18294c104c4b192d910b2f8e6b
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 37 ++++++++++++++++++++++------------
  1 file changed, 24 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +24 -14
index 3ecdbdfb04dd..8904ccf78fc9 100644
@@ -148,8 +148,8 @@ struct amdgpu_prt_cb {
  static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
                                       unsigned level)
  {
-       if (level != adev->vm_manager.num_level)
-               return 9 * (adev->vm_manager.num_level - level - 1) +
+       if (level != 0)
+               return 9 * (level - 1) +
                         adev->vm_manager.block_size;
         else
                 /* For the page tables on the leaves */
@@ -162,20 +162,27 @@ static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
   * @adev: amdgpu_device pointer
   *
   * Calculate the number of entries in a page directory or page table.
+ * The hiberachy of page table is as below, which aligns hw names.
+ * PDB2->PDB1->PDB0->PTB, accordingly:
+ * level3 --- PDB2
+ * level2 --- PDB1
+ * level1 --- PDB0
+ * level0 --- PTB
   */
  static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
                                       unsigned level)
  {
-       unsigned shift = amdgpu_vm_level_shift(adev, 0);
+       unsigned shift = amdgpu_vm_level_shift(adev,
+                                              adev->vm_manager.num_level);
 
-       if (level == 0)
+       if (level == adev->vm_manager.num_level)
                 /* For the root directory */
                 return round_up(adev->vm_manager.max_pfn, 1 << shift) >> shift;
-       else if (level != adev->vm_manager.num_level)
+       else if (level != 0)
                 /* Everything in between */
                 return 512;
         else
-               /* For the page tables on the leaves */
+               /* For the page tables on the leaves(PTB) */
                 return AMDGPU_VM_PTE_COUNT(adev);
  }
 
@@ -312,6 +319,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
         u64 flags;
         uint64_t init_value = 0;
 
+       BUG_ON(level > adev->vm_manager.num_level);
+
         if (!parent->entries) {
                 unsigned num_entries = amdgpu_vm_num_entries(adev, level);
 
@@ -332,7 +341,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
         if (to > parent->last_entry_used)
                 parent->last_entry_used = to;
 
-       ++level;
+       level--;
         saddr = saddr & ((1 << shift) - 1);
         eaddr = eaddr & ((1 << shift) - 1);
 
@@ -346,7 +355,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 
         if (vm->pte_support_ats) {
                 init_value = AMDGPU_PTE_DEFAULT_ATC;
-               if (level != adev->vm_manager.num_level - 1)
+               /* != PDB0 */
+               if (level != 1)
                         init_value |= AMDGPU_PDE_PTE;
 
         }
@@ -389,7 +399,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
                         entry->addr = 0;
                 }
 
-               if (level < adev->vm_manager.num_level) {
+               if (level > 0) {
                         uint64_t sub_saddr = (pt_idx == from) ? saddr : 0;
                         uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
                                 ((1 << shift) - 1);
@@ -435,7 +445,8 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
         saddr /= AMDGPU_GPU_PAGE_SIZE;
         eaddr /= AMDGPU_GPU_PAGE_SIZE;
 
-       return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr, 0);
+       return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
+                                     adev->vm_manager.num_level);
  }
 
  /**
@@ -1319,19 +1330,19 @@ void amdgpu_vm_get_entry(struct amdgpu_pte_update_params *p, uint64_t addr,
                          struct amdgpu_vm_pt **entry,
                          struct amdgpu_vm_pt **parent)
  {
-       unsigned level = 0;
+       unsigned level = p->adev->vm_manager.num_level;
 
         *parent = NULL;
         *entry = &p->vm->root;
         while ((*entry)->entries) {
-               unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level++);
+               unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level--);
 
                 idx %= amdgpu_bo_size((*entry)->base.bo) / 8;
                 *parent = *entry;
                 *entry = &(*entry)->entries[idx];
         }
 
-       if (level != p->adev->vm_manager.num_level)
+       if (level != 0)
                 *entry = NULL;
  }
 
--

2.14.1

Quoted 8 lines
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

_______________________________________________
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
Quoted 8 lines · Alex Deucher
Quoted 6 lines · Chunming Zhou

The hiberachy of page table is as below, which aligns hw names. PDB2->PDB1->PDB0->PTB, accordingly:
level3 --- PDB2
level2 --- PDB1
level1 --- PDB0
level0 --- PTB

What's the advantage of this change? It's not clear from the commit message.

Hi Alex,

previous the level is increasing, the root pdb is level0, not only me, also many people thought the root PDB is PDB0, but our many hw documents assume PDB0 is pointing to PTB, that is said, which bring us unnecessary trouble on understanding our VM hiberachy implementation, especially for ramp up beginner. For last Christian BLOCK_SIZE patch example, the spec said it only effects the PTB pointed by PDB0, but we initially thought it effects all levels, which mainly because of confuse 'PDB0'.

Above is my starting point.

Regards,
David Zhou

Quoted 126 lines

Alex

Quoted 123 lines
Change-Id I2d748e5e96cffe18294c104c4b192d910b2f8e6b
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 37 ++++++++++++++++++++++------------
  1 file changed, 24 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +24 -13
index 3ecdbdfb04dd..8904ccf78fc9 100644
@@ -148,8 +148,8 @@ struct amdgpu_prt_cb {
  static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
                                       unsigned level)
  {
-       if (level != adev->vm_manager.num_level)
-               return 9 * (adev->vm_manager.num_level - level - 1) +
+       if (level != 0)
+               return 9 * (level - 1) +
                         adev->vm_manager.block_size;
         else
                 /* For the page tables on the leaves */
@@ -162,20 +162,27 @@ static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
   * @adev: amdgpu_device pointer
   *
   * Calculate the number of entries in a page directory or page table.
+ * The hiberachy of page table is as below, which aligns hw names.
+ * PDB2->PDB1->PDB0->PTB, accordingly:
+ * level3 --- PDB2
+ * level2 --- PDB1
+ * level1 --- PDB0
+ * level0 --- PTB
   */
  static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
                                       unsigned level)
  {
-       unsigned shift = amdgpu_vm_level_shift(adev, 0);
+       unsigned shift = amdgpu_vm_level_shift(adev,
+                                              adev->vm_manager.num_level);
 
-       if (level == 0)
+       if (level == adev->vm_manager.num_level)
                 /* For the root directory */
                 return round_up(adev->vm_manager.max_pfn, 1 << shift) >> shift;
-       else if (level != adev->vm_manager.num_level)
+       else if (level != 0)
                 /* Everything in between */
                 return 512;
         else
-               /* For the page tables on the leaves */
+               /* For the page tables on the leaves(PTB) */
                 return AMDGPU_VM_PTE_COUNT(adev);
  }
 
@@ -312,6 +319,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
         u64 flags;
         uint64_t init_value = 0;
 
+       BUG_ON(level > adev->vm_manager.num_level);
+
         if (!parent->entries) {
                 unsigned num_entries = amdgpu_vm_num_entries(adev, level);
 
@@ -332,7 +341,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
         if (to > parent->last_entry_used)
                 parent->last_entry_used = to;
 
-       ++level;
+       level--;
         saddr = saddr & ((1 << shift) - 1);
         eaddr = eaddr & ((1 << shift) - 1);
 
@@ -346,7 +355,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 
         if (vm->pte_support_ats) {
                 init_value = AMDGPU_PTE_DEFAULT_ATC;
-               if (level != adev->vm_manager.num_level - 1)
+               /* != PDB0 */
+               if (level != 1)
                         init_value |= AMDGPU_PDE_PTE;
 
         }
@@ -389,7 +399,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
                         entry->addr = 0;
                 }
 
-               if (level < adev->vm_manager.num_level) {
+               if (level > 0) {
                         uint64_t sub_saddr = (pt_idx == from) ? saddr : 0;
                         uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
                                 ((1 << shift) - 1);
@@ -435,7 +445,8 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
         saddr /= AMDGPU_GPU_PAGE_SIZE;
         eaddr /= AMDGPU_GPU_PAGE_SIZE;
 
-       return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr, 0);
+       return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
+                                     adev->vm_manager.num_level);
  }
 
  /**
@@ -1319,19 +1330,19 @@ void amdgpu_vm_get_entry(struct amdgpu_pte_update_params *p, uint64_t addr,
                          struct amdgpu_vm_pt **entry,
                          struct amdgpu_vm_pt **parent)
  {
-       unsigned level = 0;
+       unsigned level = p->adev->vm_manager.num_level;
 
         *parent = NULL;
         *entry = &p->vm->root;
         while ((*entry)->entries) {
-               unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level++);
+               unsigned idx = addr >> amdgpu_vm_level_shift(p->adev, level--);
 
                 idx %= amdgpu_bo_size((*entry)->base.bo) / 8;
                 *parent = *entry;
                 *entry = &(*entry)->entries[idx];
         }
 
-       if (level != p->adev->vm_manager.num_level)
+       if (level != 0)
                 *entry = NULL;
  }
 
Quoted 7 lines
Quoted 7 lines

--
2.14.1

_______________________________________________
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

A message that is not in the archive (sent off-list or not yet received): 0321277c-e7f0-8d47-2951-21b9870194e2-5C7GfCeVMHo@public.gmane.org

#15 lore raw
Quoted 27 lines · Chunming Zhou
Quoted 10 lines · Alex Deucher
Quoted 7 lines · Chunming Zhou

The hiberachy of page table is as below, which aligns hw names. PDB2->PDB1->PDB0->PTB, accordingly:
level3 --- PDB2
level2 --- PDB1
level1 --- PDB0
level0 --- PTB

Quoted 2 lines

What's the advantage of this change? It's not clear from the commit message.

Hi Alex,

previous the level is increasing, the root pdb is level0, not only me, also many people thought the root PDB is PDB0, but our many hw documents assume PDB0 is pointing to PTB, that is said, which bring us unnecessary trouble on understanding our VM hiberachy implementation, especially for ramp up beginner.
For last Christian BLOCK_SIZE patch example, the spec said it only effects the PTB pointed by PDB0, but we initially thought it effects all levels, which mainly because of confuse 'PDB0'.

Quoted 1 line

Above is my starting point.

Thanks for clarifying. Please include that information in the commit message for clarity.

Alex

Quoted 145 lines

Regards,
David Zhou

Quoted 141 lines

Alex

Quoted 138 lines
Change-Id I2d748e5e96cffe18294c104c4b192d910b2f8e6b
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 37
++++++++++++++++++++++------------
  1 file changed, 24 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +13 -6
index 3ecdbdfb04dd..8904ccf78fc9 100644
@@ -148,8 +148,8 @@ struct amdgpu_prt_cb {
  static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
                                       unsigned level)
  {
-       if (level != adev->vm_manager.num_level)
-               return 9 * (adev->vm_manager.num_level - level - 1) +
+       if (level != 0)
+               return 9 * (level - 1) +
                         adev->vm_manager.block_size;
         else
                 /* For the page tables on the leaves */
@@ -162,20 +162,27 @@ static unsigned amdgpu_vm_level_shift(struct
 amdgpu_device *adev,
   * @adev: amdgpu_device pointer
   *
   * Calculate the number of entries in a page directory or page table.
+ * The hiberachy of page table is as below, which aligns hw names.
+ * PDB2->PDB1->PDB0->PTB, accordingly:
+ * level3 --- PDB2
+ * level2 --- PDB1
+ * level1 --- PDB0
+ * level0 --- PTB
   */
  static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
                                       unsigned level)
  {
-       unsigned shift = amdgpu_vm_level_shift(adev, 0);
+       unsigned shift = amdgpu_vm_level_shift(adev,
+
 adev->vm_manager.num_level);
 
-       if (level == 0)
+       if (level == adev->vm_manager.num_level)
                 /* For the root directory */
                 return round_up(adev->vm_manager.max_pfn, 1 << shift) >>
 shift;
-       else if (level != adev->vm_manager.num_level)
+       else if (level != 0)
                 /* Everything in between */
                 return 512;
         else
-               /* For the page tables on the leaves */
+               /* For the page tables on the leaves(PTB) */
                 return AMDGPU_VM_PTE_COUNT(adev);

}

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -0
@@ -312,6 +319,8 @@ static int amdgpu_vm_alloc_levels(struct
 amdgpu_device *adev,
         u64 flags;
         uint64_t init_value = 0;
 
+       BUG_ON(level > adev->vm_manager.num_level);
+
         if (!parent->entries) {
                 unsigned num_entries = amdgpu_vm_num_entries(adev,

level);

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -2
@@ -332,7 +341,7 @@ static int amdgpu_vm_alloc_levels(struct
 amdgpu_device *adev,
         if (to > parent->last_entry_used)
                 parent->last_entry_used = to;
 
-       ++level;
+       level--;
         saddr = saddr & ((1 << shift) - 1);
         eaddr = eaddr & ((1 << shift) - 1);
@@ -346,7 +355,8 @@ static int amdgpu_vm_alloc_levels(struct
 amdgpu_device *adev,
 
         if (vm->pte_support_ats) {
                 init_value = AMDGPU_PTE_DEFAULT_ATC;
-               if (level != adev->vm_manager.num_level - 1)
+               /* != PDB0 */
+               if (level != 1)
                         init_value |= AMDGPU_PDE_PTE;
 
         }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -389,7 +399,7 @@ static int amdgpu_vm_alloc_levels(struct
 amdgpu_device *adev,
                         entry->addr = 0;
                 }
 
-               if (level < adev->vm_manager.num_level) {
+               if (level > 0) {
                         uint64_t sub_saddr = (pt_idx == from) ? saddr :
 0;
                         uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
                                 ((1 << shift) - 1);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -1
@@ -435,7 +445,8 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
         saddr /= AMDGPU_GPU_PAGE_SIZE;
         eaddr /= AMDGPU_GPU_PAGE_SIZE;
 
-       return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
 0);
+       return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
+                                     adev->vm_manager.num_level);
  }
 

/**

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -3
@@ -1319,19 +1330,19 @@ void amdgpu_vm_get_entry(struct
 amdgpu_pte_update_params *p, uint64_t addr,
                          struct amdgpu_vm_pt **entry,
                          struct amdgpu_vm_pt **parent)
  {
-       unsigned level = 0;
+       unsigned level = p->adev->vm_manager.num_level;
 
         *parent = NULL;
         *entry = &p->vm->root;
         while ((*entry)->entries) {
-               unsigned idx = addr >> amdgpu_vm_level_shift(p->adev,
 level++);
+               unsigned idx = addr >> amdgpu_vm_level_shift(p->adev,
 level--);
 
                 idx %= amdgpu_bo_size((*entry)->base.bo) / 8;
                 *parent = *entry;
                 *entry = &(*entry)->entries[idx];
         }
 
-       if (level != p->adev->vm_manager.num_level)
+       if (level != 0)
                 *entry = NULL;

}

Quoted 9 lines
Quoted 7 lines
Quoted 7 lines

--
2.14.1

_______________________________________________
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

A message that is not in the archive (sent off-list or not yet received): CADnq5_NYVOVqK1f_Re0ibyR7ROHxW9sP+i6Vnt5F8OEGxSxVrA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#17 lore raw

Am 11.12.2017 um 04:55 schrieb Alex Deucher:

Quoted 23 lines · Chunming Zhou
Quoted 22 lines · Alex Deucher
Quoted 9 lines · Chunming Zhou
Quoted 6 lines

The hiberachy of page table is as below, which aligns hw names. PDB2->PDB1->PDB0->PTB, accordingly:
level3 --- PDB2
level2 --- PDB1
level1 --- PDB0
level0 --- PTB

What's the advantage of this change? It's not clear from the commit message.

Hi Alex,

previous the level is increasing, the root pdb is level0, not only me, also many people thought the root PDB is PDB0, but our many hw documents assume PDB0 is pointing to PTB, that is said, which bring us unnecessary trouble on understanding our VM hiberachy implementation, especially for ramp up beginner.
For last Christian BLOCK_SIZE patch example, the spec said it only effects the PTB pointed by PDB0, but we initially thought it effects all levels, which mainly because of confuse 'PDB0'.

Quoted 3 lines
Quoted 1 line

Above is my starting point.

Thanks for clarifying. Please include that information in the commit message for clarity.

We should document this, but I would keep the code as it is cause mapping level1 to PDB0 doesn't make it any clearer if you ask me.

And additional to that as you said as well most people assume that zero is the root page table.

The only people who doesn't do that are our hardware developers (and I honestly doesn't understand why, cause this causes confusion all over the place even internally to AMD).

Another problem are the page directory start value which is written into the registers on Vega10. Those reassemble a page directory entry and I referenced them as level -1 in the latest patches.

Ok we could change that to 0xff as well, but I find that even more confusing.

Christian.

Quoted 154 lines

Alex

Quoted 143 lines

Regards,
David Zhou

Quoted 140 lines

Alex

Quoted 138 lines
Change-Id I2d748e5e96cffe18294c104c4b192d910b2f8e6b
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 37
++++++++++++++++++++++------------
   1 file changed, 24 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +13 -6
index 3ecdbdfb04dd..8904ccf78fc9 100644
@@ -148,8 +148,8 @@ struct amdgpu_prt_cb {
   static unsigned amdgpu_vm_level_shift(struct amdgpu_device *adev,
                                        unsigned level)
   {
-       if (level != adev->vm_manager.num_level)
-               return 9 * (adev->vm_manager.num_level - level - 1) +
+       if (level != 0)
+               return 9 * (level - 1) +
                          adev->vm_manager.block_size;
          else
                  /* For the page tables on the leaves */
@@ -162,20 +162,27 @@ static unsigned amdgpu_vm_level_shift(struct
 amdgpu_device *adev,
    * @adev: amdgpu_device pointer
    *
    * Calculate the number of entries in a page directory or page table.
+ * The hiberachy of page table is as below, which aligns hw names.
+ * PDB2->PDB1->PDB0->PTB, accordingly:
+ * level3 --- PDB2
+ * level2 --- PDB1
+ * level1 --- PDB0
+ * level0 --- PTB
    */
   static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
                                        unsigned level)
   {
-       unsigned shift = amdgpu_vm_level_shift(adev, 0);
+       unsigned shift = amdgpu_vm_level_shift(adev,
+
 adev->vm_manager.num_level);
 
-       if (level == 0)
+       if (level == adev->vm_manager.num_level)
                  /* For the root directory */
                  return round_up(adev->vm_manager.max_pfn, 1 << shift) >>
 shift;
-       else if (level != adev->vm_manager.num_level)
+       else if (level != 0)
                  /* Everything in between */
                  return 512;
          else
-               /* For the page tables on the leaves */
+               /* For the page tables on the leaves(PTB) */
                  return AMDGPU_VM_PTE_COUNT(adev);

}

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -0
@@ -312,6 +319,8 @@ static int amdgpu_vm_alloc_levels(struct
 amdgpu_device *adev,
          u64 flags;
          uint64_t init_value = 0;
 
+       BUG_ON(level > adev->vm_manager.num_level);
+
          if (!parent->entries) {
                  unsigned num_entries = amdgpu_vm_num_entries(adev,

level);

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -2
@@ -332,7 +341,7 @@ static int amdgpu_vm_alloc_levels(struct
 amdgpu_device *adev,
          if (to > parent->last_entry_used)
                  parent->last_entry_used = to;
 
-       ++level;
+       level--;
          saddr = saddr & ((1 << shift) - 1);
          eaddr = eaddr & ((1 << shift) - 1);
@@ -346,7 +355,8 @@ static int amdgpu_vm_alloc_levels(struct
 amdgpu_device *adev,
 
          if (vm->pte_support_ats) {
                  init_value = AMDGPU_PTE_DEFAULT_ATC;
-               if (level != adev->vm_manager.num_level - 1)
+               /* != PDB0 */
+               if (level != 1)
                          init_value |= AMDGPU_PDE_PTE;
 
          }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -389,7 +399,7 @@ static int amdgpu_vm_alloc_levels(struct
 amdgpu_device *adev,
                          entry->addr = 0;
                  }
 
-               if (level < adev->vm_manager.num_level) {
+               if (level > 0) {
                          uint64_t sub_saddr = (pt_idx == from) ? saddr :
 0;
                          uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
                                  ((1 << shift) - 1);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -1
@@ -435,7 +445,8 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
          saddr /= AMDGPU_GPU_PAGE_SIZE;
          eaddr /= AMDGPU_GPU_PAGE_SIZE;
 
-       return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
 0);
+       return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
+                                     adev->vm_manager.num_level);
   }
 
   /**
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -3
@@ -1319,19 +1330,19 @@ void amdgpu_vm_get_entry(struct
 amdgpu_pte_update_params *p, uint64_t addr,
                           struct amdgpu_vm_pt **entry,
                           struct amdgpu_vm_pt **parent)
   {
-       unsigned level = 0;
+       unsigned level = p->adev->vm_manager.num_level;
 
          *parent = NULL;
          *entry = &p->vm->root;
          while ((*entry)->entries) {
-               unsigned idx = addr >> amdgpu_vm_level_shift(p->adev,
 level++);
+               unsigned idx = addr >> amdgpu_vm_level_shift(p->adev,
 level--);
 
                  idx %= amdgpu_bo_size((*entry)->base.bo) / 8;
                  *parent = *entry;
                  *entry = &(*entry)->entries[idx];
          }
 
-       if (level != p->adev->vm_manager.num_level)
+       if (level != 0)
                  *entry = NULL;

}

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

--
2.14.1

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

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