GEN8+ GPU Watchdog Reset Support
Subsystems (3)
v5 cover GEN8+ GPU Watchdog Reset Support
This is a rebased on the original patch series from Michel Thierry:
https://patchwork.freedesktop.org/series/21868
Note that this series is only limited to the GPU Watchdog timeout for execlists as it leaves out support for GuC based submissions for later.
PATCH v5 of this series was tested from userspace through an IGT test gem_watchdog --run-subtest basic-bsd1 that is is not in upstream yet.
The corresponding changes on the i965 media userspace are also under
review: https://github.com/intel/intel-vaapi-driver/pull/429/files
Michel Thierry (5):
drm/i915: Add engine reset count in get-reset-stats ioctl drm/i915: Watchdog timeout: IRQ handler for gen8+ drm/i915: Watchdog timeout: Ringbuffer command emission for gen8+ drm/i915: Watchdog timeout: DRM kernel interface to set the timeout drm/i915: Watchdog timeout: Include threshold value in error state
drivers/gpu/drm/i915/i915_drv.h | 5 + drivers/gpu/drm/i915/i915_gem_context.c | 162 ++++++++++++++++++++- drivers/gpu/drm/i915/i915_gpu_error.c | 14 +- drivers/gpu/drm/i915/i915_gpu_error.h | 5 + drivers/gpu/drm/i915/i915_irq.c | 14 +- drivers/gpu/drm/i915/i915_reg.h | 6 + drivers/gpu/drm/i915/i915_reset.c | 20 +++ drivers/gpu/drm/i915/i915_reset.h | 6 + drivers/gpu/drm/i915/intel_context_types.h | 4 + drivers/gpu/drm/i915/intel_engine_cs.c | 3 + drivers/gpu/drm/i915/intel_engine_types.h | 22 ++- drivers/gpu/drm/i915/intel_hangcheck.c | 11 +- drivers/gpu/drm/i915/intel_lrc.c | 141 +++++++++++++++++- drivers/gpu/drm/i915/intel_lrc.h | 2 + include/uapi/drm/i915_drm.h | 21 +++ 15 files changed, 410 insertions(+), 26 deletions(-)
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 1/5 drm/i915: Add engine reset count in get-reset-stats ioctl
From: Michel Thierry <[email protected]>
Users/tests relying on the total reset count will start seeing a smaller number since most of the hangs can be handled by engine reset. Note that if reset engine x, context a running on engine y will be unaware and unaffected.
To start the discussion, include just a total engine reset count. If it is deemed useful, it can be extended to report each engine separately.
Our igt's gem_reset_stats test will need changes to ignore the pad field, since it can now return reset_engine_count.
v2: s/engine_reset/reset_engine/, use union in uapi to not break compatibility.
v3: Keep rejecting attempts to use pad as input (Antonio)
v4: Rebased.
v5: Rebased.
Get rid of the union to store pad/engine count (Chris)
--- drivers/gpu/drm/i915/i915_gem_context.c | 12 ++++++++++-- include/uapi/drm/i915_drm.h | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +10 -2
@@ -1350,6 +1350,8 @@ int i915_gem_context_reset_stats_ioctl(struct drm_device *dev,struct drm_i915_private *dev_priv =to_i915 (dev);struct drm_i915_reset_stats *args = data;struct i915_gem_context *ctx; +struct intel_engine_cs *engine; +enum intel_engine_id id;int ret;if (args->flags || args->pad)
@@ -1368,10 +1370,16 @@ int i915_gem_context_reset_stats_ioctl(struct drm_device *dev,* we should wrap the hangstats with a seqlock. */ -if (capable (CAP_SYS_ADMIN )) +if (capable (CAP_SYS_ADMIN )) { args->reset_count =i915_reset_count (&dev_priv->gpu_error); -else +for_each_engine (engine, dev_priv, id) + args->reset_engine_count += +i915_reset_engine_count (&dev_priv->gpu_error, + engine); + }else { args->reset_count =0 ; + args->reset_engine_count =0 ; + } args->batch_active =atomic_read (&ctx->guilty_count); args->batch_pending =atomic_read (&ctx->active_count);
include/uapi/drm/i915_drm.h +4 -0
@@ -1459,6 +1459,9 @@ struct drm_i915_reset_stats {/* All resets since boot/module reload, for all contexts */ __u32 reset_count; +/* Engine resets since boot/module reload, for all contexts */ +__u32 reset_engine_count; +/* Number of batches lost when active in GPU, for this context */ __u32 batch_active;
@@ -1466,6 +1469,7 @@ struct drm_i915_reset_stats {__u32 batch_pending;__u32 pad; + };struct drm_i915_gem_userptr {
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 1/5] drm/i915: Add engine reset count in get-reset-stats ioctl
Quoting Carlos Santa (2019-03-22 23:41:14)
Quoted 45 lines
From: Michel Thierry <[email protected]>
Users/tests relying on the total reset count will start seeing a smaller number since most of the hangs can be handled by engine reset. Note that if reset engine x, context a running on engine y will be unaware and unaffected.
To start the discussion, include just a total engine reset count. If it is deemed useful, it can be extended to report each engine separately.
Our igt's
gem_reset_statstest will need changes to ignore the pad field, since it can now returnreset_engine_count.v2: s/engine_reset/reset_engine/, use union in uapi to not break compatibility.
v3: Keep rejecting attempts to use pad as input (Antonio)
v4: Rebased.
v5: Rebased.
Get rid of the union to store pad/engine count (Chris)Cc Chris Wilson <[email protected]>Cc Mika Kuoppala <[email protected]>Cc Antonio Argenziano <[email protected]>Cc Cc: Tvrtko Ursulin <[email protected]>Signed-off-by Michel Thierry <[email protected]>Signed-off-by Carlos Santa <[email protected]>--- drivers/gpu/drm/i915/i915_gem_context.c | 12 ++++++++++-- include/uapi/drm/i915_drm.h | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_gem_context.c +2
-0@@ -1350,6 +1350,8 @@ int i915_gem_context_reset_stats_ioctl(struct drm_device *dev,struct drm_i915_private *dev_priv =to_i915 (dev);struct drm_i915_reset_stats *args = data;struct i915_gem_context *ctx; +struct intel_engine_cs *engine; +enum intel_engine_id id;int ret;if (args->flags || args->pad)@@ -1368,10 +1370,16 @@ int i915_gem_context_reset_stats_ioctl(struct drm_device *dev,* we should wrap the hangstats with a seqlock.
drivers/gpu/drm/i915/i915_gem_context.c int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, · line 1378
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_context.c +5
-2*/ -if (capable (CAP_SYS_ADMIN )) +if (capable (CAP_SYS_ADMIN )) { args->reset_count =i915_reset_count (&dev_priv->gpu_error); -else +for_each_engine (engine, dev_priv, id) + args->reset_engine_count += +i915_reset_engine_count (&dev_priv->gpu_error, + engine);
Do we really care about device-vs-engine here? Amalgamating all engine resets into one variable is barely any more information than amalgamating them with the device count.
Quoted 12 lines
drivers/gpu/drm/i915/i915_gem_context.c +3
-0+ }else { args->reset_count =0 ; + args->reset_engine_count =0 ; + } args->batch_active =atomic_read (&ctx->guilty_count); args->batch_pending =atomic_read (&ctx->active_count);include/uapi/drm/i915_drm.h +0
-0
include/uapi/drm/i915_drm.h struct drm_i915_reset_stats { · line 1463
Quoted 5 lines
include/uapi/drm/i915_drm.h +2
-0@@ -1459,6 +1459,9 @@ struct drm_i915_reset_stats {/* All resets since boot/module reload, for all contexts */ __u32 reset_count; +/* Engine resets since boot/module reload, for all contexts */ +__u32 reset_engine_count;
You cannot insert elements into the middle of an uABI struct. You can only extend. To avoid problems with sw layout, always introduce a new struct.
Quoted 15 lines
include/uapi/drm/i915_drm.h +2
-0+/* Number of batches lost when active in GPU, for this context */ __u32 batch_active;@@ -1466,6 +1469,7 @@ struct drm_i915_reset_stats {__u32 batch_pending;__u32 pad; + };struct drm_i915_gem_userptr {Signature · 1 line
2.17.1
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 2/5 drm/i915: Watchdog timeout: IRQ handler for gen8+
In reply to Carlos SantaFrom: Michel Thierry <[email protected]>
*** General ***
Watchdog timeout (or "media engine reset") is a feature that allows userland applications to enable hang detection on individual batch buffers. The detection mechanism itself is mostly bound to the hardware and the only thing that the driver needs to do to support this form of hang detection is to implement the interrupt handling support as well as watchdog command emission before and after the emitted batch buffer start instruction in the ring buffer.
The principle of the hang detection mechanism is as follows:
1. Once the decision has been made to enable watchdog timeout for a particular batch buffer and the driver is in the process of emitting the batch buffer start instruction into the ring buffer it also emits a watchdog timer start instruction before and a watchdog timer cancellation instruction after the batch buffer start instruction in the ring buffer.
2. Once the GPU execution reaches the watchdog timer start instruction the hardware watchdog counter is started by the hardware. The counter keeps counting until either reaching a previously configured threshold value or the timer cancellation instruction is executed.
2a. If the counter reaches the threshold value the hardware fires a watchdog interrupt that is picked up by the watchdog interrupt handler. This means that a hang has been detected and the driver needs to deal with it the same way it would deal with a engine hang detected by the periodic hang checker. The only difference between the two is that we already blamed the active request (to ensure an engine reset).
2b. If the batch buffer completes and the execution reaches the watchdog cancellation instruction before the watchdog counter reaches its threshold value the watchdog is cancelled and nothing more comes of it. No hang is detected.
Note about future interaction with preemption: Preemption could happen in a command sequence prior to watchdog counter getting disabled, resulting in watchdog being triggered following preemption (e.g. when watchdog had been enabled in the low priority batch). The driver will need to explicitly disable the watchdog counter as part of the preemption sequence.
*** This patch introduces: ***
1. IRQ handler code for watchdog timeout allowing direct hang recovery based on hardware-driven hang detection, which then integrates directly with the hang recovery path. This is independent of having per-engine reset or just full gpu reset.
2. Watchdog specific register information.
Currently the render engine and all available media engines support watchdog timeout (VECS is only supported in GEN9). The specifications elude to the BCS engine being supported but that is currently not supported by this commit.
Note that the value to stop the counter is different between render and non-render engines in GEN8; GEN9 onwards it's the same.
v2: Move irq handler to tasklet, arm watchdog for a 2nd time to check against false-positives.
v3: Don't use high priority tasklet, use engine_last_submit while checking for false-positives. From GEN9 onwards, the stop counter bit is the same for all engines.
v4: Remove unnecessary brackets, use current_seqno to mark the request as guilty in the hangcheck/capture code.
v5: Rebased after RESET_ENGINEs flag.
v6: Don't capture error state in case of watchdog timeout. The capture process is time consuming and this will align to what happens when we use GuC to handle the watchdog timeout. (Chris)
v7: Rebase.
v8: Rebase, use HZ to reschedule.
v9: Rebase, get forcewake domains in function (no longer in execlists struct).
v10: Rebase.
v11: Rebase,
remove extra braces (Tvrtko),
implement watchdog_to_clock_counts helper (Tvrtko), Move tasklet_kill(watchdog_tasklet) inside intel_engines (Tvrtko), Use a global heartbeat seqno instead of engine seqno (Chris) Make all engines checks all class based checks (Tvrtko)
v12: Rebase,
Reset immediately upon entering the IRQ (Chris) Make reset_engine_to_str a helper (Tvrtko) Rename watchdog_irq_handler as watchdog_tasklet (Tvrtko) Let the compiler itself do the inline (Tvrtko)
v13: Rebase
v14: Rebase, skip checking for the guilty seqno in the tasklet (Tvrtko)
--- drivers/gpu/drm/i915/i915_gpu_error.h | 4 ++ drivers/gpu/drm/i915/i915_irq.c | 14 ++++-- drivers/gpu/drm/i915/i915_reg.h | 6 +++ drivers/gpu/drm/i915/i915_reset.c | 20 +++++++++ drivers/gpu/drm/i915/i915_reset.h | 6 +++ drivers/gpu/drm/i915/intel_engine_cs.c | 1 + drivers/gpu/drm/i915/intel_engine_types.h | 5 +++ drivers/gpu/drm/i915/intel_hangcheck.c | 11 +---- drivers/gpu/drm/i915/intel_lrc.c | 52 +++++++++++++++++++++++ 9 files changed, 107 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_gpu_error.h +4 -0
@@ -203,6 +203,9 @@ struct i915_gpu_error {* any global resources that may be clobber by the reset (such as * FENCE registers). * +* #I915_RESET_WATCHDOG - When hw detects a hang before us, we can use +* I915_RESET_WATCHDOG to report the hang detection cause accurately. +* * #I915_RESET_ENGINE[num_engines] - Since the driver doesn't need to * acquire the struct_mutex to reset an engine, we need an explicit * flag to prevent two concurrent reset attempts in the same engine.
@@ -218,6 +221,7 @@ struct i915_gpu_error {#define I915_RESET_BACKOFF 0#define I915_RESET_MODESET 1#define I915_RESET_ENGINE 2 +#define I915_RESET_WATCHDOG 3#define I915_WEDGED (BITS_PER_LONG - 1)/** Number of times the device has been reset (global) */
drivers/gpu/drm/i915/i915_irq.c +11 -3
@@ -1466,6 +1466,9 @@ gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir)if (tasklet)tasklet_hi_schedule (&engine->execlists.tasklet); + +if (iir >_GEN8_WATCHDOG_INTERRUPT ) +tasklet_schedule (&engine->execlists.watchdog_tasklet); } static void gen8_gt_irq_ack(struct drm_i915_private *i915,
@@ -3892,20 +3895,25 @@ static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)u32 gt_interrupts[] = { (GT_RENDER_USER_INTERRUPT <<GEN8_RCS_IRQ_SHIFT |GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_RCS_IRQ_SHIFT | +GT_GEN8_WATCHDOG_INTERRUPT <<GEN8_RCS_IRQ_SHIFT |GT_RENDER_USER_INTERRUPT <<GEN8_BCS_IRQ_SHIFT |GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_BCS_IRQ_SHIFT ), - (GT_RENDER_USER_INTERRUPT <<GEN8_VCS0_IRQ_SHIFT |GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_VCS0_IRQ_SHIFT | +GT_GEN8_WATCHDOG_INTERRUPT <<GEN8_VCS0_IRQ_SHIFT |GT_RENDER_USER_INTERRUPT <<GEN8_VCS1_IRQ_SHIFT | -GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_VCS1_IRQ_SHIFT ), - +GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_VCS1_IRQ_SHIFT | +GT_GEN8_WATCHDOG_INTERRUPT <<GEN8_VCS1_IRQ_SHIFT ),0 , (GT_RENDER_USER_INTERRUPT <<GEN8_VECS_IRQ_SHIFT |GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_VECS_IRQ_SHIFT ) }; +/* VECS watchdog is only available in skl+ */ +if (INTEL_GEN (dev_priv) >=9 ) + gt_interrupts[3 ] |=GT_GEN8_WATCHDOG_INTERRUPT ; + dev_priv->pm_ier =0x0 ; dev_priv->pm_imr = ~dev_priv->pm_ier;GEN8_IRQ_INIT_NDX (GT ,0 , ~gt_interrupts[0 ], gt_interrupts[0 ]);
drivers/gpu/drm/i915/i915_reg.h +6 -0
@@ -2363,6 +2363,11 @@ enum i915_power_well_id {#define RING_START (base) _MMIO((base) + 0x38)#define RING_CTL (base) _MMIO((base) + 0x3c)#define RING_CTL_SIZE (size) ((size) - PAGE_SIZE)/* in bytes -> pages */ +#define RING_CNTR (base) _MMIO((base) + 0x178) +#define GEN8_WATCHDOG_ENABLE 0 +#define GEN8_WATCHDOG_DISABLE 1 +#define GEN8_XCS_WATCHDOG_DISABLE 0xFFFFFFFF/* GEN8 & non-render only */ +#define RING_THRESH (base) _MMIO((base) + 0x17C)#define RING_SYNC_0 (base) _MMIO((base) + 0x40)#define RING_SYNC_1 (base) _MMIO((base) + 0x44)#define RING_SYNC_2 (base) _MMIO((base) + 0x48)
@@ -2925,6 +2930,7 @@ enum i915_power_well_id {#define GT_BSD_USER_INTERRUPT (1 << 12)#define GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1 (1 << 11)/* hsw+; rsvd on snb, ivb, vlv */ #define GT_CONTEXT_SWITCH_INTERRUPT (1 << 8) +#define GT_GEN8_WATCHDOG_INTERRUPT (1 << 6)/* gen8+ */ #define GT_RENDER_L3_PARITY_ERROR_INTERRUPT (1 << 5)/* !snb */ #define GT_RENDER_PIPECTL_NOTIFY_INTERRUPT (1 << 4)#define GT_RENDER_CS_MASTER_ERROR_INTERRUPT (1 << 3)
drivers/gpu/drm/i915/i915_reset.c +20 -0
@@ -1208,6 +1208,26 @@ void i915_clear_error_registers(struct drm_i915_private *dev_priv) } } +void engine_reset_error_to_str (struct drm_i915_private *i915, +char *msg, +size_t sz, +unsigned int hung, +unsigned int stuck, +unsigned int watchdog) +{ +int len; +unsigned int tmp; +struct intel_engine_cs *engine; + + len =scnprintf (msg, sz, +"%s on " , watchdog ?"watchdog timeout" : + stuck == hung ?"no_progress" :"hang" ); +for_each_engine_masked (engine, i915, hung, tmp) + len +=scnprintf (msg + len, sz - len, +"%s, " , engine->name); + msg[len-2 ] ='\0' ; +} +/** * i915_handle_error - handle a gpu error * @i915: i915 device private
drivers/gpu/drm/i915/i915_reset.h +6 -0
@@ -20,6 +20,12 @@ void i915_handle_error(struct drm_i915_private *i915,u32 engine_mask, unsigned long flags, const char *fmt, ...); +void engine_reset_error_to_str (struct drm_i915_private *i915, +char *str, +size_t sz, +unsigned int hung, +unsigned int stuck, +unsigned int watchdog);#define I915_ERROR_CAPTURE BIT(0)void i915_clear_error_registers (struct drm_i915_private *i915);
drivers/gpu/drm/i915/intel_engine_cs.c +1 -0
@@ -1149,6 +1149,7 @@ void intel_engines_park(struct drm_i915_private *i915)/* Flush the residual irq tasklets first. */ intel_engine_disarm_breadcrumbs (engine);tasklet_kill (&engine->execlists.tasklet); +tasklet_kill (&engine->execlists.watchdog_tasklet);/* * We are committed now to parking the engines, make sure there
drivers/gpu/drm/i915/intel_engine_types.h +5 -0
@@ -124,6 +124,11 @@ struct intel_engine_execlists {*/ struct tasklet_struct tasklet; +/* +* @watchdog_tasklet: stop counter and reschedule hangcheck_work asap +*/ +struct tasklet_struct watchdog_tasklet; +/** * @default_priolist: priority list for I915_PRIORITY_NORMAL */
drivers/gpu/drm/i915/intel_hangcheck.c +2 -9
@@ -220,22 +220,15 @@ static void hangcheck_declare_hang(struct drm_i915_private *i915,unsigned int hung, unsigned int stuck) { -struct intel_engine_cs *engine; char msg[80]; -unsigned int tmp; -int len; +size_t len =sizeof (msg);/* If some rings hung but others were still busy, only * blame the hanging rings in the synopsis. */ if (stuck != hung) hung &= ~stuck; - len =scnprintf (msg,sizeof (msg), -"%s on " , stuck == hung ?"no progress" :"hang" ); -for_each_engine_masked (engine, i915, hung, tmp) - len +=scnprintf (msg + len,sizeof (msg) - len, -"%s, " , engine->name); - msg[len-2 ] ='\0' ; +engine_reset_error_to_str (i915, msg, len, hung, stuck,0 );return i915_handle_error (i915, hung,I915_ERROR_CAPTURE ,"%s" , msg); }
drivers/gpu/drm/i915/intel_lrc.c +52 -0
70 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 2/5] drm/i915: Watchdog timeout: IRQ handler for gen8+
Quoted 93 lines · Carlos Santa
From: Michel Thierry <[email protected]>
*** General ***
Watchdog timeout (or "media engine reset") is a feature that allows userland applications to enable hang detection on individual batch buffers. The detection mechanism itself is mostly bound to the hardware and the only thing that the driver needs to do to support this form of hang detection is to implement the interrupt handling support as well as watchdog command emission before and after the emitted batch buffer start instruction in the ring buffer.
The principle of the hang detection mechanism is as follows:
1. Once the decision has been made to enable watchdog timeout for a particular batch buffer and the driver is in the process of emitting the batch buffer start instruction into the ring buffer it also emits a watchdog timer start instruction before and a watchdog timer cancellation instruction after the batch buffer start instruction in the ring buffer.
2. Once the GPU execution reaches the watchdog timer start instruction the hardware watchdog counter is started by the hardware. The counter keeps counting until either reaching a previously configured threshold value or the timer cancellation instruction is executed.
2a. If the counter reaches the threshold value the hardware fires a watchdog interrupt that is picked up by the watchdog interrupt handler. This means that a hang has been detected and the driver needs to deal with it the same way it would deal with a engine hang detected by the periodic hang checker. The only difference between the two is that we already blamed the active request (to ensure an engine reset).
2b. If the batch buffer completes and the execution reaches the watchdog cancellation instruction before the watchdog counter reaches its threshold value the watchdog is cancelled and nothing more comes of it. No hang is detected.
Note about future interaction with preemption: Preemption could happen in a command sequence prior to watchdog counter getting disabled, resulting in watchdog being triggered following preemption (e.g. when watchdog had been enabled in the low priority batch). The driver will need to explicitly disable the watchdog counter as part of the preemption sequence.
*** This patch introduces: ***
1. IRQ handler code for watchdog timeout allowing direct hang recovery based on hardware-driven hang detection, which then integrates directly with the hang recovery path. This is independent of having per-engine reset or just full gpu reset.
2. Watchdog specific register information.
Currently the render engine and all available media engines support watchdog timeout (VECS is only supported in GEN9). The specifications elude to the BCS engine being supported but that is currently not supported by this commit.
Note that the value to stop the counter is different between render and non-render engines in GEN8; GEN9 onwards it's the same.
v2: Move irq handler to tasklet, arm watchdog for a 2nd time to check against false-positives.
v3: Don't use high priority tasklet, use
engine_last_submitwhile checking for false-positives. From GEN9 onwards, the stop counter bit is the same for all engines.v4: Remove unnecessary brackets, use
current_seqnoto mark the request as guilty in the hangcheck/capture code.v5: Rebased after
RESET_ENGINEsflag.v6: Don't capture error state in case of watchdog timeout. The capture process is time consuming and this will align to what happens when we use GuC to handle the watchdog timeout. (Chris)
v7: Rebase.
v8: Rebase, use HZ to reschedule.
v9: Rebase, get forcewake domains in function (no longer in execlists struct).
v10: Rebase.
v11: Rebase,
remove extra braces (Tvrtko),
implementwatchdog_to_clock_countshelper (Tvrtko), Movetasklet_kill(watchdog_tasklet)insideintel_engines(Tvrtko), Use a global heartbeat seqno instead of engine seqno (Chris) Make all engines checks all class based checks (Tvrtko)
Quoted 8 lines
v12: Rebase,
Reset immediately upon entering the IRQ (Chris) Makereset_engine_to_stra helper (Tvrtko) Renamewatchdog_irq_handleraswatchdog_tasklet(Tvrtko) Let the compiler itself do the inline (Tvrtko)v13: Rebase
v14: Rebase, skip checking for the guilty seqno in the tasklet (Tvrtko)
IIRC I only asked about it so I guess you tried it and it works well?
Can you also post the IGTs so we can see the test coverage?
Regards,
Tvrtko
Quoted 280 lines
Cc Antonio Argenziano <[email protected]>Cc Tvrtko Ursulin <[email protected]>Signed-off-by Michel Thierry <[email protected]>Signed-off-by Carlos Santa <[email protected]>--- drivers/gpu/drm/i915/i915_gpu_error.h | 4 ++ drivers/gpu/drm/i915/i915_irq.c | 14 ++++-- drivers/gpu/drm/i915/i915_reg.h | 6 +++ drivers/gpu/drm/i915/i915_reset.c | 20 +++++++++ drivers/gpu/drm/i915/i915_reset.h | 6 +++ drivers/gpu/drm/i915/intel_engine_cs.c | 1 + drivers/gpu/drm/i915/intel_engine_types.h | 5 +++ drivers/gpu/drm/i915/intel_hangcheck.c | 11 +---- drivers/gpu/drm/i915/intel_lrc.c | 52 +++++++++++++++++++++++ 9 files changed, 107 insertions(+), 12 deletions(-)drivers/gpu/drm/i915/i915_gpu_error.h +4
-0@@ -203,6 +203,9 @@ struct i915_gpu_error {* any global resources that may be clobber by the reset (such as * FENCE registers). * +* #I915_RESET_WATCHDOG - When hw detects a hang before us, we can use +* I915_RESET_WATCHDOG to report the hang detection cause accurately. +* * #I915_RESET_ENGINE[num_engines] - Since the driver doesn't need to * acquire the struct_mutex to reset an engine, we need an explicit * flag to prevent two concurrent reset attempts in the same engine. @@ -218,6 +221,7 @@ struct i915_gpu_error {#define I915_RESET_BACKOFF 0#define I915_RESET_MODESET 1#define I915_RESET_ENGINE 2 +#define I915_RESET_WATCHDOG 3#define I915_WEDGED (BITS_PER_LONG - 1)/** Number of times the device has been reset (global) */ drivers/gpu/drm/i915/i915_irq.c +11
-3@@ -1466,6 +1466,9 @@ gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir)if (tasklet)tasklet_hi_schedule (&engine->execlists.tasklet); + +if (iir >_GEN8_WATCHDOG_INTERRUPT ) +tasklet_schedule (&engine->execlists.watchdog_tasklet); } static void gen8_gt_irq_ack(struct drm_i915_private *i915,@@ -3892,20 +3895,25 @@ static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)u32 gt_interrupts[] = { (GT_RENDER_USER_INTERRUPT <<GEN8_RCS_IRQ_SHIFT |GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_RCS_IRQ_SHIFT | +GT_GEN8_WATCHDOG_INTERRUPT <<GEN8_RCS_IRQ_SHIFT |GT_RENDER_USER_INTERRUPT <<GEN8_BCS_IRQ_SHIFT |GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_BCS_IRQ_SHIFT ), - (GT_RENDER_USER_INTERRUPT <<GEN8_VCS0_IRQ_SHIFT |GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_VCS0_IRQ_SHIFT | +GT_GEN8_WATCHDOG_INTERRUPT <<GEN8_VCS0_IRQ_SHIFT |GT_RENDER_USER_INTERRUPT <<GEN8_VCS1_IRQ_SHIFT | -GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_VCS1_IRQ_SHIFT ), - +GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_VCS1_IRQ_SHIFT | +GT_GEN8_WATCHDOG_INTERRUPT <<GEN8_VCS1_IRQ_SHIFT ),0 , (GT_RENDER_USER_INTERRUPT <<GEN8_VECS_IRQ_SHIFT |GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_VECS_IRQ_SHIFT ) }; +/* VECS watchdog is only available in skl+ */ +if (INTEL_GEN (dev_priv) >=9 ) + gt_interrupts[3 ] |=GT_GEN8_WATCHDOG_INTERRUPT ; + dev_priv->pm_ier =0x0 ; dev_priv->pm_imr = ~dev_priv->pm_ier;GEN8_IRQ_INIT_NDX (GT ,0 , ~gt_interrupts[0 ], gt_interrupts[0 ]);drivers/gpu/drm/i915/i915_reg.h +6
-0@@ -2363,6 +2363,11 @@ enum i915_power_well_id {#define RING_START (base) _MMIO((base) + 0x38)#define RING_CTL (base) _MMIO((base) + 0x3c)#define RING_CTL_SIZE (size) ((size) - PAGE_SIZE)/* in bytes -> pages */ +#define RING_CNTR (base) _MMIO((base) + 0x178) +#define GEN8_WATCHDOG_ENABLE 0 +#define GEN8_WATCHDOG_DISABLE 1 +#define GEN8_XCS_WATCHDOG_DISABLE 0xFFFFFFFF/* GEN8 & non-render only */ +#define RING_THRESH (base) _MMIO((base) + 0x17C)#define RING_SYNC_0 (base) _MMIO((base) + 0x40)#define RING_SYNC_1 (base) _MMIO((base) + 0x44)#define RING_SYNC_2 (base) _MMIO((base) + 0x48)@@ -2925,6 +2930,7 @@ enum i915_power_well_id {#define GT_BSD_USER_INTERRUPT (1 << 12)#define GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1 (1 << 11)/* hsw+; rsvd on snb, ivb, vlv */ #define GT_CONTEXT_SWITCH_INTERRUPT (1 << 8) +#define GT_GEN8_WATCHDOG_INTERRUPT (1 << 6)/* gen8+ */ #define GT_RENDER_L3_PARITY_ERROR_INTERRUPT (1 << 5)/* !snb */ #define GT_RENDER_PIPECTL_NOTIFY_INTERRUPT (1 << 4)#define GT_RENDER_CS_MASTER_ERROR_INTERRUPT (1 << 3)drivers/gpu/drm/i915/i915_reset.c +20
-0@@ -1208,6 +1208,26 @@ void i915_clear_error_registers(struct drm_i915_private *dev_priv) } } +void engine_reset_error_to_str (struct drm_i915_private *i915, +char *msg, +size_t sz, +unsigned int hung, +unsigned int stuck, +unsigned int watchdog) +{ +int len; +unsigned int tmp; +struct intel_engine_cs *engine; + + len =scnprintf (msg, sz, +"%s on " , watchdog ?"watchdog timeout" : + stuck == hung ?"no_progress" :"hang" ); +for_each_engine_masked (engine, i915, hung, tmp) + len +=scnprintf (msg + len, sz - len, +"%s, " , engine->name); + msg[len-2 ] ='\0' ; +} +/** * i915_handle_error - handle a gpu error * @i915: i915 device private drivers/gpu/drm/i915/i915_reset.h +6
-0@@ -20,6 +20,12 @@ void i915_handle_error(struct drm_i915_private *i915,u32 engine_mask, unsigned long flags, const char *fmt, ...); +void engine_reset_error_to_str (struct drm_i915_private *i915, +char *str, +size_t sz, +unsigned int hung, +unsigned int stuck, +unsigned int watchdog);#define I915_ERROR_CAPTURE BIT(0)void i915_clear_error_registers (struct drm_i915_private *i915);drivers/gpu/drm/i915/intel_engine_cs.c +1
-0@@ -1149,6 +1149,7 @@ void intel_engines_park(struct drm_i915_private *i915)/* Flush the residual irq tasklets first. */ intel_engine_disarm_breadcrumbs (engine);tasklet_kill (&engine->execlists.tasklet); +tasklet_kill (&engine->execlists.watchdog_tasklet);/* * We are committed now to parking the engines, make sure there drivers/gpu/drm/i915/intel_engine_types.h +5
-0@@ -124,6 +124,11 @@ struct intel_engine_execlists {*/ struct tasklet_struct tasklet; +/* +* @watchdog_tasklet: stop counter and reschedule hangcheck_work asap +*/ +struct tasklet_struct watchdog_tasklet; +/** * @default_priolist: priority list for I915_PRIORITY_NORMAL */ drivers/gpu/drm/i915/intel_hangcheck.c +2
-9@@ -220,22 +220,15 @@ static void hangcheck_declare_hang(struct drm_i915_private *i915,unsigned int hung, unsigned int stuck) { -struct intel_engine_cs *engine; char msg[80]; -unsigned int tmp; -int len; +size_t len =sizeof (msg);/* If some rings hung but others were still busy, only * blame the hanging rings in the synopsis. */ if (stuck != hung) hung &= ~stuck; - len =scnprintf (msg,sizeof (msg), -"%s on " , stuck == hung ?"no progress" :"hang" ); -for_each_engine_masked (engine, i915, hung, tmp) - len +=scnprintf (msg + len,sizeof (msg) - len, -"%s, " , engine->name); - msg[len-2 ] ='\0' ; +engine_reset_error_to_str (i915, msg, len, hung, stuck,0 );return i915_handle_error (i915, hung,I915_ERROR_CAPTURE ,"%s" , msg); }drivers/gpu/drm/i915/intel_lrc.c +49
-0@@ -2195,6 +2195,40 @@ static int gen8_emit_flush_render(struct i915_request *request,return 0 ; } +static void gen8_watchdog_tasklet (unsigned long data) +{ +struct intel_engine_cs *engine = (struct intel_engine_cs *)data; +struct drm_i915_private *dev_priv = engine->i915; +enum forcewake_domains fw_domains; +char msg[80 ]; +size_t len =sizeof (msg); +unsigned long *lock = &engine->i915->gpu_error.flags; +unsigned int bit =I915_RESET_ENGINE + engine->id; + +switch (engine->class) { +default : +MISSING_CASE (engine->id); +/* fall through */ +case RENDER_CLASS : + fw_domains =FORCEWAKE_RENDER ; +break ; +case VIDEO_DECODE_CLASS : +case VIDEO_ENHANCEMENT_CLASS : + fw_domains =FORCEWAKE_MEDIA ; +break ; + } + +intel_uncore_forcewake_get (dev_priv, fw_domains); + +if (!test_and_set_bit (bit, lock)) { +unsigned int hung = engine->mask; +engine_reset_error_to_str (dev_priv, msg, len, hung,0 ,1 ); +i915_reset_engine (engine, msg); +clear_bit (bit, lock); +wake_up_bit (lock, bit); + } +} +/* * Reserve space for 2 NOOPs at the end of each request to be * used as a workaround for not being allowed to do lite @@ -2377,6 +2411,21 @@ logical_ring_default_irqs(struct intel_engine_cs *engine) engine->irq_enable_mask =GT_RENDER_USER_INTERRUPT << shift; engine->irq_keep_mask =GT_CONTEXT_SWITCH_INTERRUPT << shift; + +switch (engine->class) { +default : +/* BCS engine does not support hw watchdog */ +break ; +case RENDER_CLASS : +case VIDEO_DECODE_CLASS : + engine->irq_keep_mask |=GT_GEN8_WATCHDOG_INTERRUPT << shift; +break ; +case VIDEO_ENHANCEMENT_CLASS : +if (INTEL_GEN (engine->i915) >=9 ) + engine->irq_keep_mask |= +GT_GEN8_WATCHDOG_INTERRUPT << shift; +break ; + } } static int
drivers/gpu/drm/i915/intel_lrc.c logical_ring_setup(struct intel_engine_cs *engine) · line 2451
Quoted 9 lines
drivers/gpu/drm/i915/intel_lrc.c +3
-0@@ -2394,6 +2443,9 @@ logical_ring_setup(struct intel_engine_cs *engine)tasklet_init (&engine->execlists.tasklet, execlists_submission_tasklet, (unsigned long )engine); +tasklet_init (&engine->execlists.watchdog_tasklet, + gen8_watchdog_tasklet, (unsigned long )engine); +logical_ring_default_vfuncs (engine);logical_ring_default_irqs (engine);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 2/5] drm/i915: Watchdog timeout: IRQ handler for gen8+
Quoted 137 lines · Tvrtko Ursulin
Quoted 132 lines · Carlos Santa
From: Michel Thierry <[email protected]>
*** General ***
Watchdog timeout (or "media engine reset") is a feature that allows userland applications to enable hang detection on individual batch buffers.
The detection mechanism itself is mostly bound to the hardware and the only
thing that the driver needs to do to support this form of hang detection
is to implement the interrupt handling support as well as watchdog command
emission before and after the emitted batch buffer start instruction in the
ring buffer.The principle of the hang detection mechanism is as follows:
1. Once the decision has been made to enable watchdog timeout for a particular batch buffer and the driver is in the process of emitting the
batch buffer start instruction into the ring buffer it also emits a watchdog timer start instruction before and a watchdog timer cancellation
instruction after the batch buffer start instruction in the ring buffer.2. Once the GPU execution reaches the watchdog timer start instruction
the hardware watchdog counter is started by the hardware. The counter
keeps counting until either reaching a previously configured threshold
value or the timer cancellation instruction is executed.2a. If the counter reaches the threshold value the hardware fires a watchdog interrupt that is picked up by the watchdog interrupt handler.
This means that a hang has been detected and the driver needs to deal with
it the same way it would deal with a engine hang detected by the periodic
hang checker. The only difference between the two is that we already blamed
the active request (to ensure an engine reset).2b. If the batch buffer completes and the execution reaches the watchdog
cancellation instruction before the watchdog counter reaches its threshold value the watchdog is cancelled and nothing more comes of it.
No hang is detected.Note about future interaction with preemption: Preemption could happen
in a command sequence prior to watchdog counter getting disabled, resulting in watchdog being triggered following preemption (e.g. when
watchdog had been enabled in the low priority batch). The driver will
need to explicitly disable the watchdog counter as part of the preemption sequence.*** This patch introduces: ***
1. IRQ handler code for watchdog timeout allowing direct hang recovery
based on hardware-driven hang detection, which then integrates directly
with the hang recovery path. This is independent of having per- engine reset
or just full gpu reset.2. Watchdog specific register information.
Currently the render engine and all available media engines support watchdog timeout (VECS is only supported in GEN9). The specifications elude
to the BCS engine being supported but that is currently not supported by
this commit.Note that the value to stop the counter is different between render and
non-render engines in GEN8; GEN9 onwards it's the same.v2: Move irq handler to tasklet, arm watchdog for a 2nd time to check
against false-positives.v3: Don't use high priority tasklet, use
engine_last_submitwhile checking for false-positives. From GEN9 onwards, the stop counter bit is
the same for all engines.v4: Remove unnecessary brackets, use
current_seqnoto mark the request
as guilty in the hangcheck/capture code.v5: Rebased after
RESET_ENGINEsflag.v6: Don't capture error state in case of watchdog timeout. The capture
process is time consuming and this will align to what happens when we
use GuC to handle the watchdog timeout. (Chris)v7: Rebase.
v8: Rebase, use HZ to reschedule.
v9: Rebase, get forcewake domains in function (no longer in execlists
struct).v10: Rebase.
v11: Rebase,
remove extra braces (Tvrtko),
implementwatchdog_to_clock_countshelper (Tvrtko), Movetasklet_kill(watchdog_tasklet)insideintel_engines
(Tvrtko),
Use a global heartbeat seqno instead of engine seqno (Chris) Make all engines checks all class based checks (Tvrtko)v12: Rebase,
Reset immediately upon entering the IRQ (Chris) Makereset_engine_to_stra helper (Tvrtko) Renamewatchdog_irq_handleraswatchdog_tasklet(Tvrtko) Let the compiler itself do the inline (Tvrtko)Quoted 3 lines
v13: Rebase
v14: Rebase, skip checking for the guilty seqno in the tasklet (Tvrtko)
Quoted 7 lines
IIRC I only asked about it so I guess you tried it and it works well?
Can you also post the IGTs so we can see the test coverage?
Regards,
Tvrtko
Yeah, the unit test works but it's still the very simple one (updated for the uAPI mods) I started with last August, I still need to add more to it though...
https://lists.freedesktop.org/archives/igt-dev/2018-September/005834.html
Right now, I am on the hrtimer workaround to see how that works, will get back to the test coverage after that...
Regards,
Carlos
Quoted 321 lines
Quoted 321 lines
Cc Antonio Argenziano <[email protected]>Cc Tvrtko Ursulin <[email protected]>Signed-off-by Michel Thierry <[email protected]>Signed-off-by Carlos Santa <[email protected]>--- drivers/gpu/drm/i915/i915_gpu_error.h | 4 ++ drivers/gpu/drm/i915/i915_irq.c | 14 ++++-- drivers/gpu/drm/i915/i915_reg.h | 6 +++ drivers/gpu/drm/i915/i915_reset.c | 20 +++++++++ drivers/gpu/drm/i915/i915_reset.h | 6 +++ drivers/gpu/drm/i915/intel_engine_cs.c | 1 + drivers/gpu/drm/i915/intel_engine_types.h | 5 +++ drivers/gpu/drm/i915/intel_hangcheck.c | 11 +---- drivers/gpu/drm/i915/intel_lrc.c | 52 +++++++++++++++++++++++ 9 files changed, 107 insertions(+), 12 deletions(-)drivers/gpu/drm/i915/i915_gpu_error.h +0
-0@@ -203,6 +203,9 @@ struct i915_gpu_error {* any global resources that may be clobber by the reset (such as
* FENCE registers).
*drivers/gpu/drm/i915/i915_gpu_error.h +1
-0+* #I915_RESET_WATCHDOG - When hw detects a hang before us, we can use
drivers/gpu/drm/i915/i915_gpu_error.h +1
-0+* I915_RESET_WATCHDOG to report the hang detection cause accurately.
drivers/gpu/drm/i915/i915_gpu_error.h +1
-0+* * #I915_RESET_ENGINE[num_engines] - Since the driver doesn't need to
* acquire thestruct_mutexto reset an engine, we need an
explicit
* flag to prevent two concurrent reset attempts in the same
engine.drivers/gpu/drm/i915/i915_gpu_error.h +1
-0@@ -218,6 +221,7 @@ struct i915_gpu_error {#define I915_RESET_BACKOFF 0#define I915_RESET_MODESET 1#define I915_RESET_ENGINE 2 +#define I915_RESET_WATCHDOG 3#define I915_WEDGED (BITS_PER_LONG - 1)/** Number of times the device has been reset (global) */ drivers/gpu/drm/i915/i915_irq.c +3
-0@@ -1466,6 +1466,9 @@ gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir)if (tasklet)tasklet_hi_schedule (&engine->execlists.tasklet); + +if (iir >_GEN8_WATCHDOG_INTERRUPT ) +tasklet_schedule (&engine->execlists.watchdog_tasklet); }static void gen8_gt_irq_ack(struct
drm_i915_private*i915,drivers/gpu/drm/i915/i915_irq.c +8
-3@@ -3892,20 +3895,25 @@ static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv) u32 gt_interrupts[] = { (GT_RENDER_USER_INTERRUPT <<GEN8_RCS_IRQ_SHIFT |GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_RCS_IRQ_SHIFT | +GT_GEN8_WATCHDOG_INTERRUPT <<GEN8_RCS_IRQ_SHIFT |GT_RENDER_USER_INTERRUPT <<GEN8_BCS_IRQ_SHIFT |GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_BCS_IRQ_SHIFT ), - (GT_RENDER_USER_INTERRUPT <<GEN8_VCS0_IRQ_SHIFT |GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_VCS0_IRQ_SHIFT | +GT_GEN8_WATCHDOG_INTERRUPT <<GEN8_VCS0_IRQ_SHIFT |GT_RENDER_USER_INTERRUPT <<GEN8_VCS1_IRQ_SHIFT | -GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_VCS1_IRQ_SHIFT ), - +GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_VCS1_IRQ_SHIFT | +GT_GEN8_WATCHDOG_INTERRUPT <<GEN8_VCS1_IRQ_SHIFT ),0 , (GT_RENDER_USER_INTERRUPT <<GEN8_VECS_IRQ_SHIFT |GT_CONTEXT_SWITCH_INTERRUPT <<GEN8_VECS_IRQ_SHIFT ) }; +/* VECS watchdog is only available in skl+ */ +if (INTEL_GEN (dev_priv) >=9 ) + gt_interrupts[3 ] |=GT_GEN8_WATCHDOG_INTERRUPT ; + dev_priv->pm_ier =0x0 ; dev_priv->pm_imr = ~dev_priv->pm_ier;GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);drivers/gpu/drm/i915/i915_reg.h +0
-0@@ -2363,6 +2363,11 @@ enum i915_power_well_id {#define RING_START (base) _MMIO((base) + 0x38)#define RING_CTL (base) _MMIO((base) + 0x3c)#define RING_CTL_SIZE (size) ((size) - PAGE_SIZE)/* in bytes -> pages */
drivers/gpu/drm/i915/i915_reg.h +4
-0+#define RING_CNTR (base) _MMIO((base) + 0x178) +#define GEN8_WATCHDOG_ENABLE 0 +#define GEN8_WATCHDOG_DISABLE 1 +#define GEN8_XCS_WATCHDOG_DISABLE 0xFFFFFFFF/* GEN8 & non-render only */
drivers/gpu/drm/i915/i915_reg.h +1
-0+#define RING_THRESH (base) _MMIO((base) + 0x17C)#define RING_SYNC_0 (base) _MMIO((base) + 0x40)#define RING_SYNC_1 (base) _MMIO((base) + 0x44)#define RING_SYNC_2 (base) _MMIO((base) + 0x48)@@ -2925,6 +2930,7 @@ enum i915_power_well_id {#define GT_BSD_USER_INTERRUPT (1 << 12)#define GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1 (1 << 11)/* hsw+; rsvd on snb, ivb, vlv */
#defineGT_CONTEXT_SWITCH_INTERRUPT(1 << 8)
+#defineGT_GEN8_WATCHDOG_INTERRUPT(1 << 6) /* gen8+ */
#defineGT_RENDER_L3_PARITY_ERROR_INTERRUPT(1 << 5) /*
!snb */
#defineGT_RENDER_PIPECTL_NOTIFY_INTERRUPT(1 << 4)
#defineGT_RENDER_CS_MASTER_ERROR_INTERRUPT(1 << 3)drivers/gpu/drm/i915/i915_reset.c +20
-0@@ -1208,6 +1208,26 @@ void i915_clear_error_registers(struct drm_i915_private *dev_priv) } } +void engine_reset_error_to_str (struct drm_i915_private *i915, +char *msg, +size_t sz, +unsigned int hung, +unsigned int stuck, +unsigned int watchdog) +{ +int len; +unsigned int tmp; +struct intel_engine_cs *engine; + + len =scnprintf (msg, sz, +"%s on " , watchdog ?"watchdog timeout" : + stuck == hung ?"no_progress" :"hang" ); +for_each_engine_masked (engine, i915, hung, tmp) + len +=scnprintf (msg + len, sz - len, +"%s, " , engine->name); + msg[len-2 ] ='\0' ; +} +/** *
i915_handle_error- handle a gpu error
* @i915: i915 device privatedrivers/gpu/drm/i915/i915_reset.h +6
-0@@ -20,6 +20,12 @@ void i915_handle_error(struct drm_i915_private *i915, u32 engine_mask, unsigned long flags, const char *fmt, ...); +void engine_reset_error_to_str (struct drm_i915_private *i915, +char *str, +size_t sz, +unsigned int hung, +unsigned int stuck, +unsigned int watchdog);#define I915_ERROR_CAPTURE BIT(0)void i915_clear_error_registers(struct drm_i915_private *i915);drivers/gpu/drm/i915/intel_engine_cs.c +1
-0@@ -1149,6 +1149,7 @@ void intel_engines_park(struct drm_i915_private *i915)/* Flush the residual irq tasklets first. */ intel_engine_disarm_breadcrumbs (engine );tasklet_kill (&engine->execlists.tasklet); +tasklet_kill (&engine->execlists.watchdog_tasklet);/* * We are committed now to parking the engines, make
sure theredrivers/gpu/drm/i915/intel_engine_types.h +2
-0@@ -124,6 +124,11 @@ struct intel_engine_execlists {*/ struct tasklet_struct tasklet; +/* +* @watchdog_tasklet: stop counter and reschedule
hangcheck_workasapdrivers/gpu/drm/i915/intel_engine_types.h +3
-0+*/ +struct tasklet_struct watchdog_tasklet; +/** * @default_priolist: priority list for I915_PRIORITY_NORMAL */ drivers/gpu/drm/i915/intel_hangcheck.c +2
-9@@ -220,22 +220,15 @@ static void hangcheck_declare_hang(structdrm_i915_private *i915, unsigned int hung, unsigned int stuck) { - struct intel_engine_cs *engine; char msg[80]; -unsigned int tmp; -int len; +size_t len =sizeof (msg);/* If some rings hung but others were still busy, only * blame the hanging rings in the synopsis. */ if (stuck != hung) hung &= ~stuck; - len =scnprintf (msg,sizeof (msg), -"%s on " , stuck == hung ?"no progress" : "hang"); -for_each_engine_masked (engine, i915, hung, tmp) - len +=scnprintf (msg + len,sizeof (msg) - len, -"%s, " , engine->name); - msg[len-2 ] ='\0' ; +engine_reset_error_to_str (i915, msg, len, hung, stuck,0 );return i915_handle_error(i915, hung,
I915_ERROR_CAPTURE, "%s",
msg);
}drivers/gpu/drm/i915/intel_lrc.c +34
-0@@ -2195,6 +2195,40 @@ static int gen8_emit_flush_render(structi915_request *request, return 0; } +static void gen8_watchdog_tasklet (unsigned long data) +{ +struct intel_engine_cs *engine = (struct intel_engine_cs *)data; +struct drm_i915_private *dev_priv = engine->i915; +enum forcewake_domains fw_domains; +char msg[80 ]; +size_t len =sizeof (msg); +unsigned long *lock = &engine->i915->gpu_error.flags; +unsigned int bit =I915_RESET_ENGINE + engine->id; + +switch (engine->class) { +default : +MISSING_CASE (engine->id); +/* fall through */ +case RENDER_CLASS : + fw_domains =FORCEWAKE_RENDER ; +break ; +case VIDEO_DECODE_CLASS : +case VIDEO_ENHANCEMENT_CLASS : + fw_domains =FORCEWAKE_MEDIA ; +break ; + } + +intel_uncore_forcewake_get (dev_priv, fw_domains); + +if (!test_and_set_bit (bit, lock)) { +unsigned int hung = engine->mask; +engine_reset_error_to_str (dev_priv, msg, len, hung,0 ,1 ); +i915_reset_engine (engine, msg); +clear_bit (bit, lock); +wake_up_bit (lock, bit); + } +} +/*
* Reserve space for 2 NOOPs at the end of each request to be
* used as a workaround for not being allowed to do litedrivers/gpu/drm/i915/intel_lrc.c +15
-0@@ -2377,6 +2411,21 @@ logical_ring_default_irqs(struct intel_engine_cs *engine) engine->irq_enable_mask = GT_RENDER_USER_INTERRUPT << shift; engine->irq_keep_mask =GT_CONTEXT_SWITCH_INTERRUPT << shift; + +switch (engine->class) { +default : +/* BCS engine does not support hw watchdog */ +break ; +case RENDER_CLASS : +case VIDEO_DECODE_CLASS : + engine->irq_keep_mask |=GT_GEN8_WATCHDOG_INTERRUPT << shift; +break ; +case VIDEO_ENHANCEMENT_CLASS : +if (INTEL_GEN (engine->i915) >=9 ) + engine->irq_keep_mask |= +GT_GEN8_WATCHDOG_INTERRUPT << shift; +break ; + } }static int
drivers/gpu/drm/i915/intel_lrc.c +0
-0@@ -2394,6 +2443,9 @@ logical_ring_setup(struct intel_engine_cs *engine)tasklet_init (&engine->execlists.tasklet, execlists_submission_tasklet, (unsigned long )engine);
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/intel_lrc.c +3
-0+tasklet_init (&engine->execlists.watchdog_tasklet, + gen8_watchdog_tasklet, (unsigned long )engine); +logical_ring_default_vfuncs (engine);logical_ring_default_irqs(engine);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 2/5] drm/i915: Watchdog timeout: IRQ handler for gen8+
On 27/03/2019 01:58, Carlos Santa wrote:
[snip]
Quoted 17 lines
Quoted 11 lines
Quoted 3 lines
v13: Rebase
v14: Rebase, skip checking for the guilty seqno in the tasklet (Tvrtko)IIRC I only asked about it so I guess you tried it and it works well?
Can you also post the IGTs so we can see the test coverage?
Regards,
Tvrtko
Yeah, the unit test works but it's still the very simple one (updated for the uAPI mods) I started with last August, I still need to add more to it though...
Quoted 4 lines
https://lists.freedesktop.org/archives/igt-dev/2018-September/005834.html
Right now, I am on the hrtimer workaround to see how that works, will get back to the test coverage after that...
It may be tricky though so it may make sense to extend the test first until you can make a test which fails with the hw watchdog implementation. :)
What are the test cases I can think of..
Probably could use fence status to figure out which context was reset, and could use spin batches with userspace timers to control durations. And corking to control ordering. Then you need some preemption (priorities). A mix of batches on contexts with and without the watchdog and checking the expected one was reset.
ctx = create_context
long batch -> executed
ctx.set_watchdog
ctx.long batch -> canceled
ctx2.long_batch
ctx.long_batch
-> executed, canceled
ctx.long_batch
ctx2.long_batch
-> canceled, executed
(Hm maybe you end up having to use nop calibrated batches to make the last one work.)
ctx.batch_just_below_threshold -> executed
(Try a few times in a loop, or a bunch of batches like this one submitted at once and check all executed.)
Then expand and submit one random one of them as over threshold and check only that one was canceled.
Flavour of the above with two contexts, one with watchdog, one without.
Flavour where watchdog is set only on some engines. Single context, batches on different engines = different watchog behaviour.
Then preemption handling.. submit a long batch and after half of expected runtime submit a higher prio batch with half duration. Check the latter was executed. Then check the status of the former. What should it be? (Don't know, open to define the semantics..)
Submit a low prio long batch, wo/ watchdog, then a higher prio with watchdog and check it was canceled before the low prio one completed.
This is how much I can think of right now, but should be a good start.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 3/5 drm/i915: Watchdog timeout: Ringbuffer command emission for gen8+
In reply to Carlos SantaFrom: Michel Thierry <[email protected]>
Emit the required commands into the ring buffer for starting and stopping the watchdog timer before/after batch buffer start during batch buffer submission.
v2: Support watchdog threshold per context engine, merge lri commands, and move watchdog commands emission to emit_bb_start. Request space of combined start_watchdog, bb_start and stop_watchdog to avoid any error after emitting bb_start.
v3: There were too many req->engine in emit_bb_start.
Use GEM_BUG_ON instead of returning a very late EINVAL in the remote case of watchdog misprogramming; set correct LRI cmd size in emit_stop_watchdog. (Chris)
v4: Rebase.
v5: use to_intel_context instead of ctx->engine.
v6: Rebase.
v7: Rebase,
Store gpu watchdog capability in engine flag (Tvrtko) Store WATCHDOG_DISABLE magic # in engine (Tvrtko)
No need to declare emit_{start|stop}_watchdog as vfuncs (Tvrtko) Replace flag watchdog_running with enable_watchdog (Tvrtko) Emit a single MI_NOOP by conditionally checking whether the # of emitted OPs is odd (Tvrtko)
v8: Rebase
--- drivers/gpu/drm/i915/intel_context_types.h | 4 + drivers/gpu/drm/i915/intel_engine_cs.c | 2 + drivers/gpu/drm/i915/intel_engine_types.h | 17 ++++- drivers/gpu/drm/i915/intel_lrc.c | 89 +++++++++++++++++++++- drivers/gpu/drm/i915/intel_lrc.h | 2 + 5 files changed, 106 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/intel_context_types.h +4 -0
@@ -51,6 +51,10 @@ struct intel_context {u64 lrc_desc;atomic_t pin_count; +/** watchdog_threshold: hw watchdog threshold value, +* in clock counts +*/ +u32 watchdog_threshold;struct mutex pin_mutex;/* guards pinning and associated on-gpuing */ /**
drivers/gpu/drm/i915/intel_engine_cs.c +2 -0
@@ -324,6 +324,8 @@ intel_engine_setup(struct drm_i915_private *dev_priv,if (engine->context_size)DRIVER_CAPS (dev_priv)->has_logical_contexts = true; + engine->watchdog_disable_id =get_watchdog_disable (engine); +/* Nothing to do here, execute in order of dependencies */ engine->schedule =NULL ;
drivers/gpu/drm/i915/intel_engine_types.h +13 -4
@@ -260,6 +260,7 @@ struct intel_engine_cs {unsigned int guc_id;intel_engine_mask_t mask; +u32 watchdog_disable_id;u8 uabi_class;u8 class;
@@ -422,10 +423,12 @@ struct intel_engine_cs {struct intel_engine_hangcheck hangcheck; -#define I915_ENGINE_NEEDS_CMD_PARSER BIT(0) -#define I915_ENGINE_SUPPORTS_STATS BIT(1) -#define I915_ENGINE_HAS_PREEMPTION BIT(2) -#define I915_ENGINE_HAS_SEMAPHORES BIT(3) +#define I915_ENGINE_NEEDS_CMD_PARSER BIT(0) +#define I915_ENGINE_SUPPORTS_STATS BIT(1) +#define I915_ENGINE_HAS_PREEMPTION BIT(2) +#define I915_ENGINE_HAS_SEMAPHORES BIT(3) +#define I915_ENGINE_SUPPORTS_WATCHDOG BIT(4) +unsigned int flags;/*
@@ -509,6 +512,12 @@ intel_engine_has_semaphores(const struct intel_engine_cs *engine)return engine->flags &I915_ENGINE_HAS_SEMAPHORES ; } +static inline bool +intel_engine_supports_watchdog (const struct intel_engine_cs *engine) +{ +return engine->flags &I915_ENGINE_SUPPORTS_WATCHDOG ; +} +#define instdone_slice_mask (dev_priv__) \ (IS_GEN(dev_priv__, 7) ? \ 1 : RUNTIME_INFO(dev_priv__)->sseu.slice_mask)
drivers/gpu/drm/i915/intel_lrc.c +85 -4
142 lines not on this page · raw message
drivers/gpu/drm/i915/intel_lrc.h +2 -0
@@ -114,4 +114,6 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine,u32 gen8_make_rpcs (struct drm_i915_private *i915,struct intel_sseu *ctx_sseu); +u32 get_watchdog_disable (struct intel_engine_cs *engine); +#endif /* _INTEL_LRC_H_ */
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 3/5] drm/i915: Watchdog timeout: Ringbuffer command emission for gen8+
Quoting Carlos Santa (2019-03-22 23:41:16)
Quoted 10 lines
static int gen8_emit_bb_start(struct
i915_request*rq,
u64 offset, u32 len, const unsigned int flags)
{drivers/gpu/drm/i915/intel_lrc.c +5
-0+struct intel_engine_cs *engine = rq->engine; +struct i915_gem_context *ctx = rq->gem_context; +struct intel_context *ce =intel_context_lookup (ctx, engine);u32 *cs; +u32 num_dwords; +bool enable_watchdog = false;
drivers/gpu/drm/i915/intel_lrc.c static void execlists_reset_finish(struct intel_engine_cs *engine) · line 2096
Quoted 10 lines
drivers/gpu/drm/i915/intel_lrc.c +8
-1- cs =intel_ring_begin (rq,6 ); +/* bb_start only */ + num_dwords =6 ; + +/* check if watchdog will be required */ +if (ce->watchdog_threshold !=0 ) { +/* + start_watchdog (6) + stop_watchdog (4) */ + num_dwords +=10 ; + enable_watchdog = true;
What do you do about the recommendation not to enable the watchdog across semaphores inside user batches? Is that caveat made clear in the uAPI docs?
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 3/5] drm/i915: Watchdog timeout: Ringbuffer command emission for gen8+
In reply to Carlos SantaQuoting Carlos Santa (2019-03-22 23:41:16)
Quoted 5 lines
From: Michel Thierry <[email protected]>
Emit the required commands into the ring buffer for starting and stopping the watchdog timer before/after batch buffer start during batch buffer submission.
I'm expecting to see some discussion of how this is handled across preemption here since you are inside an arbitration enabled section.
Quoted 40 lines
v2: Support watchdog threshold per context engine, merge lri commands, and move watchdog commands emission to
emit_bb_start. Request space of combinedstart_watchdog,bb_startandstop_watchdogto avoid any error after emittingbb_start.v3: There were too many
req->engineinemit_bb_start.
UseGEM_BUG_ONinstead of returning a very late EINVAL in the remote case of watchdog misprogramming; set correct LRI cmd size inemit_stop_watchdog. (Chris)v4: Rebase.
v5: useto_intel_contextinstead ofctx->engine.
v6: Rebase.
v7: Rebase,
Store gpu watchdog capability in engine flag (Tvrtko) StoreWATCHDOG_DISABLEmagic # in engine (Tvrtko)
No need to declare emit_{start|stop}_watchdog as vfuncs (Tvrtko) Replace flagwatchdog_runningwithenable_watchdog(Tvrtko) Emit a singleMI_NOOPby conditionally checking whether the # of emitted OPs is odd (Tvrtko)
v8: RebaseCc Chris Wilson <[email protected]>Cc Antonio Argenziano <[email protected]>Cc Tvrtko Ursulin <[email protected]>Signed-off-by Michel Thierry <[email protected]>Signed-off-by Carlos Santa <[email protected]>--- drivers/gpu/drm/i915/intel_context_types.h | 4 + drivers/gpu/drm/i915/intel_engine_cs.c | 2 + drivers/gpu/drm/i915/intel_engine_types.h | 17 ++++- drivers/gpu/drm/i915/intel_lrc.c | 89 +++++++++++++++++++++- drivers/gpu/drm/i915/intel_lrc.h | 2 + 5 files changed, 106 insertions(+), 8 deletions(-)drivers/gpu/drm/i915/intel_context_types.h +0
-0
drivers/gpu/drm/i915/intel_context_types.h struct intel_context { · line 56
Quoted 6 lines
drivers/gpu/drm/i915/intel_context_types.h +3
-0@@ -51,6 +51,10 @@ struct intel_context {u64 lrc_desc;atomic_t pin_count; +/** watchdog_threshold: hw watchdog threshold value, +* in clock counts +*/
Gah. Why would you put it here? Between a tightly coupled count + mutex.
Quoted 22 lines
drivers/gpu/drm/i915/intel_context_types.h +1
-0+u32 watchdog_threshold;struct mutex pin_mutex;/* guards pinning and associated on-gpuing */ /** drivers/gpu/drm/i915/intel_engine_cs.c +2
-0@@ -324,6 +324,8 @@ intel_engine_setup(struct drm_i915_private *dev_priv,if (engine->context_size)DRIVER_CAPS (dev_priv)->has_logical_contexts = true; + engine->watchdog_disable_id =get_watchdog_disable (engine); +/* Nothing to do here, execute in order of dependencies */ engine->schedule =NULL ;drivers/gpu/drm/i915/intel_engine_types.h +0
-0
drivers/gpu/drm/i915/intel_engine_types.h struct intel_engine_cs { · line 263
Quoted 4 lines
drivers/gpu/drm/i915/intel_engine_types.h +1
-0@@ -260,6 +260,7 @@ struct intel_engine_cs {unsigned int guc_id;intel_engine_mask_t mask; +u32 watchdog_disable_id;
You've just put this between a pair of u8s.
Quoted 53 lines
drivers/gpu/drm/i915/intel_engine_types.h +12
-4u8 uabi_class;u8 class;@@ -422,10 +423,12 @@ struct intel_engine_cs {struct intel_engine_hangcheck hangcheck; -#define I915_ENGINE_NEEDS_CMD_PARSER BIT(0) -#define I915_ENGINE_SUPPORTS_STATS BIT(1) -#define I915_ENGINE_HAS_PREEMPTION BIT(2) -#define I915_ENGINE_HAS_SEMAPHORES BIT(3) +#define I915_ENGINE_NEEDS_CMD_PARSER BIT(0) +#define I915_ENGINE_SUPPORTS_STATS BIT(1) +#define I915_ENGINE_HAS_PREEMPTION BIT(2) +#define I915_ENGINE_HAS_SEMAPHORES BIT(3) +#define I915_ENGINE_SUPPORTS_WATCHDOG BIT(4) +unsigned int flags;/* @@ -509,6 +512,12 @@ intel_engine_has_semaphores(const struct intel_engine_cs *engine)return engine->flags &I915_ENGINE_HAS_SEMAPHORES ; } +static inline bool +intel_engine_supports_watchdog (const struct intel_engine_cs *engine) +{ +return engine->flags &I915_ENGINE_SUPPORTS_WATCHDOG ; +} +#define instdone_slice_mask (dev_priv__) \ (IS_GEN(dev_priv__, 7) ? \ 1 : RUNTIME_INFO(dev_priv__)->sseu.slice_mask)drivers/gpu/drm/i915/intel_lrc.c +12
-0@@ -2036,16 +2036,75 @@ static void execlists_reset_finish(struct intel_engine_cs *engine) atomic_read(&execlists->tasklet.count)); } +static u32 *gen8_emit_start_watchdog (struct i915_request *rq,u32 *cs) +{ +struct intel_engine_cs *engine = rq->engine; +struct i915_gem_context *ctx = rq->gem_context; +struct intel_context *ce =intel_context_lookup (ctx, engine); + +GEM_BUG_ON (!intel_engine_supports_watchdog (engine)); + +/* +* watchdog register must never be programmed to zero. This would +* cause the watchdog counter to exceed and not allow the engine to +* go into IDLE state
drivers/gpu/drm/i915/intel_lrc.c static void execlists_reset_finish(struct intel_engine_cs *engine) · line 2060
Quoted 10 lines
drivers/gpu/drm/i915/intel_lrc.c +10
-0+*/ +GEM_BUG_ON (ce->watchdog_threshold ==0 ); + +/* Set counter period */ + *cs++ =MI_LOAD_REGISTER_IMM (2 ); + *cs++ =i915_mmio_reg_offset (RING_THRESH (engine->mmio_base)); + *cs++ = ce->watchdog_threshold; +/* Start counter */ + *cs++ =i915_mmio_reg_offset (RING_CNTR (engine->mmio_base)); + *cs++ =GEN8_WATCHDOG_ENABLE ;
Hmm, so no watchdog seqno.
Quoted 13 lines
drivers/gpu/drm/i915/intel_lrc.c +13
-0+return cs; +} + +static u32 *gen8_emit_stop_watchdog (struct i915_request *rq,u32 *cs) +{ +struct intel_engine_cs *engine = rq->engine; + +GEM_BUG_ON (!intel_engine_supports_watchdog (engine)); + + *cs++ =MI_LOAD_REGISTER_IMM (1 ); + *cs++ =i915_mmio_reg_offset (RING_CNTR (engine->mmio_base)); + *cs++ = engine->watchdog_disable_id; +
drivers/gpu/drm/i915/intel_lrc.c static void execlists_reset_finish(struct intel_engine_cs *engine) · line 2084
Quoted 10 lines
drivers/gpu/drm/i915/intel_lrc.c +6
-0+return cs; +} +static int gen8_emit_bb_start (struct i915_request *rq,u64 offset,u32 len,const unsigned int flags) { +struct intel_engine_cs *engine = rq->engine; +struct i915_gem_context *ctx = rq->gem_context; +struct intel_context *ce =intel_context_lookup (ctx, engine);
Ahem. This keeps on getting worse.
Quoted 11 lines
drivers/gpu/drm/i915/intel_lrc.c +8
-1u32 *cs; +u32 num_dwords; +bool enable_watchdog = false; - cs =intel_ring_begin (rq,6 ); +/* bb_start only */ + num_dwords =6 ; + +/* check if watchdog will be required */ +if (ce->watchdog_threshold !=0 ) { +/* + start_watchdog (6) + stop_watchdog (4) */
drivers/gpu/drm/i915/intel_lrc.c static void execlists_reset_finish(struct intel_engine_cs *engine) · line 2104
Quoted 10 lines
drivers/gpu/drm/i915/intel_lrc.c +7
-0+ num_dwords +=10 ; + enable_watchdog = true; + } + + cs =intel_ring_begin (rq, num_dwords);if (IS_ERR (cs))return PTR_ERR (cs); +if (enable_watchdog) { +/* Start watchdog timer */
Please don't simply repeat code in comments.
Quoted 10 lines
drivers/gpu/drm/i915/intel_lrc.c +3
-0+ cs =gen8_emit_start_watchdog (rq, cs); + } +/* * WaDisableCtxRestoreArbitration:bdw,chv * @@ -2072,10 +2131,16 @@ static int gen8_emit_bb_start(struct i915_request *rq, *cs++ =upper_32_bits (offset); *cs++ =MI_ARB_ON_OFF |MI_ARB_DISABLE ;
drivers/gpu/drm/i915/intel_lrc.c static int gen8_emit_bb_start(struct i915_request *rq, · line 2141
Quoted 10 lines
drivers/gpu/drm/i915/intel_lrc.c +7
-2- *cs++ =MI_NOOP ; -intel_ring_advance (rq, cs); +if (enable_watchdog) { +/* Cancel watchdog timer */ + cs =gen8_emit_stop_watchdog (rq, cs); + } + +if (*cs%2 !=0 ) + *cs++ =MI_NOOP ;
This is wrong. cs points into the unset portion of the ring. The watchdog commands are even, so there is no reason to move the original NOOP, or at least no reason to make it conditional.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 3/5] drm/i915: Watchdog timeout: Ringbuffer command emission for gen8+
Quoted 194 lines · Chris Wilson
Quoting Carlos Santa (2019-03-22 23:41:16)
Quoted 5 lines
From: Michel Thierry <[email protected]>
Emit the required commands into the ring buffer for starting and stopping the watchdog timer before/after batch buffer start during batch buffer submission.
I'm expecting to see some discussion of how this is handled across preemption here since you are inside an arbitration enabled section.
Quoted 47 lines
v2: Support watchdog threshold per context engine, merge lri commands,
and move watchdog commands emission toemit_bb_start. Request space of
combinedstart_watchdog,bb_startandstop_watchdogto avoid any error
after emittingbb_start.v3: There were too many
req->engineinemit_bb_start. UseGEM_BUG_ONinstead of returning a very late EINVAL in the remote
case of watchdog misprogramming; set correct LRI cmd size inemit_stop_watchdog. (Chris)v4: Rebase.
v5: useto_intel_contextinstead ofctx->engine.
v6: Rebase.
v7: Rebase,
Store gpu watchdog capability in engine flag (Tvrtko) StoreWATCHDOG_DISABLEmagic # in engine (Tvrtko) No need to declare emit_{start|stop}_watchdog as vfuncs
(Tvrtko)
Replace flagwatchdog_runningwithenable_watchdog(Tvrtko) Emit a singleMI_NOOPby conditionally checking whether the # of emitted OPs is odd (Tvrtko)
v8: RebaseCc Chris Wilson <[email protected]>Cc Antonio Argenziano <[email protected]>Cc Tvrtko Ursulin <[email protected]>Signed-off-by Michel Thierry <[email protected]>Signed-off-by Carlos Santa <[email protected]>--- drivers/gpu/drm/i915/intel_context_types.h | 4 + drivers/gpu/drm/i915/intel_engine_cs.c | 2 + drivers/gpu/drm/i915/intel_engine_types.h | 17 ++++- drivers/gpu/drm/i915/intel_lrc.c | 89 +++++++++++++++++++++- drivers/gpu/drm/i915/intel_lrc.h | 2 + 5 files changed, 106 insertions(+), 8 deletions(-)drivers/gpu/drm/i915/intel_context_types.h +0
-0drivers/gpu/drm/i915/intel_context_types.h struct intel_context { · line 56
Quoted 6 lines
drivers/gpu/drm/i915/intel_context_types.h +3
-0@@ -51,6 +51,10 @@ struct intel_context {u64 lrc_desc;atomic_t pin_count; +/** watchdog_threshold: hw watchdog threshold value, +* in clock counts +*/ Gah. Why would you put it here? Between a tightly coupled count + mutex.
Quoted 26 lines
drivers/gpu/drm/i915/intel_context_types.h +1
-0+u32 watchdog_threshold;struct mutex pin_mutex;/* guards pinning and associated on-gpuing */
/**drivers/gpu/drm/i915/intel_engine_cs.c +2
-0@@ -324,6 +324,8 @@ intel_engine_setup(struct drm_i915_private *dev_priv, if (engine->context_size)DRIVER_CAPS (dev_priv)->has_logical_contexts = true; + engine->watchdog_disable_id =get_watchdog_disable (engine); +/* Nothing to do here, execute in order of dependencies */ engine->schedule =NULL ;drivers/gpu/drm/i915/intel_engine_types.h +0
-0drivers/gpu/drm/i915/intel_engine_types.h struct intel_engine_cs { · line 263
Quoted 4 lines
drivers/gpu/drm/i915/intel_engine_types.h +1
-0@@ -260,6 +260,7 @@ struct intel_engine_cs {unsigned int guc_id;intel_engine_mask_t mask; +u32 watchdog_disable_id;You've just put this between a pair of u8s.
Quoted 68 lines
drivers/gpu/drm/i915/intel_engine_types.h +12
-4u8 uabi_class;u8 class;@@ -422,10 +423,12 @@ struct intel_engine_cs {struct intel_engine_hangcheck hangcheck; -#define I915_ENGINE_NEEDS_CMD_PARSER BIT(0) -#define I915_ENGINE_SUPPORTS_STATS BIT(1) -#define I915_ENGINE_HAS_PREEMPTION BIT(2) -#define I915_ENGINE_HAS_SEMAPHORES BIT(3) +#define I915_ENGINE_NEEDS_CMD_PARSER BIT(0) +#define I915_ENGINE_SUPPORTS_STATS BIT(1) +#define I915_ENGINE_HAS_PREEMPTION BIT(2) +#define I915_ENGINE_HAS_SEMAPHORES BIT(3) +#define I915_ENGINE_SUPPORTS_WATCHDOG BIT(4) +unsigned int flags;/* @@ -509,6 +512,12 @@ intel_engine_has_semaphores(const struct intel_engine_cs *engine)return engine->flags &I915_ENGINE_HAS_SEMAPHORES ; } +static inline bool +intel_engine_supports_watchdog (const struct intel_engine_cs *engine) +{ +return engine->flags &I915_ENGINE_SUPPORTS_WATCHDOG ; +} +#define instdone_slice_mask (dev_priv__) \(IS_GEN(dev_priv__, 7) ? \ 1 : RUNTIME_INFO(dev_priv__)->sseu.slice_mask)drivers/gpu/drm/i915/intel_lrc.c +10
-0@@ -2036,16 +2036,75 @@ static void execlists_reset_finish(struct intel_engine_cs *engine) atomic_read(&execlists->tasklet.count)); } +static u32 *gen8_emit_start_watchdog (struct i915_request *rq,u32 *cs) +{ +struct intel_engine_cs *engine = rq->engine; +struct i915_gem_context *ctx = rq->gem_context; +struct intel_context *ce =intel_context_lookup (ctx, engine); + +GEM_BUG_ON (!intel_engine_supports_watchdog (engine)); + +/* +* watchdog register must never be programmed to zero. This would
+ * cause the watchdog counter to exceed and not allow the
engine todrivers/gpu/drm/i915/intel_lrc.c +7
-0+* go into IDLE state +*/ +GEM_BUG_ON (ce->watchdog_threshold ==0 ); + +/* Set counter period */ + *cs++ =MI_LOAD_REGISTER_IMM (2 ); + *cs++ = i915_mmio_reg_offset(RING_THRESH(engine-Quoted 1 line
mmio_base));drivers/gpu/drm/i915/intel_lrc.c static void execlists_reset_finish(struct intel_engine_cs *engine) · line 2060
Quoted 4 lines
drivers/gpu/drm/i915/intel_lrc.c +4
-0+ *cs++ = ce->watchdog_threshold; +/* Start counter */ + *cs++ =i915_mmio_reg_offset (RING_CNTR (engine->mmio_base)); + *cs++ =GEN8_WATCHDOG_ENABLE ;Hmm, so no watchdog seqno.
Quoted 19 lines
drivers/gpu/drm/i915/intel_lrc.c +4
-0+return cs; +} + +static u32 *gen8_emit_stop_watchdog(struct i915_request *rq, u32*cs)
drivers/gpu/drm/i915/intel_lrc.c +12
-0+{ +struct intel_engine_cs *engine = rq->engine; + +GEM_BUG_ON (!intel_engine_supports_watchdog (engine)); + + *cs++ =MI_LOAD_REGISTER_IMM (1 ); + *cs++ =i915_mmio_reg_offset (RING_CNTR (engine->mmio_base)); + *cs++ = engine->watchdog_disable_id; + +return cs; +} + static int gen8_emit_bb_start(struct i915_request *rq, u64 offset, u32 len,
Quoted 8 lines
Quoted 6 lines
const unsigned int flags)
{drivers/gpu/drm/i915/intel_lrc.c +3
-0+struct intel_engine_cs *engine = rq->engine; +struct i915_gem_context *ctx = rq->gem_context; + struct intel_context *ce = intel_context_lookup(ctx,engine);
Ahem. This keeps on getting worse.
Can you explain a bit more why?
Quoted 20 lines
Quoted 20 lines
u32 *cs;drivers/gpu/drm/i915/intel_lrc.c +13
-1+u32 num_dwords; +bool enable_watchdog = false; - cs =intel_ring_begin (rq,6 ); +/* bb_start only */ + num_dwords =6 ; + +/* check if watchdog will be required */ +if (ce->watchdog_threshold !=0 ) { +/* + start_watchdog (6) + stop_watchdog (4) */ + num_dwords +=10 ; + enable_watchdog = true; + } + + cs =intel_ring_begin (rq, num_dwords);if (IS_ERR (cs))return PTR_ERR (cs);
Quoted 4 lines
drivers/gpu/drm/i915/intel_lrc.c static void execlists_reset_finish(struct intel_engine_cs *engine) · line 2104
Quoted 2 lines
drivers/gpu/drm/i915/intel_lrc.c +2
-0+if (enable_watchdog) { +/* Start watchdog timer */ Please don't simply repeat code in comments.
Ack.
Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/i915/intel_lrc.c +3
-1+ cs =gen8_emit_start_watchdog (rq, cs); + } +/* * WaDisableCtxRestoreArbitration:bdw,chv * @@ -2072,10 +2131,16 @@ static int gen8_emit_bb_start(struct i915_request *rq, *cs++ =upper_32_bits (offset); *cs++ =MI_ARB_ON_OFF |MI_ARB_DISABLE ; - *cs++ =MI_NOOP ;
Quoted 13 lines
drivers/gpu/drm/i915/intel_lrc.c static int gen8_emit_bb_start(struct i915_request *rq, · line 2141
Quoted 8 lines
drivers/gpu/drm/i915/intel_lrc.c +7
-1-intel_ring_advance (rq, cs); +if (enable_watchdog) { +/* Cancel watchdog timer */ + cs =gen8_emit_stop_watchdog (rq, cs); + } + +if (*cs%2 !=0 ) + *cs++ =MI_NOOP ;This is wrong. cs points into the unset portion of the ring. The watchdog commands are even, so there is no reason to move the original
NOOP, or at least no reason to make it conditional.
Ok, I initially took the suggestion from Tvrtko from way back, where we were trying to get rid of too many MI_NOOPs by emitting them conditionally based on whether the cs pointer was odd...
Carlos
Quoted 1 line
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 4/5 drm/i915: Watchdog timeout: DRM kernel interface to set the timeout
In reply to Carlos SantaFrom: Michel Thierry <[email protected]>
Final enablement patch for GPU hang detection using watchdog timeout. Using the gem_context_setparam ioctl, users can specify the desired timeout value in microseconds, and the driver will do the conversion to 'timestamps'.
The recommended default watchdog threshold for video engines is 60000 us, since this has been _empirically determined_ to be a good compromise for low-latency requirements and low rate of false positives. The default register value is ~106000us and the theoretical max value (all 1s) is 353 seconds.
[1] http://patchwork.freedesktop.org/patch/msgid/[email protected]
v2: Fixed get api to return values in microseconds. Threshold updated to be per context engine. Check for u32 overflow. Capture ctx threshold value in error state.
v3: Add a way to get array size, short-cut to disable all thresholds, return EFAULT / EINVAL as needed. Move the capture of the threshold value in the error state into a new patch. BXT has a different timestamp base (because why not?).
v4: Checking if watchdog is available should be the first thing to do, instead of giving false hopes to abi users; remove unnecessary & in set_watchdog; ignore args->size in getparam.
v5: GEN9-LP platforms have a different crystal clock frequency, use the right timestamp base for them (magic 8-ball predicts this will change again later on, so future-proof it). (Daniele)
v6: Rebase, no more mutex BLK in getparam_ioctl.
v7: use to_intel_context instead of ctx->engine.
v8: Rebase, remove extra mutex from i915_gem_context_set_watchdog (Tvrtko), Update UAPI to use engine class while keeping thresholds per engine class (Michel).
v9: Rebase,
Remove outdated comment from the commit message (Tvrtko) Use the engine->flag to verify for gpu watchdog support (Tvrtko) Use the standard copy_to_user() instead (Tvrtko)
Use the correct type when declaring engine class iterator (Tvrtko) Remove yet another unncessary mutex_lock (Tvrtko)
v10: Rebase,
Document uAPI struct drm_i915_watchdog_timeout and use it (Tvrtko) Let the compiler takes care of inlines (Tvrtko)
Make watchdog_to_clock_counts more robust (Tvrtko)
--- drivers/gpu/drm/i915/i915_drv.h | 3 + drivers/gpu/drm/i915/i915_gem_context.c | 150 ++++++++++++++++++++++++ include/uapi/drm/i915_drm.h | 17 +++ 3 files changed, 170 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +3 -0
@@ -1598,6 +1598,9 @@ struct drm_i915_private {struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES ];/* assume 965 */ int num_fence_regs;/* 8 on pre-965, 16 otherwise */ +/* Command stream timestamp base - helps define watchdog threshold */ +u32 cs_timestamp_base; +unsigned int fsb_freq, mem_freq, is_ddr3;unsigned int skl_preferred_vco_freq;unsigned int max_cdclk_freq;
drivers/gpu/drm/i915/i915_gem_context.c +150 -0
168 lines not on this page · raw message
include/uapi/drm/i915_drm.h +17 -0
@@ -1440,6 +1440,7 @@ struct drm_i915_reg_read {*/ __u64 offset;#define I915_REG_READ_8B_WA (1ul << 0) +#define I915_CONTEXT_PARAM_WATCHDOG 0x10__u64 val;/* Return value */ };
@@ -1472,6 +1473,22 @@ struct drm_i915_reset_stats { }; +struct drm_i915_gem_watchdog_timeout { +union { +struct { +/* +* Engine class & instance to be configured or queried. +*/ +__u16 engine_class; +__u16 engine_instance; + }; +/* Index based addressing mode */ +__u32 index; + }; +/* GPU Engine watchdog reset timeout in us */ +__u32 timeout_us; +}; +struct drm_i915_gem_userptr {__u64 user_ptr;__u64 user_size;
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 5/5 drm/i915: Watchdog timeout: Include threshold value in error state
In reply to Carlos SantaFrom: Michel Thierry <[email protected]>
Save the watchdog threshold (in us) as part of the engine state.
v2: Only do it for gen8+ (and prevent a missing-case warn).
v3: use ctx->__engine.
v4: Rebase.
v5: Rebase.
v6: Rebase, use intel_context_lookup()
--- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_gpu_error.c | 14 ++++++++++---- drivers/gpu/drm/i915/i915_gpu_error.h | 1 + 3 files changed, 13 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -3118,6 +3118,8 @@ i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id)return ctx; } +u32 watchdog_to_us (struct drm_i915_private *i915,u32 value_in_clock_counts); +int i915_perf_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file); int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
drivers/gpu/drm/i915/i915_gpu_error.c +10 -4
@@ -454,9 +454,11 @@ static void error_print_context(struct drm_i915_error_state_buf *m, const char *header, const struct drm_i915_error_context *ctx) { - err_printf(m, "%s%s[%d] user_handle %d hw_id %d, prio %d, guilty %d active %d\n", + err_printf(m, "%s%s[%d] user_handle %d hw_id %d, prio %d, guilty %d active %d, watchdog %dus\n", header, ctx->comm, ctx->pid, ctx->handle, ctx->hw_id, - ctx->sched_attr.priority, ctx->guilty, ctx->active); + ctx->sched_attr.priority, ctx->guilty, ctx->active, +INTEL_GEN (m->i915) >=8 ? + watchdog_to_us(m->i915, ctx->watchdog_threshold) : 0); } static void error_print_engine(struct drm_i915_error_state_buf *m,
@@ -1316,8 +1318,11 @@ static void error_record_engine_execlists(struct intel_engine_cs *engine, }static void record_context (struct drm_i915_error_context *e, -struct i915_gem_context *ctx) +struct i915_gem_context *ctx, +u32 engine_id) { +struct drm_i915_private *dev_priv = ctx->i915; +if (ctx->pid) {struct task_struct *task;
@@ -1335,6 +1340,7 @@ static void record_context(struct drm_i915_error_context *e, e->sched_attr = ctx->sched; e->guilty =atomic_read (&ctx->guilty_count); e->active =atomic_read (&ctx->active_count); + e->watchdog_threshold =intel_context_lookup (ctx, dev_priv->engine[engine_id])->watchdog_threshold; } static void request_record_user_bo(struct i915_request *request,
@@ -1418,7 +1424,7 @@ static void gem_record_rings(struct i915_gpu_state *error) ee->vm = ctx->ppgtt ? &ctx->ppgtt->vm : &ggtt->vm; -record_context (&ee->context, ctx); +record_context (&ee->context, ctx, engine->id);/* We need to copy these to an anonymous buffer * as the simplest method to avoid being overwritten
drivers/gpu/drm/i915/i915_gpu_error.h +1 -0
@@ -120,6 +120,7 @@ struct i915_gpu_state {u32 hw_id;int active;int guilty; +int watchdog_threshold;struct i915_sched_attr sched_attr; } context;
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Fi.CI.BAT: failure for GEN8+ GPU Watchdog Reset Support
In reply to Carlos Santa== Series Details ==
== Series Details ==
Series: GEN8+ GPU Watchdog Reset Support
URL : https://patchwork.freedesktop.org/series/58443/
State : failure
== Summary ==
Applying: drm/i915: Add engine reset count in get-reset-stats ioctl
Applying: drm/i915: Watchdog timeout: IRQ handler for gen8+
Applying: drm/i915: Watchdog timeout: Ringbuffer command emission for gen8+
Applying: drm/i915: Watchdog timeout: DRM kernel interface to set the timeout
error: sha1 information is lacking or useless (drivers/gpu/drm/i915/i915_gem_context.c).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch' to see the failed patch
Patch failed at 0004 drm/i915: Watchdog timeout: DRM kernel interface to set the timeout When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx