xref: /linux/drivers/gpu/drm/i915/selftests/igt_live_test.c (revision e6a901a00822659181c93c86d8bbc2a17779fddc)
1 /*
2  * SPDX-License-Identifier: MIT
3  *
4  * Copyright © 2018 Intel Corporation
5  */
6 
7 #include "i915_drv.h"
8 #include "gt/intel_gt.h"
9 #include "gt/intel_gt_print.h"
10 
11 #include "../i915_selftest.h"
12 #include "igt_flush_test.h"
13 #include "igt_live_test.h"
14 
15 int igt_live_test_begin(struct igt_live_test *t,
16 			struct drm_i915_private *i915,
17 			const char *func,
18 			const char *name)
19 {
20 	struct intel_engine_cs *engine;
21 	enum intel_engine_id id;
22 	struct intel_gt *gt;
23 	unsigned int i;
24 	int err;
25 
26 	t->i915 = i915;
27 	t->func = func;
28 	t->name = name;
29 
30 	for_each_gt(gt, i915, i) {
31 
32 		err = intel_gt_wait_for_idle(gt, MAX_SCHEDULE_TIMEOUT);
33 		if (err) {
34 			gt_err(gt, "%s(%s): GT failed to idle before, with err=%d!",
35 			       func, name, err);
36 			return err;
37 		}
38 
39 		for_each_engine(engine, gt, id)
40 			t->reset_engine[i][id] =
41 				i915_reset_engine_count(&i915->gpu_error,
42 							engine);
43 	}
44 
45 	t->reset_global = i915_reset_count(&i915->gpu_error);
46 
47 	return 0;
48 }
49 
50 int igt_live_test_end(struct igt_live_test *t)
51 {
52 	struct drm_i915_private *i915 = t->i915;
53 	struct intel_engine_cs *engine;
54 	enum intel_engine_id id;
55 	struct intel_gt *gt;
56 	unsigned int i;
57 
58 	if (igt_flush_test(i915))
59 		return -EIO;
60 
61 	if (t->reset_global != i915_reset_count(&i915->gpu_error)) {
62 		pr_err("%s(%s): GPU was reset %d times!\n",
63 		       t->func, t->name,
64 		       i915_reset_count(&i915->gpu_error) - t->reset_global);
65 		return -EIO;
66 	}
67 
68 	for_each_gt(gt, i915, i) {
69 		for_each_engine(engine, gt, id) {
70 			if (t->reset_engine[i][id] ==
71 			    i915_reset_engine_count(&i915->gpu_error, engine))
72 				continue;
73 
74 			gt_err(gt, "%s(%s): engine '%s' was reset %d times!\n",
75 			       t->func, t->name, engine->name,
76 			       i915_reset_engine_count(&i915->gpu_error, engine) -
77 			       t->reset_engine[i][id]);
78 			return -EIO;
79 		}
80 	}
81 
82 	return 0;
83 }
84