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