drm/amdgpu:implement ctx query2
authorMonk Liu <Monk.Liu@amd.com>
Tue, 17 Oct 2017 06:58:01 +0000 (14:58 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 4 Dec 2017 21:33:12 +0000 (16:33 -0500)
this query will give flag bits to indicate what happend
on the given context

Signed-off-by: Monk Liu <Monk.Liu@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
include/uapi/drm/amdgpu_drm.h

index c539fb6a597e41969555b3c61c0d633ca193501f..d71dc164b4693b5b0e67405eaee5990a0e4af5e1 100644 (file)
@@ -227,6 +227,40 @@ static int amdgpu_ctx_query(struct amdgpu_device *adev,
        return 0;
 }
 
+static int amdgpu_ctx_query2(struct amdgpu_device *adev,
+       struct amdgpu_fpriv *fpriv, uint32_t id,
+       union drm_amdgpu_ctx_out *out)
+{
+       struct amdgpu_ctx *ctx;
+       struct amdgpu_ctx_mgr *mgr;
+
+       if (!fpriv)
+               return -EINVAL;
+
+       mgr = &fpriv->ctx_mgr;
+       mutex_lock(&mgr->lock);
+       ctx = idr_find(&mgr->ctx_handles, id);
+       if (!ctx) {
+               mutex_unlock(&mgr->lock);
+               return -EINVAL;
+       }
+
+       out->state.flags = 0x0;
+       out->state.hangs = 0x0;
+
+       if (ctx->reset_counter != atomic_read(&adev->gpu_reset_counter))
+               out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_RESET;
+
+       if (ctx->vram_lost_counter != atomic_read(&adev->vram_lost_counter))
+               out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_VRAMLOST;
+
+       if (atomic_read(&ctx->guilty))
+               out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_GUILTY;
+
+       mutex_unlock(&mgr->lock);
+       return 0;
+}
+
 int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
                     struct drm_file *filp)
 {
@@ -258,6 +292,9 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
        case AMDGPU_CTX_OP_QUERY_STATE:
                r = amdgpu_ctx_query(adev, fpriv, id, &args->out);
                break;
+       case AMDGPU_CTX_OP_QUERY_STATE2:
+               r = amdgpu_ctx_query2(adev, fpriv, id, &args->out);
+               break;
        default:
                return -EINVAL;
        }
index 919248fb4028bd084c0949dcea30f86796741367..0e23ce3f31137146217e79f89d25093716bd386d 100644 (file)
@@ -160,6 +160,7 @@ union drm_amdgpu_bo_list {
 #define AMDGPU_CTX_OP_ALLOC_CTX        1
 #define AMDGPU_CTX_OP_FREE_CTX 2
 #define AMDGPU_CTX_OP_QUERY_STATE      3
+#define AMDGPU_CTX_OP_QUERY_STATE2     4
 
 /* GPU reset status */
 #define AMDGPU_CTX_NO_RESET            0
@@ -170,6 +171,13 @@ union drm_amdgpu_bo_list {
 /* unknown cause */
 #define AMDGPU_CTX_UNKNOWN_RESET       3
 
+/* indicate gpu reset occured after ctx created */
+#define AMDGPU_CTX_QUERY2_FLAGS_RESET    (1<<0)
+/* indicate vram lost occured after ctx created */
+#define AMDGPU_CTX_QUERY2_FLAGS_VRAMLOST (1<<1)
+/* indicate some job from this context once cause gpu hang */
+#define AMDGPU_CTX_QUERY2_FLAGS_GUILTY   (1<<2)
+
 /* Context priority level */
 #define AMDGPU_CTX_PRIORITY_UNSET       -2048
 #define AMDGPU_CTX_PRIORITY_VERY_LOW    -1023