Skip to contentSkip to conversation

TDR/watchdog timeout support for gen8

RFC Superseded Tomas Elf 1 participant 15 messages Jul 21, 2015 – Jul 24, 2015

Subsystems (3)
lore
Share & tools
lore

Tomas Elf

author
#0 lore raw

v2 cover TDR/watchdog timeout support for gen8

This patch series introduces the following features:

* Feature 1: TDR (Timeout Detection and Recovery) for gen8 execlist mode.

TDR is an umbrella term for anything that goes into detecting and recovering from GPU hangs and is a term more widely used outside of the upstream driver.
This feature introduces an extensible framework that currently supports gen8 but that can be easily extended to support gen7 as well (which is already the case in GMIN but unfortunately in a not quite upstreamable form). The code contained in this submission represents the essentials of what is currently in GMIN merged with what is currently in upstream (as of the time when this work commenced a few months back).

This feature adds a new hang recovery path alongside the legacy GPU reset path, which takes care of engine recovery only. Aside from adding support for per-engine recovery this feature also introduces rules for how to promote a potential per-engine reset to a legacy, full GPU reset.

The hang checker now integrates with the error handler in a slightly different way in that it allows hang recovery on multiple engines at the same time by passing an engine flag mask to the error handler where flags representing all of the hung engines are set. This allows us to schedule hang recovery once for all currently hung engines instead of one hang recovery per detected engine hang. Previously, when only full GPU reset was supported this was all the same since it wouldn't matter if one or four engines were hung at any given point since it would all amount to the same thing - the GPU getting reset. As it stands now the behaviour is different depending on which engine is hung since each engine is reset separately from all the other engines, therefore we have to think about this in terms of scheduling cost and recovery latency. (see open question below)

OPEN QUESTIONS:

1. Do we want to investigate the possibility of per-engine hang detection? In the current upstream driver there is only one work queue that handles the hang checker and everything from initial hang detection to final hang recovery runs in this thread. This makes sense if you're only supporting one form of hang recovery - using full GPU reset and nothing tied to any particular engine. However, as part of this patch series we're changing that by introducing per-engine hang recovery. It could make sense to introduce multiple work queues - one per engine - to run multiple hang checking threads in parallel.

This would potentially allow savings in terms of recovery latency since we don't have to scan all engines every time the hang checker is scheduled and the error handler does not have to scan all engines every time it is scheduled. Instead, we could implement one work queue per engine that would invoke the hang checker that only checks _that_ particular engine and then the error handler is invoked for _that_ particular engine. If one engine has hung the latency for getting to the hang recovery path for that particular engine would be (Time For Hang Checking One Engine) + (Time For Error Handling One Engine) rather than the time it takes to do hang checking for all engines + the time it takes to do error handling for all engines that have been detected as hung (which in the worst case would be all engines). There would potentially be as many hang checker and error handling threads going on concurrently as there are engines in the hardware but they would all be running in parallel without any significant locking. The first time where any thread needs exclusive access to the driver is at the point of the actual hang recovery but the time it takes to get there would theoretically be lower and the time it actually takes to do per-engine hang recovery is quite a lot lower than the time it takes to actually detect a hang reliably.

How much we would save by such a change still needs to be analysed and compared against the current single-thread model but it makes sense from a theoretical design point of view.

* Feature 2: Watchdog Timeout (a.k.a "media engine reset") for gen8.

This feature allows userland applications to control whether or not individual batch buffers should have a first-level, fine-grained, hardware-based hang detection mechanism on top of the ordinary, software-based periodic hang checker that is already in the driver. The advantage over relying solely on the current software-based hang checker is that the watchdog timeout mechanism is about 1000x quicker and more precise. Since it's not a full driver-level hang detection mechanism but only targetting one individual batch buffer at a time it can afford to be that quick without risking an increase in false positive hang detection.

This feature includes the following changes:

a) Watchdog timeout interrupt service routine for handling watchdog interrupts and connecting these to per-engine hang recovery.

b) Injection of watchdog timer enablement/cancellation instructions before/after the batch buffer start instruction in the ring buffer so that watchdog timeout is connected to the submission of an individual batch buffer.

c) Extension of the DRM batch buffer interface, exposing the watchdog timeout feature to userland. We've got two open source groups in VPG currently in the process of integrating support for this feature, which should make it principally possible to upstream this extension.

There is currently full watchdog timeout support for gen7 in GMIN and it is quite similar to the gen8 implementation so there is nothing obvious that prevents us from upstreaming that code along with the gen8 code. However, watchdog timeout is fully dependent on the per-engine hang recovery path and that is not part of this code submission for gen7. Therefore watchdog timeout support for gen7 has been excluded until per-engine hang recovery support for gen7 has landed upstream.

As part of this submission we've had to reinstate the work queue that was previously in place between the error handler and the hang recovery path. The reason for this is that the per-engine recovery path is called directly from the interrupt handler in the case of watchdog timeout. In that situation there's no way of grabbing the struct_mutex, which is a requirement for the hang recovery path. Therefore, by reinstating the work queue we provide a unified execution context for the hang recovery code that allows the hang recovery code to grab whatever locks it needs without sacrificing interrupt latency too much or sleeping indefinitely in hard interrupt context.

* Feature 3. Context Submission Status Consistency checking

Something that becomes apparent when you run long-duration operations tests with concurrent rendering processes with intermittently injected hangs is that it seems like the GPU forgets to send context completion interrupts to the driver under some circumstances. What this means is that the driver sometimes gets stuck on a context that never seems to finish, all the while the hardware has completed and is waiting for more work.

The problem with this is that the per-engine hang recovery path relies on context resubmission to kick off the hardware again following an engine reset.
This can only be done safely if the hardware and driver share the same opinion about the current state. Therefore we've extended the periodic hang checker to check for context submission state inconsistencies aside from the hang checking it already does.

If such a state is detected it is assumed (based on experience) that a context completion interrupt has been lost somehow. If this state persists for some time an attempt to correct it is made by faking the presumably lost context completion interrupt by manually calling the execlist interrupt handler, which is normally called from the main interrupt handler cued by a received context event interrupt. Just because an interrupt goes missing does not mean that the context status buffer (CSB) does not get appropriately updated by the hardware, which means that we can expect to find all the recent changes to the context states for each engine captured there.

If there are outstanding context status changes in store there then the faked context event interrupt will allow the interrupt handler to act on them. In the case of lost context completion interrupts this will prompt the driver to remove the already completed context from the execlist queue and move on to the next pending piece of work and thereby eliminating the inconsistency.

* Feature 4. Debugfs extensions for per-engine hang recovery and TDR/watchdog trace points.

GITHUB REPOSITORY:
https://github.com/telf/TDR_watchdog_RFC_1.git

RFC VERSION 1 BRANCH:
20150608_TDR_upstream_adaptation_single-thread_hangchecking_RFC_delivery_sendmail_1

RFC VERSION 2 BRANCH:
20150604_TDR_upstream_adaptation_single-thread_hangchecking_RFCv2_delivery_sendmail_1

CHANGES IN VERSION 2
--------------------
Version 2 of this RFC series addresses design concerns that Chris Wilson and Daniel Vetter et. al. had with the first version of this RFC series. Below is a summary of all the changes made between versions:

* [1/12] drm/i915: Early exit from semaphore_waits_for for execlist mode:
Turned the execlist mode check into a ringbuffer NULL check to make it more submission mode agnostic and less of a layering violation.

* [2/12] drm/i915: Make i915_gem_reset_ring_status() public
Replaces the old patch in RFCv1: "drm/i915: Add reset stats entry point for per-engine reset"

* [3/12] drm/i915: Adding TDR / per-engine reset support for gen8:

1. Simply use the previously private function i915_gem_reset_ring_status() from the engine hang recovery path to set active/pending context status. This replicates the same behaviour as in full GPU reset but for a single, targetted engine.

2. Remove all additional uevents for both full GPU reset and per-engine reset. Adapted uevent behaviour to the new per-engine hang recovery mode in that it will only send one uevent regardless of which form of recovery is employed. If a per-engine reset is attempted first then one uevent will be dispatched. If that recovery mode fails and the hang is promoted to a full GPU reset no further uevents will be dispatched at that point.

3. Removed the 2*HUNG hang threshold from i915_hangcheck_elapsed in order to not make the hang detection algorithm too complicated. This threshold was introduced to compensate for the possibility that hang recovery might be delayed due to inconsistent context submission status that would prevent per-engine hang recovery from happening. In a later patch we introduce faked context event interrupts and inconsistency rectification at the onset of per-engine hang recovery instead of relying on the hang checker to do this for us. Therefore, since we do not delay and defer to future hang detections, we never allow hangs to go addressed beyond the HUNG threshold and therefore there is no need for any further thresholds.

4. Tidied up the TDR context resubmission path in intel_lrc.c . Reduced the amount of duplication by relying entirely on the normal unqueue function. Added a new parameter to the unqueue function that takes into consideration if the unqueue call is for a first-time context submission or a resubmission and adapts the handling of elsp_submitted accordingly. The reason for this is that for context resubmission we don't expect any further interrupts for the submission or the following context completion. A more elegant way of handling this would be to phase out elsp_submitted altogether, however that's part of a LRC/execlist cleanup effort that is happening independently of this RFC. For now we make this change as simple as possible with as few non-TDR-related side-effects as possible.

* [4/12] drm/i915: Extending i915_gem_check_wedge to check engine reset in progress:
Removed unwarranted changes made to i915_gem_ring_throttle()

* [7/12] drm/i915: Fake lost context interrupts through forced CSB check Remove context submission status consistency pre-check from i915_hangcheck_elapsed() and turn it into a pre-check to per-engine reset.

The following describes the change in philosphy in how context submission state inconsistencies are detected:

Previously we would let the periodic hang checker ensure that there were no context submission status inconsistencies on any engine, at any point. If an inconsistency was detected in the per-engine hang recovery path we would back off and defer to the next hang check since per-engine hang recovery is not effective during inconsistent context submission states.

What we do in this new version is to move the consistency pre-check from the hang checker to the earliest point in the per-engine hang recovery path. If we detect an inconsistency at that point we fake a potentially lost context event interrupt by forcing a CSB check. If there are outstanding events in the CSB these will be acted upon and hopefully that will bring the driver up to speed with the hardware. If the CSB check did not amount to anything it is concluded that the inconsistency is unresolvable and the per-engine hang recovery fails and promotes to full GPU reset instead.

In the hang checker-based consistency checking we would check the inconsistency for a number of times to make sure the detected state was stable before attempting to rectify the situation. This is possible since hang checking is a recurring event. Having moved the consistency checking to the recovery path instead (i.e. a one-time, fire & forget-style event) it is assumed that the hang detection that brought on the hang recovery has detected a stable hang and therefore, if an inconsistency is detected at that point, the inconsistency must be stable and not the result of a momentary context state transition. Therefore, unlike in the hang checker case, at the very first indication of an inconsistent context submission status the interrupt is faked speculatively. If outstanding CSB events are found it is determined that the hang was in fact just a context submission status inconsistency and no hang recovery is done. If the inconsistency cannot be resolved the per-engine

* [8/12] drm/i915: Debugfs interface for per-engine hang recovery
1. After review comments by Chris Wilson we're dropping the dual-mode parameter value interpretation in i915_wedged_set(). In this version we only accept engine id flag masks that contain the engine id flags of all currently hung engines. Full GPU reset is most easily requested by passing an all zero engine id flag mask.

2. Moved TDR-specific engine metrics like number of detected engine hangs and number of per-engine resets into i915_hangcheck_info() from i915_hangcheck_read().

* [9/12] drm/i915: TDR/watchdog trace points
As a consequence of the faking context event interrupt commit being moved from the hang checker to the per-engine recovery path we no longer check context submission status from the hang checker. Therefore there is no need to provide submission status of the currently running context to the trace_i915_tdr_hang_check() event.

* [10/12] drm/i915: Fix __i915_wait_request() behaviour during hang detection
* [11/12] drm/i915: Port of Added scheduler support to __wait_request() calls
NEW: Added to address the way that __i915_wait_request() behaves in the face of hang detections and hang recovery.

* [12/12] drm/i915: Extended error state with TDR count, watchdog count and engine reset count
NEW: Adds per-engine TDR statistics to captured error state.

Tomas Elf (12):
drm/i915: Early exit from semaphore_waits_for for execlist mode. drm/i915: Make i915_gem_reset_ring_status() public drm/i915: Adding TDR / per-engine reset support for gen8. drm/i915: Extending i915_gem_check_wedge to check engine reset in
progress
drm/i915: Reinstate hang recovery work queue.
drm/i915: Watchdog timeout support for gen8.
drm/i915: Fake lost context interrupts through forced CSB check. drm/i915: Debugfs interface for per-engine hang recovery. drm/i915: TDR/watchdog trace points.
drm/i915: Port of Added scheduler support to __wait_request() calls drm/i915: Fix __i915_wait_request() behaviour during hang detection. drm/i915: Extended error state with TDR count, watchdog count and
engine reset count

 drivers/gpu/drm/i915/i915_debugfs.c     |  76 +++-
 drivers/gpu/drm/i915/i915_dma.c         |  78 ++++
 drivers/gpu/drm/i915/i915_drv.c         | 257 +++++++++++
 drivers/gpu/drm/i915/i915_drv.h         |  79 +++-
 drivers/gpu/drm/i915/i915_gem.c         | 128 ++++--
 drivers/gpu/drm/i915/i915_gpu_error.c   |   8 +-
 drivers/gpu/drm/i915/i915_irq.c         | 292 +++++++++++--
 drivers/gpu/drm/i915/i915_params.c      |  10 +
 drivers/gpu/drm/i915/i915_reg.h         |  13 +
 drivers/gpu/drm/i915/i915_trace.h       | 308 +++++++++++++-
 drivers/gpu/drm/i915/intel_display.c    |   2 +-
 drivers/gpu/drm/i915/intel_lrc.c        | 729 ++++++++++++++++++++++++++++++--
 drivers/gpu/drm/i915/intel_lrc.h        |  16 +-
 drivers/gpu/drm/i915/intel_lrc_tdr.h    |  39 ++
 drivers/gpu/drm/i915/intel_ringbuffer.c |  87 +++-
 drivers/gpu/drm/i915/intel_ringbuffer.h |  95 +++++
 drivers/gpu/drm/i915/intel_uncore.c     | 203 +++++++++
 include/uapi/drm/i915_drm.h             |   5 +-
 18 files changed, 2313 insertions(+), 112 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/intel_lrc_tdr.h
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#1 lore raw

RFC v2 1/12 drm/i915: Early exit from semaphore_waits_for for execlist mode.

When submitting semaphores in execlist mode the hang checker crashes in this function because it is only runnable in ring submission mode. The reason this is of particular interest to the TDR patch series is because we use semaphores as a mean to induce hangs during testing (which is the recommended way to induce hangs for gen8+). It's not clear how this is supposed to work in execlist mode since:

1. This function requires a ring buffer.

2. Retrieving a ring buffer in execlist mode requires us to retrieve the corresponding context, which we get from a request.

3. Retieving a request from the hang checker is not straight-forward since that requires us to grab the struct_mutex in order to synchronize against the request retirement thread.

4. Grabbing the struct_mutex from the hang checker is nothing that we will do since that puts us at risk of deadlock since a hung thread might be holding the struct_mutex already.

Therefore it's not obvious how we're supposed to deal with this. For now, we're doing an early exit from this function, which avoids any kernel panic situation when running our own internal TDR ULT.

* v2: (Chris Wilson)
Turned the execlist mode check into a ringbuffer NULL check to make it more submission mode agnostic and less of a layering violation.

Cc Chris Wilson <[email protected]>
Cc Mika Kuoppala <[email protected]>
---
 drivers/gpu/drm/i915/i915_irq.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/gpu/drm/i915/i915_irq.c +20 -0
index 46bcbff..4e8e722 100644
@@ -2698,6 +2698,26 @@ semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
 	u64 offset = 0;
 	int i, backwards;
 
+	/*
+	 * This function does not support execlist mode - any attempt to
+	 * proceed further into this function will result in a kernel panic
+	 * when dereferencing ring->buffer, which is not set up in execlist
+	 * mode.
+	 *
+	 * The correct way of doing it would be to derive the currently
+	 * executing ring buffer from the current context, which is derived
+	 * from the currently running request. Unfortunately, to get the
+	 * current request we would have to grab the struct_mutex before doing
+	 * anything else, which would be ill-advised since some other thread
+	 * might have grabbed it already and managed to hang itself, causing
+	 * the hang checker to deadlock.
+	 *
+	 * Therefore, this function does not support execlist mode in its
+	 * current form. Just return NULL and move on.
+	 */
+	if (ring->buffer == NULL)
+		return NULL;
+
 	ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
 	if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
 		return NULL;
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#2 lore raw

RFC v2 2/12 drm/i915: Make i915_gem_reset_ring_status() public

In reply to Tomas Elf

Makes i915_gem_reset_ring_status() public for use from engine reset path in order to replicate the same behavior as in full GPU reset but for a single engine.

Cc Chris Wilson <[email protected]>
Cc Mika Kuoppala <[email protected]>
---
 drivers/gpu/drm/i915/i915_drv.h | 2 ++
 drivers/gpu/drm/i915/i915_gem.c | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 47be4a5..c32c502 100644
@@ -2781,6 +2781,8 @@ static inline bool i915_stop_ring_allow_warn(struct drm_i915_private *dev_priv)
 }
 
 void i915_gem_reset(struct drm_device *dev);
+void i915_gem_reset_ring_status(struct drm_i915_private *dev_priv,
+			        struct intel_engine_cs *ring);
 bool i915_gem_clflush_object(struct drm_i915_gem_object *obj, bool force);
 int __must_check i915_gem_object_finish_gpu(struct drm_i915_gem_object *obj);
 int __must_check i915_gem_init(struct drm_device *dev);
drivers/gpu/drm/i915/i915_gem.c +2 -2
index 8ce363a..4f4fc3e0 100644
@@ -2561,8 +2561,8 @@ i915_gem_find_active_request(struct intel_engine_cs *ring)
 	return NULL;
 }
 
-static void i915_gem_reset_ring_status(struct drm_i915_private *dev_priv,
-				       struct intel_engine_cs *ring)
+void i915_gem_reset_ring_status(struct drm_i915_private *dev_priv,
+			        struct intel_engine_cs *ring)
 {
 	struct drm_i915_gem_request *request;
 	bool ring_hung;
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#3 lore raw

RFC v2 3/12 drm/i915: Adding TDR / per-engine reset support for gen8.

In reply to Tomas Elf

This change introduces support for TDR-style per-engine reset as a initial, less intrusive hang recovery option to be attempted before falling back to the legacy full GPU reset recovery mode if necessary. Initially we're only supporting gen8 but adding support for gen7 is straight-forward since we've already established an extensible framework where gen7 support can be plugged in (add corresponding versions of intel_ring_enable, intel_ring_disable, intel_ring_save, intel_ring_restore, etc.).

1. Per-engine recovery vs. Full GPU recovery

To capture the state of a single engine being detected as hung there is now a new flag for every engine that can be set once the decision has been made to schedule hang recovery for that particular engine.

The following algorithm is used to determine when to use which recovery mode:

a. Once the hang check score reaches level HUNG hang recovery is scheduled as usual. The hang checker aggregates all engines currently detected as hung into a single engine flag mask and passes that to the error handler, which allows us to schedule hang recovery for all currently hung engines in a single call.

b. The error handler checks all engines that have been marked as hung by the hang checker and - more specifically - checks how long ago it was since it last attempted to do per-engine hang recovery for each respective, currently hung engine. If the measured time period is within a certain time window, i.e. the last per-engine hang recovery was done too recently, it is determined that per-engine hang recovery is ineffective and the step is taken to promote a full GPU reset.

c. If the error handler determines that no currently hung engine has recently had hang recovery a per-engine hang recovery is scheduled.

d. Additionally, if the hang checker detects that the hang check score has grown too high (currently defined as twice the HUNG level) it determines that previous hang recovery attempts have failed for whatever reason and it will bypass the error checker full GPU reset promotion logic. One case where this is important is if the hang checker and error handler thinks that per-engine hang recovery is a suitable option and several such attempts are made - infrequently enough - but no effective reset is done, perhaps due to inconsistent context submission status, which is described further down below.

NOTE: Gen 7 and earlier will always promote to full GPU reset since there is currently no per-engine reset support for these gens.

2. Context Submission Status Consistency.

Per-engine hang recovery on gen8 relies on the basic concept of context submission status consistency. What this means is that we make sure that the status of the hardware and the driver when it comes to the submission status of the current context on any engine is consistent. For example, when submitting a context to the corresponding ELSP port of an engine we expect the owning request of that context to be at the head of the corresponding execution list queue. Likewise, as long as the context is executing on the GPU we expect the EXECLIST_STATUS register and the context status buffer to reflect this. Thus, if the context submission status is consistent the ID of the currently executing context should be in EXECLIST_STATUS and it should be consistent with the context of the head request element in the execution list queue corresponding to that engine.

The reason why this is important for per-engine hang recovery on gen8 is because this recovery mode relies on context resubmission to resume execution following the recovery. If a context has been determined to be hung and the per-engine hang recovery mode is engaged leading to the resubmission of that context it's important that the hardware is in fact not busy doing something else or being idle since a resubmission during this state would cause unforseen side-effects such as unexpected preemptions.

There are rare, although consistently reproducable, situations that have shown up in practice where the driver and hardware are no longer consistent with each other, e.g. due to lost context completion interrupts after which the hardware would be idle but the driver would still think that a context would still be active.

3. There is a new reset path for engine reset alongside the legacy full GPU reset path. This path does the following:

1) Check for context submission consistency to make sure that the context that the hardware is currently stuck on is actually what the driver is working on. If not then clearly we're not in a consistently hung state and we bail out early.

2) Disable/idle the engine. This is done through reset handshaking on gen8+ unlike earlier gens where this was done by clearing the ring valid bits in MI_MODE and ring control registers, which are no longer supported on gen8+. Reset handshaking translates to setting the reset request bit in the reset control register.

3) Save the current engine state.

What this translates to on gen8 is simply to read the current value of the head register and nudge it so that it points to the next valid instruction in the ring buffer. Since we assume that the execution is currently stuck in a batch buffer the effect of this is that the batchbuffer start instruction of the hung batch buffer is skipped so that when execution resumes, following the hang recovery completion, it resumes immediately following the batch buffer.

This effectively means that we're forcefully terminating the currently active, hung batch buffer. Obviously, the outcome of this intervention is potentially undefined but there are not many good options in this scenario. It's better than resetting the entire GPU in the vast majority of cases.

Save the nudged head value to be applied later.

4) Reset the engine.

5) Apply the nudged head value to the head register.

6) Reenable the engine. For gen8 this means resubmitting the fixed-up context, allowing execution to resume. In order to resubmit a context without relying on the currently hung execution list queues we use a privileged API that is dedicated for TDR use only. This submission API bypasses any currently queued work and gets exclusive access to the ELSP ports.

7) If the engine hang recovery procedure fails at any point in between disablement and reenablement of the engine there is a back-off
procedure: For gen8 it's possible to back out of the reset handshake by clearing the reset request bit in the reset control register.

NOTE:
It's possible that some of Ben Widawsky's original per-engine reset patches from 3 years ago are in this commit but since this work has gone through the hands of at least 3 people already any kind of ownership tracking has been lost a long time ago. If you think that you should be on the sob list just let me know.

* v2: (Chris Wilson / Daniel Vetter)
- Simply use the previously private function i915_gem_reset_ring_status() from the engine hang recovery path to set active/pending context status. This replicates the same behaviour as in full GPU reset but for a single, targetted engine.

- Remove all additional uevents for both full GPU reset and per-engine reset. Adapted uevent behaviour to the new per-engine hang recovery mode in that it will only send one uevent regardless of which form of recovery is employed. If a per-engine reset is attempted first then one uevent will be dispatched. If that recovery mode fails and the hang is promoted to a full GPU reset no further uevents will be dispatched at that point.

- Removed the 2*HUNG hang threshold from i915_hangcheck_elapsed in order to not make the hang detection algorithm too complicated. This threshold was introduced to compensate for the possibility that hang recovery might be delayed due to inconsistent context submission status that would prevent per-engine hang recovery from happening. In a later patch we introduce faked context event interrupts and inconsistency rectification at the onset of per-engine hang recovery instead of relying on the hang checker to do this for us. Therefore, since we do not delay and defer to future hang detections, we never allow hangs to go addressed beyond the HUNG threshold and therefore there is no need for any further thresholds.

- Tidied up the TDR context resubmission path in intel_lrc.c . Reduced the amount of duplication by relying entirely on the normal unqueue function. Added a new parameter to the unqueue function that takes into consideration if the unqueue call is for a first-time context submission or a resubmission and adapts the handling of elsp_submitted accordingly. The reason for this is that for context resubmission we don't expect any further interrupts for the submission or the following context completion. A more elegant way of handling this would be to phase out elsp_submitted altogether, however that's part of a LRC/execlist cleanup effort that is happening independently of this RFC. For now we make this change as simple as possible with as few non-TDR-related side-effects as possible.

---
 drivers/gpu/drm/i915/i915_debugfs.c     |   2 +-
 drivers/gpu/drm/i915/i915_dma.c         |  18 ++
 drivers/gpu/drm/i915/i915_drv.c         | 198 ++++++++++++
 drivers/gpu/drm/i915/i915_drv.h         |  63 +++-
 drivers/gpu/drm/i915/i915_irq.c         | 199 ++++++++++--
 drivers/gpu/drm/i915/i915_params.c      |  10 +
 drivers/gpu/drm/i915/i915_reg.h         |   6 +
 drivers/gpu/drm/i915/intel_lrc.c        | 556 ++++++++++++++++++++++++++++++--
 drivers/gpu/drm/i915/intel_lrc.h        |  14 +
 drivers/gpu/drm/i915/intel_lrc_tdr.h    |  36 +++
 drivers/gpu/drm/i915/intel_ringbuffer.c |  84 ++++-
 drivers/gpu/drm/i915/intel_ringbuffer.h |  64 ++++
 drivers/gpu/drm/i915/intel_uncore.c     | 199 ++++++++++++
 13 files changed, 1400 insertions(+), 49 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/intel_lrc_tdr.h
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
index 8446ef4..e33e105 100644
@@ -4183,7 +4183,7 @@ i915_wedged_set(void *data, u64 val)
 
 	intel_runtime_pm_get(dev_priv);
 
-	i915_handle_error(dev, val,
+	i915_handle_error(dev, 0x0, val,
 			  "Manually setting wedged to %llu", val);
 
 	intel_runtime_pm_put(dev_priv);
drivers/gpu/drm/i915/i915_dma.c +18 -0
index e44116f..cf01e84 100644
@@ -776,6 +776,22 @@ static void intel_device_info_runtime_init(struct drm_device *dev)
 			 info->has_eu_pg ? "y" : "n");
 }
 
+static void
+i915_hangcheck_init(struct drm_device *dev)
+{
+	int i;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	for (i = 0; i < I915_NUM_RINGS; i++) {
+		struct intel_engine_cs *engine = &dev_priv->ring[i];
+		struct intel_ring_hangcheck *hc = &engine->hangcheck;
+
+		i915_hangcheck_reinit(engine);
+		hc->reset_count = 0;
+		hc->tdr_count = 0;
+	}
+}
+
 /**
  * i915_driver_load - setup chip and create an initial config
  * @dev: DRM device
@@ -956,6 +972,8 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
 
 	i915_gem_load(dev);
 
+	i915_hangcheck_init(dev);
+
 	/* On the 945G/GM, the chipset reports the MSI capability on the
 	 * integrated graphics even though the support isn't actually there
 	 * according to the published specs.  It doesn't appear to function
drivers/gpu/drm/i915/i915_drv.c +198 -0

222 lines not on this page · raw message

drivers/gpu/drm/i915/i915_drv.h +61 -2

91 lines not on this page · raw message

drivers/gpu/drm/i915/i915_irq.c +176 -23

279 lines not on this page · raw message

drivers/gpu/drm/i915/i915_params.c +10 -0
index bb64415..9cea004 100644
@@ -50,6 +50,7 @@ struct i915_params i915 __read_mostly = {
 	.enable_cmd_parser = 1,
 	.disable_vtd_wa = 0,
 	.use_mmio_flip = 0,
+	.gpu_reset_promotion_time = 0,
 	.mmio_debug = 0,
 	.verbose_state_checks = 1,
 	.nuclear_pageflip = 0,
@@ -172,6 +173,15 @@ module_param_named(use_mmio_flip, i915.use_mmio_flip, int, 0600);
 MODULE_PARM_DESC(use_mmio_flip,
 		 "use MMIO flips (-1=never, 0=driver discretion [default], 1=always)");
 
+module_param_named(gpu_reset_promotion_time,
+               i915.gpu_reset_promotion_time, int, 0644);
+MODULE_PARM_DESC(gpu_reset_promotion_time,
+               "Catch excessive engine resets. Each engine maintains a "
+	       "timestamp of the last time it was reset. If it hangs again "
+	       "within this period then fall back to full GPU reset to try and"
+	       " recover from the hang. "
+               "default=0 seconds (disabled)");
+
 module_param_named(mmio_debug, i915.mmio_debug, int, 0600);
 MODULE_PARM_DESC(mmio_debug,
 	"Enable the MMIO debug code for the first N failures (default: off). "
drivers/gpu/drm/i915/i915_reg.h +6 -0
index 9c97842..af9f0ad 100644
@@ -100,6 +100,10 @@
 #define  GRDOM_RESET_STATUS (1<<1)
 #define  GRDOM_RESET_ENABLE (1<<0)
 
+#define RING_RESET_CTL(ring)	((ring)->mmio_base+0xd0)
+#define  READY_FOR_RESET	0x2
+#define  REQUEST_RESET		0x1
+
 #define ILK_GDSR 0x2ca4 /* MCHBAR offset */
 #define  ILK_GRDOM_FULL		(0<<1)
 #define  ILK_GRDOM_RENDER	(1<<1)
@@ -130,6 +134,8 @@
 #define  GEN6_GRDOM_RENDER		(1 << 1)
 #define  GEN6_GRDOM_MEDIA		(1 << 2)
 #define  GEN6_GRDOM_BLT			(1 << 3)
+#define  GEN6_GRDOM_VECS		(1 << 4)
+#define  GEN8_GRDOM_MEDIA2		(1 << 7)
 
 #define RING_PP_DIR_BASE(ring)		((ring)->mmio_base+0x228)
 #define RING_PP_DIR_BASE_READ(ring)	((ring)->mmio_base+0x518)
drivers/gpu/drm/i915/intel_lrc.c +534 -22

650 lines not on this page · raw message

drivers/gpu/drm/i915/intel_lrc.h +14 -0
index 04d3a6d..d2f497c 100644
@@ -29,6 +29,8 @@
 /* Execlists regs */
 #define RING_ELSP(ring)			((ring)->mmio_base+0x230)
 #define RING_EXECLIST_STATUS(ring)	((ring)->mmio_base+0x234)
+#define	  EXECLIST_STATUS_CURRENT_ACTIVE_ELEMENT_STATUS	(0x3 << 14)
+#define RING_EXECLIST_STATUS_CTX_ID(ring)	(RING_EXECLIST_STATUS(ring)+4)
 #define RING_CONTEXT_CONTROL(ring)	((ring)->mmio_base+0x244)
 #define	  CTX_CTRL_INHIBIT_SYN_CTX_SWITCH	(1 << 3)
 #define	  CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT	(1 << 0)
@@ -89,4 +91,16 @@ u32 intel_execlists_ctx_id(struct drm_i915_gem_object *ctx_obj);
 void intel_lrc_irq_handler(struct intel_engine_cs *ring);
 void intel_execlists_retire_requests(struct intel_engine_cs *ring);
 
+int intel_execlists_read_tail(struct intel_engine_cs *ring,
+			 struct intel_context *ctx,
+			 u32 *tail);
+
+int intel_execlists_write_head(struct intel_engine_cs *ring,
+			  struct intel_context *ctx,
+			  u32 head);
+
+int intel_execlists_read_head(struct intel_engine_cs *ring,
+			 struct intel_context *ctx,
+			 u32 *head);
+
 #endif /* _INTEL_LRC_H_ */
drivers/gpu/drm/i915/intel_lrc_tdr.h new file +36 -0
new file mode 100644
index 0000000..4520753
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _INTEL_LRC_TDR_H_
+#define _INTEL_LRC_TDR_H_
+
+/* Privileged execlist API used exclusively by TDR */
+
+void intel_execlists_TDR_context_resubmission(struct intel_engine_cs *ring);
+
+enum context_submission_status
+intel_execlists_TDR_get_current_request(struct intel_engine_cs *ring,
+		struct drm_i915_gem_request **req);
+
+#endif /* _INTEL_LRC_TDR_H_ */
+
drivers/gpu/drm/i915/intel_ringbuffer.c +83 -1

96 lines not on this page · raw message

drivers/gpu/drm/i915/intel_ringbuffer.h +64 -0

94 lines not on this page · raw message

drivers/gpu/drm/i915/intel_uncore.c +199 -0

205 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#4 lore raw

RFC v2 4/12 drm/i915: Extending i915_gem_check_wedge to check engine reset in progress

In reply to Tomas Elf

i915_gem_wedge now returns a positive result in three different cases:

1. Legacy: A hang has been detected and full GPU reset has been promoted.

2. Per-engine recovery:

a. A single engine reference can be passed to the function, in which case only that engine will be checked. If that particular engine is detected to be hung and is to be reset this will yield a positive result but not if reset is in progress for any other engine.

b. No engine reference is passed to the function, in which case all engines are checked for ongoing per-engine hang recovery.

Also, i915_wait_request was updated to take advantage of this new functionality. This is important since the TDR hang recovery mechanism needs a way to force waiting threads that hold the struct_mutex to give up the struct_mutex and try again after the hang recovery has completed. If i915_wait_request does not take per-engine hang recovery into account there is no way for a waiting thread to know that a per-engine recovery is about to happen and that it needs to back off.

* v2 (Chris Wilson):
Removed unwarranted changes made to i915_gem_ring_throttle().

---
 drivers/gpu/drm/i915/i915_drv.h         |  3 +-
 drivers/gpu/drm/i915/i915_gem.c         | 63 +++++++++++++++++++++++++++------
 drivers/gpu/drm/i915/intel_lrc.c        |  3 +-
 drivers/gpu/drm/i915/intel_ringbuffer.c |  3 +-
 4 files changed, 58 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -1
index be4c95c..f4d0c1f 100644
@@ -2807,7 +2807,8 @@ i915_gem_find_active_request(struct intel_engine_cs *ring);
 
 bool i915_gem_retire_requests(struct drm_device *dev);
 void i915_gem_retire_requests_ring(struct intel_engine_cs *ring);
-int __must_check i915_gem_check_wedge(struct i915_gpu_error *error,
+int __must_check i915_gem_check_wedge(struct drm_i915_private *dev_priv,
+				      struct intel_engine_cs *engine,
 				      bool interruptible);
 int __must_check i915_gem_check_olr(struct drm_i915_gem_request *req);
 
drivers/gpu/drm/i915/i915_gem.c +52 -11

129 lines not on this page · raw message

drivers/gpu/drm/i915/intel_lrc.c +2 -1
index e02abec..4a19385 100644
@@ -986,7 +986,8 @@ static int intel_logical_ring_begin(struct intel_ringbuffer *ringbuf,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	int ret;
 
-	ret = i915_gem_check_wedge(&dev_priv->gpu_error,
+	ret = i915_gem_check_wedge(dev_priv,
+				   ring,
 				   dev_priv->mm.interruptible);
 	if (ret)
 		return ret;
drivers/gpu/drm/i915/intel_ringbuffer.c +2 -1
index 0fdf983..fc82942 100644
@@ -2259,7 +2259,8 @@ int intel_ring_begin(struct intel_engine_cs *ring,
 	struct drm_i915_private *dev_priv = ring->dev->dev_private;
 	int ret;
 
-	ret = i915_gem_check_wedge(&dev_priv->gpu_error,
+	ret = i915_gem_check_wedge(dev_priv,
+				   ring,
 				   dev_priv->mm.interruptible);
 	if (ret)
 		return ret;
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#5 lore raw

RFC v2 5/12 drm/i915: Reinstate hang recovery work queue.

In reply to Tomas Elf

There used to be a work queue separating the error handler from the hang recovery path, which was removed a while back in this commit:

	commit b8d24a06568368076ebd5a858a011699a97bfa42
	Author: Mika Kuoppala <[email protected]>
	Date:   Wed Jan 28 17:03:14 2015 +0200

	    drm/i915: Remove nested work in gpu error handling

Now we need to revert most of that commit since the work queue separating hang detection from hang recovery is needed in preparation for the upcoming watchdog timeout feature. The watchdog interrupt service routine will be a second callsite of the error handler alongside the periodic hang checker, which runs in a work queue context. Seeing as the error handler will be serving a caller in a hard interrupt execution context that means that the error handler must never end up in a situation where it needs to grab the struct_mutex. Unfortunately, that is exactly what we need to do first at the start of the hang recovery path, which might potentially sleep if the struct_mutex is already held by another thread. Not good when you're in a hard interrupt context.

---
 drivers/gpu/drm/i915/i915_dma.c |  1 +
 drivers/gpu/drm/i915/i915_drv.h |  1 +
 drivers/gpu/drm/i915/i915_irq.c | 28 +++++++++++++++++++++++-----
 3 files changed, 25 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +1 -0
index cf01e84..39b8f5f 100644
@@ -1116,6 +1116,7 @@ int i915_driver_unload(struct drm_device *dev)
 	/* Free error state after interrupts are fully disabled. */
 	cancel_delayed_work_sync(&dev_priv->gpu_error.hangcheck_work);
 	i915_destroy_error_state(dev);
+	cancel_work_sync(&dev_priv->gpu_error.work);
 
 	if (dev->pdev->msi_enabled)
 		pci_disable_msi(dev->pdev);
drivers/gpu/drm/i915/i915_drv.h +1 -0
index f4d0c1f..ef7c129 100644
@@ -1245,6 +1245,7 @@ struct i915_gpu_error {
 	spinlock_t lock;
 	/* Protected by the above dev->gpu_error.lock. */
 	struct drm_i915_error_state *first_error;
+	struct work_struct work;
 
 	unsigned long missed_irq_rings;
 
drivers/gpu/drm/i915/i915_irq.c +23 -5
index e869823..4973826 100644
@@ -2300,15 +2300,18 @@ static void i915_error_wake_up(struct drm_i915_private *dev_priv,
 }
 
 /**
- * i915_reset_and_wakeup - do process context error handling work
+ * i915_error_work_func - do process context error handling work
  *
  * Fire an error uevent so userspace can see that a hang or error
  * was detected.
  */
-static void i915_reset_and_wakeup(struct drm_device *dev)
+static void i915_error_work_func(struct work_struct *work)
 {
-	struct drm_i915_private *dev_priv = to_i915(dev);
-	struct i915_gpu_error *error = &dev_priv->gpu_error;
+	struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
+	                                            work);
+	struct drm_i915_private *dev_priv =
+	        container_of(error, struct drm_i915_private, gpu_error);
+	struct drm_device *dev = dev_priv->dev;
 	char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
 	char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
 	char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
@@ -2668,7 +2671,21 @@ void i915_handle_error(struct drm_device *dev, u32 engine_mask, bool wedged,
 		i915_error_wake_up(dev_priv, false);
 	}
 
-	i915_reset_and_wakeup(dev);
+	/*
+	 * Gen 7:
+	 *
+	 * Our reset work can grab modeset locks (since it needs to reset the
+	 * state of outstanding pageflips). Hence it must not be run on our own
+	 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
+	 * code will deadlock.
+	 * If error_work is already in the work queue then it will not be added
+	 * again. It hasn't yet executed so it will see the reset flags when
+	 * it is scheduled. If it isn't in the queue or it is currently
+	 * executing then this call will add it to the queue again so that
+	 * even if it misses the reset flags during the current call it is
+	 * guaranteed to see them on the next call.
+	 */
+	schedule_work(&dev_priv->gpu_error.work);
 }
 
 /* Called from drm generic code, passed 'crtc' which
@@ -4389,6 +4406,7 @@ void intel_irq_init(struct drm_i915_private *dev_priv)
 	struct drm_device *dev = dev_priv->dev;
 
 	INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
+	INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
 	INIT_WORK(&dev_priv->dig_port_work, i915_digport_work_func);
 	INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
 	INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#6 lore raw

RFC v2 6/12 drm/i915: Watchdog timeout support for gen8.

In reply to Tomas Elf

Watchdog timeout (or "media engine reset" as it is sometimes called, even though the render engine is also supported) 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 instruction injection before and after the emitted batch buffer start instruction in the ring buffer.

The principle of this 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 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 it reaches a previously configured threshold value.

2a. If the counter reaches the threshold value the hardware fires a watchdog interrupt that is picked up by the watchdog interrupt service routine in this commit. 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 never promote full GPU reset following a watchdog timeout in case a per-engine reset was attempted too recently. Thusly, the watchdog interrupt handler calls the error handler directly passing the engine mask of the hung engine in question, which immediately results in a per-engine hang recovery being scheduled.

2b. If the batch buffer finishes executing 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 was detected.

Currently watchdog timeout for the render engine and all available media engines are supported. The specifications elude to the VECS engine being supported but that is currently not supported by this commit.

The current default watchdog threshold value is 60 ms, since this has been emprically determined to be a good compromise for low-latency requirements and low rate of false positives.

NOTE: I don't know if Ben Widawsky had any part in this code from 3 years ago. There have been so many people involved in this already that I am in no position to know. If I've missed anyone's sob line please let me know.

---
 drivers/gpu/drm/i915/i915_debugfs.c     |  2 +-
 drivers/gpu/drm/i915/i915_dma.c         | 59 ++++++++++++++++++++
 drivers/gpu/drm/i915/i915_drv.h         |  7 ++-
 drivers/gpu/drm/i915/i915_irq.c         | 84 ++++++++++++++++++++++------
 drivers/gpu/drm/i915/i915_reg.h         |  7 +++
 drivers/gpu/drm/i915/intel_lrc.c        | 99 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_ringbuffer.h | 31 +++++++++++
 include/uapi/drm/i915_drm.h             |  5 +-
 8 files changed, 271 insertions(+), 23 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
index e33e105..a89da48 100644
@@ -4183,7 +4183,7 @@ i915_wedged_set(void *data, u64 val)
 
 	intel_runtime_pm_get(dev_priv);
 
-	i915_handle_error(dev, 0x0, val,
+	i915_handle_error(dev, 0x0, false, val,
 			  "Manually setting wedged to %llu", val);
 
 	intel_runtime_pm_put(dev_priv);
drivers/gpu/drm/i915/i915_dma.c +59 -0

71 lines not on this page · raw message

drivers/gpu/drm/i915/i915_drv.h +4 -3
index ef7c129..3d31872 100644
@@ -2563,6 +2563,7 @@ extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);
 extern void i915_update_gfx_val(struct drm_i915_private *dev_priv);
 int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool on);
 void intel_hpd_cancel_work(struct drm_i915_private *dev_priv);
+void i915_watchdog_init(struct drm_device *dev);
 static inline void i915_hangcheck_reinit(struct intel_engine_cs *engine)
 {
 	struct intel_ring_hangcheck *hc = &engine->hangcheck;
@@ -2578,9 +2579,9 @@ static inline void i915_hangcheck_reinit(struct intel_engine_cs *engine)
 
 /* i915_irq.c */
 void i915_queue_hangcheck(struct drm_device *dev);
-__printf(4, 5)
-void i915_handle_error(struct drm_device *dev, u32 engine_mask, bool wedged,
-		       const char *fmt, ...);
+__printf(5, 6)
+void i915_handle_error(struct drm_device *dev, u32 engine_mask,
+		       bool watchdog, bool wedged, const char *fmt, ...);
 
 extern void intel_irq_init(struct drm_i915_private *dev_priv);
 extern void intel_hpd_init(struct drm_i915_private *dev_priv);
drivers/gpu/drm/i915/i915_irq.c +66 -18

166 lines not on this page · raw message

drivers/gpu/drm/i915/i915_reg.h +7 -0
index af9f0ad..d2adb9b 100644
@@ -1181,6 +1181,8 @@ enum skl_disp_power_wells {
 #define RING_HEAD(base)		((base)+0x34)
 #define RING_START(base)	((base)+0x38)
 #define RING_CTL(base)		((base)+0x3c)
+#define RING_CNTR(base)        ((base)+0x178)
+#define RING_THRESH(base) ((base)+0x17C)
 #define RING_SYNC_0(base)	((base)+0x40)
 #define RING_SYNC_1(base)	((base)+0x44)
 #define RING_SYNC_2(base)	((base)+0x48)
@@ -1584,6 +1586,11 @@ enum skl_disp_power_wells {
 #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_GEN6_RENDER_WATCHDOG_INTERRUPT	(1 <<  6)
+#define GT_GEN8_RCS_WATCHDOG_INTERRUPT		(1 <<  6)
+#define   GEN6_RCS_WATCHDOG_DISABLE		1
+#define GT_GEN8_VCS_WATCHDOG_INTERRUPT		(1 <<  6)
+#define   GEN8_VCS_WATCHDOG_DISABLE		0xFFFFFFFF
 #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/intel_lrc.c +99 -0

141 lines not on this page · raw message

drivers/gpu/drm/i915/intel_ringbuffer.h +31 -0
index 35360a4..9058789 100644
@@ -30,6 +30,8 @@ struct  intel_hw_status_page {
 	struct		drm_i915_gem_object *obj;
 };
 
+#define I915_WATCHDOG_ENABLE 0
+
 #define I915_READ_TAIL(ring) I915_READ(RING_TAIL((ring)->mmio_base))
 #define I915_WRITE_TAIL(ring, val) I915_WRITE(RING_TAIL((ring)->mmio_base), val)
 
@@ -136,6 +138,9 @@ struct intel_ring_hangcheck {
 
 	/* Number of TDR hang detections */
 	u32 tdr_count;
+
+	/* Number of watchdog hang detections for this ring */
+	u32 watchdog_count;
 };
 
 struct intel_ringbuffer {
@@ -338,6 +343,12 @@ struct  intel_engine_cs {
 	/* Saved head value to be restored after reset */
 	u32 saved_head;
 
+	/*
+	 * Watchdog timer threshold values
+	 * only RCS, VCS, VCS2 rings have watchdog timeout support
+	 */
+	uint32_t watchdog_threshold;
+
 	struct {
 		struct drm_i915_gem_object *obj;
 		u32 gtt_offset;
@@ -484,6 +495,26 @@ int intel_ring_save(struct intel_engine_cs *ring,
 int intel_ring_restore(struct intel_engine_cs *ring,
 		struct drm_i915_gem_request *req);
 
+static inline bool intel_ring_supports_watchdog(struct intel_engine_cs *ring)
+{
+	bool ret = false;
+
+	if (WARN_ON(!ring))
+		goto exit;
+
+	ret = (	ring->id == RCS ||
+		ring->id == VCS ||
+		ring->id == VCS2);
+
+	if (!ret)
+		DRM_ERROR("%s does not support watchdog timeout!\n", ring->name);
+
+exit:
+	return ret;
+}
+int intel_ring_start_watchdog(struct intel_engine_cs *ring);
+int intel_ring_stop_watchdog(struct intel_engine_cs *ring);
+
 int __must_check intel_ring_idle(struct intel_engine_cs *ring);
 void intel_ring_init_seqno(struct intel_engine_cs *ring, u32 seqno);
 int intel_ring_flush_all_caches(struct intel_engine_cs *ring);
include/uapi/drm/i915_drm.h +4 -1
index 4851d66..f8af7d2 100644
@@ -760,7 +760,10 @@ struct drm_i915_gem_execbuffer2 {
 #define I915_EXEC_BSD_RING1		(1<<13)
 #define I915_EXEC_BSD_RING2		(2<<13)
 
-#define __I915_EXEC_UNKNOWN_FLAGS -(1<<15)
+/* Enable watchdog timer for this batch buffer */
+#define I915_EXEC_ENABLE_WATCHDOG       (1<<15)
+
+#define __I915_EXEC_UNKNOWN_FLAGS -(1<<16)
 
 #define I915_EXEC_CONTEXT_ID_MASK	(0xffffffff)
 #define i915_execbuffer2_set_context_id(eb2, context) \
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#7 lore raw

RFC v2 7/12 drm/i915: Fake lost context interrupts through forced CSB check.

In reply to Tomas Elf

A recurring issue during long-duration operations testing of concurrent rendering tasks with intermittent hangs is that context completion interrupts following engine resets are sometimes lost. This becomes a real problem since the hardware might have completed a previously hung context following a per-engine hang recovery and then gone idle somehow without sending an interrupt telling the driver about this. At this point the driver would be stuck waiting for context completion, thinking that the context is still active, even though the hardware would be idle and waiting for more work.

The way this is solved is by periodically checking for context submission status inconsistencies. What this means is that the ID of the currently running context on a given engine is compared against the context ID in the EXECLIST_STATUS register of the respective engine. If the two do not match and if the state does not change over time it is assumed that an interrupt was missed and that the driver is now stuck in an inconsistent state.

Following the decision that the driver and the hardware are irreversibly stuck in an inconsistent state on a certain engine, the presumably lost interrupt is faked by simply calling the execlist interrupt handler from a non-interrupt context. Even though interrupts might be lost that does not mean that the hardware does not always update the context status buffer (CSB) when appropriate, which means that any context state transitions would be captured there regardless of the interrupt being sent or not. By faking the lost interrupt the interrupt handler could act on the outstanding context status transition events in the CSB, e.g. a context completion event. In the case where the hardware would be idle but the driver would be waiting for completion, faking an interrupt and finding a context completion status event would cause the driver to remove the currently active request from the execlist queue and go idle - thereby reestablishing a consistent context submission status between the hardware and the driver.

The way this is implemented is that the hang checker will always keep alive as long as there is outstanding work. Even if the enable_hangcheck flag is disabled one part of the hang checker will always keep alive and reschedule itself, only to scan for inconsistent context submission states on all engines. As long as the context submission status of the currently running context on a given engine is consistent the hang checker works as normal and schedules hang recoveries as expected. If the status is not consistent no hang recoveries will be scheduled since no context resubmission will be possible anyway, so there is no point in trying until the status becomes consistent again. Of course, if enough hangs on the same engine are detected without any change in consistency the hang checker will go straight for the full GPU reset so there is no chance of getting stuck in this state.

It's worth keeping in mind that the watchdog timeout hang detection mechanism relies entirely on the per-engine hang recovery path. So if we have an inconsistent context submission status on the engine that the watchdog timeout has detected a hang there is no way to recover from that hang if the period hangchecker is turned off since the per-engine hang recovery cannot do its final context resubmission if the context submission status is inconsistent. That's why we need to make sure that there is always a thread alive that keeps an eye out for inconsistent context submission states, not only for the periodic hang checker but also for watchdog timeout.

Finally, since a non-interrupt context thread could end up in the interrupt handler as part of the forced CSB checking there's the chance of a race condition between the interrupt handler and the ring init code since both update ring->next_context_status_buffer. Therefore we've had to update the interrupt handler so that it grabs the execlist spinlock before updating the variable. We've also had to make sure that the ring init code grabs the execlist spinlock before initing this variable.

* v2: (Chris Wilson)
Remove context submission status consistency pre-check from i915_hangcheck_elapsed() and turn it into a pre-check to per-engine reset.

The following describes the change in philosphy in how context submission state inconsistencies are detected:

Previously we would let the periodic hang checker ensure that there were no context submission status inconsistencies on any engine, at any point. If an inconsistency was detected in the per-engine hang recovery path we would back off and defer to the next hang check since per-engine hang recovery is not effective during inconsistent context submission states.

What we do in this new version is to move the consistency pre-check from the hang checker to the earliest point in the per-engine hang recovery path. If we detect an inconsistency at that point we fake a potentially lost context event interrupt by forcing a CSB check. If there are outstanding events in the CSB these will be acted upon and hopefully that will bring the driver up to speed with the hardware. If the CSB check did not amount to anything it is concluded that the inconsistency is unresolvable and the per-engine hang recovery fails and promotes to full GPU reset instead.

In the hang checker-based consistency checking we would check the inconsistency for a number of times to make sure the detected state was stable before attempting to rectify the situation. This is possible since hang checking is a recurring event. Having moved the consistency checking to the recovery path instead (i.e. a one-time, fire & forget-style event) it is assumed that the hang detection that brought on the hang recovery has detected a stable hang and therefore, if an inconsistency is detected at that point, the inconsistency must be stable and not the result of a momentary context state transition. Therefore, unlike in the hang checker case, at the very first indication of an inconsistent context submission status the interrupt is faked speculatively. If outstanding CSB events are found it is determined that the hang was in fact just a context submission status inconsistency and no hang recovery is done. If the inconsistency cannot be resolved the per-engine hang recovery is failed and the hang is promoted to full GPU reset instead.

Cc Chris Wilson <[email protected]>
Cc Mika Kuoppala <[email protected]>
---
 drivers/gpu/drm/i915/i915_drv.c      | 118 ++++++++++++++++++++++++++---------
 drivers/gpu/drm/i915/i915_irq.c      |  32 ++--------
 drivers/gpu/drm/i915/intel_lrc.c     |  67 ++++++++++++++++++--
 drivers/gpu/drm/i915/intel_lrc.h     |   2 +-
 drivers/gpu/drm/i915/intel_lrc_tdr.h |   3 +
 5 files changed, 159 insertions(+), 63 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +87 -31
index c7ba64e..2ccb2e8 100644
@@ -917,6 +917,71 @@ int i915_reset(struct drm_device *dev)
 	return 0;
 }
 
+static bool i915_gem_reset_engine_CSSC_precheck(
+		struct drm_i915_private *dev_priv,
+		struct intel_engine_cs *engine,
+		struct drm_i915_gem_request **req,
+		int *ret)
+{
+	bool precheck_ok = true;
+	enum context_submission_status status;
+
+	WARN_ON(!ret);
+
+	*ret = 0;
+
+	status = intel_execlists_TDR_get_current_request(engine, req);
+
+	/*
+	 * If the hardware and driver states do not coincide
+	 * or if there for some reason is no current context
+	 * in the process of being submitted then bail out and
+	 * try again. Do not proceed unless we have reliable
+	 * current context state information.
+	 */
+	if (status == CONTEXT_SUBMISSION_STATUS_NONE_SUBMITTED) {
+		/*
+		 * No work in flight. This state is possible to get
+		 * into if calling the error handler directly from
+		 * debugfs.  Just do early exit and forget it happened.
+		 */
+		WARN(1, "No work in flight! Aborting recovery on %s\n",
+			engine->name);
+
+		 precheck_ok = false;
+		 *ret = 0;
+
+	} else if (status == CONTEXT_SUBMISSION_STATUS_INCONSISTENT) {
+		if (!intel_execlists_TDR_force_CSB_check(dev_priv, engine)) {
+			/*
+			 * Context submission state is inconsistent and
+			 * faking a context event IRQ did not help.
+			 * Fail and promote to higher level of
+			 * recovery!
+			 */
+			precheck_ok = false;
+			*ret = -EINVAL;
+		} else {
+			/*
+			 * Rectifying the inconsistent context
+			 * submission status helped! No reset required,
+			 * just exit and move on!
+			 */
+			 precheck_ok = false;
+			 *ret = 0;
+		}
+
+	} else if (status != CONTEXT_SUBMISSION_STATUS_OK) {
+		WARN(1, "Unexpected context submission status (%u) on %s\n",
+			status, engine->name);
+
+		precheck_ok = false;
+		*ret = -EINVAL;
+	}
+
+	return precheck_ok;
+}
+
 /**
  * i915_reset_engine - reset GPU engine after a hang
  * @engine: engine to reset
@@ -958,20 +1023,17 @@ int i915_reset_engine(struct intel_engine_cs *engine)
 	i915_gem_reset_ring_status(dev_priv, engine);
 
 	if (i915.enable_execlists) {
-		enum context_submission_status status =
-			intel_execlists_TDR_get_current_request(engine, NULL);
-
 		/*
-		 * If the hardware and driver states do not coincide
-		 * or if there for some reason is no current context
-		 * in the process of being submitted then bail out and
-		 * try again. Do not proceed unless we have reliable
-		 * current context state information.
+		 * Check context submission status consistency (CSSC) before
+		 * moving on. If the driver and hardware have different
+		 * opinions about what is going on just fail and escalate to a
+		 * higher form of hang recovery.
 		 */
-		if (status != CONTEXT_SUBMISSION_STATUS_OK) {
-			ret = -EAGAIN;
+		 if (!i915_gem_reset_engine_CSSC_precheck(dev_priv,
+							  engine,
+							  NULL,
+							  &ret))
 			goto reset_engine_error;
-		}
 	}
 
 	ret = intel_ring_disable(engine);
@@ -981,27 +1043,21 @@ int i915_reset_engine(struct intel_engine_cs *engine)
 	}
 
 	if (i915.enable_execlists) {
-		enum context_submission_status status;
-		bool inconsistent;
-
-		status = intel_execlists_TDR_get_current_request(engine,
-				&current_request);
-
-		inconsistent = (status != CONTEXT_SUBMISSION_STATUS_OK);
-		if (inconsistent) {
-			/*
-			 * If we somehow have reached this point with
-			 * an inconsistent context submission status then
-			 * back out of the previously requested reset and
-			 * retry later.
-			 */
-			WARN(inconsistent,
-			     "Inconsistent context status on %s: %u\n",
-			     engine->name, status);
-
-			ret = -EAGAIN;
+		/*
+		 * Get a hold of the currently executing context.
+		 *
+		 * Context submission status consistency is done implicitly so
+		 * we might as well check it post-engine disablement since we
+		 * get that option for free. Also, it's conceivable that the
+		 * context submission state might have changed as part of the
+		 * reset request on gen8+ so it's not completely devoid of
+		 * value to do this.
+		 */
+		 if (!i915_gem_reset_engine_CSSC_precheck(dev_priv,
+							  engine,
+							  &current_request,
+							  &ret))
 			goto reenable_reset_engine_error;
-		}
 	}
 
 	/* Sample the current ring head position */
drivers/gpu/drm/i915/i915_irq.c +6 -26
index 5672a2c..22dd96c 100644
@@ -36,6 +36,7 @@
 #include "i915_drv.h"
 #include "i915_trace.h"
 #include "intel_drv.h"
+#include "intel_lrc_tdr.h"
 
 /**
  * DOC: interrupt handling
@@ -1286,7 +1287,7 @@ static irqreturn_t gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
 			ret = IRQ_HANDLED;
 
 			if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT))
-				intel_lrc_irq_handler(&dev_priv->ring[RCS]);
+				intel_lrc_irq_handler(&dev_priv->ring[RCS], true);
 			if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT))
 				notify_ring(&dev_priv->ring[RCS]);
 			if (tmp & (GT_GEN8_RCS_WATCHDOG_INTERRUPT << GEN8_RCS_IRQ_SHIFT)) {
@@ -1303,7 +1304,7 @@ static irqreturn_t gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
 			}
 
 			if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT))
-				intel_lrc_irq_handler(&dev_priv->ring[BCS]);
+				intel_lrc_irq_handler(&dev_priv->ring[BCS], true);
 			if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT))
 				notify_ring(&dev_priv->ring[BCS]);
 		} else
@@ -1317,7 +1318,7 @@ static irqreturn_t gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
 			ret = IRQ_HANDLED;
 
 			if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT))
-				intel_lrc_irq_handler(&dev_priv->ring[VCS]);
+				intel_lrc_irq_handler(&dev_priv->ring[VCS], true);
 			if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT))
 				notify_ring(&dev_priv->ring[VCS]);
 			if (tmp & (GT_GEN8_VCS_WATCHDOG_INTERRUPT << GEN8_VCS1_IRQ_SHIFT)) {
@@ -1334,7 +1335,7 @@ static irqreturn_t gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
 			}
 
 			if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT))
-				intel_lrc_irq_handler(&dev_priv->ring[VCS2]);
+				intel_lrc_irq_handler(&dev_priv->ring[VCS2], true);
 			if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT))
 				notify_ring(&dev_priv->ring[VCS2]);
 			if (tmp & (GT_GEN8_VCS_WATCHDOG_INTERRUPT << GEN8_VCS2_IRQ_SHIFT)) {
@@ -1360,7 +1361,7 @@ static irqreturn_t gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
 			ret = IRQ_HANDLED;
 
 			if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT))
-				intel_lrc_irq_handler(&dev_priv->ring[VECS]);
+				intel_lrc_irq_handler(&dev_priv->ring[VECS], true);
 			if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT))
 				notify_ring(&dev_priv->ring[VECS]);
 		} else
@@ -2381,27 +2382,6 @@ static void i915_error_work_func(struct work_struct *work)
 
 			ret = i915_reset_engine(ring);
 
-			/*
-			 * Execlist mode only:
-			 *
-			 * -EAGAIN means that between detecting a hang (and
-			 * also determining that the currently submitted
-			 * context is stable and valid) and trying to recover
-			 * from the hang the current context changed state.
-			 * This means that we are probably not completely hung
-			 * after all. Just fail and retry by exiting all the
-			 * way back and wait for the next hang detection. If we
-			 * have a true hang on our hands then we will detect it
-			 * again, otherwise we will continue like nothing
-			 * happened.
-			 */
-			if (ret == -EAGAIN) {
-				DRM_ERROR("Reset of %s aborted due to " \
-					  "change in context submission " \
-					  "state - retrying!", ring->name);
-				ret = 0;
-			}
-
 			if (ret) {
 				DRM_ERROR("Reset of %s failed! (%d)", ring->name, ret);
 
drivers/gpu/drm/i915/intel_lrc.c +62 -5

111 lines not on this page · raw message

drivers/gpu/drm/i915/intel_lrc.h +1 -1
index d2f497c..6fae3c8 100644
@@ -88,7 +88,7 @@ int intel_execlists_submission(struct drm_device *dev, struct drm_file *file,
 			       u64 exec_start, u32 dispatch_flags);
 u32 intel_execlists_ctx_id(struct drm_i915_gem_object *ctx_obj);
 
-void intel_lrc_irq_handler(struct intel_engine_cs *ring);
+int intel_lrc_irq_handler(struct intel_engine_cs *ring, bool do_lock);
 void intel_execlists_retire_requests(struct intel_engine_cs *ring);
 
 int intel_execlists_read_tail(struct intel_engine_cs *ring,
drivers/gpu/drm/i915/intel_lrc_tdr.h +3 -0
index 4520753..041c808 100644
@@ -32,5 +32,8 @@ enum context_submission_status
 intel_execlists_TDR_get_current_request(struct intel_engine_cs *ring,
 		struct drm_i915_gem_request **req);
 
+bool intel_execlists_TDR_force_CSB_check(struct drm_i915_private *dev_priv,
+					 struct intel_engine_cs *engine);
+
 #endif /* _INTEL_LRC_TDR_H_ */
 
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#8 lore raw

RFC v2 8/12 drm/i915: Debugfs interface for per-engine hang recovery.

In reply to Tomas Elf

1. The i915_wedged_set() function allows us to schedule three forms of hang recovery:

a) Legacy hang recovery: By passing e.g. -1 we trigger the legacy full GPU reset recovery path.

b) Single engine hang recovery: By passing an engine ID in the interval of [0, I915_NUM_RINGS) we can schedule hang recovery of any single engine assuming that the context submission consistency requirements are met (otherwise the hang recovery path will simply exit early and wait for another hang detection). The values are assumed to use up bits 3:0 only since we certainly do not support as many as 16 engines.

This mode is supported since there are several legacy test applications that rely on this interface.

c) Multiple engine hang recovery: By passing in an engine flag mask in bits 31:8 (bit 8 corresponds to engine 0 = RCS, bit 9 corresponds to engine 1 = VCS etc) we can schedule any combination of engine hang recoveries as we please. For example, by passing in the value 0x3 << 8 we would schedule hang recovery for engines 0 and 1 (RCS and VCS) at the same time.

If bits in fields 3:0 and 31:8 are both used then single engine hang recovery mode takes presidence and bits 31:8 are ignored.

2. The i915_hangcheck_read() function produces a set of statistics related to:

a) Number of engine hangs detected by periodic hang checker.
b) Number of watchdog timeout hangs detected.
c) Number of full GPU resets carried out.
d) Number of engine resets carried out.

These statistics are presented in a very parser-friendly way and are used by the TDR ULT to poll system behaviour to validate test outcomes.

* v2: (Chris Wilson)
- After review comments by Chris Wilson we're dropping the dual-mode parameter value interpretation in i915_wedged_set(). In this version we only accept engine id flag masks that contain the engine id flags of all currently hung engines. Full GPU reset is most easily requested by passing an all zero engine id flag mask.

- Moved TDR-specific engine metrics like number of detected engine hangs and number of per-engine resets into i915_hangcheck_info() from i915_hangcheck_read().

---
 drivers/gpu/drm/i915/i915_debugfs.c | 76 ++++++++++++++++++++++++++++++++++---
 1 file changed, 71 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +71 -5
index a89da48..d99c152 100644
@@ -1302,6 +1302,8 @@ static int i915_hangcheck_info(struct seq_file *m, void *unused)
 	} else
 		seq_printf(m, "Hangcheck inactive\n");
 
+	seq_printf(m, "Full GPU resets = %u\n", i915_reset_count(&dev_priv->gpu_error));
+
 	for_each_ring(ring, dev_priv, i) {
 		seq_printf(m, "%s:\n", ring->name);
 		seq_printf(m, "\tseqno = %x [current %x]\n",
@@ -1313,6 +1315,12 @@ static int i915_hangcheck_info(struct seq_file *m, void *unused)
 			   (long long)ring->hangcheck.max_acthd);
 		seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
 		seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
+		seq_printf(m, "\tengine resets = %u\n",
+			ring->hangcheck.reset_count);
+		seq_printf(m, "\tengine hang detections = %u\n",
+			ring->hangcheck.tdr_count);
+		seq_printf(m, "\tengine watchdog timeout detections = %u\n",
+			ring->hangcheck.watchdog_count);
 	}
 
 	return 0;
@@ -2030,7 +2038,7 @@ static int i915_execlists(struct seq_file *m, void *data)
 		seq_printf(m, "%s\n", ring->name);
 
 		status = I915_READ(RING_EXECLIST_STATUS(ring));
-		ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
+		ctx_id = I915_READ(RING_EXECLIST_STATUS_CTX_ID(ring));
 		seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
 			   status, ctx_id);
 
@@ -4164,11 +4172,47 @@ i915_wedged_get(void *data, u64 *val)
 	return 0;
 }
 
+static const char *ringid_to_str(enum intel_ring_id ring_id)
+{
+	switch (ring_id) {
+	case RCS:
+		return "RCS";
+	case VCS:
+		return "VCS";
+	case BCS:
+		return "BCS";
+	case VECS:
+		return "VECS";
+	case VCS2:
+		return "VCS2";
+	}
+
+	return "unknown";
+}
+
 static int
 i915_wedged_set(void *data, u64 val)
 {
 	struct drm_device *dev = data;
 	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct intel_engine_cs *engine;
+	u32 i;
+#define ENGINE_MSGLEN 64
+	char msg[ENGINE_MSGLEN];
+
+	/*
+	 * Val contains the engine flag mask of engines to be reset.
+	 *
+	 * Full GPU reset is implied in the following two cases:
+	 * 1. val == 0x0
+	 * 2. val >= (1 << I915_NUM_RINGS)
+	 *
+	 * Bit 0: RCS engine
+	 * Bit 1: VCS engine
+	 * Bit 2: BCS engine
+	 * Bit 3: VECS engine
+	 * Bit 4: VCS2 engine (if available)
+	 */
 
 	/*
 	 * There is no safeguard against this debugfs entry colliding
@@ -4177,14 +4221,36 @@ i915_wedged_set(void *data, u64 val)
 	 * test harness is responsible enough not to inject gpu hangs
 	 * while it is writing to 'i915_wedged'
 	 */
-
-	if (i915_reset_in_progress(&dev_priv->gpu_error))
+	if (i915_gem_check_wedge(dev_priv, NULL, true))
 		return -EAGAIN;
 
 	intel_runtime_pm_get(dev_priv);
 
-	i915_handle_error(dev, 0x0, false, val,
-			  "Manually setting wedged to %llu", val);
+	memset(msg, 0, sizeof(msg));
+
+	if (val) {
+		scnprintf(msg, sizeof(msg), "Manual reset:");
+
+		/* Assemble message string */
+		for_each_ring(engine, dev_priv, i)
+			if (intel_ring_flag(engine) & val) {
+				DRM_INFO("Manual reset: %s\n", engine->name);
+
+				scnprintf(msg, sizeof(msg),
+					  "%s [%s]",
+					  msg,
+					  ringid_to_str(i));
+			}
+
+	} else {
+		scnprintf(msg, sizeof(msg), "Manual global reset");
+	}
+
+	i915_handle_error(dev,
+			  val,
+			  false,
+			  true,
+			  msg);
 
 	intel_runtime_pm_put(dev_priv);
 
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#9 lore raw

RFC v2 9/12 drm/i915: TDR/watchdog trace points.

In reply to Tomas Elf

Defined trace points and sprinkled the usage of these throughout the TDR/watchdog implementation.

The following trace points are supported:

1. trace_i915_tdr_gpu_recovery:
Called at the onset of the full GPU reset recovery path.

2. trace_i915_tdr_engine_recovery:
Called at the onset of the per-engine recovery path.

3. i915_tdr_recovery_start:
Called at the onset of hang recovery before recovery mode has been decided.

4. i915_tdr_recovery_complete:
Called at the point of hang recovery completion.

5. i915_tdr_recovery_queued:
Called once the error handler decides to schedule the actual hang recovery, which marks the end of the hang detection path.

6. i915_tdr_engine_save:
Called at the point of saving the engine state during per-engine hang recovery.

7. i915_tdr_gpu_reset_complete:
Called at the point of full GPU reset recovery completion.

8. i915_tdr_engine_reset_complete:
Called at the point of per-engine recovery completion.

9. i915_tdr_forced_csb_check:
Called at the completion of a forced CSB check.

10. i915_tdr_hang_check:
Called for every engine in the periodic hang checker loop before moving on to the next engine. Provides an overview of all hang check stats in real-time. The collected stats are:

a. Engine name.

b. Current engine seqno.

c. Seqno of previous hang check iteration for that engine.

d. ACTHD register value of given engine.

e. Current hang check score of given engine (and whether or not the engine has been detected as hung).

f. Current action for given engine.

g. Busyness of given engine.

h. Submission status of currently running context on given engine.

* v2:
As a consequence of the faking context event interrupt commit being moved from the hang checker to the per-engine recovery path we no longer check context submission status from the hang checker. Therefore there is no need to provide submission status of the currently running context to the trace_i915_tdr_hang_check() event.

---
 drivers/gpu/drm/i915/i915_drv.c       |   3 +
 drivers/gpu/drm/i915/i915_drv.h       |   1 +
 drivers/gpu/drm/i915/i915_gpu_error.c |   2 +-
 drivers/gpu/drm/i915/i915_irq.c       |   9 +-
 drivers/gpu/drm/i915/i915_trace.h     | 293 ++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_lrc.c      |   8 +-
 drivers/gpu/drm/i915/intel_uncore.c   |   4 +
 7 files changed, 316 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +3 -0
index 2ccb2e8..f923036 100644
@@ -845,6 +845,7 @@ int i915_reset(struct drm_device *dev)
 	if (!i915.reset)
 		return 0;
 
+	trace_i915_tdr_gpu_recovery(dev);
 	intel_reset_gt_powersave(dev);
 
 	mutex_lock(&dev->struct_mutex);
@@ -1017,6 +1018,8 @@ int i915_reset_engine(struct intel_engine_cs *engine)
 
 	WARN_ON(!mutex_is_locked(&dev->struct_mutex));
 
+	trace_i915_tdr_engine_recovery(engine);
+
         /* Take wake lock to prevent power saving mode */
 	intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
 
drivers/gpu/drm/i915/i915_drv.h +1 -0
index 3d31872..9f37cba 100644
@@ -3129,6 +3129,7 @@ void i915_destroy_error_state(struct drm_device *dev);
 
 void i915_get_extra_instdone(struct drm_device *dev, uint32_t *instdone);
 const char *i915_cache_level_str(struct drm_i915_private *i915, int type);
+const char *hangcheck_action_to_str(enum intel_ring_hangcheck_action a);
 
 /* i915_cmd_parser.c */
 int i915_cmd_parser_get_version(void);
drivers/gpu/drm/i915/i915_gpu_error.c +1 -1
index ac22614..cee1825 100644
@@ -220,7 +220,7 @@ static void print_error_buffers(struct drm_i915_error_state_buf *m,
 	}
 }
 
-static const char *hangcheck_action_to_str(enum intel_ring_hangcheck_action a)
+const char *hangcheck_action_to_str(enum intel_ring_hangcheck_action a)
 {
 	switch (a) {
 	case HANGCHECK_IDLE:
drivers/gpu/drm/i915/i915_irq.c +8 -1
index 22dd96c..beee624 100644
@@ -2359,6 +2359,7 @@ static void i915_error_work_func(struct work_struct *work)
 
 	mutex_lock(&dev->struct_mutex);
 
+	trace_i915_tdr_recovery_start(dev);
 	kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
 
 	for_each_ring(ring, dev_priv, i) {
@@ -2477,6 +2478,7 @@ static void i915_error_work_func(struct work_struct *work)
 			kobject_uevent_env(&dev->primary->kdev->kobj,
 					   KOBJ_CHANGE, reset_done_event);
 	}
+	trace_i915_tdr_recovery_complete(dev);
 }
 
 static void i915_report_and_clear_eir(struct drm_device *dev)
@@ -2607,6 +2609,7 @@ void i915_handle_error(struct drm_device *dev, u32 engine_mask,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	va_list args;
 	char error_msg[80];
+	bool full_reset = true;
 
 	struct intel_engine_cs *engine;
 
@@ -2624,7 +2627,6 @@ void i915_handle_error(struct drm_device *dev, u32 engine_mask,
 		 *	2. The hardware does not support it (pre-gen7).
 		 *	3. We already tried per-engine reset recently.
 		 */
-		bool full_reset = true;
 
 		/*
 		 * TBD: We currently only support per-engine reset for gen8+.
@@ -2648,6 +2650,7 @@ void i915_handle_error(struct drm_device *dev, u32 engine_mask,
 						i915.gpu_reset_promotion_time;
 
 					engine->hangcheck.last_engine_reset_time = now;
+
 				} else {
 					/*
 					 * Watchdog timeout always results
@@ -2696,6 +2699,8 @@ void i915_handle_error(struct drm_device *dev, u32 engine_mask,
 		i915_error_wake_up(dev_priv, false);
 	}
 
+	trace_i915_tdr_recovery_queued(dev, engine_mask, watchdog, full_reset);
+
 	/*
 	 * Gen 7:
 	 *
@@ -3146,6 +3151,8 @@ static void i915_hangcheck_elapsed(struct work_struct *work)
 		ring->hangcheck.seqno = seqno;
 		ring->hangcheck.acthd = acthd;
 		busy_count += busy;
+
+		trace_i915_tdr_hang_check(ring, seqno, acthd, busy);
 	}
 
 	for_each_ring(ring, dev_priv, i) {
drivers/gpu/drm/i915/i915_trace.h +293 -0

299 lines not on this page · raw message

drivers/gpu/drm/i915/intel_lrc.c +6 -2
index 476eff0..a8f2954 100644
@@ -1663,7 +1663,7 @@ gen8_ring_save(struct intel_engine_cs *ring, struct drm_i915_gem_request *req,
 	struct intel_context *ctx;
 	int ret = 0;
 	int clamp_to_tail = 0;
-	uint32_t head;
+	uint32_t head, old_head;
 	uint32_t tail;
 	uint32_t head_addr;
 	uint32_t tail_addr;
@@ -1678,7 +1678,7 @@ gen8_ring_save(struct intel_engine_cs *ring, struct drm_i915_gem_request *req,
 	 * Read head from MMIO register since it contains the
 	 * most up to date value of head at this point.
 	 */
-	head = I915_READ_HEAD(ring);
+	old_head = head = I915_READ_HEAD(ring);
 
 	/*
 	 * Read tail from the context because the execlist queue
@@ -1735,6 +1735,9 @@ gen8_ring_save(struct intel_engine_cs *ring, struct drm_i915_gem_request *req,
 	head |= (head_addr & HEAD_ADDR);
 	ring->saved_head = head;
 
+	trace_i915_tdr_engine_save(ring, old_head,
+		head, force_advance);
+
 	return 0;
 }
 
@@ -2638,6 +2641,7 @@ bool intel_execlists_TDR_force_CSB_check(struct drm_i915_private *dev_priv,
 		DRM_ERROR("Forced CSB check of %s ineffective!\n", engine->name);
 	spin_unlock_irqrestore(&engine->execlist_lock, flags);
 
+	trace_i915_tdr_forced_csb_check(engine, !!was_effective);
 	wake_up_all(&engine->irq_queue);
 
 	return !!was_effective;
drivers/gpu/drm/i915/intel_uncore.c +4 -0
index 91427ac..67a34aa 100644
@@ -1442,6 +1442,8 @@ static int gen6_do_reset(struct drm_device *dev)
 	/* Spin waiting for the device to ack the reset request */
 	ret = wait_for((__raw_i915_read32(dev_priv, GEN6_GDRST) & GEN6_GRDOM_FULL) == 0, 500);
 
+	trace_i915_tdr_gpu_reset_complete(dev);
+
 	intel_uncore_forcewake_reset(dev, true);
 
 	return ret;
@@ -1520,6 +1522,8 @@ static int do_engine_reset_nolock(struct intel_engine_cs *engine)
 		break;
 	}
 
+	trace_i915_tdr_engine_reset_complete(engine);
+
 	return ret;
 }
 
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#10 lore raw

RFC v2 10/12 drm/i915: Port of Added scheduler support to __wait_request() calls

In reply to Tomas Elf

This is a partial port of the following patch from John Harrison's GPU scheduler patch series: (patch sent to Intel-GFX with the subject line "[Intel-gfx] [RFC 19/39] drm/i915: Added scheduler support to __wait_request() calls" on Fri 17 July 2015)

Author: John Harrison <[email protected]>
Date: Thu Apr 10 10:48:55 2014 +0100
Subject: drm/i915: Added scheduler support to __wait_request() calls

Removed all scheduler references and backported it to this baseline. The reason we need this is because Chris Wilson has pointed out that threads that don't hold the struct_mutex should not be thrown out of __i915_wait_request during TDR hang recovery. Therefore we need a way to determine which threads are holding the mutex and which are not.

---
 drivers/gpu/drm/i915/i915_drv.h      |  3 ++-
 drivers/gpu/drm/i915/i915_gem.c      | 11 ++++++-----
 drivers/gpu/drm/i915/intel_display.c |  2 +-
 3 files changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -1
index 9f37cba..2cf8b38 100644
@@ -2864,7 +2864,8 @@ int __i915_wait_request(struct drm_i915_gem_request *req,
 			unsigned reset_counter,
 			bool interruptible,
 			s64 *timeout,
-			struct drm_i915_file_private *file_priv);
+			struct drm_i915_file_private *file_priv,
+			bool is_locked);
 int __must_check i915_wait_request(struct drm_i915_gem_request *req);
 int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
 int __must_check
drivers/gpu/drm/i915/i915_gem.c +6 -5
index 036735b..340418b 100644
@@ -1233,7 +1233,8 @@ int __i915_wait_request(struct drm_i915_gem_request *req,
 			unsigned reset_counter,
 			bool interruptible,
 			s64 *timeout,
-			struct drm_i915_file_private *file_priv)
+			struct drm_i915_file_private *file_priv,
+			bool is_locked)
 {
 	struct intel_engine_cs *ring = i915_gem_request_get_ring(req);
 	struct drm_device *dev = ring->dev;
@@ -1376,7 +1377,7 @@ i915_wait_request(struct drm_i915_gem_request *req)
 	reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
 	i915_gem_request_reference(req);
 	ret = __i915_wait_request(req, reset_counter,
-				  interruptible, NULL, NULL);
+				  interruptible, NULL, NULL, true);
 	i915_gem_request_unreference(req);
 	return ret;
 }
@@ -1456,7 +1457,7 @@ i915_gem_object_wait_rendering__nonblocking(struct drm_i915_gem_object *obj,
 	reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
 	i915_gem_request_reference(req);
 	mutex_unlock(&dev->struct_mutex);
-	ret = __i915_wait_request(req, reset_counter, true, NULL, file_priv);
+	ret = __i915_wait_request(req, reset_counter, true, NULL, file_priv, false);
 	mutex_lock(&dev->struct_mutex);
 	i915_gem_request_unreference(req);
 	if (ret)
@@ -2950,7 +2951,7 @@ i915_gem_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 
 	ret = __i915_wait_request(req, reset_counter, true,
 				  args->timeout_ns > 0 ? &args->timeout_ns : NULL,
-				  file->driver_priv);
+				  file->driver_priv, false);
 	i915_gem_request_unreference__unlocked(req);
 	return ret;
 
@@ -4139,7 +4140,7 @@ i915_gem_ring_throttle(struct drm_device *dev, struct drm_file *file)
 	if (target == NULL)
 		return 0;
 
-	ret = __i915_wait_request(target, reset_counter, true, NULL, NULL);
+	ret = __i915_wait_request(target, reset_counter, true, NULL, NULL, false);
 	if (ret == 0)
 		queue_delayed_work(dev_priv->wq, &dev_priv->mm.retire_work, 0);
 
drivers/gpu/drm/i915/intel_display.c +1 -1
index 97922fb..3e1db90 100644
@@ -10358,7 +10358,7 @@ static void intel_mmio_flip_work_func(struct work_struct *work)
 	if (mmio_flip->req)
 		WARN_ON(__i915_wait_request(mmio_flip->req,
 					    crtc->reset_counter,
-					    false, NULL, NULL) != 0);
+					    false, NULL, NULL, false) != 0);
 
 	intel_do_mmio_flip(crtc);
 	if (mmio_flip->req) {
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#11 lore raw

RFC v2 11/12 drm/i915: Fix __i915_wait_request() behaviour during hang detection.

In reply to Tomas Elf

Use is_locked parameter in __i915_wait_request() to determine if a thread should be forced to back off and retry or if it can continue sleeping. Don't return -EIO from __i915_wait_request since that is bad for the upper layers, only -EAGAIN to signify reset in progress.

Also, use is_locked in trace_i915_gem_request_wait_begin() trace point for more accurate reflection of current thread's lock state.

Cc Chris Wilson <[email protected]>
Cc Mika Kuoppala <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem.c   | 66 ++++++++++++++++++++++++++++++---------
 drivers/gpu/drm/i915/i915_trace.h | 15 +++------
 2 files changed, 56 insertions(+), 25 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +52 -14
index 340418b..3339365 100644
@@ -1245,7 +1245,6 @@ int __i915_wait_request(struct drm_i915_gem_request *req,
 	unsigned long timeout_expire;
 	s64 before, now;
 	int ret;
-	int reset_in_progress = 0;
 
 	WARN(!intel_irqs_enabled(dev_priv), "IRQs disabled");
 
@@ -1262,28 +1261,67 @@ int __i915_wait_request(struct drm_i915_gem_request *req,
 		return -ENODEV;
 
 	/* Record current time in case interrupted by signal, or wedged */
-	trace_i915_gem_request_wait_begin(req);
+	trace_i915_gem_request_wait_begin(req, is_locked);
 	before = ktime_get_raw_ns();
 	for (;;) {
 		struct timer_list timer;
+		bool full_gpu_reset_completed_unlocked = false;
+		bool reset_in_progress_locked = false;
 
 		prepare_to_wait(&ring->irq_queue, &wait,
 				interruptible ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
 
-		/* We need to check whether any gpu reset happened in between
-		 * the caller grabbing the seqno and now ... */
-		reset_in_progress =
-			i915_gem_check_wedge(ring->dev->dev_private, NULL, interruptible);
+		/*
+		 * Rules for waiting with/without struct_mutex held in the face
+		 * of asynchronous TDR hang detection/recovery:
+		 *
+		 * ("reset in progress" = TDR has detected a hang, hang
+		 * recovery may or may not have commenced)
+		 *
+		 * 1. Is this thread holding the struct_mutex and is any of the
+		 *    following true?
+		 *
+		 *	a) Is any kind of reset in progress?
+		 *	b) Has a full GPU reset happened while this thread were
+		 *	   sleeping?
+		 *
+		 *    If so:
+		 *	Return -EAGAIN. The caller should interpret this as:
+		 *	Release struct_mutex, try to acquire struct_mutex
+		 *	(through i915_mutex_lock_interruptible(), which will
+		 *	fail as long as any reset is in progress) and retry the
+		 *	call to __i915_wait_request(), which hopefully will go
+		 *	better as soon as the hang has been resolved.
+		 *
+		 * 2. Is this thread not holding the struct_mutex and has a
+		 *    full GPU reset completed?
+		 *
+		 *    If so:
+		 *	Return 0. Since the request has been purged there is no
+		 *	requests left to wait for. Just go home.
+		 *
+		 * 3. Is this thread not holding the struct_mutex and is any
+		 *    kind of reset in progress?
+		 *
+		 *   If so:
+		 *	This thread may keep on waiting.
+		 */
 
-		if ((reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) ||
-		     reset_in_progress) {
+		reset_in_progress_locked =
+			(((i915_gem_check_wedge(ring->dev->dev_private, NULL, interruptible)) ||
+			  (reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))) &&
+			  is_locked);
 
-			/* ... but upgrade the -EAGAIN to an -EIO if the gpu
-			 * is truely gone. */
-			if (reset_in_progress)
-				ret = reset_in_progress;
-			else
-				ret = -EAGAIN;
+		if (reset_in_progress_locked) {
+			ret = -EAGAIN;
+			break;
+		}
+
+		full_gpu_reset_completed_unlocked =
+			(reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter));
+
+		if (full_gpu_reset_completed_unlocked) {
+			ret = 0;
 			break;
 		}
 
drivers/gpu/drm/i915/i915_trace.h +4 -11
index b970259..fe0524e 100644
@@ -556,8 +556,8 @@ DEFINE_EVENT(i915_gem_request, i915_gem_request_complete,
 );
 
 TRACE_EVENT(i915_gem_request_wait_begin,
-	    TP_PROTO(struct drm_i915_gem_request *req),
-	    TP_ARGS(req),
+	    TP_PROTO(struct drm_i915_gem_request *req, bool blocking),
+	    TP_ARGS(req, blocking),
 
 	    TP_STRUCT__entry(
 			     __field(u32, dev)
@@ -566,25 +566,18 @@ TRACE_EVENT(i915_gem_request_wait_begin,
 			     __field(bool, blocking)
 			     ),
 
-	    /* NB: the blocking information is racy since mutex_is_locked
-	     * doesn't check that the current thread holds the lock. The only
-	     * other option would be to pass the boolean information of whether
-	     * or not the class was blocking down through the stack which is
-	     * less desirable.
-	     */
 	    TP_fast_assign(
 			   struct intel_engine_cs *ring =
 						i915_gem_request_get_ring(req);
 			   __entry->dev = ring->dev->primary->index;
 			   __entry->ring = ring->id;
 			   __entry->seqno = i915_gem_request_get_seqno(req);
-			   __entry->blocking =
-				     mutex_is_locked(&ring->dev->struct_mutex);
+			   __entry->blocking = blocking;
 			   ),
 
 	    TP_printk("dev=%u, ring=%u, seqno=%u, blocking=%s",
 		      __entry->dev, __entry->ring,
-		      __entry->seqno, __entry->blocking ?  "yes (NB)" : "no")
+		      __entry->seqno, __entry->blocking ?  "yes" : "no")
 );
 
 DEFINE_EVENT(i915_gem_request, i915_gem_request_wait_end,
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#12 lore raw

RFC v2 12/12 drm/i915: Extended error state with TDR count, watchdog count and engine reset count

In reply to Tomas Elf

These new TDR-specific metrics have previously been added to i915_hangcheck_info() in debugfs. During design review Chris Wilson asked for these metrics to be added to the error state as well.

Cc Chris Wilson <[email protected]>
Cc Mika Kuoppala <[email protected]>
---
 drivers/gpu/drm/i915/i915_drv.h       | 3 +++
 drivers/gpu/drm/i915/i915_gpu_error.c | 6 ++++++
 2 files changed, 9 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +3 -0
index 2cf8b38..862e995 100644
@@ -447,6 +447,9 @@ struct drm_i915_error_state {
 		int hangcheck_score;
 		enum intel_ring_hangcheck_action hangcheck_action;
 		int num_requests;
+		int hangcheck_tdr_count;
+		int hangcheck_watchdog_count;
+		int hangcheck_reset_count;
 
 		/* our own tracking of ring head and tail */
 		u32 cpu_ring_head;
drivers/gpu/drm/i915/i915_gpu_error.c +6 -0
index cee1825..f4d89df 100644
@@ -303,6 +303,9 @@ static void i915_ring_error_state(struct drm_i915_error_state_buf *m,
 	err_printf(m, "  hangcheck: %s [%d]\n",
 		   hangcheck_action_to_str(ring->hangcheck_action),
 		   ring->hangcheck_score);
+	err_printf(m, "  TDR count: %d\n", ring->hangcheck_tdr_count);
+	err_printf(m, "  Watchdog count: %d\n", ring->hangcheck_watchdog_count);
+	err_printf(m, "  Engine reset count: %d\n", ring->hangcheck_reset_count);
 }
 
 void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...)
@@ -920,6 +923,9 @@ static void i915_record_ring_state(struct drm_device *dev,
 
 	ering->hangcheck_score = ring->hangcheck.score;
 	ering->hangcheck_action = ring->hangcheck.action;
+	ering->hangcheck_tdr_count = ring->hangcheck.tdr_count;
+	ering->hangcheck_watchdog_count = ring->hangcheck.watchdog_count;
+	ering->hangcheck_reset_count = ring->hangcheck.reset_count;
 
 	if (USES_PPGTT(dev)) {
 		int i;
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#13 lore raw

v2 cover TDR/watchdog timeout support for gen8 (edit: fixed coverletter)

In reply to Tomas Elf

This patch series introduces the following features:

* Feature 1: TDR (Timeout Detection and Recovery) for gen8 execlist mode.

TDR is an umbrella term for anything that goes into detecting and recovering from GPU hangs and is a term more widely used outside of the upstream driver.
This feature introduces an extensible framework that currently supports gen8 but that can be easily extended to support gen7 as well (which is already the case in GMIN but unfortunately in a not quite upstreamable form). The code contained in this submission represents the essentials of what is currently in GMIN merged with what is currently in upstream (as of the time when this work commenced a few months back).

This feature adds a new hang recovery path alongside the legacy GPU reset path, which takes care of engine recovery only. Aside from adding support for per-engine recovery this feature also introduces rules for how to promote a potential per-engine reset to a legacy, full GPU reset.

The hang checker now integrates with the error handler in a slightly different way in that it allows hang recovery on multiple engines at the same time by passing an engine flag mask to the error handler where flags representing all of the hung engines are set. This allows us to schedule hang recovery once for all currently hung engines instead of one hang recovery per detected engine hang. Previously, when only full GPU reset was supported this was all the same since it wouldn't matter if one or four engines were hung at any given point since it would all amount to the same thing - the GPU getting reset. As it stands now the behaviour is different depending on which engine is hung since each engine is reset separately from all the other engines, therefore we have to think about this in terms of scheduling cost and recovery latency. (see open question below)

OPEN QUESTIONS:

1. Do we want to investigate the possibility of per-engine hang detection? In the current upstream driver there is only one work queue that handles the hang checker and everything from initial hang detection to final hang recovery runs in this thread. This makes sense if you're only supporting one form of hang recovery - using full GPU reset and nothing tied to any particular engine. However, as part of this patch series we're changing that by introducing per-engine hang recovery. It could make sense to introduce multiple work queues - one per engine - to run multiple hang checking threads in parallel.

This would potentially allow savings in terms of recovery latency since we don't have to scan all engines every time the hang checker is scheduled and the error handler does not have to scan all engines every time it is scheduled. Instead, we could implement one work queue per engine that would invoke the hang checker that only checks _that_ particular engine and then the error handler is invoked for _that_ particular engine. If one engine has hung the latency for getting to the hang recovery path for that particular engine would be (Time For Hang Checking One Engine) + (Time For Error Handling One Engine) rather than the time it takes to do hang checking for all engines + the time it takes to do error handling for all engines that have been detected as hung (which in the worst case would be all engines). There would potentially be as many hang checker and error handling threads going on concurrently as there are engines in the hardware but they would all be running in parallel without any significant locking. The first time where any thread needs exclusive access to the driver is at the point of the actual hang recovery but the time it takes to get there would theoretically be lower and the time it actually takes to do per-engine hang recovery is quite a lot lower than the time it takes to actually detect a hang reliably.

How much we would save by such a change still needs to be analysed and compared against the current single-thread model but it makes sense from a theoretical design point of view.

* Feature 2: Watchdog Timeout (a.k.a "media engine reset") for gen8.

This feature allows userland applications to control whether or not individual batch buffers should have a first-level, fine-grained, hardware-based hang detection mechanism on top of the ordinary, software-based periodic hang checker that is already in the driver. The advantage over relying solely on the current software-based hang checker is that the watchdog timeout mechanism is about 1000x quicker and more precise. Since it's not a full driver-level hang detection mechanism but only targetting one individual batch buffer at a time it can afford to be that quick without risking an increase in false positive hang detection.

This feature includes the following changes:

a) Watchdog timeout interrupt service routine for handling watchdog interrupts and connecting these to per-engine hang recovery.

b) Injection of watchdog timer enablement/cancellation instructions before/after the batch buffer start instruction in the ring buffer so that watchdog timeout is connected to the submission of an individual batch buffer.

c) Extension of the DRM batch buffer interface, exposing the watchdog timeout feature to userland. We've got two open source groups in VPG currently in the process of integrating support for this feature, which should make it principally possible to upstream this extension.

There is currently full watchdog timeout support for gen7 in GMIN and it is quite similar to the gen8 implementation so there is nothing obvious that prevents us from upstreaming that code along with the gen8 code. However, watchdog timeout is fully dependent on the per-engine hang recovery path and that is not part of this code submission for gen7. Therefore watchdog timeout support for gen7 has been excluded until per-engine hang recovery support for gen7 has landed upstream.

As part of this submission we've had to reinstate the work queue that was previously in place between the error handler and the hang recovery path. The reason for this is that the per-engine recovery path is called directly from the interrupt handler in the case of watchdog timeout. In that situation there's no way of grabbing the struct_mutex, which is a requirement for the hang recovery path. Therefore, by reinstating the work queue we provide a unified execution context for the hang recovery code that allows the hang recovery code to grab whatever locks it needs without sacrificing interrupt latency too much or sleeping indefinitely in hard interrupt context.

* Feature 3. Context Submission Status Consistency checking

Something that becomes apparent when you run long-duration operations tests with concurrent rendering processes with intermittently injected hangs is that it seems like the GPU forgets to send context completion interrupts to the driver under some circumstances. What this means is that the driver sometimes gets stuck on a context that never seems to finish, all the while the hardware has completed and is waiting for more work.

The problem with this is that the per-engine hang recovery path relies on context resubmission to kick off the hardware again following an engine reset.
This can only be done safely if the hardware and driver share the same opinion about the current state. Therefore we've extended the periodic hang checker to check for context submission state inconsistencies aside from the hang checking it already does.

If such a state is detected it is assumed (based on experience) that a context completion interrupt has been lost somehow. If this state persists for some time an attempt to correct it is made by faking the presumably lost context completion interrupt by manually calling the execlist interrupt handler, which is normally called from the main interrupt handler cued by a received context event interrupt. Just because an interrupt goes missing does not mean that the context status buffer (CSB) does not get appropriately updated by the hardware, which means that we can expect to find all the recent changes to the context states for each engine captured there.

If there are outstanding context status changes in store there then the faked context event interrupt will allow the interrupt handler to act on them. In the case of lost context completion interrupts this will prompt the driver to remove the already completed context from the execlist queue and move on to the next pending piece of work and thereby eliminating the inconsistency.

* Feature 4. Debugfs extensions for per-engine hang recovery and TDR/watchdog trace points.

GITHUB REPOSITORY:
https://github.com/telf/TDR_watchdog_RFC_1.git

RFC VERSION 1 BRANCH:
20150608_TDR_upstream_adaptation_single-thread_hangchecking_RFC_delivery_sendmail_1

RFC VERSION 2 BRANCH:
20150604_TDR_upstream_adaptation_single-thread_hangchecking_RFCv2_delivery_sendmail_1

CHANGES IN VERSION 2
--------------------
Version 2 of this RFC series addresses design concerns that Chris Wilson and Daniel Vetter et. al. had with the first version of this RFC series. Below is a summary of all the changes made between versions:

* [1/12] drm/i915: Early exit from semaphore_waits_for for execlist mode:
Turned the execlist mode check into a ringbuffer NULL check to make it more submission mode agnostic and less of a layering violation.

* [2/12] drm/i915: Make i915_gem_reset_ring_status() public
Replaces the old patch in RFCv1: "drm/i915: Add reset stats entry point for per-engine reset"

* [3/12] drm/i915: Adding TDR / per-engine reset support for gen8:

1. Simply use the previously private function i915_gem_reset_ring_status() from the engine hang recovery path to set active/pending context status. This replicates the same behaviour as in full GPU reset but for a single, targetted engine.

2. Remove all additional uevents for both full GPU reset and per-engine reset. Adapted uevent behaviour to the new per-engine hang recovery mode in that it will only send one uevent regardless of which form of recovery is employed. If a per-engine reset is attempted first then one uevent will be dispatched. If that recovery mode fails and the hang is promoted to a full GPU reset no further uevents will be dispatched at that point.

3. Removed the 2*HUNG hang threshold from i915_hangcheck_elapsed in order to not make the hang detection algorithm too complicated. This threshold was introduced to compensate for the possibility that hang recovery might be delayed due to inconsistent context submission status that would prevent per-engine hang recovery from happening. In a later patch we introduce faked context event interrupts and inconsistency rectification at the onset of per-engine hang recovery instead of relying on the hang checker to do this for us. Therefore, since we do not delay and defer to future hang detections, we never allow hangs to go addressed beyond the HUNG threshold and therefore there is no need for any further thresholds.

4. Tidied up the TDR context resubmission path in intel_lrc.c . Reduced the amount of duplication by relying entirely on the normal unqueue function. Added a new parameter to the unqueue function that takes into consideration if the unqueue call is for a first-time context submission or a resubmission and adapts the handling of elsp_submitted accordingly. The reason for this is that for context resubmission we don't expect any further interrupts for the submission or the following context completion. A more elegant way of handling this would be to phase out elsp_submitted altogether, however that's part of a LRC/execlist cleanup effort that is happening independently of this RFC. For now we make this change as simple as possible with as few non-TDR-related side-effects as possible.

* [4/12] drm/i915: Extending i915_gem_check_wedge to check engine reset in progress:
Removed unwarranted changes made to i915_gem_ring_throttle()

* [7/12] drm/i915: Fake lost context interrupts through forced CSB check Remove context submission status consistency pre-check from i915_hangcheck_elapsed() and turn it into a pre-check to per-engine reset.

The following describes the change in philosphy in how context submission state inconsistencies are detected:

Previously we would let the periodic hang checker ensure that there were no context submission status inconsistencies on any engine, at any point. If an inconsistency was detected in the per-engine hang recovery path we would back off and defer to the next hang check since per-engine hang recovery is not effective during inconsistent context submission states.

What we do in this new version is to move the consistency pre-check from the hang checker to the earliest point in the per-engine hang recovery path. If we detect an inconsistency at that point we fake a potentially lost context event interrupt by forcing a CSB check. If there are outstanding events in the CSB these will be acted upon and hopefully that will bring the driver up to speed with the hardware. If the CSB check did not amount to anything it is concluded that the inconsistency is unresolvable and the per-engine hang recovery fails and promotes to full GPU reset instead.

In the hang checker-based consistency checking we would check the inconsistency for a number of times to make sure the detected state was stable before attempting to rectify the situation. This is possible since hang checking is a recurring event. Having moved the consistency checking to the recovery path instead (i.e. a one-time, fire & forget-style event) it is assumed that the hang detection that brought on the hang recovery has detected a stable hang and therefore, if an inconsistency is detected at that point, the inconsistency must be stable and not the result of a momentary context state transition. Therefore, unlike in the hang checker case, at the very first indication of an inconsistent context submission status the interrupt is faked speculatively. If outstanding CSB events are found it is determined that the hang was in fact just a context submission status inconsistency and no hang recovery is done. If the inconsistency cannot be resolved the per-engine hang recovery is failed and the hang is promoted to full GPU reset instead.

* [8/12] drm/i915: Debugfs interface for per-engine hang recovery
1. After review comments by Chris Wilson we're dropping the dual-mode parameter value interpretation in i915_wedged_set(). In this version we only accept engine id flag masks that contain the engine id flags of all currently hung engines. Full GPU reset is most easily requested by passing an all zero engine id flag mask.

2. Moved TDR-specific engine metrics like number of detected engine hangs and number of per-engine resets into i915_hangcheck_info() from i915_hangcheck_read().

* [9/12] drm/i915: TDR/watchdog trace points
As a consequence of the faking context event interrupt commit being moved from the hang checker to the per-engine recovery path we no longer check context submission status from the hang checker. Therefore there is no need to provide submission status of the currently running context to the trace_i915_tdr_hang_check() event.

* [10/12] drm/i915: Fix __i915_wait_request() behaviour during hang detection
* [11/12] drm/i915: Port of Added scheduler support to __wait_request() calls
NEW: Added to address the way that __i915_wait_request() behaves in the face of hang detections and hang recovery.

* [12/12] drm/i915: Extended error state with TDR count, watchdog count and engine reset count
NEW: Adds per-engine TDR statistics to captured error state.

Tomas Elf (12):
drm/i915: Early exit from semaphore_waits_for for execlist mode. drm/i915: Make i915_gem_reset_ring_status() public drm/i915: Adding TDR / per-engine reset support for gen8. drm/i915: Extending i915_gem_check_wedge to check engine reset in
progress
drm/i915: Reinstate hang recovery work queue.
drm/i915: Watchdog timeout support for gen8.
drm/i915: Fake lost context interrupts through forced CSB check. drm/i915: Debugfs interface for per-engine hang recovery. drm/i915: TDR/watchdog trace points.
drm/i915: Port of Added scheduler support to __wait_request() calls drm/i915: Fix __i915_wait_request() behaviour during hang detection. drm/i915: Extended error state with TDR count, watchdog count and
engine reset count

 drivers/gpu/drm/i915/i915_debugfs.c     |  76 +++-
 drivers/gpu/drm/i915/i915_dma.c         |  78 ++++
 drivers/gpu/drm/i915/i915_drv.c         | 257 +++++++++++
 drivers/gpu/drm/i915/i915_drv.h         |  79 +++-
 drivers/gpu/drm/i915/i915_gem.c         | 128 ++++--
 drivers/gpu/drm/i915/i915_gpu_error.c   |   8 +-
 drivers/gpu/drm/i915/i915_irq.c         | 292 +++++++++++--
 drivers/gpu/drm/i915/i915_params.c      |  10 +
 drivers/gpu/drm/i915/i915_reg.h         |  13 +
 drivers/gpu/drm/i915/i915_trace.h       | 308 +++++++++++++-
 drivers/gpu/drm/i915/intel_display.c    |   2 +-
 drivers/gpu/drm/i915/intel_lrc.c        | 729 ++++++++++++++++++++++++++++++--
 drivers/gpu/drm/i915/intel_lrc.h        |  16 +-
 drivers/gpu/drm/i915/intel_lrc_tdr.h    |  39 ++
 drivers/gpu/drm/i915/intel_ringbuffer.c |  87 +++-
 drivers/gpu/drm/i915/intel_ringbuffer.h |  95 +++++
 drivers/gpu/drm/i915/intel_uncore.c     | 203 +++++++++
 include/uapi/drm/i915_drm.h             |   5 +-
 18 files changed, 2313 insertions(+), 112 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/intel_lrc_tdr.h
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#14 lore raw

Re: [RFCv2 00/12] TDR/watchdog timeout support for gen8 (edit: fixed coverletter)

Quoted 245 lines · Tomas Elf

This patch series introduces the following features:

* Feature 1: TDR (Timeout Detection and Recovery) for gen8 execlist mode.

TDR is an umbrella term for anything that goes into detecting and recovering from GPU hangs and is a term more widely used outside of the upstream driver.
This feature introduces an extensible framework that currently supports gen8 but that can be easily extended to support gen7 as well (which is already the case in GMIN but unfortunately in a not quite upstreamable form). The code contained in this submission represents the essentials of what is currently in GMIN merged with what is currently in upstream (as of the time when this work commenced a few months back).

This feature adds a new hang recovery path alongside the legacy GPU reset path, which takes care of engine recovery only. Aside from adding support for per-engine recovery this feature also introduces rules for how to promote a potential per-engine reset to a legacy, full GPU reset.

The hang checker now integrates with the error handler in a slightly different way in that it allows hang recovery on multiple engines at the same time by passing an engine flag mask to the error handler where flags representing all of the hung engines are set. This allows us to schedule hang recovery once for all currently hung engines instead of one hang recovery per detected engine hang. Previously, when only full GPU reset was supported this was all the same since it wouldn't matter if one or four engines were hung at any given point since it would all amount to the same thing - the GPU getting reset. As it stands now the behaviour is different depending on which engine is hung since each engine is reset separately from all the other engines, therefore we have to think about this in terms of scheduling cost and recovery latency. (see open question below)

OPEN QUESTIONS:

1. Do we want to investigate the possibility of per-engine hang detection? In the current upstream driver there is only one work queue that handles the hang checker and everything from initial hang detection to final hang recovery runs in this thread. This makes sense if you're only supporting one form of hang recovery - using full GPU reset and nothing tied to any particular engine. However, as part of this patch series we're changing that by introducing per-engine hang recovery. It could make sense to introduce multiple work queues - one per engine - to run multiple hang checking threads in parallel.

This would potentially allow savings in terms of recovery latency since we don't have to scan all engines every time the hang checker is scheduled and the error handler does not have to scan all engines every time it is scheduled. Instead, we could implement one work queue per engine that would invoke the hang checker that only checks _that_ particular engine and then the error handler is invoked for _that_ particular engine. If one engine has hung the latency for getting to the hang recovery path for that particular engine would be (Time For Hang Checking One Engine) + (Time For Error Handling One Engine) rather than the time it takes to do hang checking for all engines + the time it takes to do error handling for all engines that have been detected as hung (which in the worst case would be all engines). There would potentially be as many hang checker and error handling threads going on concurrently as there are engines in the hardware but they would all be running in parallel without any significant locking. The first time where any thread needs exclusive access to the driver is at the point of the actual hang recovery but the time it takes to get there would theoretically be lower and the time it actually takes to do per-engine hang recovery is quite a lot lower than the time it takes to actually detect a hang reliably.

How much we would save by such a change still needs to be analysed and compared against the current single-thread model but it makes sense from a theoretical design point of view.

* Feature 2: Watchdog Timeout (a.k.a "media engine reset") for gen8.

This feature allows userland applications to control whether or not individual batch buffers should have a first-level, fine-grained, hardware-based hang detection mechanism on top of the ordinary, software-based periodic hang checker that is already in the driver. The advantage over relying solely on the current software-based hang checker is that the watchdog timeout mechanism is about 1000x quicker and more precise. Since it's not a full driver-level hang detection mechanism but only targetting one individual batch buffer at a time it can afford to be that quick without risking an increase in false positive hang detection.

This feature includes the following changes:

a) Watchdog timeout interrupt service routine for handling watchdog interrupts and connecting these to per-engine hang recovery.

b) Injection of watchdog timer enablement/cancellation instructions before/after the batch buffer start instruction in the ring buffer so that watchdog timeout is connected to the submission of an individual batch buffer.

c) Extension of the DRM batch buffer interface, exposing the watchdog timeout feature to userland. We've got two open source groups in VPG currently in the process of integrating support for this feature, which should make it principally possible to upstream this extension.

There is currently full watchdog timeout support for gen7 in GMIN and it is quite similar to the gen8 implementation so there is nothing obvious that prevents us from upstreaming that code along with the gen8 code. However, watchdog timeout is fully dependent on the per-engine hang recovery path and that is not part of this code submission for gen7. Therefore watchdog timeout support for gen7 has been excluded until per-engine hang recovery support for gen7 has landed upstream.

As part of this submission we've had to reinstate the work queue that was previously in place between the error handler and the hang recovery path. The reason for this is that the per-engine recovery path is called directly from the interrupt handler in the case of watchdog timeout. In that situation there's no way of grabbing the struct_mutex, which is a requirement for the hang recovery path. Therefore, by reinstating the work queue we provide a unified execution context for the hang recovery code that allows the hang recovery code to grab whatever locks it needs without sacrificing interrupt latency too much or sleeping indefinitely in hard interrupt context.

* Feature 3. Context Submission Status Consistency checking

Something that becomes apparent when you run long-duration operations tests with concurrent rendering processes with intermittently injected hangs is that it seems like the GPU forgets to send context completion interrupts to the driver under some circumstances. What this means is that the driver sometimes gets stuck on a context that never seems to finish, all the while the hardware has completed and is waiting for more work.

The problem with this is that the per-engine hang recovery path relies on context resubmission to kick off the hardware again following an engine reset.
This can only be done safely if the hardware and driver share the same opinion about the current state. Therefore we've extended the periodic hang checker to check for context submission state inconsistencies aside from the hang checking it already does.

If such a state is detected it is assumed (based on experience) that a context completion interrupt has been lost somehow. If this state persists for some time an attempt to correct it is made by faking the presumably lost context completion interrupt by manually calling the execlist interrupt handler, which is normally called from the main interrupt handler cued by a received context event interrupt. Just because an interrupt goes missing does not mean that the context status buffer (CSB) does not get appropriately updated by the hardware, which means that we can expect to find all the recent changes to the context states for each engine captured there.

If there are outstanding context status changes in store there then the faked context event interrupt will allow the interrupt handler to act on them. In the case of lost context completion interrupts this will prompt the driver to remove the already completed context from the execlist queue and move on to the next pending piece of work and thereby eliminating the inconsistency.

* Feature 4. Debugfs extensions for per-engine hang recovery and TDR/watchdog trace points.

GITHUB REPOSITORY:
https://github.com/telf/TDR_watchdog_RFC_1.git

RFC VERSION 1 BRANCH:
20150608_TDR_upstream_adaptation_single-thread_hangchecking_RFC_delivery_sendmail_1

RFC VERSION 2 BRANCH:
20150604_TDR_upstream_adaptation_single-thread_hangchecking_RFCv2_delivery_sendmail_1

CHANGES IN VERSION 2
--------------------
Version 2 of this RFC series addresses design concerns that Chris Wilson and Daniel Vetter et. al. had with the first version of this RFC series. Below is a summary of all the changes made between versions:

* [1/12] drm/i915: Early exit from semaphore_waits_for for execlist mode:
Turned the execlist mode check into a ringbuffer NULL check to make it more submission mode agnostic and less of a layering violation.

* [2/12] drm/i915: Make i915_gem_reset_ring_status() public
Replaces the old patch in RFCv1: "drm/i915: Add reset stats entry point for per-engine reset"

* [3/12] drm/i915: Adding TDR / per-engine reset support for gen8:

1. Simply use the previously private function i915_gem_reset_ring_status() from the engine hang recovery path to set active/pending context status. This replicates the same behaviour as in full GPU reset but for a single, targetted engine.

2. Remove all additional uevents for both full GPU reset and per-engine reset. Adapted uevent behaviour to the new per-engine hang recovery mode in that it will only send one uevent regardless of which form of recovery is employed. If a per-engine reset is attempted first then one uevent will be dispatched. If that recovery mode fails and the hang is promoted to a full GPU reset no further uevents will be dispatched at that point.

3. Removed the 2*HUNG hang threshold from i915_hangcheck_elapsed in order to not make the hang detection algorithm too complicated. This threshold was introduced to compensate for the possibility that hang recovery might be delayed due to inconsistent context submission status that would prevent per-engine hang recovery from happening. In a later patch we introduce faked context event interrupts and inconsistency rectification at the onset of per-engine hang recovery instead of relying on the hang checker to do this for us. Therefore, since we do not delay and defer to future hang detections, we never allow hangs to go addressed beyond the HUNG threshold and therefore there is no need for any further thresholds.

4. Tidied up the TDR context resubmission path in intel_lrc.c . Reduced the amount of duplication by relying entirely on the normal unqueue function. Added a new parameter to the unqueue function that takes into consideration if the unqueue call is for a first-time context submission or a resubmission and adapts the handling of elsp_submitted accordingly. The reason for this is that for context resubmission we don't expect any further interrupts for the submission or the following context completion. A more elegant way of handling this would be to phase out elsp_submitted altogether, however that's part of a LRC/execlist cleanup effort that is happening independently of this RFC. For now we make this change as simple as possible with as few non-TDR-related side-effects as possible.

* [4/12] drm/i915: Extending i915_gem_check_wedge to check engine reset in progress:
Removed unwarranted changes made to i915_gem_ring_throttle()

* [7/12] drm/i915: Fake lost context interrupts through forced CSB check Remove context submission status consistency pre-check from i915_hangcheck_elapsed() and turn it into a pre-check to per-engine reset.

The following describes the change in philosphy in how context submission state inconsistencies are detected:

Previously we would let the periodic hang checker ensure that there were no context submission status inconsistencies on any engine, at any point. If an inconsistency was detected in the per-engine hang recovery path we would back off and defer to the next hang check since per-engine hang recovery is not effective during inconsistent context submission states.

What we do in this new version is to move the consistency pre-check from the hang checker to the earliest point in the per-engine hang recovery path. If we detect an inconsistency at that point we fake a potentially lost context event interrupt by forcing a CSB check. If there are outstanding events in the CSB these will be acted upon and hopefully that will bring the driver up to speed with the hardware. If the CSB check did not amount to anything it is concluded that the inconsistency is unresolvable and the per-engine hang recovery fails and promotes to full GPU reset instead.

In the hang checker-based consistency checking we would check the inconsistency for a number of times to make sure the detected state was stable before attempting to rectify the situation. This is possible since hang checking is a recurring event. Having moved the consistency checking to the recovery path instead (i.e. a one-time, fire & forget-style event) it is assumed that the hang detection that brought on the hang recovery has detected a stable hang and therefore, if an inconsistency is detected at that point, the inconsistency must be stable and not the result of a momentary context state transition. Therefore, unlike in the hang checker case, at the very first indication of an inconsistent context submission status the interrupt is faked speculatively. If outstanding CSB events are found it is determined that the hang was in fact just a context submission status inconsistency and no hang recovery is done. If the inconsistency cannot be resolved the per-engine hang recovery is failed and the hang is promoted to full GPU reset instead.

* [8/12] drm/i915: Debugfs interface for per-engine hang recovery
1. After review comments by Chris Wilson we're dropping the dual-mode parameter value interpretation in i915_wedged_set(). In this version we only accept engine id flag masks that contain the engine id flags of all currently hung engines. Full GPU reset is most easily requested by passing an all zero engine id flag mask.

2. Moved TDR-specific engine metrics like number of detected engine hangs and number of per-engine resets into i915_hangcheck_info() from i915_hangcheck_read().

* [9/12] drm/i915: TDR/watchdog trace points
As a consequence of the faking context event interrupt commit being moved from the hang checker to the per-engine recovery path we no longer check context submission status from the hang checker. Therefore there is no need to provide submission status of the currently running context to the trace_i915_tdr_hang_check() event.

* [10/12] drm/i915: Fix __i915_wait_request() behaviour during hang detection
* [11/12] drm/i915: Port of Added scheduler support to __wait_request() calls
NEW: Added to address the way that __i915_wait_request() behaves in the face of hang detections and hang recovery.

* [12/12] drm/i915: Extended error state with TDR count, watchdog count and engine reset count
NEW: Adds per-engine TDR statistics to captured error state.

Tomas Elf (12):
drm/i915: Early exit from semaphore_waits_for for execlist mode. drm/i915: Make i915_gem_reset_ring_status() public drm/i915: Adding TDR / per-engine reset support for gen8. drm/i915: Extending i915_gem_check_wedge to check engine reset in
progress
drm/i915: Reinstate hang recovery work queue.
drm/i915: Watchdog timeout support for gen8.
drm/i915: Fake lost context interrupts through forced CSB check. drm/i915: Debugfs interface for per-engine hang recovery. drm/i915: TDR/watchdog trace points.
drm/i915: Port of Added scheduler support to __wait_request() calls drm/i915: Fix __i915_wait_request() behaviour during hang detection. drm/i915: Extended error state with TDR count, watchdog count and
engine reset count

  drivers/gpu/drm/i915/i915_debugfs.c     |  76 +++-
  drivers/gpu/drm/i915/i915_dma.c         |  78 ++++
  drivers/gpu/drm/i915/i915_drv.c         | 257 +++++++++++
  drivers/gpu/drm/i915/i915_drv.h         |  79 +++-
  drivers/gpu/drm/i915/i915_gem.c         | 128 ++++--
  drivers/gpu/drm/i915/i915_gpu_error.c   |   8 +-
  drivers/gpu/drm/i915/i915_irq.c         | 292 +++++++++++--
  drivers/gpu/drm/i915/i915_params.c      |  10 +
  drivers/gpu/drm/i915/i915_reg.h         |  13 +
  drivers/gpu/drm/i915/i915_trace.h       | 308 +++++++++++++-
  drivers/gpu/drm/i915/intel_display.c    |   2 +-
  drivers/gpu/drm/i915/intel_lrc.c        | 729 ++++++++++++++++++++++++++++++--
  drivers/gpu/drm/i915/intel_lrc.h        |  16 +-
  drivers/gpu/drm/i915/intel_lrc_tdr.h    |  39 ++
  drivers/gpu/drm/i915/intel_ringbuffer.c |  87 +++-
  drivers/gpu/drm/i915/intel_ringbuffer.h |  95 +++++
  drivers/gpu/drm/i915/intel_uncore.c     | 203 +++++++++
  include/uapi/drm/i915_drm.h             |   5 +-
  18 files changed, 2313 insertions(+), 112 deletions(-)
Quoted 2 lines

create mode 100644 drivers/gpu/drm/i915/intel_lrc_tdr.h

Summarising follow-up on IRC:

Chris Wilson is ok with RFCv2 from a design point-of-view. We're moving on to the detailed code review which will commence once I get back from my holiday in three weeks and once I've prepared a properly split up patch series that is suitable for code reviewing.

Thanks,
Tomas

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx