Skip to contentSkip to conversation

drm/amd/pm: avoid duplicate powergate/ungate setting

PATCH In review Evan Quan 2 participants 3 messages Nov 15, 2021

Subsystems (3)
lore
Share & tools
lore

Evan Quan

author
#0 lore raw

PATCH v3 1/1 drm/amd/pm: avoid duplicate powergate/ungate setting

Just bail out if the target IP block is already in the desired powergate/ungate state. This can avoid some duplicate settings which sometimes may cause unexpected issues.

Change-Id I66346c69f121df0f5ee20182451313ae4fda2d04

--
v1->v2:
- typo fix and add link for the issue referred in commit message(Paul/Boris)
- update the data type to uint32_t(Paul)
- better Macro naming(Lijo)
v2->v3:
- stick to original logics on handling unmentioned IP blocks(Lijo)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  3 +++
 drivers/gpu/drm/amd/include/amd_shared.h   |  3 ++-
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c        | 10 ++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h    |  8 ++++++++
 4 files changed, 23 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
index 0bd90ec9e43e..fca592394fa1 100644
@@ -3508,6 +3508,9 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 		adev->rmmio_size = pci_resource_len(adev->pdev, 2);
 	}
 
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->pm.pwr_state[i], POWER_STATE_UNKNOWN);
+
 	adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size);
 	if (adev->rmmio == NULL) {
 		return -ENOMEM;
drivers/gpu/drm/amd/include/amd_shared.h +2 -1
index f1a46d16f7ea..4b9e68a79f06 100644
@@ -98,7 +98,8 @@ enum amd_ip_block_type {
 	AMD_IP_BLOCK_TYPE_ACP,
 	AMD_IP_BLOCK_TYPE_VCN,
 	AMD_IP_BLOCK_TYPE_MES,
-	AMD_IP_BLOCK_TYPE_JPEG
+	AMD_IP_BLOCK_TYPE_JPEG,
+	AMD_IP_BLOCK_TYPE_NUM,
 };
 
 enum amd_clockgating_state {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
index 03581d5b1836..08362d506534 100644
@@ -927,6 +927,13 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block
 {
 	int ret = 0;
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum ip_power_state pwr_state = gate ? POWER_STATE_OFF : POWER_STATE_ON;
+
+	if (atomic_read(&adev->pm.pwr_state[block_type]) == pwr_state) {
+		dev_dbg(adev->dev, "IP block%d already in the target %s state!",
+				block_type, gate ? "gate" : "ungate");
+		return 0;
+	}
 
 	switch (block_type) {
 	case AMD_IP_BLOCK_TYPE_UVD:
@@ -979,6 +986,9 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block
 		break;
 	}
 
+	if (!ret)
+		atomic_set(&adev->pm.pwr_state[block_type], pwr_state);
+
 	return ret;
 }
 
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +8 -0
index 98f1b3d8c1d5..16e3f72d31b9 100644
@@ -417,6 +417,12 @@ struct amdgpu_dpm {
 	enum amd_dpm_forced_level forced_level;
 };
 
+enum ip_power_state {
+	POWER_STATE_UNKNOWN,
+	POWER_STATE_ON,
+	POWER_STATE_OFF,
+};
+
 struct amdgpu_pm {
 	struct mutex		mutex;
 	u32                     current_sclk;
@@ -452,6 +458,8 @@ struct amdgpu_pm {
 	struct i2c_adapter smu_i2c;
 	struct mutex		smu_i2c_mutex;
 	struct list_head	pm_attr_list;
+
+	atomic_t		pwr_state[AMD_IP_BLOCK_TYPE_NUM];
 };
 
 #define R600_SSTU_DFLT                               0
Signature · 1 line
2.29.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 71 lines · Evan Quan

Just bail out if the target IP block is already in the desired powergate/ungate state. This can avoid some duplicate settings which sometimes may cause unexpected issues.

Change-Id I66346c69f121df0f5ee20182451313ae4fda2d04

--
v1->v2:
- typo fix and add link for the issue referred in commit message(Paul/Boris)
- update the data type to uint32_t(Paul)
- better Macro naming(Lijo)
v2->v3:
- stick to original logics on handling unmentioned IP blocks(Lijo)

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  3 +++
  drivers/gpu/drm/amd/include/amd_shared.h   |  3 ++-
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c        | 10 ++++++++++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h    |  8 ++++++++
  4 files changed, 23 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
index 0bd90ec9e43e..fca592394fa1 100644
@@ -3508,6 +3508,9 @@ int amdgpu_device_init(struct amdgpu_device *adev,
  		adev->rmmio_size = pci_resource_len(adev->pdev, 2);
  	}
 
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->pm.pwr_state[i], POWER_STATE_UNKNOWN);
+
  	adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size);
  	if (adev->rmmio == NULL) {
  		return -ENOMEM;
drivers/gpu/drm/amd/include/amd_shared.h +2 -1
index f1a46d16f7ea..4b9e68a79f06 100644
@@ -98,7 +98,8 @@ enum amd_ip_block_type {
  	AMD_IP_BLOCK_TYPE_ACP,
  	AMD_IP_BLOCK_TYPE_VCN,
  	AMD_IP_BLOCK_TYPE_MES,
-	AMD_IP_BLOCK_TYPE_JPEG
+	AMD_IP_BLOCK_TYPE_JPEG,
+	AMD_IP_BLOCK_TYPE_NUM,
  };
 
  enum amd_clockgating_state {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -0
index 03581d5b1836..08362d506534 100644
@@ -927,6 +927,13 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block
  {
  	int ret = 0;
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum ip_power_state pwr_state = gate ? POWER_STATE_OFF : POWER_STATE_ON;
+
+	if (atomic_read(&adev->pm.pwr_state[block_type]) == pwr_state) {
+		dev_dbg(adev->dev, "IP block%d already in the target %s state!",
+				block_type, gate ? "gate" : "ungate");
+		return 0;
+	}
 
  	switch (block_type) {
  	case AMD_IP_BLOCK_TYPE_UVD:

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block · line 991

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
@@ -979,6 +986,9 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block
  		break;
  	}
 
+	if (!ret)
+		atomic_set(&adev->pm.pwr_state[block_type], pwr_state);
+

Once the default case is skipped, this will set the state for unhandled blocks. Should be fine if such blocks are not expected. Otherwise, just return 0 such that they hold unknown power states.

Thanks,
Lijo

Quoted 30 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
  	return ret;
  }
 
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +8 -0
index 98f1b3d8c1d5..16e3f72d31b9 100644
@@ -417,6 +417,12 @@ struct amdgpu_dpm {
  	enum amd_dpm_forced_level forced_level;
  };
 
+enum ip_power_state {
+	POWER_STATE_UNKNOWN,
+	POWER_STATE_ON,
+	POWER_STATE_OFF,
+};
+
  struct amdgpu_pm {
  	struct mutex		mutex;
  	u32                     current_sclk;
@@ -452,6 +458,8 @@ struct amdgpu_pm {
  	struct i2c_adapter smu_i2c;
  	struct mutex		smu_i2c_mutex;
  	struct list_head	pm_attr_list;
+
+	atomic_t		pwr_state[AMD_IP_BLOCK_TYPE_NUM];
  };
 
  #define R600_SSTU_DFLT                               0
author
#2 lore raw

[AMD Official Use Only]

Quoted 96 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, November 15, 2021 12:34 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Borislav Petkov <[email protected]>
Subject: Re: [PATCH V3] drm/amd/pm: avoid duplicate powergate/ungate setting

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_init(struct amdgpu_device

Quoted 30 lines · Evan Quan

Just bail out if the target IP block is already in the desired powergate/ungate state. This can avoid some duplicate settings which sometimes may cause unexpected issues.

Change-Id I66346c69f121df0f5ee20182451313ae4fda2d04

--
v1->v2:
- typo fix and add link for the issue referred in commit message(Paul/Boris)
- update the data type to uint32_t(Paul)
- better Macro naming(Lijo)
v2->v3:
- stick to original logics on handling unmentioned IP blocks(Lijo)

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  3 +++
  drivers/gpu/drm/amd/include/amd_shared.h   |  3 ++-
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c        | 10 ++++++++++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h    |  8 ++++++++
  4 files changed, 23 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 0bd90ec9e43e..fca592394fa1 100644
@@ -3508,6 +3508,9 @@ int amdgpu_device_init(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_init(struct amdgpu_device *adev,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
  		adev->rmmio_size = pci_resource_len(adev->pdev, 2);
  	}
 
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->pm.pwr_state[i],

POWER_STATE_UNKNOWN);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 25 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
+
  	adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size);
  	if (adev->rmmio == NULL) {
  		return -ENOMEM;
drivers/gpu/drm/amd/include/amd_shared.h +2 -1
index f1a46d16f7ea..4b9e68a79f06 100644
@@ -98,7 +98,8 @@ enum amd_ip_block_type {
  	AMD_IP_BLOCK_TYPE_ACP,
  	AMD_IP_BLOCK_TYPE_VCN,
  	AMD_IP_BLOCK_TYPE_MES,
-	AMD_IP_BLOCK_TYPE_JPEG
+	AMD_IP_BLOCK_TYPE_JPEG,
+	AMD_IP_BLOCK_TYPE_NUM,
  };
 
  enum amd_clockgating_state {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 03581d5b1836..08362d506534 100644
@@ -927,6 +927,13 @@ int

amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
  {
  	int ret = 0;
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum ip_power_state pwr_state = gate ? POWER_STATE_OFF :
+POWER_STATE_ON;
+
+	if (atomic_read(&adev->pm.pwr_state[block_type]) == pwr_state) {
+		dev_dbg(adev->dev, "IP block%d already in the target %s

state!",

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+				block_type, gate ? "gate" : "ungate");
+		return 0;
+	}
 
  	switch (block_type) {
  	case AMD_IP_BLOCK_TYPE_UVD:
@@ -979,6 +986,9 @@ int amdgpu_dpm_set_powergating_by_smu(struct

amdgpu_device *adev, uint32_t block

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
  		break;
  	}
 
Quoted 6 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block · line 991

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+	if (!ret)
+		atomic_set(&adev->pm.pwr_state[block_type], pwr_state);
+

Once the default case is skipped, this will set the state for unhandled blocks. Should be fine if such blocks are not expected.

[Quan, Evan] Yes, that's the case.

Thanks,
Evan

Quoted 38 lines

Otherwise, just return 0 such
that they hold unknown power states.

Thanks,
Lijo

Quoted 31 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
  	return ret;
  }
 
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +8 -0
index 98f1b3d8c1d5..16e3f72d31b9 100644
@@ -417,6 +417,12 @@ struct amdgpu_dpm {
  	enum amd_dpm_forced_level forced_level;
  };
 
+enum ip_power_state {
+	POWER_STATE_UNKNOWN,
+	POWER_STATE_ON,
+	POWER_STATE_OFF,
+};
+
  struct amdgpu_pm {
  	struct mutex		mutex;
  	u32                     current_sclk;
@@ -452,6 +458,8 @@ struct amdgpu_pm {
  	struct i2c_adapter smu_i2c;
  	struct mutex		smu_i2c_mutex;
  	struct list_head	pm_attr_list;
+
+	atomic_t		pwr_state[AMD_IP_BLOCK_TYPE_NUM];
  };
 
  #define R600_SSTU_DFLT                               0