Skip to contentSkip to conversation

drm/amdgpu: add pmlog structure definition

PATCH In review Lijo Lazar 5 participants 13 messages Oct 6, 2023 – Oct 9, 2023

Subsystems (3)
lore
Share & tools
lore

Lijo Lazar

author
#0 lore raw

PATCH v2 1/4 drm/amdgpu: add pmlog structure definition

From: Alex Deucher <[email protected]>

Define the pmlog structures to be exposed via sysfs.

---
 drivers/gpu/drm/amd/include/kgd_pp_interface.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +15 -0
index e0bb6d39f0c3..9905228fd89c 100644
@@ -980,4 +980,19 @@ struct gpu_metrics_v2_4 {
 	uint16_t			average_soc_current;
 	uint16_t			average_gfx_current;
 };
+
+struct amdgpu_pmlog_header {
+	uint16_t structure_size;
+	uint16_t pad;
+	uint32_t mp1_ip_discovery_version;
+	uint32_t pmfw_version;
+	uint32_t pmlog_version;
+};
+
+struct amdgpu_pmlog {
+	struct amdgpu_pmlog_header common_header;
+
+	uint8_t data[];
+};
+
 #endif
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 2/4 drm/amd/pm: Add support to fetch pm log sample

Add API support to fetch a snapshot of power management log from PMFW.

---

v2: Add max size of input buffer to take care of overflows

 drivers/gpu/drm/amd/include/kgd_pp_interface.h |  1 +
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c            | 16 ++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h        | 11 +++++++++++
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c      | 14 ++++++++++++++
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h  |  8 ++++++++
 5 files changed, 50 insertions(+)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
index 9905228fd89c..01eaafafd3c3 100644
@@ -426,6 +426,7 @@ struct amd_pm_funcs {
 	int (*set_df_cstate)(void *handle, enum pp_df_cstate state);
 	int (*set_xgmi_pstate)(void *handle, uint32_t pstate);
 	ssize_t (*get_gpu_metrics)(void *handle, void **table);
+	ssize_t (*get_pm_log)(void *handle, void *pmlog, size_t size);
 	int (*set_watermarks_for_clock_ranges)(void *handle,
 					       struct pp_smu_wm_range_sets *ranges);
 	int (*display_disable_memory_clock_switch)(void *handle,
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +16 -0
index 1b17a71ed45e..1db899485309 100644
@@ -1300,6 +1300,22 @@ int amdgpu_dpm_get_gpu_metrics(struct amdgpu_device *adev, void **table)
 	return ret;
 }
 
+ssize_t amdgpu_dpm_get_pm_log(struct amdgpu_device *adev, void *pm_log,
+			      size_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
+
+	if (!pp_funcs->get_pm_log)
+		return 0;
+
+	mutex_lock(&adev->pm.mutex);
+	ret = pp_funcs->get_pm_log(adev->powerplay.pp_handle, pm_log, size);
+	mutex_unlock(&adev->pm.mutex);
+
+	return ret;
+}
+
 int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,
 				    uint32_t *fan_mode)
 {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +11 -0
index feccd2a7120d..ea2c1cc9c7b0 100644
@@ -511,6 +511,17 @@ int amdgpu_dpm_get_power_profile_mode(struct amdgpu_device *adev,
 int amdgpu_dpm_set_power_profile_mode(struct amdgpu_device *adev,
 				      long *input, uint32_t size);
 int amdgpu_dpm_get_gpu_metrics(struct amdgpu_device *adev, void **table);
+
+/**
+ * @get_pm_log: Get one snapshot of power management log from PMFW. The sample
+ * is copied to pmlog buffer. It's expected to be allocated by the caller. Max
+ * size expected for a log sample is 4096 bytes.
+ *
+ * Return: Actual size of the log
+ */
+ssize_t amdgpu_dpm_get_pm_log(struct amdgpu_device *adev, void *pmlog,
+			      size_t size);
+
 int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,
 				    uint32_t *fan_mode);
 int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +14 -0
index 99750c182279..73f3e7915d23 100644
@@ -3090,6 +3090,19 @@ static ssize_t smu_sys_get_gpu_metrics(void *handle, void **table)
 	return smu->ppt_funcs->get_gpu_metrics(smu, table);
 }
 
+static ssize_t smu_sys_get_pm_log(void *handle, void *pm_log, size_t size)
+{
+	struct smu_context *smu = handle;
+
+	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->get_pm_log)
+		return -EOPNOTSUPP;
+
+	return smu->ppt_funcs->get_pm_log(smu, pm_log, size);
+}
+
 static int smu_enable_mgpu_fan_boost(void *handle)
 {
 	struct smu_context *smu = handle;
@@ -3231,6 +3244,7 @@ static const struct amd_pm_funcs swsmu_pm_funcs = {
 	.set_df_cstate                    = smu_set_df_cstate,
 	.set_xgmi_pstate                  = smu_set_xgmi_pstate,
 	.get_gpu_metrics                  = smu_sys_get_gpu_metrics,
+	.get_pm_log                       = smu_sys_get_pm_log,
 	.set_watermarks_for_clock_ranges     = smu_set_watermarks_for_clock_ranges,
 	.display_disable_memory_clock_switch = smu_display_disable_memory_clock_switch,
 	.get_max_sustainable_clocks_by_dc    = smu_get_max_sustainable_clocks_by_dc,
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +8 -0
index f3cab5e633a7..0d84fb9640a6 100644
@@ -1247,6 +1247,14 @@ struct pptable_funcs {
 	 */
 	ssize_t (*get_gpu_metrics)(struct smu_context *smu, void **table);
 
+	/**
+	 * @get_pm_log: Get one snapshot of power management log from PMFW.
+	 *
+	 * Return: Size of the log
+	 */
+	ssize_t (*get_pm_log)(struct smu_context *smu, void *pm_log,
+			      size_t size);
+
 	/**
 	 * @enable_mgpu_fan_boost: Enable multi-GPU fan boost.
 	 */
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH v2 3/4 drm/amd/pm: Add pm log support to SMU v13.0.6

In reply to Lijo Lazar

Add support to fetch PM log sample from SMU v13.0.6

---

v2: Check if input buffer has enough space to copy log data

 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  1 +
 .../pm/swsmu/inc/pmfw_if/smu_v13_0_6_ppsmc.h  |  4 +-
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |  4 +-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c  | 59 +++++++++++++++++++
 4 files changed, 66 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +1 -0
index 0d84fb9640a6..01bc92875f3e 100644
@@ -253,6 +253,7 @@ struct smu_table {
 	uint64_t mc_address;
 	void *cpu_addr;
 	struct amdgpu_bo *bo;
+	uint32_t version;
 };
 
 enum smu_perf_level_designation {
drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_6_ppsmc.h +3 -1
index 509e3cd483fb..891d03327ffa 100644
@@ -91,7 +91,9 @@
 #define PPSMC_MSG_QueryValidMcaCeCount              0x3A
 #define PPSMC_MSG_McaBankCeDumpDW                   0x3B
 #define PPSMC_MSG_SelectPLPDMode                    0x40
-#define PPSMC_Message_Count                         0x41
+#define PPSMC_MSG_PmLogReadSample                   0x41
+#define PPSMC_MSG_PmLogGetTableVersion              0x42
+#define PPSMC_Message_Count                         0x43
 
 //PPSMC Reset Types for driver msg argument
 #define PPSMC_RESET_TYPE_DRIVER_MODE_1_RESET        0x1
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +3 -1
index 4850e48bbef5..6ea9adabe30f 100644
@@ -253,7 +253,9 @@
 	__SMU_DUMMY_MAP(QueryValidMcaCeCount),	\
 	__SMU_DUMMY_MAP(McaBankDumpDW),		\
 	__SMU_DUMMY_MAP(McaBankCeDumpDW),	\
-	__SMU_DUMMY_MAP(SelectPLPDMode),
+	__SMU_DUMMY_MAP(SelectPLPDMode),	\
+	__SMU_DUMMY_MAP(PmLogGetTableVersion),	\
+	__SMU_DUMMY_MAP(PmLogReadSample),
 
 #undef __SMU_DUMMY_MAP
 #define __SMU_DUMMY_MAP(type)	SMU_MSG_##type
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +59 -0

83 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#3 lore raw

PATCH v2 4/4 drm/amd/pm: Add sysfs attribute to get pm log

In reply to Lijo Lazar

Add sysfs attribute to read power management log. A snapshot is captured to the buffer when the attribute is read.

---

v2: Pass PAGE_SIZE as the max size of input buffer

 drivers/gpu/drm/amd/pm/amdgpu_pm.c | 40 ++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +40 -0
index 4c65a2fac028..5a1d21c52672 100644
@@ -1794,6 +1794,44 @@ static ssize_t amdgpu_set_apu_thermal_cap(struct device *dev,
 	return count;
 }
 
+static int amdgpu_pmlog_attr_update(struct amdgpu_device *adev,
+				    struct amdgpu_device_attr *attr,
+				    uint32_t mask,
+				    enum amdgpu_device_attr_states *states)
+{
+	if (amdgpu_dpm_get_pm_log(adev, NULL, 0) == -EOPNOTSUPP)
+		*states = ATTR_STATE_UNSUPPORTED;
+
+	return 0;
+}
+
+static ssize_t amdgpu_get_pmlog(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	struct drm_device *ddev = dev_get_drvdata(dev);
+	struct amdgpu_device *adev = drm_to_adev(ddev);
+	ssize_t size = 0;
+	int ret;
+
+	if (amdgpu_in_reset(adev))
+		return -EPERM;
+	if (adev->in_suspend && !adev->in_runpm)
+		return -EPERM;
+
+	ret = pm_runtime_get_sync(ddev->dev);
+	if (ret < 0) {
+		pm_runtime_put_autosuspend(ddev->dev);
+		return ret;
+	}
+
+	size = amdgpu_dpm_get_pm_log(adev, buf, PAGE_SIZE);
+
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
+	return size;
+}
+
 /**
  * DOC: gpu_metrics
  *
@@ -2091,6 +2129,8 @@ static struct amdgpu_device_attr amdgpu_device_attrs[] = {
 	AMDGPU_DEVICE_ATTR_RW(smartshift_bias,				ATTR_FLAG_BASIC,
 			      .attr_update = ss_bias_attr_update),
 	AMDGPU_DEVICE_ATTR_RW(xgmi_plpd_policy,				ATTR_FLAG_BASIC),
+	AMDGPU_DEVICE_ATTR_RO(pmlog,					ATTR_FLAG_BASIC,
+			      .attr_update = amdgpu_pmlog_attr_update),
 };
 
 static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v2 4/4] drm/amd/pm: Add sysfs attribute to get pm log

Am 06.10.23 um 07:21 schrieb Lijo Lazar:

Quoted 30 lines

Add sysfs attribute to read power management log. A snapshot is captured to the buffer when the attribute is read.

---

v2: Pass PAGE_SIZE as the max size of input buffer

  drivers/gpu/drm/amd/pm/amdgpu_pm.c | 40 ++++++++++++++++++++++++++++++
  1 file changed, 40 insertions(+)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +11 -0
index 4c65a2fac028..5a1d21c52672 100644
@@ -1794,6 +1794,44 @@ static ssize_t amdgpu_set_apu_thermal_cap(struct device *dev,
  	return count;
  }
 
+static int amdgpu_pmlog_attr_update(struct amdgpu_device *adev,
+				    struct amdgpu_device_attr *attr,
+				    uint32_t mask,
+				    enum amdgpu_device_attr_states *states)
+{
+	if (amdgpu_dpm_get_pm_log(adev, NULL, 0) == -EOPNOTSUPP)
+		*states = ATTR_STATE_UNSUPPORTED;
+
+	return 0;
+}
+

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_apu_thermal_cap(struct device *dev, · line 1817

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+static ssize_t amdgpu_get_pmlog(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	struct drm_device *ddev = dev_get_drvdata(dev);
+	struct amdgpu_device *adev = drm_to_adev(ddev);
+	ssize_t size = 0;
+	int ret;
+
+	if (amdgpu_in_reset(adev))
+		return -EPERM;

Please stop using amdgpu_in_reset() for stuff like that altogether.

When this is reset critical it should grab the reset rw semaphore. If it isn't than that check isn't necessary.

Regards,
Christian.

Quoted 29 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +19 -0
+	if (adev->in_suspend && !adev->in_runpm)
+		return -EPERM;
+
+	ret = pm_runtime_get_sync(ddev->dev);
+	if (ret < 0) {
+		pm_runtime_put_autosuspend(ddev->dev);
+		return ret;
+	}
+
+	size = amdgpu_dpm_get_pm_log(adev, buf, PAGE_SIZE);
+
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
+	return size;
+}
+
  /**
   * DOC: gpu_metrics
   *
@@ -2091,6 +2129,8 @@ static struct amdgpu_device_attr amdgpu_device_attrs[] = {
  	AMDGPU_DEVICE_ATTR_RW(smartshift_bias,				ATTR_FLAG_BASIC,
  			      .attr_update = ss_bias_attr_update),
  	AMDGPU_DEVICE_ATTR_RW(xgmi_plpd_policy,				ATTR_FLAG_BASIC),
+	AMDGPU_DEVICE_ATTR_RO(pmlog,					ATTR_FLAG_BASIC,
+			      .attr_update = amdgpu_pmlog_attr_update),
  };
 
  static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
#5 lore raw

Re: [PATCH v2 4/4] drm/amd/pm: Add sysfs attribute to get pm log

Quoted 45 lines · Christian König

Am 06.10.23 um 07:21 schrieb Lijo Lazar:

Quoted 30 lines

Add sysfs attribute to read power management log. A snapshot is captured to the buffer when the attribute is read.

---

v2: Pass PAGE_SIZE as the max size of input buffer

  drivers/gpu/drm/amd/pm/amdgpu_pm.c | 40 ++++++++++++++++++++++++++++++
  1 file changed, 40 insertions(+)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +11 -0
index 4c65a2fac028..5a1d21c52672 100644
@@ -1794,6 +1794,44 @@ static ssize_t amdgpu_set_apu_thermal_cap(struct device *dev,
      return count;
  }
 
+static int amdgpu_pmlog_attr_update(struct amdgpu_device *adev,
+                                 struct amdgpu_device_attr *attr,
+                                 uint32_t mask,
+                                 enum amdgpu_device_attr_states *states)
+{
+     if (amdgpu_dpm_get_pm_log(adev, NULL, 0) == -EOPNOTSUPP)
+             *states = ATTR_STATE_UNSUPPORTED;
+
+     return 0;
+}
+

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_apu_thermal_cap(struct device *dev, · line 1817

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+static ssize_t amdgpu_get_pmlog(struct device *dev,
+                             struct device_attribute *attr, char *buf)
+{
+     struct drm_device *ddev = dev_get_drvdata(dev);
+     struct amdgpu_device *adev = drm_to_adev(ddev);
+     ssize_t size = 0;
+     int ret;
+
+     if (amdgpu_in_reset(adev))
+             return -EPERM;

Please stop using amdgpu_in_reset() for stuff like that altogether.

Quoted 2 lines

When this is reset critical it should grab the reset rw semaphore. If it isn't than that check isn't necessary.

All of the power related sysfs files have this check. It was originally added because users have processes running which poll various hwmon files at regular intervals and since SMU also handles reset, we don't want to get a metrics table request while a reset is happening otherwise the SMU gets confused.

Alex

Quoted 34 lines

Regards,
Christian.

Quoted 29 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +19 -0
+     if (adev->in_suspend && !adev->in_runpm)
+             return -EPERM;
+
+     ret = pm_runtime_get_sync(ddev->dev);
+     if (ret < 0) {
+             pm_runtime_put_autosuspend(ddev->dev);
+             return ret;
+     }
+
+     size = amdgpu_dpm_get_pm_log(adev, buf, PAGE_SIZE);
+
+     pm_runtime_mark_last_busy(ddev->dev);
+     pm_runtime_put_autosuspend(ddev->dev);
+
+     return size;
+}
+
  /**
   * DOC: gpu_metrics
   *
@@ -2091,6 +2129,8 @@ static struct amdgpu_device_attr amdgpu_device_attrs[] = {
      AMDGPU_DEVICE_ATTR_RW(smartshift_bias,                          ATTR_FLAG_BASIC,
                            .attr_update = ss_bias_attr_update),
      AMDGPU_DEVICE_ATTR_RW(xgmi_plpd_policy,                         ATTR_FLAG_BASIC),
+     AMDGPU_DEVICE_ATTR_RO(pmlog,                                    ATTR_FLAG_BASIC,
+                           .attr_update = amdgpu_pmlog_attr_update),
  };
 
  static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
#6 lore raw

Re: [PATCH v2 4/4] drm/amd/pm: Add sysfs attribute to get pm log

Am 06.10.23 um 16:24 schrieb Alex Deucher:

Quoted 45 lines
Quoted 43 lines · Christian König

Am 06.10.23 um 07:21 schrieb Lijo Lazar:

Quoted 30 lines

Add sysfs attribute to read power management log. A snapshot is captured to the buffer when the attribute is read.

---

v2: Pass PAGE_SIZE as the max size of input buffer

   drivers/gpu/drm/amd/pm/amdgpu_pm.c | 40 ++++++++++++++++++++++++++++++
   1 file changed, 40 insertions(+)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +11 -0
index 4c65a2fac028..5a1d21c52672 100644
@@ -1794,6 +1794,44 @@ static ssize_t amdgpu_set_apu_thermal_cap(struct device *dev,
       return count;
   }
 
+static int amdgpu_pmlog_attr_update(struct amdgpu_device *adev,
+                                 struct amdgpu_device_attr *attr,
+                                 uint32_t mask,
+                                 enum amdgpu_device_attr_states *states)
+{
+     if (amdgpu_dpm_get_pm_log(adev, NULL, 0) == -EOPNOTSUPP)
+             *states = ATTR_STATE_UNSUPPORTED;
+
+     return 0;
+}
+

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_apu_thermal_cap(struct device *dev, · line 1817

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+static ssize_t amdgpu_get_pmlog(struct device *dev,
+                             struct device_attribute *attr, char *buf)
+{
+     struct drm_device *ddev = dev_get_drvdata(dev);
+     struct amdgpu_device *adev = drm_to_adev(ddev);
+     ssize_t size = 0;
+     int ret;
+
+     if (amdgpu_in_reset(adev))
+             return -EPERM;

Please stop using amdgpu_in_reset() for stuff like that altogether.

Quoted 7 lines
Quoted 2 lines

When this is reset critical it should grab the reset rw semaphore. If it isn't than that check isn't necessary.

All of the power related sysfs files have this check. It was originally added because users have processes running which poll various hwmon files at regular intervals and since SMU also handles reset, we don't want to get a metrics table request while a reset is happening otherwise the SMU gets confused.

Then this approach is completely broken. Nothing prevents the reset from starting right after doing the check.

If we need exclusive access to the SMU then we should just grab a lock.

Christian.

Quoted 35 lines

Alex

Quoted 32 lines

Regards,
Christian.

Quoted 29 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +19 -0
+     if (adev->in_suspend && !adev->in_runpm)
+             return -EPERM;
+
+     ret = pm_runtime_get_sync(ddev->dev);
+     if (ret < 0) {
+             pm_runtime_put_autosuspend(ddev->dev);
+             return ret;
+     }
+
+     size = amdgpu_dpm_get_pm_log(adev, buf, PAGE_SIZE);
+
+     pm_runtime_mark_last_busy(ddev->dev);
+     pm_runtime_put_autosuspend(ddev->dev);
+
+     return size;
+}
+
   /**
    * DOC: gpu_metrics
    *
@@ -2091,6 +2129,8 @@ static struct amdgpu_device_attr amdgpu_device_attrs[] = {
       AMDGPU_DEVICE_ATTR_RW(smartshift_bias,                          ATTR_FLAG_BASIC,
                             .attr_update = ss_bias_attr_update),
       AMDGPU_DEVICE_ATTR_RW(xgmi_plpd_policy,                         ATTR_FLAG_BASIC),
+     AMDGPU_DEVICE_ATTR_RO(pmlog,                                    ATTR_FLAG_BASIC,
+                           .attr_update = amdgpu_pmlog_attr_update),
   };
 
   static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
#7 lore raw

Re: [PATCH v2 4/4] drm/amd/pm: Add sysfs attribute to get pm log

Quoted 55 lines · Christian König

Am 06.10.23 um 16:24 schrieb Alex Deucher:

Quoted 45 lines
Quoted 43 lines · Christian König

Am 06.10.23 um 07:21 schrieb Lijo Lazar:

Quoted 30 lines

Add sysfs attribute to read power management log. A snapshot is captured to the buffer when the attribute is read.

---

v2: Pass PAGE_SIZE as the max size of input buffer

   drivers/gpu/drm/amd/pm/amdgpu_pm.c | 40 ++++++++++++++++++++++++++++++
   1 file changed, 40 insertions(+)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +11 -0
index 4c65a2fac028..5a1d21c52672 100644
@@ -1794,6 +1794,44 @@ static ssize_t amdgpu_set_apu_thermal_cap(struct device *dev,
       return count;
   }
 
+static int amdgpu_pmlog_attr_update(struct amdgpu_device *adev,
+                                 struct amdgpu_device_attr *attr,
+                                 uint32_t mask,
+                                 enum amdgpu_device_attr_states *states)
+{
+     if (amdgpu_dpm_get_pm_log(adev, NULL, 0) == -EOPNOTSUPP)
+             *states = ATTR_STATE_UNSUPPORTED;
+
+     return 0;
+}
+

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_apu_thermal_cap(struct device *dev, · line 1817

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+static ssize_t amdgpu_get_pmlog(struct device *dev,
+                             struct device_attribute *attr, char *buf)
+{
+     struct drm_device *ddev = dev_get_drvdata(dev);
+     struct amdgpu_device *adev = drm_to_adev(ddev);
+     ssize_t size = 0;
+     int ret;
+
+     if (amdgpu_in_reset(adev))
+             return -EPERM;

Please stop using amdgpu_in_reset() for stuff like that altogether.

Quoted 7 lines
Quoted 2 lines

When this is reset critical it should grab the reset rw semaphore. If it isn't than that check isn't necessary.

All of the power related sysfs files have this check. It was originally added because users have processes running which poll various hwmon files at regular intervals and since SMU also handles reset, we don't want to get a metrics table request while a reset is happening otherwise the SMU gets confused.

Quoted 4 lines

Then this approach is completely broken. Nothing prevents the reset from starting right after doing the check.

If we need exclusive access to the SMU then we should just grab a lock.

Right, but the entire file should be fixed. It's sort of orthogonal to this patch.

Alex

Quoted 39 lines

Christian.

Quoted 35 lines

Alex

Quoted 32 lines

Regards,
Christian.

Quoted 29 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +19 -0
+     if (adev->in_suspend && !adev->in_runpm)
+             return -EPERM;
+
+     ret = pm_runtime_get_sync(ddev->dev);
+     if (ret < 0) {
+             pm_runtime_put_autosuspend(ddev->dev);
+             return ret;
+     }
+
+     size = amdgpu_dpm_get_pm_log(adev, buf, PAGE_SIZE);
+
+     pm_runtime_mark_last_busy(ddev->dev);
+     pm_runtime_put_autosuspend(ddev->dev);
+
+     return size;
+}
+
   /**
    * DOC: gpu_metrics
    *
@@ -2091,6 +2129,8 @@ static struct amdgpu_device_attr amdgpu_device_attrs[] = {
       AMDGPU_DEVICE_ATTR_RW(smartshift_bias,                          ATTR_FLAG_BASIC,
                             .attr_update = ss_bias_attr_update),
       AMDGPU_DEVICE_ATTR_RW(xgmi_plpd_policy,                         ATTR_FLAG_BASIC),
+     AMDGPU_DEVICE_ATTR_RO(pmlog,                                    ATTR_FLAG_BASIC,
+                           .attr_update = amdgpu_pmlog_attr_update),
   };
 
   static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
#8 lore raw
In reply to Lijo Lazar

[AMD Official Use Only - General]

Hi Lijo,

I prefer to add a version field in header, which is used for compatible in the future, what is your idea? When the user attempts to parse this node, they cannot accurately determine the format of the content.

Best Regards,
Kevin

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 6, 2023 1:22 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH v2 1/4] drm/amdgpu: add pmlog structure definition

From: Alex Deucher <[email protected]>

Define the pmlog structures to be exposed via sysfs.

---
 drivers/gpu/drm/amd/include/kgd_pp_interface.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +15 -0
index e0bb6d39f0c3..9905228fd89c 100644
@@ -980,4 +980,19 @@ struct gpu_metrics_v2_4 {
        uint16_t                        average_soc_current;
        uint16_t                        average_gfx_current;
 };
+
+struct amdgpu_pmlog_header {
+       uint16_t structure_size;
+       uint16_t pad;
+       uint32_t mp1_ip_discovery_version;
+       uint32_t pmfw_version;
+       uint32_t pmlog_version;
+};
+
+struct amdgpu_pmlog {
+       struct amdgpu_pmlog_header common_header;
+
+       uint8_t data[];
+};
+
 #endif

--
2.25.1

#9 lore raw

[AMD Official Use Only - General]

Presently only a byte stream is intended. If version is needed, uint16_t pad can be converted to format/content revision.

@Deucher, Alexander/@StDenis, Tom, any comments on keeping a version?

Thanks,
Lijo

-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Friday, October 6, 2023 5:08 PM
To: Lazar, Lijo <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>
Subject: RE: [PATCH v2 1/4] drm/amdgpu: add pmlog structure definition

[AMD Official Use Only - General]

Hi Lijo,

I prefer to add a version field in header, which is used for compatible in the future, what is your idea? When the user attempts to parse this node, they cannot accurately determine the format of the content.

Best Regards,
Kevin

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 6, 2023 1:22 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH v2 1/4] drm/amdgpu: add pmlog structure definition

From: Alex Deucher <[email protected]>

Define the pmlog structures to be exposed via sysfs.

---
 drivers/gpu/drm/amd/include/kgd_pp_interface.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +15 -0
index e0bb6d39f0c3..9905228fd89c 100644
@@ -980,4 +980,19 @@ struct gpu_metrics_v2_4 {
        uint16_t                        average_soc_current;
        uint16_t                        average_gfx_current;
 };
+
+struct amdgpu_pmlog_header {
+       uint16_t structure_size;
+       uint16_t pad;
+       uint32_t mp1_ip_discovery_version;
+       uint32_t pmfw_version;
+       uint32_t pmlog_version;
+};
+
+struct amdgpu_pmlog {
+       struct amdgpu_pmlog_header common_header;
+
+       uint8_t data[];
+};
+
 #endif

--
2.25.1

#10 lore raw

[AMD Official Use Only - General]

I'm lost are we talking about the pmlog? umr currently just uses the pmfw_version as a key to find the correct decoding table.

Is that value not specific to a given table version?

Tom

________________________________________
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 6, 2023 08:36
To: Wang, Yang(Kevin); [email protected]; Deucher, Alexander; StDenis, Tom
Cc: Zhang, Hawking
Subject: RE: [PATCH v2 1/4] drm/amdgpu: add pmlog structure definition

[AMD Official Use Only - General]

Presently only a byte stream is intended. If version is needed, uint16_t pad can be converted to format/content revision.

@Deucher, Alexander/@StDenis, Tom, any comments on keeping a version?

Thanks,
Lijo

-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Friday, October 6, 2023 5:08 PM
To: Lazar, Lijo <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>
Subject: RE: [PATCH v2 1/4] drm/amdgpu: add pmlog structure definition

[AMD Official Use Only - General]

Hi Lijo,

I prefer to add a version field in header, which is used for compatible in the future, what is your idea? When the user attempts to parse this node, they cannot accurately determine the format of the content.

Best Regards,
Kevin

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 6, 2023 1:22 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH v2 1/4] drm/amdgpu: add pmlog structure definition

From: Alex Deucher <[email protected]>

Define the pmlog structures to be exposed via sysfs.

---
 drivers/gpu/drm/amd/include/kgd_pp_interface.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +15 -0
index e0bb6d39f0c3..9905228fd89c 100644
@@ -980,4 +980,19 @@ struct gpu_metrics_v2_4 {
        uint16_t                        average_soc_current;
        uint16_t                        average_gfx_current;
 };
+
+struct amdgpu_pmlog_header {
+       uint16_t structure_size;
+       uint16_t pad;
+       uint32_t mp1_ip_discovery_version;
+       uint32_t pmfw_version;
+       uint32_t pmlog_version;
+};
+
+struct amdgpu_pmlog {
+       struct amdgpu_pmlog_header common_header;
+
+       uint8_t data[];
+};
+
 #endif

--
2.25.1

#11 lore raw

[Public]

Hi Tom,

It's about below sort of versioning. I don't know if we will have multiple log data stacked or whether this will need a different format. So far we only get a single buffer of data from FW.

struct amdgpu_pmlog_v2 {
       struct amdgpu_pmlog_header common_header;

      <add some variables here for x,y,z?>
       uint8_t data[] or some struct here <>
};

Thanks,
Lijo

-----Original Message-----
From: StDenis, Tom <[email protected]>
Sent: Friday, October 6, 2023 6:22 PM
To: Lazar, Lijo <[email protected]>; Wang, Yang(Kevin) <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>
Cc: Zhang, Hawking <[email protected]>
Subject: Re: [PATCH v2 1/4] drm/amdgpu: add pmlog structure definition

[AMD Official Use Only - General]

I'm lost are we talking about the pmlog? umr currently just uses the pmfw_version as a key to find the correct decoding table.

Is that value not specific to a given table version?

Tom

________________________________________
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 6, 2023 08:36
To: Wang, Yang(Kevin); [email protected]; Deucher, Alexander; StDenis, Tom
Cc: Zhang, Hawking
Subject: RE: [PATCH v2 1/4] drm/amdgpu: add pmlog structure definition

[AMD Official Use Only - General]

Presently only a byte stream is intended. If version is needed, uint16_t pad can be converted to format/content revision.

@Deucher, Alexander/@StDenis, Tom, any comments on keeping a version?

Thanks,
Lijo

-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Friday, October 6, 2023 5:08 PM
To: Lazar, Lijo <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>
Subject: RE: [PATCH v2 1/4] drm/amdgpu: add pmlog structure definition

[AMD Official Use Only - General]

Hi Lijo,

I prefer to add a version field in header, which is used for compatible in the future, what is your idea? When the user attempts to parse this node, they cannot accurately determine the format of the content.

Best Regards,
Kevin

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 6, 2023 1:22 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH v2 1/4] drm/amdgpu: add pmlog structure definition

From: Alex Deucher <[email protected]>

Define the pmlog structures to be exposed via sysfs.

---
 drivers/gpu/drm/amd/include/kgd_pp_interface.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +15 -0
index e0bb6d39f0c3..9905228fd89c 100644
@@ -980,4 +980,19 @@ struct gpu_metrics_v2_4 {
        uint16_t                        average_soc_current;
        uint16_t                        average_gfx_current;
 };
+
+struct amdgpu_pmlog_header {
+       uint16_t structure_size;
+       uint16_t pad;
+       uint32_t mp1_ip_discovery_version;
+       uint32_t pmfw_version;
+       uint32_t pmlog_version;
+};
+
+struct amdgpu_pmlog {
+       struct amdgpu_pmlog_header common_header;
+
+       uint8_t data[];
+};
+
 #endif

--
2.25.1

#12 lore raw
In reply to Lazar, Lijo
Quoted 6 lines · Lijo

[AMD Official Use Only - General]

Presently only a byte stream is intended. If version is needed, uint16_t pad can be converted to format/content revision.

@Deucher, Alexander/@StDenis, Tom, any comments on keeping a version?

What version are you referring to in this case? You already have the pmfw version and the pmlog version.

Alex

Quoted 66 lines

Thanks,
Lijo

-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Friday, October 6, 2023 5:08 PM
To: Lazar, Lijo <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>
Subject: RE: [PATCH v2 1/4] drm/amdgpu: add pmlog structure definition

[AMD Official Use Only - General]

Hi Lijo,

I prefer to add a version field in header, which is used for compatible in the future, what is your idea? When the user attempts to parse this node, they cannot accurately determine the format of the content.

Best Regards,
Kevin

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 6, 2023 1:22 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH v2 1/4] drm/amdgpu: add pmlog structure definition

From: Alex Deucher <[email protected]>

Define the pmlog structures to be exposed via sysfs.

---
 drivers/gpu/drm/amd/include/kgd_pp_interface.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +15 -1
index e0bb6d39f0c3..9905228fd89c 100644
@@ -980,4 +980,19 @@ struct gpu_metrics_v2_4 {
        uint16_t                        average_soc_current;
        uint16_t                        average_gfx_current;
 };
+
+struct amdgpu_pmlog_header {
+       uint16_t structure_size;
+       uint16_t pad;
+       uint32_t mp1_ip_discovery_version;
+       uint32_t pmfw_version;
+       uint32_t pmlog_version;
+};
+
+struct amdgpu_pmlog {
+       struct amdgpu_pmlog_header common_header;
+
+       uint8_t data[];
+};
+
 #endif
--

2.25.1