All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig-5C7GfCeVMHo@public.gmane.org>
To: Pixel Ding <Pixel.Ding-5C7GfCeVMHo@public.gmane.org>,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	Monk.Liu-5C7GfCeVMHo@public.gmane.org
Cc: Gary.Sun-5C7GfCeVMHo@public.gmane.org,
	Bingley.Li-5C7GfCeVMHo@public.gmane.org
Subject: Re: [PATCH 3/3] drm/amdgpu: busywait KIQ register accessing v2
Date: Tue, 17 Oct 2017 10:20:14 +0200	[thread overview]
Message-ID: <7f22595c-ae6d-f859-3ba6-42fe30a24707@amd.com> (raw)
In-Reply-To: <1508222267-18627-4-git-send-email-Pixel.Ding-5C7GfCeVMHo@public.gmane.org>

Am 17.10.2017 um 08:37 schrieb Pixel Ding:
> From: pding <Pixel.Ding@amd.com>
>
> Register accessing is performed when IRQ is disabled. Never sleep in
> this function.
>
> Known issue: dead sleep in many use cases of index/data registers.
>
> v2: wrap polling fence functions. don't trigger IRQ for polling in
> case of wrongly fence signal.
>
> Signed-off-by: pding <Pixel.Ding@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu.h               |  2 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c |  4 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c |  4 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c        |  8 +---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c         | 53 +++++++++++++++++++++++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c           |  2 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h          |  4 ++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c          | 30 ++++++-------
>   8 files changed, 78 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index ca212ef..cc06e62 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -885,7 +885,7 @@ struct amdgpu_mec {
>   struct amdgpu_kiq {
>   	u64			eop_gpu_addr;
>   	struct amdgpu_bo	*eop_obj;
> -	struct mutex		ring_mutex;
> +	spinlock_t              ring_lock;
>   	struct amdgpu_ring	ring;
>   	struct amdgpu_irq_src	irq;
>   };
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
> index 9d9965d..6d83573 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
> @@ -788,7 +788,7 @@ static int invalidate_tlbs_with_kiq(struct amdgpu_device *adev, uint16_t pasid)
>   	struct dma_fence *f;
>   	struct amdgpu_ring *ring = &adev->gfx.kiq.ring;
>   
> -	mutex_lock(&adev->gfx.kiq.ring_mutex);
> +	spin_lock(&adev->gfx.kiq.ring_lock);
>   	amdgpu_ring_alloc(ring, 12); /* fence + invalidate_tlbs package*/
>   	amdgpu_ring_write(ring, PACKET3(PACKET3_INVALIDATE_TLBS, 0));
>   	amdgpu_ring_write(ring,
> @@ -796,7 +796,7 @@ static int invalidate_tlbs_with_kiq(struct amdgpu_device *adev, uint16_t pasid)
>   			PACKET3_INVALIDATE_TLBS_PASID(pasid));
>   	amdgpu_fence_emit(ring, &f);
>   	amdgpu_ring_commit(ring);
> -	mutex_unlock(&adev->gfx.kiq.ring_mutex);
> +	spin_unlock(&adev->gfx.kiq.ring_lock);
>   
>   	r = dma_fence_wait(f, false);
>   	if (r)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
> index edbae19..c92217f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
> @@ -973,7 +973,7 @@ static int invalidate_tlbs_with_kiq(struct amdgpu_device *adev, uint16_t pasid)
>   	struct dma_fence *f;
>   	struct amdgpu_ring *ring = &adev->gfx.kiq.ring;
>   
> -	mutex_lock(&adev->gfx.kiq.ring_mutex);
> +	spin_lock(&adev->gfx.kiq.ring_lock);
>   	amdgpu_ring_alloc(ring, 12); /* fence + invalidate_tlbs package*/
>   	amdgpu_ring_write(ring, PACKET3(PACKET3_INVALIDATE_TLBS, 0));
>   	amdgpu_ring_write(ring,
> @@ -983,7 +983,7 @@ static int invalidate_tlbs_with_kiq(struct amdgpu_device *adev, uint16_t pasid)
>   			PACKET3_INVALIDATE_TLBS_FLUSH_TYPE(2));
>   	amdgpu_fence_emit(ring, &f);
>   	amdgpu_ring_commit(ring);
> -	mutex_unlock(&adev->gfx.kiq.ring_mutex);
> +	spin_unlock(&adev->gfx.kiq.ring_lock);
>   
>   	r = dma_fence_wait(f, false);
>   	if (r)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index ab8f0d6..1197274 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -109,10 +109,8 @@ uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
>   {
>   	uint32_t ret;
>   
> -	if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev)) {
> -		BUG_ON(in_interrupt());
> +	if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev))
>   		return amdgpu_virt_kiq_rreg(adev, reg);
> -	}
>   
>   	if ((reg * 4) < adev->rmmio_size && !(acc_flags & AMDGPU_REGS_IDX))
>   		ret = readl(((void __iomem *)adev->rmmio) + (reg * 4));
> @@ -137,10 +135,8 @@ void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
>   		adev->last_mm_index = v;
>   	}
>   
> -	if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev)) {
> -		BUG_ON(in_interrupt());
> +	if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev))
>   		return amdgpu_virt_kiq_wreg(adev, reg, v);
> -	}
>   
>   	if ((reg * 4) < adev->rmmio_size && !(acc_flags & AMDGPU_REGS_IDX))
>   		writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> index 688740e..68a5e90 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> @@ -169,6 +169,32 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f)
>   }
>   
>   /**
> + * amdgpu_fence_emit_polling - emit a fence on the requeste ring
> + *
> + * @ring: ring the fence is associated with
> + * @s: resulting sequence number
> + *
> + * Emits a fence command on the requested ring (all asics).
> + * Used For polling fence.
> + * Returns 0 on success, -ENOMEM on failure.
> + */
> +int amdgpu_fence_emit_polling(struct amdgpu_ring *ring, uint32_t *s)
> +{
> +	uint32_t seq;
> +
> +	if (!s)
> +		return -EINVAL;
> +
> +	seq = ++ring->fence_drv.sync_seq;
> +	amdgpu_ring_emit_fence(ring, ring->fence_drv.gpu_addr,
> +			       seq, AMDGPU_FENCE_FLAG_INT);
> +
> +	*s = seq;
> +
> +	return 0;
> +}
> +
> +/**
>    * amdgpu_fence_schedule_fallback - schedule fallback check
>    *
>    * @ring: pointer to struct amdgpu_ring
> @@ -281,6 +307,33 @@ int amdgpu_fence_wait_empty(struct amdgpu_ring *ring)
>   	return r;
>   }
>   

Please add some documentation here that timeout is in usec.

> +signed long amdgpu_fence_wait_polling(struct amdgpu_ring *ring,
> +				      uint32_t wait_seq,
> +				      signed long timeout)
> +{
> +	uint32_t seq, last_seq;
> +	struct amdgpu_fence_driver *drv = &ring->fence_drv;
> +
> +	last_seq = atomic_read(&ring->fence_drv.last_seq);
> +
> +	do {
> +		seq = amdgpu_fence_read(ring);
> +
> +		if (unlikely(seq == last_seq))
> +			break;

That doesn't look correct to me, it will abort the busy wait as soon as 
we see the last value we have seen.

> +		if (seq >= wait_seq && wait_seq >= last_seq)
> +			break;
> +		if (seq <= last_seq &&
> +		    (wait_seq <= seq || wait_seq >= last_seq))
> +			break;

Why not just "(int32_t)(wait_seq - seq) > 0" ? IIRC that should be 
sufficient for a wrap around test.

Regards,
Christian.

> +		udelay(5);
> +		timeout -= 5;
> +	} while (timeout > 0);
> +
> +	atomic_cmpxchg(&drv->last_seq, last_seq, wait_seq);
> +
> +	return timeout;
> +}
>   /**
>    * amdgpu_fence_count_emitted - get the count of emitted fences
>    *
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
> index 4f6c68f..e5a9077 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
> @@ -185,7 +185,7 @@ int amdgpu_gfx_kiq_init_ring(struct amdgpu_device *adev,
>   	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
>   	int r = 0;
>   
> -	mutex_init(&kiq->ring_mutex);
> +	spin_lock_init(&kiq->ring_lock);
>   
>   	r = amdgpu_wb_get(adev, &adev->virt.reg_val_offs);
>   	if (r)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
> index af8e544..9de89ea 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
> @@ -89,8 +89,12 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
>   void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
>   void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
>   int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **fence);
> +int amdgpu_fence_emit_polling(struct amdgpu_ring *ring, uint32_t *s);
>   void amdgpu_fence_process(struct amdgpu_ring *ring);
>   int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
> +signed long amdgpu_fence_wait_polling(struct amdgpu_ring *ring,
> +				      uint32_t wait_seq,
> +				      signed long timeout);
>   unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
>   
>   /*
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> index ab05121..177fe10 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> @@ -22,7 +22,7 @@
>    */
>   
>   #include "amdgpu.h"
> -#define MAX_KIQ_REG_WAIT	100000
> +#define MAX_KIQ_REG_WAIT	100000000 /* in usecs */
>   
>   int amdgpu_allocate_static_csa(struct amdgpu_device *adev)
>   {
> @@ -114,27 +114,24 @@ void amdgpu_virt_init_setting(struct amdgpu_device *adev)
>   uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg)
>   {
>   	signed long r;
> -	uint32_t val;
> -	struct dma_fence *f;
> +	uint32_t val, seq;
>   	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
>   	struct amdgpu_ring *ring = &kiq->ring;
>   
>   	BUG_ON(!ring->funcs->emit_rreg);
>   
> -	mutex_lock(&kiq->ring_mutex);
> +	spin_lock(&kiq->ring_lock);
>   	amdgpu_ring_alloc(ring, 32);
>   	amdgpu_ring_emit_rreg(ring, reg);
> -	amdgpu_fence_emit(ring, &f);
> +	amdgpu_fence_emit_polling(ring, &seq);
>   	amdgpu_ring_commit(ring);
> -	mutex_unlock(&kiq->ring_mutex);
> +	spin_unlock(&kiq->ring_lock);
>   
> -	r = dma_fence_wait_timeout(f, false, msecs_to_jiffies(MAX_KIQ_REG_WAIT));
> -	dma_fence_put(f);
> +	r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
>   	if (r < 1) {
> -		DRM_ERROR("wait for kiq fence error: %ld.\n", r);
> +		DRM_ERROR("wait for kiq fence error: %ld\n", r);
>   		return ~0;
>   	}
> -
>   	val = adev->wb.wb[adev->virt.reg_val_offs];
>   
>   	return val;
> @@ -143,23 +140,22 @@ 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;
> +	uint32_t seq;
>   	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
>   	struct amdgpu_ring *ring = &kiq->ring;
>   
>   	BUG_ON(!ring->funcs->emit_wreg);
>   
> -	mutex_lock(&kiq->ring_mutex);
> +	spin_lock(&kiq->ring_lock);
>   	amdgpu_ring_alloc(ring, 32);
>   	amdgpu_ring_emit_wreg(ring, reg, v);
> -	amdgpu_fence_emit(ring, &f);
> +	amdgpu_fence_emit_polling(ring, &seq);
>   	amdgpu_ring_commit(ring);
> -	mutex_unlock(&kiq->ring_mutex);
> +	spin_unlock(&kiq->ring_lock);
>   
> -	r = dma_fence_wait_timeout(f, false, msecs_to_jiffies(MAX_KIQ_REG_WAIT));
> +	r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
>   	if (r < 1)
> -		DRM_ERROR("wait for kiq fence error: %ld.\n", r);
> -	dma_fence_put(f);
> +		DRM_ERROR("wait for kiq fence error: %ld\n", r);
>   }
>   
>   /**


_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2017-10-17  8:20 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-17  6:37 Make staging driver stable for SRIOV VF (1 v2) Pixel Ding
     [not found] ` <1508222267-18627-1-git-send-email-Pixel.Ding-5C7GfCeVMHo@public.gmane.org>
2017-10-17  6:37   ` [PATCH 1/3] drm/amdgpu: always consider virualised device for checking post Pixel Ding
     [not found]     ` <1508222267-18627-2-git-send-email-Pixel.Ding-5C7GfCeVMHo@public.gmane.org>
2017-10-17  7:48       ` Liu, Monk
     [not found]         ` <BLUPR12MB04492724C9C66EF3ABA7C295844C0-7LeqcoF/hwpTIQvHjXdJlwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-10-17  7:53           ` Ding, Pixel
     [not found]             ` <77D84CB4-2676-4DBC-AB49-431923E87EAC-5C7GfCeVMHo@public.gmane.org>
2017-10-17  8:00               ` Liu, Monk
     [not found]                 ` <BLUPR12MB0449C0C378B70A73A44579CC844C0-7LeqcoF/hwpTIQvHjXdJlwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-10-17  8:06                   ` Ding, Pixel
     [not found]                     ` <BA0191B9-16C3-43D8-9816-BF77301CE5D5-5C7GfCeVMHo@public.gmane.org>
2017-10-18  2:13                       ` Liu, Monk
2017-10-18  2:25                       ` Ding, Pixel
     [not found]                         ` <9035FC71-9AB1-406C-9A0B-8B050E51C7F4-5C7GfCeVMHo@public.gmane.org>
2017-10-18  7:19                           ` Ding, Pixel
     [not found]                             ` <83AE16CE-43F8-44E7-AEF6-6FA581134C7A-5C7GfCeVMHo@public.gmane.org>
2017-10-18  7:23                               ` Christian König
     [not found]                                 ` <b3d8df4b-38f9-2bc2-3340-782069591058-5C7GfCeVMHo@public.gmane.org>
2017-10-18  9:13                                   ` Liu, Monk
2017-10-18  9:20                                   ` Ding, Pixel
2017-10-18 14:08                                   ` Deucher, Alexander
     [not found]                                     ` <BN6PR12MB16521D66D545EE9CF038725AF74D0-/b2+HYfkarQqUD6E6FAiowdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-10-19  3:23                                       ` Ding, Pixel
     [not found]                                         ` <5D15F8FE-DDA7-4AC9-AB1B-2B69ED5C410F-5C7GfCeVMHo@public.gmane.org>
2017-10-19  3:32                                           ` Deucher, Alexander
2017-10-17  6:37   ` [PATCH 2/3] drm/amdgpu: report more amdgpu_fence_info v2 Pixel Ding
     [not found]     ` <1508222267-18627-3-git-send-email-Pixel.Ding-5C7GfCeVMHo@public.gmane.org>
2017-10-17  7:03       ` Christian König
2017-10-17  7:49       ` Liu, Monk
     [not found]         ` <BLUPR12MB0449B223F1C69AE2587EE9F5844C0-7LeqcoF/hwpTIQvHjXdJlwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-10-17  7:55           ` Ding, Pixel
     [not found]             ` <AE86FEF5-92C5-4F1B-B302-5A9289C42CD8-5C7GfCeVMHo@public.gmane.org>
2017-10-17  7:59               ` Liu, Monk
2017-10-17  6:37   ` [PATCH 3/3] drm/amdgpu: busywait KIQ register accessing v2 Pixel Ding
     [not found]     ` <1508222267-18627-4-git-send-email-Pixel.Ding-5C7GfCeVMHo@public.gmane.org>
2017-10-17  8:20       ` Christian König [this message]
     [not found]         ` <7f22595c-ae6d-f859-3ba6-42fe30a24707-5C7GfCeVMHo@public.gmane.org>
2017-10-17  8:38           ` Ding, Pixel
     [not found]             ` <E8EDC6D0-8756-4E09-8C0F-187CE061A470-5C7GfCeVMHo@public.gmane.org>
2017-10-17  8:59               ` Christian König
     [not found]                 ` <b6506918-3acf-6480-2f90-6b4bbc09eada-5C7GfCeVMHo@public.gmane.org>
2017-10-17  9:27                   ` Ding, Pixel
  -- strict thread matches above, loose matches on Subject: below --
2017-10-17  6:25 Make staging driver stable for SRIOV VF (1 v2) Pixel Ding
     [not found] ` <1508221510-7159-1-git-send-email-Pixel.Ding-5C7GfCeVMHo@public.gmane.org>
2017-10-17  6:25   ` [PATCH 3/3] drm/amdgpu: busywait KIQ register accessing v2 Pixel Ding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7f22595c-ae6d-f859-3ba6-42fe30a24707@amd.com \
    --to=christian.koenig-5c7gfcevmho@public.gmane.org \
    --cc=Bingley.Li-5C7GfCeVMHo@public.gmane.org \
    --cc=Gary.Sun-5C7GfCeVMHo@public.gmane.org \
    --cc=Monk.Liu-5C7GfCeVMHo@public.gmane.org \
    --cc=Pixel.Ding-5C7GfCeVMHo@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.