i915_gem_request.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. /*
  2. * Copyright © 2008-2015 Intel 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 (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. */
  24. #include <linux/prefetch.h>
  25. #include <linux/dma-fence-array.h>
  26. #include <linux/sched.h>
  27. #include <linux/sched/clock.h>
  28. #include <linux/sched/signal.h>
  29. #include "i915_drv.h"
  30. static const char *i915_fence_get_driver_name(struct dma_fence *fence)
  31. {
  32. return "i915";
  33. }
  34. static const char *i915_fence_get_timeline_name(struct dma_fence *fence)
  35. {
  36. /* The timeline struct (as part of the ppgtt underneath a context)
  37. * may be freed when the request is no longer in use by the GPU.
  38. * We could extend the life of a context to beyond that of all
  39. * fences, possibly keeping the hw resource around indefinitely,
  40. * or we just give them a false name. Since
  41. * dma_fence_ops.get_timeline_name is a debug feature, the occasional
  42. * lie seems justifiable.
  43. */
  44. if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
  45. return "signaled";
  46. return to_request(fence)->timeline->common->name;
  47. }
  48. static bool i915_fence_signaled(struct dma_fence *fence)
  49. {
  50. return i915_gem_request_completed(to_request(fence));
  51. }
  52. static bool i915_fence_enable_signaling(struct dma_fence *fence)
  53. {
  54. if (i915_fence_signaled(fence))
  55. return false;
  56. intel_engine_enable_signaling(to_request(fence), true);
  57. return !i915_fence_signaled(fence);
  58. }
  59. static signed long i915_fence_wait(struct dma_fence *fence,
  60. bool interruptible,
  61. signed long timeout)
  62. {
  63. return i915_wait_request(to_request(fence), interruptible, timeout);
  64. }
  65. static void i915_fence_release(struct dma_fence *fence)
  66. {
  67. struct drm_i915_gem_request *req = to_request(fence);
  68. /* The request is put onto a RCU freelist (i.e. the address
  69. * is immediately reused), mark the fences as being freed now.
  70. * Otherwise the debugobjects for the fences are only marked as
  71. * freed when the slab cache itself is freed, and so we would get
  72. * caught trying to reuse dead objects.
  73. */
  74. i915_sw_fence_fini(&req->submit);
  75. kmem_cache_free(req->i915->requests, req);
  76. }
  77. const struct dma_fence_ops i915_fence_ops = {
  78. .get_driver_name = i915_fence_get_driver_name,
  79. .get_timeline_name = i915_fence_get_timeline_name,
  80. .enable_signaling = i915_fence_enable_signaling,
  81. .signaled = i915_fence_signaled,
  82. .wait = i915_fence_wait,
  83. .release = i915_fence_release,
  84. };
  85. static inline void
  86. i915_gem_request_remove_from_client(struct drm_i915_gem_request *request)
  87. {
  88. struct drm_i915_file_private *file_priv;
  89. file_priv = request->file_priv;
  90. if (!file_priv)
  91. return;
  92. spin_lock(&file_priv->mm.lock);
  93. if (request->file_priv) {
  94. list_del(&request->client_link);
  95. request->file_priv = NULL;
  96. }
  97. spin_unlock(&file_priv->mm.lock);
  98. }
  99. static struct i915_dependency *
  100. i915_dependency_alloc(struct drm_i915_private *i915)
  101. {
  102. return kmem_cache_alloc(i915->dependencies, GFP_KERNEL);
  103. }
  104. static void
  105. i915_dependency_free(struct drm_i915_private *i915,
  106. struct i915_dependency *dep)
  107. {
  108. kmem_cache_free(i915->dependencies, dep);
  109. }
  110. static void
  111. __i915_priotree_add_dependency(struct i915_priotree *pt,
  112. struct i915_priotree *signal,
  113. struct i915_dependency *dep,
  114. unsigned long flags)
  115. {
  116. INIT_LIST_HEAD(&dep->dfs_link);
  117. list_add(&dep->wait_link, &signal->waiters_list);
  118. list_add(&dep->signal_link, &pt->signalers_list);
  119. dep->signaler = signal;
  120. dep->flags = flags;
  121. }
  122. static int
  123. i915_priotree_add_dependency(struct drm_i915_private *i915,
  124. struct i915_priotree *pt,
  125. struct i915_priotree *signal)
  126. {
  127. struct i915_dependency *dep;
  128. dep = i915_dependency_alloc(i915);
  129. if (!dep)
  130. return -ENOMEM;
  131. __i915_priotree_add_dependency(pt, signal, dep, I915_DEPENDENCY_ALLOC);
  132. return 0;
  133. }
  134. static void
  135. i915_priotree_fini(struct drm_i915_private *i915, struct i915_priotree *pt)
  136. {
  137. struct i915_dependency *dep, *next;
  138. GEM_BUG_ON(!list_empty(&pt->link));
  139. /* Everyone we depended upon (the fences we wait to be signaled)
  140. * should retire before us and remove themselves from our list.
  141. * However, retirement is run independently on each timeline and
  142. * so we may be called out-of-order.
  143. */
  144. list_for_each_entry_safe(dep, next, &pt->signalers_list, signal_link) {
  145. list_del(&dep->wait_link);
  146. if (dep->flags & I915_DEPENDENCY_ALLOC)
  147. i915_dependency_free(i915, dep);
  148. }
  149. /* Remove ourselves from everyone who depends upon us */
  150. list_for_each_entry_safe(dep, next, &pt->waiters_list, wait_link) {
  151. list_del(&dep->signal_link);
  152. if (dep->flags & I915_DEPENDENCY_ALLOC)
  153. i915_dependency_free(i915, dep);
  154. }
  155. }
  156. static void
  157. i915_priotree_init(struct i915_priotree *pt)
  158. {
  159. INIT_LIST_HEAD(&pt->signalers_list);
  160. INIT_LIST_HEAD(&pt->waiters_list);
  161. INIT_LIST_HEAD(&pt->link);
  162. pt->priority = I915_PRIORITY_INVALID;
  163. }
  164. static int reset_all_global_seqno(struct drm_i915_private *i915, u32 seqno)
  165. {
  166. struct intel_engine_cs *engine;
  167. enum intel_engine_id id;
  168. int ret;
  169. /* Carefully retire all requests without writing to the rings */
  170. ret = i915_gem_wait_for_idle(i915,
  171. I915_WAIT_INTERRUPTIBLE |
  172. I915_WAIT_LOCKED);
  173. if (ret)
  174. return ret;
  175. /* If the seqno wraps around, we need to clear the breadcrumb rbtree */
  176. for_each_engine(engine, i915, id) {
  177. struct i915_gem_timeline *timeline;
  178. struct intel_timeline *tl = engine->timeline;
  179. if (!i915_seqno_passed(seqno, tl->seqno)) {
  180. /* spin until threads are complete */
  181. while (intel_breadcrumbs_busy(engine))
  182. cond_resched();
  183. }
  184. /* Check we are idle before we fiddle with hw state! */
  185. GEM_BUG_ON(!intel_engine_is_idle(engine));
  186. GEM_BUG_ON(i915_gem_active_isset(&engine->timeline->last_request));
  187. /* Finally reset hw state */
  188. intel_engine_init_global_seqno(engine, seqno);
  189. tl->seqno = seqno;
  190. list_for_each_entry(timeline, &i915->gt.timelines, link)
  191. memset(timeline->engine[id].global_sync, 0,
  192. sizeof(timeline->engine[id].global_sync));
  193. }
  194. return 0;
  195. }
  196. int i915_gem_set_global_seqno(struct drm_device *dev, u32 seqno)
  197. {
  198. struct drm_i915_private *dev_priv = to_i915(dev);
  199. lockdep_assert_held(&dev_priv->drm.struct_mutex);
  200. if (seqno == 0)
  201. return -EINVAL;
  202. /* HWS page needs to be set less than what we
  203. * will inject to ring
  204. */
  205. return reset_all_global_seqno(dev_priv, seqno - 1);
  206. }
  207. static void mark_busy(struct drm_i915_private *i915)
  208. {
  209. if (i915->gt.awake)
  210. return;
  211. GEM_BUG_ON(!i915->gt.active_requests);
  212. intel_runtime_pm_get_noresume(i915);
  213. i915->gt.awake = true;
  214. intel_enable_gt_powersave(i915);
  215. i915_update_gfx_val(i915);
  216. if (INTEL_GEN(i915) >= 6)
  217. gen6_rps_busy(i915);
  218. queue_delayed_work(i915->wq,
  219. &i915->gt.retire_work,
  220. round_jiffies_up_relative(HZ));
  221. }
  222. static int reserve_engine(struct intel_engine_cs *engine)
  223. {
  224. struct drm_i915_private *i915 = engine->i915;
  225. u32 active = ++engine->timeline->inflight_seqnos;
  226. u32 seqno = engine->timeline->seqno;
  227. int ret;
  228. /* Reservation is fine until we need to wrap around */
  229. if (unlikely(add_overflows(seqno, active))) {
  230. ret = reset_all_global_seqno(i915, 0);
  231. if (ret) {
  232. engine->timeline->inflight_seqnos--;
  233. return ret;
  234. }
  235. }
  236. if (!i915->gt.active_requests++)
  237. mark_busy(i915);
  238. return 0;
  239. }
  240. static void unreserve_engine(struct intel_engine_cs *engine)
  241. {
  242. struct drm_i915_private *i915 = engine->i915;
  243. if (!--i915->gt.active_requests) {
  244. /* Cancel the mark_busy() from our reserve_engine() */
  245. GEM_BUG_ON(!i915->gt.awake);
  246. mod_delayed_work(i915->wq,
  247. &i915->gt.idle_work,
  248. msecs_to_jiffies(100));
  249. }
  250. GEM_BUG_ON(!engine->timeline->inflight_seqnos);
  251. engine->timeline->inflight_seqnos--;
  252. }
  253. void i915_gem_retire_noop(struct i915_gem_active *active,
  254. struct drm_i915_gem_request *request)
  255. {
  256. /* Space left intentionally blank */
  257. }
  258. static void advance_ring(struct drm_i915_gem_request *request)
  259. {
  260. unsigned int tail;
  261. /* We know the GPU must have read the request to have
  262. * sent us the seqno + interrupt, so use the position
  263. * of tail of the request to update the last known position
  264. * of the GPU head.
  265. *
  266. * Note this requires that we are always called in request
  267. * completion order.
  268. */
  269. if (list_is_last(&request->ring_link, &request->ring->request_list)) {
  270. /* We may race here with execlists resubmitting this request
  271. * as we retire it. The resubmission will move the ring->tail
  272. * forwards (to request->wa_tail). We either read the
  273. * current value that was written to hw, or the value that
  274. * is just about to be. Either works, if we miss the last two
  275. * noops - they are safe to be replayed on a reset.
  276. */
  277. tail = READ_ONCE(request->ring->tail);
  278. } else {
  279. tail = request->postfix;
  280. }
  281. list_del(&request->ring_link);
  282. request->ring->head = tail;
  283. }
  284. static void free_capture_list(struct drm_i915_gem_request *request)
  285. {
  286. struct i915_gem_capture_list *capture;
  287. capture = request->capture_list;
  288. while (capture) {
  289. struct i915_gem_capture_list *next = capture->next;
  290. kfree(capture);
  291. capture = next;
  292. }
  293. }
  294. static void i915_gem_request_retire(struct drm_i915_gem_request *request)
  295. {
  296. struct intel_engine_cs *engine = request->engine;
  297. struct i915_gem_active *active, *next;
  298. lockdep_assert_held(&request->i915->drm.struct_mutex);
  299. GEM_BUG_ON(!i915_sw_fence_signaled(&request->submit));
  300. GEM_BUG_ON(!i915_gem_request_completed(request));
  301. GEM_BUG_ON(!request->i915->gt.active_requests);
  302. trace_i915_gem_request_retire(request);
  303. spin_lock_irq(&engine->timeline->lock);
  304. list_del_init(&request->link);
  305. spin_unlock_irq(&engine->timeline->lock);
  306. unreserve_engine(request->engine);
  307. advance_ring(request);
  308. free_capture_list(request);
  309. /* Walk through the active list, calling retire on each. This allows
  310. * objects to track their GPU activity and mark themselves as idle
  311. * when their *last* active request is completed (updating state
  312. * tracking lists for eviction, active references for GEM, etc).
  313. *
  314. * As the ->retire() may free the node, we decouple it first and
  315. * pass along the auxiliary information (to avoid dereferencing
  316. * the node after the callback).
  317. */
  318. list_for_each_entry_safe(active, next, &request->active_list, link) {
  319. /* In microbenchmarks or focusing upon time inside the kernel,
  320. * we may spend an inordinate amount of time simply handling
  321. * the retirement of requests and processing their callbacks.
  322. * Of which, this loop itself is particularly hot due to the
  323. * cache misses when jumping around the list of i915_gem_active.
  324. * So we try to keep this loop as streamlined as possible and
  325. * also prefetch the next i915_gem_active to try and hide
  326. * the likely cache miss.
  327. */
  328. prefetchw(next);
  329. INIT_LIST_HEAD(&active->link);
  330. RCU_INIT_POINTER(active->request, NULL);
  331. active->retire(active, request);
  332. }
  333. i915_gem_request_remove_from_client(request);
  334. /* Retirement decays the ban score as it is a sign of ctx progress */
  335. atomic_dec_if_positive(&request->ctx->ban_score);
  336. /* The backing object for the context is done after switching to the
  337. * *next* context. Therefore we cannot retire the previous context until
  338. * the next context has already started running. However, since we
  339. * cannot take the required locks at i915_gem_request_submit() we
  340. * defer the unpinning of the active context to now, retirement of
  341. * the subsequent request.
  342. */
  343. if (engine->last_retired_context)
  344. engine->context_unpin(engine, engine->last_retired_context);
  345. engine->last_retired_context = request->ctx;
  346. spin_lock_irq(&request->lock);
  347. if (request->waitboost)
  348. atomic_dec(&request->i915->gt_pm.rps.num_waiters);
  349. dma_fence_signal_locked(&request->fence);
  350. spin_unlock_irq(&request->lock);
  351. i915_priotree_fini(request->i915, &request->priotree);
  352. i915_gem_request_put(request);
  353. }
  354. void i915_gem_request_retire_upto(struct drm_i915_gem_request *req)
  355. {
  356. struct intel_engine_cs *engine = req->engine;
  357. struct drm_i915_gem_request *tmp;
  358. lockdep_assert_held(&req->i915->drm.struct_mutex);
  359. GEM_BUG_ON(!i915_gem_request_completed(req));
  360. if (list_empty(&req->link))
  361. return;
  362. do {
  363. tmp = list_first_entry(&engine->timeline->requests,
  364. typeof(*tmp), link);
  365. i915_gem_request_retire(tmp);
  366. } while (tmp != req);
  367. }
  368. static u32 timeline_get_seqno(struct intel_timeline *tl)
  369. {
  370. return ++tl->seqno;
  371. }
  372. void __i915_gem_request_submit(struct drm_i915_gem_request *request)
  373. {
  374. struct intel_engine_cs *engine = request->engine;
  375. struct intel_timeline *timeline;
  376. u32 seqno;
  377. GEM_BUG_ON(!irqs_disabled());
  378. lockdep_assert_held(&engine->timeline->lock);
  379. trace_i915_gem_request_execute(request);
  380. /* Transfer from per-context onto the global per-engine timeline */
  381. timeline = engine->timeline;
  382. GEM_BUG_ON(timeline == request->timeline);
  383. seqno = timeline_get_seqno(timeline);
  384. GEM_BUG_ON(!seqno);
  385. GEM_BUG_ON(i915_seqno_passed(intel_engine_get_seqno(engine), seqno));
  386. /* We may be recursing from the signal callback of another i915 fence */
  387. spin_lock_nested(&request->lock, SINGLE_DEPTH_NESTING);
  388. request->global_seqno = seqno;
  389. if (test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &request->fence.flags))
  390. intel_engine_enable_signaling(request, false);
  391. spin_unlock(&request->lock);
  392. engine->emit_breadcrumb(request,
  393. request->ring->vaddr + request->postfix);
  394. spin_lock(&request->timeline->lock);
  395. list_move_tail(&request->link, &timeline->requests);
  396. spin_unlock(&request->timeline->lock);
  397. wake_up_all(&request->execute);
  398. }
  399. void i915_gem_request_submit(struct drm_i915_gem_request *request)
  400. {
  401. struct intel_engine_cs *engine = request->engine;
  402. unsigned long flags;
  403. /* Will be called from irq-context when using foreign fences. */
  404. spin_lock_irqsave(&engine->timeline->lock, flags);
  405. __i915_gem_request_submit(request);
  406. spin_unlock_irqrestore(&engine->timeline->lock, flags);
  407. }
  408. void __i915_gem_request_unsubmit(struct drm_i915_gem_request *request)
  409. {
  410. struct intel_engine_cs *engine = request->engine;
  411. struct intel_timeline *timeline;
  412. GEM_BUG_ON(!irqs_disabled());
  413. lockdep_assert_held(&engine->timeline->lock);
  414. /* Only unwind in reverse order, required so that the per-context list
  415. * is kept in seqno/ring order.
  416. */
  417. GEM_BUG_ON(request->global_seqno != engine->timeline->seqno);
  418. engine->timeline->seqno--;
  419. /* We may be recursing from the signal callback of another i915 fence */
  420. spin_lock_nested(&request->lock, SINGLE_DEPTH_NESTING);
  421. request->global_seqno = 0;
  422. if (test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &request->fence.flags))
  423. intel_engine_cancel_signaling(request);
  424. spin_unlock(&request->lock);
  425. /* Transfer back from the global per-engine timeline to per-context */
  426. timeline = request->timeline;
  427. GEM_BUG_ON(timeline == engine->timeline);
  428. spin_lock(&timeline->lock);
  429. list_move(&request->link, &timeline->requests);
  430. spin_unlock(&timeline->lock);
  431. /* We don't need to wake_up any waiters on request->execute, they
  432. * will get woken by any other event or us re-adding this request
  433. * to the engine timeline (__i915_gem_request_submit()). The waiters
  434. * should be quite adapt at finding that the request now has a new
  435. * global_seqno to the one they went to sleep on.
  436. */
  437. }
  438. void i915_gem_request_unsubmit(struct drm_i915_gem_request *request)
  439. {
  440. struct intel_engine_cs *engine = request->engine;
  441. unsigned long flags;
  442. /* Will be called from irq-context when using foreign fences. */
  443. spin_lock_irqsave(&engine->timeline->lock, flags);
  444. __i915_gem_request_unsubmit(request);
  445. spin_unlock_irqrestore(&engine->timeline->lock, flags);
  446. }
  447. static int __i915_sw_fence_call
  448. submit_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
  449. {
  450. struct drm_i915_gem_request *request =
  451. container_of(fence, typeof(*request), submit);
  452. switch (state) {
  453. case FENCE_COMPLETE:
  454. trace_i915_gem_request_submit(request);
  455. /*
  456. * We need to serialize use of the submit_request() callback with its
  457. * hotplugging performed during an emergency i915_gem_set_wedged().
  458. * We use the RCU mechanism to mark the critical section in order to
  459. * force i915_gem_set_wedged() to wait until the submit_request() is
  460. * completed before proceeding.
  461. */
  462. rcu_read_lock();
  463. request->engine->submit_request(request);
  464. rcu_read_unlock();
  465. break;
  466. case FENCE_FREE:
  467. i915_gem_request_put(request);
  468. break;
  469. }
  470. return NOTIFY_DONE;
  471. }
  472. /**
  473. * i915_gem_request_alloc - allocate a request structure
  474. *
  475. * @engine: engine that we wish to issue the request on.
  476. * @ctx: context that the request will be associated with.
  477. *
  478. * Returns a pointer to the allocated request if successful,
  479. * or an error code if not.
  480. */
  481. struct drm_i915_gem_request *
  482. i915_gem_request_alloc(struct intel_engine_cs *engine,
  483. struct i915_gem_context *ctx)
  484. {
  485. struct drm_i915_private *dev_priv = engine->i915;
  486. struct drm_i915_gem_request *req;
  487. struct intel_ring *ring;
  488. int ret;
  489. lockdep_assert_held(&dev_priv->drm.struct_mutex);
  490. /*
  491. * Preempt contexts are reserved for exclusive use to inject a
  492. * preemption context switch. They are never to be used for any trivial
  493. * request!
  494. */
  495. GEM_BUG_ON(ctx == dev_priv->preempt_context);
  496. /* ABI: Before userspace accesses the GPU (e.g. execbuffer), report
  497. * EIO if the GPU is already wedged.
  498. */
  499. if (i915_terminally_wedged(&dev_priv->gpu_error))
  500. return ERR_PTR(-EIO);
  501. /* Pinning the contexts may generate requests in order to acquire
  502. * GGTT space, so do this first before we reserve a seqno for
  503. * ourselves.
  504. */
  505. ring = engine->context_pin(engine, ctx);
  506. if (IS_ERR(ring))
  507. return ERR_CAST(ring);
  508. GEM_BUG_ON(!ring);
  509. ret = reserve_engine(engine);
  510. if (ret)
  511. goto err_unpin;
  512. /* Move the oldest request to the slab-cache (if not in use!) */
  513. req = list_first_entry_or_null(&engine->timeline->requests,
  514. typeof(*req), link);
  515. if (req && i915_gem_request_completed(req))
  516. i915_gem_request_retire(req);
  517. /* Beware: Dragons be flying overhead.
  518. *
  519. * We use RCU to look up requests in flight. The lookups may
  520. * race with the request being allocated from the slab freelist.
  521. * That is the request we are writing to here, may be in the process
  522. * of being read by __i915_gem_active_get_rcu(). As such,
  523. * we have to be very careful when overwriting the contents. During
  524. * the RCU lookup, we change chase the request->engine pointer,
  525. * read the request->global_seqno and increment the reference count.
  526. *
  527. * The reference count is incremented atomically. If it is zero,
  528. * the lookup knows the request is unallocated and complete. Otherwise,
  529. * it is either still in use, or has been reallocated and reset
  530. * with dma_fence_init(). This increment is safe for release as we
  531. * check that the request we have a reference to and matches the active
  532. * request.
  533. *
  534. * Before we increment the refcount, we chase the request->engine
  535. * pointer. We must not call kmem_cache_zalloc() or else we set
  536. * that pointer to NULL and cause a crash during the lookup. If
  537. * we see the request is completed (based on the value of the
  538. * old engine and seqno), the lookup is complete and reports NULL.
  539. * If we decide the request is not completed (new engine or seqno),
  540. * then we grab a reference and double check that it is still the
  541. * active request - which it won't be and restart the lookup.
  542. *
  543. * Do not use kmem_cache_zalloc() here!
  544. */
  545. req = kmem_cache_alloc(dev_priv->requests, GFP_KERNEL);
  546. if (!req) {
  547. ret = -ENOMEM;
  548. goto err_unreserve;
  549. }
  550. req->timeline = i915_gem_context_lookup_timeline(ctx, engine);
  551. GEM_BUG_ON(req->timeline == engine->timeline);
  552. spin_lock_init(&req->lock);
  553. dma_fence_init(&req->fence,
  554. &i915_fence_ops,
  555. &req->lock,
  556. req->timeline->fence_context,
  557. timeline_get_seqno(req->timeline));
  558. /* We bump the ref for the fence chain */
  559. i915_sw_fence_init(&i915_gem_request_get(req)->submit, submit_notify);
  560. init_waitqueue_head(&req->execute);
  561. i915_priotree_init(&req->priotree);
  562. INIT_LIST_HEAD(&req->active_list);
  563. req->i915 = dev_priv;
  564. req->engine = engine;
  565. req->ctx = ctx;
  566. req->ring = ring;
  567. /* No zalloc, must clear what we need by hand */
  568. req->global_seqno = 0;
  569. req->file_priv = NULL;
  570. req->batch = NULL;
  571. req->capture_list = NULL;
  572. req->waitboost = false;
  573. /*
  574. * Reserve space in the ring buffer for all the commands required to
  575. * eventually emit this request. This is to guarantee that the
  576. * i915_add_request() call can't fail. Note that the reserve may need
  577. * to be redone if the request is not actually submitted straight
  578. * away, e.g. because a GPU scheduler has deferred it.
  579. */
  580. req->reserved_space = MIN_SPACE_FOR_ADD_REQUEST;
  581. GEM_BUG_ON(req->reserved_space < engine->emit_breadcrumb_sz);
  582. ret = engine->request_alloc(req);
  583. if (ret)
  584. goto err_ctx;
  585. /* Record the position of the start of the request so that
  586. * should we detect the updated seqno part-way through the
  587. * GPU processing the request, we never over-estimate the
  588. * position of the head.
  589. */
  590. req->head = req->ring->emit;
  591. /* Check that we didn't interrupt ourselves with a new request */
  592. GEM_BUG_ON(req->timeline->seqno != req->fence.seqno);
  593. return req;
  594. err_ctx:
  595. /* Make sure we didn't add ourselves to external state before freeing */
  596. GEM_BUG_ON(!list_empty(&req->active_list));
  597. GEM_BUG_ON(!list_empty(&req->priotree.signalers_list));
  598. GEM_BUG_ON(!list_empty(&req->priotree.waiters_list));
  599. kmem_cache_free(dev_priv->requests, req);
  600. err_unreserve:
  601. unreserve_engine(engine);
  602. err_unpin:
  603. engine->context_unpin(engine, ctx);
  604. return ERR_PTR(ret);
  605. }
  606. static int
  607. i915_gem_request_await_request(struct drm_i915_gem_request *to,
  608. struct drm_i915_gem_request *from)
  609. {
  610. int ret;
  611. GEM_BUG_ON(to == from);
  612. GEM_BUG_ON(to->timeline == from->timeline);
  613. if (i915_gem_request_completed(from))
  614. return 0;
  615. if (to->engine->schedule) {
  616. ret = i915_priotree_add_dependency(to->i915,
  617. &to->priotree,
  618. &from->priotree);
  619. if (ret < 0)
  620. return ret;
  621. }
  622. if (to->engine == from->engine) {
  623. ret = i915_sw_fence_await_sw_fence_gfp(&to->submit,
  624. &from->submit,
  625. GFP_KERNEL);
  626. return ret < 0 ? ret : 0;
  627. }
  628. if (to->engine->semaphore.sync_to) {
  629. u32 seqno;
  630. GEM_BUG_ON(!from->engine->semaphore.signal);
  631. seqno = i915_gem_request_global_seqno(from);
  632. if (!seqno)
  633. goto await_dma_fence;
  634. if (seqno <= to->timeline->global_sync[from->engine->id])
  635. return 0;
  636. trace_i915_gem_ring_sync_to(to, from);
  637. ret = to->engine->semaphore.sync_to(to, from);
  638. if (ret)
  639. return ret;
  640. to->timeline->global_sync[from->engine->id] = seqno;
  641. return 0;
  642. }
  643. await_dma_fence:
  644. ret = i915_sw_fence_await_dma_fence(&to->submit,
  645. &from->fence, 0,
  646. GFP_KERNEL);
  647. return ret < 0 ? ret : 0;
  648. }
  649. int
  650. i915_gem_request_await_dma_fence(struct drm_i915_gem_request *req,
  651. struct dma_fence *fence)
  652. {
  653. struct dma_fence **child = &fence;
  654. unsigned int nchild = 1;
  655. int ret;
  656. /* Note that if the fence-array was created in signal-on-any mode,
  657. * we should *not* decompose it into its individual fences. However,
  658. * we don't currently store which mode the fence-array is operating
  659. * in. Fortunately, the only user of signal-on-any is private to
  660. * amdgpu and we should not see any incoming fence-array from
  661. * sync-file being in signal-on-any mode.
  662. */
  663. if (dma_fence_is_array(fence)) {
  664. struct dma_fence_array *array = to_dma_fence_array(fence);
  665. child = array->fences;
  666. nchild = array->num_fences;
  667. GEM_BUG_ON(!nchild);
  668. }
  669. do {
  670. fence = *child++;
  671. if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
  672. continue;
  673. /*
  674. * Requests on the same timeline are explicitly ordered, along
  675. * with their dependencies, by i915_add_request() which ensures
  676. * that requests are submitted in-order through each ring.
  677. */
  678. if (fence->context == req->fence.context)
  679. continue;
  680. /* Squash repeated waits to the same timelines */
  681. if (fence->context != req->i915->mm.unordered_timeline &&
  682. intel_timeline_sync_is_later(req->timeline, fence))
  683. continue;
  684. if (dma_fence_is_i915(fence))
  685. ret = i915_gem_request_await_request(req,
  686. to_request(fence));
  687. else
  688. ret = i915_sw_fence_await_dma_fence(&req->submit, fence,
  689. I915_FENCE_TIMEOUT,
  690. GFP_KERNEL);
  691. if (ret < 0)
  692. return ret;
  693. /* Record the latest fence used against each timeline */
  694. if (fence->context != req->i915->mm.unordered_timeline)
  695. intel_timeline_sync_set(req->timeline, fence);
  696. } while (--nchild);
  697. return 0;
  698. }
  699. /**
  700. * i915_gem_request_await_object - set this request to (async) wait upon a bo
  701. *
  702. * @to: request we are wishing to use
  703. * @obj: object which may be in use on another ring.
  704. *
  705. * This code is meant to abstract object synchronization with the GPU.
  706. * Conceptually we serialise writes between engines inside the GPU.
  707. * We only allow one engine to write into a buffer at any time, but
  708. * multiple readers. To ensure each has a coherent view of memory, we must:
  709. *
  710. * - If there is an outstanding write request to the object, the new
  711. * request must wait for it to complete (either CPU or in hw, requests
  712. * on the same ring will be naturally ordered).
  713. *
  714. * - If we are a write request (pending_write_domain is set), the new
  715. * request must wait for outstanding read requests to complete.
  716. *
  717. * Returns 0 if successful, else propagates up the lower layer error.
  718. */
  719. int
  720. i915_gem_request_await_object(struct drm_i915_gem_request *to,
  721. struct drm_i915_gem_object *obj,
  722. bool write)
  723. {
  724. struct dma_fence *excl;
  725. int ret = 0;
  726. if (write) {
  727. struct dma_fence **shared;
  728. unsigned int count, i;
  729. ret = reservation_object_get_fences_rcu(obj->resv,
  730. &excl, &count, &shared);
  731. if (ret)
  732. return ret;
  733. for (i = 0; i < count; i++) {
  734. ret = i915_gem_request_await_dma_fence(to, shared[i]);
  735. if (ret)
  736. break;
  737. dma_fence_put(shared[i]);
  738. }
  739. for (; i < count; i++)
  740. dma_fence_put(shared[i]);
  741. kfree(shared);
  742. } else {
  743. excl = reservation_object_get_excl_rcu(obj->resv);
  744. }
  745. if (excl) {
  746. if (ret == 0)
  747. ret = i915_gem_request_await_dma_fence(to, excl);
  748. dma_fence_put(excl);
  749. }
  750. return ret;
  751. }
  752. /*
  753. * NB: This function is not allowed to fail. Doing so would mean the the
  754. * request is not being tracked for completion but the work itself is
  755. * going to happen on the hardware. This would be a Bad Thing(tm).
  756. */
  757. void __i915_add_request(struct drm_i915_gem_request *request, bool flush_caches)
  758. {
  759. struct intel_engine_cs *engine = request->engine;
  760. struct intel_ring *ring = request->ring;
  761. struct intel_timeline *timeline = request->timeline;
  762. struct drm_i915_gem_request *prev;
  763. u32 *cs;
  764. int err;
  765. lockdep_assert_held(&request->i915->drm.struct_mutex);
  766. trace_i915_gem_request_add(request);
  767. /* Make sure that no request gazumped us - if it was allocated after
  768. * our i915_gem_request_alloc() and called __i915_add_request() before
  769. * us, the timeline will hold its seqno which is later than ours.
  770. */
  771. GEM_BUG_ON(timeline->seqno != request->fence.seqno);
  772. /*
  773. * To ensure that this call will not fail, space for its emissions
  774. * should already have been reserved in the ring buffer. Let the ring
  775. * know that it is time to use that space up.
  776. */
  777. request->reserved_space = 0;
  778. /*
  779. * Emit any outstanding flushes - execbuf can fail to emit the flush
  780. * after having emitted the batchbuffer command. Hence we need to fix
  781. * things up similar to emitting the lazy request. The difference here
  782. * is that the flush _must_ happen before the next request, no matter
  783. * what.
  784. */
  785. if (flush_caches) {
  786. err = engine->emit_flush(request, EMIT_FLUSH);
  787. /* Not allowed to fail! */
  788. WARN(err, "engine->emit_flush() failed: %d!\n", err);
  789. }
  790. /* Record the position of the start of the breadcrumb so that
  791. * should we detect the updated seqno part-way through the
  792. * GPU processing the request, we never over-estimate the
  793. * position of the ring's HEAD.
  794. */
  795. cs = intel_ring_begin(request, engine->emit_breadcrumb_sz);
  796. GEM_BUG_ON(IS_ERR(cs));
  797. request->postfix = intel_ring_offset(request, cs);
  798. /* Seal the request and mark it as pending execution. Note that
  799. * we may inspect this state, without holding any locks, during
  800. * hangcheck. Hence we apply the barrier to ensure that we do not
  801. * see a more recent value in the hws than we are tracking.
  802. */
  803. prev = i915_gem_active_raw(&timeline->last_request,
  804. &request->i915->drm.struct_mutex);
  805. if (prev) {
  806. i915_sw_fence_await_sw_fence(&request->submit, &prev->submit,
  807. &request->submitq);
  808. if (engine->schedule)
  809. __i915_priotree_add_dependency(&request->priotree,
  810. &prev->priotree,
  811. &request->dep,
  812. 0);
  813. }
  814. spin_lock_irq(&timeline->lock);
  815. list_add_tail(&request->link, &timeline->requests);
  816. spin_unlock_irq(&timeline->lock);
  817. GEM_BUG_ON(timeline->seqno != request->fence.seqno);
  818. i915_gem_active_set(&timeline->last_request, request);
  819. list_add_tail(&request->ring_link, &ring->request_list);
  820. request->emitted_jiffies = jiffies;
  821. /* Let the backend know a new request has arrived that may need
  822. * to adjust the existing execution schedule due to a high priority
  823. * request - i.e. we may want to preempt the current request in order
  824. * to run a high priority dependency chain *before* we can execute this
  825. * request.
  826. *
  827. * This is called before the request is ready to run so that we can
  828. * decide whether to preempt the entire chain so that it is ready to
  829. * run at the earliest possible convenience.
  830. */
  831. if (engine->schedule)
  832. engine->schedule(request, request->ctx->priority);
  833. local_bh_disable();
  834. i915_sw_fence_commit(&request->submit);
  835. local_bh_enable(); /* Kick the execlists tasklet if just scheduled */
  836. }
  837. static unsigned long local_clock_us(unsigned int *cpu)
  838. {
  839. unsigned long t;
  840. /* Cheaply and approximately convert from nanoseconds to microseconds.
  841. * The result and subsequent calculations are also defined in the same
  842. * approximate microseconds units. The principal source of timing
  843. * error here is from the simple truncation.
  844. *
  845. * Note that local_clock() is only defined wrt to the current CPU;
  846. * the comparisons are no longer valid if we switch CPUs. Instead of
  847. * blocking preemption for the entire busywait, we can detect the CPU
  848. * switch and use that as indicator of system load and a reason to
  849. * stop busywaiting, see busywait_stop().
  850. */
  851. *cpu = get_cpu();
  852. t = local_clock() >> 10;
  853. put_cpu();
  854. return t;
  855. }
  856. static bool busywait_stop(unsigned long timeout, unsigned int cpu)
  857. {
  858. unsigned int this_cpu;
  859. if (time_after(local_clock_us(&this_cpu), timeout))
  860. return true;
  861. return this_cpu != cpu;
  862. }
  863. static bool __i915_spin_request(const struct drm_i915_gem_request *req,
  864. u32 seqno, int state, unsigned long timeout_us)
  865. {
  866. struct intel_engine_cs *engine = req->engine;
  867. unsigned int irq, cpu;
  868. GEM_BUG_ON(!seqno);
  869. /*
  870. * Only wait for the request if we know it is likely to complete.
  871. *
  872. * We don't track the timestamps around requests, nor the average
  873. * request length, so we do not have a good indicator that this
  874. * request will complete within the timeout. What we do know is the
  875. * order in which requests are executed by the engine and so we can
  876. * tell if the request has started. If the request hasn't started yet,
  877. * it is a fair assumption that it will not complete within our
  878. * relatively short timeout.
  879. */
  880. if (!i915_seqno_passed(intel_engine_get_seqno(engine), seqno - 1))
  881. return false;
  882. /* When waiting for high frequency requests, e.g. during synchronous
  883. * rendering split between the CPU and GPU, the finite amount of time
  884. * required to set up the irq and wait upon it limits the response
  885. * rate. By busywaiting on the request completion for a short while we
  886. * can service the high frequency waits as quick as possible. However,
  887. * if it is a slow request, we want to sleep as quickly as possible.
  888. * The tradeoff between waiting and sleeping is roughly the time it
  889. * takes to sleep on a request, on the order of a microsecond.
  890. */
  891. irq = atomic_read(&engine->irq_count);
  892. timeout_us += local_clock_us(&cpu);
  893. do {
  894. if (i915_seqno_passed(intel_engine_get_seqno(engine), seqno))
  895. return seqno == i915_gem_request_global_seqno(req);
  896. /* Seqno are meant to be ordered *before* the interrupt. If
  897. * we see an interrupt without a corresponding seqno advance,
  898. * assume we won't see one in the near future but require
  899. * the engine->seqno_barrier() to fixup coherency.
  900. */
  901. if (atomic_read(&engine->irq_count) != irq)
  902. break;
  903. if (signal_pending_state(state, current))
  904. break;
  905. if (busywait_stop(timeout_us, cpu))
  906. break;
  907. cpu_relax();
  908. } while (!need_resched());
  909. return false;
  910. }
  911. static bool __i915_wait_request_check_and_reset(struct drm_i915_gem_request *request)
  912. {
  913. if (likely(!i915_reset_handoff(&request->i915->gpu_error)))
  914. return false;
  915. __set_current_state(TASK_RUNNING);
  916. i915_reset(request->i915, 0);
  917. return true;
  918. }
  919. /**
  920. * i915_wait_request - wait until execution of request has finished
  921. * @req: the request to wait upon
  922. * @flags: how to wait
  923. * @timeout: how long to wait in jiffies
  924. *
  925. * i915_wait_request() waits for the request to be completed, for a
  926. * maximum of @timeout jiffies (with MAX_SCHEDULE_TIMEOUT implying an
  927. * unbounded wait).
  928. *
  929. * If the caller holds the struct_mutex, the caller must pass I915_WAIT_LOCKED
  930. * in via the flags, and vice versa if the struct_mutex is not held, the caller
  931. * must not specify that the wait is locked.
  932. *
  933. * Returns the remaining time (in jiffies) if the request completed, which may
  934. * be zero or -ETIME if the request is unfinished after the timeout expires.
  935. * May return -EINTR is called with I915_WAIT_INTERRUPTIBLE and a signal is
  936. * pending before the request completes.
  937. */
  938. long i915_wait_request(struct drm_i915_gem_request *req,
  939. unsigned int flags,
  940. long timeout)
  941. {
  942. const int state = flags & I915_WAIT_INTERRUPTIBLE ?
  943. TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE;
  944. wait_queue_head_t *errq = &req->i915->gpu_error.wait_queue;
  945. DEFINE_WAIT_FUNC(reset, default_wake_function);
  946. DEFINE_WAIT_FUNC(exec, default_wake_function);
  947. struct intel_wait wait;
  948. might_sleep();
  949. #if IS_ENABLED(CONFIG_LOCKDEP)
  950. GEM_BUG_ON(debug_locks &&
  951. !!lockdep_is_held(&req->i915->drm.struct_mutex) !=
  952. !!(flags & I915_WAIT_LOCKED));
  953. #endif
  954. GEM_BUG_ON(timeout < 0);
  955. if (i915_gem_request_completed(req))
  956. return timeout;
  957. if (!timeout)
  958. return -ETIME;
  959. trace_i915_gem_request_wait_begin(req, flags);
  960. add_wait_queue(&req->execute, &exec);
  961. if (flags & I915_WAIT_LOCKED)
  962. add_wait_queue(errq, &reset);
  963. intel_wait_init(&wait, req);
  964. restart:
  965. do {
  966. set_current_state(state);
  967. if (intel_wait_update_request(&wait, req))
  968. break;
  969. if (flags & I915_WAIT_LOCKED &&
  970. __i915_wait_request_check_and_reset(req))
  971. continue;
  972. if (signal_pending_state(state, current)) {
  973. timeout = -ERESTARTSYS;
  974. goto complete;
  975. }
  976. if (!timeout) {
  977. timeout = -ETIME;
  978. goto complete;
  979. }
  980. timeout = io_schedule_timeout(timeout);
  981. } while (1);
  982. GEM_BUG_ON(!intel_wait_has_seqno(&wait));
  983. GEM_BUG_ON(!i915_sw_fence_signaled(&req->submit));
  984. /* Optimistic short spin before touching IRQs */
  985. if (__i915_spin_request(req, wait.seqno, state, 5))
  986. goto complete;
  987. set_current_state(state);
  988. if (intel_engine_add_wait(req->engine, &wait))
  989. /* In order to check that we haven't missed the interrupt
  990. * as we enabled it, we need to kick ourselves to do a
  991. * coherent check on the seqno before we sleep.
  992. */
  993. goto wakeup;
  994. if (flags & I915_WAIT_LOCKED)
  995. __i915_wait_request_check_and_reset(req);
  996. for (;;) {
  997. if (signal_pending_state(state, current)) {
  998. timeout = -ERESTARTSYS;
  999. break;
  1000. }
  1001. if (!timeout) {
  1002. timeout = -ETIME;
  1003. break;
  1004. }
  1005. timeout = io_schedule_timeout(timeout);
  1006. if (intel_wait_complete(&wait) &&
  1007. intel_wait_check_request(&wait, req))
  1008. break;
  1009. set_current_state(state);
  1010. wakeup:
  1011. /* Carefully check if the request is complete, giving time
  1012. * for the seqno to be visible following the interrupt.
  1013. * We also have to check in case we are kicked by the GPU
  1014. * reset in order to drop the struct_mutex.
  1015. */
  1016. if (__i915_request_irq_complete(req))
  1017. break;
  1018. /* If the GPU is hung, and we hold the lock, reset the GPU
  1019. * and then check for completion. On a full reset, the engine's
  1020. * HW seqno will be advanced passed us and we are complete.
  1021. * If we do a partial reset, we have to wait for the GPU to
  1022. * resume and update the breadcrumb.
  1023. *
  1024. * If we don't hold the mutex, we can just wait for the worker
  1025. * to come along and update the breadcrumb (either directly
  1026. * itself, or indirectly by recovering the GPU).
  1027. */
  1028. if (flags & I915_WAIT_LOCKED &&
  1029. __i915_wait_request_check_and_reset(req))
  1030. continue;
  1031. /* Only spin if we know the GPU is processing this request */
  1032. if (__i915_spin_request(req, wait.seqno, state, 2))
  1033. break;
  1034. if (!intel_wait_check_request(&wait, req)) {
  1035. intel_engine_remove_wait(req->engine, &wait);
  1036. goto restart;
  1037. }
  1038. }
  1039. intel_engine_remove_wait(req->engine, &wait);
  1040. complete:
  1041. __set_current_state(TASK_RUNNING);
  1042. if (flags & I915_WAIT_LOCKED)
  1043. remove_wait_queue(errq, &reset);
  1044. remove_wait_queue(&req->execute, &exec);
  1045. trace_i915_gem_request_wait_end(req);
  1046. return timeout;
  1047. }
  1048. static void engine_retire_requests(struct intel_engine_cs *engine)
  1049. {
  1050. struct drm_i915_gem_request *request, *next;
  1051. u32 seqno = intel_engine_get_seqno(engine);
  1052. LIST_HEAD(retire);
  1053. spin_lock_irq(&engine->timeline->lock);
  1054. list_for_each_entry_safe(request, next,
  1055. &engine->timeline->requests, link) {
  1056. if (!i915_seqno_passed(seqno, request->global_seqno))
  1057. break;
  1058. list_move_tail(&request->link, &retire);
  1059. }
  1060. spin_unlock_irq(&engine->timeline->lock);
  1061. list_for_each_entry_safe(request, next, &retire, link)
  1062. i915_gem_request_retire(request);
  1063. }
  1064. void i915_gem_retire_requests(struct drm_i915_private *dev_priv)
  1065. {
  1066. struct intel_engine_cs *engine;
  1067. enum intel_engine_id id;
  1068. lockdep_assert_held(&dev_priv->drm.struct_mutex);
  1069. if (!dev_priv->gt.active_requests)
  1070. return;
  1071. for_each_engine(engine, dev_priv, id)
  1072. engine_retire_requests(engine);
  1073. }
  1074. #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
  1075. #include "selftests/mock_request.c"
  1076. #include "selftests/i915_gem_request.c"
  1077. #endif