Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 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 | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 25 | #include <linux/kthread.h> |
Ingo Molnar | ae7e81c | 2017-02-01 18:07:51 +0100 | [diff] [blame] | 26 | #include <uapi/linux/sched/types.h> |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 27 | |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 28 | #include "i915_drv.h" |
| 29 | |
Chris Wilson | b92326a | 2017-12-09 12:47:10 +0000 | [diff] [blame] | 30 | #ifdef CONFIG_SMP |
| 31 | #define task_asleep(tsk) ((tsk)->state & TASK_NORMAL && !(tsk)->on_cpu) |
| 32 | #else |
| 33 | #define task_asleep(tsk) ((tsk)->state & TASK_NORMAL) |
| 34 | #endif |
| 35 | |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 36 | static unsigned int __intel_breadcrumbs_wakeup(struct intel_breadcrumbs *b) |
Chris Wilson | 8d769ea | 2017-02-27 20:58:47 +0000 | [diff] [blame] | 37 | { |
Chris Wilson | 56299fb | 2017-02-27 20:58:48 +0000 | [diff] [blame] | 38 | struct intel_wait *wait; |
Chris Wilson | 8d769ea | 2017-02-27 20:58:47 +0000 | [diff] [blame] | 39 | unsigned int result = 0; |
| 40 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 41 | lockdep_assert_held(&b->irq_lock); |
| 42 | |
| 43 | wait = b->irq_wait; |
Chris Wilson | 56299fb | 2017-02-27 20:58:48 +0000 | [diff] [blame] | 44 | if (wait) { |
Chris Wilson | b92326a | 2017-12-09 12:47:10 +0000 | [diff] [blame] | 45 | /* |
| 46 | * N.B. Since task_asleep() and ttwu are not atomic, the |
| 47 | * waiter may actually go to sleep after the check, causing |
| 48 | * us to suppress a valid wakeup. We prefer to reduce the |
| 49 | * number of false positive missed_breadcrumb() warnings |
| 50 | * at the expense of a few false negatives, as it it easy |
| 51 | * to trigger a false positive under heavy load. Enough |
| 52 | * signal should remain from genuine missed_breadcrumb() |
| 53 | * for us to detect in CI. |
| 54 | */ |
| 55 | bool was_asleep = task_asleep(wait->tsk); |
| 56 | |
Chris Wilson | 8d769ea | 2017-02-27 20:58:47 +0000 | [diff] [blame] | 57 | result = ENGINE_WAKEUP_WAITER; |
Chris Wilson | b92326a | 2017-12-09 12:47:10 +0000 | [diff] [blame] | 58 | if (wake_up_process(wait->tsk) && was_asleep) |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 59 | result |= ENGINE_WAKEUP_ASLEEP; |
Chris Wilson | 8d769ea | 2017-02-27 20:58:47 +0000 | [diff] [blame] | 60 | } |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 61 | |
| 62 | return result; |
| 63 | } |
| 64 | |
| 65 | unsigned int intel_engine_wakeup(struct intel_engine_cs *engine) |
| 66 | { |
| 67 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
Chris Wilson | 467221b | 2017-03-20 14:31:33 +0000 | [diff] [blame] | 68 | unsigned long flags; |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 69 | unsigned int result; |
| 70 | |
Chris Wilson | 467221b | 2017-03-20 14:31:33 +0000 | [diff] [blame] | 71 | spin_lock_irqsave(&b->irq_lock, flags); |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 72 | result = __intel_breadcrumbs_wakeup(b); |
Chris Wilson | 467221b | 2017-03-20 14:31:33 +0000 | [diff] [blame] | 73 | spin_unlock_irqrestore(&b->irq_lock, flags); |
Chris Wilson | 8d769ea | 2017-02-27 20:58:47 +0000 | [diff] [blame] | 74 | |
| 75 | return result; |
| 76 | } |
| 77 | |
Chris Wilson | 2246bea | 2017-02-17 15:13:00 +0000 | [diff] [blame] | 78 | static unsigned long wait_timeout(void) |
| 79 | { |
| 80 | return round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES); |
| 81 | } |
| 82 | |
Chris Wilson | 80166e40 | 2017-02-28 08:50:18 +0000 | [diff] [blame] | 83 | static noinline void missed_breadcrumb(struct intel_engine_cs *engine) |
| 84 | { |
Chris Wilson | 832265d | 2017-12-08 01:23:01 +0000 | [diff] [blame] | 85 | if (drm_debug & DRM_UT_DRIVER) { |
| 86 | struct drm_printer p = drm_debug_printer(__func__); |
| 87 | |
| 88 | intel_engine_dump(engine, &p, |
| 89 | "%s missed breadcrumb at %pS\n", |
| 90 | engine->name, __builtin_return_address(0)); |
| 91 | } |
Chris Wilson | 80166e40 | 2017-02-28 08:50:18 +0000 | [diff] [blame] | 92 | |
| 93 | set_bit(engine->id, &engine->i915->gpu_error.missed_irq_rings); |
| 94 | } |
| 95 | |
Kees Cook | 39cbf2a | 2017-10-17 09:53:04 +0300 | [diff] [blame] | 96 | static void intel_breadcrumbs_hangcheck(struct timer_list *t) |
Chris Wilson | 83348ba | 2016-08-09 17:47:51 +0100 | [diff] [blame] | 97 | { |
Chris Wilson | b92326a | 2017-12-09 12:47:10 +0000 | [diff] [blame] | 98 | struct intel_engine_cs *engine = |
| 99 | from_timer(engine, t, breadcrumbs.hangcheck); |
Chris Wilson | 83348ba | 2016-08-09 17:47:51 +0100 | [diff] [blame] | 100 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 101 | |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 102 | if (!b->irq_armed) |
Chris Wilson | 83348ba | 2016-08-09 17:47:51 +0100 | [diff] [blame] | 103 | return; |
| 104 | |
Chris Wilson | 2246bea | 2017-02-17 15:13:00 +0000 | [diff] [blame] | 105 | if (b->hangcheck_interrupts != atomic_read(&engine->irq_count)) { |
| 106 | b->hangcheck_interrupts = atomic_read(&engine->irq_count); |
| 107 | mod_timer(&b->hangcheck, wait_timeout()); |
Chris Wilson | 83348ba | 2016-08-09 17:47:51 +0100 | [diff] [blame] | 108 | return; |
| 109 | } |
| 110 | |
Chris Wilson | a6b0a141 | 2017-03-15 22:22:59 +0000 | [diff] [blame] | 111 | /* We keep the hangcheck timer alive until we disarm the irq, even |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 112 | * if there are no waiters at present. |
| 113 | * |
| 114 | * If the waiter was currently running, assume it hasn't had a chance |
Chris Wilson | 8998567 | 2017-02-17 15:13:02 +0000 | [diff] [blame] | 115 | * to process the pending interrupt (e.g, low priority task on a loaded |
| 116 | * system) and wait until it sleeps before declaring a missed interrupt. |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 117 | * |
| 118 | * If the waiter was asleep (and not even pending a wakeup), then we |
| 119 | * must have missed an interrupt as the GPU has stopped advancing |
| 120 | * but we still have a waiter. Assuming all batches complete within |
| 121 | * DRM_I915_HANGCHECK_JIFFIES [1.5s]! |
Chris Wilson | 8998567 | 2017-02-17 15:13:02 +0000 | [diff] [blame] | 122 | */ |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 123 | if (intel_engine_wakeup(engine) & ENGINE_WAKEUP_ASLEEP) { |
Chris Wilson | 80166e40 | 2017-02-28 08:50:18 +0000 | [diff] [blame] | 124 | missed_breadcrumb(engine); |
Chris Wilson | b92326a | 2017-12-09 12:47:10 +0000 | [diff] [blame] | 125 | mod_timer(&b->fake_irq, jiffies + 1); |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 126 | } else { |
Chris Wilson | 8998567 | 2017-02-17 15:13:02 +0000 | [diff] [blame] | 127 | mod_timer(&b->hangcheck, wait_timeout()); |
Chris Wilson | 8998567 | 2017-02-17 15:13:02 +0000 | [diff] [blame] | 128 | } |
Chris Wilson | 83348ba | 2016-08-09 17:47:51 +0100 | [diff] [blame] | 129 | } |
| 130 | |
Kees Cook | 39cbf2a | 2017-10-17 09:53:04 +0300 | [diff] [blame] | 131 | static void intel_breadcrumbs_fake_irq(struct timer_list *t) |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 132 | { |
Kees Cook | 39cbf2a | 2017-10-17 09:53:04 +0300 | [diff] [blame] | 133 | struct intel_engine_cs *engine = from_timer(engine, t, |
| 134 | breadcrumbs.fake_irq); |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 135 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 136 | |
Chris Wilson | a6b0a141 | 2017-03-15 22:22:59 +0000 | [diff] [blame] | 137 | /* The timer persists in case we cannot enable interrupts, |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 138 | * or if we have previously seen seqno/interrupt incoherency |
Chris Wilson | a6b0a141 | 2017-03-15 22:22:59 +0000 | [diff] [blame] | 139 | * ("missed interrupt" syndrome, better known as a "missed breadcrumb"). |
| 140 | * Here the worker will wake up every jiffie in order to kick the |
| 141 | * oldest waiter to do the coherent seqno check. |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 142 | */ |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 143 | |
Tvrtko Ursulin | a9e6493 | 2017-03-06 15:03:20 +0000 | [diff] [blame] | 144 | spin_lock_irq(&b->irq_lock); |
Chris Wilson | bcbd5c3 | 2017-10-25 15:39:42 +0100 | [diff] [blame] | 145 | if (b->irq_armed && !__intel_breadcrumbs_wakeup(b)) |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 146 | __intel_engine_disarm_breadcrumbs(engine); |
Tvrtko Ursulin | a9e6493 | 2017-03-06 15:03:20 +0000 | [diff] [blame] | 147 | spin_unlock_irq(&b->irq_lock); |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 148 | if (!b->irq_armed) |
Chris Wilson | 19d0a57 | 2017-02-27 20:58:49 +0000 | [diff] [blame] | 149 | return; |
| 150 | |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 151 | mod_timer(&b->fake_irq, jiffies + 1); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static void irq_enable(struct intel_engine_cs *engine) |
| 155 | { |
Chris Wilson | c16c4ba | 2017-11-07 10:20:03 +0000 | [diff] [blame] | 156 | /* |
| 157 | * FIXME: Ideally we want this on the API boundary, but for the |
| 158 | * sake of testing with mock breadcrumbs (no HW so unable to |
| 159 | * enable irqs) we place it deep within the bowels, at the point |
| 160 | * of no return. |
| 161 | */ |
| 162 | GEM_BUG_ON(!intel_irqs_enabled(engine->i915)); |
| 163 | |
Chris Wilson | 3d5564e | 2016-07-01 17:23:23 +0100 | [diff] [blame] | 164 | /* Enabling the IRQ may miss the generation of the interrupt, but |
| 165 | * we still need to force the barrier before reading the seqno, |
| 166 | * just in case. |
| 167 | */ |
Chris Wilson | 538b257 | 2017-01-24 15:18:05 +0000 | [diff] [blame] | 168 | set_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted); |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 169 | |
Chris Wilson | f6168e3 | 2016-10-28 13:58:55 +0100 | [diff] [blame] | 170 | /* Caller disables interrupts */ |
Tvrtko Ursulin | d4ccceb | 2018-03-02 18:14:56 +0200 | [diff] [blame^] | 171 | if (engine->irq_enable) { |
| 172 | spin_lock(&engine->i915->irq_lock); |
| 173 | engine->irq_enable(engine); |
| 174 | spin_unlock(&engine->i915->irq_lock); |
| 175 | } |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static void irq_disable(struct intel_engine_cs *engine) |
| 179 | { |
Chris Wilson | f6168e3 | 2016-10-28 13:58:55 +0100 | [diff] [blame] | 180 | /* Caller disables interrupts */ |
Tvrtko Ursulin | d4ccceb | 2018-03-02 18:14:56 +0200 | [diff] [blame^] | 181 | if (engine->irq_disable) { |
| 182 | spin_lock(&engine->i915->irq_lock); |
| 183 | engine->irq_disable(engine); |
| 184 | spin_unlock(&engine->i915->irq_lock); |
| 185 | } |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 186 | } |
| 187 | |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 188 | void __intel_engine_disarm_breadcrumbs(struct intel_engine_cs *engine) |
| 189 | { |
| 190 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 191 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 192 | lockdep_assert_held(&b->irq_lock); |
Chris Wilson | e1c0c91 | 2017-03-06 09:29:15 +0000 | [diff] [blame] | 193 | GEM_BUG_ON(b->irq_wait); |
Chris Wilson | bcbd5c3 | 2017-10-25 15:39:42 +0100 | [diff] [blame] | 194 | GEM_BUG_ON(!b->irq_armed); |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 195 | |
Chris Wilson | bcbd5c3 | 2017-10-25 15:39:42 +0100 | [diff] [blame] | 196 | GEM_BUG_ON(!b->irq_enabled); |
| 197 | if (!--b->irq_enabled) |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 198 | irq_disable(engine); |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 199 | |
| 200 | b->irq_armed = false; |
| 201 | } |
| 202 | |
Chris Wilson | bcbd5c3 | 2017-10-25 15:39:42 +0100 | [diff] [blame] | 203 | void intel_engine_pin_breadcrumbs_irq(struct intel_engine_cs *engine) |
| 204 | { |
| 205 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 206 | |
| 207 | spin_lock_irq(&b->irq_lock); |
| 208 | if (!b->irq_enabled++) |
| 209 | irq_enable(engine); |
| 210 | GEM_BUG_ON(!b->irq_enabled); /* no overflow! */ |
| 211 | spin_unlock_irq(&b->irq_lock); |
| 212 | } |
| 213 | |
| 214 | void intel_engine_unpin_breadcrumbs_irq(struct intel_engine_cs *engine) |
| 215 | { |
| 216 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 217 | |
| 218 | spin_lock_irq(&b->irq_lock); |
| 219 | GEM_BUG_ON(!b->irq_enabled); /* no underflow! */ |
| 220 | if (!--b->irq_enabled) |
| 221 | irq_disable(engine); |
| 222 | spin_unlock_irq(&b->irq_lock); |
| 223 | } |
| 224 | |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 225 | void intel_engine_disarm_breadcrumbs(struct intel_engine_cs *engine) |
| 226 | { |
| 227 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
Chris Wilson | 832265d | 2017-12-08 01:23:01 +0000 | [diff] [blame] | 228 | struct intel_wait *wait, *n; |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 229 | |
| 230 | if (!b->irq_armed) |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 231 | return; |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 232 | |
Chris Wilson | 832265d | 2017-12-08 01:23:01 +0000 | [diff] [blame] | 233 | /* |
| 234 | * We only disarm the irq when we are idle (all requests completed), |
Chris Wilson | e1c0c91 | 2017-03-06 09:29:15 +0000 | [diff] [blame] | 235 | * so if the bottom-half remains asleep, it missed the request |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 236 | * completion. |
| 237 | */ |
Chris Wilson | 832265d | 2017-12-08 01:23:01 +0000 | [diff] [blame] | 238 | if (intel_engine_wakeup(engine) & ENGINE_WAKEUP_ASLEEP) |
| 239 | missed_breadcrumb(engine); |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 240 | |
Chris Wilson | e1c0c91 | 2017-03-06 09:29:15 +0000 | [diff] [blame] | 241 | spin_lock_irq(&b->rb_lock); |
Chris Wilson | a5cae7b | 2017-03-15 21:07:24 +0000 | [diff] [blame] | 242 | |
| 243 | spin_lock(&b->irq_lock); |
Chris Wilson | 832265d | 2017-12-08 01:23:01 +0000 | [diff] [blame] | 244 | b->irq_wait = NULL; |
Chris Wilson | e5330ac | 2017-10-31 12:22:35 +0000 | [diff] [blame] | 245 | if (b->irq_armed) |
| 246 | __intel_engine_disarm_breadcrumbs(engine); |
Chris Wilson | a5cae7b | 2017-03-15 21:07:24 +0000 | [diff] [blame] | 247 | spin_unlock(&b->irq_lock); |
| 248 | |
Chris Wilson | e1c0c91 | 2017-03-06 09:29:15 +0000 | [diff] [blame] | 249 | rbtree_postorder_for_each_entry_safe(wait, n, &b->waiters, node) { |
| 250 | RB_CLEAR_NODE(&wait->node); |
Chris Wilson | 832265d | 2017-12-08 01:23:01 +0000 | [diff] [blame] | 251 | wake_up_process(wait->tsk); |
Chris Wilson | e1c0c91 | 2017-03-06 09:29:15 +0000 | [diff] [blame] | 252 | } |
| 253 | b->waiters = RB_ROOT; |
| 254 | |
Chris Wilson | e1c0c91 | 2017-03-06 09:29:15 +0000 | [diff] [blame] | 255 | spin_unlock_irq(&b->rb_lock); |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Chris Wilson | 6ef98ea | 2017-02-17 15:13:03 +0000 | [diff] [blame] | 258 | static bool use_fake_irq(const struct intel_breadcrumbs *b) |
| 259 | { |
| 260 | const struct intel_engine_cs *engine = |
| 261 | container_of(b, struct intel_engine_cs, breadcrumbs); |
| 262 | |
| 263 | if (!test_bit(engine->id, &engine->i915->gpu_error.missed_irq_rings)) |
| 264 | return false; |
| 265 | |
| 266 | /* Only start with the heavy weight fake irq timer if we have not |
| 267 | * seen any interrupts since enabling it the first time. If the |
| 268 | * interrupts are still arriving, it means we made a mistake in our |
| 269 | * engine->seqno_barrier(), a timing error that should be transient |
| 270 | * and unlikely to reoccur. |
| 271 | */ |
| 272 | return atomic_read(&engine->irq_count) == b->hangcheck_interrupts; |
| 273 | } |
| 274 | |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 275 | static void enable_fake_irq(struct intel_breadcrumbs *b) |
| 276 | { |
| 277 | /* Ensure we never sleep indefinitely */ |
| 278 | if (!b->irq_enabled || use_fake_irq(b)) |
| 279 | mod_timer(&b->fake_irq, jiffies + 1); |
| 280 | else |
| 281 | mod_timer(&b->hangcheck, wait_timeout()); |
| 282 | } |
| 283 | |
Chris Wilson | bac2ef4 | 2017-06-08 12:14:03 +0100 | [diff] [blame] | 284 | static bool __intel_breadcrumbs_enable_irq(struct intel_breadcrumbs *b) |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 285 | { |
| 286 | struct intel_engine_cs *engine = |
| 287 | container_of(b, struct intel_engine_cs, breadcrumbs); |
| 288 | struct drm_i915_private *i915 = engine->i915; |
Chris Wilson | bcbd5c3 | 2017-10-25 15:39:42 +0100 | [diff] [blame] | 289 | bool enabled; |
| 290 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 291 | lockdep_assert_held(&b->irq_lock); |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 292 | if (b->irq_armed) |
Chris Wilson | bac2ef4 | 2017-06-08 12:14:03 +0100 | [diff] [blame] | 293 | return false; |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 294 | |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 295 | /* The breadcrumb irq will be disarmed on the interrupt after the |
| 296 | * waiters are signaled. This gives us a single interrupt window in |
| 297 | * which we can add a new waiter and avoid the cost of re-enabling |
| 298 | * the irq. |
| 299 | */ |
| 300 | b->irq_armed = true; |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 301 | |
Chris Wilson | f97fbf9 | 2017-02-13 17:15:14 +0000 | [diff] [blame] | 302 | if (I915_SELFTEST_ONLY(b->mock)) { |
| 303 | /* For our mock objects we want to avoid interaction |
| 304 | * with the real hardware (which is not set up). So |
| 305 | * we simply pretend we have enabled the powerwell |
| 306 | * and the irq, and leave it up to the mock |
| 307 | * implementation to call intel_engine_wakeup() |
| 308 | * itself when it wants to simulate a user interrupt, |
| 309 | */ |
Chris Wilson | bac2ef4 | 2017-06-08 12:14:03 +0100 | [diff] [blame] | 310 | return true; |
Chris Wilson | f97fbf9 | 2017-02-13 17:15:14 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 313 | /* Since we are waiting on a request, the GPU should be busy |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 314 | * and should have its own rpm reference. This is tracked |
| 315 | * by i915->gt.awake, we can forgo holding our own wakref |
| 316 | * for the interrupt as before i915->gt.awake is released (when |
| 317 | * the driver is idle) we disarm the breadcrumbs. |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 318 | */ |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 319 | |
| 320 | /* No interrupts? Kick the waiter every jiffie! */ |
Chris Wilson | bcbd5c3 | 2017-10-25 15:39:42 +0100 | [diff] [blame] | 321 | enabled = false; |
| 322 | if (!b->irq_enabled++ && |
| 323 | !test_bit(engine->id, &i915->gpu_error.test_irq_rings)) { |
| 324 | irq_enable(engine); |
| 325 | enabled = true; |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 328 | enable_fake_irq(b); |
Chris Wilson | bcbd5c3 | 2017-10-25 15:39:42 +0100 | [diff] [blame] | 329 | return enabled; |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | static inline struct intel_wait *to_wait(struct rb_node *node) |
| 333 | { |
Chris Wilson | d856786 | 2016-12-20 10:40:03 +0000 | [diff] [blame] | 334 | return rb_entry(node, struct intel_wait, node); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | static inline void __intel_breadcrumbs_finish(struct intel_breadcrumbs *b, |
| 338 | struct intel_wait *wait) |
| 339 | { |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 340 | lockdep_assert_held(&b->rb_lock); |
Chris Wilson | 908a6cb | 2017-03-15 21:07:25 +0000 | [diff] [blame] | 341 | GEM_BUG_ON(b->irq_wait == wait); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 342 | |
| 343 | /* This request is completed, so remove it from the tree, mark it as |
Chris Wilson | a6b0a141 | 2017-03-15 22:22:59 +0000 | [diff] [blame] | 344 | * complete, and *then* wake up the associated task. N.B. when the |
| 345 | * task wakes up, it will find the empty rb_node, discern that it |
| 346 | * has already been removed from the tree and skip the serialisation |
| 347 | * of the b->rb_lock and b->irq_lock. This means that the destruction |
| 348 | * of the intel_wait is not serialised with the interrupt handler |
| 349 | * by the waiter - it must instead be serialised by the caller. |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 350 | */ |
| 351 | rb_erase(&wait->node, &b->waiters); |
| 352 | RB_CLEAR_NODE(&wait->node); |
| 353 | |
| 354 | wake_up_process(wait->tsk); /* implicit smp_wmb() */ |
| 355 | } |
| 356 | |
Chris Wilson | b66255f | 2017-03-03 17:14:22 +0000 | [diff] [blame] | 357 | static inline void __intel_breadcrumbs_next(struct intel_engine_cs *engine, |
| 358 | struct rb_node *next) |
| 359 | { |
| 360 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 361 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 362 | spin_lock(&b->irq_lock); |
Chris Wilson | b66255f | 2017-03-03 17:14:22 +0000 | [diff] [blame] | 363 | GEM_BUG_ON(!b->irq_armed); |
Chris Wilson | 429732e | 2017-03-15 21:07:23 +0000 | [diff] [blame] | 364 | GEM_BUG_ON(!b->irq_wait); |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 365 | b->irq_wait = to_wait(next); |
| 366 | spin_unlock(&b->irq_lock); |
Chris Wilson | b66255f | 2017-03-03 17:14:22 +0000 | [diff] [blame] | 367 | |
| 368 | /* We always wake up the next waiter that takes over as the bottom-half |
| 369 | * as we may delegate not only the irq-seqno barrier to the next waiter |
| 370 | * but also the task of waking up concurrent waiters. |
| 371 | */ |
| 372 | if (next) |
| 373 | wake_up_process(to_wait(next)->tsk); |
| 374 | } |
| 375 | |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 376 | static bool __intel_engine_add_wait(struct intel_engine_cs *engine, |
| 377 | struct intel_wait *wait) |
| 378 | { |
| 379 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 380 | struct rb_node **p, *parent, *completed; |
Chris Wilson | bac2ef4 | 2017-06-08 12:14:03 +0100 | [diff] [blame] | 381 | bool first, armed; |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 382 | u32 seqno; |
| 383 | |
Chris Wilson | c68ce69 | 2018-01-02 19:25:00 +0000 | [diff] [blame] | 384 | GEM_BUG_ON(!wait->seqno); |
| 385 | |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 386 | /* Insert the request into the retirement ordered list |
| 387 | * of waiters by walking the rbtree. If we are the oldest |
| 388 | * seqno in the tree (the first to be retired), then |
| 389 | * set ourselves as the bottom-half. |
| 390 | * |
| 391 | * As we descend the tree, prune completed branches since we hold the |
| 392 | * spinlock we know that the first_waiter must be delayed and can |
| 393 | * reduce some of the sequential wake up latency if we take action |
| 394 | * ourselves and wake up the completed tasks in parallel. Also, by |
| 395 | * removing stale elements in the tree, we may be able to reduce the |
| 396 | * ping-pong between the old bottom-half and ourselves as first-waiter. |
| 397 | */ |
Chris Wilson | bac2ef4 | 2017-06-08 12:14:03 +0100 | [diff] [blame] | 398 | armed = false; |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 399 | first = true; |
| 400 | parent = NULL; |
| 401 | completed = NULL; |
Chris Wilson | 1b7744e | 2016-07-01 17:23:17 +0100 | [diff] [blame] | 402 | seqno = intel_engine_get_seqno(engine); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 403 | |
| 404 | /* If the request completed before we managed to grab the spinlock, |
| 405 | * return now before adding ourselves to the rbtree. We let the |
| 406 | * current bottom-half handle any pending wakeups and instead |
| 407 | * try and get out of the way quickly. |
| 408 | */ |
| 409 | if (i915_seqno_passed(seqno, wait->seqno)) { |
| 410 | RB_CLEAR_NODE(&wait->node); |
| 411 | return first; |
| 412 | } |
| 413 | |
| 414 | p = &b->waiters.rb_node; |
| 415 | while (*p) { |
| 416 | parent = *p; |
| 417 | if (wait->seqno == to_wait(parent)->seqno) { |
| 418 | /* We have multiple waiters on the same seqno, select |
| 419 | * the highest priority task (that with the smallest |
| 420 | * task->prio) to serve as the bottom-half for this |
| 421 | * group. |
| 422 | */ |
| 423 | if (wait->tsk->prio > to_wait(parent)->tsk->prio) { |
| 424 | p = &parent->rb_right; |
| 425 | first = false; |
| 426 | } else { |
| 427 | p = &parent->rb_left; |
| 428 | } |
| 429 | } else if (i915_seqno_passed(wait->seqno, |
| 430 | to_wait(parent)->seqno)) { |
| 431 | p = &parent->rb_right; |
| 432 | if (i915_seqno_passed(seqno, to_wait(parent)->seqno)) |
| 433 | completed = parent; |
| 434 | else |
| 435 | first = false; |
| 436 | } else { |
| 437 | p = &parent->rb_left; |
| 438 | } |
| 439 | } |
| 440 | rb_link_node(&wait->node, parent, p); |
| 441 | rb_insert_color(&wait->node, &b->waiters); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 442 | |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 443 | if (first) { |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 444 | spin_lock(&b->irq_lock); |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 445 | b->irq_wait = wait; |
Chris Wilson | 0417131 | 2016-07-06 12:39:00 +0100 | [diff] [blame] | 446 | /* After assigning ourselves as the new bottom-half, we must |
| 447 | * perform a cursory check to prevent a missed interrupt. |
| 448 | * Either we miss the interrupt whilst programming the hardware, |
| 449 | * or if there was a previous waiter (for a later seqno) they |
| 450 | * may be woken instead of us (due to the inherent race |
Chris Wilson | aca34b6 | 2016-07-06 12:39:02 +0100 | [diff] [blame] | 451 | * in the unlocked read of b->irq_seqno_bh in the irq handler) |
| 452 | * and so we miss the wake up. |
Chris Wilson | 0417131 | 2016-07-06 12:39:00 +0100 | [diff] [blame] | 453 | */ |
Chris Wilson | bac2ef4 | 2017-06-08 12:14:03 +0100 | [diff] [blame] | 454 | armed = __intel_breadcrumbs_enable_irq(b); |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 455 | spin_unlock(&b->irq_lock); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 456 | } |
Chris Wilson | 429732e | 2017-03-15 21:07:23 +0000 | [diff] [blame] | 457 | |
| 458 | if (completed) { |
Chris Wilson | a6b0a141 | 2017-03-15 22:22:59 +0000 | [diff] [blame] | 459 | /* Advance the bottom-half (b->irq_wait) before we wake up |
| 460 | * the waiters who may scribble over their intel_wait |
| 461 | * just as the interrupt handler is dereferencing it via |
| 462 | * b->irq_wait. |
| 463 | */ |
Chris Wilson | 429732e | 2017-03-15 21:07:23 +0000 | [diff] [blame] | 464 | if (!first) { |
| 465 | struct rb_node *next = rb_next(completed); |
| 466 | GEM_BUG_ON(next == &wait->node); |
| 467 | __intel_breadcrumbs_next(engine, next); |
| 468 | } |
| 469 | |
| 470 | do { |
| 471 | struct intel_wait *crumb = to_wait(completed); |
| 472 | completed = rb_prev(completed); |
| 473 | __intel_breadcrumbs_finish(b, crumb); |
| 474 | } while (completed); |
| 475 | } |
| 476 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 477 | GEM_BUG_ON(!b->irq_wait); |
Chris Wilson | 429732e | 2017-03-15 21:07:23 +0000 | [diff] [blame] | 478 | GEM_BUG_ON(!b->irq_armed); |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 479 | GEM_BUG_ON(rb_first(&b->waiters) != &b->irq_wait->node); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 480 | |
Chris Wilson | bac2ef4 | 2017-06-08 12:14:03 +0100 | [diff] [blame] | 481 | return armed; |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | bool intel_engine_add_wait(struct intel_engine_cs *engine, |
| 485 | struct intel_wait *wait) |
| 486 | { |
| 487 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
Chris Wilson | bac2ef4 | 2017-06-08 12:14:03 +0100 | [diff] [blame] | 488 | bool armed; |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 489 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 490 | spin_lock_irq(&b->rb_lock); |
Chris Wilson | bac2ef4 | 2017-06-08 12:14:03 +0100 | [diff] [blame] | 491 | armed = __intel_engine_add_wait(engine, wait); |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 492 | spin_unlock_irq(&b->rb_lock); |
Chris Wilson | bac2ef4 | 2017-06-08 12:14:03 +0100 | [diff] [blame] | 493 | if (armed) |
| 494 | return armed; |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 495 | |
Chris Wilson | bac2ef4 | 2017-06-08 12:14:03 +0100 | [diff] [blame] | 496 | /* Make the caller recheck if its request has already started. */ |
| 497 | return i915_seqno_passed(intel_engine_get_seqno(engine), |
| 498 | wait->seqno - 1); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 499 | } |
| 500 | |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 501 | static inline bool chain_wakeup(struct rb_node *rb, int priority) |
| 502 | { |
| 503 | return rb && to_wait(rb)->tsk->prio <= priority; |
| 504 | } |
| 505 | |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 506 | static inline int wakeup_priority(struct intel_breadcrumbs *b, |
| 507 | struct task_struct *tsk) |
| 508 | { |
| 509 | if (tsk == b->signaler) |
| 510 | return INT_MIN; |
| 511 | else |
| 512 | return tsk->prio; |
| 513 | } |
| 514 | |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 515 | static void __intel_engine_remove_wait(struct intel_engine_cs *engine, |
| 516 | struct intel_wait *wait) |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 517 | { |
| 518 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 519 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 520 | lockdep_assert_held(&b->rb_lock); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 521 | |
| 522 | if (RB_EMPTY_NODE(&wait->node)) |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 523 | goto out; |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 524 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 525 | if (b->irq_wait == wait) { |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 526 | const int priority = wakeup_priority(b, wait->tsk); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 527 | struct rb_node *next; |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 528 | |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 529 | /* We are the current bottom-half. Find the next candidate, |
| 530 | * the first waiter in the queue on the remaining oldest |
| 531 | * request. As multiple seqnos may complete in the time it |
| 532 | * takes us to wake up and find the next waiter, we have to |
| 533 | * wake up that waiter for it to perform its own coherent |
| 534 | * completion check. |
| 535 | */ |
| 536 | next = rb_next(&wait->node); |
| 537 | if (chain_wakeup(next, priority)) { |
| 538 | /* If the next waiter is already complete, |
| 539 | * wake it up and continue onto the next waiter. So |
| 540 | * if have a small herd, they will wake up in parallel |
| 541 | * rather than sequentially, which should reduce |
| 542 | * the overall latency in waking all the completed |
| 543 | * clients. |
| 544 | * |
| 545 | * However, waking up a chain adds extra latency to |
| 546 | * the first_waiter. This is undesirable if that |
| 547 | * waiter is a high priority task. |
| 548 | */ |
Chris Wilson | 1b7744e | 2016-07-01 17:23:17 +0100 | [diff] [blame] | 549 | u32 seqno = intel_engine_get_seqno(engine); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 550 | |
| 551 | while (i915_seqno_passed(seqno, to_wait(next)->seqno)) { |
| 552 | struct rb_node *n = rb_next(next); |
| 553 | |
| 554 | __intel_breadcrumbs_finish(b, to_wait(next)); |
| 555 | next = n; |
| 556 | if (!chain_wakeup(next, priority)) |
| 557 | break; |
| 558 | } |
| 559 | } |
| 560 | |
Chris Wilson | b66255f | 2017-03-03 17:14:22 +0000 | [diff] [blame] | 561 | __intel_breadcrumbs_next(engine, next); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 562 | } else { |
| 563 | GEM_BUG_ON(rb_first(&b->waiters) == &wait->node); |
| 564 | } |
| 565 | |
| 566 | GEM_BUG_ON(RB_EMPTY_NODE(&wait->node)); |
| 567 | rb_erase(&wait->node, &b->waiters); |
Chris Wilson | c534612 | 2017-11-15 12:14:58 +0000 | [diff] [blame] | 568 | RB_CLEAR_NODE(&wait->node); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 569 | |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 570 | out: |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 571 | GEM_BUG_ON(b->irq_wait == wait); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 572 | GEM_BUG_ON(rb_first(&b->waiters) != |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 573 | (b->irq_wait ? &b->irq_wait->node : NULL)); |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | void intel_engine_remove_wait(struct intel_engine_cs *engine, |
| 577 | struct intel_wait *wait) |
| 578 | { |
| 579 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 580 | |
| 581 | /* Quick check to see if this waiter was already decoupled from |
| 582 | * the tree by the bottom-half to avoid contention on the spinlock |
| 583 | * by the herd. |
| 584 | */ |
Chris Wilson | 908a6cb | 2017-03-15 21:07:25 +0000 | [diff] [blame] | 585 | if (RB_EMPTY_NODE(&wait->node)) { |
| 586 | GEM_BUG_ON(READ_ONCE(b->irq_wait) == wait); |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 587 | return; |
Chris Wilson | 908a6cb | 2017-03-15 21:07:25 +0000 | [diff] [blame] | 588 | } |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 589 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 590 | spin_lock_irq(&b->rb_lock); |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 591 | __intel_engine_remove_wait(engine, wait); |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 592 | spin_unlock_irq(&b->rb_lock); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 593 | } |
| 594 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 595 | static bool signal_complete(const struct i915_request *request) |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 596 | { |
Chris Wilson | b385085 | 2016-07-01 17:23:26 +0100 | [diff] [blame] | 597 | if (!request) |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 598 | return false; |
| 599 | |
Chris Wilson | fd10e2c | 2018-02-06 09:46:33 +0000 | [diff] [blame] | 600 | /* |
| 601 | * Carefully check if the request is complete, giving time for the |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 602 | * seqno to be visible or if the GPU hung. |
| 603 | */ |
Chris Wilson | fd10e2c | 2018-02-06 09:46:33 +0000 | [diff] [blame] | 604 | return __i915_request_irq_complete(request); |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 605 | } |
| 606 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 607 | static struct i915_request *to_signaler(struct rb_node *rb) |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 608 | { |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 609 | return rb_entry(rb, struct i915_request, signaling.node); |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | static void signaler_set_rtpriority(void) |
| 613 | { |
| 614 | struct sched_param param = { .sched_priority = 1 }; |
| 615 | |
| 616 | sched_setscheduler_nocheck(current, SCHED_FIFO, ¶m); |
| 617 | } |
| 618 | |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 619 | static void __intel_engine_remove_signal(struct intel_engine_cs *engine, |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 620 | struct i915_request *request) |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 621 | { |
| 622 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 623 | |
| 624 | lockdep_assert_held(&b->rb_lock); |
| 625 | |
| 626 | /* |
| 627 | * Wake up all other completed waiters and select the |
| 628 | * next bottom-half for the next user interrupt. |
| 629 | */ |
| 630 | __intel_engine_remove_wait(engine, &request->signaling.wait); |
| 631 | |
| 632 | /* |
| 633 | * Find the next oldest signal. Note that as we have |
| 634 | * not been holding the lock, another client may |
| 635 | * have installed an even older signal than the one |
| 636 | * we just completed - so double check we are still |
| 637 | * the oldest before picking the next one. |
| 638 | */ |
| 639 | if (request->signaling.wait.seqno) { |
| 640 | if (request == rcu_access_pointer(b->first_signal)) { |
| 641 | struct rb_node *rb = rb_next(&request->signaling.node); |
| 642 | rcu_assign_pointer(b->first_signal, |
| 643 | rb ? to_signaler(rb) : NULL); |
| 644 | } |
| 645 | |
| 646 | rb_erase(&request->signaling.node, &b->signals); |
| 647 | request->signaling.wait.seqno = 0; |
| 648 | } |
| 649 | } |
| 650 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 651 | static struct i915_request * |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 652 | get_first_signal_rcu(struct intel_breadcrumbs *b) |
| 653 | { |
| 654 | /* |
| 655 | * See the big warnings for i915_gem_active_get_rcu() and similarly |
| 656 | * for dma_fence_get_rcu_safe() that explain the intricacies involved |
| 657 | * here with defeating CPU/compiler speculation and enforcing |
| 658 | * the required memory barriers. |
| 659 | */ |
| 660 | do { |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 661 | struct i915_request *request; |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 662 | |
| 663 | request = rcu_dereference(b->first_signal); |
| 664 | if (request) |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 665 | request = i915_request_get_rcu(request); |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 666 | |
| 667 | barrier(); |
| 668 | |
| 669 | if (!request || request == rcu_access_pointer(b->first_signal)) |
| 670 | return rcu_pointer_handoff(request); |
| 671 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 672 | i915_request_put(request); |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 673 | } while (1); |
| 674 | } |
| 675 | |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 676 | static int intel_breadcrumbs_signaler(void *arg) |
| 677 | { |
| 678 | struct intel_engine_cs *engine = arg; |
| 679 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 680 | struct i915_request *request; |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 681 | |
| 682 | /* Install ourselves with high priority to reduce signalling latency */ |
| 683 | signaler_set_rtpriority(); |
| 684 | |
| 685 | do { |
Chris Wilson | a7980a6 | 2017-04-04 13:05:31 +0100 | [diff] [blame] | 686 | bool do_schedule = true; |
| 687 | |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 688 | set_current_state(TASK_INTERRUPTIBLE); |
| 689 | |
| 690 | /* We are either woken up by the interrupt bottom-half, |
| 691 | * or by a client adding a new signaller. In both cases, |
| 692 | * the GPU seqno may have advanced beyond our oldest signal. |
| 693 | * If it has, propagate the signal, remove the waiter and |
| 694 | * check again with the next oldest signal. Otherwise we |
| 695 | * need to wait for a new interrupt from the GPU or for |
| 696 | * a new client. |
| 697 | */ |
Chris Wilson | cced5e2 | 2017-02-23 07:44:15 +0000 | [diff] [blame] | 698 | rcu_read_lock(); |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 699 | request = get_first_signal_rcu(b); |
Chris Wilson | cced5e2 | 2017-02-23 07:44:15 +0000 | [diff] [blame] | 700 | rcu_read_unlock(); |
Chris Wilson | b385085 | 2016-07-01 17:23:26 +0100 | [diff] [blame] | 701 | if (signal_complete(request)) { |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 702 | if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, |
| 703 | &request->fence.flags)) { |
| 704 | local_bh_disable(); |
| 705 | dma_fence_signal(&request->fence); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 706 | GEM_BUG_ON(!i915_request_completed(request)); |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 707 | local_bh_enable(); /* kick start the tasklets */ |
Chris Wilson | b385085 | 2016-07-01 17:23:26 +0100 | [diff] [blame] | 708 | } |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 709 | |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 710 | if (READ_ONCE(request->signaling.wait.seqno)) { |
| 711 | spin_lock_irq(&b->rb_lock); |
| 712 | __intel_engine_remove_signal(engine, request); |
| 713 | spin_unlock_irq(&b->rb_lock); |
| 714 | } |
Chris Wilson | a7980a6 | 2017-04-04 13:05:31 +0100 | [diff] [blame] | 715 | |
| 716 | /* If the engine is saturated we may be continually |
| 717 | * processing completed requests. This angers the |
| 718 | * NMI watchdog if we never let anything else |
| 719 | * have access to the CPU. Let's pretend to be nice |
| 720 | * and relinquish the CPU if we burn through the |
| 721 | * entire RT timeslice! |
| 722 | */ |
| 723 | do_schedule = need_resched(); |
| 724 | } |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 725 | i915_request_put(request); |
Chris Wilson | a7980a6 | 2017-04-04 13:05:31 +0100 | [diff] [blame] | 726 | |
| 727 | if (unlikely(do_schedule)) { |
Chris Wilson | b1becb8 | 2017-04-03 11:51:24 +0100 | [diff] [blame] | 728 | if (kthread_should_park()) |
| 729 | kthread_parkme(); |
| 730 | |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 731 | if (unlikely(kthread_should_stop())) |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 732 | break; |
| 733 | |
| 734 | schedule(); |
| 735 | } |
| 736 | } while (1); |
| 737 | __set_current_state(TASK_RUNNING); |
| 738 | |
| 739 | return 0; |
| 740 | } |
| 741 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 742 | void intel_engine_enable_signaling(struct i915_request *request, bool wakeup) |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 743 | { |
| 744 | struct intel_engine_cs *engine = request->engine; |
| 745 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
Chris Wilson | 754c9fd | 2017-02-23 07:44:14 +0000 | [diff] [blame] | 746 | u32 seqno; |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 747 | |
Chris Wilson | f6168e3 | 2016-10-28 13:58:55 +0100 | [diff] [blame] | 748 | /* Note that we may be called from an interrupt handler on another |
| 749 | * device (e.g. nouveau signaling a fence completion causing us |
| 750 | * to submit a request, and so enable signaling). As such, |
Chris Wilson | a6b0a141 | 2017-03-15 22:22:59 +0000 | [diff] [blame] | 751 | * we need to make sure that all other users of b->rb_lock protect |
Chris Wilson | f6168e3 | 2016-10-28 13:58:55 +0100 | [diff] [blame] | 752 | * against interrupts, i.e. use spin_lock_irqsave. |
| 753 | */ |
| 754 | |
| 755 | /* locked by dma_fence_enable_sw_signaling() (irqsafe fence->lock) */ |
Chris Wilson | e60a870 | 2017-03-02 11:51:30 +0000 | [diff] [blame] | 756 | GEM_BUG_ON(!irqs_disabled()); |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 757 | lockdep_assert_held(&request->lock); |
Chris Wilson | 754c9fd | 2017-02-23 07:44:14 +0000 | [diff] [blame] | 758 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 759 | seqno = i915_request_global_seqno(request); |
Chris Wilson | 754c9fd | 2017-02-23 07:44:14 +0000 | [diff] [blame] | 760 | if (!seqno) |
Chris Wilson | 65e4760 | 2016-10-28 13:58:49 +0100 | [diff] [blame] | 761 | return; |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 762 | |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 763 | spin_lock(&b->rb_lock); |
| 764 | |
| 765 | GEM_BUG_ON(request->signaling.wait.seqno); |
Chris Wilson | b385085 | 2016-07-01 17:23:26 +0100 | [diff] [blame] | 766 | request->signaling.wait.tsk = b->signaler; |
Chris Wilson | 56299fb | 2017-02-27 20:58:48 +0000 | [diff] [blame] | 767 | request->signaling.wait.request = request; |
Chris Wilson | 754c9fd | 2017-02-23 07:44:14 +0000 | [diff] [blame] | 768 | request->signaling.wait.seqno = seqno; |
Chris Wilson | 4a50d20 | 2016-07-26 12:01:50 +0100 | [diff] [blame] | 769 | |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 770 | /* First add ourselves into the list of waiters, but register our |
| 771 | * bottom-half as the signaller thread. As per usual, only the oldest |
| 772 | * waiter (not just signaller) is tasked as the bottom-half waking |
| 773 | * up all completed waiters after the user interrupt. |
| 774 | * |
| 775 | * If we are the oldest waiter, enable the irq (after which we |
| 776 | * must double check that the seqno did not complete). |
| 777 | */ |
Chris Wilson | f7b02a5 | 2017-04-26 09:06:59 +0100 | [diff] [blame] | 778 | wakeup &= __intel_engine_add_wait(engine, &request->signaling.wait); |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 779 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 780 | if (!__i915_request_completed(request, seqno)) { |
Chris Wilson | 735e0eb | 2017-06-08 12:14:04 +0100 | [diff] [blame] | 781 | struct rb_node *parent, **p; |
| 782 | bool first; |
| 783 | |
| 784 | /* Now insert ourselves into the retirement ordered list of |
| 785 | * signals on this engine. We track the oldest seqno as that |
| 786 | * will be the first signal to complete. |
| 787 | */ |
| 788 | parent = NULL; |
| 789 | first = true; |
| 790 | p = &b->signals.rb_node; |
| 791 | while (*p) { |
| 792 | parent = *p; |
| 793 | if (i915_seqno_passed(seqno, |
| 794 | to_signaler(parent)->signaling.wait.seqno)) { |
| 795 | p = &parent->rb_right; |
| 796 | first = false; |
| 797 | } else { |
| 798 | p = &parent->rb_left; |
| 799 | } |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 800 | } |
Chris Wilson | 735e0eb | 2017-06-08 12:14:04 +0100 | [diff] [blame] | 801 | rb_link_node(&request->signaling.node, parent, p); |
| 802 | rb_insert_color(&request->signaling.node, &b->signals); |
| 803 | if (first) |
| 804 | rcu_assign_pointer(b->first_signal, request); |
| 805 | } else { |
| 806 | __intel_engine_remove_wait(engine, &request->signaling.wait); |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 807 | request->signaling.wait.seqno = 0; |
Chris Wilson | 735e0eb | 2017-06-08 12:14:04 +0100 | [diff] [blame] | 808 | wakeup = false; |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 809 | } |
Chris Wilson | b385085 | 2016-07-01 17:23:26 +0100 | [diff] [blame] | 810 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 811 | spin_unlock(&b->rb_lock); |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 812 | |
| 813 | if (wakeup) |
| 814 | wake_up_process(b->signaler); |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 815 | } |
| 816 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 817 | void intel_engine_cancel_signaling(struct i915_request *request) |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 818 | { |
Chris Wilson | e60a870 | 2017-03-02 11:51:30 +0000 | [diff] [blame] | 819 | GEM_BUG_ON(!irqs_disabled()); |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 820 | lockdep_assert_held(&request->lock); |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 821 | |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 822 | if (READ_ONCE(request->signaling.wait.seqno)) { |
| 823 | struct intel_engine_cs *engine = request->engine; |
| 824 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 825 | |
Chris Wilson | b7a3f33 | 2018-02-03 10:19:14 +0000 | [diff] [blame] | 826 | spin_lock(&b->rb_lock); |
| 827 | __intel_engine_remove_signal(engine, request); |
| 828 | spin_unlock(&b->rb_lock); |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 829 | } |
Chris Wilson | 9eb143b | 2017-02-23 07:44:16 +0000 | [diff] [blame] | 830 | } |
| 831 | |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 832 | int intel_engine_init_breadcrumbs(struct intel_engine_cs *engine) |
| 833 | { |
| 834 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 835 | struct task_struct *tsk; |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 836 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 837 | spin_lock_init(&b->rb_lock); |
| 838 | spin_lock_init(&b->irq_lock); |
| 839 | |
Kees Cook | 39cbf2a | 2017-10-17 09:53:04 +0300 | [diff] [blame] | 840 | timer_setup(&b->fake_irq, intel_breadcrumbs_fake_irq, 0); |
| 841 | timer_setup(&b->hangcheck, intel_breadcrumbs_hangcheck, 0); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 842 | |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 843 | /* Spawn a thread to provide a common bottom-half for all signals. |
| 844 | * As this is an asynchronous interface we cannot steal the current |
| 845 | * task for handling the bottom-half to the user interrupt, therefore |
| 846 | * we create a thread to do the coherent seqno dance after the |
| 847 | * interrupt and then signal the waitqueue (via the dma-buf/fence). |
| 848 | */ |
| 849 | tsk = kthread_run(intel_breadcrumbs_signaler, engine, |
| 850 | "i915/signal:%d", engine->id); |
| 851 | if (IS_ERR(tsk)) |
| 852 | return PTR_ERR(tsk); |
| 853 | |
| 854 | b->signaler = tsk; |
| 855 | |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 856 | return 0; |
| 857 | } |
| 858 | |
Chris Wilson | ad07dfc | 2016-10-07 07:53:26 +0100 | [diff] [blame] | 859 | static void cancel_fake_irq(struct intel_engine_cs *engine) |
| 860 | { |
| 861 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 862 | |
| 863 | del_timer_sync(&b->hangcheck); |
| 864 | del_timer_sync(&b->fake_irq); |
| 865 | clear_bit(engine->id, &engine->i915->gpu_error.missed_irq_rings); |
| 866 | } |
| 867 | |
| 868 | void intel_engine_reset_breadcrumbs(struct intel_engine_cs *engine) |
| 869 | { |
| 870 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 871 | |
| 872 | cancel_fake_irq(engine); |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 873 | spin_lock_irq(&b->irq_lock); |
Chris Wilson | ad07dfc | 2016-10-07 07:53:26 +0100 | [diff] [blame] | 874 | |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 875 | if (b->irq_enabled) |
| 876 | irq_enable(engine); |
| 877 | else |
Chris Wilson | ad07dfc | 2016-10-07 07:53:26 +0100 | [diff] [blame] | 878 | irq_disable(engine); |
Chris Wilson | 67b807a8 | 2017-02-27 20:58:50 +0000 | [diff] [blame] | 879 | |
| 880 | /* We set the IRQ_BREADCRUMB bit when we enable the irq presuming the |
| 881 | * GPU is active and may have already executed the MI_USER_INTERRUPT |
| 882 | * before the CPU is ready to receive. However, the engine is currently |
| 883 | * idle (we haven't started it yet), there is no possibility for a |
| 884 | * missed interrupt as we enabled the irq and so we can clear the |
| 885 | * immediate wakeup (until a real interrupt arrives for the waiter). |
| 886 | */ |
| 887 | clear_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted); |
| 888 | |
| 889 | if (b->irq_armed) |
| 890 | enable_fake_irq(b); |
Chris Wilson | ad07dfc | 2016-10-07 07:53:26 +0100 | [diff] [blame] | 891 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 892 | spin_unlock_irq(&b->irq_lock); |
Chris Wilson | ad07dfc | 2016-10-07 07:53:26 +0100 | [diff] [blame] | 893 | } |
| 894 | |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 895 | void intel_engine_fini_breadcrumbs(struct intel_engine_cs *engine) |
| 896 | { |
| 897 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 898 | |
Chris Wilson | 381744f | 2016-11-21 11:07:59 +0000 | [diff] [blame] | 899 | /* The engines should be idle and all requests accounted for! */ |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 900 | WARN_ON(READ_ONCE(b->irq_wait)); |
Chris Wilson | 381744f | 2016-11-21 11:07:59 +0000 | [diff] [blame] | 901 | WARN_ON(!RB_EMPTY_ROOT(&b->waiters)); |
Chris Wilson | cced5e2 | 2017-02-23 07:44:15 +0000 | [diff] [blame] | 902 | WARN_ON(rcu_access_pointer(b->first_signal)); |
Chris Wilson | 381744f | 2016-11-21 11:07:59 +0000 | [diff] [blame] | 903 | WARN_ON(!RB_EMPTY_ROOT(&b->signals)); |
| 904 | |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 905 | if (!IS_ERR_OR_NULL(b->signaler)) |
| 906 | kthread_stop(b->signaler); |
| 907 | |
Chris Wilson | ad07dfc | 2016-10-07 07:53:26 +0100 | [diff] [blame] | 908 | cancel_fake_irq(engine); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 909 | } |
| 910 | |
Chris Wilson | 9b6586a | 2017-02-23 07:44:08 +0000 | [diff] [blame] | 911 | bool intel_breadcrumbs_busy(struct intel_engine_cs *engine) |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 912 | { |
Chris Wilson | 9b6586a | 2017-02-23 07:44:08 +0000 | [diff] [blame] | 913 | struct intel_breadcrumbs *b = &engine->breadcrumbs; |
| 914 | bool busy = false; |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 915 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 916 | spin_lock_irq(&b->rb_lock); |
Chris Wilson | 6a5d1db | 2016-11-08 14:37:19 +0000 | [diff] [blame] | 917 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 918 | if (b->irq_wait) { |
| 919 | wake_up_process(b->irq_wait->tsk); |
Chris Wilson | 4bd6639 | 2017-03-15 21:07:22 +0000 | [diff] [blame] | 920 | busy = true; |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 921 | } |
| 922 | |
Chris Wilson | cced5e2 | 2017-02-23 07:44:15 +0000 | [diff] [blame] | 923 | if (rcu_access_pointer(b->first_signal)) { |
Chris Wilson | 9b6586a | 2017-02-23 07:44:08 +0000 | [diff] [blame] | 924 | wake_up_process(b->signaler); |
Chris Wilson | 4bd6639 | 2017-03-15 21:07:22 +0000 | [diff] [blame] | 925 | busy = true; |
Chris Wilson | 9b6586a | 2017-02-23 07:44:08 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Chris Wilson | 61d3dc7 | 2017-03-03 19:08:24 +0000 | [diff] [blame] | 928 | spin_unlock_irq(&b->rb_lock); |
Chris Wilson | 9b6586a | 2017-02-23 07:44:08 +0000 | [diff] [blame] | 929 | |
| 930 | return busy; |
Chris Wilson | c81d461 | 2016-07-01 17:23:25 +0100 | [diff] [blame] | 931 | } |
Chris Wilson | f97fbf9 | 2017-02-13 17:15:14 +0000 | [diff] [blame] | 932 | |
| 933 | #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) |
| 934 | #include "selftests/intel_breadcrumbs.c" |
| 935 | #endif |