amdgpu_sched.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright 2017 Valve Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Andres Rodriguez <andresx7@gmail.com>
  23. */
  24. #include <linux/fdtable.h>
  25. #include <linux/pid.h>
  26. #include <drm/amdgpu_drm.h>
  27. #include "amdgpu.h"
  28. #include "amdgpu_vm.h"
  29. enum drm_sched_priority amdgpu_to_sched_priority(int amdgpu_priority)
  30. {
  31. switch (amdgpu_priority) {
  32. case AMDGPU_CTX_PRIORITY_VERY_HIGH:
  33. return DRM_SCHED_PRIORITY_HIGH_HW;
  34. case AMDGPU_CTX_PRIORITY_HIGH:
  35. return DRM_SCHED_PRIORITY_HIGH_SW;
  36. case AMDGPU_CTX_PRIORITY_NORMAL:
  37. return DRM_SCHED_PRIORITY_NORMAL;
  38. case AMDGPU_CTX_PRIORITY_LOW:
  39. case AMDGPU_CTX_PRIORITY_VERY_LOW:
  40. return DRM_SCHED_PRIORITY_LOW;
  41. case AMDGPU_CTX_PRIORITY_UNSET:
  42. return DRM_SCHED_PRIORITY_UNSET;
  43. default:
  44. WARN(1, "Invalid context priority %d\n", amdgpu_priority);
  45. return DRM_SCHED_PRIORITY_INVALID;
  46. }
  47. }
  48. static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
  49. int fd,
  50. enum drm_sched_priority priority)
  51. {
  52. struct file *filp = fcheck(fd);
  53. struct drm_file *file;
  54. struct pid *pid;
  55. struct amdgpu_fpriv *fpriv;
  56. struct amdgpu_ctx *ctx;
  57. uint32_t id;
  58. if (!filp)
  59. return -EINVAL;
  60. pid = get_pid(((struct drm_file *)filp->private_data)->pid);
  61. mutex_lock(&adev->ddev->filelist_mutex);
  62. list_for_each_entry(file, &adev->ddev->filelist, lhead) {
  63. if (file->pid != pid)
  64. continue;
  65. fpriv = file->driver_priv;
  66. idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id)
  67. amdgpu_ctx_priority_override(ctx, priority);
  68. }
  69. mutex_unlock(&adev->ddev->filelist_mutex);
  70. put_pid(pid);
  71. return 0;
  72. }
  73. int amdgpu_sched_ioctl(struct drm_device *dev, void *data,
  74. struct drm_file *filp)
  75. {
  76. union drm_amdgpu_sched *args = data;
  77. struct amdgpu_device *adev = dev->dev_private;
  78. enum drm_sched_priority priority;
  79. int r;
  80. priority = amdgpu_to_sched_priority(args->in.priority);
  81. if (args->in.flags || priority == DRM_SCHED_PRIORITY_INVALID)
  82. return -EINVAL;
  83. switch (args->in.op) {
  84. case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
  85. r = amdgpu_sched_process_priority_override(adev,
  86. args->in.fd,
  87. priority);
  88. break;
  89. default:
  90. DRM_ERROR("Invalid sched op specified: %d\n", args->in.op);
  91. r = -EINVAL;
  92. break;
  93. }
  94. return r;
  95. }