[PATCH 2/3] drm/amdgpu: add the interface of waiting multiple fences (v3)

2016-11-04 Thread Deucher, Alexander
> -Original Message-
> From: Sumit Semwal [mailto:sumit.semwal at linaro.org]
> Sent: Friday, November 04, 2016 1:15 PM
> To: Alex Deucher
> Cc: amd-gfx at lists.freedesktop.org; DRI mailing list; Zhang, Jerry; Deucher,
> Alexander
> Subject: Re: [PATCH 2/3] drm/amdgpu: add the interface of waiting multiple
> fences (v3)
> 
> Hi Alex,
> 
> Thanks for the patch!
> 
> On 3 November 2016 at 11:41, Alex Deucher 
> wrote:
> > From: Junwei Zhang 
> >
> > v2: agd: rebase and squash in all the previous optimizations and
> > changes so everything compiles.
> > v3: squash in Slava's 32bit build fix
> >
> > Signed-off-by: Junwei Zhang 
> > Reviewed-by: Monk Liu 
> > Reviewed-by: Jammy Zhou 
> > Signed-off-by: Alex Deucher 
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu.h |   2 +
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 171
> 
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   1 +
> >  include/uapi/drm/amdgpu_drm.h   |  27 +
> >  4 files changed, 201 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > index 8d0c689..c2050c0 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> 
> > +
> > +   r = fence_wait_any_timeout(array, fence_count, true, timeout);
> 
> With the change proposed about returning index of signalled fence in
> patch 1/3, I don't think this would build?

Yes, Sorry, I messed up the order when I rebased the patches.  It should be 2 1 
3.

Alex

> 
> Best regards,
> Sumit.


[PATCH 2/3] drm/amdgpu: add the interface of waiting multiple fences (v3)

2016-11-04 Thread Sumit Semwal
On 4 November 2016 at 11:14, Sumit Semwal  wrote:
> Hi Alex,
>
> Thanks for the patch!
>
> On 3 November 2016 at 11:41, Alex Deucher  wrote:
>> From: Junwei Zhang 
>>
>> v2: agd: rebase and squash in all the previous optimizations and
>> changes so everything compiles.
>> v3: squash in Slava's 32bit build fix
>>
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> 
>> +
>> +   r = fence_wait_any_timeout(array, fence_count, true, timeout);
>
> With the change proposed about returning index of signalled fence in
> patch 1/3, I don't think this would build?
>
O, just noticed - perhaps just a reordering of patches so that this is
1/3 (or even a separate patch?) and dma-buf change for index + amdgpu
change for the index are 2/3 and 3/3, should solve it.


> Best regards,
> Sumit.


[PATCH 2/3] drm/amdgpu: add the interface of waiting multiple fences (v3)

2016-11-04 Thread Sumit Semwal
Hi Alex,

Thanks for the patch!

On 3 November 2016 at 11:41, Alex Deucher  wrote:
> From: Junwei Zhang 
>
> v2: agd: rebase and squash in all the previous optimizations and
> changes so everything compiles.
> v3: squash in Slava's 32bit build fix
>
> Signed-off-by: Junwei Zhang 
> Reviewed-by: Monk Liu 
> Reviewed-by: Jammy Zhou 
> Signed-off-by: Alex Deucher 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h |   2 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 171 
> 
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   1 +
>  include/uapi/drm/amdgpu_drm.h   |  27 +
>  4 files changed, 201 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 8d0c689..c2050c0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h

> +
> +   r = fence_wait_any_timeout(array, fence_count, true, timeout);

With the change proposed about returning index of signalled fence in
patch 1/3, I don't think this would build?

Best regards,
Sumit.


[PATCH 2/3] drm/amdgpu: add the interface of waiting multiple fences (v3)

2016-11-03 Thread Alex Deucher
From: Junwei Zhang 

v2: agd: rebase and squash in all the previous optimizations and
changes so everything compiles.
v3: squash in Slava's 32bit build fix

Signed-off-by: Junwei Zhang 
Reviewed-by: Monk Liu 
Reviewed-by: Jammy Zhou 
Signed-off-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 171 
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   1 +
 include/uapi/drm/amdgpu_drm.h   |  27 +
 4 files changed, 201 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 8d0c689..c2050c0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1214,6 +1214,8 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void 
*data,
struct drm_file *filp);
 int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
 int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file 
*filp);
+int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
+   struct drm_file *filp);

 int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
struct drm_file *filp);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 4068504..f0c3c356 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -1130,6 +1130,177 @@ int amdgpu_cs_wait_ioctl(struct drm_device *dev, void 
*data,
 }

 /**
+ * amdgpu_cs_get_fence - helper to get fence from drm_amdgpu_fence
+ *
+ * @adev: amdgpu device
+ * @filp: file private
+ * @user: drm_amdgpu_fence copied from user space
+ */
+static struct fence *amdgpu_cs_get_fence(struct amdgpu_device *adev,
+struct drm_file *filp,
+struct drm_amdgpu_fence *user)
+{
+   struct amdgpu_ring *ring;
+   struct amdgpu_ctx *ctx;
+   struct fence *fence;
+   int r;
+
+   r = amdgpu_cs_get_ring(adev, user->ip_type, user->ip_instance,
+  user->ring, );
+   if (r)
+   return ERR_PTR(r);
+
+   ctx = amdgpu_ctx_get(filp->driver_priv, user->ctx_id);
+   if (ctx == NULL)
+   return ERR_PTR(-EINVAL);
+
+   fence = amdgpu_ctx_get_fence(ctx, ring, user->seq_no);
+   amdgpu_ctx_put(ctx);
+
+   return fence;
+}
+
+/**
+ * amdgpu_cs_wait_all_fence - wait on all fences to signal
+ *
+ * @adev: amdgpu device
+ * @filp: file private
+ * @wait: wait parameters
+ * @fences: array of drm_amdgpu_fence
+ */
+static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev,
+struct drm_file *filp,
+union drm_amdgpu_wait_fences *wait,
+struct drm_amdgpu_fence *fences)
+{
+   uint32_t fence_count = wait->in.fence_count;
+   unsigned i;
+   long r = 1;
+
+   for (i = 0; i < fence_count; i++) {
+   struct fence *fence;
+   unsigned long timeout = amdgpu_gem_timeout(wait->in.timeout_ns);
+
+   fence = amdgpu_cs_get_fence(adev, filp, [i]);
+   if (IS_ERR(fence))
+   return PTR_ERR(fence);
+   else if (!fence)
+   continue;
+
+   r = fence_wait_timeout(fence, true, timeout);
+   if (r < 0)
+   return r;
+
+   if (r == 0)
+   break;
+   }
+
+   memset(wait, 0, sizeof(*wait));
+   wait->out.status = (r > 0);
+
+   return 0;
+}
+
+/**
+ * amdgpu_cs_wait_any_fence - wait on any fence to signal
+ *
+ * @adev: amdgpu device
+ * @filp: file private
+ * @wait: wait parameters
+ * @fences: array of drm_amdgpu_fence
+ */
+static int amdgpu_cs_wait_any_fence(struct amdgpu_device *adev,
+   struct drm_file *filp,
+   union drm_amdgpu_wait_fences *wait,
+   struct drm_amdgpu_fence *fences)
+{
+   unsigned long timeout = amdgpu_gem_timeout(wait->in.timeout_ns);
+   uint32_t fence_count = wait->in.fence_count;
+   struct fence **array;
+   unsigned i;
+   long r;
+
+   /* Prepare the fence array */
+   array = (struct fence **)kcalloc(fence_count, sizeof(struct fence *),
+   GFP_KERNEL);
+   if (array == NULL)
+   return -ENOMEM;
+
+   for (i = 0; i < fence_count; i++) {
+   struct fence *fence;
+
+   fence = amdgpu_cs_get_fence(adev, filp, [i]);
+   if (IS_ERR(fence)) {
+   r = PTR_ERR(fence);
+   goto err_free_fence_array;
+   } else if (fence) {
+   array[i] = fence;
+