Skip to contentSkip to conversation

drm/amdgpu/gfx: add ring helpers for setting workload profile

PATCH In review Alex Deucher 4 participants 13 messages Jan 8, 2025 – Jan 13, 2025

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/5 drm/amdgpu/gfx: add ring helpers for setting workload profile

Add helpers to switch the workload profile dynamically when commands are submitted. This allows us to switch to the FULLSCREEN3D or COMPUTE profile when work is submitted. Add a delayed work handler to delay switching out of the selected profile if additional work comes in. This works the same as the VIDEO profile for VCN. This lets dynamically enable workload profiles on the fly and then move back to the default when there is no work.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 57 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 11 +++++
 2 files changed, 68 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +57 -0
index 6d5d81f0dc4e7..c542617121393 100644
@@ -2110,6 +2110,63 @@ void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring)
 	mutex_unlock(&adev->enforce_isolation_mutex);
 }
 
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work)
+{
+	struct amdgpu_device *adev =
+		container_of(work, struct amdgpu_device, gfx.idle_work.work);
+	enum PP_SMC_POWER_PROFILE profile;
+	u32 i, fences = 0;
+	int r;
+
+	if (adev->gfx.num_gfx_rings)
+		profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+	else
+		profile = PP_SMC_POWER_PROFILE_COMPUTE;
+
+	for (i = 0; i < AMDGPU_MAX_GFX_RINGS; ++i)
+		fences += amdgpu_fence_count_emitted(&adev->gfx.gfx_ring[i]);
+	for (i = 0; i < (AMDGPU_MAX_COMPUTE_RINGS * AMDGPU_MAX_GC_INSTANCES); ++i)
+		fences += amdgpu_fence_count_emitted(&adev->gfx.compute_ring[i]);
+	if (!fences && !atomic_read(&adev->gfx.total_submission_cnt)) {
+		r = amdgpu_dpm_switch_power_profile(adev, profile, false);
+		if (r)
+			dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+				 profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+				 "fullscreen 3D" : "compute");
+	} else {
+		schedule_delayed_work(&adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+	}
+}
+
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
+{
+	struct amdgpu_device *adev = ring->adev;
+	enum PP_SMC_POWER_PROFILE profile;
+	int r;
+
+	if (adev->gfx.num_gfx_rings)
+		profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+	else
+		profile = PP_SMC_POWER_PROFILE_COMPUTE;
+
+	atomic_inc(&adev->gfx.total_submission_cnt);
+
+	if (!cancel_delayed_work_sync(&adev->gfx.idle_work)) {
+		r = amdgpu_dpm_switch_power_profile(adev, profile, true);
+		if (r)
+			dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+				 profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+				 "fullscreen 3D" : "compute");
+	}
+}
+
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring)
+{
+	atomic_dec(&ring->adev->gfx.total_submission_cnt);
+
+	schedule_delayed_work(&ring->adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+}
+
 /*
  * debugfs for to enable/disable gfx job submission to specific core.
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +11 -0
index 7f9e261f47f11..6c84598caec21 100644
@@ -57,6 +57,9 @@ enum amdgpu_gfx_pipe_priority {
 #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
 #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
+/* 1 second timeout */
+#define GFX_PROFILE_IDLE_TIMEOUT	msecs_to_jiffies(1000)
+
 enum amdgpu_gfx_partition {
 	AMDGPU_SPX_PARTITION_MODE = 0,
 	AMDGPU_DPX_PARTITION_MODE = 1,
@@ -477,6 +480,9 @@ struct amdgpu_gfx {
 	bool				kfd_sch_inactive[MAX_XCP];
 	unsigned long			enforce_isolation_jiffies[MAX_XCP];
 	unsigned long			enforce_isolation_time[MAX_XCP];
+
+	atomic_t			total_submission_cnt;
+	struct delayed_work		idle_work;
 };
 
 struct amdgpu_gfx_ras_reg_entry {
@@ -585,6 +591,11 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
 void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work);
 void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring);
 void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);
+
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work);
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring);
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring);
+
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
Signature · 1 line
2.47.1
author maintainer
#1 lore raw

PATCH 2/5 drm/amdgpu: add dynamic workload profile switching for gfx10

Enable dynamic workload profile switching for gfx10.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +22 -4
index 2b3b3f5ffb611..37eab608449ca 100644
@@ -4701,6 +4701,8 @@ static int gfx_v10_0_sw_init(struct amdgpu_ip_block *ip_block)
 	int xcc_id = 0;
 	struct amdgpu_device *adev = ip_block->adev;
 
+	INIT_DELAYED_WORK(&adev->gfx.idle_work, amdgpu_gfx_profile_idle_work_handler);
+
 	switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
 	case IP_VERSION(10, 1, 10):
 	case IP_VERSION(10, 1, 1):
@@ -7467,6 +7469,8 @@ static int gfx_v10_0_hw_fini(struct amdgpu_ip_block *ip_block)
 {
 	struct amdgpu_device *adev = ip_block->adev;
 
+	cancel_delayed_work_sync(&adev->gfx.idle_work);
+
 	amdgpu_irq_put(adev, &adev->gfx.priv_reg_irq, 0);
 	amdgpu_irq_put(adev, &adev->gfx.priv_inst_irq, 0);
 	amdgpu_irq_put(adev, &adev->gfx.bad_op_irq, 0);
@@ -9748,6 +9752,20 @@ static void gfx_v10_0_ring_emit_cleaner_shader(struct amdgpu_ring *ring)
 	amdgpu_ring_write(ring, 0);  /* RESERVED field, programmed to zero */
 }
 
+static void gfx_v10_0_ring_begin_use(struct amdgpu_ring *ring)
+{
+	amdgpu_gfx_profile_ring_begin_use(ring);
+
+	amdgpu_gfx_enforce_isolation_ring_begin_use(ring);
+}
+
+static void gfx_v10_0_ring_end_use(struct amdgpu_ring *ring)
+{
+	amdgpu_gfx_profile_ring_end_use(ring);
+
+	amdgpu_gfx_enforce_isolation_ring_end_use(ring);
+}
+
 static const struct amd_ip_funcs gfx_v10_0_ip_funcs = {
 	.name = "gfx_v10_0",
 	.early_init = gfx_v10_0_early_init,
@@ -9823,8 +9841,8 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = {
 	.emit_mem_sync = gfx_v10_0_emit_mem_sync,
 	.reset = gfx_v10_0_reset_kgq,
 	.emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,
-	.begin_use = amdgpu_gfx_enforce_isolation_ring_begin_use,
-	.end_use = amdgpu_gfx_enforce_isolation_ring_end_use,
+	.begin_use = gfx_v10_0_ring_begin_use,
+	.end_use = gfx_v10_0_ring_end_use,
 };
 
 static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_compute = {
@@ -9864,8 +9882,8 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_compute = {
 	.emit_mem_sync = gfx_v10_0_emit_mem_sync,
 	.reset = gfx_v10_0_reset_kcq,
 	.emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,
-	.begin_use = amdgpu_gfx_enforce_isolation_ring_begin_use,
-	.end_use = amdgpu_gfx_enforce_isolation_ring_end_use,
+	.begin_use = gfx_v10_0_ring_begin_use,
+	.end_use = gfx_v10_0_ring_end_use,
 };
 
 static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_kiq = {
Signature · 1 line
2.47.1
author maintainer
#2 lore raw

PATCH 3/5 drm/amdgpu: add dynamic workload profile switching for gfx11

In reply to Alex Deucher

Enable dynamic workload profile switching for gfx11.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +22 -4
index dbc82037c4ab9..86310741647b5 100644
@@ -1561,6 +1561,8 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
 	int xcc_id = 0;
 	struct amdgpu_device *adev = ip_block->adev;
 
+	INIT_DELAYED_WORK(&adev->gfx.idle_work, amdgpu_gfx_profile_idle_work_handler);
+
 	switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
 	case IP_VERSION(11, 0, 0):
 	case IP_VERSION(11, 0, 2):
@@ -4762,6 +4764,8 @@ static int gfx_v11_0_hw_fini(struct amdgpu_ip_block *ip_block)
 {
 	struct amdgpu_device *adev = ip_block->adev;
 
+	cancel_delayed_work_sync(&adev->gfx.idle_work);
+
 	amdgpu_irq_put(adev, &adev->gfx.priv_reg_irq, 0);
 	amdgpu_irq_put(adev, &adev->gfx.priv_inst_irq, 0);
 	amdgpu_irq_put(adev, &adev->gfx.bad_op_irq, 0);
@@ -6852,6 +6856,20 @@ static void gfx_v11_0_ring_emit_cleaner_shader(struct amdgpu_ring *ring)
 	amdgpu_ring_write(ring, 0);  /* RESERVED field, programmed to zero */
 }
 
+static void gfx_v11_0_ring_begin_use(struct amdgpu_ring *ring)
+{
+	amdgpu_gfx_profile_ring_begin_use(ring);
+
+	amdgpu_gfx_enforce_isolation_ring_begin_use(ring);
+}
+
+static void gfx_v11_0_ring_end_use(struct amdgpu_ring *ring)
+{
+	amdgpu_gfx_profile_ring_end_use(ring);
+
+	amdgpu_gfx_enforce_isolation_ring_end_use(ring);
+}
+
 static const struct amd_ip_funcs gfx_v11_0_ip_funcs = {
 	.name = "gfx_v11_0",
 	.early_init = gfx_v11_0_early_init,
@@ -6926,8 +6944,8 @@ static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_gfx = {
 	.emit_mem_sync = gfx_v11_0_emit_mem_sync,
 	.reset = gfx_v11_0_reset_kgq,
 	.emit_cleaner_shader = gfx_v11_0_ring_emit_cleaner_shader,
-	.begin_use = amdgpu_gfx_enforce_isolation_ring_begin_use,
-	.end_use = amdgpu_gfx_enforce_isolation_ring_end_use,
+	.begin_use = gfx_v11_0_ring_begin_use,
+	.end_use = gfx_v11_0_ring_end_use,
 };
 
 static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_compute = {
@@ -6968,8 +6986,8 @@ static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_compute = {
 	.emit_mem_sync = gfx_v11_0_emit_mem_sync,
 	.reset = gfx_v11_0_reset_kcq,
 	.emit_cleaner_shader = gfx_v11_0_ring_emit_cleaner_shader,
-	.begin_use = amdgpu_gfx_enforce_isolation_ring_begin_use,
-	.end_use = amdgpu_gfx_enforce_isolation_ring_end_use,
+	.begin_use = gfx_v11_0_ring_begin_use,
+	.end_use = gfx_v11_0_ring_end_use,
 };
 
 static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_kiq = {
Signature · 1 line
2.47.1
author maintainer
#3 lore raw

PATCH 4/5 drm/amdgpu: add dynamic workload profile switching for gfx12

In reply to Alex Deucher

Enable dynamic workload profile switching for gfx12.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +22 -4
index 3aa34c55554d1..9720e8fe46572 100644
@@ -1362,6 +1362,8 @@ static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block)
 	int xcc_id = 0;
 	struct amdgpu_device *adev = ip_block->adev;
 
+	INIT_DELAYED_WORK(&adev->gfx.idle_work, amdgpu_gfx_profile_idle_work_handler);
+
 	switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
 	case IP_VERSION(12, 0, 0):
 	case IP_VERSION(12, 0, 1):
@@ -3676,6 +3678,8 @@ static int gfx_v12_0_hw_fini(struct amdgpu_ip_block *ip_block)
 	struct amdgpu_device *adev = ip_block->adev;
 	uint32_t tmp;
 
+	cancel_delayed_work_sync(&adev->gfx.idle_work);
+
 	amdgpu_irq_put(adev, &adev->gfx.priv_reg_irq, 0);
 	amdgpu_irq_put(adev, &adev->gfx.priv_inst_irq, 0);
 	amdgpu_irq_put(adev, &adev->gfx.bad_op_irq, 0);
@@ -5317,6 +5321,20 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring, unsigned int vmid)
 	return amdgpu_ring_test_ring(ring);
 }
 
+static void gfx_v12_0_ring_begin_use(struct amdgpu_ring *ring)
+{
+	amdgpu_gfx_profile_ring_begin_use(ring);
+
+	amdgpu_gfx_enforce_isolation_ring_begin_use(ring);
+}
+
+static void gfx_v12_0_ring_end_use(struct amdgpu_ring *ring)
+{
+	amdgpu_gfx_profile_ring_end_use(ring);
+
+	amdgpu_gfx_enforce_isolation_ring_end_use(ring);
+}
+
 static const struct amd_ip_funcs gfx_v12_0_ip_funcs = {
 	.name = "gfx_v12_0",
 	.early_init = gfx_v12_0_early_init,
@@ -5382,8 +5400,8 @@ static const struct amdgpu_ring_funcs gfx_v12_0_ring_funcs_gfx = {
 	.emit_mem_sync = gfx_v12_0_emit_mem_sync,
 	.reset = gfx_v12_0_reset_kgq,
 	.emit_cleaner_shader = gfx_v12_0_ring_emit_cleaner_shader,
-	.begin_use = amdgpu_gfx_enforce_isolation_ring_begin_use,
-	.end_use = amdgpu_gfx_enforce_isolation_ring_end_use,
+	.begin_use = gfx_v12_0_ring_begin_use,
+	.end_use = gfx_v12_0_ring_end_use,
 };
 
 static const struct amdgpu_ring_funcs gfx_v12_0_ring_funcs_compute = {
@@ -5421,8 +5439,8 @@ static const struct amdgpu_ring_funcs gfx_v12_0_ring_funcs_compute = {
 	.emit_mem_sync = gfx_v12_0_emit_mem_sync,
 	.reset = gfx_v12_0_reset_kcq,
 	.emit_cleaner_shader = gfx_v12_0_ring_emit_cleaner_shader,
-	.begin_use = amdgpu_gfx_enforce_isolation_ring_begin_use,
-	.end_use = amdgpu_gfx_enforce_isolation_ring_end_use,
+	.begin_use = gfx_v12_0_ring_begin_use,
+	.end_use = gfx_v12_0_ring_end_use,
 };
 
 static const struct amdgpu_ring_funcs gfx_v12_0_ring_funcs_kiq = {
Signature · 1 line
2.47.1
author maintainer
#4 lore raw

PATCH 5/5 drm/amdgpu/swsmu: set workload profile to bootup default

In reply to Alex Deucher

Now that we can select a workload profile dynamically when we submit work, it's best to default to the bootup default workload profile. Defaulting to other profiles prevents some power management features from kicking in during idle periods. Once all jobs have finished, the workload profile will automatically move back to default bootup for max power savings.

---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 21 +++----------------
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  |  1 -
 2 files changed, 3 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -18
index 8ca793c222ff2..671a44bf5ba56 100644
@@ -1251,26 +1251,11 @@ static void smu_init_xgmi_plpd_mode(struct smu_context *smu)
 	}
 }
 
-static bool smu_is_workload_profile_available(struct smu_context *smu,
-					      u32 profile)
-{
-	if (profile >= PP_SMC_POWER_PROFILE_COUNT)
-		return false;
-	return smu->workload_map && smu->workload_map[profile].valid_mapping;
-}
-
 static void smu_init_power_profile(struct smu_context *smu)
 {
-	if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_UNKNOWN) {
-		if (smu->is_apu ||
-		    !smu_is_workload_profile_available(
-			    smu, PP_SMC_POWER_PROFILE_FULLSCREEN3D))
-			smu->power_profile_mode =
-				PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
-		else
-			smu->power_profile_mode =
-				PP_SMC_POWER_PROFILE_FULLSCREEN3D;
-	}
+	if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_UNKNOWN)
+		smu->power_profile_mode =
+			PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
 	smu_power_profile_mode_get(smu, smu->power_profile_mode);
 }
 
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0 -1
index 55ef18517b0fc..19f47811f6db2 100644
@@ -2811,5 +2811,4 @@ void smu_v13_0_7_set_ppt_funcs(struct smu_context *smu)
 	smu->workload_map = smu_v13_0_7_workload_map;
 	smu->smc_driver_if_version = SMU13_0_7_DRIVER_IF_VERSION;
 	smu_v13_0_set_smu_mailbox_registers(smu);
-	smu->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
 }
Signature · 1 line
2.47.1
maintainer
#5 lore raw
In reply to Alex Deucher

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Thursday, January 9, 2025 6:56 AM
To: [email protected]
Cc: Pillai, Aurabindo <[email protected]>; Feng, Kenneth <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH 1/5] drm/amdgpu/gfx: add ring helpers for setting workload profile

Add helpers to switch the workload profile dynamically when commands are submitted. This allows us to switch to the FULLSCREEN3D or COMPUTE profile when work is submitted.
Add a delayed work handler to delay switching out of the selected profile if additional work comes in. This works the same as the VIDEO profile for VCN. This lets dynamically enable workload profiles on the fly and then move back to the default when there is no work.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 57 +++++++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 11 +++++
 2 files changed, 68 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +11 -0
index 6d5d81f0dc4e7..c542617121393 100644
@@ -2110,6 +2110,63 @@ void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring)
        mutex_unlock(&adev->enforce_isolation_mutex);
 }
 
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work) {
+       struct amdgpu_device *adev =
+               container_of(work, struct amdgpu_device, gfx.idle_work.work);
+       enum PP_SMC_POWER_PROFILE profile;
+       u32 i, fences = 0;
+       int r;
+
+       if (adev->gfx.num_gfx_rings)
+               profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+       else
+               profile = PP_SMC_POWER_PROFILE_COMPUTE;
 
 

[Kenneth] - there is KFD code amdgpu_amdkfd_set_compute_idle() to manage the compute workload, is it necessary to control compute workload here?

+
+ for (i = 0; i < AMDGPU_MAX_GFX_RINGS; ++i)
+ fences += amdgpu_fence_count_emitted(&adev->gfx.gfx_ring[i]);
+ for (i = 0; i < (AMDGPU_MAX_COMPUTE_RINGS * AMDGPU_MAX_GC_INSTANCES); ++i)
+ fences += amdgpu_fence_count_emitted(&adev->gfx.compute_ring[i]);
+ if (!fences && !atomic_read(&adev->gfx.total_submission_cnt)) {
+ r = amdgpu_dpm_switch_power_profile(adev, profile, false);
+ if (r)
+ dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+ profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+ "fullscreen 3D" : "compute");
+ } else {
+ schedule_delayed_work(&adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+ }
+}
+
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring) {

+       struct amdgpu_device *adev = ring->adev;
+       enum PP_SMC_POWER_PROFILE profile;
+       int r;

+
+ if (adev->gfx.num_gfx_rings)
+ profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+ else
+ profile = PP_SMC_POWER_PROFILE_COMPUTE;
+
+ atomic_inc(&adev->gfx.total_submission_cnt);
+
+ if (!cancel_delayed_work_sync(&adev->gfx.idle_work)) {
+ r = amdgpu_dpm_switch_power_profile(adev, profile, true);
+ if (r)
+ dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+ profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+ "fullscreen 3D" : "compute");
+ }
+}
+
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring) {
+ atomic_dec(&ring->adev->gfx.total_submission_cnt);
+
+ schedule_delayed_work(&ring->adev->gfx.idle_work,
+GFX_PROFILE_IDLE_TIMEOUT); }
+
/*
* debugfs for to enable/disable gfx job submission to specific core. */

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +11 -1
index 7f9e261f47f11..6c84598caec21 100644
@@ -57,6 +57,9 @@ enum amdgpu_gfx_pipe_priority {  #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0  #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
+/* 1 second timeout */
+#define GFX_PROFILE_IDLE_TIMEOUT       msecs_to_jiffies(1000)
+
 enum amdgpu_gfx_partition {
        AMDGPU_SPX_PARTITION_MODE = 0,
        AMDGPU_DPX_PARTITION_MODE = 1,
@@ -477,6 +480,9 @@ struct amdgpu_gfx {
        bool                            kfd_sch_inactive[MAX_XCP];
        unsigned long                   enforce_isolation_jiffies[MAX_XCP];
        unsigned long                   enforce_isolation_time[MAX_XCP];
+
+       atomic_t                        total_submission_cnt;
+       struct delayed_work             idle_work;
 };
 
 struct amdgpu_gfx_ras_reg_entry {
@@ -585,6 +591,11 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,  void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work);  void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring);  void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);
+
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work);
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring); void
+amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring);
+
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);  void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
--

2.47.1

#6 lore raw
Quoted 39 lines · Kenneth

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Thursday, January 9, 2025 6:56 AM
To: [email protected]
Cc: Pillai, Aurabindo <[email protected]>; Feng, Kenneth <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH 1/5] drm/amdgpu/gfx: add ring helpers for setting workload profile

Add helpers to switch the workload profile dynamically when commands are submitted. This allows us to switch to the FULLSCREEN3D or COMPUTE profile when work is submitted.
Add a delayed work handler to delay switching out of the selected profile if additional work comes in. This works the same as the VIDEO profile for VCN. This lets dynamically enable workload profiles on the fly and then move back to the default when there is no work.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 57 +++++++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 11 +++++
 2 files changed, 68 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +11 -0
index 6d5d81f0dc4e7..c542617121393 100644
@@ -2110,6 +2110,63 @@ void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring)
        mutex_unlock(&adev->enforce_isolation_mutex);
 }
 
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work) {
+       struct amdgpu_device *adev =
+               container_of(work, struct amdgpu_device, gfx.idle_work.work);
+       enum PP_SMC_POWER_PROFILE profile;
+       u32 i, fences = 0;
+       int r;
+
+       if (adev->gfx.num_gfx_rings)
+               profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+       else
+               profile = PP_SMC_POWER_PROFILE_COMPUTE;
 
 
Quoted 1 line

[Kenneth] - there is KFD code amdgpu_amdkfd_set_compute_idle() to manage the compute workload, is it necessary to control compute workload here?

This only adjusts submissions to kernel queues. If there are no KFD user queues, then we wouldn't set the compute profile. Also, at the moment, I've only enabled this for gfx10 and newer.

Alex

Quoted 80 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +43 -0
+
+       for (i = 0; i < AMDGPU_MAX_GFX_RINGS; ++i)
+               fences += amdgpu_fence_count_emitted(&adev->gfx.gfx_ring[i]);
+       for (i = 0; i < (AMDGPU_MAX_COMPUTE_RINGS * AMDGPU_MAX_GC_INSTANCES); ++i)
+               fences += amdgpu_fence_count_emitted(&adev->gfx.compute_ring[i]);
+       if (!fences && !atomic_read(&adev->gfx.total_submission_cnt)) {
+               r = amdgpu_dpm_switch_power_profile(adev, profile, false);
+               if (r)
+                       dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+                                profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+                                "fullscreen 3D" : "compute");
+       } else {
+               schedule_delayed_work(&adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+       }
+}
+
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring) {
+       struct amdgpu_device *adev = ring->adev;
+       enum PP_SMC_POWER_PROFILE profile;
+       int r;
+
+       if (adev->gfx.num_gfx_rings)
+               profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+       else
+               profile = PP_SMC_POWER_PROFILE_COMPUTE;
+
+       atomic_inc(&adev->gfx.total_submission_cnt);
+
+       if (!cancel_delayed_work_sync(&adev->gfx.idle_work)) {
+               r = amdgpu_dpm_switch_power_profile(adev, profile, true);
+               if (r)
+                       dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+                                profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+                                "fullscreen 3D" : "compute");
+       }
+}
+
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring) {
+       atomic_dec(&ring->adev->gfx.total_submission_cnt);
+
+       schedule_delayed_work(&ring->adev->gfx.idle_work,
+GFX_PROFILE_IDLE_TIMEOUT); }
+
 /*
  * debugfs for to enable/disable gfx job submission to specific core.
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +11 -1
index 7f9e261f47f11..6c84598caec21 100644
@@ -57,6 +57,9 @@ enum amdgpu_gfx_pipe_priority {  #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0  #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
+/* 1 second timeout */
+#define GFX_PROFILE_IDLE_TIMEOUT       msecs_to_jiffies(1000)
+
 enum amdgpu_gfx_partition {
        AMDGPU_SPX_PARTITION_MODE = 0,
        AMDGPU_DPX_PARTITION_MODE = 1,
@@ -477,6 +480,9 @@ struct amdgpu_gfx {
        bool                            kfd_sch_inactive[MAX_XCP];
        unsigned long                   enforce_isolation_jiffies[MAX_XCP];
        unsigned long                   enforce_isolation_time[MAX_XCP];
+
+       atomic_t                        total_submission_cnt;
+       struct delayed_work             idle_work;
 };
 
 struct amdgpu_gfx_ras_reg_entry {
@@ -585,6 +591,11 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,  void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work);  void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring);  void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);
+
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work);
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring); void
+amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring);
+
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);  void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
--

2.47.1

#7 lore raw
In reply to Alex Deucher
Quoted 25 lines · Alex Deucher

Add helpers to switch the workload profile dynamically when commands are submitted. This allows us to switch to the FULLSCREEN3D or COMPUTE profile when work is submitted. Add a delayed work handler to delay switching out of the selected profile if additional work comes in. This works the same as the VIDEO profile for VCN. This lets dynamically enable workload profiles on the fly and then move back to the default when there is no work.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 57 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 11 +++++
 2 files changed, 68 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +2 -0
index 6d5d81f0dc4e7..c542617121393 100644
@@ -2110,6 +2110,63 @@ void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring)
 	mutex_unlock(&adev->enforce_isolation_mutex);
 }
 
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work)
+{

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring) · line 2124

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10 -0
+	struct amdgpu_device *adev =
+		container_of(work, struct amdgpu_device, gfx.idle_work.work);
+	enum PP_SMC_POWER_PROFILE profile;
+	u32 i, fences = 0;
+	int r;
+
+	if (adev->gfx.num_gfx_rings)
+		profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+	else
+		profile = PP_SMC_POWER_PROFILE_COMPUTE;

Since profile selection is in generic code, it makes sense to first check if the profile is supported for the family. Otherwise, this needs to be passed by the respective GFX family.

Thanks,
Lijo

Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +45 -0
+
+	for (i = 0; i < AMDGPU_MAX_GFX_RINGS; ++i)
+		fences += amdgpu_fence_count_emitted(&adev->gfx.gfx_ring[i]);
+	for (i = 0; i < (AMDGPU_MAX_COMPUTE_RINGS * AMDGPU_MAX_GC_INSTANCES); ++i)
+		fences += amdgpu_fence_count_emitted(&adev->gfx.compute_ring[i]);
+	if (!fences && !atomic_read(&adev->gfx.total_submission_cnt)) {
+		r = amdgpu_dpm_switch_power_profile(adev, profile, false);
+		if (r)
+			dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+				 profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+				 "fullscreen 3D" : "compute");
+	} else {
+		schedule_delayed_work(&adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+	}
+}
+
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
+{
+	struct amdgpu_device *adev = ring->adev;
+	enum PP_SMC_POWER_PROFILE profile;
+	int r;
+
+	if (adev->gfx.num_gfx_rings)
+		profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+	else
+		profile = PP_SMC_POWER_PROFILE_COMPUTE;
+
+	atomic_inc(&adev->gfx.total_submission_cnt);
+
+	if (!cancel_delayed_work_sync(&adev->gfx.idle_work)) {
+		r = amdgpu_dpm_switch_power_profile(adev, profile, true);
+		if (r)
+			dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+				 profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+				 "fullscreen 3D" : "compute");
+	}
+}
+
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring)
+{
+	atomic_dec(&ring->adev->gfx.total_submission_cnt);
+
+	schedule_delayed_work(&ring->adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+}
+
 /*
  * debugfs for to enable/disable gfx job submission to specific core.
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +11 -0
index 7f9e261f47f11..6c84598caec21 100644
@@ -57,6 +57,9 @@ enum amdgpu_gfx_pipe_priority {
 #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
 #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
+/* 1 second timeout */
+#define GFX_PROFILE_IDLE_TIMEOUT	msecs_to_jiffies(1000)
+
 enum amdgpu_gfx_partition {
 	AMDGPU_SPX_PARTITION_MODE = 0,
 	AMDGPU_DPX_PARTITION_MODE = 1,
@@ -477,6 +480,9 @@ struct amdgpu_gfx {
 	bool				kfd_sch_inactive[MAX_XCP];
 	unsigned long			enforce_isolation_jiffies[MAX_XCP];
 	unsigned long			enforce_isolation_time[MAX_XCP];
+
+	atomic_t			total_submission_cnt;
+	struct delayed_work		idle_work;
 };
 
 struct amdgpu_gfx_ras_reg_entry {
@@ -585,6 +591,11 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
 void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work);
 void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring);
 void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);
+
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work);
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring);
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring);
+
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
#8 lore raw
Quoted 27 lines · Lijo
Quoted 23 lines · Alex Deucher

Add helpers to switch the workload profile dynamically when commands are submitted. This allows us to switch to the FULLSCREEN3D or COMPUTE profile when work is submitted. Add a delayed work handler to delay switching out of the selected profile if additional work comes in. This works the same as the VIDEO profile for VCN. This lets dynamically enable workload profiles on the fly and then move back to the default when there is no work.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 57 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 11 +++++
 2 files changed, 68 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
index 6d5d81f0dc4e7..c542617121393 100644
@@ -2110,6 +2110,63 @@ void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring)
      mutex_unlock(&adev->enforce_isolation_mutex);
 }
 
Quoted 16 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring) · line 2124

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +12 -0
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work)
+{
+     struct amdgpu_device *adev =
+             container_of(work, struct amdgpu_device, gfx.idle_work.work);
+     enum PP_SMC_POWER_PROFILE profile;
+     u32 i, fences = 0;
+     int r;
+
+     if (adev->gfx.num_gfx_rings)
+             profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+     else
+             profile = PP_SMC_POWER_PROFILE_COMPUTE;

Since profile selection is in generic code, it makes sense to first check if the profile is supported for the family. Otherwise, this needs to be passed by the respective GFX family.

The generic code already handles this. If you select an unsupported profile, it's ignored when the mask is updated.

Alex

Quoted 89 lines

Thanks,
Lijo

Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +45 -0
+
+     for (i = 0; i < AMDGPU_MAX_GFX_RINGS; ++i)
+             fences += amdgpu_fence_count_emitted(&adev->gfx.gfx_ring[i]);
+     for (i = 0; i < (AMDGPU_MAX_COMPUTE_RINGS * AMDGPU_MAX_GC_INSTANCES); ++i)
+             fences += amdgpu_fence_count_emitted(&adev->gfx.compute_ring[i]);
+     if (!fences && !atomic_read(&adev->gfx.total_submission_cnt)) {
+             r = amdgpu_dpm_switch_power_profile(adev, profile, false);
+             if (r)
+                     dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+                              profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+                              "fullscreen 3D" : "compute");
+     } else {
+             schedule_delayed_work(&adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+     }
+}
+
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
+{
+     struct amdgpu_device *adev = ring->adev;
+     enum PP_SMC_POWER_PROFILE profile;
+     int r;
+
+     if (adev->gfx.num_gfx_rings)
+             profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+     else
+             profile = PP_SMC_POWER_PROFILE_COMPUTE;
+
+     atomic_inc(&adev->gfx.total_submission_cnt);
+
+     if (!cancel_delayed_work_sync(&adev->gfx.idle_work)) {
+             r = amdgpu_dpm_switch_power_profile(adev, profile, true);
+             if (r)
+                     dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+                              profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+                              "fullscreen 3D" : "compute");
+     }
+}
+
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring)
+{
+     atomic_dec(&ring->adev->gfx.total_submission_cnt);
+
+     schedule_delayed_work(&ring->adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+}
+
 /*
  * debugfs for to enable/disable gfx job submission to specific core.
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +11 -0
index 7f9e261f47f11..6c84598caec21 100644
@@ -57,6 +57,9 @@ enum amdgpu_gfx_pipe_priority {
 #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
 #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
+/* 1 second timeout */
+#define GFX_PROFILE_IDLE_TIMEOUT     msecs_to_jiffies(1000)
+
 enum amdgpu_gfx_partition {
      AMDGPU_SPX_PARTITION_MODE = 0,
      AMDGPU_DPX_PARTITION_MODE = 1,
@@ -477,6 +480,9 @@ struct amdgpu_gfx {
      bool                            kfd_sch_inactive[MAX_XCP];
      unsigned long                   enforce_isolation_jiffies[MAX_XCP];
      unsigned long                   enforce_isolation_time[MAX_XCP];
+
+     atomic_t                        total_submission_cnt;
+     struct delayed_work             idle_work;
 };
 
 struct amdgpu_gfx_ras_reg_entry {
@@ -585,6 +591,11 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
 void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work);
 void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring);
 void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);
+
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work);
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring);
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring);
+
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
#9 lore raw
Quoted 45 lines · Alex Deucher
Quoted 27 lines · Lijo
Quoted 23 lines · Alex Deucher

Add helpers to switch the workload profile dynamically when commands are submitted. This allows us to switch to the FULLSCREEN3D or COMPUTE profile when work is submitted. Add a delayed work handler to delay switching out of the selected profile if additional work comes in. This works the same as the VIDEO profile for VCN. This lets dynamically enable workload profiles on the fly and then move back to the default when there is no work.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 57 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 11 +++++
 2 files changed, 68 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
index 6d5d81f0dc4e7..c542617121393 100644
@@ -2110,6 +2110,63 @@ void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring)
      mutex_unlock(&adev->enforce_isolation_mutex);
 }
 
Quoted 16 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring) · line 2124

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +12 -0
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work)
+{
+     struct amdgpu_device *adev =
+             container_of(work, struct amdgpu_device, gfx.idle_work.work);
+     enum PP_SMC_POWER_PROFILE profile;
+     u32 i, fences = 0;
+     int r;
+
+     if (adev->gfx.num_gfx_rings)
+             profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+     else
+             profile = PP_SMC_POWER_PROFILE_COMPUTE;

Since profile selection is in generic code, it makes sense to first check if the profile is supported for the family. Otherwise, this needs to be passed by the respective GFX family.

Quoted 3 lines

The generic code already handles this. If you select an unsupported profile, it's ignored when the mask is updated.

That is strange. Does that mean user never gets an error if user attempts to set an unsupported profile?

Another problem is this could override the user set profile now. Is that intended? In the current logic, whenever user sets a profile, the current profile is removed. With this one, another profile gets added and the user preference could be ignored depending on the priority.

Thanks,
Lijo

Quoted 91 lines

Alex

Quoted 89 lines

Thanks,
Lijo

Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +45 -0
+
+     for (i = 0; i < AMDGPU_MAX_GFX_RINGS; ++i)
+             fences += amdgpu_fence_count_emitted(&adev->gfx.gfx_ring[i]);
+     for (i = 0; i < (AMDGPU_MAX_COMPUTE_RINGS * AMDGPU_MAX_GC_INSTANCES); ++i)
+             fences += amdgpu_fence_count_emitted(&adev->gfx.compute_ring[i]);
+     if (!fences && !atomic_read(&adev->gfx.total_submission_cnt)) {
+             r = amdgpu_dpm_switch_power_profile(adev, profile, false);
+             if (r)
+                     dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+                              profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+                              "fullscreen 3D" : "compute");
+     } else {
+             schedule_delayed_work(&adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+     }
+}
+
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
+{
+     struct amdgpu_device *adev = ring->adev;
+     enum PP_SMC_POWER_PROFILE profile;
+     int r;
+
+     if (adev->gfx.num_gfx_rings)
+             profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+     else
+             profile = PP_SMC_POWER_PROFILE_COMPUTE;
+
+     atomic_inc(&adev->gfx.total_submission_cnt);
+
+     if (!cancel_delayed_work_sync(&adev->gfx.idle_work)) {
+             r = amdgpu_dpm_switch_power_profile(adev, profile, true);
+             if (r)
+                     dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+                              profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+                              "fullscreen 3D" : "compute");
+     }
+}
+
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring)
+{
+     atomic_dec(&ring->adev->gfx.total_submission_cnt);
+
+     schedule_delayed_work(&ring->adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+}
+
 /*
  * debugfs for to enable/disable gfx job submission to specific core.
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +11 -0
index 7f9e261f47f11..6c84598caec21 100644
@@ -57,6 +57,9 @@ enum amdgpu_gfx_pipe_priority {
 #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
 #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
+/* 1 second timeout */
+#define GFX_PROFILE_IDLE_TIMEOUT     msecs_to_jiffies(1000)
+
 enum amdgpu_gfx_partition {
      AMDGPU_SPX_PARTITION_MODE = 0,
      AMDGPU_DPX_PARTITION_MODE = 1,
@@ -477,6 +480,9 @@ struct amdgpu_gfx {
      bool                            kfd_sch_inactive[MAX_XCP];
      unsigned long                   enforce_isolation_jiffies[MAX_XCP];
      unsigned long                   enforce_isolation_time[MAX_XCP];
+
+     atomic_t                        total_submission_cnt;
+     struct delayed_work             idle_work;
 };
 
 struct amdgpu_gfx_ras_reg_entry {
@@ -585,6 +591,11 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
 void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work);
 void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring);
 void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);
+
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work);
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring);
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring);
+
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
#10 lore raw
Quoted 49 lines · Lijo
Quoted 45 lines · Alex Deucher
Quoted 43 lines · Lijo
Quoted 25 lines · Alex Deucher

Add helpers to switch the workload profile dynamically when commands are submitted. This allows us to switch to the FULLSCREEN3D or COMPUTE profile when work is submitted. Add a delayed work handler to delay switching out of the selected profile if additional work comes in. This works the same as the VIDEO profile for VCN. This lets dynamically enable workload profiles on the fly and then move back to the default when there is no work.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 57 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 11 +++++
 2 files changed, 68 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +2 -0
index 6d5d81f0dc4e7..c542617121393 100644
@@ -2110,6 +2110,63 @@ void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring)
      mutex_unlock(&adev->enforce_isolation_mutex);
 }
 
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work)
+{

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring) · line 2124

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10 -0
+     struct amdgpu_device *adev =
+             container_of(work, struct amdgpu_device, gfx.idle_work.work);
+     enum PP_SMC_POWER_PROFILE profile;
+     u32 i, fences = 0;
+     int r;
+
+     if (adev->gfx.num_gfx_rings)
+             profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+     else
+             profile = PP_SMC_POWER_PROFILE_COMPUTE;

Since profile selection is in generic code, it makes sense to first check if the profile is supported for the family. Otherwise, this needs to be passed by the respective GFX family.

Quoted 6 lines
Quoted 3 lines

The generic code already handles this. If you select an unsupported profile, it's ignored when the mask is updated.

That is strange. Does that mean user never gets an error if user attempts to set an unsupported profile?

If you use sysfs, you can only select from the available options supported by the chip so there is no way to select a non-supported profile. For the internal driver API, we just silently ignore it.

Quoted 5 lines

Another problem is this could override the user set profile now. Is that intended? In the current logic, whenever user sets a profile, the current profile is removed. With this one, another profile gets added and the user preference could be ignored depending on the priority.

Yes, I think. For VCN we already select the video profile in a similar manner and for ROCm we already select the compute profile, this just extends that to gfx. This doesn't really change the behavior compared to the current state of the driver. At the moment we default to fullscreen3d on navi chips and on MI chips we always enable compute when ROCm is active. The change here is that we eventually fall back to the bootup profile by default when the GPU is idle. This allows PMFW to enable additional power saving features while still providing a boost when applications are running.

Alex

Quoted 96 lines

Thanks,
Lijo

Quoted 91 lines

Alex

Quoted 89 lines

Thanks,
Lijo

Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +45 -0
+
+     for (i = 0; i < AMDGPU_MAX_GFX_RINGS; ++i)
+             fences += amdgpu_fence_count_emitted(&adev->gfx.gfx_ring[i]);
+     for (i = 0; i < (AMDGPU_MAX_COMPUTE_RINGS * AMDGPU_MAX_GC_INSTANCES); ++i)
+             fences += amdgpu_fence_count_emitted(&adev->gfx.compute_ring[i]);
+     if (!fences && !atomic_read(&adev->gfx.total_submission_cnt)) {
+             r = amdgpu_dpm_switch_power_profile(adev, profile, false);
+             if (r)
+                     dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+                              profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+                              "fullscreen 3D" : "compute");
+     } else {
+             schedule_delayed_work(&adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+     }
+}
+
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
+{
+     struct amdgpu_device *adev = ring->adev;
+     enum PP_SMC_POWER_PROFILE profile;
+     int r;
+
+     if (adev->gfx.num_gfx_rings)
+             profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+     else
+             profile = PP_SMC_POWER_PROFILE_COMPUTE;
+
+     atomic_inc(&adev->gfx.total_submission_cnt);
+
+     if (!cancel_delayed_work_sync(&adev->gfx.idle_work)) {
+             r = amdgpu_dpm_switch_power_profile(adev, profile, true);
+             if (r)
+                     dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+                              profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+                              "fullscreen 3D" : "compute");
+     }
+}
+
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring)
+{
+     atomic_dec(&ring->adev->gfx.total_submission_cnt);
+
+     schedule_delayed_work(&ring->adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+}
+
 /*
  * debugfs for to enable/disable gfx job submission to specific core.
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +11 -0
index 7f9e261f47f11..6c84598caec21 100644
@@ -57,6 +57,9 @@ enum amdgpu_gfx_pipe_priority {
 #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
 #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
+/* 1 second timeout */
+#define GFX_PROFILE_IDLE_TIMEOUT     msecs_to_jiffies(1000)
+
 enum amdgpu_gfx_partition {
      AMDGPU_SPX_PARTITION_MODE = 0,
      AMDGPU_DPX_PARTITION_MODE = 1,
@@ -477,6 +480,9 @@ struct amdgpu_gfx {
      bool                            kfd_sch_inactive[MAX_XCP];
      unsigned long                   enforce_isolation_jiffies[MAX_XCP];
      unsigned long                   enforce_isolation_time[MAX_XCP];
+
+     atomic_t                        total_submission_cnt;
+     struct delayed_work             idle_work;
 };
 
 struct amdgpu_gfx_ras_reg_entry {
@@ -585,6 +591,11 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
 void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work);
 void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring);
 void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);
+
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work);
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring);
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring);
+
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
Reviewed-by
#11 lore raw
Quoted 67 lines · Alex Deucher
Quoted 49 lines · Lijo
Quoted 45 lines · Alex Deucher
Quoted 43 lines · Lijo
Quoted 25 lines · Alex Deucher

Add helpers to switch the workload profile dynamically when commands are submitted. This allows us to switch to the FULLSCREEN3D or COMPUTE profile when work is submitted. Add a delayed work handler to delay switching out of the selected profile if additional work comes in. This works the same as the VIDEO profile for VCN. This lets dynamically enable workload profiles on the fly and then move back to the default when there is no work.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 57 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 11 +++++
 2 files changed, 68 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +2 -0
index 6d5d81f0dc4e7..c542617121393 100644
@@ -2110,6 +2110,63 @@ void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring)
      mutex_unlock(&adev->enforce_isolation_mutex);
 }
 
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work)
+{

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring) · line 2124

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10 -0
+     struct amdgpu_device *adev =
+             container_of(work, struct amdgpu_device, gfx.idle_work.work);
+     enum PP_SMC_POWER_PROFILE profile;
+     u32 i, fences = 0;
+     int r;
+
+     if (adev->gfx.num_gfx_rings)
+             profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+     else
+             profile = PP_SMC_POWER_PROFILE_COMPUTE;

Since profile selection is in generic code, it makes sense to first check if the profile is supported for the family. Otherwise, this needs to be passed by the respective GFX family.

Quoted 6 lines
Quoted 3 lines

The generic code already handles this. If you select an unsupported profile, it's ignored when the mask is updated.

That is strange. Does that mean user never gets an error if user attempts to set an unsupported profile?

If you use sysfs, you can only select from the available options supported by the chip so there is no way to select a non-supported profile. For the internal driver API, we just silently ignore it.

Quoted 5 lines

Another problem is this could override the user set profile now. Is that intended? In the current logic, whenever user sets a profile, the current profile is removed. With this one, another profile gets added and the user preference could be ignored depending on the priority.

Quoted 10 lines

Yes, I think. For VCN we already select the video profile in a similar manner and for ROCm we already select the compute profile, this just extends that to gfx. This doesn't really change the behavior compared to the current state of the driver. At the moment we default to fullscreen3d on navi chips and on MI chips we always enable compute when ROCm is active. The change here is that we eventually fall back to the bootup profile by default when the GPU is idle. This allows PMFW to enable additional power saving features while still providing a boost when applications are running.

Sounds good. Only concern is if user intentionally wants to use power saving profile all the time. Not sure if 3D has a lower priority than that.

That aside, series is -

Thanks,
Lijo

Quoted 98 lines

Alex

Quoted 96 lines

Thanks,
Lijo

Quoted 91 lines

Alex

Quoted 89 lines

Thanks,
Lijo

Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +45 -0
+
+     for (i = 0; i < AMDGPU_MAX_GFX_RINGS; ++i)
+             fences += amdgpu_fence_count_emitted(&adev->gfx.gfx_ring[i]);
+     for (i = 0; i < (AMDGPU_MAX_COMPUTE_RINGS * AMDGPU_MAX_GC_INSTANCES); ++i)
+             fences += amdgpu_fence_count_emitted(&adev->gfx.compute_ring[i]);
+     if (!fences && !atomic_read(&adev->gfx.total_submission_cnt)) {
+             r = amdgpu_dpm_switch_power_profile(adev, profile, false);
+             if (r)
+                     dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+                              profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+                              "fullscreen 3D" : "compute");
+     } else {
+             schedule_delayed_work(&adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+     }
+}
+
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
+{
+     struct amdgpu_device *adev = ring->adev;
+     enum PP_SMC_POWER_PROFILE profile;
+     int r;
+
+     if (adev->gfx.num_gfx_rings)
+             profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+     else
+             profile = PP_SMC_POWER_PROFILE_COMPUTE;
+
+     atomic_inc(&adev->gfx.total_submission_cnt);
+
+     if (!cancel_delayed_work_sync(&adev->gfx.idle_work)) {
+             r = amdgpu_dpm_switch_power_profile(adev, profile, true);
+             if (r)
+                     dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+                              profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+                              "fullscreen 3D" : "compute");
+     }
+}
+
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring)
+{
+     atomic_dec(&ring->adev->gfx.total_submission_cnt);
+
+     schedule_delayed_work(&ring->adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+}
+
 /*
  * debugfs for to enable/disable gfx job submission to specific core.
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +11 -0
index 7f9e261f47f11..6c84598caec21 100644
@@ -57,6 +57,9 @@ enum amdgpu_gfx_pipe_priority {
 #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
 #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
+/* 1 second timeout */
+#define GFX_PROFILE_IDLE_TIMEOUT     msecs_to_jiffies(1000)
+
 enum amdgpu_gfx_partition {
      AMDGPU_SPX_PARTITION_MODE = 0,
      AMDGPU_DPX_PARTITION_MODE = 1,
@@ -477,6 +480,9 @@ struct amdgpu_gfx {
      bool                            kfd_sch_inactive[MAX_XCP];
      unsigned long                   enforce_isolation_jiffies[MAX_XCP];
      unsigned long                   enforce_isolation_time[MAX_XCP];
+
+     atomic_t                        total_submission_cnt;
+     struct delayed_work             idle_work;
 };
 
 struct amdgpu_gfx_ras_reg_entry {
@@ -585,6 +591,11 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
 void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work);
 void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring);
 void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);
+
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work);
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring);
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring);
+
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
#12 lore raw
Quoted 82 lines · Lijo
Quoted 67 lines · Alex Deucher
Quoted 49 lines · Lijo
Quoted 45 lines · Alex Deucher
Quoted 43 lines · Lijo
Quoted 25 lines · Alex Deucher

Add helpers to switch the workload profile dynamically when commands are submitted. This allows us to switch to the FULLSCREEN3D or COMPUTE profile when work is submitted. Add a delayed work handler to delay switching out of the selected profile if additional work comes in. This works the same as the VIDEO profile for VCN. This lets dynamically enable workload profiles on the fly and then move back to the default when there is no work.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 57 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 11 +++++
 2 files changed, 68 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +2 -0
index 6d5d81f0dc4e7..c542617121393 100644
@@ -2110,6 +2110,63 @@ void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring)
      mutex_unlock(&adev->enforce_isolation_mutex);
 }
 
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work)
+{

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring) · line 2124

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10 -0
+     struct amdgpu_device *adev =
+             container_of(work, struct amdgpu_device, gfx.idle_work.work);
+     enum PP_SMC_POWER_PROFILE profile;
+     u32 i, fences = 0;
+     int r;
+
+     if (adev->gfx.num_gfx_rings)
+             profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+     else
+             profile = PP_SMC_POWER_PROFILE_COMPUTE;

Since profile selection is in generic code, it makes sense to first check if the profile is supported for the family. Otherwise, this needs to be passed by the respective GFX family.

Quoted 6 lines
Quoted 3 lines

The generic code already handles this. If you select an unsupported profile, it's ignored when the mask is updated.

That is strange. Does that mean user never gets an error if user attempts to set an unsupported profile?

If you use sysfs, you can only select from the available options supported by the chip so there is no way to select a non-supported profile. For the internal driver API, we just silently ignore it.

Quoted 5 lines

Another problem is this could override the user set profile now. Is that intended? In the current logic, whenever user sets a profile, the current profile is removed. With this one, another profile gets added and the user preference could be ignored depending on the priority.

Quoted 10 lines

Yes, I think. For VCN we already select the video profile in a similar manner and for ROCm we already select the compute profile, this just extends that to gfx. This doesn't really change the behavior compared to the current state of the driver. At the moment we default to fullscreen3d on navi chips and on MI chips we always enable compute when ROCm is active. The change here is that we eventually fall back to the bootup profile by default when the GPU is idle. This allows PMFW to enable additional power saving features while still providing a boost when applications are running.

Quoted 2 lines

Sounds good. Only concern is if user intentionally wants to use power saving profile all the time. Not sure if 3D has a lower priority than that.

Yes, power save is higher priority than fullscreen 3d.

Alex

Quoted 106 lines

That aside, series is -

Thanks,
Lijo

Quoted 98 lines

Alex

Quoted 96 lines

Thanks,
Lijo

Quoted 91 lines

Alex

Quoted 89 lines

Thanks,
Lijo

Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +45 -0
+
+     for (i = 0; i < AMDGPU_MAX_GFX_RINGS; ++i)
+             fences += amdgpu_fence_count_emitted(&adev->gfx.gfx_ring[i]);
+     for (i = 0; i < (AMDGPU_MAX_COMPUTE_RINGS * AMDGPU_MAX_GC_INSTANCES); ++i)
+             fences += amdgpu_fence_count_emitted(&adev->gfx.compute_ring[i]);
+     if (!fences && !atomic_read(&adev->gfx.total_submission_cnt)) {
+             r = amdgpu_dpm_switch_power_profile(adev, profile, false);
+             if (r)
+                     dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+                              profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+                              "fullscreen 3D" : "compute");
+     } else {
+             schedule_delayed_work(&adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+     }
+}
+
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
+{
+     struct amdgpu_device *adev = ring->adev;
+     enum PP_SMC_POWER_PROFILE profile;
+     int r;
+
+     if (adev->gfx.num_gfx_rings)
+             profile = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+     else
+             profile = PP_SMC_POWER_PROFILE_COMPUTE;
+
+     atomic_inc(&adev->gfx.total_submission_cnt);
+
+     if (!cancel_delayed_work_sync(&adev->gfx.idle_work)) {
+             r = amdgpu_dpm_switch_power_profile(adev, profile, true);
+             if (r)
+                     dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
+                              profile == PP_SMC_POWER_PROFILE_FULLSCREEN3D ?
+                              "fullscreen 3D" : "compute");
+     }
+}
+
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring)
+{
+     atomic_dec(&ring->adev->gfx.total_submission_cnt);
+
+     schedule_delayed_work(&ring->adev->gfx.idle_work, GFX_PROFILE_IDLE_TIMEOUT);
+}
+
 /*
  * debugfs for to enable/disable gfx job submission to specific core.
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +11 -0
index 7f9e261f47f11..6c84598caec21 100644
@@ -57,6 +57,9 @@ enum amdgpu_gfx_pipe_priority {
 #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
 #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
+/* 1 second timeout */
+#define GFX_PROFILE_IDLE_TIMEOUT     msecs_to_jiffies(1000)
+
 enum amdgpu_gfx_partition {
      AMDGPU_SPX_PARTITION_MODE = 0,
      AMDGPU_DPX_PARTITION_MODE = 1,
@@ -477,6 +480,9 @@ struct amdgpu_gfx {
      bool                            kfd_sch_inactive[MAX_XCP];
      unsigned long                   enforce_isolation_jiffies[MAX_XCP];
      unsigned long                   enforce_isolation_time[MAX_XCP];
+
+     atomic_t                        total_submission_cnt;
+     struct delayed_work             idle_work;
 };
 
 struct amdgpu_gfx_ras_reg_entry {
@@ -585,6 +591,11 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
 void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work);
 void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring);
 void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);
+
+void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work);
+void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring);
+void amdgpu_gfx_profile_ring_end_use(struct amdgpu_ring *ring);
+
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);