Re: [PATCH 6/7] drm/amdkfd: New IOCTL to allocate queue GWS

2019-05-23 Thread Kuehling, Felix

On 2019-05-23 2:41 p.m., Zeng, Oak wrote:
> Add a new kfd ioctl to allocate queue GWS. Queue
> GWS is released on queue destroy.
>
> Change-Id: I60153c26a577992ad873e4292e759e5c3d5bbd15
> Signed-off-by: Oak Zeng 
> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 30 ++
>   include/uapi/linux/kfd_ioctl.h   | 20 +++-
>   2 files changed, 49 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c 
> b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index 38ae53f..f3f08fe 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -1559,6 +1559,34 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file 
> *filep,
>   return err;
>   }
>   
> +static int kfd_ioctl_alloc_queue_gws(struct file *filep,
> + struct kfd_process *p, void *data)
> +{
> + int retval;
> + struct kfd_ioctl_alloc_queue_gws_args *args = data;
> + struct kfd_dev *dev = NULL;
> +
> + if (args->num_gws == 0)
> + return -EINVAL;

This could be useful to allow releasing GWS resources without having to 
destroy the queue. See also my comment in patch 5.

Other than that this looks good to me.

Regards,
   Felix


> +
> + if (!hws_gws_support ||
> + dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)
> + return -EINVAL;
> +
> + dev = kfd_device_by_id(args->gpu_id);
> + if (!dev) {
> + pr_debug("Could not find gpu id 0x%x\n", args->gpu_id);
> + return -EINVAL;
> + }
> +
> + mutex_lock(&p->mutex);
> + retval = pqm_set_gws(&p->pqm, args->queue_id, dev->gws);
> + mutex_unlock(&p->mutex);
> +
> + args->first_gws = 0;
> + return retval;
> +}
> +
>   static int kfd_ioctl_get_dmabuf_info(struct file *filep,
>   struct kfd_process *p, void *data)
>   {
> @@ -1761,6 +1789,8 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = 
> {
>   AMDKFD_IOCTL_DEF(AMDKFD_IOC_IMPORT_DMABUF,
>   kfd_ioctl_import_dmabuf, 0),
>   
> + AMDKFD_IOCTL_DEF(AMDKFD_IOC_ALLOC_QUEUE_GWS,
> + kfd_ioctl_alloc_queue_gws, 0),
>   };
>   
>   #define AMDKFD_CORE_IOCTL_COUNT ARRAY_SIZE(amdkfd_ioctls)
> diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
> index 20917c5..070d1bc 100644
> --- a/include/uapi/linux/kfd_ioctl.h
> +++ b/include/uapi/linux/kfd_ioctl.h
> @@ -410,6 +410,21 @@ struct kfd_ioctl_unmap_memory_from_gpu_args {
>   __u32 n_success;/* to/from KFD */
>   };
>   
> +/* Allocate GWS for specific queue
> + *
> + * @gpu_id:  device identifier
> + * @queue_id:queue's id that GWS is allocated for
> + * @num_gws: how many GWS to allocate
> + * @first_gws:   index of the first GWS allocated.
> + *   only support contiguous GWS allocation
> + */
> +struct kfd_ioctl_alloc_queue_gws_args {
> + __u32 gpu_id;   /* to KFD */
> + __u32 queue_id; /* to KFD */
> + __u32 num_gws;  /* to KFD */
> + __u32 first_gws;/* from KFD */
> +};
> +
>   struct kfd_ioctl_get_dmabuf_info_args {
>   __u64 size; /* from KFD */
>   __u64 metadata_ptr; /* to KFD */
> @@ -529,7 +544,10 @@ enum kfd_mmio_remap {
>   #define AMDKFD_IOC_IMPORT_DMABUF\
>   AMDKFD_IOWR(0x1D, struct kfd_ioctl_import_dmabuf_args)
>   
> +#define AMDKFD_IOC_ALLOC_QUEUE_GWS   \
> + AMDKFD_IOWR(0x1E, struct kfd_ioctl_alloc_queue_gws_args)
> +
>   #define AMDKFD_COMMAND_START0x01
> -#define AMDKFD_COMMAND_END   0x1E
> +#define AMDKFD_COMMAND_END   0x1F
>   
>   #endif
___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH 6/7] drm/amdkfd: New IOCTL to allocate queue GWS

2019-05-23 Thread Zeng, Oak
Add a new kfd ioctl to allocate queue GWS. Queue
GWS is released on queue destroy.

Change-Id: I60153c26a577992ad873e4292e759e5c3d5bbd15
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 30 ++
 include/uapi/linux/kfd_ioctl.h   | 20 +++-
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 38ae53f..f3f08fe 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -1559,6 +1559,34 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file 
*filep,
return err;
 }
 
+static int kfd_ioctl_alloc_queue_gws(struct file *filep,
+   struct kfd_process *p, void *data)
+{
+   int retval;
+   struct kfd_ioctl_alloc_queue_gws_args *args = data;
+   struct kfd_dev *dev = NULL;
+
+   if (args->num_gws == 0)
+   return -EINVAL;
+
+   if (!hws_gws_support ||
+   dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)
+   return -EINVAL;
+
+   dev = kfd_device_by_id(args->gpu_id);
+   if (!dev) {
+   pr_debug("Could not find gpu id 0x%x\n", args->gpu_id);
+   return -EINVAL;
+   }
+
+   mutex_lock(&p->mutex);
+   retval = pqm_set_gws(&p->pqm, args->queue_id, dev->gws);
+   mutex_unlock(&p->mutex);
+
+   args->first_gws = 0;
+   return retval;
+}
+
 static int kfd_ioctl_get_dmabuf_info(struct file *filep,
struct kfd_process *p, void *data)
 {
@@ -1761,6 +1789,8 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = {
AMDKFD_IOCTL_DEF(AMDKFD_IOC_IMPORT_DMABUF,
kfd_ioctl_import_dmabuf, 0),
 
+   AMDKFD_IOCTL_DEF(AMDKFD_IOC_ALLOC_QUEUE_GWS,
+   kfd_ioctl_alloc_queue_gws, 0),
 };
 
 #define AMDKFD_CORE_IOCTL_COUNTARRAY_SIZE(amdkfd_ioctls)
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index 20917c5..070d1bc 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -410,6 +410,21 @@ struct kfd_ioctl_unmap_memory_from_gpu_args {
__u32 n_success;/* to/from KFD */
 };
 
+/* Allocate GWS for specific queue
+ *
+ * @gpu_id:  device identifier
+ * @queue_id:queue's id that GWS is allocated for
+ * @num_gws: how many GWS to allocate
+ * @first_gws:   index of the first GWS allocated.
+ *   only support contiguous GWS allocation
+ */
+struct kfd_ioctl_alloc_queue_gws_args {
+   __u32 gpu_id;   /* to KFD */
+   __u32 queue_id; /* to KFD */
+   __u32 num_gws;  /* to KFD */
+   __u32 first_gws;/* from KFD */
+};
+
 struct kfd_ioctl_get_dmabuf_info_args {
__u64 size; /* from KFD */
__u64 metadata_ptr; /* to KFD */
@@ -529,7 +544,10 @@ enum kfd_mmio_remap {
 #define AMDKFD_IOC_IMPORT_DMABUF   \
AMDKFD_IOWR(0x1D, struct kfd_ioctl_import_dmabuf_args)
 
+#define AMDKFD_IOC_ALLOC_QUEUE_GWS \
+   AMDKFD_IOWR(0x1E, struct kfd_ioctl_alloc_queue_gws_args)
+
 #define AMDKFD_COMMAND_START   0x01
-#define AMDKFD_COMMAND_END 0x1E
+#define AMDKFD_COMMAND_END 0x1F
 
 #endif
-- 
2.7.4

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

Re: [PATCH 6/7] drm/amdkfd: New IOCTL to allocate queue GWS

2019-05-22 Thread Kuehling, Felix
On 2019-05-22 11:51 a.m., Zeng, Oak wrote:
> Add a new kfd ioctl to allocate queue GWS. Queue
> GWS is released on queue destroy.
>
> Change-Id: I60153c26a577992ad873e4292e759e5c3d5bbd15
> Signed-off-by: Oak Zeng 
> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 39 
> 
>   include/uapi/linux/kfd_ioctl.h   | 20 +++-
>   2 files changed, 58 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c 
> b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index 38ae53f..828bd66 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -1559,6 +1559,43 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file 
> *filep,
>   return err;
>   }
>   
> +static int kfd_ioctl_alloc_queue_gws(struct file *filep,
> + struct kfd_process *p, void *data)
> +{
> + int retval;
> + struct kfd_ioctl_alloc_queue_gws_args *args = data;
> + struct kfd_dev *dev = NULL;
> + struct kgd_mem *mem;
> +
> + if (args->num_gws == 0)
> + return -EINVAL;
> +
> + if (!hws_gws_support ||
> + dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)
> + return -EINVAL;
> +
> + dev = kfd_device_by_id(args->gpu_id);
> + if (!dev) {
> + pr_debug("Could not find gpu id 0x%x\n", args->gpu_id);
> + return -EINVAL;
> + }
> +
> + retval = amdgpu_amdkfd_add_gws_to_process(p->kgd_process_info,
> + dev->gws, &mem);

Do you want to move this into pqm_set_gws? The corresponding call to 
amdgpu_amdkfd_remove_from_gws is handled in pqm (during queue 
destruction) too.

Regards,
   Felix


> + if (unlikely(retval))
> + return retval;
> +
> + mutex_lock(&p->mutex);
> + retval = pqm_set_gws(&p->pqm, args->queue_id, mem);
> + mutex_unlock(&p->mutex);
> +
> + if (unlikely(retval))
> + amdgpu_amdkfd_remove_gws_from_process(p->kgd_process_info, mem);
> +
> + args->first_gws = 0;
> + return retval;
> +}
> +
>   static int kfd_ioctl_get_dmabuf_info(struct file *filep,
>   struct kfd_process *p, void *data)
>   {
> @@ -1761,6 +1798,8 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = 
> {
>   AMDKFD_IOCTL_DEF(AMDKFD_IOC_IMPORT_DMABUF,
>   kfd_ioctl_import_dmabuf, 0),
>   
> + AMDKFD_IOCTL_DEF(AMDKFD_IOC_ALLOC_QUEUE_GWS,
> + kfd_ioctl_alloc_queue_gws, 0),
>   };
>   
>   #define AMDKFD_CORE_IOCTL_COUNT ARRAY_SIZE(amdkfd_ioctls)
> diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
> index 20917c5..070d1bc 100644
> --- a/include/uapi/linux/kfd_ioctl.h
> +++ b/include/uapi/linux/kfd_ioctl.h
> @@ -410,6 +410,21 @@ struct kfd_ioctl_unmap_memory_from_gpu_args {
>   __u32 n_success;/* to/from KFD */
>   };
>   
> +/* Allocate GWS for specific queue
> + *
> + * @gpu_id:  device identifier
> + * @queue_id:queue's id that GWS is allocated for
> + * @num_gws: how many GWS to allocate
> + * @first_gws:   index of the first GWS allocated.
> + *   only support contiguous GWS allocation
> + */
> +struct kfd_ioctl_alloc_queue_gws_args {
> + __u32 gpu_id;   /* to KFD */
> + __u32 queue_id; /* to KFD */
> + __u32 num_gws;  /* to KFD */
> + __u32 first_gws;/* from KFD */
> +};
> +
>   struct kfd_ioctl_get_dmabuf_info_args {
>   __u64 size; /* from KFD */
>   __u64 metadata_ptr; /* to KFD */
> @@ -529,7 +544,10 @@ enum kfd_mmio_remap {
>   #define AMDKFD_IOC_IMPORT_DMABUF\
>   AMDKFD_IOWR(0x1D, struct kfd_ioctl_import_dmabuf_args)
>   
> +#define AMDKFD_IOC_ALLOC_QUEUE_GWS   \
> + AMDKFD_IOWR(0x1E, struct kfd_ioctl_alloc_queue_gws_args)
> +
>   #define AMDKFD_COMMAND_START0x01
> -#define AMDKFD_COMMAND_END   0x1E
> +#define AMDKFD_COMMAND_END   0x1F
>   
>   #endif
___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH 6/7] drm/amdkfd: New IOCTL to allocate queue GWS

2019-05-22 Thread Zeng, Oak
Add a new kfd ioctl to allocate queue GWS. Queue
GWS is released on queue destroy.

Change-Id: I60153c26a577992ad873e4292e759e5c3d5bbd15
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 39 
 include/uapi/linux/kfd_ioctl.h   | 20 +++-
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 38ae53f..828bd66 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -1559,6 +1559,43 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file 
*filep,
return err;
 }
 
+static int kfd_ioctl_alloc_queue_gws(struct file *filep,
+   struct kfd_process *p, void *data)
+{
+   int retval;
+   struct kfd_ioctl_alloc_queue_gws_args *args = data;
+   struct kfd_dev *dev = NULL;
+   struct kgd_mem *mem;
+
+   if (args->num_gws == 0)
+   return -EINVAL;
+
+   if (!hws_gws_support ||
+   dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)
+   return -EINVAL;
+
+   dev = kfd_device_by_id(args->gpu_id);
+   if (!dev) {
+   pr_debug("Could not find gpu id 0x%x\n", args->gpu_id);
+   return -EINVAL;
+   }
+
+   retval = amdgpu_amdkfd_add_gws_to_process(p->kgd_process_info,
+   dev->gws, &mem);
+   if (unlikely(retval))
+   return retval;
+
+   mutex_lock(&p->mutex);
+   retval = pqm_set_gws(&p->pqm, args->queue_id, mem);
+   mutex_unlock(&p->mutex);
+
+   if (unlikely(retval))
+   amdgpu_amdkfd_remove_gws_from_process(p->kgd_process_info, mem);
+
+   args->first_gws = 0;
+   return retval;
+}
+
 static int kfd_ioctl_get_dmabuf_info(struct file *filep,
struct kfd_process *p, void *data)
 {
@@ -1761,6 +1798,8 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = {
AMDKFD_IOCTL_DEF(AMDKFD_IOC_IMPORT_DMABUF,
kfd_ioctl_import_dmabuf, 0),
 
+   AMDKFD_IOCTL_DEF(AMDKFD_IOC_ALLOC_QUEUE_GWS,
+   kfd_ioctl_alloc_queue_gws, 0),
 };
 
 #define AMDKFD_CORE_IOCTL_COUNTARRAY_SIZE(amdkfd_ioctls)
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index 20917c5..070d1bc 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -410,6 +410,21 @@ struct kfd_ioctl_unmap_memory_from_gpu_args {
__u32 n_success;/* to/from KFD */
 };
 
+/* Allocate GWS for specific queue
+ *
+ * @gpu_id:  device identifier
+ * @queue_id:queue's id that GWS is allocated for
+ * @num_gws: how many GWS to allocate
+ * @first_gws:   index of the first GWS allocated.
+ *   only support contiguous GWS allocation
+ */
+struct kfd_ioctl_alloc_queue_gws_args {
+   __u32 gpu_id;   /* to KFD */
+   __u32 queue_id; /* to KFD */
+   __u32 num_gws;  /* to KFD */
+   __u32 first_gws;/* from KFD */
+};
+
 struct kfd_ioctl_get_dmabuf_info_args {
__u64 size; /* from KFD */
__u64 metadata_ptr; /* to KFD */
@@ -529,7 +544,10 @@ enum kfd_mmio_remap {
 #define AMDKFD_IOC_IMPORT_DMABUF   \
AMDKFD_IOWR(0x1D, struct kfd_ioctl_import_dmabuf_args)
 
+#define AMDKFD_IOC_ALLOC_QUEUE_GWS \
+   AMDKFD_IOWR(0x1E, struct kfd_ioctl_alloc_queue_gws_args)
+
 #define AMDKFD_COMMAND_START   0x01
-#define AMDKFD_COMMAND_END 0x1E
+#define AMDKFD_COMMAND_END 0x1F
 
 #endif
-- 
2.7.4

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

Re: [PATCH 6/7] drm/amdkfd: New IOCTL to allocate queue GWS

2019-05-21 Thread Kuehling, Felix
On 2019-05-15 4:37 p.m., Zeng, Oak wrote:
> [CAUTION: External Email]
>
> Add a new kfd ioctl to allocate queue GWS. Queue
> GWS is released on queue destroy.
>
> Change-Id: I60153c26a577992ad873e4292e759e5c3d5bbd15
> Signed-off-by: Oak Zeng 
> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   | 39 
> ++
>   .../gpu/drm/amd/amdkfd/kfd_process_queue_manager.c |  6 
>   include/uapi/linux/kfd_ioctl.h | 20 ++-
>   3 files changed, 64 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c 
> b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index 38ae53f..828bd66 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -1559,6 +1559,43 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file 
> *filep,
>  return err;
>   }
>
> +static int kfd_ioctl_alloc_queue_gws(struct file *filep,
> +   struct kfd_process *p, void *data)
> +{
> +   int retval;
> +   struct kfd_ioctl_alloc_queue_gws_args *args = data;
> +   struct kfd_dev *dev = NULL;
> +   struct kgd_mem *mem;
> +
> +   if (args->num_gws == 0)
> +   return -EINVAL;
> +
> +   if (!hws_gws_support ||
> +   dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)
> +   return -EINVAL;
> +
> +   dev = kfd_device_by_id(args->gpu_id);
> +   if (!dev) {
> +   pr_debug("Could not find gpu id 0x%x\n", args->gpu_id);
> +   return -EINVAL;
> +   }
> +
> +   retval = amdgpu_amdkfd_add_gws_to_process(p->kgd_process_info,
> +   dev->gws, &mem);
> +   if (unlikely(retval))
> +   return retval;
> +
> +   mutex_lock(&p->mutex);
> +   retval = pqm_set_gws(&p->pqm, args->queue_id, mem);
> +   mutex_unlock(&p->mutex);
> +
> +   if (unlikely(retval))
> +   amdgpu_amdkfd_remove_gws_from_process(p->kgd_process_info, 
> mem);
> +
> +   args->first_gws = 0;
> +   return retval;
> +}
> +
>   static int kfd_ioctl_get_dmabuf_info(struct file *filep,
>  struct kfd_process *p, void *data)
>   {
> @@ -1761,6 +1798,8 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = 
> {
>  AMDKFD_IOCTL_DEF(AMDKFD_IOC_IMPORT_DMABUF,
>  kfd_ioctl_import_dmabuf, 0),
>
> +   AMDKFD_IOCTL_DEF(AMDKFD_IOC_ALLOC_QUEUE_GWS,
> +   kfd_ioctl_alloc_queue_gws, 0),
>   };
>
>   #define AMDKFD_CORE_IOCTL_COUNTARRAY_SIZE(amdkfd_ioctls)
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c 
> b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> index 8e45296..e15ad48 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> @@ -363,6 +363,12 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, 
> unsigned int qid)
>  return -1;
>  }
>
> +   if (pqm_get_gws(pqm, qid)) {
> +   
> amdgpu_amdkfd_remove_gws_from_process(pqm->process->kgd_process_info,
> +   pqm_get_gws(pqm, qid));
> +   pqm_set_gws(pqm, qid, NULL);
> +   }
> +
>  if (pqn->kq) {
>  /* destroy kernel queue (DIQ) */
>  dqm = pqn->kq->dev->dqm;
> diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
> index 20917c5..912d690 100644
> --- a/include/uapi/linux/kfd_ioctl.h
> +++ b/include/uapi/linux/kfd_ioctl.h
> @@ -410,6 +410,21 @@ struct kfd_ioctl_unmap_memory_from_gpu_args {
>  __u32 n_success;/* to/from KFD */
>   };
>
> +/* Allocate GWS for specific queue
> + *
> + * @gpu_id:  device identifier
> + * @queue_id:queue's id that GWS is allocated for
> + * @num_gws: how many GWS to allocate
> + * @first_gws:   index of the first GWS allocated.
> + *   only support contiguous GWS allocation
> + */
> +struct kfd_ioctl_alloc_queue_gws_args {
> +   __u32 gpu_id;   /* to KFD */
> +   __u32 queue_id; /* to KFD */
> +   __u32 num_gws;  /* to KFD */
> +   __u32 first_gws;/* from KFD */
> +};
> +
>   struct kfd_ioctl_get_dmabuf_info_args {
>  __u64 size; /* from KFD */
>  __u64 metadata_ptr; /* to KFD */
> @@ -529,7 +544,10 @@ enum kfd_mmio_remap {
>   #define AMDKFD_IOC_IMPORT_DMABUF   \
>  AMDKFD_IOWR(0x1D, struct kfd_ioctl_import_dmabuf_args)
>
> +#define AMDKFD_IOC_ALLOC_QUEUE_GWS \
> +   AMDKFD_IOWR(0x22, struct kfd_ioctl_alloc_queue_gws_args)
> +

This has to be 0x1E for upstream. When we merge this back into 
amd-kfd-staging, we'll have to move the other non-upstream ioctl numbers.


>   #define AMDKFD_COMMAND_START   0x01
> -#define AMDKFD_COMMAND_END 0x1E
> +#define AMDKFD_COMMAND_END 0x23

0

[PATCH 6/7] drm/amdkfd: New IOCTL to allocate queue GWS

2019-05-15 Thread Zeng, Oak
Add a new kfd ioctl to allocate queue GWS. Queue
GWS is released on queue destroy.

Change-Id: I60153c26a577992ad873e4292e759e5c3d5bbd15
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   | 39 ++
 .../gpu/drm/amd/amdkfd/kfd_process_queue_manager.c |  6 
 include/uapi/linux/kfd_ioctl.h | 20 ++-
 3 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 38ae53f..828bd66 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -1559,6 +1559,43 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file 
*filep,
return err;
 }
 
+static int kfd_ioctl_alloc_queue_gws(struct file *filep,
+   struct kfd_process *p, void *data)
+{
+   int retval;
+   struct kfd_ioctl_alloc_queue_gws_args *args = data;
+   struct kfd_dev *dev = NULL;
+   struct kgd_mem *mem;
+
+   if (args->num_gws == 0)
+   return -EINVAL;
+
+   if (!hws_gws_support ||
+   dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)
+   return -EINVAL;
+
+   dev = kfd_device_by_id(args->gpu_id);
+   if (!dev) {
+   pr_debug("Could not find gpu id 0x%x\n", args->gpu_id);
+   return -EINVAL;
+   }
+
+   retval = amdgpu_amdkfd_add_gws_to_process(p->kgd_process_info,
+   dev->gws, &mem);
+   if (unlikely(retval))
+   return retval;
+
+   mutex_lock(&p->mutex);
+   retval = pqm_set_gws(&p->pqm, args->queue_id, mem);
+   mutex_unlock(&p->mutex);
+
+   if (unlikely(retval))
+   amdgpu_amdkfd_remove_gws_from_process(p->kgd_process_info, mem);
+
+   args->first_gws = 0;
+   return retval;
+}
+
 static int kfd_ioctl_get_dmabuf_info(struct file *filep,
struct kfd_process *p, void *data)
 {
@@ -1761,6 +1798,8 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = {
AMDKFD_IOCTL_DEF(AMDKFD_IOC_IMPORT_DMABUF,
kfd_ioctl_import_dmabuf, 0),
 
+   AMDKFD_IOCTL_DEF(AMDKFD_IOC_ALLOC_QUEUE_GWS,
+   kfd_ioctl_alloc_queue_gws, 0),
 };
 
 #define AMDKFD_CORE_IOCTL_COUNTARRAY_SIZE(amdkfd_ioctls)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
index 8e45296..e15ad48 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
@@ -363,6 +363,12 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, 
unsigned int qid)
return -1;
}
 
+   if (pqm_get_gws(pqm, qid)) {
+   
amdgpu_amdkfd_remove_gws_from_process(pqm->process->kgd_process_info,
+   pqm_get_gws(pqm, qid));
+   pqm_set_gws(pqm, qid, NULL);
+   }
+
if (pqn->kq) {
/* destroy kernel queue (DIQ) */
dqm = pqn->kq->dev->dqm;
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index 20917c5..912d690 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -410,6 +410,21 @@ struct kfd_ioctl_unmap_memory_from_gpu_args {
__u32 n_success;/* to/from KFD */
 };
 
+/* Allocate GWS for specific queue
+ *
+ * @gpu_id:  device identifier
+ * @queue_id:queue's id that GWS is allocated for
+ * @num_gws: how many GWS to allocate
+ * @first_gws:   index of the first GWS allocated.
+ *   only support contiguous GWS allocation
+ */
+struct kfd_ioctl_alloc_queue_gws_args {
+   __u32 gpu_id;   /* to KFD */
+   __u32 queue_id; /* to KFD */
+   __u32 num_gws;  /* to KFD */
+   __u32 first_gws;/* from KFD */
+};
+
 struct kfd_ioctl_get_dmabuf_info_args {
__u64 size; /* from KFD */
__u64 metadata_ptr; /* to KFD */
@@ -529,7 +544,10 @@ enum kfd_mmio_remap {
 #define AMDKFD_IOC_IMPORT_DMABUF   \
AMDKFD_IOWR(0x1D, struct kfd_ioctl_import_dmabuf_args)
 
+#define AMDKFD_IOC_ALLOC_QUEUE_GWS \
+   AMDKFD_IOWR(0x22, struct kfd_ioctl_alloc_queue_gws_args)
+
 #define AMDKFD_COMMAND_START   0x01
-#define AMDKFD_COMMAND_END 0x1E
+#define AMDKFD_COMMAND_END 0x23
 
 #endif
-- 
2.7.4

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