<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    Am 01.05.22 um 21:45 schrieb Arunpravin Paneer Selvam:<br>
    <blockquote type="cite" cite="mid:b42d6e3d-e646-8bcb-6166-bdb94ddd1d69@amd.com">
      
      <br>
      On 5/1/2022 12:59 AM, Christian König wrote:<br>
      <blockquote type="cite" cite="mid:85927512-377e-39b1-d812-ef9bddcc2f02@gmail.com">Am
        30.04.22 um 17:14 schrieb Arunpravin Paneer Selvam: <br>
        <blockquote type="cite">- Add pipe and queue as out parameters
          to support high priority <br>
             queue test enabled in libdrm basic test suite. <br>
          <br>
          - Fetch amdgpu_ring pointer and pass sched info to userspace <br>
          <br>
          - Improve amdgpu_sched_ioctl() function <br>
          <br>
          The related merge request for enabling high priority test case
          are <br>
          libdrm -
          <a class="moz-txt-link-freetext" href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fmesa%2Fdrm%2F-%2Fmerge_requests%2F235&amp;data=05%7C01%7CArunpravin.PaneerSelvam%40amd.com%7Ce7a876029be4439b742808da2adfb82a%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637869437601696844%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=jXIBtdA4seXl%2BYKsY2SDu%2B9tPoH6tfvUUXIRl4IosJc%3D&amp;reserved=0" moz-do-not-send="true">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fmesa%2Fdrm%2F-%2Fmerge_requests%2F235&amp;data=05%7C01%7CArunpravin.PaneerSelvam%40amd.com%7Ce7a876029be4439b742808da2adfb82a%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637869437601696844%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=jXIBtdA4seXl%2BYKsY2SDu%2B9tPoH6tfvUUXIRl4IosJc%3D&amp;reserved=0</a><br>
          mesa -
          <a class="moz-txt-link-freetext" href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fmesa%2Fmesa%2F-%2Fmerge_requests%2F16262&amp;data=05%7C01%7CArunpravin.PaneerSelvam%40amd.com%7Ce7a876029be4439b742808da2adfb82a%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637869437601696844%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=%2F%2FwMJ86SXxP7K9STA%2B1x5rox1F5CPEy3JIhFMCjqwiY%3D&amp;reserved=0" moz-do-not-send="true">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fmesa%2Fmesa%2F-%2Fmerge_requests%2F16262&amp;data=05%7C01%7CArunpravin.PaneerSelvam%40amd.com%7Ce7a876029be4439b742808da2adfb82a%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637869437601696844%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=%2F%2FwMJ86SXxP7K9STA%2B1x5rox1F5CPEy3JIhFMCjqwiY%3D&amp;reserved=0</a><br>
          <br>
          Signed-off-by: Arunpravin Paneer Selvam <a class="moz-txt-link-rfc2396E" href="mailto:Arunpravin.PaneerSelvam@amd.com" moz-do-not-send="true"><Arunpravin.PaneerSelvam@amd.com></a>
          <br>
        </blockquote>
        <br>
        Well that is certainly a NAK since as far as I can see this
        breaks the UAPI in a not backward compatible way. <br>
        <br>
        Then we absolutely should not pass scheduler info to userspace.
        That should be completely transparent to userspace. <br>
        <br>
        So can you summarize once more why that should be necessary?<br>
      </blockquote>
      I added a new test case named high priority queue test in libdrm
      basic test suite to validate the kernel feature patch named<br>
      <span style="mso-spacerun:yes"></span>high priority gfx pipe. In
      the test case, we are creating a context and overriding the
      priority as HIGH, submitting a simple NOP<br>
      command to test the job scheduled on high priority pipe / queue.
      This we have manually verified using the sysfs entry<br>
      amdgpu_fence_info where fence signaled on gfx high priority pipe
      (gfx_0.1.0). To ensure this in a unit test case, we require<br>
      pipe and queue info.<br>
    </blockquote>
    <br>
    Completely drop that requirement, it's not even remotely valid
    justification for an UAPI change.<br>
    <br>
    The IOCTLs are for supporting userspace APIs like OpenGL, Vulkan,
    VA-API etc.. and *not* unit tests.<br>
    <br>
    If you need additional information for unit tests we need to add
    that to debugfs instead and as you wrote we already have that in the
    form of the amdgpu_fence_info file.<br>
    <br>
    Regards,<br>
    Christian.<br>
    <br>
    <blockquote type="cite" cite="mid:b42d6e3d-e646-8bcb-6166-bdb94ddd1d69@amd.com"> <br>
      Thanks,<br>
      Arun<br>
      <blockquote type="cite" cite="mid:85927512-377e-39b1-d812-ef9bddcc2f02@gmail.com"> <br>
        Regards, <br>
        Christian. <br>
        <br>
        <blockquote type="cite">--- <br>
            drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c | 114
          ++++++++-------------- <br>
            include/uapi/drm/amdgpu_drm.h             |  14 ++- <br>
            2 files changed, 53 insertions(+), 75 deletions(-) <br>
          <br>
          diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c
          b/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c <br>
          index e9b45089a28a..fc2864b612d9 100644 <br>
          --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c <br>
          +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c <br>
          @@ -32,106 +32,72 @@ <br>
            #include "amdgpu_sched.h" <br>
            #include "amdgpu_vm.h" <br>
            -static int amdgpu_sched_process_priority_override(struct
          amdgpu_device *adev, <br>
          -                          int fd, <br>
          -                          int32_t priority) <br>
          +int amdgpu_sched_ioctl(struct drm_device *dev, void *data, <br>
          +               struct drm_file *filp) <br>
            { <br>
          -    struct fd f = fdget(fd); <br>
          +    union drm_amdgpu_sched *args = data; <br>
          +    struct amdgpu_ctx *ctx, *ctx_ptr; <br>
          +    struct drm_sched_entity *entity; <br>
                struct amdgpu_fpriv *fpriv; <br>
          -    struct amdgpu_ctx *ctx; <br>
          -    uint32_t id; <br>
          -    int r; <br>
          - <br>
          -    if (!f.file) <br>
          -        return -EINVAL; <br>
          - <br>
          -    r = amdgpu_file_to_fpriv(f.file, &fpriv); <br>
          -    if (r) { <br>
          -        fdput(f); <br>
          -        return r; <br>
          -    } <br>
          - <br>
          -    idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles,
          ctx, id) <br>
          -        amdgpu_ctx_priority_override(ctx, priority); <br>
          - <br>
          -    fdput(f); <br>
          -    return 0; <br>
          -} <br>
          - <br>
          -static int amdgpu_sched_context_priority_override(struct
          amdgpu_device *adev, <br>
          -                          int fd, <br>
          -                          unsigned ctx_id, <br>
          -                          int32_t priority) <br>
          -{ <br>
          +    struct amdgpu_ring *ring; <br>
          +    u32 fd = args->in.fd; <br>
                struct fd f = fdget(fd); <br>
          -    struct amdgpu_fpriv *fpriv; <br>
          -    struct amdgpu_ctx *ctx; <br>
          +    u32 id; <br>
                int r; <br>
                  if (!f.file) <br>
                    return -EINVAL; <br>
                  r = amdgpu_file_to_fpriv(f.file, &fpriv); <br>
          -    if (r) { <br>
          -        fdput(f); <br>
          -        return r; <br>
          -    } <br>
          +    if (r) <br>
          +        goto out_fd; <br>
            -    ctx = amdgpu_ctx_get(fpriv, ctx_id); <br>
          +    ctx = amdgpu_ctx_get(fpriv, args->in.ctx_id); <br>
                  if (!ctx) { <br>
          -        fdput(f); <br>
          -        return -EINVAL; <br>
          -    } <br>
          - <br>
          -    amdgpu_ctx_priority_override(ctx, priority); <br>
          -    amdgpu_ctx_put(ctx); <br>
          -    fdput(f); <br>
          - <br>
          -    return 0; <br>
          -} <br>
          - <br>
          -int amdgpu_sched_ioctl(struct drm_device *dev, void *data, <br>
          -               struct drm_file *filp) <br>
          -{ <br>
          -    union drm_amdgpu_sched *args = data; <br>
          -    struct amdgpu_device *adev = drm_to_adev(dev); <br>
          -    int r; <br>
          - <br>
          -    /* First check the op, then the op's argument. <br>
          -     */ <br>
          -    switch (args->in.op) { <br>
          -    case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE: <br>
          -    case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE: <br>
          -        break; <br>
          -    default: <br>
          -        DRM_ERROR("Invalid sched op specified: %d\n",
          args->in.op); <br>
          -        return -EINVAL; <br>
          +        r = -EINVAL; <br>
          +        goto out_fd; <br>
                } <br>
                  if
          (!amdgpu_ctx_priority_is_valid(args->in.priority)) { <br>
                    WARN(1, "Invalid context priority %d\n",
          args->in.priority); <br>
          -        return -EINVAL; <br>
          +        r = -EINVAL; <br>
          +        goto out_ctx; <br>
                } <br>
                  switch (args->in.op) { <br>
                case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE: <br>
          -        r = amdgpu_sched_process_priority_override(adev, <br>
          -                               args->in.fd, <br>
          -                               args->in.priority); <br>
          +        /* Retrieve all ctx handles and override priority  */
          <br>
          +       
          idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles,
          ctx_ptr, id) <br>
          +            amdgpu_ctx_priority_override(ctx_ptr,
          args->in.priority); <br>
                    break; <br>
                case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE: <br>
          -        r = amdgpu_sched_context_priority_override(adev, <br>
          -                               args->in.fd, <br>
          -                               args->in.ctx_id, <br>
          -                               args->in.priority); <br>
          +        /* Override priority for a given context */ <br>
          +        amdgpu_ctx_priority_override(ctx,
          args->in.priority); <br>
                    break; <br>
                default: <br>
          -        /* Impossible. <br>
          -         */ <br>
          +        DRM_ERROR("Invalid sched op specified: %d\n",
          args->in.op); <br>
                    r = -EINVAL; <br>
          -        break; <br>
          +        goto out_ctx; <br>
                } <br>
            +    r = amdgpu_ctx_get_entity(ctx, args->in.ip_type, 0,
          args->in.ring, <br>
          +                  &entity); <br>
          +    if (r) <br>
          +        goto out_ctx; <br>
          + <br>
          +    /* Fetch amdgpu_ring pointer */ <br>
          +    ring = to_amdgpu_ring(entity->rq->sched); <br>
          + <br>
          +    /* Pass sched info to userspace */ <br>
          +    memset(args, 0, sizeof(*args)); <br>
          +    args->out.info.pipe = ring->pipe; <br>
          +    args->out.info.queue = ring->queue; <br>
          + <br>
          +out_ctx: <br>
          +    amdgpu_ctx_put(ctx); <br>
          +out_fd: <br>
          +    fdput(f); <br>
          + <br>
                return r; <br>
            } <br>
          diff --git a/include/uapi/drm/amdgpu_drm.h
          b/include/uapi/drm/amdgpu_drm.h <br>
          index 1d65c1fbc4ec..e93f1b6c4561 100644 <br>
          --- a/include/uapi/drm/amdgpu_drm.h <br>
          +++ b/include/uapi/drm/amdgpu_drm.h <br>
          @@ -70,7 +70,7 @@ extern "C" { <br>
            #define DRM_IOCTL_AMDGPU_WAIT_FENCES   
          DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_WAIT_FENCES, union
          drm_amdgpu_wait_fences) <br>
            #define DRM_IOCTL_AMDGPU_VM        DRM_IOWR(DRM_COMMAND_BASE
          + DRM_AMDGPU_VM, union drm_amdgpu_vm) <br>
            #define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE
          DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union
          drm_amdgpu_fence_to_handle) <br>
          -#define DRM_IOCTL_AMDGPU_SCHED       
          DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union
          drm_amdgpu_sched) <br>
          +#define DRM_IOCTL_AMDGPU_SCHED       
          DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union
          drm_amdgpu_sched) <br>
              /** <br>
             * DOC: memory domains <br>
          @@ -308,6 +308,11 @@ union drm_amdgpu_vm { <br>
            #define AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE    1 <br>
            #define AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE    2 <br>
            +struct drm_amdgpu_sched_info { <br>
          +    __u32 pipe; <br>
          +    __u32 queue; <br>
          +}; <br>
          + <br>
            struct drm_amdgpu_sched_in { <br>
                /* AMDGPU_SCHED_OP_* */ <br>
                __u32    op; <br>
          @@ -315,10 +320,17 @@ struct drm_amdgpu_sched_in { <br>
                /** AMDGPU_CTX_PRIORITY_* */ <br>
                __s32    priority; <br>
                __u32   ctx_id; <br>
          +    __u32   ip_type; <br>
          +    __u32   ring; <br>
          +}; <br>
          + <br>
          +struct drm_amdgpu_sched_out { <br>
          +    struct drm_amdgpu_sched_info info; <br>
            }; <br>
              union drm_amdgpu_sched { <br>
                struct drm_amdgpu_sched_in in; <br>
          +    struct drm_amdgpu_sched_out out; <br>
            }; <br>
              /* <br>
        </blockquote>
        <br>
      </blockquote>
      <br>
    </blockquote>
    <br>
  </body>
</html>