Skip to contentSkip to conversation

drm/amdgpu: Wait for newly allocated PTs to be idle

PATCH In review Kuehling, Felix 4 participants 5 messages Mar 12, 2019 – Mar 13, 2019 3 messages not in the archive

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

PATCH 1/1 drm/amdgpu: Wait for newly allocated PTs to be idle

When page table are updated by the CPU, synchronize with the allocation and initialization of newly allocated page tables.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +13 -7
index 8603c85..4303436 100644
@@ -899,17 +899,17 @@ static void amdgpu_vm_bo_param(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 }
 
 /**
- * amdgpu_vm_alloc_pts - Allocate page tables.
+ * amdgpu_vm_alloc_pts - Allocate a specific page table
  *
  * @adev: amdgpu_device pointer
  * @vm: VM to allocate page tables for
- * @saddr: Start address which needs to be allocated
- * @size: Size from start address we need.
+ * @cursor: Which page table to allocate
  *
- * Make sure the page directories and page tables are allocated
+ * Make sure a specific page table or directory is allocated.
  *
  * Returns:
- * 0 on success, errno otherwise.
+ * 1 if page table needed to be allocated, 0 if page table was already
+ * allocated, negative errno if an error occurred.
  */
 static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 			       struct amdgpu_vm *vm,
@@ -956,7 +956,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 	if (r)
 		goto error_free_pt;
 
-	return 0;
+	return 1;
 
 error_free_pt:
 	amdgpu_bo_unref(&pt->shadow);
@@ -1621,10 +1621,12 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
 		unsigned shift, parent_shift, mask;
 		uint64_t incr, entry_end, pe_start;
 		struct amdgpu_bo *pt;
+		bool need_to_sync;
 
 		r = amdgpu_vm_alloc_pts(params->adev, params->vm, &cursor);
-		if (r)
+		if (r < 0)
 			return r;
+		need_to_sync = (r && params->vm->use_cpu_for_update);
 
 		pt = cursor.entry->base.bo;
 
@@ -1672,6 +1674,10 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
 		entry_end += cursor.pfn & ~(entry_end - 1);
 		entry_end = min(entry_end, end);
 
+		if (need_to_sync)
+			r = amdgpu_bo_sync_wait(params->vm->root.base.bo,
+						AMDGPU_FENCE_OWNER_VM, true);
+
 		do {
 			uint64_t upd_end = min(entry_end, frag_end);
 			unsigned nptes = (upd_end - frag_start) >> shift;
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): 1552425601-19017-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org

#2 lore raw

Hi,

I think even use SDMA to update PTE we may still need to wait the clear job to be completed if we can not guarantee the clear and set PTE job will use the exact same SDMA engine ( Did we use a dedicate SDMA engine for PTE update including clear? ).  But if we didn't use the  same engine , it may explain why the  test failed occasionally.

Regards

shaoyun.liu

Quoted 59 lines · Felix

When page table are updated by the CPU, synchronize with the allocation and initialization of newly allocated page tables.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 20 +++++++++++++-------
  1 file changed, 13 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9 -7
index 8603c85..4303436 100644
@@ -899,17 +899,17 @@ static void amdgpu_vm_bo_param(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  }
 
  /**
- * amdgpu_vm_alloc_pts - Allocate page tables.
+ * amdgpu_vm_alloc_pts - Allocate a specific page table
   *
   * @adev: amdgpu_device pointer
   * @vm: VM to allocate page tables for
- * @saddr: Start address which needs to be allocated
- * @size: Size from start address we need.
+ * @cursor: Which page table to allocate
   *
- * Make sure the page directories and page tables are allocated
+ * Make sure a specific page table or directory is allocated.
   *
   * Returns:
- * 0 on success, errno otherwise.
+ * 1 if page table needed to be allocated, 0 if page table was already
+ * allocated, negative errno if an error occurred.
   */
  static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
  			       struct amdgpu_vm *vm,
@@ -956,7 +956,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
  	if (r)
  		goto error_free_pt;
 
-	return 0;
+	return 1;
 
  error_free_pt:
  	amdgpu_bo_unref(&pt->shadow);
@@ -1621,10 +1621,12 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
  		unsigned shift, parent_shift, mask;
  		uint64_t incr, entry_end, pe_start;
  		struct amdgpu_bo *pt;
+		bool need_to_sync;
 
  		r = amdgpu_vm_alloc_pts(params->adev, params->vm, &cursor);
-		if (r)
+		if (r < 0)
  			return r;
+		need_to_sync = (r && params->vm->use_cpu_for_update);
 
  		pt = cursor.entry->base.bo;
 

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, · line 1683

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
@@ -1672,6 +1674,10 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
  		entry_end += cursor.pfn & ~(entry_end - 1);
  		entry_end = min(entry_end, end);
 
+		if (need_to_sync)
+			r = amdgpu_bo_sync_wait(params->vm->root.base.bo,
+						AMDGPU_FENCE_OWNER_VM, true);
+
  		do {
  			uint64_t upd_end = min(entry_end, frag_end);
  			unsigned nptes = (upd_end - frag_start) >> shift;

_______________________________________________
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): 48e8489f-0ea3-9a4b-2e22-24eb5afc02af-5C7GfCeVMHo@public.gmane.org

#4 lore raw

When we use SDMA, we don't wait on the CPU. The GPU scheduler waits for the fences on the root PD reservation before executing the SDMA IB. amdgpu_vm_bo_update_mapping gets those fences and builds the sync object for the scheduler after all the page tables have been allocated, so it should be no problem.

Regards,
  Felix

Quoted 77 lines · Shaoyun

Hi,

I think even use SDMA to update PTE we may still need to wait the clear job to be completed if we can not guarantee the clear and set PTE job will use the exact same SDMA engine ( Did we use a dedicate SDMA engine for PTE update including clear? ).  But if we didn't use the  same engine , it may explain why the  test failed occasionally.

Regards

shaoyun.liu

Quoted 62 lines · Felix

When page table are updated by the CPU, synchronize with the allocation and initialization of newly allocated page tables.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 20 +++++++++++++-------
   1 file changed, 13 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9 -7
index 8603c85..4303436 100644
@@ -899,17 +899,17 @@ static void amdgpu_vm_bo_param(struct amdgpu_device *adev, struct amdgpu_vm *vm,
   }
 
   /**
- * amdgpu_vm_alloc_pts - Allocate page tables.
+ * amdgpu_vm_alloc_pts - Allocate a specific page table
    *
    * @adev: amdgpu_device pointer
    * @vm: VM to allocate page tables for
- * @saddr: Start address which needs to be allocated
- * @size: Size from start address we need.
+ * @cursor: Which page table to allocate
    *
- * Make sure the page directories and page tables are allocated
+ * Make sure a specific page table or directory is allocated.
    *
    * Returns:
- * 0 on success, errno otherwise.
+ * 1 if page table needed to be allocated, 0 if page table was already
+ * allocated, negative errno if an error occurred.
    */
   static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
   			       struct amdgpu_vm *vm,
@@ -956,7 +956,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
   	if (r)
   		goto error_free_pt;
 
-	return 0;
+	return 1;
 
   error_free_pt:
   	amdgpu_bo_unref(&pt->shadow);
@@ -1621,10 +1621,12 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
   		unsigned shift, parent_shift, mask;
   		uint64_t incr, entry_end, pe_start;
   		struct amdgpu_bo *pt;
+		bool need_to_sync;
 
   		r = amdgpu_vm_alloc_pts(params->adev, params->vm, &cursor);
-		if (r)
+		if (r < 0)
   			return r;
+		need_to_sync = (r && params->vm->use_cpu_for_update);
 
   		pt = cursor.entry->base.bo;
 
@@ -1672,6 +1674,10 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
   		entry_end += cursor.pfn & ~(entry_end - 1);
   		entry_end = min(entry_end, end);
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, · line 1683

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
+		if (need_to_sync)
+			r = amdgpu_bo_sync_wait(params->vm->root.base.bo,
+						AMDGPU_FENCE_OWNER_VM, true);
+
   		do {
   			uint64_t upd_end = min(entry_end, frag_end);
   			unsigned nptes = (upd_end - frag_start) >> shift;

_______________________________________________
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): bdc4ce84-894c-93de-f4c9-390c0a44ccb9-5C7GfCeVMHo@public.gmane.org

#6 lore raw

All commands updating the page tables are pushed through the same scheduler entity.

And that one makes sure that they are all executed on the same SDMA engine.

Switching of entities between engines happens only when the entities are idle.

Regards,
Christian.

Am 13.03.19 um 00:36 schrieb Kuehling, Felix:

Quoted 87 lines

When we use SDMA, we don't wait on the CPU. The GPU scheduler waits for the fences on the root PD reservation before executing the SDMA IB. amdgpu_vm_bo_update_mapping gets those fences and builds the sync object for the scheduler after all the page tables have been allocated, so it should be no problem.

Regards,
  Felix

Quoted 77 lines · Shaoyun

Hi,

I think even use SDMA to update PTE we may still need to wait the clear job to be completed if we can not guarantee the clear and set PTE job will use the exact same SDMA engine ( Did we use a dedicate SDMA engine for PTE update including clear? ).  But if we didn't use the  same engine , it may explain why the  test failed occasionally.

Regards

shaoyun.liu

Quoted 62 lines · Felix

When page table are updated by the CPU, synchronize with the allocation and initialization of newly allocated page tables.

---
    drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 20 +++++++++++++-------
    1 file changed, 13 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9 -7
index 8603c85..4303436 100644
@@ -899,17 +899,17 @@ static void amdgpu_vm_bo_param(struct amdgpu_device *adev, struct amdgpu_vm *vm,
    }
 
    /**
- * amdgpu_vm_alloc_pts - Allocate page tables.
+ * amdgpu_vm_alloc_pts - Allocate a specific page table
     *
     * @adev: amdgpu_device pointer
     * @vm: VM to allocate page tables for
- * @saddr: Start address which needs to be allocated
- * @size: Size from start address we need.
+ * @cursor: Which page table to allocate
     *
- * Make sure the page directories and page tables are allocated
+ * Make sure a specific page table or directory is allocated.
     *
     * Returns:
- * 0 on success, errno otherwise.
+ * 1 if page table needed to be allocated, 0 if page table was already
+ * allocated, negative errno if an error occurred.
     */
    static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
    			       struct amdgpu_vm *vm,
@@ -956,7 +956,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
    	if (r)
    		goto error_free_pt;
 
-	return 0;
+	return 1;
 
    error_free_pt:
    	amdgpu_bo_unref(&pt->shadow);
@@ -1621,10 +1621,12 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
    		unsigned shift, parent_shift, mask;
    		uint64_t incr, entry_end, pe_start;
    		struct amdgpu_bo *pt;
+		bool need_to_sync;
 
    		r = amdgpu_vm_alloc_pts(params->adev, params->vm, &cursor);
-		if (r)
+		if (r < 0)
    			return r;
+		need_to_sync = (r && params->vm->use_cpu_for_update);
 
    		pt = cursor.entry->base.bo;
 
@@ -1672,6 +1674,10 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
    		entry_end += cursor.pfn & ~(entry_end - 1);
    		entry_end = min(entry_end, end);
 
Quoted 11 lines
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, · line 1683

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
+		if (need_to_sync)
+			r = amdgpu_bo_sync_wait(params->vm->root.base.bo,
+						AMDGPU_FENCE_OWNER_VM, true);
+
    		do {
    			uint64_t upd_end = min(entry_end, frag_end);
    			unsigned nptes = (upd_end - frag_start) >> shift;

_______________________________________________
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

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

Am 12.03.19 um 22:20 schrieb Kuehling, Felix:

Quoted 2 lines

When page table are updated by the CPU, synchronize with the allocation and initialization of newly allocated page tables.

Really good catch, didn't thought about that fully when writing the original patch.

Would you mind if instead of this patch we do the initial clearing of the PDs/PTs with the CPU as well?

Quoted 2 lines

Anyway patch is Reviewed-by: Christian König <[email protected]> for now.

Regards,
Christian.

Quoted 55 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 20 +++++++++++++-------
  1 file changed, 13 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9 -7
index 8603c85..4303436 100644
@@ -899,17 +899,17 @@ static void amdgpu_vm_bo_param(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  }
 
  /**
- * amdgpu_vm_alloc_pts - Allocate page tables.
+ * amdgpu_vm_alloc_pts - Allocate a specific page table
   *
   * @adev: amdgpu_device pointer
   * @vm: VM to allocate page tables for
- * @saddr: Start address which needs to be allocated
- * @size: Size from start address we need.
+ * @cursor: Which page table to allocate
   *
- * Make sure the page directories and page tables are allocated
+ * Make sure a specific page table or directory is allocated.
   *
   * Returns:
- * 0 on success, errno otherwise.
+ * 1 if page table needed to be allocated, 0 if page table was already
+ * allocated, negative errno if an error occurred.
   */
  static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
  			       struct amdgpu_vm *vm,
@@ -956,7 +956,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
  	if (r)
  		goto error_free_pt;
 
-	return 0;
+	return 1;
 
  error_free_pt:
  	amdgpu_bo_unref(&pt->shadow);
@@ -1621,10 +1621,12 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
  		unsigned shift, parent_shift, mask;
  		uint64_t incr, entry_end, pe_start;
  		struct amdgpu_bo *pt;
+		bool need_to_sync;
 
  		r = amdgpu_vm_alloc_pts(params->adev, params->vm, &cursor);
-		if (r)
+		if (r < 0)
  			return r;
+		need_to_sync = (r && params->vm->use_cpu_for_update);
 
  		pt = cursor.entry->base.bo;
 

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, · line 1683

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
@@ -1672,6 +1674,10 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
  		entry_end += cursor.pfn & ~(entry_end - 1);
  		entry_end = min(entry_end, end);
 
+		if (need_to_sync)
+			r = amdgpu_bo_sync_wait(params->vm->root.base.bo,
+						AMDGPU_FENCE_OWNER_VM, true);
+
  		do {
  			uint64_t upd_end = min(entry_end, frag_end);
  			unsigned nptes = (upd_end - frag_start) >> shift;

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