]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/amdgpu: restore original stable pstate on ctx fini
authorAlex Deucher <alexander.deucher@amd.com>
Wed, 6 Jul 2022 15:10:15 +0000 (11:10 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:41:07 +0000 (14:41 +0200)
[ Upstream commit 958afce98c2c86732483458c03540d3c6ef45254 ]

Save the original stable pstate on ctx init and restore
it on ctx fini so that we restore a manually selected
stable pstate on ctx exit.

v2: fix init order (Alex)
v3: don't add new variable to ctx struct (Evan)

Fixes: c65b364c52ba ("drm/amdgpu/ctx: only reset stable pstate if the user changed it (v2)")
Reviewed-by: Evan Quan <evan.quan@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c

index a61e4c83a545a141fa87c3e021b1e97e65e6fb2d..95ed528e6ec5cb8fdea258348a2622ae327d6f47 100644 (file)
@@ -220,32 +220,6 @@ error_free_entity:
        return r;
 }
 
-static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, int32_t priority,
-                          struct drm_file *filp, struct amdgpu_ctx *ctx)
-{
-       int r;
-
-       r = amdgpu_ctx_priority_permit(filp, priority);
-       if (r)
-               return r;
-
-       memset(ctx, 0, sizeof(*ctx));
-
-       kref_init(&ctx->refcount);
-       ctx->mgr = mgr;
-       spin_lock_init(&ctx->ring_lock);
-       mutex_init(&ctx->lock);
-
-       ctx->reset_counter = atomic_read(&mgr->adev->gpu_reset_counter);
-       ctx->reset_counter_query = ctx->reset_counter;
-       ctx->vram_lost_counter = atomic_read(&mgr->adev->vram_lost_counter);
-       ctx->init_priority = priority;
-       ctx->override_priority = AMDGPU_CTX_PRIORITY_UNSET;
-       ctx->stable_pstate = AMDGPU_CTX_STABLE_PSTATE_NONE;
-
-       return 0;
-}
-
 static void amdgpu_ctx_fini_entity(struct amdgpu_ctx_entity *entity)
 {
 
@@ -288,6 +262,38 @@ static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
        return 0;
 }
 
+static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, int32_t priority,
+                          struct drm_file *filp, struct amdgpu_ctx *ctx)
+{
+       u32 current_stable_pstate;
+       int r;
+
+       r = amdgpu_ctx_priority_permit(filp, priority);
+       if (r)
+               return r;
+
+       memset(ctx, 0, sizeof(*ctx));
+
+       kref_init(&ctx->refcount);
+       ctx->mgr = mgr;
+       spin_lock_init(&ctx->ring_lock);
+       mutex_init(&ctx->lock);
+
+       ctx->reset_counter = atomic_read(&mgr->adev->gpu_reset_counter);
+       ctx->reset_counter_query = ctx->reset_counter;
+       ctx->vram_lost_counter = atomic_read(&mgr->adev->vram_lost_counter);
+       ctx->init_priority = priority;
+       ctx->override_priority = AMDGPU_CTX_PRIORITY_UNSET;
+
+       r = amdgpu_ctx_get_stable_pstate(ctx, &current_stable_pstate);
+       if (r)
+               return r;
+
+       ctx->stable_pstate = current_stable_pstate;
+
+       return 0;
+}
+
 static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
                                        u32 stable_pstate)
 {
@@ -357,7 +363,7 @@ static void amdgpu_ctx_fini(struct kref *ref)
        }
 
        if (drm_dev_enter(&adev->ddev, &idx)) {
-               amdgpu_ctx_set_stable_pstate(ctx, AMDGPU_CTX_STABLE_PSTATE_NONE);
+               amdgpu_ctx_set_stable_pstate(ctx, ctx->stable_pstate);
                drm_dev_exit(idx);
        }