Skip to contentSkip to conversation

drm/amdgpu: Use polling for KIQ read/write register

PATCH In review Shaoyun Liu 2 participants 2 messages Jun 30, 2017 – Jul 2, 2017 1 message not in the archive

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

PATCH 3/3 drm/amdgpu: Use polling for KIQ read/write register

Change-Id I87762bfc9903401ac06892bed10efa1767c15025
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 47 +++++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +34 -13
index a65e76c..06ef893 100644
@@ -116,24 +116,33 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg)
 {
 	signed long r;
 	uint32_t val;
-	struct dma_fence *f;
 	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
 	struct amdgpu_ring *ring = &kiq->ring;
+	unsigned long end_jiffies;
+	uint32_t seq;
+	volatile uint32_t *f;
 
 	BUG_ON(!ring->funcs->emit_rreg);
 
 	spin_lock(&kiq->ring_lock);
 	amdgpu_ring_alloc(ring, 32);
 	amdgpu_ring_emit_rreg(ring, reg);
-	amdgpu_fence_emit(ring, &f);
+	f = amdgpu_fence_drv_cpu_addr(ring);
+	*f = 0;
+	seq = ++ring->fence_drv.sync_seq;
+	amdgpu_ring_emit_fence(ring, amdgpu_fence_drv_gpu_addr(ring), seq, 0);
 	amdgpu_ring_commit(ring);
 	spin_unlock(&kiq->ring_lock);
 
-	r = dma_fence_wait_timeout(f, false, msecs_to_jiffies(MAX_KIQ_REG_WAIT));
-	dma_fence_put(f);
-	if (r < 1) {
-		DRM_ERROR("wait for kiq fence error: %ld.\n", r);
-		return ~0;
+	end_jiffies = (MAX_KIQ_REG_WAIT * HZ / 1000) + jiffies;
+	while (true) {
+		if (*f >= seq)
+			break;
+		if (time_after(jiffies, end_jiffies)) {
+			DRM_ERROR("wait for kiq fence error: %ld.\n", r);
+			return ~0;
+		}
+		cpu_relax();
 	}
 
 	val = adev->wb.wb[adev->virt.reg_val_offs];
@@ -144,23 +153,35 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg)
 void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
 {
 	signed long r;
-	struct dma_fence *f;
 	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
 	struct amdgpu_ring *ring = &kiq->ring;
+	unsigned long end_jiffies;
+	uint32_t seq;
+	volatile uint32_t *f;
 
 	BUG_ON(!ring->funcs->emit_wreg);
 
 	spin_lock(&kiq->ring_lock);
 	amdgpu_ring_alloc(ring, 32);
 	amdgpu_ring_emit_wreg(ring, reg, v);
-	amdgpu_fence_emit(ring, &f);
+	f = amdgpu_fence_drv_cpu_addr(ring);
+	*f = 0;
+	seq = ++ring->fence_drv.sync_seq;
+	amdgpu_ring_emit_fence(ring, amdgpu_fence_drv_gpu_addr(ring), seq, 0);
 	amdgpu_ring_commit(ring);
 	spin_unlock(&kiq->ring_lock);
 
-	r = dma_fence_wait_timeout(f, false, msecs_to_jiffies(MAX_KIQ_REG_WAIT));
-	if (r < 1)
-		DRM_ERROR("wait for kiq fence error: %ld.\n", r);
-	dma_fence_put(f);
+	end_jiffies = (MAX_KIQ_REG_WAIT * HZ / 1000) + jiffies;
+	while (true) {
+		if (*f >= seq)
+			break;
+		if (time_after(jiffies, end_jiffies)) {
+			DRM_ERROR("wait for kiq fence error: %ld.\n", r);
+			return;
+		}
+		cpu_relax();
+	}
+
 }
 
 /**
Signature · 6 lines
1.9.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): 1498838052-15608-1-git-send-email-Shaoyun.Liu-5C7GfCeVMHo@public.gmane.org

#2 lore raw

Am 30.06.2017 um 17:54 schrieb Shaoyun Liu:

Quoted 19 lines
Change-Id I87762bfc9903401ac06892bed10efa1767c15025
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 47 +++++++++++++++++++++++---------
  1 file changed, 34 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2 -1
index a65e76c..06ef893 100644
@@ -116,24 +116,33 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg)
  {
  	signed long r;
  	uint32_t val;
-	struct dma_fence *f;
  	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
  	struct amdgpu_ring *ring = &kiq->ring;
+	unsigned long end_jiffies;
+	uint32_t seq;

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) · line 131

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +3 -1
+	volatile uint32_t *f;
 
  	BUG_ON(!ring->funcs->emit_rreg);
 
  	spin_lock(&kiq->ring_lock);
  	amdgpu_ring_alloc(ring, 32);
  	amdgpu_ring_emit_rreg(ring, reg);
-	amdgpu_fence_emit(ring, &f);
+	f = amdgpu_fence_drv_cpu_addr(ring);
+	*f = 0;

Wow, wait a second. Messing with the fence counter here is a clear no-go. That could even crash the interrupt handler.

You need to add proper wrap around handling instead of setting the value to zero.

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) · line 132

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1 -0
+	seq = ++ring->fence_drv.sync_seq;

What I meant with moving the functionality into the fence code was increasing the counter and emitting the fence write.

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1 -5
+	amdgpu_ring_emit_fence(ring, amdgpu_fence_drv_gpu_addr(ring), seq, 0);
  	amdgpu_ring_commit(ring);
  	spin_unlock(&kiq->ring_lock);
 
-	r = dma_fence_wait_timeout(f, false, msecs_to_jiffies(MAX_KIQ_REG_WAIT));
-	dma_fence_put(f);
-	if (r < 1) {
-		DRM_ERROR("wait for kiq fence error: %ld.\n", r);
-		return ~0;

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) · line 146

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +9 -0
+	end_jiffies = (MAX_KIQ_REG_WAIT * HZ / 1000) + jiffies;
+	while (true) {
+		if (*f >= seq)
+			break;
+		if (time_after(jiffies, end_jiffies)) {
+			DRM_ERROR("wait for kiq fence error: %ld.\n", r);
+			return ~0;
+		}
+		cpu_relax();
  	}

That waiting should go into the fence code as well.

Regards,
Christian.

Quoted 34 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +11 -6
  	val = adev->wb.wb[adev->virt.reg_val_offs];
@@ -144,23 +153,35 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg)
  void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
  {
  	signed long r;
-	struct dma_fence *f;
  	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
  	struct amdgpu_ring *ring = &kiq->ring;
+	unsigned long end_jiffies;
+	uint32_t seq;
+	volatile uint32_t *f;
 
  	BUG_ON(!ring->funcs->emit_wreg);
 
  	spin_lock(&kiq->ring_lock);
  	amdgpu_ring_alloc(ring, 32);
  	amdgpu_ring_emit_wreg(ring, reg, v);
-	amdgpu_fence_emit(ring, &f);
+	f = amdgpu_fence_drv_cpu_addr(ring);
+	*f = 0;
+	seq = ++ring->fence_drv.sync_seq;
+	amdgpu_ring_emit_fence(ring, amdgpu_fence_drv_gpu_addr(ring), seq, 0);
  	amdgpu_ring_commit(ring);
  	spin_unlock(&kiq->ring_lock);
 
-	r = dma_fence_wait_timeout(f, false, msecs_to_jiffies(MAX_KIQ_REG_WAIT));
-	if (r < 1)
-		DRM_ERROR("wait for kiq fence error: %ld.\n", r);
-	dma_fence_put(f);
+	end_jiffies = (MAX_KIQ_REG_WAIT * HZ / 1000) + jiffies;
+	while (true) {
+		if (*f >= seq)
+			break;

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) · line 187

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +7 -0
+		if (time_after(jiffies, end_jiffies)) {
+			DRM_ERROR("wait for kiq fence error: %ld.\n", r);
+			return;
+		}
+		cpu_relax();
+	}
+
  }
 
  /**

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