gpu_scheduler.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright 2015 Advanced Micro Devices, Inc.
  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. */
  23. #ifndef _GPU_SCHEDULER_H_
  24. #define _GPU_SCHEDULER_H_
  25. #include <linux/kfifo.h>
  26. #include <linux/fence.h>
  27. struct amd_gpu_scheduler;
  28. struct amd_sched_rq;
  29. /**
  30. * A scheduler entity is a wrapper around a job queue or a group
  31. * of other entities. Entities take turns emitting jobs from their
  32. * job queues to corresponding hardware ring based on scheduling
  33. * policy.
  34. */
  35. struct amd_sched_entity {
  36. struct list_head list;
  37. struct amd_sched_rq *rq;
  38. struct amd_gpu_scheduler *sched;
  39. spinlock_t queue_lock;
  40. struct kfifo job_queue;
  41. atomic_t fence_seq;
  42. uint64_t fence_context;
  43. struct fence *dependency;
  44. struct fence_cb cb;
  45. };
  46. /**
  47. * Run queue is a set of entities scheduling command submissions for
  48. * one specific ring. It implements the scheduling policy that selects
  49. * the next entity to emit commands from.
  50. */
  51. struct amd_sched_rq {
  52. spinlock_t lock;
  53. struct list_head entities;
  54. struct amd_sched_entity *current_entity;
  55. };
  56. struct amd_sched_fence {
  57. struct fence base;
  58. struct fence_cb cb;
  59. struct amd_gpu_scheduler *sched;
  60. spinlock_t lock;
  61. void *owner;
  62. };
  63. struct amd_sched_job {
  64. struct amd_gpu_scheduler *sched;
  65. struct amd_sched_entity *s_entity;
  66. struct amd_sched_fence *s_fence;
  67. void *owner;
  68. };
  69. extern const struct fence_ops amd_sched_fence_ops;
  70. static inline struct amd_sched_fence *to_amd_sched_fence(struct fence *f)
  71. {
  72. struct amd_sched_fence *__f = container_of(f, struct amd_sched_fence, base);
  73. if (__f->base.ops == &amd_sched_fence_ops)
  74. return __f;
  75. return NULL;
  76. }
  77. /**
  78. * Define the backend operations called by the scheduler,
  79. * these functions should be implemented in driver side
  80. */
  81. struct amd_sched_backend_ops {
  82. struct fence *(*dependency)(struct amd_sched_job *sched_job);
  83. struct fence *(*run_job)(struct amd_sched_job *sched_job);
  84. };
  85. /**
  86. * One scheduler is implemented for each hardware ring
  87. */
  88. struct amd_gpu_scheduler {
  89. struct amd_sched_backend_ops *ops;
  90. uint32_t hw_submission_limit;
  91. const char *name;
  92. struct amd_sched_rq sched_rq;
  93. struct amd_sched_rq kernel_rq;
  94. wait_queue_head_t wake_up_worker;
  95. wait_queue_head_t job_scheduled;
  96. atomic_t hw_rq_count;
  97. struct task_struct *thread;
  98. };
  99. int amd_sched_init(struct amd_gpu_scheduler *sched,
  100. struct amd_sched_backend_ops *ops,
  101. uint32_t hw_submission, const char *name);
  102. void amd_sched_fini(struct amd_gpu_scheduler *sched);
  103. int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
  104. struct amd_sched_entity *entity,
  105. struct amd_sched_rq *rq,
  106. uint32_t jobs);
  107. void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
  108. struct amd_sched_entity *entity);
  109. int amd_sched_entity_push_job(struct amd_sched_job *sched_job);
  110. struct amd_sched_fence *amd_sched_fence_create(
  111. struct amd_sched_entity *s_entity, void *owner);
  112. void amd_sched_fence_signal(struct amd_sched_fence *fence);
  113. #endif