This source file includes following definitions.
- instdone_unchanged
- subunits_stuck
- head_stuck
- engine_stuck
- hangcheck_load_sample
- hangcheck_store_sample
- hangcheck_get_action
- hangcheck_accumulate_sample
- hangcheck_declare_hang
- hangcheck_elapsed
- intel_gt_queue_hangcheck
- intel_engine_init_hangcheck
- intel_gt_init_hangcheck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include "i915_drv.h"
26 #include "intel_engine.h"
27 #include "intel_gt.h"
28 #include "intel_reset.h"
29
30 struct hangcheck {
31 u64 acthd;
32 u32 ring;
33 u32 head;
34 enum intel_engine_hangcheck_action action;
35 unsigned long action_timestamp;
36 int deadlock;
37 struct intel_instdone instdone;
38 bool wedged:1;
39 bool stalled:1;
40 };
41
42 static bool instdone_unchanged(u32 current_instdone, u32 *old_instdone)
43 {
44 u32 tmp = current_instdone | *old_instdone;
45 bool unchanged;
46
47 unchanged = tmp == *old_instdone;
48 *old_instdone |= tmp;
49
50 return unchanged;
51 }
52
53 static bool subunits_stuck(struct intel_engine_cs *engine)
54 {
55 struct drm_i915_private *dev_priv = engine->i915;
56 struct intel_instdone instdone;
57 struct intel_instdone *accu_instdone = &engine->hangcheck.instdone;
58 bool stuck;
59 int slice;
60 int subslice;
61
62 intel_engine_get_instdone(engine, &instdone);
63
64
65
66
67
68
69 stuck = instdone_unchanged(instdone.instdone,
70 &accu_instdone->instdone);
71 stuck &= instdone_unchanged(instdone.slice_common,
72 &accu_instdone->slice_common);
73
74 for_each_instdone_slice_subslice(dev_priv, slice, subslice) {
75 stuck &= instdone_unchanged(instdone.sampler[slice][subslice],
76 &accu_instdone->sampler[slice][subslice]);
77 stuck &= instdone_unchanged(instdone.row[slice][subslice],
78 &accu_instdone->row[slice][subslice]);
79 }
80
81 return stuck;
82 }
83
84 static enum intel_engine_hangcheck_action
85 head_stuck(struct intel_engine_cs *engine, u64 acthd)
86 {
87 if (acthd != engine->hangcheck.acthd) {
88
89
90 memset(&engine->hangcheck.instdone, 0,
91 sizeof(engine->hangcheck.instdone));
92
93 return ENGINE_ACTIVE_HEAD;
94 }
95
96 if (!subunits_stuck(engine))
97 return ENGINE_ACTIVE_SUBUNITS;
98
99 return ENGINE_DEAD;
100 }
101
102 static enum intel_engine_hangcheck_action
103 engine_stuck(struct intel_engine_cs *engine, u64 acthd)
104 {
105 enum intel_engine_hangcheck_action ha;
106 u32 tmp;
107
108 ha = head_stuck(engine, acthd);
109 if (ha != ENGINE_DEAD)
110 return ha;
111
112 if (IS_GEN(engine->i915, 2))
113 return ENGINE_DEAD;
114
115
116
117
118
119
120 tmp = ENGINE_READ(engine, RING_CTL);
121 if (tmp & RING_WAIT) {
122 intel_gt_handle_error(engine->gt, engine->mask, 0,
123 "stuck wait on %s", engine->name);
124 ENGINE_WRITE(engine, RING_CTL, tmp);
125 return ENGINE_WAIT_KICK;
126 }
127
128 return ENGINE_DEAD;
129 }
130
131 static void hangcheck_load_sample(struct intel_engine_cs *engine,
132 struct hangcheck *hc)
133 {
134 hc->acthd = intel_engine_get_active_head(engine);
135 hc->ring = ENGINE_READ(engine, RING_START);
136 hc->head = ENGINE_READ(engine, RING_HEAD);
137 }
138
139 static void hangcheck_store_sample(struct intel_engine_cs *engine,
140 const struct hangcheck *hc)
141 {
142 engine->hangcheck.acthd = hc->acthd;
143 engine->hangcheck.last_ring = hc->ring;
144 engine->hangcheck.last_head = hc->head;
145 }
146
147 static enum intel_engine_hangcheck_action
148 hangcheck_get_action(struct intel_engine_cs *engine,
149 const struct hangcheck *hc)
150 {
151 if (intel_engine_is_idle(engine))
152 return ENGINE_IDLE;
153
154 if (engine->hangcheck.last_ring != hc->ring)
155 return ENGINE_ACTIVE_SEQNO;
156
157 if (engine->hangcheck.last_head != hc->head)
158 return ENGINE_ACTIVE_SEQNO;
159
160 return engine_stuck(engine, hc->acthd);
161 }
162
163 static void hangcheck_accumulate_sample(struct intel_engine_cs *engine,
164 struct hangcheck *hc)
165 {
166 unsigned long timeout = I915_ENGINE_DEAD_TIMEOUT;
167
168 hc->action = hangcheck_get_action(engine, hc);
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 switch (hc->action) {
186 case ENGINE_IDLE:
187 case ENGINE_ACTIVE_SEQNO:
188
189 hc->acthd = 0;
190
191 memset(&engine->hangcheck.instdone, 0,
192 sizeof(engine->hangcheck.instdone));
193
194
195 case ENGINE_WAIT_KICK:
196 case ENGINE_WAIT:
197 engine->hangcheck.action_timestamp = jiffies;
198 break;
199
200 case ENGINE_ACTIVE_HEAD:
201 case ENGINE_ACTIVE_SUBUNITS:
202
203
204
205
206 timeout = I915_SEQNO_DEAD_TIMEOUT;
207 break;
208
209 case ENGINE_DEAD:
210 break;
211
212 default:
213 MISSING_CASE(hc->action);
214 }
215
216 hc->stalled = time_after(jiffies,
217 engine->hangcheck.action_timestamp + timeout);
218 hc->wedged = time_after(jiffies,
219 engine->hangcheck.action_timestamp +
220 I915_ENGINE_WEDGED_TIMEOUT);
221 }
222
223 static void hangcheck_declare_hang(struct intel_gt *gt,
224 intel_engine_mask_t hung,
225 intel_engine_mask_t stuck)
226 {
227 struct intel_engine_cs *engine;
228 intel_engine_mask_t tmp;
229 char msg[80];
230 int len;
231
232
233
234
235 if (stuck != hung)
236 hung &= ~stuck;
237 len = scnprintf(msg, sizeof(msg),
238 "%s on ", stuck == hung ? "no progress" : "hang");
239 for_each_engine_masked(engine, gt->i915, hung, tmp)
240 len += scnprintf(msg + len, sizeof(msg) - len,
241 "%s, ", engine->name);
242 msg[len-2] = '\0';
243
244 return intel_gt_handle_error(gt, hung, I915_ERROR_CAPTURE, "%s", msg);
245 }
246
247
248
249
250
251
252
253
254
255 static void hangcheck_elapsed(struct work_struct *work)
256 {
257 struct intel_gt *gt =
258 container_of(work, typeof(*gt), hangcheck.work.work);
259 intel_engine_mask_t hung = 0, stuck = 0, wedged = 0;
260 struct intel_engine_cs *engine;
261 enum intel_engine_id id;
262 intel_wakeref_t wakeref;
263
264 if (!i915_modparams.enable_hangcheck)
265 return;
266
267 if (!READ_ONCE(gt->awake))
268 return;
269
270 if (intel_gt_is_wedged(gt))
271 return;
272
273 wakeref = intel_runtime_pm_get_if_in_use(>->i915->runtime_pm);
274 if (!wakeref)
275 return;
276
277
278
279
280
281 intel_uncore_arm_unclaimed_mmio_detection(gt->uncore);
282
283 for_each_engine(engine, gt->i915, id) {
284 struct hangcheck hc;
285
286 intel_engine_signal_breadcrumbs(engine);
287
288 hangcheck_load_sample(engine, &hc);
289 hangcheck_accumulate_sample(engine, &hc);
290 hangcheck_store_sample(engine, &hc);
291
292 if (hc.stalled) {
293 hung |= engine->mask;
294 if (hc.action != ENGINE_DEAD)
295 stuck |= engine->mask;
296 }
297
298 if (hc.wedged)
299 wedged |= engine->mask;
300 }
301
302 if (GEM_SHOW_DEBUG() && (hung | stuck)) {
303 struct drm_printer p = drm_debug_printer("hangcheck");
304
305 for_each_engine(engine, gt->i915, id) {
306 if (intel_engine_is_idle(engine))
307 continue;
308
309 intel_engine_dump(engine, &p, "%s\n", engine->name);
310 }
311 }
312
313 if (wedged) {
314 dev_err(gt->i915->drm.dev,
315 "GPU recovery timed out,"
316 " cancelling all in-flight rendering.\n");
317 GEM_TRACE_DUMP();
318 intel_gt_set_wedged(gt);
319 }
320
321 if (hung)
322 hangcheck_declare_hang(gt, hung, stuck);
323
324 intel_runtime_pm_put(>->i915->runtime_pm, wakeref);
325
326
327 intel_gt_queue_hangcheck(gt);
328 }
329
330 void intel_gt_queue_hangcheck(struct intel_gt *gt)
331 {
332 unsigned long delay;
333
334 if (unlikely(!i915_modparams.enable_hangcheck))
335 return;
336
337
338
339
340
341
342
343 delay = round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES);
344 queue_delayed_work(system_long_wq, >->hangcheck.work, delay);
345 }
346
347 void intel_engine_init_hangcheck(struct intel_engine_cs *engine)
348 {
349 memset(&engine->hangcheck, 0, sizeof(engine->hangcheck));
350 engine->hangcheck.action_timestamp = jiffies;
351 }
352
353 void intel_gt_init_hangcheck(struct intel_gt *gt)
354 {
355 INIT_DELAYED_WORK(>->hangcheck.work, hangcheck_elapsed);
356 }
357
358 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
359 #include "selftest_hangcheck.c"
360 #endif