2 * Copyright © 2008-2015 Intel Corporation
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:
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
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
25 #include <linux/prefetch.h>
26 #include <linux/dma-fence-array.h>
30 static const char *i915_fence_get_driver_name(struct dma_fence *fence)
35 static const char *i915_fence_get_timeline_name(struct dma_fence *fence)
37 /* Timelines are bound by eviction to a VM. However, since
38 * we only have a global seqno at the moment, we only have
39 * a single timeline. Note that each timeline will have
40 * multiple execution contexts (fence contexts) as we allow
41 * engines within a single timeline to execute in parallel.
43 return to_request(fence)->timeline->common->name;
46 static bool i915_fence_signaled(struct dma_fence *fence)
48 return i915_gem_request_completed(to_request(fence));
51 static bool i915_fence_enable_signaling(struct dma_fence *fence)
53 if (i915_fence_signaled(fence))
56 intel_engine_enable_signaling(to_request(fence));
60 static signed long i915_fence_wait(struct dma_fence *fence,
64 return i915_wait_request(to_request(fence), interruptible, timeout);
67 static void i915_fence_value_str(struct dma_fence *fence, char *str, int size)
69 snprintf(str, size, "%u", fence->seqno);
72 static void i915_fence_timeline_value_str(struct dma_fence *fence, char *str,
75 snprintf(str, size, "%u",
76 intel_engine_get_seqno(to_request(fence)->engine));
79 static void i915_fence_release(struct dma_fence *fence)
81 struct drm_i915_gem_request *req = to_request(fence);
83 kmem_cache_free(req->i915->requests, req);
86 const struct dma_fence_ops i915_fence_ops = {
87 .get_driver_name = i915_fence_get_driver_name,
88 .get_timeline_name = i915_fence_get_timeline_name,
89 .enable_signaling = i915_fence_enable_signaling,
90 .signaled = i915_fence_signaled,
91 .wait = i915_fence_wait,
92 .release = i915_fence_release,
93 .fence_value_str = i915_fence_value_str,
94 .timeline_value_str = i915_fence_timeline_value_str,
97 int i915_gem_request_add_to_client(struct drm_i915_gem_request *req,
98 struct drm_file *file)
100 struct drm_i915_private *dev_private;
101 struct drm_i915_file_private *file_priv;
103 WARN_ON(!req || !file || req->file_priv);
111 dev_private = req->i915;
112 file_priv = file->driver_priv;
114 spin_lock(&file_priv->mm.lock);
115 req->file_priv = file_priv;
116 list_add_tail(&req->client_list, &file_priv->mm.request_list);
117 spin_unlock(&file_priv->mm.lock);
123 i915_gem_request_remove_from_client(struct drm_i915_gem_request *request)
125 struct drm_i915_file_private *file_priv = request->file_priv;
130 spin_lock(&file_priv->mm.lock);
131 list_del(&request->client_list);
132 request->file_priv = NULL;
133 spin_unlock(&file_priv->mm.lock);
136 void i915_gem_retire_noop(struct i915_gem_active *active,
137 struct drm_i915_gem_request *request)
139 /* Space left intentionally blank */
142 static void i915_gem_request_retire(struct drm_i915_gem_request *request)
144 struct i915_gem_active *active, *next;
146 lockdep_assert_held(&request->i915->drm.struct_mutex);
147 GEM_BUG_ON(!i915_gem_request_completed(request));
149 trace_i915_gem_request_retire(request);
150 list_del_init(&request->link);
152 /* We know the GPU must have read the request to have
153 * sent us the seqno + interrupt, so use the position
154 * of tail of the request to update the last known position
157 * Note this requires that we are always called in request
160 list_del(&request->ring_link);
161 request->ring->last_retired_head = request->postfix;
163 /* Walk through the active list, calling retire on each. This allows
164 * objects to track their GPU activity and mark themselves as idle
165 * when their *last* active request is completed (updating state
166 * tracking lists for eviction, active references for GEM, etc).
168 * As the ->retire() may free the node, we decouple it first and
169 * pass along the auxiliary information (to avoid dereferencing
170 * the node after the callback).
172 list_for_each_entry_safe(active, next, &request->active_list, link) {
173 /* In microbenchmarks or focusing upon time inside the kernel,
174 * we may spend an inordinate amount of time simply handling
175 * the retirement of requests and processing their callbacks.
176 * Of which, this loop itself is particularly hot due to the
177 * cache misses when jumping around the list of i915_gem_active.
178 * So we try to keep this loop as streamlined as possible and
179 * also prefetch the next i915_gem_active to try and hide
180 * the likely cache miss.
184 INIT_LIST_HEAD(&active->link);
185 RCU_INIT_POINTER(active->request, NULL);
187 active->retire(active, request);
190 i915_gem_request_remove_from_client(request);
192 if (request->previous_context) {
193 if (i915.enable_execlists)
194 intel_lr_context_unpin(request->previous_context,
198 i915_gem_context_put(request->ctx);
200 dma_fence_signal(&request->fence);
201 i915_gem_request_put(request);
204 void i915_gem_request_retire_upto(struct drm_i915_gem_request *req)
206 struct intel_engine_cs *engine = req->engine;
207 struct drm_i915_gem_request *tmp;
209 lockdep_assert_held(&req->i915->drm.struct_mutex);
210 if (list_empty(&req->link))
214 tmp = list_first_entry(&engine->timeline->requests,
217 i915_gem_request_retire(tmp);
218 } while (tmp != req);
221 static int i915_gem_check_wedge(struct drm_i915_private *dev_priv)
223 struct i915_gpu_error *error = &dev_priv->gpu_error;
225 if (i915_terminally_wedged(error))
228 if (i915_reset_in_progress(error)) {
229 /* Non-interruptible callers can't handle -EAGAIN, hence return
230 * -EIO unconditionally for these.
232 if (!dev_priv->mm.interruptible)
241 static int i915_gem_init_global_seqno(struct drm_i915_private *dev_priv,
244 struct i915_gem_timeline *timeline = &dev_priv->gt.global_timeline;
245 struct intel_engine_cs *engine;
246 enum intel_engine_id id;
249 /* Carefully retire all requests without writing to the rings */
250 ret = i915_gem_wait_for_idle(dev_priv,
251 I915_WAIT_INTERRUPTIBLE |
256 i915_gem_retire_requests(dev_priv);
258 /* If the seqno wraps around, we need to clear the breadcrumb rbtree */
259 if (!i915_seqno_passed(seqno, timeline->next_seqno)) {
260 while (intel_kick_waiters(dev_priv) ||
261 intel_kick_signalers(dev_priv))
266 /* Finally reset hw state */
267 for_each_engine(engine, dev_priv, id)
268 intel_engine_init_global_seqno(engine, seqno);
273 int i915_gem_set_global_seqno(struct drm_device *dev, u32 seqno)
275 struct drm_i915_private *dev_priv = to_i915(dev);
278 lockdep_assert_held(&dev_priv->drm.struct_mutex);
283 /* HWS page needs to be set less than what we
284 * will inject to ring
286 ret = i915_gem_init_global_seqno(dev_priv, seqno - 1);
290 dev_priv->gt.global_timeline.next_seqno = seqno;
294 static int i915_gem_get_global_seqno(struct drm_i915_private *dev_priv,
297 struct i915_gem_timeline *tl = &dev_priv->gt.global_timeline;
299 /* reserve 0 for non-seqno */
300 if (unlikely(tl->next_seqno == 0)) {
303 ret = i915_gem_init_global_seqno(dev_priv, 0);
310 *seqno = tl->next_seqno++;
314 static int __i915_sw_fence_call
315 submit_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
317 struct drm_i915_gem_request *request =
318 container_of(fence, typeof(*request), submit);
319 struct intel_engine_cs *engine = request->engine;
321 /* Will be called from irq-context when using foreign DMA fences */
325 engine->timeline->last_submitted_seqno = request->fence.seqno;
326 engine->submit_request(request);
337 * i915_gem_request_alloc - allocate a request structure
339 * @engine: engine that we wish to issue the request on.
340 * @ctx: context that the request will be associated with.
341 * This can be NULL if the request is not directly related to
342 * any specific user context, in which case this function will
343 * choose an appropriate context to use.
345 * Returns a pointer to the allocated request if successful,
346 * or an error code if not.
348 struct drm_i915_gem_request *
349 i915_gem_request_alloc(struct intel_engine_cs *engine,
350 struct i915_gem_context *ctx)
352 struct drm_i915_private *dev_priv = engine->i915;
353 struct drm_i915_gem_request *req;
357 /* ABI: Before userspace accesses the GPU (e.g. execbuffer), report
358 * EIO if the GPU is already wedged, or EAGAIN to drop the struct_mutex
361 ret = i915_gem_check_wedge(dev_priv);
365 /* Move the oldest request to the slab-cache (if not in use!) */
366 req = list_first_entry_or_null(&engine->timeline->requests,
368 if (req && i915_gem_request_completed(req))
369 i915_gem_request_retire(req);
371 /* Beware: Dragons be flying overhead.
373 * We use RCU to look up requests in flight. The lookups may
374 * race with the request being allocated from the slab freelist.
375 * That is the request we are writing to here, may be in the process
376 * of being read by __i915_gem_active_get_rcu(). As such,
377 * we have to be very careful when overwriting the contents. During
378 * the RCU lookup, we change chase the request->engine pointer,
379 * read the request->fence.seqno and increment the reference count.
381 * The reference count is incremented atomically. If it is zero,
382 * the lookup knows the request is unallocated and complete. Otherwise,
383 * it is either still in use, or has been reallocated and reset
384 * with dma_fence_init(). This increment is safe for release as we
385 * check that the request we have a reference to and matches the active
388 * Before we increment the refcount, we chase the request->engine
389 * pointer. We must not call kmem_cache_zalloc() or else we set
390 * that pointer to NULL and cause a crash during the lookup. If
391 * we see the request is completed (based on the value of the
392 * old engine and seqno), the lookup is complete and reports NULL.
393 * If we decide the request is not completed (new engine or seqno),
394 * then we grab a reference and double check that it is still the
395 * active request - which it won't be and restart the lookup.
397 * Do not use kmem_cache_zalloc() here!
399 req = kmem_cache_alloc(dev_priv->requests, GFP_KERNEL);
401 return ERR_PTR(-ENOMEM);
403 ret = i915_gem_get_global_seqno(dev_priv, &seqno);
407 req->timeline = engine->timeline;
409 spin_lock_init(&req->lock);
410 dma_fence_init(&req->fence,
413 req->timeline->fence_context,
416 i915_sw_fence_init(&req->submit, submit_notify);
418 INIT_LIST_HEAD(&req->active_list);
419 req->i915 = dev_priv;
420 req->engine = engine;
421 req->ctx = i915_gem_context_get(ctx);
423 /* No zalloc, must clear what we need by hand */
424 req->previous_context = NULL;
425 req->file_priv = NULL;
429 * Reserve space in the ring buffer for all the commands required to
430 * eventually emit this request. This is to guarantee that the
431 * i915_add_request() call can't fail. Note that the reserve may need
432 * to be redone if the request is not actually submitted straight
433 * away, e.g. because a GPU scheduler has deferred it.
435 req->reserved_space = MIN_SPACE_FOR_ADD_REQUEST;
437 if (i915.enable_execlists)
438 ret = intel_logical_ring_alloc_request_extras(req);
440 ret = intel_ring_alloc_request_extras(req);
444 /* Record the position of the start of the request so that
445 * should we detect the updated seqno part-way through the
446 * GPU processing the request, we never over-estimate the
447 * position of the head.
449 req->head = req->ring->tail;
454 i915_gem_context_put(ctx);
456 kmem_cache_free(dev_priv->requests, req);
461 i915_gem_request_await_request(struct drm_i915_gem_request *to,
462 struct drm_i915_gem_request *from)
466 GEM_BUG_ON(to == from);
468 if (to->timeline == from->timeline)
471 if (to->engine == from->engine) {
472 ret = i915_sw_fence_await_sw_fence_gfp(&to->submit,
475 return ret < 0 ? ret : 0;
478 idx = intel_engine_sync_index(from->engine, to->engine);
479 if (from->fence.seqno <= from->engine->semaphore.sync_seqno[idx])
482 trace_i915_gem_ring_sync_to(to, from);
483 if (!i915.semaphores) {
484 if (!i915_spin_request(from, TASK_INTERRUPTIBLE, 2)) {
485 ret = i915_sw_fence_await_dma_fence(&to->submit,
492 ret = to->engine->semaphore.sync_to(to, from);
497 from->engine->semaphore.sync_seqno[idx] = from->fence.seqno;
502 i915_gem_request_await_dma_fence(struct drm_i915_gem_request *req,
503 struct dma_fence *fence)
505 struct dma_fence_array *array;
509 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
512 if (dma_fence_is_i915(fence))
513 return i915_gem_request_await_request(req, to_request(fence));
515 if (!dma_fence_is_array(fence)) {
516 ret = i915_sw_fence_await_dma_fence(&req->submit,
517 fence, I915_FENCE_TIMEOUT,
519 return ret < 0 ? ret : 0;
522 /* Note that if the fence-array was created in signal-on-any mode,
523 * we should *not* decompose it into its individual fences. However,
524 * we don't currently store which mode the fence-array is operating
525 * in. Fortunately, the only user of signal-on-any is private to
526 * amdgpu and we should not see any incoming fence-array from
527 * sync-file being in signal-on-any mode.
530 array = to_dma_fence_array(fence);
531 for (i = 0; i < array->num_fences; i++) {
532 struct dma_fence *child = array->fences[i];
534 if (dma_fence_is_i915(child))
535 ret = i915_gem_request_await_request(req,
538 ret = i915_sw_fence_await_dma_fence(&req->submit,
539 child, I915_FENCE_TIMEOUT,
549 * i915_gem_request_await_object - set this request to (async) wait upon a bo
551 * @to: request we are wishing to use
552 * @obj: object which may be in use on another ring.
554 * This code is meant to abstract object synchronization with the GPU.
555 * Conceptually we serialise writes between engines inside the GPU.
556 * We only allow one engine to write into a buffer at any time, but
557 * multiple readers. To ensure each has a coherent view of memory, we must:
559 * - If there is an outstanding write request to the object, the new
560 * request must wait for it to complete (either CPU or in hw, requests
561 * on the same ring will be naturally ordered).
563 * - If we are a write request (pending_write_domain is set), the new
564 * request must wait for outstanding read requests to complete.
566 * Returns 0 if successful, else propagates up the lower layer error.
569 i915_gem_request_await_object(struct drm_i915_gem_request *to,
570 struct drm_i915_gem_object *obj,
573 struct dma_fence *excl;
577 struct dma_fence **shared;
578 unsigned int count, i;
580 ret = reservation_object_get_fences_rcu(obj->resv,
581 &excl, &count, &shared);
585 for (i = 0; i < count; i++) {
586 ret = i915_gem_request_await_dma_fence(to, shared[i]);
590 dma_fence_put(shared[i]);
593 for (; i < count; i++)
594 dma_fence_put(shared[i]);
597 excl = reservation_object_get_excl_rcu(obj->resv);
602 ret = i915_gem_request_await_dma_fence(to, excl);
610 static void i915_gem_mark_busy(const struct intel_engine_cs *engine)
612 struct drm_i915_private *dev_priv = engine->i915;
614 dev_priv->gt.active_engines |= intel_engine_flag(engine);
615 if (dev_priv->gt.awake)
618 intel_runtime_pm_get_noresume(dev_priv);
619 dev_priv->gt.awake = true;
621 intel_enable_gt_powersave(dev_priv);
622 i915_update_gfx_val(dev_priv);
623 if (INTEL_GEN(dev_priv) >= 6)
624 gen6_rps_busy(dev_priv);
626 queue_delayed_work(dev_priv->wq,
627 &dev_priv->gt.retire_work,
628 round_jiffies_up_relative(HZ));
632 * NB: This function is not allowed to fail. Doing so would mean the the
633 * request is not being tracked for completion but the work itself is
634 * going to happen on the hardware. This would be a Bad Thing(tm).
636 void __i915_add_request(struct drm_i915_gem_request *request, bool flush_caches)
638 struct intel_engine_cs *engine = request->engine;
639 struct intel_ring *ring = request->ring;
640 struct intel_timeline *timeline = request->timeline;
641 struct drm_i915_gem_request *prev;
646 lockdep_assert_held(&request->i915->drm.struct_mutex);
647 trace_i915_gem_request_add(request);
650 * To ensure that this call will not fail, space for its emissions
651 * should already have been reserved in the ring buffer. Let the ring
652 * know that it is time to use that space up.
654 request_start = ring->tail;
655 reserved_tail = request->reserved_space;
656 request->reserved_space = 0;
659 * Emit any outstanding flushes - execbuf can fail to emit the flush
660 * after having emitted the batchbuffer command. Hence we need to fix
661 * things up similar to emitting the lazy request. The difference here
662 * is that the flush _must_ happen before the next request, no matter
666 ret = engine->emit_flush(request, EMIT_FLUSH);
668 /* Not allowed to fail! */
669 WARN(ret, "engine->emit_flush() failed: %d!\n", ret);
672 /* Record the position of the start of the breadcrumb so that
673 * should we detect the updated seqno part-way through the
674 * GPU processing the request, we never over-estimate the
675 * position of the ring's HEAD.
677 request->postfix = ring->tail;
679 /* Not allowed to fail! */
680 ret = engine->emit_request(request);
681 WARN(ret, "(%s)->emit_request failed: %d!\n", engine->name, ret);
683 /* Sanity check that the reserved size was large enough. */
684 ret = ring->tail - request_start;
687 WARN_ONCE(ret > reserved_tail,
688 "Not enough space reserved (%d bytes) "
689 "for adding the request (%d bytes)\n",
692 /* Seal the request and mark it as pending execution. Note that
693 * we may inspect this state, without holding any locks, during
694 * hangcheck. Hence we apply the barrier to ensure that we do not
695 * see a more recent value in the hws than we are tracking.
698 prev = i915_gem_active_raw(&timeline->last_request,
699 &request->i915->drm.struct_mutex);
701 i915_sw_fence_await_sw_fence(&request->submit, &prev->submit,
704 request->emitted_jiffies = jiffies;
705 request->previous_seqno = timeline->last_pending_seqno;
706 timeline->last_pending_seqno = request->fence.seqno;
707 i915_gem_active_set(&timeline->last_request, request);
708 list_add_tail(&request->link, &timeline->requests);
709 list_add_tail(&request->ring_link, &ring->request_list);
711 i915_gem_mark_busy(engine);
714 i915_sw_fence_commit(&request->submit);
715 local_bh_enable(); /* Kick the execlists tasklet if just scheduled */
718 static void reset_wait_queue(wait_queue_head_t *q, wait_queue_t *wait)
722 spin_lock_irqsave(&q->lock, flags);
723 if (list_empty(&wait->task_list))
724 __add_wait_queue(q, wait);
725 spin_unlock_irqrestore(&q->lock, flags);
728 static unsigned long local_clock_us(unsigned int *cpu)
732 /* Cheaply and approximately convert from nanoseconds to microseconds.
733 * The result and subsequent calculations are also defined in the same
734 * approximate microseconds units. The principal source of timing
735 * error here is from the simple truncation.
737 * Note that local_clock() is only defined wrt to the current CPU;
738 * the comparisons are no longer valid if we switch CPUs. Instead of
739 * blocking preemption for the entire busywait, we can detect the CPU
740 * switch and use that as indicator of system load and a reason to
741 * stop busywaiting, see busywait_stop().
744 t = local_clock() >> 10;
750 static bool busywait_stop(unsigned long timeout, unsigned int cpu)
752 unsigned int this_cpu;
754 if (time_after(local_clock_us(&this_cpu), timeout))
757 return this_cpu != cpu;
760 bool __i915_spin_request(const struct drm_i915_gem_request *req,
761 int state, unsigned long timeout_us)
765 /* When waiting for high frequency requests, e.g. during synchronous
766 * rendering split between the CPU and GPU, the finite amount of time
767 * required to set up the irq and wait upon it limits the response
768 * rate. By busywaiting on the request completion for a short while we
769 * can service the high frequency waits as quick as possible. However,
770 * if it is a slow request, we want to sleep as quickly as possible.
771 * The tradeoff between waiting and sleeping is roughly the time it
772 * takes to sleep on a request, on the order of a microsecond.
775 timeout_us += local_clock_us(&cpu);
777 if (i915_gem_request_completed(req))
780 if (signal_pending_state(state, current))
783 if (busywait_stop(timeout_us, cpu))
786 cpu_relax_lowlatency();
787 } while (!need_resched());
793 * i915_wait_request - wait until execution of request has finished
794 * @req: the request to wait upon
795 * @flags: how to wait
796 * @timeout: how long to wait in jiffies
798 * i915_wait_request() waits for the request to be completed, for a
799 * maximum of @timeout jiffies (with MAX_SCHEDULE_TIMEOUT implying an
802 * If the caller holds the struct_mutex, the caller must pass I915_WAIT_LOCKED
803 * in via the flags, and vice versa if the struct_mutex is not held, the caller
804 * must not specify that the wait is locked.
806 * Returns the remaining time (in jiffies) if the request completed, which may
807 * be zero or -ETIME if the request is unfinished after the timeout expires.
808 * May return -EINTR is called with I915_WAIT_INTERRUPTIBLE and a signal is
809 * pending before the request completes.
811 long i915_wait_request(struct drm_i915_gem_request *req,
815 const int state = flags & I915_WAIT_INTERRUPTIBLE ?
816 TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE;
818 struct intel_wait wait;
821 #if IS_ENABLED(CONFIG_LOCKDEP)
822 GEM_BUG_ON(debug_locks &&
823 !!lockdep_is_held(&req->i915->drm.struct_mutex) !=
824 !!(flags & I915_WAIT_LOCKED));
826 GEM_BUG_ON(timeout < 0);
828 if (i915_gem_request_completed(req))
834 trace_i915_gem_request_wait_begin(req);
836 /* Optimistic short spin before touching IRQs */
837 if (i915_spin_request(req, state, 5))
840 set_current_state(state);
841 if (flags & I915_WAIT_LOCKED)
842 add_wait_queue(&req->i915->gpu_error.wait_queue, &reset);
844 intel_wait_init(&wait, req->fence.seqno);
845 if (intel_engine_add_wait(req->engine, &wait))
846 /* In order to check that we haven't missed the interrupt
847 * as we enabled it, we need to kick ourselves to do a
848 * coherent check on the seqno before we sleep.
853 if (signal_pending_state(state, current)) {
854 timeout = -ERESTARTSYS;
863 timeout = io_schedule_timeout(timeout);
865 if (intel_wait_complete(&wait))
868 set_current_state(state);
871 /* Carefully check if the request is complete, giving time
872 * for the seqno to be visible following the interrupt.
873 * We also have to check in case we are kicked by the GPU
874 * reset in order to drop the struct_mutex.
876 if (__i915_request_irq_complete(req))
879 /* If the GPU is hung, and we hold the lock, reset the GPU
880 * and then check for completion. On a full reset, the engine's
881 * HW seqno will be advanced passed us and we are complete.
882 * If we do a partial reset, we have to wait for the GPU to
883 * resume and update the breadcrumb.
885 * If we don't hold the mutex, we can just wait for the worker
886 * to come along and update the breadcrumb (either directly
887 * itself, or indirectly by recovering the GPU).
889 if (flags & I915_WAIT_LOCKED &&
890 i915_reset_in_progress(&req->i915->gpu_error)) {
891 __set_current_state(TASK_RUNNING);
892 i915_reset(req->i915);
893 reset_wait_queue(&req->i915->gpu_error.wait_queue,
898 /* Only spin if we know the GPU is processing this request */
899 if (i915_spin_request(req, state, 2))
903 intel_engine_remove_wait(req->engine, &wait);
904 if (flags & I915_WAIT_LOCKED)
905 remove_wait_queue(&req->i915->gpu_error.wait_queue, &reset);
906 __set_current_state(TASK_RUNNING);
909 trace_i915_gem_request_wait_end(req);
914 static bool engine_retire_requests(struct intel_engine_cs *engine)
916 struct drm_i915_gem_request *request, *next;
918 list_for_each_entry_safe(request, next,
919 &engine->timeline->requests, link) {
920 if (!i915_gem_request_completed(request))
923 i915_gem_request_retire(request);
929 void i915_gem_retire_requests(struct drm_i915_private *dev_priv)
931 struct intel_engine_cs *engine;
934 lockdep_assert_held(&dev_priv->drm.struct_mutex);
936 if (dev_priv->gt.active_engines == 0)
939 GEM_BUG_ON(!dev_priv->gt.awake);
941 for_each_engine_masked(engine, dev_priv, dev_priv->gt.active_engines, tmp)
942 if (engine_retire_requests(engine))
943 dev_priv->gt.active_engines &= ~intel_engine_flag(engine);
945 if (dev_priv->gt.active_engines == 0)
946 queue_delayed_work(dev_priv->wq,
947 &dev_priv->gt.idle_work,
948 msecs_to_jiffies(100));