• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2021 Intel Corporation
4  */
5 
6 //#include "gt/intel_engine_user.h"
7 #include "gt/intel_gt.h"
8 #include "i915_drv.h"
9 #include "i915_selftest.h"
10 
11 #include "selftests/intel_scheduler_helpers.h"
12 
13 #define REDUCED_TIMESLICE	5
14 #define REDUCED_PREEMPT		10
15 #define WAIT_FOR_RESET_TIME	10000
16 
intel_selftest_modify_policy(struct intel_engine_cs * engine,struct intel_selftest_saved_policy * saved,enum selftest_scheduler_modify modify_type)17 int intel_selftest_modify_policy(struct intel_engine_cs *engine,
18 				 struct intel_selftest_saved_policy *saved,
19 				 enum selftest_scheduler_modify modify_type)
20 {
21 	int err;
22 
23 	saved->reset = engine->i915->params.reset;
24 	saved->flags = engine->flags;
25 	saved->timeslice = engine->props.timeslice_duration_ms;
26 	saved->preempt_timeout = engine->props.preempt_timeout_ms;
27 
28 	switch (modify_type) {
29 	case SELFTEST_SCHEDULER_MODIFY_FAST_RESET:
30 		/*
31 		 * Enable force pre-emption on time slice expiration
32 		 * together with engine reset on pre-emption timeout.
33 		 * This is required to make the GuC notice and reset
34 		 * the single hanging context.
35 		 * Also, reduce the preemption timeout to something
36 		 * small to speed the test up.
37 		 */
38 		engine->i915->params.reset = 2;
39 		engine->flags |= I915_ENGINE_WANT_FORCED_PREEMPTION;
40 		engine->props.timeslice_duration_ms = REDUCED_TIMESLICE;
41 		engine->props.preempt_timeout_ms = REDUCED_PREEMPT;
42 		break;
43 
44 	case SELFTEST_SCHEDULER_MODIFY_NO_HANGCHECK:
45 		engine->props.preempt_timeout_ms = 0;
46 		break;
47 
48 	default:
49 		pr_err("Invalid scheduler policy modification type: %d!\n", modify_type);
50 		return -EINVAL;
51 	}
52 
53 	if (!intel_engine_uses_guc(engine))
54 		return 0;
55 
56 	err = intel_guc_global_policies_update(&engine->gt->uc.guc);
57 	if (err)
58 		intel_selftest_restore_policy(engine, saved);
59 
60 	return err;
61 }
62 
intel_selftest_restore_policy(struct intel_engine_cs * engine,struct intel_selftest_saved_policy * saved)63 int intel_selftest_restore_policy(struct intel_engine_cs *engine,
64 				  struct intel_selftest_saved_policy *saved)
65 {
66 	/* Restore the original policies */
67 	engine->i915->params.reset = saved->reset;
68 	engine->flags = saved->flags;
69 	engine->props.timeslice_duration_ms = saved->timeslice;
70 	engine->props.preempt_timeout_ms = saved->preempt_timeout;
71 
72 	if (!intel_engine_uses_guc(engine))
73 		return 0;
74 
75 	return intel_guc_global_policies_update(&engine->gt->uc.guc);
76 }
77 
intel_selftest_wait_for_rq(struct i915_request * rq)78 int intel_selftest_wait_for_rq(struct i915_request *rq)
79 {
80 	long ret;
81 
82 	ret = i915_request_wait(rq, 0, WAIT_FOR_RESET_TIME);
83 	if (ret < 0)
84 		return ret;
85 
86 	return 0;
87 }
88