Commit bc1d53c6 authored by Mika Kuoppala's avatar Mika Kuoppala Committed by Mika Kuoppala

drm/i915: Wipe hang stats as an embedded struct

Bannable property, banned status, guilty and active counts are
properties of i915_gem_context. Make them so.

v2: rebase

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarMika Kuoppala <mika.kuoppala@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1479309634-28574-1-git-send-email-mika.kuoppala@intel.com
parent b083a087
...@@ -913,25 +913,6 @@ enum i915_cache_level { ...@@ -913,25 +913,6 @@ enum i915_cache_level {
I915_CACHE_WT, /* hsw:gt3e WriteThrough for scanouts */ I915_CACHE_WT, /* hsw:gt3e WriteThrough for scanouts */
}; };
struct i915_ctx_hang_stats {
/* This context had batch pending when hang was declared */
unsigned batch_pending;
/* This context had batch active when hang was declared */
unsigned batch_active;
bool bannable:1;
/* This context is banned to submit more work */
bool banned:1;
#define CONTEXT_SCORE_GUILTY 10
#define CONTEXT_SCORE_BAN_THRESHOLD 40
/* Accumulated score of hangs caused by this context */
int ban_score;
};
/* This must match up with the value previously used for execbuf2.rsvd1. */
#define DEFAULT_CONTEXT_HANDLE 0 #define DEFAULT_CONTEXT_HANDLE 0
/** /**
...@@ -961,8 +942,6 @@ struct i915_gem_context { ...@@ -961,8 +942,6 @@ struct i915_gem_context {
struct pid *pid; struct pid *pid;
const char *name; const char *name;
struct i915_ctx_hang_stats hang_stats;
unsigned long flags; unsigned long flags;
#define CONTEXT_NO_ZEROMAP BIT(0) #define CONTEXT_NO_ZEROMAP BIT(0)
#define CONTEXT_NO_ERROR_CAPTURE BIT(1) #define CONTEXT_NO_ERROR_CAPTURE BIT(1)
...@@ -991,6 +970,16 @@ struct i915_gem_context { ...@@ -991,6 +970,16 @@ struct i915_gem_context {
u8 remap_slice; u8 remap_slice;
bool closed:1; bool closed:1;
bool bannable:1;
bool banned:1;
unsigned int guilty_count; /* guilty of a hang */
unsigned int active_count; /* active during hang */
#define CONTEXT_SCORE_GUILTY 10
#define CONTEXT_SCORE_BAN_THRESHOLD 40
/* Accumulated score of hangs caused by this context */
int ban_score;
}; };
enum fb_op_origin { enum fb_op_origin {
......
...@@ -2622,15 +2622,13 @@ void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj, ...@@ -2622,15 +2622,13 @@ void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj,
static bool i915_context_is_banned(const struct i915_gem_context *ctx) static bool i915_context_is_banned(const struct i915_gem_context *ctx)
{ {
const struct i915_ctx_hang_stats *hs = &ctx->hang_stats; if (ctx->banned)
if (hs->banned)
return true; return true;
if (!hs->bannable) if (!ctx->bannable)
return false; return false;
if (hs->ban_score >= CONTEXT_SCORE_BAN_THRESHOLD) { if (ctx->ban_score >= CONTEXT_SCORE_BAN_THRESHOLD) {
DRM_DEBUG("context hanging too often, banning!\n"); DRM_DEBUG("context hanging too often, banning!\n");
return true; return true;
} }
...@@ -2640,20 +2638,19 @@ static bool i915_context_is_banned(const struct i915_gem_context *ctx) ...@@ -2640,20 +2638,19 @@ static bool i915_context_is_banned(const struct i915_gem_context *ctx)
static void i915_gem_context_mark_guilty(struct i915_gem_context *ctx) static void i915_gem_context_mark_guilty(struct i915_gem_context *ctx)
{ {
struct i915_ctx_hang_stats *hs = &ctx->hang_stats; ctx->ban_score += CONTEXT_SCORE_GUILTY;
hs->ban_score += CONTEXT_SCORE_GUILTY;
hs->banned = i915_context_is_banned(ctx); ctx->banned = i915_context_is_banned(ctx);
hs->batch_active++; ctx->guilty_count++;
DRM_DEBUG_DRIVER("context %s marked guilty (score %d) banned? %s\n", DRM_DEBUG_DRIVER("context %s marked guilty (score %d) banned? %s\n",
ctx->name, hs->ban_score, yesno(hs->banned)); ctx->name, ctx->ban_score,
yesno(ctx->banned));
if (!ctx->file_priv) if (!ctx->file_priv)
return; return;
if (hs->banned) { if (ctx->banned) {
ctx->file_priv->context_bans++; ctx->file_priv->context_bans++;
DRM_DEBUG_DRIVER("client %s has has %d context banned\n", DRM_DEBUG_DRIVER("client %s has has %d context banned\n",
...@@ -2664,9 +2661,7 @@ static void i915_gem_context_mark_guilty(struct i915_gem_context *ctx) ...@@ -2664,9 +2661,7 @@ static void i915_gem_context_mark_guilty(struct i915_gem_context *ctx)
static void i915_gem_context_mark_innocent(struct i915_gem_context *ctx) static void i915_gem_context_mark_innocent(struct i915_gem_context *ctx)
{ {
struct i915_ctx_hang_stats *hs = &ctx->hang_stats; ctx->active_count++;
hs->batch_pending++;
} }
struct drm_i915_gem_request * struct drm_i915_gem_request *
......
...@@ -331,7 +331,7 @@ __create_hw_context(struct drm_device *dev, ...@@ -331,7 +331,7 @@ __create_hw_context(struct drm_device *dev,
* is no remap info, it will be a NOP. */ * is no remap info, it will be a NOP. */
ctx->remap_slice = ALL_L3_SLICES(dev_priv); ctx->remap_slice = ALL_L3_SLICES(dev_priv);
ctx->hang_stats.bannable = true; ctx->bannable = true;
ctx->ring_size = 4 * PAGE_SIZE; ctx->ring_size = 4 * PAGE_SIZE;
ctx->desc_template = GEN8_CTX_ADDRESSING_MODE(dev_priv) << ctx->desc_template = GEN8_CTX_ADDRESSING_MODE(dev_priv) <<
GEN8_CTX_ADDRESSING_MODE_SHIFT; GEN8_CTX_ADDRESSING_MODE_SHIFT;
...@@ -1115,7 +1115,7 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data, ...@@ -1115,7 +1115,7 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
args->value = !!(ctx->flags & CONTEXT_NO_ERROR_CAPTURE); args->value = !!(ctx->flags & CONTEXT_NO_ERROR_CAPTURE);
break; break;
case I915_CONTEXT_PARAM_BANNABLE: case I915_CONTEXT_PARAM_BANNABLE:
args->value = ctx->hang_stats.bannable; args->value = ctx->bannable;
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
...@@ -1172,7 +1172,7 @@ int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data, ...@@ -1172,7 +1172,7 @@ int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
else if (!capable(CAP_SYS_ADMIN) && !args->value) else if (!capable(CAP_SYS_ADMIN) && !args->value)
ret = -EPERM; ret = -EPERM;
else else
ctx->hang_stats.bannable = args->value; ctx->bannable = args->value;
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
...@@ -1188,7 +1188,6 @@ int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, ...@@ -1188,7 +1188,6 @@ int i915_gem_context_reset_stats_ioctl(struct drm_device *dev,
{ {
struct drm_i915_private *dev_priv = to_i915(dev); struct drm_i915_private *dev_priv = to_i915(dev);
struct drm_i915_reset_stats *args = data; struct drm_i915_reset_stats *args = data;
struct i915_ctx_hang_stats *hs;
struct i915_gem_context *ctx; struct i915_gem_context *ctx;
int ret; int ret;
...@@ -1207,15 +1206,14 @@ int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, ...@@ -1207,15 +1206,14 @@ int i915_gem_context_reset_stats_ioctl(struct drm_device *dev,
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
return PTR_ERR(ctx); return PTR_ERR(ctx);
} }
hs = &ctx->hang_stats;
if (capable(CAP_SYS_ADMIN)) if (capable(CAP_SYS_ADMIN))
args->reset_count = i915_reset_count(&dev_priv->gpu_error); args->reset_count = i915_reset_count(&dev_priv->gpu_error);
else else
args->reset_count = 0; args->reset_count = 0;
args->batch_active = hs->batch_active; args->batch_active = ctx->guilty_count;
args->batch_pending = hs->batch_pending; args->batch_pending = ctx->active_count;
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
......
...@@ -1232,14 +1232,12 @@ i915_gem_validate_context(struct drm_device *dev, struct drm_file *file, ...@@ -1232,14 +1232,12 @@ i915_gem_validate_context(struct drm_device *dev, struct drm_file *file,
struct intel_engine_cs *engine, const u32 ctx_id) struct intel_engine_cs *engine, const u32 ctx_id)
{ {
struct i915_gem_context *ctx; struct i915_gem_context *ctx;
struct i915_ctx_hang_stats *hs;
ctx = i915_gem_context_lookup(file->driver_priv, ctx_id); ctx = i915_gem_context_lookup(file->driver_priv, ctx_id);
if (IS_ERR(ctx)) if (IS_ERR(ctx))
return ctx; return ctx;
hs = &ctx->hang_stats; if (ctx->banned) {
if (hs->banned) {
DRM_DEBUG("Context %u tried to submit while banned\n", ctx_id); DRM_DEBUG("Context %u tried to submit while banned\n", ctx_id);
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
} }
......
...@@ -264,8 +264,8 @@ static void i915_gem_request_retire(struct drm_i915_gem_request *request) ...@@ -264,8 +264,8 @@ static void i915_gem_request_retire(struct drm_i915_gem_request *request)
} }
/* Retirement decays the ban score as it is a sign of ctx progress */ /* Retirement decays the ban score as it is a sign of ctx progress */
if (request->ctx->hang_stats.ban_score > 0) if (request->ctx->ban_score > 0)
request->ctx->hang_stats.ban_score--; request->ctx->ban_score--;
i915_gem_context_put(request->ctx); i915_gem_context_put(request->ctx);
......
...@@ -1172,7 +1172,7 @@ static void record_request(struct drm_i915_gem_request *request, ...@@ -1172,7 +1172,7 @@ static void record_request(struct drm_i915_gem_request *request,
struct drm_i915_error_request *erq) struct drm_i915_error_request *erq)
{ {
erq->context = request->ctx->hw_id; erq->context = request->ctx->hw_id;
erq->ban_score = request->ctx->hang_stats.ban_score; erq->ban_score = request->ctx->ban_score;
erq->seqno = request->global_seqno; erq->seqno = request->global_seqno;
erq->jiffies = request->emitted_jiffies; erq->jiffies = request->emitted_jiffies;
erq->head = request->head; erq->head = request->head;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment