Skip to contentSkip to conversation

Introduce a method to get clock gating status dynamically

PATCH Superseded Huang Rui 3 participants 8 messages Jan 6, 2017 4 messages not in the archive

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Huang Rui

author
#0 lore raw

v2 cover Introduce a method to get clock gating status dynamically

This series patches implement to get the clock gating status dynamically into debugfs. User will enter profiling mode to runtime disable clockgating, so it needs an interface to expose clock gating states. Part 1 works for VI, I will implement it on CI/SI in following days.

Changes from V1 -> V2:
- add powergated check before reading register back for UVD/VCE.
- refine parse clock gating method as inspired by Felix.
- rename clockgating function name.

I just send patch 2&7&8 for V2 review, as others hardly have update with V1.

Here is the example on Fiji:

root@jenkins-All-Series:/home/jenkins# cat /sys/kernel/debug/dri/64/amdgpu_pm_info
Clock Gating Flags Mask: 0x3dfff
        Medium Grain Clock Gating: On
        Medium Grain memory Light Sleep: On
        Coarse Grain Clock Gating: On
        Coarse Grain memory Light Sleep: On
        Coarse Grain Tree Shader: On
        Coarse Grain Tree Shader Light Sleep: On
        Command Processor Light Sleep: On
        Run List Controller Light Sleep: On
        Memory Controller Light Sleep: On
        Memory Controller Medium Grain Clock Gating: On
        System Direct Memory Access Light Sleep: On
        System Direct Memory Access Medium Grain Clock Gating: On
        Bus Interface Light Sleep: On
        Universal Video Decoder Medium Grain Clock Gating: Off
        Video Coding Engine Medium Grain Clock Gating: On
        Host Data Path Light Sleep: On
        Host Data Path Medium Grain Clock Gating: On
        Rom Medium Grain Clock Gating: On
...

Thanks,
Rui

Huang Rui (8):
drm/amdgpu: introduce an interface to get clock gating status
dynamically
drm/amdgpu: add parse clock gating state drm/amdgpu: add get clockgating_state method for gfx v8 drm/amdgpu: add get clockgating_state method for gmc v8 drm/amdgpu: add get clockgating_state method for sdma v3 drm/amdgpu: add get clockgating_state method for vi common drm/amdgpu: add get clockgating_state method for uvd v5&v6 drm/amdgpu: add get clockgating_state method for vce v3

 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c     | 37 +++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h     |  6 +++++
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c      | 40 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c      | 16 ++++++++++++
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c     | 17 +++++++++++++
 drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c      | 26 +++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c      | 26 +++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/vce_v3_0.c      | 37 ++++++++++++++++++++++++---
 drivers/gpu/drm/amd/amdgpu/vi.c            | 27 ++++++++++++++++++++
 drivers/gpu/drm/amd/include/amd_shared.h   |  2 ++
 12 files changed, 241 insertions(+), 8 deletions(-)
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1483688740-7530-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org

author
#2 lore raw

PATCH v2 2/8 drm/amdgpu: add parse clock gating state

---

William,

"Medium Grain Clock Gating" is referred from HW spec. So it's better to align with it. I updated function name from clockgating_state to get_clockgating_state.

Thanks,
Rui

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 33 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h |  6 ++++++
 2 files changed, 39 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +33 -0
index 1203e9a..906ed4e 100644
@@ -34,6 +34,28 @@
 
 static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev);
 
+static const struct cg_flag_name clocks[] = {
+	{AMD_CG_SUPPORT_GFX_MGCG, "Medium Grain Clock Gating"},
+	{AMD_CG_SUPPORT_GFX_MGLS, "Medium Grain memory Light Sleep"},
+	{AMD_CG_SUPPORT_GFX_CGCG, "Coarse Grain Clock Gating"},
+	{AMD_CG_SUPPORT_GFX_CGLS, "Coarse Grain memory Light Sleep"},
+	{AMD_CG_SUPPORT_GFX_CGTS, "Coarse Grain Tree Shader Light Sleep"},
+	{AMD_CG_SUPPORT_GFX_CGTS_LS, "Coarse Grain Tree Shader Light Sleep"},
+	{AMD_CG_SUPPORT_GFX_CP_LS, "Command Processor Light Sleep"},
+	{AMD_CG_SUPPORT_GFX_RLC_LS, "Run List Controller Light Sleep"},
+	{AMD_CG_SUPPORT_MC_LS, "Memory Controller Light Sleep"},
+	{AMD_CG_SUPPORT_MC_MGCG, "Memory Controller Medium Grain Clock Gating"},
+	{AMD_CG_SUPPORT_SDMA_LS, "System Direct Memory Access Light Sleep"},
+	{AMD_CG_SUPPORT_SDMA_MGCG, "System Direct Memory Access Medium Grain Clock Gating"},
+	{AMD_CG_SUPPORT_BIF_LS, "Bus Interface Light Sleep"},
+	{AMD_CG_SUPPORT_UVD_MGCG, "Universal Video Decoder Medium Grain Clock Gating"},
+	{AMD_CG_SUPPORT_VCE_MGCG, "Video Coding Engine Medium Grain Clock Gating"},
+	{AMD_CG_SUPPORT_HDP_LS, "Host Data Path Light Sleep"},
+	{AMD_CG_SUPPORT_HDP_MGCG, "Host Data Path Medium Grain Clock Gating"},
+	{AMD_CG_SUPPORT_ROM_MGCG, "Rom Medium Grain Clock Gating"},
+	{0, NULL},
+};
+
 void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev)
 {
 	if (adev->pp_enabled)
@@ -1536,6 +1558,15 @@ static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *a
 	return 0;
 }
 
+static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
+{
+	int i;
+
+	for (i = 0; clocks[i].flag; i++)
+		seq_printf(m, "\t%s: %s\n", clocks[i].name,
+			   (flags & clocks[i].flag) ? "On" : "Off");
+}
+
 static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
 {
 	struct drm_info_node *node = (struct drm_info_node *) m->private;
@@ -1546,6 +1577,8 @@ static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
 
 	amdgpu_get_clockgating_state(adev, &flags);
 	seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
+	amdgpu_parse_cg_state(m, flags);
+	seq_printf(m, "\n");
 
 	if (!adev->pm.dpm_enabled) {
 		seq_printf(m, "dpm not enabled\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h +6 -0
index 5fd7734..c19c4d1 100644
@@ -24,6 +24,12 @@
 #ifndef __AMDGPU_PM_H__
 #define __AMDGPU_PM_H__
 
+struct cg_flag_name
+{
+	u32 flag;
+	const char *name;
+};
+
 int amdgpu_pm_sysfs_init(struct amdgpu_device *adev);
 void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev);
 void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1483688740-7530-2-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org

#4 lore raw

RE: [PART1 PATCH v2 2/8] drm/amdgpu: add parse clock gating state

Quoted 48 lines

-----Original Message-----
From: Huang Rui [mailto:[email protected]]
Sent: Friday, January 06, 2017 2:46 AM
To: Deucher, Alexander; [email protected]
Cc: Zhu, Rex; Mao, David; Fu, Ping; Zhang, Hawking; Kuehling, Felix; Huang, Ray; William Lewis
Subject: [PART1 PATCH v2 2/8] drm/amdgpu: add parse clock gating state

---

William,

"Medium Grain Clock Gating" is referred from HW spec. So it's better to align with it. I updated function name from clockgating_state to get_clockgating_state.

Thanks,
Rui

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 33
+++++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h |  6 ++++++
 2 files changed, 39 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +7 -0
index 1203e9a..906ed4e 100644
@@ -34,6 +34,28 @@
 
 static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev);
 
+static const struct cg_flag_name clocks[] = {
+	{AMD_CG_SUPPORT_GFX_MGCG, "Medium Grain Clock Gating"},
+	{AMD_CG_SUPPORT_GFX_MGLS, "Medium Grain memory Light
 Sleep"},
+	{AMD_CG_SUPPORT_GFX_CGCG, "Coarse Grain Clock Gating"},
+	{AMD_CG_SUPPORT_GFX_CGLS, "Coarse Grain memory Light
 Sleep"},
+	{AMD_CG_SUPPORT_GFX_CGTS, "Coarse Grain Tree Shader Light
 Sleep"},
+	{AMD_CG_SUPPORT_GFX_CGTS_LS, "Coarse Grain Tree Shader Light
Quoted 1 line

Sleep"},

Minor nit, maybe prefix these with GFX.

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -0
+	{AMD_CG_SUPPORT_GFX_CP_LS, "Command Processor Light

Sleep"},

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +3 -0
+	{AMD_CG_SUPPORT_GFX_RLC_LS, "Run List Controller Light Sleep"},
+	{AMD_CG_SUPPORT_MC_LS, "Memory Controller Light Sleep"},
+	{AMD_CG_SUPPORT_MC_MGCG, "Memory Controller Medium

Grain Clock Gating"},

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -0
+	{AMD_CG_SUPPORT_SDMA_LS, "System Direct Memory Access

Light Sleep"},

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -0
+	{AMD_CG_SUPPORT_SDMA_MGCG, "System Direct Memory Access

Medium Grain Clock Gating"},

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +2 -0
+	{AMD_CG_SUPPORT_BIF_LS, "Bus Interface Light Sleep"},
+	{AMD_CG_SUPPORT_UVD_MGCG, "Universal Video Decoder
Quoted 1 line

Medium Grain Clock Gating"},

Unified -> Universal

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -0
+	{AMD_CG_SUPPORT_VCE_MGCG, "Video Coding Engine Medium

Grain Clock Gating"},

Coding -> Compression

Quoted 58 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +2 -0
+	{AMD_CG_SUPPORT_HDP_LS, "Host Data Path Light Sleep"},
+	{AMD_CG_SUPPORT_HDP_MGCG, "Host Data Path Medium Grain

Clock Gating"},

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -0
+	{AMD_CG_SUPPORT_ROM_MGCG, "Rom Medium Grain Clock

Gating"},

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +3 -0
+	{0, NULL},
+};
+
 void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev)
 {
 	if (adev->pp_enabled)
@@ -1536,6 +1558,15 @@ static int amdgpu_debugfs_pm_info_pp(struct

seq_file *m, struct amdgpu_device *a

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +9 -0
 	return 0;
 }
 
+static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
+{
+	int i;
+
+	for (i = 0; clocks[i].flag; i++)
+		seq_printf(m, "\t%s: %s\n", clocks[i].name,
+			   (flags & clocks[i].flag) ? "On" : "Off");
+}
+
 static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
 {
 	struct drm_info_node *node = (struct drm_info_node *) m-
Quoted 1 line

private;

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +2 -0
@@ -1546,6 +1577,8 @@ static int amdgpu_debugfs_pm_info(struct seq_file
 *m, void *data)
 
 	amdgpu_get_clockgating_state(adev, &flags);
 	seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
+	amdgpu_parse_cg_state(m, flags);
+	seq_printf(m, "\n");
 
 	if (!adev->pm.dpm_enabled) {
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0 -0
 		seq_printf(m, "dpm not enabled\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h +6 -1
index 5fd7734..c19c4d1 100644
@@ -24,6 +24,12 @@
 #ifndef __AMDGPU_PM_H__
 #define __AMDGPU_PM_H__
 
+struct cg_flag_name
+{
+	u32 flag;
+	const char *name;
+};
+
 int amdgpu_pm_sysfs_init(struct amdgpu_device *adev);
 void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev);
 void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
--
Quoted 1 line

2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#5 lore raw

PATCH v2 7/8 drm/amdgpu: add get clockgating_state method for uvd v5&v6

In reply to a message not in the archive
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c | 26 ++++++++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c | 26 ++++++++++++++++++++++++--
 3 files changed, 49 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 530549b..31054c7 100644
@@ -1183,6 +1183,7 @@ struct amdgpu_uvd {
 	bool			use_ctx_buf;
 	struct amd_sched_entity entity;
 	uint32_t                srbm_soft_reset;
+	bool			is_powergated;
 };
 
 /*
drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c +24 -2
index 03a35d9..ca96f06 100644
@@ -781,16 +781,37 @@ static int uvd_v5_0_set_powergating_state(void *handle,
 	 * the smc and the hw blocks
 	 */
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int ret;
 
 	if (!(adev->pg_flags & AMD_PG_SUPPORT_UVD))
 		return 0;
 
 	if (state == AMD_PG_STATE_GATE) {
+		adev->uvd.is_powergated = true;
 		uvd_v5_0_stop(adev);
-		return 0;
 	} else {
-		return uvd_v5_0_start(adev);
+		ret = uvd_v5_0_start(adev);
+		if (ret)
+			return ret;
+		adev->uvd.is_powergated = false;
+	}
+	return 0;
+}
+
+static void uvd_v5_0_get_clockgating_state(void *handle, u32 *flags)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int data;
+
+	if (adev->uvd.is_powergated) {
+		DRM_INFO("Cannot get clockgating state when UVD is powergated.\n");
+		return;
 	}
+
+	/* AMD_CG_SUPPORT_UVD_MGCG */
+	data = RREG32(mmUVD_CGC_CTRL);
+	if (data & UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK)
+		*flags |= AMD_CG_SUPPORT_UVD_MGCG;
 }
 
 static const struct amd_ip_funcs uvd_v5_0_ip_funcs = {
@@ -808,6 +829,7 @@ static const struct amd_ip_funcs uvd_v5_0_ip_funcs = {
 	.soft_reset = uvd_v5_0_soft_reset,
 	.set_clockgating_state = uvd_v5_0_set_clockgating_state,
 	.set_powergating_state = uvd_v5_0_set_powergating_state,
+	.get_clockgating_state = uvd_v5_0_get_clockgating_state,
 };
 
 static const struct amdgpu_ring_funcs uvd_v5_0_ring_funcs = {
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +24 -2
index 8779d4b..0ce6a11 100644
@@ -987,6 +987,7 @@ static int uvd_v6_0_set_powergating_state(void *handle,
 	 * the smc and the hw blocks
 	 */
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int ret;
 
 	if (!(adev->pg_flags & AMD_PG_SUPPORT_UVD))
 		return 0;
@@ -994,11 +995,31 @@ static int uvd_v6_0_set_powergating_state(void *handle,
 	WREG32(mmUVD_POWER_STATUS, UVD_POWER_STATUS__UVD_PG_EN_MASK);
 
 	if (state == AMD_PG_STATE_GATE) {
+		adev->uvd.is_powergated = true;
 		uvd_v6_0_stop(adev);
-		return 0;
 	} else {
-		return uvd_v6_0_start(adev);
+		ret = uvd_v6_0_start(adev);
+		if (ret)
+			return ret;
+		adev->uvd.is_powergated = false;
+	}
+	return 0;
+}
+
+static void uvd_v6_0_get_clockgating_state(void *handle, u32 *flags)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int data;
+
+	if (adev->uvd.is_powergated) {
+		DRM_INFO("Cannot get clockgating state when UVD is powergated.\n");
+		return;
 	}
+
+	/* AMD_CG_SUPPORT_UVD_MGCG */
+	data = RREG32(mmUVD_CGC_CTRL);
+	if (data & UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK)
+		*flags |= AMD_CG_SUPPORT_UVD_MGCG;
 }
 
 static const struct amd_ip_funcs uvd_v6_0_ip_funcs = {
@@ -1019,6 +1040,7 @@ static const struct amd_ip_funcs uvd_v6_0_ip_funcs = {
 	.post_soft_reset = uvd_v6_0_post_soft_reset,
 	.set_clockgating_state = uvd_v6_0_set_clockgating_state,
 	.set_powergating_state = uvd_v6_0_set_powergating_state,
+	.get_clockgating_state = uvd_v6_0_get_clockgating_state,
 };
 
 static const struct amdgpu_ring_funcs uvd_v6_0_ring_phys_funcs = {
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1483688740-7530-3-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org

#7 lore raw

Re: [PART1 PATCH v2 7/8] drm/amdgpu: add get clockgating_state method for uvd v5&v6

Am 06.01.2017 um 08:45 schrieb Huang Rui:

Quoted 99 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  1 +
  drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c | 26 ++++++++++++++++++++++++--
  drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c | 26 ++++++++++++++++++++++++--
  3 files changed, 49 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 530549b..31054c7 100644
@@ -1183,6 +1183,7 @@ struct amdgpu_uvd {
  	bool			use_ctx_buf;
  	struct amd_sched_entity entity;
  	uint32_t                srbm_soft_reset;
+	bool			is_powergated;
  };
 
  /*
drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c +24 -2
index 03a35d9..ca96f06 100644
@@ -781,16 +781,37 @@ static int uvd_v5_0_set_powergating_state(void *handle,
  	 * the smc and the hw blocks
  	 */
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int ret;
 
  	if (!(adev->pg_flags & AMD_PG_SUPPORT_UVD))
  		return 0;
 
  	if (state == AMD_PG_STATE_GATE) {
+		adev->uvd.is_powergated = true;
  		uvd_v5_0_stop(adev);
-		return 0;
  	} else {
-		return uvd_v5_0_start(adev);
+		ret = uvd_v5_0_start(adev);
+		if (ret)
+			return ret;
+		adev->uvd.is_powergated = false;
+	}
+	return 0;
+}
+
+static void uvd_v5_0_get_clockgating_state(void *handle, u32 *flags)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int data;
+
+	if (adev->uvd.is_powergated) {
+		DRM_INFO("Cannot get clockgating state when UVD is powergated.\n");
+		return;
  	}
+
+	/* AMD_CG_SUPPORT_UVD_MGCG */
+	data = RREG32(mmUVD_CGC_CTRL);
+	if (data & UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK)
+		*flags |= AMD_CG_SUPPORT_UVD_MGCG;
  }
 
  static const struct amd_ip_funcs uvd_v5_0_ip_funcs = {
@@ -808,6 +829,7 @@ static const struct amd_ip_funcs uvd_v5_0_ip_funcs = {
  	.soft_reset = uvd_v5_0_soft_reset,
  	.set_clockgating_state = uvd_v5_0_set_clockgating_state,
  	.set_powergating_state = uvd_v5_0_set_powergating_state,
+	.get_clockgating_state = uvd_v5_0_get_clockgating_state,
  };
 
  static const struct amdgpu_ring_funcs uvd_v5_0_ring_funcs = {
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +9 -2
index 8779d4b..0ce6a11 100644
@@ -987,6 +987,7 @@ static int uvd_v6_0_set_powergating_state(void *handle,
  	 * the smc and the hw blocks
  	 */
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int ret;
 
  	if (!(adev->pg_flags & AMD_PG_SUPPORT_UVD))
  		return 0;
@@ -994,11 +995,31 @@ static int uvd_v6_0_set_powergating_state(void *handle,
  	WREG32(mmUVD_POWER_STATUS, UVD_POWER_STATUS__UVD_PG_EN_MASK);
 
  	if (state == AMD_PG_STATE_GATE) {
+		adev->uvd.is_powergated = true;
  		uvd_v6_0_stop(adev);
-		return 0;
  	} else {
-		return uvd_v6_0_start(adev);
+		ret = uvd_v6_0_start(adev);
+		if (ret)
+			return ret;
+		adev->uvd.is_powergated = false;
+	}
+	return 0;
+}

drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c static int uvd_v6_0_set_powergating_state(void *handle, · line 1017

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +9 -0
+
+static void uvd_v6_0_get_clockgating_state(void *handle, u32 *flags)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int data;
+
+	if (adev->uvd.is_powergated) {
+		DRM_INFO("Cannot get clockgating state when UVD is powergated.\n");
+		return;
  	}

This is not really save. The power can be gated just in the moment you check the variable.

Adding a spinlock or mutex to protect the variable should be sufficient.

Regards,
Christian.

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +5 -0
+
+	/* AMD_CG_SUPPORT_UVD_MGCG */
+	data = RREG32(mmUVD_CGC_CTRL);
+	if (data & UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK)
+		*flags |= AMD_CG_SUPPORT_UVD_MGCG;
  }
 
  static const struct amd_ip_funcs uvd_v6_0_ip_funcs = {

drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c static const struct amd_ip_funcs uvd_v6_0_ip_funcs = { · line 1046

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +1 -0
@@ -1019,6 +1040,7 @@ static const struct amd_ip_funcs uvd_v6_0_ip_funcs = {
  	.post_soft_reset = uvd_v6_0_post_soft_reset,
  	.set_clockgating_state = uvd_v6_0_set_clockgating_state,
  	.set_powergating_state = uvd_v6_0_set_powergating_state,
+	.get_clockgating_state = uvd_v6_0_get_clockgating_state,
  };
 
  static const struct amdgpu_ring_funcs uvd_v6_0_ring_phys_funcs = {

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 195a9920-1e4a-d3d5-88c7-daf431c90b6c-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

author
#9 lore raw

Re: [PART1 PATCH v2 7/8] drm/amdgpu: add get clockgating_state method for uvd v5&v6

Quoted 14 lines · Christian König

Am 06.01.2017 um 08:45 schrieb Huang Rui:

Review

Quoted 9 lines
(quoted diff) +8 -0
+static void uvd_v6_0_get_clockgating_state(void *handle, u32 *flags)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int data;
+
+	if (adev->uvd.is_powergated) {
+		DRM_INFO("Cannot get clockgating state when UVD is powergated.\n");
+		return;
 	}

This is not really save. The power can be gated just in the moment you check the variable.

Quoted 2 lines

Adding a spinlock or mutex to protect the variable should be sufficient.

Yes, a lock should be added. How about below changes:

---
From 2d4f0232bda6bffd175ce5d10803454c3ce7dd87 Mon Sep 17 00:00:00 2001
From: Huang Rui <[email protected]>
Date: Thu, 5 Jan 2017 21:07:02 +0800
Subject: [PATCH] drm/amdgpu: add get clockgating_state method for uvd v5&v6

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  2 ++
 drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c | 36 +++++++++++++++++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c | 26 +++++++++++++++++++++++--
 3 files changed, 60 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index 001499b..5d31e4d 100644
@@ -1183,6 +1183,8 @@ struct amdgpu_uvd {
 	bool			use_ctx_buf;
 	struct amd_sched_entity entity;
 	uint32_t                srbm_soft_reset;
+	bool			is_powergated;
+	struct mutex		pg_mutex;
 };
 
 /*
drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c +34 -2
index 03a35d9..bfd94de 100644
@@ -781,16 +781,47 @@ static int uvd_v5_0_set_powergating_state(void *handle,
 	 * the smc and the hw blocks
 	 */
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int ret;
 
 	if (!(adev->pg_flags & AMD_PG_SUPPORT_UVD))
 		return 0;
 
+	mutex_lock(&adev->uvd.pg_mutex);
+
 	if (state == AMD_PG_STATE_GATE) {
+		adev->uvd.is_powergated = true;
 		uvd_v5_0_stop(adev);
-		return 0;
 	} else {
-		return uvd_v5_0_start(adev);
+		ret = uvd_v5_0_start(adev);
+		if (ret)
+			goto out;
+		adev->uvd.is_powergated = false;
+	}
+
+out:
+	mutex_unlock(&adev->uvd.pg_mutex);
+
+	return ret;
+}
+
+static void uvd_v5_0_get_clockgating_state(void *handle, u32 *flags)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int data;
+
+	mutex_lock(&adev->uvd.pg_mutex);
+
+	if (adev->uvd.is_powergated) {
+		DRM_INFO("Cannot get clockgating state when UVD is powergated.\n");
+		return;
 	}
+
+	/* AMD_CG_SUPPORT_UVD_MGCG */
+	data = RREG32(mmUVD_CGC_CTRL);
+	if (data & UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK)
+		*flags |= AMD_CG_SUPPORT_UVD_MGCG;
+
+	mutex_unlock(&adev->uvd.pg_mutex);
 }
 
 static const struct amd_ip_funcs uvd_v5_0_ip_funcs = {
@@ -808,6 +839,7 @@ static const struct amd_ip_funcs uvd_v5_0_ip_funcs = {
 	.soft_reset = uvd_v5_0_soft_reset,
 	.set_clockgating_state = uvd_v5_0_set_clockgating_state,
 	.set_powergating_state = uvd_v5_0_set_powergating_state,
+	.get_clockgating_state = uvd_v5_0_get_clockgating_state,
 };
 
 static const struct amdgpu_ring_funcs uvd_v5_0_ring_funcs = {
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +24 -2
index 8779d4b..0ce6a11 100644
@@ -987,6 +987,7 @@ static int uvd_v6_0_set_powergating_state(void *handle,
 	 * the smc and the hw blocks
 	 */
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int ret;
 
 	if (!(adev->pg_flags & AMD_PG_SUPPORT_UVD))
 		return 0;
@@ -994,11 +995,31 @@ static int uvd_v6_0_set_powergating_state(void *handle,
 	WREG32(mmUVD_POWER_STATUS, UVD_POWER_STATUS__UVD_PG_EN_MASK);
 
 	if (state == AMD_PG_STATE_GATE) {
+		adev->uvd.is_powergated = true;
 		uvd_v6_0_stop(adev);
-		return 0;
 	} else {
-		return uvd_v6_0_start(adev);
+		ret = uvd_v6_0_start(adev);
+		if (ret)
+			return ret;
+		adev->uvd.is_powergated = false;
+	}
+	return 0;
+}
+
+static void uvd_v6_0_get_clockgating_state(void *handle, u32 *flags)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int data;
+
+	if (adev->uvd.is_powergated) {
+		DRM_INFO("Cannot get clockgating state when UVD is powergated.\n");
+		return;
 	}
+
+	/* AMD_CG_SUPPORT_UVD_MGCG */
+	data = RREG32(mmUVD_CGC_CTRL);
+	if (data & UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK)
+		*flags |= AMD_CG_SUPPORT_UVD_MGCG;
 }
 
 static const struct amd_ip_funcs uvd_v6_0_ip_funcs = {
@@ -1019,6 +1040,7 @@ static const struct amd_ip_funcs uvd_v6_0_ip_funcs = {
 	.post_soft_reset = uvd_v6_0_post_soft_reset,
 	.set_clockgating_state = uvd_v6_0_set_clockgating_state,
 	.set_powergating_state = uvd_v6_0_set_powergating_state,
+	.get_clockgating_state = uvd_v6_0_get_clockgating_state,
 };
 
 static const struct amdgpu_ring_funcs uvd_v6_0_ring_phys_funcs = {
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#10 lore raw

Re: [PART1 PATCH v2 7/8] drm/amdgpu: add get clockgating_state method for uvd v5&v6

Quoted 15 lines · Huang Rui
Quoted 14 lines · Christian König

Am 06.01.2017 um 08:45 schrieb Huang Rui:

drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c static int uvd_v6_0_set_powergating_state(void *handle, · line 1017

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +8 -0
+static void uvd_v6_0_get_clockgating_state(void *handle, u32 *flags)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int data;
+
+	if (adev->uvd.is_powergated) {
+		DRM_INFO("Cannot get clockgating state when UVD is powergated.\n");
+		return;
 	}

This is not really save. The power can be gated just in the moment you check the variable.

Quoted 5 lines
Quoted 2 lines

Adding a spinlock or mutex to protect the variable should be sufficient.

Yes, a lock should be added. How about below changes:

Christian, sorry please ignore this mail, I just update uvd v5, missed to update uvd v6. I will send it later.

Thanks,
Rui
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#11 lore raw

PATCH v2 8/8 drm/amdgpu: add get clockgating_state method for vce v3

In reply to a message not in the archive
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/vce_v3_0.c | 37 +++++++++++++++++++++++++++++++----
 2 files changed, 34 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 31054c7..3c52b81 100644
@@ -1212,6 +1212,7 @@ struct amdgpu_vce {
 	struct amd_sched_entity	entity;
 	uint32_t                srbm_soft_reset;
 	unsigned		num_rings;
+	bool			is_powergated;
 };
 
 /*
drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +33 -4
index 35ff1c3..72fc53c 100644
@@ -770,15 +770,43 @@ static int vce_v3_0_set_powergating_state(void *handle,
 	 * the smc and the hw blocks
 	 */
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int ret;
 
 	if (!(adev->pg_flags & AMD_PG_SUPPORT_VCE))
 		return 0;
 
-	if (state == AMD_PG_STATE_GATE)
+	if (state == AMD_PG_STATE_GATE) {
+		adev->vce.is_powergated = true;
 		/* XXX do we need a vce_v3_0_stop()? */
-		return 0;
-	else
-		return vce_v3_0_start(adev);
+	} else {
+		ret = vce_v3_0_start(adev);
+		if (ret)
+			return ret;
+		adev->vce.is_powergated = false;
+	}
+	return 0;
+}
+
+static void vce_v3_0_get_clockgating_state(void *handle, u32 *flags)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int data;
+
+	if (adev->vce.is_powergated) {
+		DRM_INFO("Cannot get clockgating state when VCE is powergated.\n");
+		return;
+	}
+
+	mutex_lock(&adev->grbm_idx_mutex);
+
+	WREG32_FIELD(GRBM_GFX_INDEX, VCE_INSTANCE, 0);
+
+	/* AMD_CG_SUPPORT_VCE_MGCG */
+	data = RREG32(mmVCE_CLOCK_GATING_A);
+	if (data & (0x04 << 4))
+		*flags |= AMD_CG_SUPPORT_VCE_MGCG;
+
+	mutex_unlock(&adev->grbm_idx_mutex);
 }
 
 static void vce_v3_0_ring_emit_ib(struct amdgpu_ring *ring,
@@ -832,6 +860,7 @@ static const struct amd_ip_funcs vce_v3_0_ip_funcs = {
 	.post_soft_reset = vce_v3_0_post_soft_reset,
 	.set_clockgating_state = vce_v3_0_set_clockgating_state,
 	.set_powergating_state = vce_v3_0_set_powergating_state,
+	.get_clockgating_state = vce_v3_0_get_clockgating_state,
 };
 
 static const struct amdgpu_ring_funcs vce_v3_0_ring_phys_funcs = {
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx