<div dir="ltr"><div><div><div>I was thinking of that originally, but the allocation context already has a flags variable which allows us to preserve the IOCTL ABI.<br><br></div>We could reserve a few bits of the flags for a priority level instead if that sounds good?<br><br></div>Regards,<br></div>Andres<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 3, 2017 at 5:59 PM, Alex Deucher <span dir="ltr"><<a href="mailto:alexdeucher@gmail.com" target="_blank">alexdeucher@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue, Jan 3, 2017 at 5:54 PM, Andres Rodriguez <<a href="mailto:andresx7@gmail.com">andresx7@gmail.com</a>> wrote:<br>
> Add a new context creation flag, AMDGPU_CTX_FLAG_HIGHPRIORITY. This flag<br>
> results in the allocated context receiving a higher scheduler priority<br>
> that other contexts system-wide.<br>
><br>
> Signed-off-by: Andres Rodriguez <<a href="mailto:andresx7@gmail.com">andresx7@gmail.com</a>><br>
> ---<br>
>  drivers/gpu/drm/amd/amdgpu/<wbr>amdgpu_ctx.c       | 24 ++++++++++++++++++------<br>
>  drivers/gpu/drm/amd/scheduler/<wbr>gpu_scheduler.h |  1 +<br>
>  include/uapi/drm/amdgpu_drm.h                 |  3 ++-<br>
>  3 files changed, 21 insertions(+), 7 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/<wbr>amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/<wbr>amdgpu_ctx.c<br>
> index 400c66b..ce470e2 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/<wbr>amdgpu_ctx.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/<wbr>amdgpu_ctx.c<br>
> @@ -25,11 +25,17 @@<br>
>  #include <drm/drmP.h><br>
>  #include "amdgpu.h"<br>
><br>
> -static int amdgpu_ctx_init(struct amdgpu_device *adev, struct amdgpu_ctx *ctx)<br>
> +static int amdgpu_ctx_init(struct amdgpu_device *adev, int priority, struct amdgpu_ctx *ctx)<br>
>  {<br>
>         unsigned i, j;<br>
>         int r;<br>
><br>
> +       if (priority < 0 || priority >= AMD_SCHED_MAX_PRIORITY)<br>
> +               return -EINVAL;<br>
> +<br>
> +       if (priority == AMD_SCHED_PRIORITY_HIGH && !capable(CAP_SYS_ADMIN))<br>
> +               return -EACCES;<br>
> +<br>
>         memset(ctx, 0, sizeof(*ctx));<br>
>         ctx->adev = adev;<br>
>         kref_init(&ctx->refcount);<br>
> @@ -51,7 +57,7 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev, struct amdgpu_ctx *ctx)<br>
>                 struct amdgpu_ring *ring = adev->rings[i];<br>
>                 struct amd_sched_rq *rq;<br>
><br>
> -               rq = &ring->sched.sched_rq[AMD_<wbr>SCHED_PRIORITY_NORMAL];<br>
> +               rq = &ring->sched.sched_rq[<wbr>priority];<br>
>                 r = amd_sched_entity_init(&ring-><wbr>sched, &ctx->rings[i].entity,<br>
>                                           rq, amdgpu_sched_jobs);<br>
>                 if (r)<br>
> @@ -90,11 +96,15 @@ static void amdgpu_ctx_fini(struct amdgpu_ctx *ctx)<br>
><br>
>  static int amdgpu_ctx_alloc(struct amdgpu_device *adev,<br>
>                             struct amdgpu_fpriv *fpriv,<br>
> +                           int flags,<br>
>                             uint32_t *id)<br>
>  {<br>
>         struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr;<br>
>         struct amdgpu_ctx *ctx;<br>
> -       int r;<br>
> +       int r, priority;<br>
> +<br>
> +       priority = flags & AMDGPU_CTX_FLAG_HIGHPRIORITY ?<br>
> +               AMD_SCHED_PRIORITY_HIGH : AMD_SCHED_PRIORITY_NORMAL;<br>
><br>
>         ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);<br>
>         if (!ctx)<br>
> @@ -107,8 +117,9 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,<br>
>                 kfree(ctx);<br>
>                 return r;<br>
>         }<br>
> +<br>
>         *id = (uint32_t)r;<br>
> -       r = amdgpu_ctx_init(adev, ctx);<br>
> +       r = amdgpu_ctx_init(adev, priority, ctx);<br>
>         if (r) {<br>
>                 idr_remove(&mgr->ctx_handles, *id);<br>
>                 *id = 0;<br>
> @@ -186,7 +197,7 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,<br>
>                      struct drm_file *filp)<br>
>  {<br>
>         int r;<br>
> -       uint32_t id;<br>
> +       uint32_t id, flags;<br>
><br>
>         union drm_amdgpu_ctx *args = data;<br>
>         struct amdgpu_device *adev = dev->dev_private;<br>
> @@ -194,10 +205,11 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,<br>
><br>
>         r = 0;<br>
>         id = args->in.ctx_id;<br>
> +       flags = args->in.flags;<br>
><br>
>         switch (args->in.op) {<br>
>         case AMDGPU_CTX_OP_ALLOC_CTX:<br>
> -               r = amdgpu_ctx_alloc(adev, fpriv, &id);<br>
> +               r = amdgpu_ctx_alloc(adev, fpriv, flags, &id);<br>
>                 args->out.alloc.ctx_id = id;<br>
>                 break;<br>
>         case AMDGPU_CTX_OP_FREE_CTX:<br>
> diff --git a/drivers/gpu/drm/amd/<wbr>scheduler/gpu_scheduler.h b/drivers/gpu/drm/amd/<wbr>scheduler/gpu_scheduler.h<br>
> index d8dc681..2e458de 100644<br>
> --- a/drivers/gpu/drm/amd/<wbr>scheduler/gpu_scheduler.h<br>
> +++ b/drivers/gpu/drm/amd/<wbr>scheduler/gpu_scheduler.h<br>
> @@ -108,6 +108,7 @@ struct amd_sched_backend_ops {<br>
><br>
>  enum amd_sched_priority {<br>
>         AMD_SCHED_PRIORITY_KERNEL = 0,<br>
> +       AMD_SCHED_PRIORITY_HIGH,<br>
>         AMD_SCHED_PRIORITY_NORMAL,<br>
>         AMD_SCHED_MAX_PRIORITY<br>
>  };<br>
> diff --git a/include/uapi/drm/amdgpu_drm.<wbr>h b/include/uapi/drm/amdgpu_drm.<wbr>h<br>
> index 3961836..702332e 100644<br>
> --- a/include/uapi/drm/amdgpu_drm.<wbr>h<br>
> +++ b/include/uapi/drm/amdgpu_drm.<wbr>h<br>
> @@ -160,10 +160,11 @@ union drm_amdgpu_bo_list {<br>
>  /* unknown cause */<br>
>  #define AMDGPU_CTX_UNKNOWN_RESET       3<br>
><br>
> +#define AMDGPU_CTX_FLAG_HIGHPRIORITY   (1 << 0)<br>
<br>
</div></div>Would it be better to expose a priority level rather than a single<br>
flag?  If we want to expose more than just normal/high in the future<br>
for example.<br>
<br>
Alex<br>
<span class=""><br>
>  struct drm_amdgpu_ctx_in {<br>
>         /** AMDGPU_CTX_OP_* */<br>
>         __u32   op;<br>
> -       /** For future use, no flags defined so far */<br>
> +       /** AMDGPU_CTX_FLAG_* */<br>
>         __u32   flags;<br>
>         __u32   ctx_id;<br>
>         __u32   _pad;<br>
> --<br>
> 2.7.4<br>
><br>
</span>> ______________________________<wbr>_________________<br>
> amd-gfx mailing list<br>
> <a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/amd-gfx</a><br>
</blockquote></div><br></div>