Skip to content

Commit

Permalink
drm/i915/guc: Implement banned contexts for GuC submission
Browse files Browse the repository at this point in the history
When using GuC submission, if a context gets banned disable scheduling
and mark all inflight requests as complete.

Cc: John Harrison <John.C.Harrison@Intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: John Harrison <John.C.Harrison@Intel.com>
Signed-off-by: John Harrison <John.C.Harrison@Intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210727002348.97202-25-matthew.brost@intel.com
  • Loading branch information
Matthew Brost authored and John Harrison committed Jul 28, 2021
1 parent 481d458 commit ae8ac10
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 37 deletions.
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/gem/i915_gem_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ static void kill_engines(struct i915_gem_engines *engines, bool ban)
for_each_gem_engine(ce, engines, it) {
struct intel_engine_cs *engine;

if (ban && intel_context_set_banned(ce))
if (ban && intel_context_ban(ce, NULL))
continue;

/*
Expand Down
13 changes: 13 additions & 0 deletions drivers/gpu/drm/i915/gt/intel_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "intel_engine_types.h"
#include "intel_ring_types.h"
#include "intel_timeline_types.h"
#include "i915_trace.h"

#define CE_TRACE(ce, fmt, ...) do { \
const struct intel_context *ce__ = (ce); \
Expand Down Expand Up @@ -243,6 +244,18 @@ static inline bool intel_context_set_banned(struct intel_context *ce)
return test_and_set_bit(CONTEXT_BANNED, &ce->flags);
}

static inline bool intel_context_ban(struct intel_context *ce,
struct i915_request *rq)
{
bool ret = intel_context_set_banned(ce);

trace_intel_context_ban(ce);
if (ce->ops->ban)
ce->ops->ban(ce, rq);

return ret;
}

static inline bool
intel_context_force_single_submission(const struct intel_context *ce)
{
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/i915/gt/intel_context_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct intel_context_ops {

int (*alloc)(struct intel_context *ce);

void (*ban)(struct intel_context *ce, struct i915_request *rq);

int (*pre_pin)(struct intel_context *ce, struct i915_gem_ww_ctx *ww, void **vaddr);
int (*pin)(struct intel_context *ce, void *vaddr);
void (*unpin)(struct intel_context *ce);
Expand Down
32 changes: 8 additions & 24 deletions drivers/gpu/drm/i915/gt/intel_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "intel_reset.h"

#include "uc/intel_guc.h"
#include "uc/intel_guc_submission.h"

#define RESET_MAX_RETRIES 3

Expand All @@ -39,21 +38,6 @@ static void rmw_clear_fw(struct intel_uncore *uncore, i915_reg_t reg, u32 clr)
intel_uncore_rmw_fw(uncore, reg, clr, 0);
}

static void skip_context(struct i915_request *rq)
{
struct intel_context *hung_ctx = rq->context;

list_for_each_entry_from_rcu(rq, &hung_ctx->timeline->requests, link) {
if (!i915_request_is_active(rq))
return;

if (rq->context == hung_ctx) {
i915_request_set_error_once(rq, -EIO);
__i915_request_skip(rq);
}
}
}

static void client_mark_guilty(struct i915_gem_context *ctx, bool banned)
{
struct drm_i915_file_private *file_priv = ctx->file_priv;
Expand Down Expand Up @@ -88,10 +72,8 @@ static bool mark_guilty(struct i915_request *rq)
bool banned;
int i;

if (intel_context_is_closed(rq->context)) {
intel_context_set_banned(rq->context);
if (intel_context_is_closed(rq->context))
return true;
}

rcu_read_lock();
ctx = rcu_dereference(rq->context->gem_context);
Expand Down Expand Up @@ -123,11 +105,9 @@ static bool mark_guilty(struct i915_request *rq)
banned = !i915_gem_context_is_recoverable(ctx);
if (time_before(jiffies, prev_hang + CONTEXT_FAST_HANG_JIFFIES))
banned = true;
if (banned) {
if (banned)
drm_dbg(&ctx->i915->drm, "context %s: guilty %d, banned\n",
ctx->name, atomic_read(&ctx->guilty_count));
intel_context_set_banned(rq->context);
}

client_mark_guilty(ctx, banned);

Expand All @@ -149,20 +129,24 @@ static void mark_innocent(struct i915_request *rq)

void __i915_request_reset(struct i915_request *rq, bool guilty)
{
bool banned = false;

RQ_TRACE(rq, "guilty? %s\n", yesno(guilty));
GEM_BUG_ON(__i915_request_is_complete(rq));

rcu_read_lock(); /* protect the GEM context */
if (guilty) {
i915_request_set_error_once(rq, -EIO);
__i915_request_skip(rq);
if (mark_guilty(rq) && !intel_engine_uses_guc(rq->engine))
skip_context(rq);
banned = mark_guilty(rq);
} else {
i915_request_set_error_once(rq, -EAGAIN);
mark_innocent(rq);
}
rcu_read_unlock();

if (banned)
intel_context_ban(rq->context, rq);
}

static bool i915_in_reset(struct pci_dev *pdev)
Expand Down
20 changes: 20 additions & 0 deletions drivers/gpu/drm/i915/gt/intel_ring_submission.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,29 @@ static void ring_context_reset(struct intel_context *ce)
clear_bit(CONTEXT_VALID_BIT, &ce->flags);
}

static void ring_context_ban(struct intel_context *ce,
struct i915_request *rq)
{
struct intel_engine_cs *engine;

if (!rq || !i915_request_is_active(rq))
return;

engine = rq->engine;
lockdep_assert_held(&engine->sched_engine->lock);
list_for_each_entry_continue(rq, &engine->sched_engine->requests,
sched.link)
if (rq->context == ce) {
i915_request_set_error_once(rq, -EIO);
__i915_request_skip(rq);
}
}

static const struct intel_context_ops ring_context_ops = {
.alloc = ring_context_alloc,

.ban = ring_context_ban,

.pre_pin = ring_context_pre_pin,
.pin = ring_context_pin,
.unpin = ring_context_unpin,
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/i915/gt/uc/intel_guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ void intel_guc_find_hung_context(struct intel_engine_cs *engine);

int intel_guc_global_policies_update(struct intel_guc *guc);

void intel_guc_context_ban(struct intel_context *ce, struct i915_request *rq);

void intel_guc_submission_reset_prepare(struct intel_guc *guc);
void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
void intel_guc_submission_reset_finish(struct intel_guc *guc);
Expand Down
Loading

0 comments on commit ae8ac10

Please sign in to comment.