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