Skip to contentSkip to conversation

platform/x86: amd-pmc: Validate entry into the deepest state on resume

PATCH In review Mario Limonciello 2 participants 2 messages Mar 10, 2022 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 platform/x86: amd-pmc: Validate entry into the deepest state on resume

Currently the only way to discover if a system went into the deepest sleep state is to read from sysfs after you finished suspend.

To better illustrate to users that problems have occurred, check as part of resume and display a warning.

---
changes from v1->v2
* rebase on platform-x86.git/review-hans

 drivers/platform/x86/amd-pmc.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
drivers/platform/x86/amd-pmc.c +26 -3
index fc0b4d628dec..971aaabaa9c8 100644
@@ -322,6 +322,28 @@ static int amd_pmc_idlemask_read(struct amd_pmc_dev *pdev, struct device *dev,
 	return 0;
 }
 
+static int get_metrics_table(struct amd_pmc_dev *pdev, struct smu_metrics *table)
+{
+	if (pdev->cpu_id == AMD_CPU_ID_PCO)
+		return -ENODEV;
+	memcpy_fromio(table, pdev->smu_virt_addr, sizeof(struct smu_metrics));
+	return 0;
+}
+
+static void amd_pmc_validate_deepest(struct amd_pmc_dev *pdev)
+{
+	struct smu_metrics table;
+
+	if (get_metrics_table(pdev, &table))
+		return;
+
+	if (!table.s0i3_last_entry_status)
+		dev_warn(pdev->dev, "Last suspend didn't reach deepest state\n");
+	else
+		dev_dbg(pdev->dev, "Last suspend in deepest state for %lluus\n",
+			 table.timein_s0i3_lastcapture);
+}
+
 #ifdef CONFIG_DEBUG_FS
 static int smu_fw_info_show(struct seq_file *s, void *unused)
 {
@@ -329,11 +351,9 @@ static int smu_fw_info_show(struct seq_file *s, void *unused)
 	struct smu_metrics table;
 	int idx;
 
-	if (dev->cpu_id == AMD_CPU_ID_PCO)
+	if (get_metrics_table(dev, &table))
 		return -EINVAL;
 
-	memcpy_fromio(&table, dev->smu_virt_addr, sizeof(struct smu_metrics));
-
 	seq_puts(s, "\n=== SMU Statistics ===\n");
 	seq_printf(s, "Table Version: %d\n", table.table_version);
 	seq_printf(s, "Hint Count: %d\n", table.hint_count);
@@ -689,6 +709,9 @@ static int __maybe_unused amd_pmc_resume(struct device *dev)
 		cpu_latency_qos_update_request(&pdev->amd_pmc_pm_qos_req,
 						PM_QOS_DEFAULT_VALUE);
 
+	/* Notify on failed entry */
+	amd_pmc_validate_deepest(pdev);
+
 	return rc;
 }
 
Signature · 1 line
2.34.1
#1 lore raw

Hi,

Quoted 7 lines · Mario Limonciello

Currently the only way to discover if a system went into the deepest sleep state is to read from sysfs after you finished suspend.

To better illustrate to users that problems have occurred, check as part of resume and display a warning.

Thank you for your patch, I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.

Regards,

Hans

Quoted 62 lines

---
changes from v1->v2
* rebase on platform-x86.git/review-hans

 drivers/platform/x86/amd-pmc.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
drivers/platform/x86/amd-pmc.c +26 -3
index fc0b4d628dec..971aaabaa9c8 100644
@@ -322,6 +322,28 @@ static int amd_pmc_idlemask_read(struct amd_pmc_dev *pdev, struct device *dev,
 	return 0;
 }
 
+static int get_metrics_table(struct amd_pmc_dev *pdev, struct smu_metrics *table)
+{
+	if (pdev->cpu_id == AMD_CPU_ID_PCO)
+		return -ENODEV;
+	memcpy_fromio(table, pdev->smu_virt_addr, sizeof(struct smu_metrics));
+	return 0;
+}
+
+static void amd_pmc_validate_deepest(struct amd_pmc_dev *pdev)
+{
+	struct smu_metrics table;
+
+	if (get_metrics_table(pdev, &table))
+		return;
+
+	if (!table.s0i3_last_entry_status)
+		dev_warn(pdev->dev, "Last suspend didn't reach deepest state\n");
+	else
+		dev_dbg(pdev->dev, "Last suspend in deepest state for %lluus\n",
+			 table.timein_s0i3_lastcapture);
+}
+
 #ifdef CONFIG_DEBUG_FS
 static int smu_fw_info_show(struct seq_file *s, void *unused)
 {
@@ -329,11 +351,9 @@ static int smu_fw_info_show(struct seq_file *s, void *unused)
 	struct smu_metrics table;
 	int idx;
 
-	if (dev->cpu_id == AMD_CPU_ID_PCO)
+	if (get_metrics_table(dev, &table))
 		return -EINVAL;
 
-	memcpy_fromio(&table, dev->smu_virt_addr, sizeof(struct smu_metrics));
-
 	seq_puts(s, "\n=== SMU Statistics ===\n");
 	seq_printf(s, "Table Version: %d\n", table.table_version);
 	seq_printf(s, "Hint Count: %d\n", table.hint_count);
@@ -689,6 +709,9 @@ static int __maybe_unused amd_pmc_resume(struct device *dev)
 		cpu_latency_qos_update_request(&pdev->amd_pmc_pm_qos_req,
 						PM_QOS_DEFAULT_VALUE);
 
+	/* Notify on failed entry */
+	amd_pmc_validate_deepest(pdev);
+
 	return rc;
 }