Skip to contentSkip to conversation

drm/amdkfd: Use atomic64_t type for pdd->tlb_seq

PATCH In review Philip Yang 2 participants 2 messages Mar 28, 2022 – Mar 29, 2022

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

PATCH v3 1/1 drm/amdkfd: Use atomic64_t type for pdd->tlb_seq

To support multi-thread update page table.

---
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -1
index 945982a5d688..e1b7e6afa920 100644
@@ -705,7 +705,7 @@ struct kfd_process_device {
 	/* VM context for GPUVM allocations */
 	struct file *drm_file;
 	void *drm_priv;
-	uint64_t tlb_seq;
+	atomic64_t tlb_seq;
 
 	/* GPUVM allocations storage */
 	struct idr alloc_idr;
drivers/gpu/drm/amd/amdkfd/kfd_process.c +2 -3
index ac8123c1ee8f..267ba8c434c0 100644
@@ -1560,7 +1560,7 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
 		return ret;
 	}
 	pdd->drm_priv = drm_file->private_data;
-	pdd->tlb_seq = 0;
+	atomic64_set(&pdd->tlb_seq, 0);
 
 	ret = kfd_process_device_reserve_ib_mem(pdd);
 	if (ret)
@@ -1954,10 +1954,9 @@ void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type)
 	uint64_t tlb_seq = amdgpu_vm_tlb_seq(vm);
 	struct kfd_dev *dev = pdd->dev;
 
-	if (pdd->tlb_seq == tlb_seq)
+	if (atomic64_xchg(&pdd->tlb_seq, tlb_seq) == tlb_seq)
 		return;
 
-	pdd->tlb_seq = tlb_seq;
 	if (dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS) {
 		/* Nothing to flush until a VMID is assigned, which
 		 * only happens when the first queue is created.
Signature · 1 line
2.35.1
maintainer
#1 lore raw

Am 28.03.22 um 23:19 schrieb Philip Yang:

Quoted 3 lines

To support multi-thread update page table.

One nit comment below, but patch is Reviewed-by: Christian König <[email protected]> anyway.

Quoted 32 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 2 +-
  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 5 ++---
  2 files changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -1
index 945982a5d688..e1b7e6afa920 100644
@@ -705,7 +705,7 @@ struct kfd_process_device {
  	/* VM context for GPUVM allocations */
  	struct file *drm_file;
  	void *drm_priv;
-	uint64_t tlb_seq;
+	atomic64_t tlb_seq;
 
  	/* GPUVM allocations storage */
  	struct idr alloc_idr;
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
index ac8123c1ee8f..267ba8c434c0 100644
@@ -1560,7 +1560,7 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
  		return ret;
  	}
  	pdd->drm_priv = drm_file->private_data;
-	pdd->tlb_seq = 0;
+	atomic64_set(&pdd->tlb_seq, 0);
 
  	ret = kfd_process_device_reserve_ib_mem(pdd);
  	if (ret)

drivers/gpu/drm/amd/amdkfd/kfd_process.c void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type) · line 1958

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
@@ -1954,10 +1954,9 @@ void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type)
  	uint64_t tlb_seq = amdgpu_vm_tlb_seq(vm);
  	struct kfd_dev *dev = pdd->dev;
 
-	if (pdd->tlb_seq == tlb_seq)
+	if (atomic64_xchg(&pdd->tlb_seq, tlb_seq) == tlb_seq)
  		return;

It can be that we race and lose here, but that is extremely unlikely and the worst thing which could happen is that we flush the changes into the TLB once more which is harmless.

Might be a good idea to note that in a comment.

Regards,
Christian.

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -1
-	pdd->tlb_seq = tlb_seq;
  	if (dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS) {
  		/* Nothing to flush until a VMID is assigned, which
  		 * only happens when the first queue is created.