0290-drm-vc4-improve-throughput-by-pipelining-binning-and.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. From d5bd63dfce65ffdda325e7b2bb6e37266af17e26 Mon Sep 17 00:00:00 2001
  2. From: Varad Gautam <varadgautam@gmail.com>
  3. Date: Wed, 17 Feb 2016 19:08:21 +0530
  4. Subject: [PATCH] drm/vc4: improve throughput by pipelining binning and
  5. rendering jobs
  6. The hardware provides us with separate threads for binning and
  7. rendering, and the existing model waits for them both to complete
  8. before submitting the next job.
  9. Splitting the binning and rendering submissions reduces idle time and
  10. gives us approx 20-30% speedup with some x11perf tests such as -line10
  11. and -tilerect1. Improves openarena performance by 1.01897% +/-
  12. 0.247857% (n=16).
  13. Thanks to anholt for suggesting this.
  14. v2: Rebase on the spurious resets fix (change by anholt).
  15. Signed-off-by: Varad Gautam <varadgautam@gmail.com>
  16. Reviewed-by: Eric Anholt <eric@anholt.net>
  17. Signed-off-by: Eric Anholt <eric@anholt.net>
  18. (cherry picked from commit ca26d28bbaa39f31d5e7e4812603b015c8d54207)
  19. ---
  20. drivers/gpu/drm/vc4/vc4_drv.h | 37 +++++++++----
  21. drivers/gpu/drm/vc4/vc4_gem.c | 123 ++++++++++++++++++++++++++++++------------
  22. drivers/gpu/drm/vc4/vc4_irq.c | 58 ++++++++++++++++----
  23. 3 files changed, 166 insertions(+), 52 deletions(-)
  24. --- a/drivers/gpu/drm/vc4/vc4_drv.h
  25. +++ b/drivers/gpu/drm/vc4/vc4_drv.h
  26. @@ -53,7 +53,7 @@ struct vc4_dev {
  27. /* Protects bo_cache and the BO stats. */
  28. struct mutex bo_lock;
  29. - /* Sequence number for the last job queued in job_list.
  30. + /* Sequence number for the last job queued in bin_job_list.
  31. * Starts at 0 (no jobs emitted).
  32. */
  33. uint64_t emit_seqno;
  34. @@ -63,11 +63,19 @@ struct vc4_dev {
  35. */
  36. uint64_t finished_seqno;
  37. - /* List of all struct vc4_exec_info for jobs to be executed.
  38. - * The first job in the list is the one currently programmed
  39. - * into ct0ca/ct1ca for execution.
  40. + /* List of all struct vc4_exec_info for jobs to be executed in
  41. + * the binner. The first job in the list is the one currently
  42. + * programmed into ct0ca for execution.
  43. + */
  44. + struct list_head bin_job_list;
  45. +
  46. + /* List of all struct vc4_exec_info for jobs that have
  47. + * completed binning and are ready for rendering. The first
  48. + * job in the list is the one currently programmed into ct1ca
  49. + * for execution.
  50. */
  51. - struct list_head job_list;
  52. + struct list_head render_job_list;
  53. +
  54. /* List of the finished vc4_exec_infos waiting to be freed by
  55. * job_done_work.
  56. */
  57. @@ -291,11 +299,20 @@ struct vc4_exec_info {
  58. };
  59. static inline struct vc4_exec_info *
  60. -vc4_first_job(struct vc4_dev *vc4)
  61. +vc4_first_bin_job(struct vc4_dev *vc4)
  62. +{
  63. + if (list_empty(&vc4->bin_job_list))
  64. + return NULL;
  65. + return list_first_entry(&vc4->bin_job_list, struct vc4_exec_info, head);
  66. +}
  67. +
  68. +static inline struct vc4_exec_info *
  69. +vc4_first_render_job(struct vc4_dev *vc4)
  70. {
  71. - if (list_empty(&vc4->job_list))
  72. + if (list_empty(&vc4->render_job_list))
  73. return NULL;
  74. - return list_first_entry(&vc4->job_list, struct vc4_exec_info, head);
  75. + return list_first_entry(&vc4->render_job_list,
  76. + struct vc4_exec_info, head);
  77. }
  78. /**
  79. @@ -410,7 +427,9 @@ int vc4_wait_seqno_ioctl(struct drm_devi
  80. struct drm_file *file_priv);
  81. int vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
  82. struct drm_file *file_priv);
  83. -void vc4_submit_next_job(struct drm_device *dev);
  84. +void vc4_submit_next_bin_job(struct drm_device *dev);
  85. +void vc4_submit_next_render_job(struct drm_device *dev);
  86. +void vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec);
  87. int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno,
  88. uint64_t timeout_ns, bool interruptible);
  89. void vc4_job_handle_completed(struct vc4_dev *vc4);
  90. --- a/drivers/gpu/drm/vc4/vc4_gem.c
  91. +++ b/drivers/gpu/drm/vc4/vc4_gem.c
  92. @@ -154,10 +154,10 @@ vc4_save_hang_state(struct drm_device *d
  93. struct vc4_dev *vc4 = to_vc4_dev(dev);
  94. struct drm_vc4_get_hang_state *state;
  95. struct vc4_hang_state *kernel_state;
  96. - struct vc4_exec_info *exec;
  97. + struct vc4_exec_info *exec[2];
  98. struct vc4_bo *bo;
  99. unsigned long irqflags;
  100. - unsigned int i, unref_list_count;
  101. + unsigned int i, j, unref_list_count, prev_idx;
  102. kernel_state = kcalloc(1, sizeof(*kernel_state), GFP_KERNEL);
  103. if (!kernel_state)
  104. @@ -166,37 +166,55 @@ vc4_save_hang_state(struct drm_device *d
  105. state = &kernel_state->user_state;
  106. spin_lock_irqsave(&vc4->job_lock, irqflags);
  107. - exec = vc4_first_job(vc4);
  108. - if (!exec) {
  109. + exec[0] = vc4_first_bin_job(vc4);
  110. + exec[1] = vc4_first_render_job(vc4);
  111. + if (!exec[0] && !exec[1]) {
  112. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  113. return;
  114. }
  115. - unref_list_count = 0;
  116. - list_for_each_entry(bo, &exec->unref_list, unref_head)
  117. - unref_list_count++;
  118. -
  119. - state->bo_count = exec->bo_count + unref_list_count;
  120. - kernel_state->bo = kcalloc(state->bo_count, sizeof(*kernel_state->bo),
  121. - GFP_ATOMIC);
  122. + /* Get the bos from both binner and renderer into hang state. */
  123. + state->bo_count = 0;
  124. + for (i = 0; i < 2; i++) {
  125. + if (!exec[i])
  126. + continue;
  127. +
  128. + unref_list_count = 0;
  129. + list_for_each_entry(bo, &exec[i]->unref_list, unref_head)
  130. + unref_list_count++;
  131. + state->bo_count += exec[i]->bo_count + unref_list_count;
  132. + }
  133. +
  134. + kernel_state->bo = kcalloc(state->bo_count,
  135. + sizeof(*kernel_state->bo), GFP_ATOMIC);
  136. +
  137. if (!kernel_state->bo) {
  138. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  139. return;
  140. }
  141. - for (i = 0; i < exec->bo_count; i++) {
  142. - drm_gem_object_reference(&exec->bo[i]->base);
  143. - kernel_state->bo[i] = &exec->bo[i]->base;
  144. - }
  145. + prev_idx = 0;
  146. + for (i = 0; i < 2; i++) {
  147. + if (!exec[i])
  148. + continue;
  149. +
  150. + for (j = 0; j < exec[i]->bo_count; j++) {
  151. + drm_gem_object_reference(&exec[i]->bo[j]->base);
  152. + kernel_state->bo[j + prev_idx] = &exec[i]->bo[j]->base;
  153. + }
  154. - list_for_each_entry(bo, &exec->unref_list, unref_head) {
  155. - drm_gem_object_reference(&bo->base.base);
  156. - kernel_state->bo[i] = &bo->base.base;
  157. - i++;
  158. + list_for_each_entry(bo, &exec[i]->unref_list, unref_head) {
  159. + drm_gem_object_reference(&bo->base.base);
  160. + kernel_state->bo[j + prev_idx] = &bo->base.base;
  161. + j++;
  162. + }
  163. + prev_idx = j + 1;
  164. }
  165. - state->start_bin = exec->ct0ca;
  166. - state->start_render = exec->ct1ca;
  167. + if (exec[0])
  168. + state->start_bin = exec[0]->ct0ca;
  169. + if (exec[1])
  170. + state->start_render = exec[1]->ct1ca;
  171. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  172. @@ -272,13 +290,15 @@ vc4_hangcheck_elapsed(unsigned long data
  173. struct vc4_dev *vc4 = to_vc4_dev(dev);
  174. uint32_t ct0ca, ct1ca;
  175. unsigned long irqflags;
  176. - struct vc4_exec_info *exec;
  177. + struct vc4_exec_info *bin_exec, *render_exec;
  178. spin_lock_irqsave(&vc4->job_lock, irqflags);
  179. - exec = vc4_first_job(vc4);
  180. +
  181. + bin_exec = vc4_first_bin_job(vc4);
  182. + render_exec = vc4_first_render_job(vc4);
  183. /* If idle, we can stop watching for hangs. */
  184. - if (!exec) {
  185. + if (!bin_exec && !render_exec) {
  186. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  187. return;
  188. }
  189. @@ -289,9 +309,12 @@ vc4_hangcheck_elapsed(unsigned long data
  190. /* If we've made any progress in execution, rearm the timer
  191. * and wait.
  192. */
  193. - if (ct0ca != exec->last_ct0ca || ct1ca != exec->last_ct1ca) {
  194. - exec->last_ct0ca = ct0ca;
  195. - exec->last_ct1ca = ct1ca;
  196. + if ((bin_exec && ct0ca != bin_exec->last_ct0ca) ||
  197. + (render_exec && ct1ca != render_exec->last_ct1ca)) {
  198. + if (bin_exec)
  199. + bin_exec->last_ct0ca = ct0ca;
  200. + if (render_exec)
  201. + render_exec->last_ct1ca = ct1ca;
  202. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  203. vc4_queue_hangcheck(dev);
  204. return;
  205. @@ -391,11 +414,13 @@ vc4_flush_caches(struct drm_device *dev)
  206. * The job_lock should be held during this.
  207. */
  208. void
  209. -vc4_submit_next_job(struct drm_device *dev)
  210. +vc4_submit_next_bin_job(struct drm_device *dev)
  211. {
  212. struct vc4_dev *vc4 = to_vc4_dev(dev);
  213. - struct vc4_exec_info *exec = vc4_first_job(vc4);
  214. + struct vc4_exec_info *exec;
  215. +again:
  216. + exec = vc4_first_bin_job(vc4);
  217. if (!exec)
  218. return;
  219. @@ -405,11 +430,40 @@ vc4_submit_next_job(struct drm_device *d
  220. V3D_WRITE(V3D_BPOA, 0);
  221. V3D_WRITE(V3D_BPOS, 0);
  222. - if (exec->ct0ca != exec->ct0ea)
  223. + /* Either put the job in the binner if it uses the binner, or
  224. + * immediately move it to the to-be-rendered queue.
  225. + */
  226. + if (exec->ct0ca != exec->ct0ea) {
  227. submit_cl(dev, 0, exec->ct0ca, exec->ct0ea);
  228. + } else {
  229. + vc4_move_job_to_render(dev, exec);
  230. + goto again;
  231. + }
  232. +}
  233. +
  234. +void
  235. +vc4_submit_next_render_job(struct drm_device *dev)
  236. +{
  237. + struct vc4_dev *vc4 = to_vc4_dev(dev);
  238. + struct vc4_exec_info *exec = vc4_first_render_job(vc4);
  239. +
  240. + if (!exec)
  241. + return;
  242. +
  243. submit_cl(dev, 1, exec->ct1ca, exec->ct1ea);
  244. }
  245. +void
  246. +vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec)
  247. +{
  248. + struct vc4_dev *vc4 = to_vc4_dev(dev);
  249. + bool was_empty = list_empty(&vc4->render_job_list);
  250. +
  251. + list_move_tail(&exec->head, &vc4->render_job_list);
  252. + if (was_empty)
  253. + vc4_submit_next_render_job(dev);
  254. +}
  255. +
  256. static void
  257. vc4_update_bo_seqnos(struct vc4_exec_info *exec, uint64_t seqno)
  258. {
  259. @@ -448,14 +502,14 @@ vc4_queue_submit(struct drm_device *dev,
  260. exec->seqno = seqno;
  261. vc4_update_bo_seqnos(exec, seqno);
  262. - list_add_tail(&exec->head, &vc4->job_list);
  263. + list_add_tail(&exec->head, &vc4->bin_job_list);
  264. /* If no job was executing, kick ours off. Otherwise, it'll
  265. - * get started when the previous job's frame done interrupt
  266. + * get started when the previous job's flush done interrupt
  267. * occurs.
  268. */
  269. - if (vc4_first_job(vc4) == exec) {
  270. - vc4_submit_next_job(dev);
  271. + if (vc4_first_bin_job(vc4) == exec) {
  272. + vc4_submit_next_bin_job(dev);
  273. vc4_queue_hangcheck(dev);
  274. }
  275. @@ -849,7 +903,8 @@ vc4_gem_init(struct drm_device *dev)
  276. {
  277. struct vc4_dev *vc4 = to_vc4_dev(dev);
  278. - INIT_LIST_HEAD(&vc4->job_list);
  279. + INIT_LIST_HEAD(&vc4->bin_job_list);
  280. + INIT_LIST_HEAD(&vc4->render_job_list);
  281. INIT_LIST_HEAD(&vc4->job_done_list);
  282. INIT_LIST_HEAD(&vc4->seqno_cb_list);
  283. spin_lock_init(&vc4->job_lock);
  284. --- a/drivers/gpu/drm/vc4/vc4_irq.c
  285. +++ b/drivers/gpu/drm/vc4/vc4_irq.c
  286. @@ -30,6 +30,10 @@
  287. * disables that specific interrupt, and 0s written are ignored
  288. * (reading either one returns the set of enabled interrupts).
  289. *
  290. + * When we take a binning flush done interrupt, we need to submit the
  291. + * next frame for binning and move the finished frame to the render
  292. + * thread.
  293. + *
  294. * When we take a render frame interrupt, we need to wake the
  295. * processes waiting for some frame to be done, and get the next frame
  296. * submitted ASAP (so the hardware doesn't sit idle when there's work
  297. @@ -44,6 +48,7 @@
  298. #include "vc4_regs.h"
  299. #define V3D_DRIVER_IRQS (V3D_INT_OUTOMEM | \
  300. + V3D_INT_FLDONE | \
  301. V3D_INT_FRDONE)
  302. DECLARE_WAIT_QUEUE_HEAD(render_wait);
  303. @@ -77,7 +82,7 @@ vc4_overflow_mem_work(struct work_struct
  304. unsigned long irqflags;
  305. spin_lock_irqsave(&vc4->job_lock, irqflags);
  306. - current_exec = vc4_first_job(vc4);
  307. + current_exec = vc4_first_bin_job(vc4);
  308. if (current_exec) {
  309. vc4->overflow_mem->seqno = vc4->finished_seqno + 1;
  310. list_add_tail(&vc4->overflow_mem->unref_head,
  311. @@ -98,17 +103,43 @@ vc4_overflow_mem_work(struct work_struct
  312. }
  313. static void
  314. -vc4_irq_finish_job(struct drm_device *dev)
  315. +vc4_irq_finish_bin_job(struct drm_device *dev)
  316. +{
  317. + struct vc4_dev *vc4 = to_vc4_dev(dev);
  318. + struct vc4_exec_info *exec = vc4_first_bin_job(vc4);
  319. +
  320. + if (!exec)
  321. + return;
  322. +
  323. + vc4_move_job_to_render(dev, exec);
  324. + vc4_submit_next_bin_job(dev);
  325. +}
  326. +
  327. +static void
  328. +vc4_cancel_bin_job(struct drm_device *dev)
  329. +{
  330. + struct vc4_dev *vc4 = to_vc4_dev(dev);
  331. + struct vc4_exec_info *exec = vc4_first_bin_job(vc4);
  332. +
  333. + if (!exec)
  334. + return;
  335. +
  336. + list_move_tail(&exec->head, &vc4->bin_job_list);
  337. + vc4_submit_next_bin_job(dev);
  338. +}
  339. +
  340. +static void
  341. +vc4_irq_finish_render_job(struct drm_device *dev)
  342. {
  343. struct vc4_dev *vc4 = to_vc4_dev(dev);
  344. - struct vc4_exec_info *exec = vc4_first_job(vc4);
  345. + struct vc4_exec_info *exec = vc4_first_render_job(vc4);
  346. if (!exec)
  347. return;
  348. vc4->finished_seqno++;
  349. list_move_tail(&exec->head, &vc4->job_done_list);
  350. - vc4_submit_next_job(dev);
  351. + vc4_submit_next_render_job(dev);
  352. wake_up_all(&vc4->job_wait_queue);
  353. schedule_work(&vc4->job_done_work);
  354. @@ -125,9 +156,10 @@ vc4_irq(int irq, void *arg)
  355. barrier();
  356. intctl = V3D_READ(V3D_INTCTL);
  357. - /* Acknowledge the interrupts we're handling here. The render
  358. - * frame done interrupt will be cleared, while OUTOMEM will
  359. - * stay high until the underlying cause is cleared.
  360. + /* Acknowledge the interrupts we're handling here. The binner
  361. + * last flush / render frame done interrupt will be cleared,
  362. + * while OUTOMEM will stay high until the underlying cause is
  363. + * cleared.
  364. */
  365. V3D_WRITE(V3D_INTCTL, intctl);
  366. @@ -138,9 +170,16 @@ vc4_irq(int irq, void *arg)
  367. status = IRQ_HANDLED;
  368. }
  369. + if (intctl & V3D_INT_FLDONE) {
  370. + spin_lock(&vc4->job_lock);
  371. + vc4_irq_finish_bin_job(dev);
  372. + spin_unlock(&vc4->job_lock);
  373. + status = IRQ_HANDLED;
  374. + }
  375. +
  376. if (intctl & V3D_INT_FRDONE) {
  377. spin_lock(&vc4->job_lock);
  378. - vc4_irq_finish_job(dev);
  379. + vc4_irq_finish_render_job(dev);
  380. spin_unlock(&vc4->job_lock);
  381. status = IRQ_HANDLED;
  382. }
  383. @@ -205,6 +244,7 @@ void vc4_irq_reset(struct drm_device *de
  384. V3D_WRITE(V3D_INTENA, V3D_DRIVER_IRQS);
  385. spin_lock_irqsave(&vc4->job_lock, irqflags);
  386. - vc4_irq_finish_job(dev);
  387. + vc4_cancel_bin_job(dev);
  388. + vc4_irq_finish_render_job(dev);
  389. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  390. }