Skip to contentSkip to conversation

drm/amdgpu/ctx: only reset stable pstate if the user changed it

PATCH In review Alex Deucher 4 participants 4 messages May 9, 2022 – May 11, 2022

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu/ctx: only reset stable pstate if the user changed it

Track whether the user requested a stable pstate via the ctx IOCTL and only reset the pstate on context destroy if the user actually changed it. This avoids changing the pstate on contex destroy if the user never changed it in the first place via the IOCTL.

Fixes 8cda7a4f96e435 ("drm/amdgpu/UAPI: add new CTX OP to get/set stable pstates")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 5 ++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +4 -1
index 5981c7d9bd48..e4b0c6ec227c 100644
@@ -330,6 +330,8 @@ static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
 		adev->pm.stable_pstate_ctx = NULL;
 	else
 		adev->pm.stable_pstate_ctx = ctx;
+
+	ctx->stable_pstate_requested = true;
 done:
 	mutex_unlock(&adev->pm.stable_pstate_ctx_lock);
 
@@ -353,7 +355,8 @@ 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);
+		if (ctx->stable_pstate_requested)
+			amdgpu_ctx_set_stable_pstate(ctx, AMDGPU_CTX_STABLE_PSTATE_NONE);
 		drm_dev_exit(idx);
 	}
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +1 -0
index d0cbfcea90f7..f03e842209b8 100644
@@ -53,6 +53,7 @@ struct amdgpu_ctx {
 	unsigned long			ras_counter_ce;
 	unsigned long			ras_counter_ue;
 	uint32_t			stable_pstate;
+	bool				stable_pstate_requested;
 };
 
 struct amdgpu_ctx_mgr {
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw

[AMD Official Use Only - General]

Quoted 65 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Tuesday, May 10, 2022 4:04 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH] drm/amdgpu/ctx: only reset stable pstate if the user changed it

Track whether the user requested a stable pstate via the ctx IOCTL and only reset the pstate on context destroy if the user actually changed it. This avoids changing the pstate on contex destroy if the user never changed it in the first place via the IOCTL.

Fixes 8cda7a4f96e435 ("drm/amdgpu/UAPI: add new CTX OP to get/set

stable pstates")

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 5 ++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +4 -1
index 5981c7d9bd48..e4b0c6ec227c 100644
@@ -330,6 +330,8 @@ static int amdgpu_ctx_set_stable_pstate(struct
 amdgpu_ctx *ctx,
 		adev->pm.stable_pstate_ctx = NULL;
 	else
 		adev->pm.stable_pstate_ctx = ctx;
+
+	ctx->stable_pstate_requested = true;
 done:
 	mutex_unlock(&adev->pm.stable_pstate_ctx_lock);
@@ -353,7 +355,8 @@ 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);
+		if (ctx->stable_pstate_requested)
+			amdgpu_ctx_set_stable_pstate(ctx,
 AMDGPU_CTX_STABLE_PSTATE_NONE);
 		drm_dev_exit(idx);
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +1 -1
index d0cbfcea90f7..f03e842209b8 100644
@@ -53,6 +53,7 @@ struct amdgpu_ctx {
 	unsigned long			ras_counter_ce;
 	unsigned long			ras_counter_ue;
 	uint32_t			stable_pstate;
+	bool				stable_pstate_requested;
 };
 
 struct amdgpu_ctx_mgr {
--

2.35.1

#2 lore raw
In reply to Alex Deucher
Quoted 27 lines · Alex Deucher

Track whether the user requested a stable pstate via the ctx IOCTL and only reset the pstate on context destroy if the user actually changed it. This avoids changing the pstate on contex destroy if the user never changed it in the first place via the IOCTL.

Fixes 8cda7a4f96e435 ("drm/amdgpu/UAPI: add new CTX OP to get/set stable pstates")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 5 ++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 1 +
  2 files changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -0
index 5981c7d9bd48..e4b0c6ec227c 100644
@@ -330,6 +330,8 @@ static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
  		adev->pm.stable_pstate_ctx = NULL;
  	else
  		adev->pm.stable_pstate_ctx = ctx;
+
+	ctx->stable_pstate_requested = true;
  done:
  	mutex_unlock(&adev->pm.stable_pstate_ctx_lock);
 

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static void amdgpu_ctx_fini(struct kref *ref) · line 359

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -1
@@ -353,7 +355,8 @@ 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);
+		if (ctx->stable_pstate_requested)
+			amdgpu_ctx_set_stable_pstate(ctx, AMDGPU_CTX_STABLE_PSTATE_NONE);

Why not have the check inside amdgpu_ctx_set_stable_pstate - if current stable pstate is not the same as the requested one, then only switch. If the user has not made a request, it will be NONE and the call doesn't have any effect.

Thanks,
Lijo

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
  		drm_dev_exit(idx);
  	}
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +1 -0
index d0cbfcea90f7..f03e842209b8 100644
@@ -53,6 +53,7 @@ struct amdgpu_ctx {
  	unsigned long			ras_counter_ce;
  	unsigned long			ras_counter_ue;
  	uint32_t			stable_pstate;
+	bool				stable_pstate_requested;
  };
 
  struct amdgpu_ctx_mgr {
#3 lore raw
Quoted 33 lines · Lijo
Quoted 29 lines · Alex Deucher

Track whether the user requested a stable pstate via the ctx IOCTL and only reset the pstate on context destroy if the user actually changed it. This avoids changing the pstate on contex destroy if the user never changed it in the first place via the IOCTL.

Fixes 8cda7a4f96e435 ("drm/amdgpu/UAPI: add new CTX OP to get/set stable pstates")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 5 ++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 1 +
  2 files changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -0
index 5981c7d9bd48..e4b0c6ec227c 100644
@@ -330,6 +330,8 @@ static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
              adev->pm.stable_pstate_ctx = NULL;
      else
              adev->pm.stable_pstate_ctx = ctx;
+
+     ctx->stable_pstate_requested = true;
  done:
      mutex_unlock(&adev->pm.stable_pstate_ctx_lock);
 
@@ -353,7 +355,8 @@ static void amdgpu_ctx_fini(struct kref *ref)
      }
 
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static void amdgpu_ctx_fini(struct kref *ref) · line 359

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -1
      if (drm_dev_enter(&adev->ddev, &idx)) {
-             amdgpu_ctx_set_stable_pstate(ctx, AMDGPU_CTX_STABLE_PSTATE_NONE);
+             if (ctx->stable_pstate_requested)
+                     amdgpu_ctx_set_stable_pstate(ctx, AMDGPU_CTX_STABLE_PSTATE_NONE);

Why not have the check inside amdgpu_ctx_set_stable_pstate - if current stable pstate is not the same as the requested one, then only switch. If the user has not made a request, it will be NONE and the call doesn't have any effect.

Good idea. New patch sent out earlier today.

Alex

Quoted 20 lines

Thanks,
Lijo

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
              drm_dev_exit(idx);
      }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +1 -0
index d0cbfcea90f7..f03e842209b8 100644
@@ -53,6 +53,7 @@ struct amdgpu_ctx {
      unsigned long                   ras_counter_ce;
      unsigned long                   ras_counter_ue;
      uint32_t                        stable_pstate;
+     bool                            stable_pstate_requested;
  };
 
  struct amdgpu_ctx_mgr {