Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915: Make the heartbeat play nice with long pre-emption timeouts

Compute workloads are inherently not pre-emptible for long periods on
current hardware. As a workaround for this, the pre-emption timeout
for compute capable engines was disabled. This is undesirable with GuC
submission as it prevents per engine reset of hung contexts. Hence the
next patch will re-enable the timeout but bumped up by an order of
magnitude.

However, the heartbeat might not respect that. Depending upon current
activity, a pre-emption to the heartbeat pulse might not even be
attempted until the last heartbeat period. Which means that only one
period is granted for the pre-emption to occur. With the aforesaid
bump, the pre-emption timeout could be significantly larger than this
heartbeat period.

So adjust the heartbeat code to take the pre-emption timeout into
account. When it reaches the final (high priority) period, it now
ensures the delay before hitting reset is bigger than the pre-emption
timeout.

v2: Fix for selftests which adjust the heartbeat period manually.
v3: Add FIXME comment about selftests. Add extra FIXME comment and
drm_notices when setting heartbeat to a non-default value (review
feedback from Tvrtko)

Signed-off-by: John Harrison <John.C.Harrison@Intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221006213813.1563435-4-John.C.Harrison@Intel.com

+39
+39
drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c
··· 22 22 23 23 static bool next_heartbeat(struct intel_engine_cs *engine) 24 24 { 25 + struct i915_request *rq; 25 26 long delay; 26 27 27 28 delay = READ_ONCE(engine->props.heartbeat_interval_ms); 29 + 30 + rq = engine->heartbeat.systole; 31 + 32 + /* 33 + * FIXME: The final period extension is disabled if the period has been 34 + * modified from the default. This is to prevent issues with certain 35 + * selftests which override the value and expect specific behaviour. 36 + * Once the selftests have been updated to either cope with variable 37 + * heartbeat periods (or to override the pre-emption timeout as well, 38 + * or just to add a selftest specific override of the extension), the 39 + * generic override can be removed. 40 + */ 41 + if (rq && rq->sched.attr.priority >= I915_PRIORITY_BARRIER && 42 + delay == engine->defaults.heartbeat_interval_ms) { 43 + long longer; 44 + 45 + /* 46 + * The final try is at the highest priority possible. Up until now 47 + * a pre-emption might not even have been attempted. So make sure 48 + * this last attempt allows enough time for a pre-emption to occur. 49 + */ 50 + longer = READ_ONCE(engine->props.preempt_timeout_ms) * 2; 51 + longer = intel_clamp_heartbeat_interval_ms(engine, longer); 52 + if (longer > delay) 53 + delay = longer; 54 + } 55 + 28 56 if (!delay) 29 57 return false; 30 58 ··· 315 287 316 288 if (!delay && !intel_engine_has_preempt_reset(engine)) 317 289 return -ENODEV; 290 + 291 + /* FIXME: Remove together with equally marked hack in next_heartbeat. */ 292 + if (delay != engine->defaults.heartbeat_interval_ms && 293 + delay < 2 * engine->props.preempt_timeout_ms) { 294 + if (intel_engine_uses_guc(engine)) 295 + drm_notice(&engine->i915->drm, "%s heartbeat interval adjusted to a non-default value which may downgrade individual engine resets to full GPU resets!\n", 296 + engine->name); 297 + else 298 + drm_notice(&engine->i915->drm, "%s heartbeat interval adjusted to a non-default value which may cause engine resets to target innocent contexts!\n", 299 + engine->name); 300 + } 318 301 319 302 intel_engine_pm_get(engine); 320 303