Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 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 | |
Chris Wilson | fa545cb | 2016-08-04 07:52:35 +0100 | [diff] [blame] | 25 | #include <linux/prefetch.h> |
Chris Wilson | b52992c | 2016-10-28 13:58:24 +0100 | [diff] [blame] | 26 | #include <linux/dma-fence-array.h> |
Chris Wilson | fa545cb | 2016-08-04 07:52:35 +0100 | [diff] [blame] | 27 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 28 | #include "i915_drv.h" |
| 29 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 30 | static const char *i915_fence_get_driver_name(struct dma_fence *fence) |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 31 | { |
| 32 | return "i915"; |
| 33 | } |
| 34 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 35 | static const char *i915_fence_get_timeline_name(struct dma_fence *fence) |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 36 | { |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 37 | return to_request(fence)->timeline->common->name; |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 38 | } |
| 39 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 40 | static bool i915_fence_signaled(struct dma_fence *fence) |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 41 | { |
| 42 | return i915_gem_request_completed(to_request(fence)); |
| 43 | } |
| 44 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 45 | static bool i915_fence_enable_signaling(struct dma_fence *fence) |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 46 | { |
| 47 | if (i915_fence_signaled(fence)) |
| 48 | return false; |
| 49 | |
| 50 | intel_engine_enable_signaling(to_request(fence)); |
| 51 | return true; |
| 52 | } |
| 53 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 54 | static signed long i915_fence_wait(struct dma_fence *fence, |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 55 | bool interruptible, |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 56 | signed long timeout) |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 57 | { |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 58 | return i915_wait_request(to_request(fence), interruptible, timeout); |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 61 | static void i915_fence_release(struct dma_fence *fence) |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 62 | { |
| 63 | struct drm_i915_gem_request *req = to_request(fence); |
| 64 | |
| 65 | kmem_cache_free(req->i915->requests, req); |
| 66 | } |
| 67 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 68 | const struct dma_fence_ops i915_fence_ops = { |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 69 | .get_driver_name = i915_fence_get_driver_name, |
| 70 | .get_timeline_name = i915_fence_get_timeline_name, |
| 71 | .enable_signaling = i915_fence_enable_signaling, |
| 72 | .signaled = i915_fence_signaled, |
| 73 | .wait = i915_fence_wait, |
| 74 | .release = i915_fence_release, |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 75 | }; |
| 76 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 77 | int i915_gem_request_add_to_client(struct drm_i915_gem_request *req, |
| 78 | struct drm_file *file) |
| 79 | { |
| 80 | struct drm_i915_private *dev_private; |
| 81 | struct drm_i915_file_private *file_priv; |
| 82 | |
| 83 | WARN_ON(!req || !file || req->file_priv); |
| 84 | |
| 85 | if (!req || !file) |
| 86 | return -EINVAL; |
| 87 | |
| 88 | if (req->file_priv) |
| 89 | return -EINVAL; |
| 90 | |
| 91 | dev_private = req->i915; |
| 92 | file_priv = file->driver_priv; |
| 93 | |
| 94 | spin_lock(&file_priv->mm.lock); |
| 95 | req->file_priv = file_priv; |
| 96 | list_add_tail(&req->client_list, &file_priv->mm.request_list); |
| 97 | spin_unlock(&file_priv->mm.lock); |
| 98 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static inline void |
| 103 | i915_gem_request_remove_from_client(struct drm_i915_gem_request *request) |
| 104 | { |
| 105 | struct drm_i915_file_private *file_priv = request->file_priv; |
| 106 | |
| 107 | if (!file_priv) |
| 108 | return; |
| 109 | |
| 110 | spin_lock(&file_priv->mm.lock); |
| 111 | list_del(&request->client_list); |
| 112 | request->file_priv = NULL; |
| 113 | spin_unlock(&file_priv->mm.lock); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Chris Wilson | fa545cb | 2016-08-04 07:52:35 +0100 | [diff] [blame] | 116 | void i915_gem_retire_noop(struct i915_gem_active *active, |
| 117 | struct drm_i915_gem_request *request) |
| 118 | { |
| 119 | /* Space left intentionally blank */ |
| 120 | } |
| 121 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 122 | static void i915_gem_request_retire(struct drm_i915_gem_request *request) |
| 123 | { |
Chris Wilson | fa545cb | 2016-08-04 07:52:35 +0100 | [diff] [blame] | 124 | struct i915_gem_active *active, *next; |
| 125 | |
Chris Wilson | 4c7d62c | 2016-10-28 13:58:32 +0100 | [diff] [blame] | 126 | lockdep_assert_held(&request->i915->drm.struct_mutex); |
| 127 | GEM_BUG_ON(!i915_gem_request_completed(request)); |
| 128 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 129 | trace_i915_gem_request_retire(request); |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 130 | |
| 131 | spin_lock_irq(&request->engine->timeline->lock); |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 132 | list_del_init(&request->link); |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 133 | spin_unlock_irq(&request->engine->timeline->lock); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 134 | |
| 135 | /* We know the GPU must have read the request to have |
| 136 | * sent us the seqno + interrupt, so use the position |
| 137 | * of tail of the request to update the last known position |
| 138 | * of the GPU head. |
| 139 | * |
| 140 | * Note this requires that we are always called in request |
| 141 | * completion order. |
| 142 | */ |
Chris Wilson | 675d9ad | 2016-08-04 07:52:36 +0100 | [diff] [blame] | 143 | list_del(&request->ring_link); |
Chris Wilson | 1dae2df | 2016-08-02 22:50:19 +0100 | [diff] [blame] | 144 | request->ring->last_retired_head = request->postfix; |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 145 | request->i915->gt.active_requests--; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 146 | |
Chris Wilson | fa545cb | 2016-08-04 07:52:35 +0100 | [diff] [blame] | 147 | /* Walk through the active list, calling retire on each. This allows |
| 148 | * objects to track their GPU activity and mark themselves as idle |
| 149 | * when their *last* active request is completed (updating state |
| 150 | * tracking lists for eviction, active references for GEM, etc). |
| 151 | * |
| 152 | * As the ->retire() may free the node, we decouple it first and |
| 153 | * pass along the auxiliary information (to avoid dereferencing |
| 154 | * the node after the callback). |
| 155 | */ |
| 156 | list_for_each_entry_safe(active, next, &request->active_list, link) { |
| 157 | /* In microbenchmarks or focusing upon time inside the kernel, |
| 158 | * we may spend an inordinate amount of time simply handling |
| 159 | * the retirement of requests and processing their callbacks. |
| 160 | * Of which, this loop itself is particularly hot due to the |
| 161 | * cache misses when jumping around the list of i915_gem_active. |
| 162 | * So we try to keep this loop as streamlined as possible and |
| 163 | * also prefetch the next i915_gem_active to try and hide |
| 164 | * the likely cache miss. |
| 165 | */ |
| 166 | prefetchw(next); |
| 167 | |
| 168 | INIT_LIST_HEAD(&active->link); |
Chris Wilson | 0eafec6 | 2016-08-04 16:32:41 +0100 | [diff] [blame] | 169 | RCU_INIT_POINTER(active->request, NULL); |
Chris Wilson | fa545cb | 2016-08-04 07:52:35 +0100 | [diff] [blame] | 170 | |
| 171 | active->retire(active, request); |
| 172 | } |
| 173 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 174 | i915_gem_request_remove_from_client(request); |
| 175 | |
| 176 | if (request->previous_context) { |
| 177 | if (i915.enable_execlists) |
| 178 | intel_lr_context_unpin(request->previous_context, |
| 179 | request->engine); |
| 180 | } |
| 181 | |
Chris Wilson | 9a6feaf | 2016-07-20 13:31:50 +0100 | [diff] [blame] | 182 | i915_gem_context_put(request->ctx); |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 183 | |
| 184 | dma_fence_signal(&request->fence); |
Chris Wilson | e8a261e | 2016-07-20 13:31:49 +0100 | [diff] [blame] | 185 | i915_gem_request_put(request); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | void i915_gem_request_retire_upto(struct drm_i915_gem_request *req) |
| 189 | { |
| 190 | struct intel_engine_cs *engine = req->engine; |
| 191 | struct drm_i915_gem_request *tmp; |
| 192 | |
| 193 | lockdep_assert_held(&req->i915->drm.struct_mutex); |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 194 | if (list_empty(&req->link)) |
| 195 | return; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 196 | |
| 197 | do { |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 198 | tmp = list_first_entry(&engine->timeline->requests, |
Chris Wilson | efdf7c0 | 2016-08-04 07:52:33 +0100 | [diff] [blame] | 199 | typeof(*tmp), link); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 200 | |
| 201 | i915_gem_request_retire(tmp); |
| 202 | } while (tmp != req); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 203 | } |
| 204 | |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 205 | static int i915_gem_check_wedge(struct drm_i915_private *dev_priv) |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 206 | { |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 207 | struct i915_gpu_error *error = &dev_priv->gpu_error; |
| 208 | |
| 209 | if (i915_terminally_wedged(error)) |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 210 | return -EIO; |
| 211 | |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 212 | if (i915_reset_in_progress(error)) { |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 213 | /* Non-interruptible callers can't handle -EAGAIN, hence return |
| 214 | * -EIO unconditionally for these. |
| 215 | */ |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 216 | if (!dev_priv->mm.interruptible) |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 217 | return -EIO; |
| 218 | |
| 219 | return -EAGAIN; |
| 220 | } |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
Chris Wilson | 85e17f5 | 2016-10-28 13:58:53 +0100 | [diff] [blame] | 225 | static int i915_gem_init_global_seqno(struct drm_i915_private *i915, u32 seqno) |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 226 | { |
Chris Wilson | 85e17f5 | 2016-10-28 13:58:53 +0100 | [diff] [blame] | 227 | struct i915_gem_timeline *timeline = &i915->gt.global_timeline; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 228 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 229 | enum intel_engine_id id; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 230 | int ret; |
| 231 | |
| 232 | /* Carefully retire all requests without writing to the rings */ |
Chris Wilson | 85e17f5 | 2016-10-28 13:58:53 +0100 | [diff] [blame] | 233 | ret = i915_gem_wait_for_idle(i915, |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 234 | I915_WAIT_INTERRUPTIBLE | |
| 235 | I915_WAIT_LOCKED); |
| 236 | if (ret) |
| 237 | return ret; |
| 238 | |
Chris Wilson | 85e17f5 | 2016-10-28 13:58:53 +0100 | [diff] [blame] | 239 | i915_gem_retire_requests(i915); |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 240 | GEM_BUG_ON(i915->gt.active_requests > 1); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 241 | |
| 242 | /* If the seqno wraps around, we need to clear the breadcrumb rbtree */ |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 243 | if (!i915_seqno_passed(seqno, atomic_read(&timeline->next_seqno))) { |
Chris Wilson | 6a5d1db | 2016-11-08 14:37:19 +0000 | [diff] [blame] | 244 | while (intel_breadcrumbs_busy(i915)) |
| 245 | cond_resched(); /* spin until threads are complete */ |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 246 | } |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 247 | atomic_set(&timeline->next_seqno, seqno); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 248 | |
| 249 | /* Finally reset hw state */ |
Chris Wilson | 85e17f5 | 2016-10-28 13:58:53 +0100 | [diff] [blame] | 250 | for_each_engine(engine, i915, id) |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 251 | intel_engine_init_global_seqno(engine, seqno); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 252 | |
Chris Wilson | 85e17f5 | 2016-10-28 13:58:53 +0100 | [diff] [blame] | 253 | list_for_each_entry(timeline, &i915->gt.timelines, link) { |
| 254 | for_each_engine(engine, i915, id) { |
| 255 | struct intel_timeline *tl = &timeline->engine[id]; |
| 256 | |
| 257 | memset(tl->sync_seqno, 0, sizeof(tl->sync_seqno)); |
| 258 | } |
| 259 | } |
| 260 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 261 | return 0; |
| 262 | } |
| 263 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 264 | int i915_gem_set_global_seqno(struct drm_device *dev, u32 seqno) |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 265 | { |
| 266 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 267 | |
Chris Wilson | 4c7d62c | 2016-10-28 13:58:32 +0100 | [diff] [blame] | 268 | lockdep_assert_held(&dev_priv->drm.struct_mutex); |
| 269 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 270 | if (seqno == 0) |
| 271 | return -EINVAL; |
| 272 | |
| 273 | /* HWS page needs to be set less than what we |
| 274 | * will inject to ring |
| 275 | */ |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 276 | return i915_gem_init_global_seqno(dev_priv, seqno - 1); |
| 277 | } |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 278 | |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 279 | static int reserve_global_seqno(struct drm_i915_private *i915) |
| 280 | { |
| 281 | u32 active_requests = ++i915->gt.active_requests; |
| 282 | u32 next_seqno = atomic_read(&i915->gt.global_timeline.next_seqno); |
| 283 | int ret; |
| 284 | |
| 285 | /* Reservation is fine until we need to wrap around */ |
| 286 | if (likely(next_seqno + active_requests > next_seqno)) |
| 287 | return 0; |
| 288 | |
| 289 | ret = i915_gem_init_global_seqno(i915, 0); |
| 290 | if (ret) { |
| 291 | i915->gt.active_requests--; |
| 292 | return ret; |
| 293 | } |
| 294 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 295 | return 0; |
| 296 | } |
| 297 | |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 298 | static u32 __timeline_get_seqno(struct i915_gem_timeline *tl) |
| 299 | { |
| 300 | /* next_seqno only incremented under a mutex */ |
| 301 | return ++tl->next_seqno.counter; |
| 302 | } |
| 303 | |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 304 | static u32 timeline_get_seqno(struct i915_gem_timeline *tl) |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 305 | { |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 306 | return atomic_inc_return(&tl->next_seqno); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 307 | } |
| 308 | |
Chris Wilson | 5590af3 | 2016-09-09 14:11:54 +0100 | [diff] [blame] | 309 | static int __i915_sw_fence_call |
| 310 | submit_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state) |
| 311 | { |
| 312 | struct drm_i915_gem_request *request = |
| 313 | container_of(fence, typeof(*request), submit); |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 314 | struct intel_engine_cs *engine = request->engine; |
Chris Wilson | f2d1329 | 2016-10-28 13:58:57 +0100 | [diff] [blame] | 315 | struct intel_timeline *timeline; |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 316 | unsigned long flags; |
Chris Wilson | f2d1329 | 2016-10-28 13:58:57 +0100 | [diff] [blame] | 317 | u32 seqno; |
Chris Wilson | 5590af3 | 2016-09-09 14:11:54 +0100 | [diff] [blame] | 318 | |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 319 | if (state != FENCE_COMPLETE) |
| 320 | return NOTIFY_DONE; |
| 321 | |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 322 | /* Transfer from per-context onto the global per-engine timeline */ |
| 323 | timeline = engine->timeline; |
| 324 | GEM_BUG_ON(timeline == request->timeline); |
| 325 | |
Chris Wilson | 5590af3 | 2016-09-09 14:11:54 +0100 | [diff] [blame] | 326 | /* Will be called from irq-context when using foreign DMA fences */ |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 327 | spin_lock_irqsave(&timeline->lock, flags); |
Chris Wilson | 5590af3 | 2016-09-09 14:11:54 +0100 | [diff] [blame] | 328 | |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 329 | seqno = timeline_get_seqno(timeline->common); |
Chris Wilson | f2d1329 | 2016-10-28 13:58:57 +0100 | [diff] [blame] | 330 | GEM_BUG_ON(!seqno); |
| 331 | GEM_BUG_ON(i915_seqno_passed(intel_engine_get_seqno(engine), seqno)); |
| 332 | |
| 333 | GEM_BUG_ON(i915_seqno_passed(timeline->last_submitted_seqno, seqno)); |
| 334 | request->previous_seqno = timeline->last_submitted_seqno; |
| 335 | timeline->last_submitted_seqno = seqno; |
| 336 | |
| 337 | /* We may be recursing from the signal callback of another i915 fence */ |
| 338 | spin_lock_nested(&request->lock, SINGLE_DEPTH_NESTING); |
| 339 | request->global_seqno = seqno; |
| 340 | if (test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &request->fence.flags)) |
| 341 | intel_engine_enable_signaling(request); |
| 342 | spin_unlock(&request->lock); |
| 343 | |
| 344 | GEM_BUG_ON(!request->global_seqno); |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 345 | engine->emit_breadcrumb(request, |
| 346 | request->ring->vaddr + request->postfix); |
| 347 | engine->submit_request(request); |
Chris Wilson | 5590af3 | 2016-09-09 14:11:54 +0100 | [diff] [blame] | 348 | |
Chris Wilson | bb89485 | 2016-11-14 20:40:57 +0000 | [diff] [blame^] | 349 | spin_lock(&request->timeline->lock); |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 350 | list_move_tail(&request->link, &timeline->requests); |
| 351 | spin_unlock(&request->timeline->lock); |
| 352 | |
| 353 | spin_unlock_irqrestore(&timeline->lock, flags); |
| 354 | |
Chris Wilson | 5590af3 | 2016-09-09 14:11:54 +0100 | [diff] [blame] | 355 | return NOTIFY_DONE; |
| 356 | } |
| 357 | |
Chris Wilson | 8e63717 | 2016-08-02 22:50:26 +0100 | [diff] [blame] | 358 | /** |
| 359 | * i915_gem_request_alloc - allocate a request structure |
| 360 | * |
| 361 | * @engine: engine that we wish to issue the request on. |
| 362 | * @ctx: context that the request will be associated with. |
| 363 | * This can be NULL if the request is not directly related to |
| 364 | * any specific user context, in which case this function will |
| 365 | * choose an appropriate context to use. |
| 366 | * |
| 367 | * Returns a pointer to the allocated request if successful, |
| 368 | * or an error code if not. |
| 369 | */ |
| 370 | struct drm_i915_gem_request * |
| 371 | i915_gem_request_alloc(struct intel_engine_cs *engine, |
| 372 | struct i915_gem_context *ctx) |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 373 | { |
| 374 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 375 | struct drm_i915_gem_request *req; |
| 376 | int ret; |
| 377 | |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 378 | lockdep_assert_held(&dev_priv->drm.struct_mutex); |
| 379 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 380 | /* ABI: Before userspace accesses the GPU (e.g. execbuffer), report |
| 381 | * EIO if the GPU is already wedged, or EAGAIN to drop the struct_mutex |
| 382 | * and restart. |
| 383 | */ |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 384 | ret = i915_gem_check_wedge(dev_priv); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 385 | if (ret) |
Chris Wilson | 8e63717 | 2016-08-02 22:50:26 +0100 | [diff] [blame] | 386 | return ERR_PTR(ret); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 387 | |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 388 | ret = reserve_global_seqno(dev_priv); |
| 389 | if (ret) |
| 390 | return ERR_PTR(ret); |
| 391 | |
Chris Wilson | 9b5f4e5 | 2016-07-20 09:21:09 +0100 | [diff] [blame] | 392 | /* Move the oldest request to the slab-cache (if not in use!) */ |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 393 | req = list_first_entry_or_null(&engine->timeline->requests, |
Chris Wilson | efdf7c0 | 2016-08-04 07:52:33 +0100 | [diff] [blame] | 394 | typeof(*req), link); |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 395 | if (req && __i915_gem_request_completed(req)) |
Chris Wilson | 2a1d775 | 2016-07-26 12:01:51 +0100 | [diff] [blame] | 396 | i915_gem_request_retire(req); |
Chris Wilson | 9b5f4e5 | 2016-07-20 09:21:09 +0100 | [diff] [blame] | 397 | |
Chris Wilson | 5a198b8 | 2016-08-09 09:23:34 +0100 | [diff] [blame] | 398 | /* Beware: Dragons be flying overhead. |
| 399 | * |
| 400 | * We use RCU to look up requests in flight. The lookups may |
| 401 | * race with the request being allocated from the slab freelist. |
| 402 | * That is the request we are writing to here, may be in the process |
Chris Wilson | 1426f71 | 2016-08-09 17:03:22 +0100 | [diff] [blame] | 403 | * of being read by __i915_gem_active_get_rcu(). As such, |
Chris Wilson | 5a198b8 | 2016-08-09 09:23:34 +0100 | [diff] [blame] | 404 | * we have to be very careful when overwriting the contents. During |
| 405 | * the RCU lookup, we change chase the request->engine pointer, |
Chris Wilson | 65e4760 | 2016-10-28 13:58:49 +0100 | [diff] [blame] | 406 | * read the request->global_seqno and increment the reference count. |
Chris Wilson | 5a198b8 | 2016-08-09 09:23:34 +0100 | [diff] [blame] | 407 | * |
| 408 | * The reference count is incremented atomically. If it is zero, |
| 409 | * the lookup knows the request is unallocated and complete. Otherwise, |
| 410 | * it is either still in use, or has been reallocated and reset |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 411 | * with dma_fence_init(). This increment is safe for release as we |
| 412 | * check that the request we have a reference to and matches the active |
Chris Wilson | 5a198b8 | 2016-08-09 09:23:34 +0100 | [diff] [blame] | 413 | * request. |
| 414 | * |
| 415 | * Before we increment the refcount, we chase the request->engine |
| 416 | * pointer. We must not call kmem_cache_zalloc() or else we set |
| 417 | * that pointer to NULL and cause a crash during the lookup. If |
| 418 | * we see the request is completed (based on the value of the |
| 419 | * old engine and seqno), the lookup is complete and reports NULL. |
| 420 | * If we decide the request is not completed (new engine or seqno), |
| 421 | * then we grab a reference and double check that it is still the |
| 422 | * active request - which it won't be and restart the lookup. |
| 423 | * |
| 424 | * Do not use kmem_cache_zalloc() here! |
| 425 | */ |
| 426 | req = kmem_cache_alloc(dev_priv->requests, GFP_KERNEL); |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 427 | if (!req) { |
| 428 | ret = -ENOMEM; |
| 429 | goto err_unreserve; |
| 430 | } |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 431 | |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 432 | req->timeline = i915_gem_context_lookup_timeline(ctx, engine); |
| 433 | GEM_BUG_ON(req->timeline == engine->timeline); |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 434 | |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 435 | spin_lock_init(&req->lock); |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 436 | dma_fence_init(&req->fence, |
| 437 | &i915_fence_ops, |
| 438 | &req->lock, |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 439 | req->timeline->fence_context, |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 440 | __timeline_get_seqno(req->timeline->common)); |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 441 | |
Chris Wilson | 5590af3 | 2016-09-09 14:11:54 +0100 | [diff] [blame] | 442 | i915_sw_fence_init(&req->submit, submit_notify); |
| 443 | |
Chris Wilson | fa545cb | 2016-08-04 07:52:35 +0100 | [diff] [blame] | 444 | INIT_LIST_HEAD(&req->active_list); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 445 | req->i915 = dev_priv; |
| 446 | req->engine = engine; |
Chris Wilson | 9a6feaf | 2016-07-20 13:31:50 +0100 | [diff] [blame] | 447 | req->ctx = i915_gem_context_get(ctx); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 448 | |
Chris Wilson | 5a198b8 | 2016-08-09 09:23:34 +0100 | [diff] [blame] | 449 | /* No zalloc, must clear what we need by hand */ |
Chris Wilson | f2d1329 | 2016-10-28 13:58:57 +0100 | [diff] [blame] | 450 | req->global_seqno = 0; |
Chris Wilson | 5a198b8 | 2016-08-09 09:23:34 +0100 | [diff] [blame] | 451 | req->previous_context = NULL; |
| 452 | req->file_priv = NULL; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 453 | req->batch = NULL; |
Chris Wilson | 5a198b8 | 2016-08-09 09:23:34 +0100 | [diff] [blame] | 454 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 455 | /* |
| 456 | * Reserve space in the ring buffer for all the commands required to |
| 457 | * eventually emit this request. This is to guarantee that the |
| 458 | * i915_add_request() call can't fail. Note that the reserve may need |
| 459 | * to be redone if the request is not actually submitted straight |
| 460 | * away, e.g. because a GPU scheduler has deferred it. |
| 461 | */ |
| 462 | req->reserved_space = MIN_SPACE_FOR_ADD_REQUEST; |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 463 | GEM_BUG_ON(req->reserved_space < engine->emit_breadcrumb_sz); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 464 | |
| 465 | if (i915.enable_execlists) |
| 466 | ret = intel_logical_ring_alloc_request_extras(req); |
| 467 | else |
| 468 | ret = intel_ring_alloc_request_extras(req); |
| 469 | if (ret) |
| 470 | goto err_ctx; |
| 471 | |
Chris Wilson | d045446 | 2016-08-15 10:48:40 +0100 | [diff] [blame] | 472 | /* Record the position of the start of the request so that |
| 473 | * should we detect the updated seqno part-way through the |
| 474 | * GPU processing the request, we never over-estimate the |
| 475 | * position of the head. |
| 476 | */ |
| 477 | req->head = req->ring->tail; |
| 478 | |
Chris Wilson | 8e63717 | 2016-08-02 22:50:26 +0100 | [diff] [blame] | 479 | return req; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 480 | |
| 481 | err_ctx: |
Chris Wilson | 9a6feaf | 2016-07-20 13:31:50 +0100 | [diff] [blame] | 482 | i915_gem_context_put(ctx); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 483 | kmem_cache_free(dev_priv->requests, req); |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 484 | err_unreserve: |
| 485 | dev_priv->gt.active_requests--; |
Chris Wilson | 8e63717 | 2016-08-02 22:50:26 +0100 | [diff] [blame] | 486 | return ERR_PTR(ret); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 487 | } |
| 488 | |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 489 | static int |
| 490 | i915_gem_request_await_request(struct drm_i915_gem_request *to, |
| 491 | struct drm_i915_gem_request *from) |
| 492 | { |
Chris Wilson | 85e17f5 | 2016-10-28 13:58:53 +0100 | [diff] [blame] | 493 | int ret; |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 494 | |
| 495 | GEM_BUG_ON(to == from); |
| 496 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 497 | if (to->timeline == from->timeline) |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 498 | return 0; |
| 499 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 500 | if (to->engine == from->engine) { |
| 501 | ret = i915_sw_fence_await_sw_fence_gfp(&to->submit, |
| 502 | &from->submit, |
| 503 | GFP_KERNEL); |
| 504 | return ret < 0 ? ret : 0; |
| 505 | } |
| 506 | |
Chris Wilson | 65e4760 | 2016-10-28 13:58:49 +0100 | [diff] [blame] | 507 | if (!from->global_seqno) { |
| 508 | ret = i915_sw_fence_await_dma_fence(&to->submit, |
| 509 | &from->fence, 0, |
| 510 | GFP_KERNEL); |
| 511 | return ret < 0 ? ret : 0; |
| 512 | } |
| 513 | |
Chris Wilson | 85e17f5 | 2016-10-28 13:58:53 +0100 | [diff] [blame] | 514 | if (from->global_seqno <= to->timeline->sync_seqno[from->engine->id]) |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 515 | return 0; |
| 516 | |
| 517 | trace_i915_gem_ring_sync_to(to, from); |
| 518 | if (!i915.semaphores) { |
Chris Wilson | 0a046a0 | 2016-09-09 14:12:00 +0100 | [diff] [blame] | 519 | if (!i915_spin_request(from, TASK_INTERRUPTIBLE, 2)) { |
| 520 | ret = i915_sw_fence_await_dma_fence(&to->submit, |
| 521 | &from->fence, 0, |
| 522 | GFP_KERNEL); |
| 523 | if (ret < 0) |
| 524 | return ret; |
| 525 | } |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 526 | } else { |
| 527 | ret = to->engine->semaphore.sync_to(to, from); |
| 528 | if (ret) |
| 529 | return ret; |
| 530 | } |
| 531 | |
Chris Wilson | 85e17f5 | 2016-10-28 13:58:53 +0100 | [diff] [blame] | 532 | to->timeline->sync_seqno[from->engine->id] = from->global_seqno; |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 533 | return 0; |
| 534 | } |
| 535 | |
Chris Wilson | b52992c | 2016-10-28 13:58:24 +0100 | [diff] [blame] | 536 | int |
| 537 | i915_gem_request_await_dma_fence(struct drm_i915_gem_request *req, |
| 538 | struct dma_fence *fence) |
| 539 | { |
| 540 | struct dma_fence_array *array; |
| 541 | int ret; |
| 542 | int i; |
| 543 | |
| 544 | if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) |
| 545 | return 0; |
| 546 | |
| 547 | if (dma_fence_is_i915(fence)) |
| 548 | return i915_gem_request_await_request(req, to_request(fence)); |
| 549 | |
| 550 | if (!dma_fence_is_array(fence)) { |
| 551 | ret = i915_sw_fence_await_dma_fence(&req->submit, |
| 552 | fence, I915_FENCE_TIMEOUT, |
| 553 | GFP_KERNEL); |
| 554 | return ret < 0 ? ret : 0; |
| 555 | } |
| 556 | |
| 557 | /* Note that if the fence-array was created in signal-on-any mode, |
| 558 | * we should *not* decompose it into its individual fences. However, |
| 559 | * we don't currently store which mode the fence-array is operating |
| 560 | * in. Fortunately, the only user of signal-on-any is private to |
| 561 | * amdgpu and we should not see any incoming fence-array from |
| 562 | * sync-file being in signal-on-any mode. |
| 563 | */ |
| 564 | |
| 565 | array = to_dma_fence_array(fence); |
| 566 | for (i = 0; i < array->num_fences; i++) { |
| 567 | struct dma_fence *child = array->fences[i]; |
| 568 | |
| 569 | if (dma_fence_is_i915(child)) |
| 570 | ret = i915_gem_request_await_request(req, |
| 571 | to_request(child)); |
| 572 | else |
| 573 | ret = i915_sw_fence_await_dma_fence(&req->submit, |
| 574 | child, I915_FENCE_TIMEOUT, |
| 575 | GFP_KERNEL); |
| 576 | if (ret < 0) |
| 577 | return ret; |
| 578 | } |
| 579 | |
| 580 | return 0; |
| 581 | } |
| 582 | |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 583 | /** |
| 584 | * i915_gem_request_await_object - set this request to (async) wait upon a bo |
| 585 | * |
| 586 | * @to: request we are wishing to use |
| 587 | * @obj: object which may be in use on another ring. |
| 588 | * |
| 589 | * This code is meant to abstract object synchronization with the GPU. |
| 590 | * Conceptually we serialise writes between engines inside the GPU. |
| 591 | * We only allow one engine to write into a buffer at any time, but |
| 592 | * multiple readers. To ensure each has a coherent view of memory, we must: |
| 593 | * |
| 594 | * - If there is an outstanding write request to the object, the new |
| 595 | * request must wait for it to complete (either CPU or in hw, requests |
| 596 | * on the same ring will be naturally ordered). |
| 597 | * |
| 598 | * - If we are a write request (pending_write_domain is set), the new |
| 599 | * request must wait for outstanding read requests to complete. |
| 600 | * |
| 601 | * Returns 0 if successful, else propagates up the lower layer error. |
| 602 | */ |
| 603 | int |
| 604 | i915_gem_request_await_object(struct drm_i915_gem_request *to, |
| 605 | struct drm_i915_gem_object *obj, |
| 606 | bool write) |
| 607 | { |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 608 | struct dma_fence *excl; |
| 609 | int ret = 0; |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 610 | |
| 611 | if (write) { |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 612 | struct dma_fence **shared; |
| 613 | unsigned int count, i; |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 614 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 615 | ret = reservation_object_get_fences_rcu(obj->resv, |
| 616 | &excl, &count, &shared); |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 617 | if (ret) |
| 618 | return ret; |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 619 | |
| 620 | for (i = 0; i < count; i++) { |
| 621 | ret = i915_gem_request_await_dma_fence(to, shared[i]); |
| 622 | if (ret) |
| 623 | break; |
| 624 | |
| 625 | dma_fence_put(shared[i]); |
| 626 | } |
| 627 | |
| 628 | for (; i < count; i++) |
| 629 | dma_fence_put(shared[i]); |
| 630 | kfree(shared); |
| 631 | } else { |
| 632 | excl = reservation_object_get_excl_rcu(obj->resv); |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 633 | } |
| 634 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 635 | if (excl) { |
| 636 | if (ret == 0) |
| 637 | ret = i915_gem_request_await_dma_fence(to, excl); |
| 638 | |
| 639 | dma_fence_put(excl); |
| 640 | } |
| 641 | |
| 642 | return ret; |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 643 | } |
| 644 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 645 | static void i915_gem_mark_busy(const struct intel_engine_cs *engine) |
| 646 | { |
| 647 | struct drm_i915_private *dev_priv = engine->i915; |
| 648 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 649 | if (dev_priv->gt.awake) |
| 650 | return; |
| 651 | |
| 652 | intel_runtime_pm_get_noresume(dev_priv); |
| 653 | dev_priv->gt.awake = true; |
| 654 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 655 | intel_enable_gt_powersave(dev_priv); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 656 | i915_update_gfx_val(dev_priv); |
| 657 | if (INTEL_GEN(dev_priv) >= 6) |
| 658 | gen6_rps_busy(dev_priv); |
| 659 | |
| 660 | queue_delayed_work(dev_priv->wq, |
| 661 | &dev_priv->gt.retire_work, |
| 662 | round_jiffies_up_relative(HZ)); |
| 663 | } |
| 664 | |
| 665 | /* |
| 666 | * NB: This function is not allowed to fail. Doing so would mean the the |
| 667 | * request is not being tracked for completion but the work itself is |
| 668 | * going to happen on the hardware. This would be a Bad Thing(tm). |
| 669 | */ |
Chris Wilson | 17f298cf | 2016-08-10 13:41:46 +0100 | [diff] [blame] | 670 | void __i915_add_request(struct drm_i915_gem_request *request, bool flush_caches) |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 671 | { |
Chris Wilson | 95b2ab5 | 2016-08-15 10:48:46 +0100 | [diff] [blame] | 672 | struct intel_engine_cs *engine = request->engine; |
| 673 | struct intel_ring *ring = request->ring; |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 674 | struct intel_timeline *timeline = request->timeline; |
Chris Wilson | 0a046a0 | 2016-09-09 14:12:00 +0100 | [diff] [blame] | 675 | struct drm_i915_gem_request *prev; |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 676 | int err; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 677 | |
Chris Wilson | 4c7d62c | 2016-10-28 13:58:32 +0100 | [diff] [blame] | 678 | lockdep_assert_held(&request->i915->drm.struct_mutex); |
Chris Wilson | 0f25dff | 2016-09-09 14:11:55 +0100 | [diff] [blame] | 679 | trace_i915_gem_request_add(request); |
| 680 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 681 | /* |
| 682 | * To ensure that this call will not fail, space for its emissions |
| 683 | * should already have been reserved in the ring buffer. Let the ring |
| 684 | * know that it is time to use that space up. |
| 685 | */ |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 686 | request->reserved_space = 0; |
| 687 | |
| 688 | /* |
| 689 | * Emit any outstanding flushes - execbuf can fail to emit the flush |
| 690 | * after having emitted the batchbuffer command. Hence we need to fix |
| 691 | * things up similar to emitting the lazy request. The difference here |
| 692 | * is that the flush _must_ happen before the next request, no matter |
| 693 | * what. |
| 694 | */ |
| 695 | if (flush_caches) { |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 696 | err = engine->emit_flush(request, EMIT_FLUSH); |
Chris Wilson | c7fe7d2 | 2016-08-02 22:50:24 +0100 | [diff] [blame] | 697 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 698 | /* Not allowed to fail! */ |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 699 | WARN(err, "engine->emit_flush() failed: %d!\n", err); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 700 | } |
| 701 | |
Chris Wilson | d045446 | 2016-08-15 10:48:40 +0100 | [diff] [blame] | 702 | /* Record the position of the start of the breadcrumb so that |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 703 | * should we detect the updated seqno part-way through the |
| 704 | * GPU processing the request, we never over-estimate the |
Chris Wilson | d045446 | 2016-08-15 10:48:40 +0100 | [diff] [blame] | 705 | * position of the ring's HEAD. |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 706 | */ |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 707 | err = intel_ring_begin(request, engine->emit_breadcrumb_sz); |
| 708 | GEM_BUG_ON(err); |
Chris Wilson | ba76d91 | 2016-08-02 22:50:28 +0100 | [diff] [blame] | 709 | request->postfix = ring->tail; |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 710 | ring->tail += engine->emit_breadcrumb_sz * sizeof(u32); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 711 | |
Chris Wilson | 0f25dff | 2016-09-09 14:11:55 +0100 | [diff] [blame] | 712 | /* Seal the request and mark it as pending execution. Note that |
| 713 | * we may inspect this state, without holding any locks, during |
| 714 | * hangcheck. Hence we apply the barrier to ensure that we do not |
| 715 | * see a more recent value in the hws than we are tracking. |
| 716 | */ |
Chris Wilson | 0a046a0 | 2016-09-09 14:12:00 +0100 | [diff] [blame] | 717 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 718 | prev = i915_gem_active_raw(&timeline->last_request, |
Chris Wilson | 0a046a0 | 2016-09-09 14:12:00 +0100 | [diff] [blame] | 719 | &request->i915->drm.struct_mutex); |
| 720 | if (prev) |
| 721 | i915_sw_fence_await_sw_fence(&request->submit, &prev->submit, |
| 722 | &request->submitq); |
| 723 | |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 724 | spin_lock_irq(&timeline->lock); |
Chris Wilson | f2d1329 | 2016-10-28 13:58:57 +0100 | [diff] [blame] | 725 | list_add_tail(&request->link, &timeline->requests); |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 726 | spin_unlock_irq(&timeline->lock); |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 727 | |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 728 | GEM_BUG_ON(i915_seqno_passed(timeline->last_submitted_seqno, |
| 729 | request->fence.seqno)); |
| 730 | |
| 731 | timeline->last_submitted_seqno = request->fence.seqno; |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 732 | i915_gem_active_set(&timeline->last_request, request); |
Chris Wilson | f2d1329 | 2016-10-28 13:58:57 +0100 | [diff] [blame] | 733 | |
Chris Wilson | 0f25dff | 2016-09-09 14:11:55 +0100 | [diff] [blame] | 734 | list_add_tail(&request->ring_link, &ring->request_list); |
Chris Wilson | f2d1329 | 2016-10-28 13:58:57 +0100 | [diff] [blame] | 735 | request->emitted_jiffies = jiffies; |
Chris Wilson | 0f25dff | 2016-09-09 14:11:55 +0100 | [diff] [blame] | 736 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 737 | i915_gem_mark_busy(engine); |
Chris Wilson | 5590af3 | 2016-09-09 14:11:54 +0100 | [diff] [blame] | 738 | |
| 739 | local_bh_disable(); |
| 740 | i915_sw_fence_commit(&request->submit); |
| 741 | local_bh_enable(); /* Kick the execlists tasklet if just scheduled */ |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 742 | } |
| 743 | |
Chris Wilson | 221fe79 | 2016-09-09 14:11:51 +0100 | [diff] [blame] | 744 | static void reset_wait_queue(wait_queue_head_t *q, wait_queue_t *wait) |
| 745 | { |
| 746 | unsigned long flags; |
| 747 | |
| 748 | spin_lock_irqsave(&q->lock, flags); |
| 749 | if (list_empty(&wait->task_list)) |
| 750 | __add_wait_queue(q, wait); |
| 751 | spin_unlock_irqrestore(&q->lock, flags); |
| 752 | } |
| 753 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 754 | static unsigned long local_clock_us(unsigned int *cpu) |
| 755 | { |
| 756 | unsigned long t; |
| 757 | |
| 758 | /* Cheaply and approximately convert from nanoseconds to microseconds. |
| 759 | * The result and subsequent calculations are also defined in the same |
| 760 | * approximate microseconds units. The principal source of timing |
| 761 | * error here is from the simple truncation. |
| 762 | * |
| 763 | * Note that local_clock() is only defined wrt to the current CPU; |
| 764 | * the comparisons are no longer valid if we switch CPUs. Instead of |
| 765 | * blocking preemption for the entire busywait, we can detect the CPU |
| 766 | * switch and use that as indicator of system load and a reason to |
| 767 | * stop busywaiting, see busywait_stop(). |
| 768 | */ |
| 769 | *cpu = get_cpu(); |
| 770 | t = local_clock() >> 10; |
| 771 | put_cpu(); |
| 772 | |
| 773 | return t; |
| 774 | } |
| 775 | |
| 776 | static bool busywait_stop(unsigned long timeout, unsigned int cpu) |
| 777 | { |
| 778 | unsigned int this_cpu; |
| 779 | |
| 780 | if (time_after(local_clock_us(&this_cpu), timeout)) |
| 781 | return true; |
| 782 | |
| 783 | return this_cpu != cpu; |
| 784 | } |
| 785 | |
| 786 | bool __i915_spin_request(const struct drm_i915_gem_request *req, |
| 787 | int state, unsigned long timeout_us) |
| 788 | { |
| 789 | unsigned int cpu; |
| 790 | |
| 791 | /* When waiting for high frequency requests, e.g. during synchronous |
| 792 | * rendering split between the CPU and GPU, the finite amount of time |
| 793 | * required to set up the irq and wait upon it limits the response |
| 794 | * rate. By busywaiting on the request completion for a short while we |
| 795 | * can service the high frequency waits as quick as possible. However, |
| 796 | * if it is a slow request, we want to sleep as quickly as possible. |
| 797 | * The tradeoff between waiting and sleeping is roughly the time it |
| 798 | * takes to sleep on a request, on the order of a microsecond. |
| 799 | */ |
| 800 | |
| 801 | timeout_us += local_clock_us(&cpu); |
| 802 | do { |
Chris Wilson | 65e4760 | 2016-10-28 13:58:49 +0100 | [diff] [blame] | 803 | if (__i915_gem_request_completed(req)) |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 804 | return true; |
| 805 | |
| 806 | if (signal_pending_state(state, current)) |
| 807 | break; |
| 808 | |
| 809 | if (busywait_stop(timeout_us, cpu)) |
| 810 | break; |
| 811 | |
| 812 | cpu_relax_lowlatency(); |
| 813 | } while (!need_resched()); |
| 814 | |
| 815 | return false; |
| 816 | } |
| 817 | |
Chris Wilson | 4680816b | 2016-10-28 13:58:48 +0100 | [diff] [blame] | 818 | static long |
| 819 | __i915_request_wait_for_submit(struct drm_i915_gem_request *request, |
| 820 | unsigned int flags, |
| 821 | long timeout) |
| 822 | { |
| 823 | const int state = flags & I915_WAIT_INTERRUPTIBLE ? |
| 824 | TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE; |
| 825 | wait_queue_head_t *q = &request->i915->gpu_error.wait_queue; |
| 826 | DEFINE_WAIT(reset); |
| 827 | DEFINE_WAIT(wait); |
| 828 | |
| 829 | if (flags & I915_WAIT_LOCKED) |
| 830 | add_wait_queue(q, &reset); |
| 831 | |
| 832 | do { |
| 833 | prepare_to_wait(&request->submit.wait, &wait, state); |
| 834 | |
| 835 | if (i915_sw_fence_done(&request->submit)) |
| 836 | break; |
| 837 | |
| 838 | if (flags & I915_WAIT_LOCKED && |
| 839 | i915_reset_in_progress(&request->i915->gpu_error)) { |
| 840 | __set_current_state(TASK_RUNNING); |
| 841 | i915_reset(request->i915); |
| 842 | reset_wait_queue(q, &reset); |
| 843 | continue; |
| 844 | } |
| 845 | |
| 846 | if (signal_pending_state(state, current)) { |
| 847 | timeout = -ERESTARTSYS; |
| 848 | break; |
| 849 | } |
| 850 | |
| 851 | timeout = io_schedule_timeout(timeout); |
| 852 | } while (timeout); |
| 853 | finish_wait(&request->submit.wait, &wait); |
| 854 | |
| 855 | if (flags & I915_WAIT_LOCKED) |
| 856 | remove_wait_queue(q, &reset); |
| 857 | |
| 858 | return timeout; |
| 859 | } |
| 860 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 861 | /** |
Chris Wilson | 776f323 | 2016-08-04 07:52:40 +0100 | [diff] [blame] | 862 | * i915_wait_request - wait until execution of request has finished |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 863 | * @req: the request to wait upon |
Chris Wilson | ea746f3 | 2016-09-09 14:11:49 +0100 | [diff] [blame] | 864 | * @flags: how to wait |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 865 | * @timeout: how long to wait in jiffies |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 866 | * |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 867 | * i915_wait_request() waits for the request to be completed, for a |
| 868 | * maximum of @timeout jiffies (with MAX_SCHEDULE_TIMEOUT implying an |
| 869 | * unbounded wait). |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 870 | * |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 871 | * If the caller holds the struct_mutex, the caller must pass I915_WAIT_LOCKED |
| 872 | * in via the flags, and vice versa if the struct_mutex is not held, the caller |
| 873 | * must not specify that the wait is locked. |
| 874 | * |
| 875 | * Returns the remaining time (in jiffies) if the request completed, which may |
| 876 | * be zero or -ETIME if the request is unfinished after the timeout expires. |
| 877 | * May return -EINTR is called with I915_WAIT_INTERRUPTIBLE and a signal is |
| 878 | * pending before the request completes. |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 879 | */ |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 880 | long i915_wait_request(struct drm_i915_gem_request *req, |
| 881 | unsigned int flags, |
| 882 | long timeout) |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 883 | { |
Chris Wilson | ea746f3 | 2016-09-09 14:11:49 +0100 | [diff] [blame] | 884 | const int state = flags & I915_WAIT_INTERRUPTIBLE ? |
| 885 | TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 886 | DEFINE_WAIT(reset); |
| 887 | struct intel_wait wait; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 888 | |
| 889 | might_sleep(); |
Chris Wilson | 22dd3bb | 2016-09-09 14:11:50 +0100 | [diff] [blame] | 890 | #if IS_ENABLED(CONFIG_LOCKDEP) |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 891 | GEM_BUG_ON(debug_locks && |
| 892 | !!lockdep_is_held(&req->i915->drm.struct_mutex) != |
Chris Wilson | 22dd3bb | 2016-09-09 14:11:50 +0100 | [diff] [blame] | 893 | !!(flags & I915_WAIT_LOCKED)); |
| 894 | #endif |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 895 | GEM_BUG_ON(timeout < 0); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 896 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 897 | if (i915_gem_request_completed(req)) |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 898 | return timeout; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 899 | |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 900 | if (!timeout) |
| 901 | return -ETIME; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 902 | |
| 903 | trace_i915_gem_request_wait_begin(req); |
| 904 | |
Chris Wilson | 4680816b | 2016-10-28 13:58:48 +0100 | [diff] [blame] | 905 | if (!i915_sw_fence_done(&req->submit)) { |
| 906 | timeout = __i915_request_wait_for_submit(req, flags, timeout); |
| 907 | if (timeout < 0) |
| 908 | goto complete; |
| 909 | |
| 910 | GEM_BUG_ON(!i915_sw_fence_done(&req->submit)); |
| 911 | } |
Chris Wilson | 65e4760 | 2016-10-28 13:58:49 +0100 | [diff] [blame] | 912 | GEM_BUG_ON(!req->global_seqno); |
Chris Wilson | 4680816b | 2016-10-28 13:58:48 +0100 | [diff] [blame] | 913 | |
Daniel Vetter | 437c308 | 2016-08-05 18:11:24 +0200 | [diff] [blame] | 914 | /* Optimistic short spin before touching IRQs */ |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 915 | if (i915_spin_request(req, state, 5)) |
| 916 | goto complete; |
| 917 | |
| 918 | set_current_state(state); |
Chris Wilson | 22dd3bb | 2016-09-09 14:11:50 +0100 | [diff] [blame] | 919 | if (flags & I915_WAIT_LOCKED) |
| 920 | add_wait_queue(&req->i915->gpu_error.wait_queue, &reset); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 921 | |
Chris Wilson | 65e4760 | 2016-10-28 13:58:49 +0100 | [diff] [blame] | 922 | intel_wait_init(&wait, req->global_seqno); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 923 | if (intel_engine_add_wait(req->engine, &wait)) |
| 924 | /* In order to check that we haven't missed the interrupt |
| 925 | * as we enabled it, we need to kick ourselves to do a |
| 926 | * coherent check on the seqno before we sleep. |
| 927 | */ |
| 928 | goto wakeup; |
| 929 | |
| 930 | for (;;) { |
| 931 | if (signal_pending_state(state, current)) { |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 932 | timeout = -ERESTARTSYS; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 933 | break; |
| 934 | } |
| 935 | |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 936 | if (!timeout) { |
| 937 | timeout = -ETIME; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 938 | break; |
| 939 | } |
| 940 | |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 941 | timeout = io_schedule_timeout(timeout); |
| 942 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 943 | if (intel_wait_complete(&wait)) |
| 944 | break; |
| 945 | |
| 946 | set_current_state(state); |
| 947 | |
| 948 | wakeup: |
| 949 | /* Carefully check if the request is complete, giving time |
| 950 | * for the seqno to be visible following the interrupt. |
| 951 | * We also have to check in case we are kicked by the GPU |
| 952 | * reset in order to drop the struct_mutex. |
| 953 | */ |
| 954 | if (__i915_request_irq_complete(req)) |
| 955 | break; |
| 956 | |
Chris Wilson | 221fe79 | 2016-09-09 14:11:51 +0100 | [diff] [blame] | 957 | /* If the GPU is hung, and we hold the lock, reset the GPU |
| 958 | * and then check for completion. On a full reset, the engine's |
| 959 | * HW seqno will be advanced passed us and we are complete. |
| 960 | * If we do a partial reset, we have to wait for the GPU to |
| 961 | * resume and update the breadcrumb. |
| 962 | * |
| 963 | * If we don't hold the mutex, we can just wait for the worker |
| 964 | * to come along and update the breadcrumb (either directly |
| 965 | * itself, or indirectly by recovering the GPU). |
| 966 | */ |
| 967 | if (flags & I915_WAIT_LOCKED && |
| 968 | i915_reset_in_progress(&req->i915->gpu_error)) { |
| 969 | __set_current_state(TASK_RUNNING); |
| 970 | i915_reset(req->i915); |
| 971 | reset_wait_queue(&req->i915->gpu_error.wait_queue, |
| 972 | &reset); |
| 973 | continue; |
| 974 | } |
| 975 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 976 | /* Only spin if we know the GPU is processing this request */ |
| 977 | if (i915_spin_request(req, state, 2)) |
| 978 | break; |
| 979 | } |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 980 | |
| 981 | intel_engine_remove_wait(req->engine, &wait); |
Chris Wilson | 22dd3bb | 2016-09-09 14:11:50 +0100 | [diff] [blame] | 982 | if (flags & I915_WAIT_LOCKED) |
| 983 | remove_wait_queue(&req->i915->gpu_error.wait_queue, &reset); |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 984 | __set_current_state(TASK_RUNNING); |
Chris Wilson | 22dd3bb | 2016-09-09 14:11:50 +0100 | [diff] [blame] | 985 | |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 986 | complete: |
| 987 | trace_i915_gem_request_wait_end(req); |
| 988 | |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 989 | return timeout; |
Chris Wilson | 05235c5 | 2016-07-20 09:21:08 +0100 | [diff] [blame] | 990 | } |
Chris Wilson | 4b8de8e | 2016-08-04 07:52:42 +0100 | [diff] [blame] | 991 | |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 992 | static void engine_retire_requests(struct intel_engine_cs *engine) |
Chris Wilson | 4b8de8e | 2016-08-04 07:52:42 +0100 | [diff] [blame] | 993 | { |
| 994 | struct drm_i915_gem_request *request, *next; |
| 995 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 996 | list_for_each_entry_safe(request, next, |
| 997 | &engine->timeline->requests, link) { |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 998 | if (!__i915_gem_request_completed(request)) |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 999 | return; |
Chris Wilson | 4b8de8e | 2016-08-04 07:52:42 +0100 | [diff] [blame] | 1000 | |
| 1001 | i915_gem_request_retire(request); |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | void i915_gem_retire_requests(struct drm_i915_private *dev_priv) |
| 1006 | { |
| 1007 | struct intel_engine_cs *engine; |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 1008 | enum intel_engine_id id; |
Chris Wilson | 4b8de8e | 2016-08-04 07:52:42 +0100 | [diff] [blame] | 1009 | |
| 1010 | lockdep_assert_held(&dev_priv->drm.struct_mutex); |
| 1011 | |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 1012 | if (!dev_priv->gt.active_requests) |
Chris Wilson | 4b8de8e | 2016-08-04 07:52:42 +0100 | [diff] [blame] | 1013 | return; |
| 1014 | |
| 1015 | GEM_BUG_ON(!dev_priv->gt.awake); |
| 1016 | |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 1017 | for_each_engine(engine, dev_priv, id) |
| 1018 | engine_retire_requests(engine); |
Chris Wilson | 4b8de8e | 2016-08-04 07:52:42 +0100 | [diff] [blame] | 1019 | |
Chris Wilson | 28176ef | 2016-10-28 13:58:56 +0100 | [diff] [blame] | 1020 | if (!dev_priv->gt.active_requests) |
Imre Deak | 5bd11a3 | 2016-11-07 11:20:02 +0200 | [diff] [blame] | 1021 | mod_delayed_work(dev_priv->wq, |
| 1022 | &dev_priv->gt.idle_work, |
| 1023 | msecs_to_jiffies(100)); |
Chris Wilson | 4b8de8e | 2016-08-04 07:52:42 +0100 | [diff] [blame] | 1024 | } |