Skip to contentSkip to conversation

drm/amdgpu: restore perf state after runtime resume

PATCH In review Candice Li 4 participants 10 messages Jul 22 – Jul 24

Subsystems (3)
lore
Share & tools
lore

Candice Li

author
#0 lore raw

PATCH 1/1 drm/amdgpu: restore perf state after runtime resume

Runtime suspend runs GFX hw_fini and clears perfmon clock gating while KFD keeps running, so block perf counters read zero after resume even though profiling remains enabled in software.

Re-apply UMD stable pstate for profile DPM modes and re-enable KFD perfcount after a successful runtime resume.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 46 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 17 ++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   |  8 ++++
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  2 +
 drivers/gpu/drm/amd/amdkfd/kfd_process.c   |  1 +
 6 files changed, 75 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +46 -0
index 121282dd30c161..38974beb98ef88 100644
@@ -38,6 +38,7 @@
 #include "amdgpu_reset.h"
 #if IS_ENABLED(CONFIG_HSA_AMD)
 #include "kfd_priv.h"
+#include "kfd_device_queue_manager.h"
 #endif
 
 /* Total memory size in system memory and all GPU VRAM. Used to
@@ -280,6 +281,51 @@ int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc)
 	return r;
 }
 
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device *adev)
+{
+#if IS_ENABLED(CONFIG_HSA_AMD)
+	struct kfd_dev *kfd;
+	struct kfd_process *p;
+	struct kfd_process_device *pdd;
+	struct device_queue_manager *dqm;
+	int i;
+
+	if (!adev->kfd.dev || !adev->kfd.init_complete)
+		return;
+
+	kfd = adev->kfd.dev;
+
+	mutex_lock(&kfd->profiler_lock);
+	p = kfd->profiler_process;
+	if (!p || !kfd->profiler_perfcount_enabled) {
+		mutex_unlock(&kfd->profiler_lock);
+		return;
+	}
+	mutex_unlock(&kfd->profiler_lock);
+
+	mutex_lock(&p->mutex);
+
+	mutex_lock(&kfd->profiler_lock);
+	if (kfd->profiler_process != p || !kfd->profiler_perfcount_enabled) {
+		mutex_unlock(&kfd->profiler_lock);
+		mutex_unlock(&p->mutex);
+		return;
+	}
+	mutex_unlock(&kfd->profiler_lock);
+
+	for (i = 0; i < p->n_pdds; i++) {
+		pdd = p->pdds[i];
+		if (!pdd || !pdd->dev || pdd->dev->kfd != kfd)
+			continue;
+
+		dqm = pdd->dev->dqm;
+		if (dqm && dqm->ops.set_perfcount)
+			dqm->ops.set_perfcount(dqm, 1);
+	}
+	mutex_unlock(&p->mutex);
+#endif
+}
+
 void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev)
 {
 	if (adev->kfd.dev)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index 338412a750edf0..1be9d5ef97d6d0 100644
@@ -164,6 +164,7 @@ void amdgpu_amdkfd_teardown_processes(struct amdgpu_device *adev);
 
 void amdgpu_amdkfd_suspend(struct amdgpu_device *adev, bool suspend_proc);
 int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc);
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device *adev);
 void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev);
 int amdgpu_amdkfd_resume_process(struct amdgpu_device *adev);
 void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +17 -0
index 5362705143bc75..f7a1064c340692 100644
@@ -2920,6 +2920,21 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
 	return 0;
 }
 
+static void amdgpu_restore_perf_state_after_runpm(struct amdgpu_device *adev)
+{
+	enum amd_dpm_forced_level level;
+	uint32_t profile_mode_mask = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
+		AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
+		AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
+		AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
+
+	level = amdgpu_dpm_get_performance_level(adev);
+	if (level & profile_mode_mask)
+		amdgpu_asic_update_umd_stable_pstate(adev, true);
+
+	amdgpu_amdkfd_restore_profiler_after_runpm(adev);
+}
+
 static int amdgpu_pmops_runtime_resume(struct device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
@@ -2964,6 +2979,8 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
 
 	if (adev->pm.rpm_mode == AMDGPU_RUNPM_PX)
 		drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
+
+	amdgpu_restore_perf_state_after_runpm(adev);
 	adev->in_runpm = false;
 	return 0;
 }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +8 -0
index 2c1a936459ac87..2a140c40b53f9c 100644
@@ -3347,6 +3347,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
 	if (op == 1) {
 		if (!kfd->profiler_process) {
 			kfd->profiler_process = p;
+			kfd->profiler_perfcount_enabled = false;
 			status = 0;
 			mutex_unlock(&kfd->profiler_lock);
 			if (ptl->hw_supported) {
@@ -3364,6 +3365,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
 		}
 	} else if (op == 0 && kfd->profiler_process == p) {
 		kfd->profiler_process = NULL;
+		kfd->profiler_perfcount_enabled = false;
 		status = 0;
 		mutex_unlock(&kfd->profiler_lock);
 
@@ -3404,6 +3406,12 @@ static inline int kfd_profiler_pmc(struct kfd_process *p,
 	mutex_unlock(&p->mutex);
 
 	dqm->ops.set_perfcount(dqm, args->perfcount_enable);
+
+	mutex_lock(&pdd->dev->kfd->profiler_lock);
+	if (pdd->dev->kfd->profiler_process == p)
+		pdd->dev->kfd->profiler_perfcount_enabled = !!args->perfcount_enable;
+	mutex_unlock(&pdd->dev->kfd->profiler_lock);
+
 	return status;
 }
 
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 88191a4c165796..81055ada4f80b8 100644
@@ -389,6 +389,8 @@ struct kfd_dev {
 	struct mutex profiler_lock;
 	/* Process currently holding the lock */
 	struct kfd_process *profiler_process;
+	/* Whether perfcount is enabled for profiler_process */
+	bool profiler_perfcount_enabled;
 };
 
 enum kfd_mempool {
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
index eb508fe3ded780..8b7020fc0577a2 100644
@@ -1180,6 +1180,7 @@ static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_proce
 	if (pdd->dev->kfd->profiler_process == p) {
 		pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
 		pdd->dev->kfd->profiler_process = NULL;
+		pdd->dev->kfd->profiler_perfcount_enabled = false;
 	}
 	mutex_unlock(&pdd->dev->kfd->profiler_lock);
 }
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw

AMD General

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Candice Li
Sent: Wednesday, July 22, 2026 6:36 PM
To: [email protected]
Cc: Li, Candice <[email protected]>
Subject: [PATCH] drm/amdgpu: restore perf state after runtime resume

Runtime suspend runs GFX hw_fini and clears perfmon clock gating while KFD keeps running, so block perf counters read zero after resume even though profiling remains enabled in software.

Re-apply UMD stable pstate for profile DPM modes and re-enable KFD perfcount after a successful runtime resume.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 46 ++++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 17 ++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   |  8 ++++
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  2 +
 drivers/gpu/drm/amd/amdkfd/kfd_process.c   |  1 +
 6 files changed, 75 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -0
index 121282dd30c161..38974beb98ef88 100644
@@ -38,6 +38,7 @@
 #include "amdgpu_reset.h"
 #if IS_ENABLED(CONFIG_HSA_AMD)
 #include "kfd_priv.h"
+#include "kfd_device_queue_manager.h"
 #endif
 
 /* Total memory size in system memory and all GPU VRAM. Used to @@ -280,6 +281,51 @@ int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc)
        return r;

}

+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device +*adev) { #if IS_ENABLED(CONFIG_HSA_AMD)

+       struct kfd_dev *kfd;
+       struct kfd_process *p;
+       struct kfd_process_device *pdd;
+       struct device_queue_manager *dqm;
+       int i;

+
+ if (!adev->kfd.dev || !adev->kfd.init_complete)
+ return;
+
+ kfd = adev->kfd.dev;
+

+       mutex_lock(&kfd->profiler_lock);
+       p = kfd->profiler_process;
+       if (!p || !kfd->profiler_perfcount_enabled) {

+ mutex_unlock(&kfd->profiler_lock);
+ return;
+ }
+ mutex_unlock(&kfd->profiler_lock);
+
+ mutex_lock(&p->mutex);
+
+ mutex_lock(&kfd->profiler_lock);
+ if (kfd->profiler_process != p || !kfd->profiler_perfcount_enabled) {

+               mutex_unlock(&kfd->profiler_lock);
+               mutex_unlock(&p->mutex);
+               return;

+ }
+ mutex_unlock(&kfd->profiler_lock);
+
+ for (i = 0; i < p->n_pdds; i++) {
+ pdd = p->pdds[i];
+ if (!pdd || !pdd->dev || pdd->dev->kfd != kfd)
+ continue;
+
+ dqm = pdd->dev->dqm;
+ if (dqm && dqm->ops.set_perfcount)
+ dqm->ops.set_perfcount(dqm, 1);
+ }
+ mutex_unlock(&p->mutex);
+#endif
+}
+

 void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev)  {
        if (adev->kfd.dev)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
index 338412a750edf0..1be9d5ef97d6d0 100644
@@ -164,6 +164,7 @@ void amdgpu_amdkfd_teardown_processes(struct amdgpu_device *adev);
 
 void amdgpu_amdkfd_suspend(struct amdgpu_device *adev, bool suspend_proc);  int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc);
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev);
 void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev);  int amdgpu_amdkfd_resume_process(struct amdgpu_device *adev);  void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

index 5362705143bc75..f7a1064c340692 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +15 -0
@@ -2920,6 +2920,21 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
        return 0;
 }
 
+static void amdgpu_restore_perf_state_after_runpm(struct amdgpu_device
+*adev) {
+       enum amd_dpm_forced_level level;
+       uint32_t profile_mode_mask = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
+
+       level = amdgpu_dpm_get_performance_level(adev);
+       if (level & profile_mode_mask)
+               amdgpu_asic_update_umd_stable_pstate(adev, true);
+
+       amdgpu_amdkfd_restore_profiler_after_runpm(adev);
+}
+
 static int amdgpu_pmops_runtime_resume(struct device *dev)  {
        struct pci_dev *pdev = to_pci_dev(dev); @@ -2964,6 +2979,8 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
 
        if (adev->pm.rpm_mode == AMDGPU_RUNPM_PX)
                drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
+
+       amdgpu_restore_perf_state_after_runpm(adev);
        adev->in_runpm = false;
        return 0;

}

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +8 -0
index 2c1a936459ac87..2a140c40b53f9c 100644
@@ -3347,6 +3347,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
        if (op == 1) {
                if (!kfd->profiler_process) {
                        kfd->profiler_process = p;
+                       kfd->profiler_perfcount_enabled = false;
                        status = 0;
                        mutex_unlock(&kfd->profiler_lock);
                        if (ptl->hw_supported) {
@@ -3364,6 +3365,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
                }
        } else if (op == 0 && kfd->profiler_process == p) {
                kfd->profiler_process = NULL;
+               kfd->profiler_perfcount_enabled = false;
                status = 0;
                mutex_unlock(&kfd->profiler_lock);
 
@@ -3404,6 +3406,12 @@ static inline int kfd_profiler_pmc(struct kfd_process *p,
        mutex_unlock(&p->mutex);
 
        dqm->ops.set_perfcount(dqm, args->perfcount_enable);
+
+       mutex_lock(&pdd->dev->kfd->profiler_lock);
+       if (pdd->dev->kfd->profiler_process == p)
+               pdd->dev->kfd->profiler_perfcount_enabled = !!args->perfcount_enable;
+       mutex_unlock(&pdd->dev->kfd->profiler_lock);
+
        return status;
 }
 
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 88191a4c165796..81055ada4f80b8 100644
@@ -389,6 +389,8 @@ struct kfd_dev {
        struct mutex profiler_lock;
        /* Process currently holding the lock */
        struct kfd_process *profiler_process;
+       /* Whether perfcount is enabled for profiler_process */
+       bool profiler_perfcount_enabled;
 };
 
 enum kfd_mempool {
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
index eb508fe3ded780..8b7020fc0577a2 100644
@@ -1180,6 +1180,7 @@ static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_proce
        if (pdd->dev->kfd->profiler_process == p) {
                pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
                pdd->dev->kfd->profiler_process = NULL;
+               pdd->dev->kfd->profiler_perfcount_enabled = false;
        }
        mutex_unlock(&pdd->dev->kfd->profiler_lock);
 }

--
2.25.1

#2 lore raw
Quoted 105 lines · Hawking

AMD General

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Candice Li
Sent: Wednesday, July 22, 2026 6:36 PM
To: [email protected]
Cc: Li, Candice <[email protected]>
Subject: [PATCH] drm/amdgpu: restore perf state after runtime resume

Runtime suspend runs GFX hw_fini and clears perfmon clock gating while KFD keeps running, so block perf counters read zero after resume even though profiling remains enabled in software.

Re-apply UMD stable pstate for profile DPM modes and re-enable KFD perfcount after a successful runtime resume.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 46 ++++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 17 ++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   |  8 ++++
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  2 +
  drivers/gpu/drm/amd/amdkfd/kfd_process.c   |  1 +
  6 files changed, 75 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -0
index 121282dd30c161..38974beb98ef88 100644
@@ -38,6 +38,7 @@
  #include "amdgpu_reset.h"
  #if IS_ENABLED(CONFIG_HSA_AMD)
  #include "kfd_priv.h"
+#include "kfd_device_queue_manager.h"
  #endif
 
  /* Total memory size in system memory and all GPU VRAM. Used to @@ -280,6 +281,51 @@ int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc)
         return r;

}

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +44 -0
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev) { #if IS_ENABLED(CONFIG_HSA_AMD)
+       struct kfd_dev *kfd;
+       struct kfd_process *p;
+       struct kfd_process_device *pdd;
+       struct device_queue_manager *dqm;
+       int i;
+
+       if (!adev->kfd.dev || !adev->kfd.init_complete)
+               return;
+
+       kfd = adev->kfd.dev;
+
+       mutex_lock(&kfd->profiler_lock);
+       p = kfd->profiler_process;
+       if (!p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       mutex_lock(&p->mutex);
+
+       mutex_lock(&kfd->profiler_lock);
+       if (kfd->profiler_process != p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               mutex_unlock(&p->mutex);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       for (i = 0; i < p->n_pdds; i++) {
+               pdd = p->pdds[i];
+               if (!pdd || !pdd->dev || pdd->dev->kfd != kfd)
+                       continue;
+
+               dqm = pdd->dev->dqm;
+               if (dqm && dqm->ops.set_perfcount)
+                       dqm->ops.set_perfcount(dqm, 1);
+       }
+       mutex_unlock(&p->mutex);
+#endif
+}
+
  void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev)  {
         if (adev->kfd.dev)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
index 338412a750edf0..1be9d5ef97d6d0 100644
@@ -164,6 +164,7 @@ void amdgpu_amdkfd_teardown_processes(struct amdgpu_device *adev);
 
  void amdgpu_amdkfd_suspend(struct amdgpu_device *adev, bool suspend_proc);  int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc);
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev);
  void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev);  int amdgpu_amdkfd_resume_process(struct amdgpu_device *adev);  void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

index 5362705143bc75..f7a1064c340692 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -2920,6 +2920,21 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
         return 0;
  }
 
+static void amdgpu_restore_perf_state_after_runpm(struct amdgpu_device

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_suspend(struct device *dev) · line 2933

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +10 -0
+*adev) {
+       enum amd_dpm_forced_level level;
+       uint32_t profile_mode_mask = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
+
+       level = amdgpu_dpm_get_performance_level(adev);
+       if (level & profile_mode_mask)
+               amdgpu_asic_update_umd_stable_pstate(adev, true);

This is supposed to be called before entering the force dpm level mode. It's better to move this logic inside swsmu late_init before reapplying the level.

Thanks,
Lijo

Quoted 75 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -0
+
+       amdgpu_amdkfd_restore_profiler_after_runpm(adev);
+}
+
  static int amdgpu_pmops_runtime_resume(struct device *dev)  {
         struct pci_dev *pdev = to_pci_dev(dev); @@ -2964,6 +2979,8 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
 
         if (adev->pm.rpm_mode == AMDGPU_RUNPM_PX)
                 drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
+
+       amdgpu_restore_perf_state_after_runpm(adev);
         adev->in_runpm = false;
         return 0;
  }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +8 -0
index 2c1a936459ac87..2a140c40b53f9c 100644
@@ -3347,6 +3347,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
         if (op == 1) {
                 if (!kfd->profiler_process) {
                         kfd->profiler_process = p;
+                       kfd->profiler_perfcount_enabled = false;
                         status = 0;
                         mutex_unlock(&kfd->profiler_lock);
                         if (ptl->hw_supported) {
@@ -3364,6 +3365,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
                 }
         } else if (op == 0 && kfd->profiler_process == p) {
                 kfd->profiler_process = NULL;
+               kfd->profiler_perfcount_enabled = false;
                 status = 0;
                 mutex_unlock(&kfd->profiler_lock);
 
@@ -3404,6 +3406,12 @@ static inline int kfd_profiler_pmc(struct kfd_process *p,
         mutex_unlock(&p->mutex);
 
         dqm->ops.set_perfcount(dqm, args->perfcount_enable);
+
+       mutex_lock(&pdd->dev->kfd->profiler_lock);
+       if (pdd->dev->kfd->profiler_process == p)
+               pdd->dev->kfd->profiler_perfcount_enabled = !!args->perfcount_enable;
+       mutex_unlock(&pdd->dev->kfd->profiler_lock);
+
         return status;
  }
 
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 88191a4c165796..81055ada4f80b8 100644
@@ -389,6 +389,8 @@ struct kfd_dev {
         struct mutex profiler_lock;
         /* Process currently holding the lock */
         struct kfd_process *profiler_process;
+       /* Whether perfcount is enabled for profiler_process */
+       bool profiler_perfcount_enabled;
  };
 
  enum kfd_mempool {
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
index eb508fe3ded780..8b7020fc0577a2 100644
@@ -1180,6 +1180,7 @@ static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_proce
         if (pdd->dev->kfd->profiler_process == p) {
                 pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
                 pdd->dev->kfd->profiler_process = NULL;
+               pdd->dev->kfd->profiler_perfcount_enabled = false;
         }
         mutex_unlock(&pdd->dev->kfd->profiler_lock);
  }
--

2.25.1

#3 lore raw

AMD General

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, July 22, 2026 8:11 PM
To: Zhang, Hawking <[email protected]>; Li, Candice <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: restore perf state after runtime resume

Quoted 105 lines · Hawking

AMD General

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Candice Li
Sent: Wednesday, July 22, 2026 6:36 PM
To: [email protected]
Cc: Li, Candice <[email protected]>
Subject: [PATCH] drm/amdgpu: restore perf state after runtime resume

Runtime suspend runs GFX hw_fini and clears perfmon clock gating while KFD keeps running, so block perf counters read zero after resume even though profiling remains enabled in software.

Re-apply UMD stable pstate for profile DPM modes and re-enable KFD perfcount after a successful runtime resume.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 46 ++++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 17 ++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   |  8 ++++
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  2 +
  drivers/gpu/drm/amd/amdkfd/kfd_process.c   |  1 +
  6 files changed, 75 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -0
index 121282dd30c161..38974beb98ef88 100644
@@ -38,6 +38,7 @@
  #include "amdgpu_reset.h"
  #if IS_ENABLED(CONFIG_HSA_AMD)
  #include "kfd_priv.h"
+#include "kfd_device_queue_manager.h"
  #endif
 
  /* Total memory size in system memory and all GPU VRAM. Used to @@ -280,6 +281,51 @@ int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc)
         return r;

}

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +44 -0
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev) { #if IS_ENABLED(CONFIG_HSA_AMD)
+       struct kfd_dev *kfd;
+       struct kfd_process *p;
+       struct kfd_process_device *pdd;
+       struct device_queue_manager *dqm;
+       int i;
+
+       if (!adev->kfd.dev || !adev->kfd.init_complete)
+               return;
+
+       kfd = adev->kfd.dev;
+
+       mutex_lock(&kfd->profiler_lock);
+       p = kfd->profiler_process;
+       if (!p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       mutex_lock(&p->mutex);
+
+       mutex_lock(&kfd->profiler_lock);
+       if (kfd->profiler_process != p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               mutex_unlock(&p->mutex);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       for (i = 0; i < p->n_pdds; i++) {
+               pdd = p->pdds[i];
+               if (!pdd || !pdd->dev || pdd->dev->kfd != kfd)
+                       continue;
+
+               dqm = pdd->dev->dqm;
+               if (dqm && dqm->ops.set_perfcount)
+                       dqm->ops.set_perfcount(dqm, 1);
+       }
+       mutex_unlock(&p->mutex);
+#endif
+}
+
  void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev)  {
         if (adev->kfd.dev)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
index 338412a750edf0..1be9d5ef97d6d0 100644
@@ -164,6 +164,7 @@ void amdgpu_amdkfd_teardown_processes(struct amdgpu_device *adev);
 
  void amdgpu_amdkfd_suspend(struct amdgpu_device *adev, bool suspend_proc);  int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc);
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev);
  void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev);  int amdgpu_amdkfd_resume_process(struct amdgpu_device *adev);  void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

index 5362705143bc75..f7a1064c340692 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -2920,6 +2920,21 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
         return 0;
  }
 
+static void amdgpu_restore_perf_state_after_runpm(struct amdgpu_device

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_suspend(struct device *dev) · line 2933

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +10 -0
+*adev) {
+       enum amd_dpm_forced_level level;
+       uint32_t profile_mode_mask = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
+
+       level = amdgpu_dpm_get_performance_level(adev);
+       if (level & profile_mode_mask)
+               amdgpu_asic_update_umd_stable_pstate(adev, true);

This is supposed to be called before entering the force dpm level mode. It's better to move this logic inside swsmu late_init before reapplying the level.

Thanks,
Lijo

Thanks, Lijo.

I think this logic should remain in runtime resume. The amdgpu_asic_update_umd_stable_pstate(adev, true) call here is a restore/re-apply step for an already-selected profile forced level, not a force-level entry. Enter/exit behavior is already covered by the regular DPM force path (amdgpu_dpm_force_performance_level() / SMU force handling) when level transitions occur.

During runpm suspend/resume, the software forced level can remain profile mode, but HW-side stable pstate (and KFD profiler state) may be cleared by hw_fini/hw_init. That is why this restore is done after amdgpu_device_resume().

Moving this into swsmu late_init would apply the logic to broader flows (not only runpm), so I’d prefer to keep it in runpm resume.

Thanks,
Candice

Quoted 75 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -0
+
+       amdgpu_amdkfd_restore_profiler_after_runpm(adev);
+}
+
  static int amdgpu_pmops_runtime_resume(struct device *dev)  {
         struct pci_dev *pdev = to_pci_dev(dev); @@ -2964,6 +2979,8 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
 
         if (adev->pm.rpm_mode == AMDGPU_RUNPM_PX)
                 drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
+
+       amdgpu_restore_perf_state_after_runpm(adev);
         adev->in_runpm = false;
         return 0;
  }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +8 -0
index 2c1a936459ac87..2a140c40b53f9c 100644
@@ -3347,6 +3347,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
         if (op == 1) {
                 if (!kfd->profiler_process) {
                         kfd->profiler_process = p;
+                       kfd->profiler_perfcount_enabled = false;
                         status = 0;
                         mutex_unlock(&kfd->profiler_lock);
                         if (ptl->hw_supported) {
@@ -3364,6 +3365,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
                 }
         } else if (op == 0 && kfd->profiler_process == p) {
                 kfd->profiler_process = NULL;
+               kfd->profiler_perfcount_enabled = false;
                 status = 0;
                 mutex_unlock(&kfd->profiler_lock);
 
@@ -3404,6 +3406,12 @@ static inline int kfd_profiler_pmc(struct kfd_process *p,
         mutex_unlock(&p->mutex);
 
         dqm->ops.set_perfcount(dqm, args->perfcount_enable);
+
+       mutex_lock(&pdd->dev->kfd->profiler_lock);
+       if (pdd->dev->kfd->profiler_process == p)
+               pdd->dev->kfd->profiler_perfcount_enabled = !!args->perfcount_enable;
+       mutex_unlock(&pdd->dev->kfd->profiler_lock);
+
         return status;
  }
 
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 88191a4c165796..81055ada4f80b8 100644
@@ -389,6 +389,8 @@ struct kfd_dev {
         struct mutex profiler_lock;
         /* Process currently holding the lock */
         struct kfd_process *profiler_process;
+       /* Whether perfcount is enabled for profiler_process */
+       bool profiler_perfcount_enabled;
  };
 
  enum kfd_mempool {
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
index eb508fe3ded780..8b7020fc0577a2 100644
@@ -1180,6 +1180,7 @@ static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_proce
         if (pdd->dev->kfd->profiler_process == p) {
                 pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
                 pdd->dev->kfd->profiler_process = NULL;
+               pdd->dev->kfd->profiler_perfcount_enabled = false;
         }
         mutex_unlock(&pdd->dev->kfd->profiler_lock);
  }
--

2.25.1

#4 lore raw
Quoted 136 lines · Candice

AMD General

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, July 22, 2026 8:11 PM
To: Zhang, Hawking <[email protected]>; Li, Candice <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: restore perf state after runtime resume

Quoted 105 lines · Hawking

AMD General

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Candice Li
Sent: Wednesday, July 22, 2026 6:36 PM
To: [email protected]
Cc: Li, Candice <[email protected]>
Subject: [PATCH] drm/amdgpu: restore perf state after runtime resume

Runtime suspend runs GFX hw_fini and clears perfmon clock gating while KFD keeps running, so block perf counters read zero after resume even though profiling remains enabled in software.

Re-apply UMD stable pstate for profile DPM modes and re-enable KFD perfcount after a successful runtime resume.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 46 ++++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 17 ++++++++
   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   |  8 ++++
   drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  2 +
   drivers/gpu/drm/amd/amdkfd/kfd_process.c   |  1 +
   6 files changed, 75 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -0
index 121282dd30c161..38974beb98ef88 100644
@@ -38,6 +38,7 @@
   #include "amdgpu_reset.h"
   #if IS_ENABLED(CONFIG_HSA_AMD)
   #include "kfd_priv.h"
+#include "kfd_device_queue_manager.h"
   #endif
 
   /* Total memory size in system memory and all GPU VRAM. Used to @@ -280,6 +281,51 @@ int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc)
          return r;

}

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +44 -0
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev) { #if IS_ENABLED(CONFIG_HSA_AMD)
+       struct kfd_dev *kfd;
+       struct kfd_process *p;
+       struct kfd_process_device *pdd;
+       struct device_queue_manager *dqm;
+       int i;
+
+       if (!adev->kfd.dev || !adev->kfd.init_complete)
+               return;
+
+       kfd = adev->kfd.dev;
+
+       mutex_lock(&kfd->profiler_lock);
+       p = kfd->profiler_process;
+       if (!p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       mutex_lock(&p->mutex);
+
+       mutex_lock(&kfd->profiler_lock);
+       if (kfd->profiler_process != p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               mutex_unlock(&p->mutex);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       for (i = 0; i < p->n_pdds; i++) {
+               pdd = p->pdds[i];
+               if (!pdd || !pdd->dev || pdd->dev->kfd != kfd)
+                       continue;
+
+               dqm = pdd->dev->dqm;
+               if (dqm && dqm->ops.set_perfcount)
+                       dqm->ops.set_perfcount(dqm, 1);
+       }
+       mutex_unlock(&p->mutex);
+#endif
+}
+
   void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev)  {
          if (adev->kfd.dev)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
index 338412a750edf0..1be9d5ef97d6d0 100644
@@ -164,6 +164,7 @@ void amdgpu_amdkfd_teardown_processes(struct amdgpu_device *adev);
 
   void amdgpu_amdkfd_suspend(struct amdgpu_device *adev, bool suspend_proc);  int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc);
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev);
   void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev);  int amdgpu_amdkfd_resume_process(struct amdgpu_device *adev);  void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

index 5362705143bc75..f7a1064c340692 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -2920,6 +2920,21 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
          return 0;
   }
 
+static void amdgpu_restore_perf_state_after_runpm(struct amdgpu_device

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_suspend(struct device *dev) · line 2933

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +10 -0
+*adev) {
+       enum amd_dpm_forced_level level;
+       uint32_t profile_mode_mask = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
+
+       level = amdgpu_dpm_get_performance_level(adev);
+       if (level & profile_mode_mask)
+               amdgpu_asic_update_umd_stable_pstate(adev, true);

This is supposed to be called before entering the force dpm level mode. It's better to move this logic inside swsmu late_init before reapplying the level.

Thanks,
Lijo

Thanks, Lijo.

Quoted 8 lines

I think this logic should remain in runtime resume. The amdgpu_asic_update_umd_stable_pstate(adev, true) call here is a restore/re-apply step for an already-selected profile forced level, not a force-level entry. Enter/exit behavior is already covered by the regular DPM force path (amdgpu_dpm_force_performance_level() / SMU force handling) when level transitions occur.

During runpm suspend/resume, the software forced level can remain profile mode, but HW-side stable pstate (and KFD profiler state) may be cleared by hw_fini/hw_init. That is why this restore is done after amdgpu_device_resume().

Moving this into swsmu late_init would apply the logic to broader flows (not only runpm), so I’d prefer to keep it in runpm resume.

Profile setting is a user level setting and it's not the default SOC behavior. During runtime PM, chip is in ~D3 state and some settings are lost. For proper restoration, all the steps that are followed for a regular user profile setting needs to be done (you don't need to go by the 'force' name). That is done in the logic here also - it's checking if the level is one of the forced dpm levels. To properly reapply, it needs to follow the same process.

This is followed in other user setting scenarios also. smu late init has a specific call to restore user setttings.

Thanks,
Lijo

Quoted 80 lines

Thanks,
Candice

Quoted 75 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -0
+
+       amdgpu_amdkfd_restore_profiler_after_runpm(adev);
+}
+
   static int amdgpu_pmops_runtime_resume(struct device *dev)  {
          struct pci_dev *pdev = to_pci_dev(dev); @@ -2964,6 +2979,8 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
 
          if (adev->pm.rpm_mode == AMDGPU_RUNPM_PX)
                  drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
+
+       amdgpu_restore_perf_state_after_runpm(adev);
          adev->in_runpm = false;
          return 0;
   }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +8 -0
index 2c1a936459ac87..2a140c40b53f9c 100644
@@ -3347,6 +3347,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
          if (op == 1) {
                  if (!kfd->profiler_process) {
                          kfd->profiler_process = p;
+                       kfd->profiler_perfcount_enabled = false;
                          status = 0;
                          mutex_unlock(&kfd->profiler_lock);
                          if (ptl->hw_supported) {
@@ -3364,6 +3365,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
                  }
          } else if (op == 0 && kfd->profiler_process == p) {
                  kfd->profiler_process = NULL;
+               kfd->profiler_perfcount_enabled = false;
                  status = 0;
                  mutex_unlock(&kfd->profiler_lock);
 
@@ -3404,6 +3406,12 @@ static inline int kfd_profiler_pmc(struct kfd_process *p,
          mutex_unlock(&p->mutex);
 
          dqm->ops.set_perfcount(dqm, args->perfcount_enable);
+
+       mutex_lock(&pdd->dev->kfd->profiler_lock);
+       if (pdd->dev->kfd->profiler_process == p)
+               pdd->dev->kfd->profiler_perfcount_enabled = !!args->perfcount_enable;
+       mutex_unlock(&pdd->dev->kfd->profiler_lock);
+
          return status;
   }
 
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 88191a4c165796..81055ada4f80b8 100644
@@ -389,6 +389,8 @@ struct kfd_dev {
          struct mutex profiler_lock;
          /* Process currently holding the lock */
          struct kfd_process *profiler_process;
+       /* Whether perfcount is enabled for profiler_process */
+       bool profiler_perfcount_enabled;
   };
 
   enum kfd_mempool {
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
index eb508fe3ded780..8b7020fc0577a2 100644
@@ -1180,6 +1180,7 @@ static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_proce
          if (pdd->dev->kfd->profiler_process == p) {
                  pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
                  pdd->dev->kfd->profiler_process = NULL;
+               pdd->dev->kfd->profiler_perfcount_enabled = false;
          }
          mutex_unlock(&pdd->dev->kfd->profiler_lock);
   }
--

2.25.1

#5 lore raw

AMD General

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, July 23, 2026 11:46 AM
To: Li, Candice <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: restore perf state after runtime resume

Quoted 136 lines · Candice

AMD General

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, July 22, 2026 8:11 PM
To: Zhang, Hawking <[email protected]>; Li, Candice <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: restore perf state after runtime resume

Quoted 105 lines · Hawking

AMD General

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Candice Li
Sent: Wednesday, July 22, 2026 6:36 PM
To: [email protected]
Cc: Li, Candice <[email protected]>
Subject: [PATCH] drm/amdgpu: restore perf state after runtime resume

Runtime suspend runs GFX hw_fini and clears perfmon clock gating while KFD keeps running, so block perf counters read zero after resume even though profiling remains enabled in software.

Re-apply UMD stable pstate for profile DPM modes and re-enable KFD perfcount after a successful runtime resume.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 46 ++++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 17 ++++++++
   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   |  8 ++++
   drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  2 +
   drivers/gpu/drm/amd/amdkfd/kfd_process.c   |  1 +
   6 files changed, 75 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -0
index 121282dd30c161..38974beb98ef88 100644
@@ -38,6 +38,7 @@
   #include "amdgpu_reset.h"
   #if IS_ENABLED(CONFIG_HSA_AMD)
   #include "kfd_priv.h"
+#include "kfd_device_queue_manager.h"
   #endif
 
   /* Total memory size in system memory and all GPU VRAM. Used to @@ -280,6 +281,51 @@ int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc)
          return r;

}

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +44 -0
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev) { #if IS_ENABLED(CONFIG_HSA_AMD)
+       struct kfd_dev *kfd;
+       struct kfd_process *p;
+       struct kfd_process_device *pdd;
+       struct device_queue_manager *dqm;
+       int i;
+
+       if (!adev->kfd.dev || !adev->kfd.init_complete)
+               return;
+
+       kfd = adev->kfd.dev;
+
+       mutex_lock(&kfd->profiler_lock);
+       p = kfd->profiler_process;
+       if (!p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       mutex_lock(&p->mutex);
+
+       mutex_lock(&kfd->profiler_lock);
+       if (kfd->profiler_process != p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               mutex_unlock(&p->mutex);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       for (i = 0; i < p->n_pdds; i++) {
+               pdd = p->pdds[i];
+               if (!pdd || !pdd->dev || pdd->dev->kfd != kfd)
+                       continue;
+
+               dqm = pdd->dev->dqm;
+               if (dqm && dqm->ops.set_perfcount)
+                       dqm->ops.set_perfcount(dqm, 1);
+       }
+       mutex_unlock(&p->mutex);
+#endif
+}
+
   void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev)  {
          if (adev->kfd.dev)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
index 338412a750edf0..1be9d5ef97d6d0 100644
@@ -164,6 +164,7 @@ void amdgpu_amdkfd_teardown_processes(struct amdgpu_device *adev);
 
   void amdgpu_amdkfd_suspend(struct amdgpu_device *adev, bool suspend_proc);  int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc);
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev);
   void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev);  int amdgpu_amdkfd_resume_process(struct amdgpu_device *adev);  void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

index 5362705143bc75..f7a1064c340692 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -2920,6 +2920,21 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
          return 0;
   }
 
+static void amdgpu_restore_perf_state_after_runpm(struct amdgpu_device

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_suspend(struct device *dev) · line 2933

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +10 -0
+*adev) {
+       enum amd_dpm_forced_level level;
+       uint32_t profile_mode_mask = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
+
+       level = amdgpu_dpm_get_performance_level(adev);
+       if (level & profile_mode_mask)
+               amdgpu_asic_update_umd_stable_pstate(adev, true);

This is supposed to be called before entering the force dpm level mode. It's better to move this logic inside swsmu late_init before reapplying the level.

Thanks,
Lijo

Thanks, Lijo.

Quoted 8 lines

I think this logic should remain in runtime resume. The amdgpu_asic_update_umd_stable_pstate(adev, true) call here is a restore/re-apply step for an already-selected profile forced level, not a force-level entry. Enter/exit behavior is already covered by the regular DPM force path (amdgpu_dpm_force_performance_level() / SMU force handling) when level transitions occur.

During runpm suspend/resume, the software forced level can remain profile mode, but HW-side stable pstate (and KFD profiler state) may be cleared by hw_fini/hw_init. That is why this restore is done after amdgpu_device_resume().

Moving this into swsmu late_init would apply the logic to broader flows (not only runpm), so I’d prefer to keep it in runpm resume.

Profile setting is a user level setting and it's not the default SOC behavior. During runtime PM, chip is in ~D3 state and some settings are lost. For proper restoration, all the steps that are followed for a regular user profile setting needs to be done (you don't need to go by the 'force' name). That is done in the logic here also - it's checking if the level is one of the forced dpm levels. To properly reapply, it needs to follow the same process.

This is followed in other user setting scenarios also. smu late init has a specific call to restore user setttings.

Thanks,
Lijo

Thanks, Lijo.
Good point - profile mode is user-level state and after runpm we should replay it through the same user-setting restore path, not only re-enable UMD stable pstate. I’ll move this logic into the swsmu late init restore flow (alongside user profile restoration) so profile reapply follows the same sequence as normal user profile programming. Then runtime-resume side will keep only kfd profiler restore hook.

Thanks,
Candice

Quoted 80 lines

Thanks,
Candice

Quoted 75 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -0
+
+       amdgpu_amdkfd_restore_profiler_after_runpm(adev);
+}
+
   static int amdgpu_pmops_runtime_resume(struct device *dev)  {
          struct pci_dev *pdev = to_pci_dev(dev); @@ -2964,6 +2979,8 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
 
          if (adev->pm.rpm_mode == AMDGPU_RUNPM_PX)
                  drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
+
+       amdgpu_restore_perf_state_after_runpm(adev);
          adev->in_runpm = false;
          return 0;
   }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +8 -0
index 2c1a936459ac87..2a140c40b53f9c 100644
@@ -3347,6 +3347,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
          if (op == 1) {
                  if (!kfd->profiler_process) {
                          kfd->profiler_process = p;
+                       kfd->profiler_perfcount_enabled = false;
                          status = 0;
                          mutex_unlock(&kfd->profiler_lock);
                          if (ptl->hw_supported) {
@@ -3364,6 +3365,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
                  }
          } else if (op == 0 && kfd->profiler_process == p) {
                  kfd->profiler_process = NULL;
+               kfd->profiler_perfcount_enabled = false;
                  status = 0;
                  mutex_unlock(&kfd->profiler_lock);
 
@@ -3404,6 +3406,12 @@ static inline int kfd_profiler_pmc(struct kfd_process *p,
          mutex_unlock(&p->mutex);
 
          dqm->ops.set_perfcount(dqm, args->perfcount_enable);
+
+       mutex_lock(&pdd->dev->kfd->profiler_lock);
+       if (pdd->dev->kfd->profiler_process == p)
+               pdd->dev->kfd->profiler_perfcount_enabled = !!args->perfcount_enable;
+       mutex_unlock(&pdd->dev->kfd->profiler_lock);
+
          return status;
   }
 
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 88191a4c165796..81055ada4f80b8 100644
@@ -389,6 +389,8 @@ struct kfd_dev {
          struct mutex profiler_lock;
          /* Process currently holding the lock */
          struct kfd_process *profiler_process;
+       /* Whether perfcount is enabled for profiler_process */
+       bool profiler_perfcount_enabled;
   };
 
   enum kfd_mempool {
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
index eb508fe3ded780..8b7020fc0577a2 100644
@@ -1180,6 +1180,7 @@ static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_proce
          if (pdd->dev->kfd->profiler_process == p) {
                  pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
                  pdd->dev->kfd->profiler_process = NULL;
+               pdd->dev->kfd->profiler_perfcount_enabled = false;
          }
          mutex_unlock(&pdd->dev->kfd->profiler_lock);
   }
--

2.25.1

#6 lore raw

AMD General

Hi Lijo,

I want to revise my earlier agreement after rechecking the full runtime-resume flow.

I agree profile/forced DPM is a user policy and D3 can lose HW programming, but for this bug the key is restore timing.
If we do this in smu_late_init(), later resume stages can still touch CG/PG/GC and clear PERFMON_CLOCK_STATE again, so the restore is not persistent.

For that reason, I’d like to keep the original placement: restore at the end of amdgpu_pmops_runtime_resume(), and only re-assert UMD stable pstate when current level is a profile forced level. This keeps smu_late_init() for normal policy replay, while ensuring perfmon state is restored at a point where it is not overwritten afterward.

Thanks,
Candice

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Li, Candice
Sent: Thursday, July 23, 2026 2:16 PM
To: Lazar, Lijo <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: RE: [PATCH] drm/amdgpu: restore perf state after runtime resume

AMD General

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, July 23, 2026 11:46 AM
To: Li, Candice <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: restore perf state after runtime resume

Quoted 136 lines · Candice

AMD General

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, July 22, 2026 8:11 PM
To: Zhang, Hawking <[email protected]>; Li, Candice <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: restore perf state after runtime resume

Quoted 105 lines · Hawking

AMD General

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Candice Li
Sent: Wednesday, July 22, 2026 6:36 PM
To: [email protected]
Cc: Li, Candice <[email protected]>
Subject: [PATCH] drm/amdgpu: restore perf state after runtime resume

Runtime suspend runs GFX hw_fini and clears perfmon clock gating while KFD keeps running, so block perf counters read zero after resume even though profiling remains enabled in software.

Re-apply UMD stable pstate for profile DPM modes and re-enable KFD perfcount after a successful runtime resume.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 46 ++++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 17 ++++++++
   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   |  8 ++++
   drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  2 +
   drivers/gpu/drm/amd/amdkfd/kfd_process.c   |  1 +
   6 files changed, 75 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -0
index 121282dd30c161..38974beb98ef88 100644
@@ -38,6 +38,7 @@
   #include "amdgpu_reset.h"
   #if IS_ENABLED(CONFIG_HSA_AMD)
   #include "kfd_priv.h"
+#include "kfd_device_queue_manager.h"
   #endif
 
   /* Total memory size in system memory and all GPU VRAM. Used to @@ -280,6 +281,51 @@ int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc)
          return r;

}

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +44 -0
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev) { #if IS_ENABLED(CONFIG_HSA_AMD)
+       struct kfd_dev *kfd;
+       struct kfd_process *p;
+       struct kfd_process_device *pdd;
+       struct device_queue_manager *dqm;
+       int i;
+
+       if (!adev->kfd.dev || !adev->kfd.init_complete)
+               return;
+
+       kfd = adev->kfd.dev;
+
+       mutex_lock(&kfd->profiler_lock);
+       p = kfd->profiler_process;
+       if (!p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       mutex_lock(&p->mutex);
+
+       mutex_lock(&kfd->profiler_lock);
+       if (kfd->profiler_process != p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               mutex_unlock(&p->mutex);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       for (i = 0; i < p->n_pdds; i++) {
+               pdd = p->pdds[i];
+               if (!pdd || !pdd->dev || pdd->dev->kfd != kfd)
+                       continue;
+
+               dqm = pdd->dev->dqm;
+               if (dqm && dqm->ops.set_perfcount)
+                       dqm->ops.set_perfcount(dqm, 1);
+       }
+       mutex_unlock(&p->mutex);
+#endif
+}
+
   void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev)  {
          if (adev->kfd.dev)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
index 338412a750edf0..1be9d5ef97d6d0 100644
@@ -164,6 +164,7 @@ void amdgpu_amdkfd_teardown_processes(struct amdgpu_device *adev);
 
   void amdgpu_amdkfd_suspend(struct amdgpu_device *adev, bool suspend_proc);  int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc);
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev);
   void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev);  int amdgpu_amdkfd_resume_process(struct amdgpu_device *adev);  void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

index 5362705143bc75..f7a1064c340692 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -2920,6 +2920,21 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
          return 0;
   }
 
+static void amdgpu_restore_perf_state_after_runpm(struct amdgpu_device

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_suspend(struct device *dev) · line 2933

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +10 -0
+*adev) {
+       enum amd_dpm_forced_level level;
+       uint32_t profile_mode_mask = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
+
+       level = amdgpu_dpm_get_performance_level(adev);
+       if (level & profile_mode_mask)
+               amdgpu_asic_update_umd_stable_pstate(adev, true);

This is supposed to be called before entering the force dpm level mode. It's better to move this logic inside swsmu late_init before reapplying the level.

Thanks,
Lijo

Thanks, Lijo.

Quoted 8 lines

I think this logic should remain in runtime resume. The amdgpu_asic_update_umd_stable_pstate(adev, true) call here is a restore/re-apply step for an already-selected profile forced level, not a force-level entry. Enter/exit behavior is already covered by the regular DPM force path (amdgpu_dpm_force_performance_level() / SMU force handling) when level transitions occur.

During runpm suspend/resume, the software forced level can remain profile mode, but HW-side stable pstate (and KFD profiler state) may be cleared by hw_fini/hw_init. That is why this restore is done after amdgpu_device_resume().

Moving this into swsmu late_init would apply the logic to broader flows (not only runpm), so I’d prefer to keep it in runpm resume.

Profile setting is a user level setting and it's not the default SOC behavior. During runtime PM, chip is in ~D3 state and some settings are lost. For proper restoration, all the steps that are followed for a regular user profile setting needs to be done (you don't need to go by the 'force' name). That is done in the logic here also - it's checking if the level is one of the forced dpm levels. To properly reapply, it needs to follow the same process.

This is followed in other user setting scenarios also. smu late init has a specific call to restore user setttings.

Thanks,
Lijo

Thanks, Lijo.
Good point - profile mode is user-level state and after runpm we should replay it through the same user-setting restore path, not only re-enable UMD stable pstate. I’ll move this logic into the swsmu late init restore flow (alongside user profile restoration) so profile reapply follows the same sequence as normal user profile programming. Then runtime-resume side will keep only kfd profiler restore hook.

Thanks,
Candice

Quoted 80 lines

Thanks,
Candice

Quoted 75 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -0
+
+       amdgpu_amdkfd_restore_profiler_after_runpm(adev);
+}
+
   static int amdgpu_pmops_runtime_resume(struct device *dev)  {
          struct pci_dev *pdev = to_pci_dev(dev); @@ -2964,6 +2979,8 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
 
          if (adev->pm.rpm_mode == AMDGPU_RUNPM_PX)
                  drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
+
+       amdgpu_restore_perf_state_after_runpm(adev);
          adev->in_runpm = false;
          return 0;
   }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +8 -0
index 2c1a936459ac87..2a140c40b53f9c 100644
@@ -3347,6 +3347,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
          if (op == 1) {
                  if (!kfd->profiler_process) {
                          kfd->profiler_process = p;
+                       kfd->profiler_perfcount_enabled = false;
                          status = 0;
                          mutex_unlock(&kfd->profiler_lock);
                          if (ptl->hw_supported) {
@@ -3364,6 +3365,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
                  }
          } else if (op == 0 && kfd->profiler_process == p) {
                  kfd->profiler_process = NULL;
+               kfd->profiler_perfcount_enabled = false;
                  status = 0;
                  mutex_unlock(&kfd->profiler_lock);
 
@@ -3404,6 +3406,12 @@ static inline int kfd_profiler_pmc(struct kfd_process *p,
          mutex_unlock(&p->mutex);
 
          dqm->ops.set_perfcount(dqm, args->perfcount_enable);
+
+       mutex_lock(&pdd->dev->kfd->profiler_lock);
+       if (pdd->dev->kfd->profiler_process == p)
+               pdd->dev->kfd->profiler_perfcount_enabled = !!args->perfcount_enable;
+       mutex_unlock(&pdd->dev->kfd->profiler_lock);
+
          return status;
   }
 
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 88191a4c165796..81055ada4f80b8 100644
@@ -389,6 +389,8 @@ struct kfd_dev {
          struct mutex profiler_lock;
          /* Process currently holding the lock */
          struct kfd_process *profiler_process;
+       /* Whether perfcount is enabled for profiler_process */
+       bool profiler_perfcount_enabled;
   };
 
   enum kfd_mempool {
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
index eb508fe3ded780..8b7020fc0577a2 100644
@@ -1180,6 +1180,7 @@ static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_proce
          if (pdd->dev->kfd->profiler_process == p) {
                  pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
                  pdd->dev->kfd->profiler_process = NULL;
+               pdd->dev->kfd->profiler_perfcount_enabled = false;
          }
          mutex_unlock(&pdd->dev->kfd->profiler_lock);
   }
--

2.25.1

Reviewed-by
#7 lore raw

AMD General

Quoted 6 lines

For that reason, I’d like to keep the original placement: restore at the end of amdgpu_pmops_runtime_resume(), and only re-assert UMD stable pstate when current level is a profile forced level.
This keeps smu_late_init() for normal policy replay, while ensuring perfmon state is restored at a point where it is not overwritten afterward.

I agree with your point, please isolate all runpm-related logic away from SWSMU. And also split this patch into two separate parts: one for KFD, the other for PM. For the PM parts, please add my RB:

Best Regards,
Kevin

Quoted 341 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Li, Candice
Sent: Friday, July 24, 2026 11:08 AM
To: Li, Candice <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: RE: [PATCH] drm/amdgpu: restore perf state after runtime resume

AMD General

Hi Lijo,

I want to revise my earlier agreement after rechecking the full runtime-resume flow.

I agree profile/forced DPM is a user policy and D3 can lose HW programming, but for this bug the key is restore timing.
If we do this in smu_late_init(), later resume stages can still touch CG/PG/GC and clear PERFMON_CLOCK_STATE again, so the restore is not persistent.

For that reason, I’d like to keep the original placement: restore at the end of amdgpu_pmops_runtime_resume(), and only re-assert UMD stable pstate when current level is a profile forced level.
This keeps smu_late_init() for normal policy replay, while ensuring perfmon state is restored at a point where it is not overwritten afterward.

Thanks,
Candice

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Li, Candice
Sent: Thursday, July 23, 2026 2:16 PM
To: Lazar, Lijo <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: RE: [PATCH] drm/amdgpu: restore perf state after runtime resume

AMD General

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, July 23, 2026 11:46 AM
To: Li, Candice <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: restore perf state after runtime resume

Quoted 12 lines · Candice

AMD General

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, July 22, 2026 8:11 PM
To: Zhang, Hawking <[email protected]>; Li, Candice <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: restore perf state after runtime resume

Quoted 16 lines
Quoted 15 lines · Hawking

AMD General

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Candice Li
Sent: Wednesday, July 22, 2026 6:36 PM
To: [email protected]
Cc: Li, Candice <[email protected]>
Subject: [PATCH] drm/amdgpu: restore perf state after runtime resume

Runtime suspend runs GFX hw_fini and clears perfmon clock gating while

KFD keeps running, so block perf counters read zero after resume even though profiling remains enabled in software.

Quoted 2 lines
Quoted 2 lines

Re-apply UMD stable pstate for profile DPM modes and re-enable KFD

perfcount after a successful runtime resume.

Quoted 4 lines
Quoted 4 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 46

++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 1 +

Quoted 18 lines
Quoted 18 lines
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 17 ++++++++
   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   |  8 ++++
   drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  2 +
   drivers/gpu/drm/amd/amdkfd/kfd_process.c   |  1 +
   6 files changed, 75 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -0
index 121282dd30c161..38974beb98ef88 100644
@@ -38,6 +38,7 @@
   #include "amdgpu_reset.h"
   #if IS_ENABLED(CONFIG_HSA_AMD)
   #include "kfd_priv.h"
+#include "kfd_device_queue_manager.h"
   #endif
 
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c line 44

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -0
   /* Total memory size in system memory and all GPU VRAM. Used to @@

-280,6 +281,51 @@ int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc)

Quoted 4 lines
Quoted 4 lines
          return r;

}

+void amdgpu_amdkfd_restore_profiler_after_runpm(struct

amdgpu_device

Quoted 53 lines
Quoted 53 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +43 -0
+*adev) { #if IS_ENABLED(CONFIG_HSA_AMD)
+       struct kfd_dev *kfd;
+       struct kfd_process *p;
+       struct kfd_process_device *pdd;
+       struct device_queue_manager *dqm;
+       int i;
+
+       if (!adev->kfd.dev || !adev->kfd.init_complete)
+               return;
+
+       kfd = adev->kfd.dev;
+
+       mutex_lock(&kfd->profiler_lock);
+       p = kfd->profiler_process;
+       if (!p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       mutex_lock(&p->mutex);
+
+       mutex_lock(&kfd->profiler_lock);
+       if (kfd->profiler_process != p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               mutex_unlock(&p->mutex);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       for (i = 0; i < p->n_pdds; i++) {
+               pdd = p->pdds[i];
+               if (!pdd || !pdd->dev || pdd->dev->kfd != kfd)
+                       continue;
+
+               dqm = pdd->dev->dqm;
+               if (dqm && dqm->ops.set_perfcount)
+                       dqm->ops.set_perfcount(dqm, 1);
+       }
+       mutex_unlock(&p->mutex);
+#endif
+}
+
   void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev)  {
          if (adev->kfd.dev)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0 -0
index 338412a750edf0..1be9d5ef97d6d0 100644
@@ -164,6 +164,7 @@ void amdgpu_amdkfd_teardown_processes(struct
 amdgpu_device *adev);
 
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0 -0
   void amdgpu_amdkfd_suspend(struct amdgpu_device *adev, bool

suspend_proc); int amdgpu_amdkfd_resume(struct amdgpu_device

*adev,

Quoted 2 lines
Quoted 2 lines

bool resume_proc);
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct

amdgpu_device

Quoted 10 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int

Quoted 10 lines
+*adev);
   void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev);

int amdgpu_amdkfd_resume_process(struct amdgpu_device *adev); void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 5362705143bc75..f7a1064c340692 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -0
@@ -2920,6 +2920,21 @@ static int

amdgpu_pmops_runtime_suspend(struct device *dev)

Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_suspend(struct device *dev)

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +5 -0
          return 0;
   }
 
+static void amdgpu_restore_perf_state_after_runpm(struct
+amdgpu_device
+*adev) {
+       enum amd_dpm_forced_level level;
+       uint32_t profile_mode_mask =

AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |

Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_suspend(struct device *dev) · line 2933

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +7 -0
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
+
+       level = amdgpu_dpm_get_performance_level(adev);
+       if (level & profile_mode_mask)
+               amdgpu_asic_update_umd_stable_pstate(adev, true);

This is supposed to be called before entering the force dpm level mode. It's better to move this logic inside swsmu late_init before reapplying the level.

Quoted 6 lines

Thanks,
Lijo

Thanks, Lijo.

I think this logic should remain in runtime resume. The

amdgpu_asic_update_umd_stable_pstate(adev, true) call here is a restore/re- apply step for an already-selected profile forced level, not a force-level entry.

Quoted 1 line

Enter/exit behavior is already covered by the regular DPM force path

(amdgpu_dpm_force_performance_level() / SMU force handling) when level transitions occur.

Quoted 2 lines

During runpm suspend/resume, the software forced level can remain profile

mode, but HW-side stable pstate (and KFD profiler state) may be cleared by hw_fini/hw_init.

Quoted 3 lines

That is why this restore is done after amdgpu_device_resume().

Moving this into swsmu late_init would apply the logic to broader flows (not

only runpm), so I’d prefer to keep it in runpm resume.

Quoted 1 line

Profile setting is a user level setting and it's not the default SOC behavior. During runtime PM, chip is in ~D3 state and some settings are lost. For proper restoration, all the steps that are followed for a regular user profile setting needs to be done (you don't need to go by the 'force' name). That is done in the logic here also - it's checking if the level is one of the forced dpm levels. To properly reapply, it needs to follow the same process.

This is followed in other user setting scenarios also. smu late init has a specific call to restore user setttings.

Thanks,
Lijo

Thanks, Lijo.
Good point - profile mode is user-level state and after runpm we should replay it through the same user-setting restore path, not only re-enable UMD stable pstate.
I’ll move this logic into the swsmu late init restore flow (alongside user profile restoration) so profile reapply follows the same sequence as normal user profile programming.
Then runtime-resume side will keep only kfd profiler restore hook.

Thanks,
Candice

Quoted 12 lines

Thanks,
Candice

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -0
+
+       amdgpu_amdkfd_restore_profiler_after_runpm(adev);
+}
+
   static int amdgpu_pmops_runtime_resume(struct device *dev)  {
          struct pci_dev *pdev = to_pci_dev(dev); @@ -2964,6 +2979,8

@@ static int amdgpu_pmops_runtime_resume(struct device *dev)

Quoted 13 lines

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static inline uint32_t profile_lock_device(struct

Quoted 13 lines
          if (adev->pm.rpm_mode == AMDGPU_RUNPM_PX)
                  drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
+
+       amdgpu_restore_perf_state_after_runpm(adev);
          adev->in_runpm = false;
          return 0;
   }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
index 2c1a936459ac87..2a140c40b53f9c 100644
@@ -3347,6 +3347,7 @@ static inline uint32_t profile_lock_device(struct

kfd_process *p,

Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -0
          if (op == 1) {
                  if (!kfd->profiler_process) {
                          kfd->profiler_process = p;
+                       kfd->profiler_perfcount_enabled = false;
                          status = 0;
                          mutex_unlock(&kfd->profiler_lock);
                          if (ptl->hw_supported) { @@ -3364,6 +3365,7

@@ static inline uint32_t profile_lock_device(struct kfd_process *p,

                  }
          } else if (op == 0 && kfd->profiler_process == p) {
                  kfd->profiler_process = NULL;
+               kfd->profiler_perfcount_enabled = false;
                  status = 0;
                  mutex_unlock(&kfd->profiler_lock);
Quoted 1 line

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static inline int kfd_profiler_pmc(struct

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
@@ -3404,6 +3406,12 @@ static inline int kfd_profiler_pmc(struct

kfd_process *p,

Quoted 26 lines

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static inline int kfd_profiler_pmc(struct kfd_process *p,

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +4 -0
          mutex_unlock(&p->mutex);
 
          dqm->ops.set_perfcount(dqm, args->perfcount_enable);
+
+       mutex_lock(&pdd->dev->kfd->profiler_lock);
+       if (pdd->dev->kfd->profiler_process == p)
+               pdd->dev->kfd->profiler_perfcount_enabled = !!args-

perfcount_enable;

Quoted 18 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -0
+       mutex_unlock(&pdd->dev->kfd->profiler_lock);
+
          return status;
   }
 
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 88191a4c165796..81055ada4f80b8 100644
@@ -389,6 +389,8 @@ struct kfd_dev {
          struct mutex profiler_lock;
          /* Process currently holding the lock */
          struct kfd_process *profiler_process;
+       /* Whether perfcount is enabled for profiler_process */
+       bool profiler_perfcount_enabled;
   };
 
Quoted 7 lines

drivers/gpu/drm/amd/amdkfd/kfd_process.c static void kfd_process_profiler_release(struct

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
   enum kfd_mempool {
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index eb508fe3ded780..8b7020fc0577a2 100644
@@ -1180,6 +1180,7 @@ static void kfd_process_profiler_release(struct

kfd_process *p, struct kfd_proce

Quoted 11 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
          if (pdd->dev->kfd->profiler_process == p) {
                  pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
                  pdd->dev->kfd->profiler_process = NULL;
+               pdd->dev->kfd->profiler_perfcount_enabled = false;
          }
          mutex_unlock(&pdd->dev->kfd->profiler_lock);
   }
--

2.25.1

#8 lore raw
In reply to Li, Candice

AMD General

Quoted 1 line

If we do this in smu_late_init(), later resume stages can still touch CG/PG/GC and clear PERFMON_CLOCK_STATE again, so the restore is not persistent.

If this happens, the check that user level is enforced is not correct (since it is not really enforced). The same could happen when a user applies force profile mode also. Basically, we need to prevent this for all other cases also. Where do you see this happening?

Thanks,
Lijo
-----Original Message-----
From: Li, Candice <[email protected]>
Sent: Friday, July 24, 2026 8:38 AM
To: Li, Candice <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: RE: [PATCH] drm/amdgpu: restore perf state after runtime resume

AMD General

Hi Lijo,

I want to revise my earlier agreement after rechecking the full runtime-resume flow.

I agree profile/forced DPM is a user policy and D3 can lose HW programming, but for this bug the key is restore timing.
If we do this in smu_late_init(), later resume stages can still touch CG/PG/GC and clear PERFMON_CLOCK_STATE again, so the restore is not persistent.

For that reason, I’d like to keep the original placement: restore at the end of amdgpu_pmops_runtime_resume(), and only re-assert UMD stable pstate when current level is a profile forced level. This keeps smu_late_init() for normal policy replay, while ensuring perfmon state is restored at a point where it is not overwritten afterward.

Thanks,
Candice

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Li, Candice
Sent: Thursday, July 23, 2026 2:16 PM
To: Lazar, Lijo <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: RE: [PATCH] drm/amdgpu: restore perf state after runtime resume

AMD General

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, July 23, 2026 11:46 AM
To: Li, Candice <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: restore perf state after runtime resume

Quoted 149 lines · Candice

AMD General

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, July 22, 2026 8:11 PM
To: Zhang, Hawking <[email protected]>; Li, Candice <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: restore perf state after runtime resume

Quoted 116 lines · Hawking

AMD General

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Candice Li
Sent: Wednesday, July 22, 2026 6:36 PM
To: [email protected]
Cc: Li, Candice <[email protected]>
Subject: [PATCH] drm/amdgpu: restore perf state after runtime resume

Runtime suspend runs GFX hw_fini and clears perfmon clock gating while KFD keeps running, so block perf counters read zero after resume even though profiling remains enabled in software.

Re-apply UMD stable pstate for profile DPM modes and re-enable KFD perfcount after a successful runtime resume.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 46 ++++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 17 ++++++++
   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   |  8 ++++
   drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  2 +
   drivers/gpu/drm/amd/amdkfd/kfd_process.c   |  1 +
   6 files changed, 75 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -0
index 121282dd30c161..38974beb98ef88 100644
@@ -38,6 +38,7 @@
   #include "amdgpu_reset.h"
   #if IS_ENABLED(CONFIG_HSA_AMD)
   #include "kfd_priv.h"
+#include "kfd_device_queue_manager.h"
   #endif
 
   /* Total memory size in system memory and all GPU VRAM. Used to @@ -280,6 +281,51 @@ int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc)
          return r;

}

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +44 -0
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev) { #if IS_ENABLED(CONFIG_HSA_AMD)
+       struct kfd_dev *kfd;
+       struct kfd_process *p;
+       struct kfd_process_device *pdd;
+       struct device_queue_manager *dqm;
+       int i;
+
+       if (!adev->kfd.dev || !adev->kfd.init_complete)
+               return;
+
+       kfd = adev->kfd.dev;
+
+       mutex_lock(&kfd->profiler_lock);
+       p = kfd->profiler_process;
+       if (!p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       mutex_lock(&p->mutex);
+
+       mutex_lock(&kfd->profiler_lock);
+       if (kfd->profiler_process != p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               mutex_unlock(&p->mutex);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       for (i = 0; i < p->n_pdds; i++) {
+               pdd = p->pdds[i];
+               if (!pdd || !pdd->dev || pdd->dev->kfd != kfd)
+                       continue;
+
+               dqm = pdd->dev->dqm;
+               if (dqm && dqm->ops.set_perfcount)
+                       dqm->ops.set_perfcount(dqm, 1);
+       }
+       mutex_unlock(&p->mutex);
+#endif
+}
+
   void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev)  {
          if (adev->kfd.dev)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
index 338412a750edf0..1be9d5ef97d6d0 100644
@@ -164,6 +164,7 @@ void amdgpu_amdkfd_teardown_processes(struct
 amdgpu_device *adev);
 
   void amdgpu_amdkfd_suspend(struct amdgpu_device *adev, bool
 suspend_proc);  int amdgpu_amdkfd_resume(struct amdgpu_device *adev,
 bool resume_proc);
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev);
   void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev);

int amdgpu_amdkfd_resume_process(struct amdgpu_device *adev); void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 5362705143bc75..f7a1064c340692 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
@@ -2920,6 +2920,21 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
          return 0;
   }
 
+static void amdgpu_restore_perf_state_after_runpm(struct
+amdgpu_device

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_suspend(struct device *dev) · line 2934

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +10 -0
+*adev) {
+       enum amd_dpm_forced_level level;
+       uint32_t profile_mode_mask = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
+
+       level = amdgpu_dpm_get_performance_level(adev);
+       if (level & profile_mode_mask)
+               amdgpu_asic_update_umd_stable_pstate(adev, true);

This is supposed to be called before entering the force dpm level mode. It's better to move this logic inside swsmu late_init before reapplying the level.

Thanks,
Lijo

Thanks, Lijo.

Quoted 8 lines

I think this logic should remain in runtime resume. The amdgpu_asic_update_umd_stable_pstate(adev, true) call here is a restore/re-apply step for an already-selected profile forced level, not a force-level entry. Enter/exit behavior is already covered by the regular DPM force path (amdgpu_dpm_force_performance_level() / SMU force handling) when level transitions occur.

During runpm suspend/resume, the software forced level can remain profile mode, but HW-side stable pstate (and KFD profiler state) may be cleared by hw_fini/hw_init. That is why this restore is done after amdgpu_device_resume().

Moving this into swsmu late_init would apply the logic to broader flows (not only runpm), so I’d prefer to keep it in runpm resume.

Profile setting is a user level setting and it's not the default SOC behavior. During runtime PM, chip is in ~D3 state and some settings are lost. For proper restoration, all the steps that are followed for a regular user profile setting needs to be done (you don't need to go by the 'force' name). That is done in the logic here also - it's checking if the level is one of the forced dpm levels. To properly reapply, it needs to follow the same process.

This is followed in other user setting scenarios also. smu late init has a specific call to restore user setttings.

Thanks,
Lijo

Thanks, Lijo.
Good point - profile mode is user-level state and after runpm we should replay it through the same user-setting restore path, not only re-enable UMD stable pstate. I’ll move this logic into the swsmu late init restore flow (alongside user profile restoration) so profile reapply follows the same sequence as normal user profile programming. Then runtime-resume side will keep only kfd profiler restore hook.

Thanks,
Candice

Quoted 84 lines

Thanks,
Candice

Quoted 79 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -0
+
+       amdgpu_amdkfd_restore_profiler_after_runpm(adev);
+}
+
   static int amdgpu_pmops_runtime_resume(struct device *dev)  {
          struct pci_dev *pdev = to_pci_dev(dev); @@ -2964,6 +2979,8

@@ static int amdgpu_pmops_runtime_resume(struct device *dev)

          if (adev->pm.rpm_mode == AMDGPU_RUNPM_PX)
                  drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
+
+       amdgpu_restore_perf_state_after_runpm(adev);
          adev->in_runpm = false;
          return 0;
   }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -0
index 2c1a936459ac87..2a140c40b53f9c 100644
@@ -3347,6 +3347,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
          if (op == 1) {
                  if (!kfd->profiler_process) {
                          kfd->profiler_process = p;
+                       kfd->profiler_perfcount_enabled = false;
                          status = 0;
                          mutex_unlock(&kfd->profiler_lock);
                          if (ptl->hw_supported) { @@ -3364,6 +3365,7

@@ static inline uint32_t profile_lock_device(struct kfd_process *p,

                  }
          } else if (op == 0 && kfd->profiler_process == p) {
                  kfd->profiler_process = NULL;
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +7 -0
+               kfd->profiler_perfcount_enabled = false;
                  status = 0;
                  mutex_unlock(&kfd->profiler_lock);
@@ -3404,6 +3406,12 @@ static inline int kfd_profiler_pmc(struct kfd_process *p,
          mutex_unlock(&p->mutex);
 
          dqm->ops.set_perfcount(dqm, args->perfcount_enable);
+
+       mutex_lock(&pdd->dev->kfd->profiler_lock);
+       if (pdd->dev->kfd->profiler_process == p)
+               pdd->dev->kfd->profiler_perfcount_enabled = !!args->perfcount_enable;
+       mutex_unlock(&pdd->dev->kfd->profiler_lock);
+
          return status;
   }
 
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 88191a4c165796..81055ada4f80b8 100644
@@ -389,6 +389,8 @@ struct kfd_dev {
          struct mutex profiler_lock;
          /* Process currently holding the lock */
          struct kfd_process *profiler_process;
+       /* Whether perfcount is enabled for profiler_process */
+       bool profiler_perfcount_enabled;
   };
 
   enum kfd_mempool {
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
index eb508fe3ded780..8b7020fc0577a2 100644
@@ -1180,6 +1180,7 @@ static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_proce
          if (pdd->dev->kfd->profiler_process == p) {
                  pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
                  pdd->dev->kfd->profiler_process = NULL;
+               pdd->dev->kfd->profiler_perfcount_enabled = false;
          }
          mutex_unlock(&pdd->dev->kfd->profiler_lock);
   }
--

2.25.1

#9 lore raw

AMD General

The issue here is specific to runpm resume: SW still keeps the forced level, but D3 can drop perfmon-related HW programming, and during resume smu_late_init() is not the final step inside amdgpu_device_ip_late_init().

After smu_late_init(), amdgpu_device_ip_late_init() still executes global amdgpu_device_set_cg_state() / amdgpu_device_set_pg_state().

That is why this fix restores at the end of amdgpu_pmops_runtime_resume(): once resume programming is done, re-assert UMD/perfmon state if current level is profile-forced.

Thanks,
Candice

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, July 24, 2026 11:41 AM
To: Li, Candice <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: RE: [PATCH] drm/amdgpu: restore perf state after runtime resume

AMD General

Quoted 1 line

If we do this in smu_late_init(), later resume stages can still touch CG/PG/GC and clear PERFMON_CLOCK_STATE again, so the restore is not persistent.

If this happens, the check that user level is enforced is not correct (since it is not really enforced). The same could happen when a user applies force profile mode also. Basically, we need to prevent this for all other cases also. Where do you see this happening?

Thanks,
Lijo
-----Original Message-----
From: Li, Candice <[email protected]>
Sent: Friday, July 24, 2026 8:38 AM
To: Li, Candice <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: RE: [PATCH] drm/amdgpu: restore perf state after runtime resume

AMD General

Hi Lijo,

I want to revise my earlier agreement after rechecking the full runtime-resume flow.

I agree profile/forced DPM is a user policy and D3 can lose HW programming, but for this bug the key is restore timing.
If we do this in smu_late_init(), later resume stages can still touch CG/PG/GC and clear PERFMON_CLOCK_STATE again, so the restore is not persistent.

For that reason, I’d like to keep the original placement: restore at the end of amdgpu_pmops_runtime_resume(), and only re-assert UMD stable pstate when current level is a profile forced level. This keeps smu_late_init() for normal policy replay, while ensuring perfmon state is restored at a point where it is not overwritten afterward.

Thanks,
Candice

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Li, Candice
Sent: Thursday, July 23, 2026 2:16 PM
To: Lazar, Lijo <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: RE: [PATCH] drm/amdgpu: restore perf state after runtime resume

AMD General

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, July 23, 2026 11:46 AM
To: Li, Candice <[email protected]>; Zhang, Hawking <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: restore perf state after runtime resume

Quoted 149 lines · Candice

AMD General

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, July 22, 2026 8:11 PM
To: Zhang, Hawking <[email protected]>; Li, Candice <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: restore perf state after runtime resume

Quoted 116 lines · Hawking

AMD General

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Candice Li
Sent: Wednesday, July 22, 2026 6:36 PM
To: [email protected]
Cc: Li, Candice <[email protected]>
Subject: [PATCH] drm/amdgpu: restore perf state after runtime resume

Runtime suspend runs GFX hw_fini and clears perfmon clock gating while KFD keeps running, so block perf counters read zero after resume even though profiling remains enabled in software.

Re-apply UMD stable pstate for profile DPM modes and re-enable KFD perfcount after a successful runtime resume.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 46 ++++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 17 ++++++++
   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   |  8 ++++
   drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  2 +
   drivers/gpu/drm/amd/amdkfd/kfd_process.c   |  1 +
   6 files changed, 75 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -0
index 121282dd30c161..38974beb98ef88 100644
@@ -38,6 +38,7 @@
   #include "amdgpu_reset.h"
   #if IS_ENABLED(CONFIG_HSA_AMD)
   #include "kfd_priv.h"
+#include "kfd_device_queue_manager.h"
   #endif
 
   /* Total memory size in system memory and all GPU VRAM. Used to @@ -280,6 +281,51 @@ int amdgpu_amdkfd_resume(struct amdgpu_device *adev, bool resume_proc)
          return r;

}

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +44 -0
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev) { #if IS_ENABLED(CONFIG_HSA_AMD)
+       struct kfd_dev *kfd;
+       struct kfd_process *p;
+       struct kfd_process_device *pdd;
+       struct device_queue_manager *dqm;
+       int i;
+
+       if (!adev->kfd.dev || !adev->kfd.init_complete)
+               return;
+
+       kfd = adev->kfd.dev;
+
+       mutex_lock(&kfd->profiler_lock);
+       p = kfd->profiler_process;
+       if (!p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       mutex_lock(&p->mutex);
+
+       mutex_lock(&kfd->profiler_lock);
+       if (kfd->profiler_process != p || !kfd->profiler_perfcount_enabled) {
+               mutex_unlock(&kfd->profiler_lock);
+               mutex_unlock(&p->mutex);
+               return;
+       }
+       mutex_unlock(&kfd->profiler_lock);
+
+       for (i = 0; i < p->n_pdds; i++) {
+               pdd = p->pdds[i];
+               if (!pdd || !pdd->dev || pdd->dev->kfd != kfd)
+                       continue;
+
+               dqm = pdd->dev->dqm;
+               if (dqm && dqm->ops.set_perfcount)
+                       dqm->ops.set_perfcount(dqm, 1);
+       }
+       mutex_unlock(&p->mutex);
+#endif
+}
+
   void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev)  {
          if (adev->kfd.dev)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
index 338412a750edf0..1be9d5ef97d6d0 100644
@@ -164,6 +164,7 @@ void amdgpu_amdkfd_teardown_processes(struct
 amdgpu_device *adev);
 
   void amdgpu_amdkfd_suspend(struct amdgpu_device *adev, bool
 suspend_proc);  int amdgpu_amdkfd_resume(struct amdgpu_device *adev,
 bool resume_proc);
+void amdgpu_amdkfd_restore_profiler_after_runpm(struct amdgpu_device
+*adev);
   void amdgpu_amdkfd_suspend_process(struct amdgpu_device *adev);

int amdgpu_amdkfd_resume_process(struct amdgpu_device *adev); void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 5362705143bc75..f7a1064c340692 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
@@ -2920,6 +2920,21 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
          return 0;
   }
 
+static void amdgpu_restore_perf_state_after_runpm(struct
+amdgpu_device

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_suspend(struct device *dev) · line 2934

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +10 -0
+*adev) {
+       enum amd_dpm_forced_level level;
+       uint32_t profile_mode_mask = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
+               AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
+
+       level = amdgpu_dpm_get_performance_level(adev);
+       if (level & profile_mode_mask)
+               amdgpu_asic_update_umd_stable_pstate(adev, true);

This is supposed to be called before entering the force dpm level mode. It's better to move this logic inside swsmu late_init before reapplying the level.

Thanks,
Lijo

Thanks, Lijo.

Quoted 8 lines

I think this logic should remain in runtime resume. The amdgpu_asic_update_umd_stable_pstate(adev, true) call here is a restore/re-apply step for an already-selected profile forced level, not a force-level entry. Enter/exit behavior is already covered by the regular DPM force path (amdgpu_dpm_force_performance_level() / SMU force handling) when level transitions occur.

During runpm suspend/resume, the software forced level can remain profile mode, but HW-side stable pstate (and KFD profiler state) may be cleared by hw_fini/hw_init. That is why this restore is done after amdgpu_device_resume().

Moving this into swsmu late_init would apply the logic to broader flows (not only runpm), so I’d prefer to keep it in runpm resume.

Profile setting is a user level setting and it's not the default SOC behavior. During runtime PM, chip is in ~D3 state and some settings are lost. For proper restoration, all the steps that are followed for a regular user profile setting needs to be done (you don't need to go by the 'force' name). That is done in the logic here also - it's checking if the level is one of the forced dpm levels. To properly reapply, it needs to follow the same process.

This is followed in other user setting scenarios also. smu late init has a specific call to restore user setttings.

Thanks,
Lijo

Thanks, Lijo.
Good point - profile mode is user-level state and after runpm we should replay it through the same user-setting restore path, not only re-enable UMD stable pstate. I’ll move this logic into the swsmu late init restore flow (alongside user profile restoration) so profile reapply follows the same sequence as normal user profile programming. Then runtime-resume side will keep only kfd profiler restore hook.

Thanks,
Candice

Quoted 84 lines

Thanks,
Candice

Quoted 79 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -0
+
+       amdgpu_amdkfd_restore_profiler_after_runpm(adev);
+}
+
   static int amdgpu_pmops_runtime_resume(struct device *dev)  {
          struct pci_dev *pdev = to_pci_dev(dev); @@ -2964,6 +2979,8

@@ static int amdgpu_pmops_runtime_resume(struct device *dev)

          if (adev->pm.rpm_mode == AMDGPU_RUNPM_PX)
                  drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
+
+       amdgpu_restore_perf_state_after_runpm(adev);
          adev->in_runpm = false;
          return 0;
   }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -0
index 2c1a936459ac87..2a140c40b53f9c 100644
@@ -3347,6 +3347,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,
          if (op == 1) {
                  if (!kfd->profiler_process) {
                          kfd->profiler_process = p;
+                       kfd->profiler_perfcount_enabled = false;
                          status = 0;
                          mutex_unlock(&kfd->profiler_lock);
                          if (ptl->hw_supported) { @@ -3364,6 +3365,7

@@ static inline uint32_t profile_lock_device(struct kfd_process *p,

                  }
          } else if (op == 0 && kfd->profiler_process == p) {
                  kfd->profiler_process = NULL;
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +7 -0
+               kfd->profiler_perfcount_enabled = false;
                  status = 0;
                  mutex_unlock(&kfd->profiler_lock);
@@ -3404,6 +3406,12 @@ static inline int kfd_profiler_pmc(struct kfd_process *p,
          mutex_unlock(&p->mutex);
 
          dqm->ops.set_perfcount(dqm, args->perfcount_enable);
+
+       mutex_lock(&pdd->dev->kfd->profiler_lock);
+       if (pdd->dev->kfd->profiler_process == p)
+               pdd->dev->kfd->profiler_perfcount_enabled = !!args->perfcount_enable;
+       mutex_unlock(&pdd->dev->kfd->profiler_lock);
+
          return status;
   }
 
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 88191a4c165796..81055ada4f80b8 100644
@@ -389,6 +389,8 @@ struct kfd_dev {
          struct mutex profiler_lock;
          /* Process currently holding the lock */
          struct kfd_process *profiler_process;
+       /* Whether perfcount is enabled for profiler_process */
+       bool profiler_perfcount_enabled;
   };
 
   enum kfd_mempool {
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
index eb508fe3ded780..8b7020fc0577a2 100644
@@ -1180,6 +1180,7 @@ static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_proce
          if (pdd->dev->kfd->profiler_process == p) {
                  pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
                  pdd->dev->kfd->profiler_process = NULL;
+               pdd->dev->kfd->profiler_perfcount_enabled = false;
          }
          mutex_unlock(&pdd->dev->kfd->profiler_lock);
   }
--

2.25.1