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 17 int intel_selftest_modify_policy(struct intel_engine_cs *engine, 18 struct intel_selftest_saved_policy *saved, 19 u32 modify_type) 20 21 { 22 int err; 23 24 saved->reset = engine->i915->params.reset; 25 saved->flags = engine->flags; 26 saved->timeslice = engine->props.timeslice_duration_ms; 27 saved->preempt_timeout = engine->props.preempt_timeout_ms; 28 29 switch (modify_type) { 30 case SELFTEST_SCHEDULER_MODIFY_FAST_RESET: 31 /* 32 * Enable force pre-emption on time slice expiration 33 * together with engine reset on pre-emption timeout. 34 * This is required to make the GuC notice and reset 35 * the single hanging context. 36 * Also, reduce the preemption timeout to something 37 * small to speed the test up. 38 */ 39 engine->i915->params.reset = 2; 40 engine->flags |= I915_ENGINE_WANT_FORCED_PREEMPTION; 41 engine->props.timeslice_duration_ms = REDUCED_TIMESLICE; 42 engine->props.preempt_timeout_ms = REDUCED_PREEMPT; 43 break; 44 45 case SELFTEST_SCHEDULER_MODIFY_NO_HANGCHECK: 46 engine->props.preempt_timeout_ms = 0; 47 break; 48 49 default: 50 pr_err("Invalid scheduler policy modification type: %d!\n", modify_type); 51 return -EINVAL; 52 } 53 54 if (!intel_engine_uses_guc(engine)) 55 return 0; 56 57 err = intel_guc_global_policies_update(&engine->gt->uc.guc); 58 if (err) 59 intel_selftest_restore_policy(engine, saved); 60 61 return err; 62 } 63 64 int intel_selftest_restore_policy(struct intel_engine_cs *engine, 65 struct intel_selftest_saved_policy *saved) 66 { 67 /* Restore the original policies */ 68 engine->i915->params.reset = saved->reset; 69 engine->flags = saved->flags; 70 engine->props.timeslice_duration_ms = saved->timeslice; 71 engine->props.preempt_timeout_ms = saved->preempt_timeout; 72 73 if (!intel_engine_uses_guc(engine)) 74 return 0; 75 76 return intel_guc_global_policies_update(&engine->gt->uc.guc); 77 } 78 79 int intel_selftest_wait_for_rq(struct i915_request *rq) 80 { 81 long ret; 82 83 ret = i915_request_wait(rq, 0, WAIT_FOR_RESET_TIME); 84 if (ret < 0) 85 return ret; 86 87 return 0; 88 } 89