RE: [PATCH 7/7] drm/amdgpu: add a fence timeout for the IB tests v2

2016-07-27 Thread Deucher, Alexander
> -Original Message-
> From: amd-gfx [mailto:amd-gfx-boun...@lists.freedesktop.org] On Behalf
> Of Christian König
> Sent: Thursday, July 21, 2016 6:01 AM
> To: amd-gfx@lists.freedesktop.org
> Subject: [PATCH 7/7] drm/amdgpu: add a fence timeout for the IB tests v2
> 
> From: Christian König 
> 
> 10ms should be enough for now.
> 
> v2: fix some typos in CIK code
> 
> Signed-off-by: Christian König 

For the series:
Reviewed-by: Alex Deucher 

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h |  4 ++--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c  |  4 +++-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 25 +++-
> -
>  drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h |  2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 18 +++---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  2 +-
>  drivers/gpu/drm/amd/amdgpu/cik_sdma.c   | 19 ---
>  drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c   | 19 ---
>  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c   | 19 ---
>  drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c  | 19 ---
>  drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c  | 19 ---
>  11 files changed, 93 insertions(+), 57 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index f724a87..03c3a8a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -307,7 +307,7 @@ struct amdgpu_ring_funcs {
>   uint32_t oa_base, uint32_t oa_size);
>   /* testing functions */
>   int (*test_ring)(struct amdgpu_ring *ring);
> - int (*test_ib)(struct amdgpu_ring *ring);
> + int (*test_ib)(struct amdgpu_ring *ring, long timeout);
>   /* insert NOP packets */
>   void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
>   /* pad the indirect buffer to the necessary number of dw */
> @@ -2261,7 +2261,7 @@ amdgpu_get_sdma_instance(struct amdgpu_ring
> *ring)
>  #define amdgpu_vm_set_pte_pde(adev, ib, pe, addr, count, incr, flags)
> ((adev)->vm_manager.vm_pte_funcs->set_pte_pde((ib), (pe), (addr),
> (count), (incr), (flags)))
>  #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
>  #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
> -#define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
> +#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
>  #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
>  #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
>  #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> index 428ebf3..050062e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> @@ -33,6 +33,8 @@
>  #include "amdgpu.h"
>  #include "atom.h"
> 
> +#define AMDGPU_IB_TEST_TIMEOUT   msecs_to_jiffies(10)
> +
>  /*
>   * IB
>   * IBs (Indirect Buffers) and areas of GPU accessible memory where
> @@ -286,7 +288,7 @@ int amdgpu_ib_ring_tests(struct amdgpu_device
> *adev)
>   if (!ring || !ring->ready)
>   continue;
> 
> - r = amdgpu_ring_test_ib(ring);
> + r = amdgpu_ring_test_ib(ring,
> AMDGPU_IB_TEST_TIMEOUT);
>   if (r) {
>   ring->ready = false;
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> index d8b461a..aa80b72 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> @@ -1139,29 +1139,34 @@ void amdgpu_uvd_ring_end_use(struct
> amdgpu_ring *ring)
>   *
>   * Test if we can successfully execute an IB
>   */
> -int amdgpu_uvd_ring_test_ib(struct amdgpu_ring *ring)
> +int amdgpu_uvd_ring_test_ib(struct amdgpu_ring *ring, long timeout)
>  {
> - struct fence *fence = NULL;
> - int r;
> + struct fence *fence;
> + long r;
> 
>   r = amdgpu_uvd_get_create_msg(ring, 1, NULL);
>   if (r) {
> - DRM_ERROR("amdgpu: failed to get create msg (%d).\n", r);
> + DRM_ERROR("amdgpu: failed to get create msg (%ld).\n", r);
>   goto error;
>   }
> 
>   r = amdgpu_uvd_get_destroy_msg(ring, 1, true, &fence);
>   if (r) {
> - DRM_ERROR("amdgpu: failed to get destroy ib (%d).\n", r);
> + DRM_ERROR("amdgpu: failed to get destroy ib (%ld).\n", r);
>   goto error;
>   }
> 
> - r 

Re: [PATCH 7/7] drm/amdgpu: add a fence timeout for the IB tests v2

2016-07-21 Thread zhoucm1



On 2016年07月21日 18:01, Christian König wrote:

From: Christian König 

10ms should be enough for now.

v2: fix some typos in CIK code

Signed-off-by: Christian König 

Reviewed-by: Chunming Zhou 

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h |  4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c  |  4 +++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 25 +++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 18 +++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  2 +-
  drivers/gpu/drm/amd/amdgpu/cik_sdma.c   | 19 ---
  drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c   | 19 ---
  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c   | 19 ---
  drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c  | 19 ---
  drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c  | 19 ---
  11 files changed, 93 insertions(+), 57 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index f724a87..03c3a8a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -307,7 +307,7 @@ struct amdgpu_ring_funcs {
uint32_t oa_base, uint32_t oa_size);
/* testing functions */
int (*test_ring)(struct amdgpu_ring *ring);
-   int (*test_ib)(struct amdgpu_ring *ring);
+   int (*test_ib)(struct amdgpu_ring *ring, long timeout);
/* insert NOP packets */
void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
/* pad the indirect buffer to the necessary number of dw */
@@ -2261,7 +2261,7 @@ amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
  #define amdgpu_vm_set_pte_pde(adev, ib, pe, addr, count, incr, flags) 
((adev)->vm_manager.vm_pte_funcs->set_pte_pde((ib), (pe), (addr), (count), 
(incr), (flags)))
  #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
  #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
-#define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
+#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
  #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
  #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
  #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
index 428ebf3..050062e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
@@ -33,6 +33,8 @@
  #include "amdgpu.h"
  #include "atom.h"
  
+#define AMDGPU_IB_TEST_TIMEOUT	msecs_to_jiffies(10)

+
  /*
   * IB
   * IBs (Indirect Buffers) and areas of GPU accessible memory where
@@ -286,7 +288,7 @@ int amdgpu_ib_ring_tests(struct amdgpu_device *adev)
if (!ring || !ring->ready)
continue;
  
-		r = amdgpu_ring_test_ib(ring);

+   r = amdgpu_ring_test_ib(ring, AMDGPU_IB_TEST_TIMEOUT);
if (r) {
ring->ready = false;
  
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c

index d8b461a..aa80b72 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
@@ -1139,29 +1139,34 @@ void amdgpu_uvd_ring_end_use(struct amdgpu_ring *ring)
   *
   * Test if we can successfully execute an IB
   */
-int amdgpu_uvd_ring_test_ib(struct amdgpu_ring *ring)
+int amdgpu_uvd_ring_test_ib(struct amdgpu_ring *ring, long timeout)
  {
-   struct fence *fence = NULL;
-   int r;
+   struct fence *fence;
+   long r;
  
  	r = amdgpu_uvd_get_create_msg(ring, 1, NULL);

if (r) {
-   DRM_ERROR("amdgpu: failed to get create msg (%d).\n", r);
+   DRM_ERROR("amdgpu: failed to get create msg (%ld).\n", r);
goto error;
}
  
  	r = amdgpu_uvd_get_destroy_msg(ring, 1, true, &fence);

if (r) {
-   DRM_ERROR("amdgpu: failed to get destroy ib (%d).\n", r);
+   DRM_ERROR("amdgpu: failed to get destroy ib (%ld).\n", r);
goto error;
}
  
-	r = fence_wait(fence, false);

-   if (r) {
-   DRM_ERROR("amdgpu: fence wait failed (%d).\n", r);
-   goto error;
+   r = fence_wait_timeout(fence, false, timeout);
+   if (r == 0) {
+   DRM_ERROR("amdgpu: IB test timed out.\n");
+   r = -ETIMEDOUT;
+   } else if (r < 0) {
+   DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r);
+   } else {
+   DRM_INFO("ib test on ring %d succeeded\n",  ring->idx);
+   r = 0;
}
-   DRM_INFO("ib test on ring %d succeeded\n",  ring->idx);
+
  error:
fence_put(fence);
return r;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h
index 224359e..c850009 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h
+++ b/drivers/gpu/drm/a

[PATCH 7/7] drm/amdgpu: add a fence timeout for the IB tests v2

2016-07-21 Thread Christian König
From: Christian König 

10ms should be enough for now.

v2: fix some typos in CIK code

Signed-off-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c  |  4 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 25 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 18 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  2 +-
 drivers/gpu/drm/amd/amdgpu/cik_sdma.c   | 19 ---
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c   | 19 ---
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c   | 19 ---
 drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c  | 19 ---
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c  | 19 ---
 11 files changed, 93 insertions(+), 57 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index f724a87..03c3a8a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -307,7 +307,7 @@ struct amdgpu_ring_funcs {
uint32_t oa_base, uint32_t oa_size);
/* testing functions */
int (*test_ring)(struct amdgpu_ring *ring);
-   int (*test_ib)(struct amdgpu_ring *ring);
+   int (*test_ib)(struct amdgpu_ring *ring, long timeout);
/* insert NOP packets */
void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
/* pad the indirect buffer to the necessary number of dw */
@@ -2261,7 +2261,7 @@ amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
 #define amdgpu_vm_set_pte_pde(adev, ib, pe, addr, count, incr, flags) 
((adev)->vm_manager.vm_pte_funcs->set_pte_pde((ib), (pe), (addr), (count), 
(incr), (flags)))
 #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
 #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
-#define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
+#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
 #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
 #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
 #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
index 428ebf3..050062e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
@@ -33,6 +33,8 @@
 #include "amdgpu.h"
 #include "atom.h"
 
+#define AMDGPU_IB_TEST_TIMEOUT msecs_to_jiffies(10)
+
 /*
  * IB
  * IBs (Indirect Buffers) and areas of GPU accessible memory where
@@ -286,7 +288,7 @@ int amdgpu_ib_ring_tests(struct amdgpu_device *adev)
if (!ring || !ring->ready)
continue;
 
-   r = amdgpu_ring_test_ib(ring);
+   r = amdgpu_ring_test_ib(ring, AMDGPU_IB_TEST_TIMEOUT);
if (r) {
ring->ready = false;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
index d8b461a..aa80b72 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
@@ -1139,29 +1139,34 @@ void amdgpu_uvd_ring_end_use(struct amdgpu_ring *ring)
  *
  * Test if we can successfully execute an IB
  */
-int amdgpu_uvd_ring_test_ib(struct amdgpu_ring *ring)
+int amdgpu_uvd_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 {
-   struct fence *fence = NULL;
-   int r;
+   struct fence *fence;
+   long r;
 
r = amdgpu_uvd_get_create_msg(ring, 1, NULL);
if (r) {
-   DRM_ERROR("amdgpu: failed to get create msg (%d).\n", r);
+   DRM_ERROR("amdgpu: failed to get create msg (%ld).\n", r);
goto error;
}
 
r = amdgpu_uvd_get_destroy_msg(ring, 1, true, &fence);
if (r) {
-   DRM_ERROR("amdgpu: failed to get destroy ib (%d).\n", r);
+   DRM_ERROR("amdgpu: failed to get destroy ib (%ld).\n", r);
goto error;
}
 
-   r = fence_wait(fence, false);
-   if (r) {
-   DRM_ERROR("amdgpu: fence wait failed (%d).\n", r);
-   goto error;
+   r = fence_wait_timeout(fence, false, timeout);
+   if (r == 0) {
+   DRM_ERROR("amdgpu: IB test timed out.\n");
+   r = -ETIMEDOUT;
+   } else if (r < 0) {
+   DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r);
+   } else {
+   DRM_INFO("ib test on ring %d succeeded\n",  ring->idx);
+   r = 0;
}
-   DRM_INFO("ib test on ring %d succeeded\n",  ring->idx);
+
 error:
fence_put(fence);
return r;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h
index 224359e..c850009 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h
@@ -37,6 +37,6 @@ void amdgpu_uvd_free_handles(struct amdgpu_devic