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

drm/i915: Improve long running compute w/a for GuC submission

A workaround was added to the driver to allow compute workloads to run
'forever' by disabling pre-emption on the RCS engine for Gen12.
It is not totally unbound as the heartbeat will kick in eventually
and cause a reset of the hung engine.

However, this does not work well in GuC submission mode. In GuC mode,
the pre-emption timeout is how GuC detects hung contexts and triggers
a per engine reset. Thus, disabling the timeout means also losing all
per engine reset ability. A full GT reset will still occur when the
heartbeat finally expires, but that is a much more destructive and
undesirable mechanism.

The purpose of the workaround is actually to give compute tasks longer
to reach a pre-emption point after a pre-emption request has been
issued. This is necessary because Gen12 does not support mid-thread
pre-emption and compute tasks can have long running threads.

So, rather than disabling the timeout completely, just set it to a
'long' value.

v2: Review feedback from Tvrtko - must hard code the 'long' value
instead of determining it algorithmically. So make it an extra CONFIG
definition. Also, remove the execlist centric comment from the
existing pre-emption timeout CONFIG option given that it applies to
more than just execlists.

Signed-off-by: John Harrison <John.C.Harrison@Intel.com>
Reviewed-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Acked-by: Michal Mrozek <michal.mrozek@intel.com>
Acked-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221006213813.1563435-5-John.C.Harrison@Intel.com

+29 -6
+22 -4
drivers/gpu/drm/i915/Kconfig.profile
··· 57 57 default 640 # milliseconds 58 58 help 59 59 How long to wait (in milliseconds) for a preemption event to occur 60 - when submitting a new context via execlists. If the current context 61 - does not hit an arbitration point and yield to HW before the timer 62 - expires, the HW will be reset to allow the more important context 63 - to execute. 60 + when submitting a new context. If the current context does not hit 61 + an arbitration point and yield to HW before the timer expires, the 62 + HW will be reset to allow the more important context to execute. 63 + 64 + This is adjustable via 65 + /sys/class/drm/card?/engine/*/preempt_timeout_ms 66 + 67 + May be 0 to disable the timeout. 68 + 69 + The compiled in default may get overridden at driver probe time on 70 + certain platforms and certain engines which will be reflected in the 71 + sysfs control. 72 + 73 + config DRM_I915_PREEMPT_TIMEOUT_COMPUTE 74 + int "Preempt timeout for compute engines (ms, jiffy granularity)" 75 + default 7500 # milliseconds 76 + help 77 + How long to wait (in milliseconds) for a preemption event to occur 78 + when submitting a new context to a compute capable engine. If the 79 + current context does not hit an arbitration point and yield to HW 80 + before the timer expires, the HW will be reset to allow the more 81 + important context to execute. 64 82 65 83 This is adjustable via 66 84 /sys/class/drm/card?/engine/*/preempt_timeout_ms
+7 -2
drivers/gpu/drm/i915/gt/intel_engine_cs.c
··· 508 508 engine->props.timeslice_duration_ms = 509 509 CONFIG_DRM_I915_TIMESLICE_DURATION; 510 510 511 - /* Override to uninterruptible for OpenCL workloads. */ 511 + /* 512 + * Mid-thread pre-emption is not available in Gen12. Unfortunately, 513 + * some compute workloads run quite long threads. That means they get 514 + * reset due to not pre-empting in a timely manner. So, bump the 515 + * pre-emption timeout value to be much higher for compute engines. 516 + */ 512 517 if (GRAPHICS_VER(i915) == 12 && (engine->flags & I915_ENGINE_HAS_RCS_REG_STATE)) 513 - engine->props.preempt_timeout_ms = 0; 518 + engine->props.preempt_timeout_ms = CONFIG_DRM_I915_PREEMPT_TIMEOUT_COMPUTE; 514 519 515 520 /* Cap properties according to any system limits */ 516 521 #define CLAMP_PROP(field) \