public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/4] Add some extra debugging mechanisms for s0i3
@ 2022-08-29 16:29 Mario Limonciello
  2022-08-29 16:29 ` [PATCH v3 1/4] ACPI: s2idle: Add a new ->check() callback for platform_s2idle_ops Mario Limonciello
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Mario Limonciello @ 2022-08-29 16:29 UTC (permalink / raw)
  To: mario.limonciello, Len Brown, linux-acpi, platform-driver-x86,
	linux-pm
  Cc: rafael, hdegoede, linux-kernel

Recently there have been reports of problems where the system consumes
too much power after certain interrupts occur that would notify the
kernel of some event but those events aren't marked for wakeup.

These problems have been root caused to the timing of the kernel moving
the cores into ACPI C3 relative to other events from the previous wakeup
not being settled.  Linux will more aggressively move the cores into C3
for s2idle than Windows does for Modern Standby.

To aide with debugging this class of problems in the future add a new
set of optional debugging infrastructure.

Mario Limonciello (4):
  ACPI: s2idle: Add a new ->check() callback for platform_s2idle_ops
  platform/x86/amd: pmc: Add defines for STB events
  platform/x86/amd: pmc: Always write to the STB
  platform/x86/amd: pmc: Add an extra STB message for checking s2idle
    entry

 drivers/acpi/sleep.h           |  1 +
 drivers/acpi/x86/s2idle.c      | 14 ++++++++++++++
 drivers/platform/x86/amd/pmc.c | 32 ++++++++++++++++++++------------
 include/linux/acpi.h           |  1 +
 include/linux/suspend.h        |  1 +
 kernel/power/suspend.c         |  3 +++
 6 files changed, 40 insertions(+), 12 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3 1/4] ACPI: s2idle: Add a new ->check() callback for platform_s2idle_ops
  2022-08-29 16:29 [PATCH v3 0/4] Add some extra debugging mechanisms for s0i3 Mario Limonciello
@ 2022-08-29 16:29 ` Mario Limonciello
  2022-08-30 11:39   ` Rafael J. Wysocki
  2022-08-29 16:29 ` [PATCH v3 2/4] platform/x86/amd: pmc: Add defines for STB events Mario Limonciello
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Mario Limonciello @ 2022-08-29 16:29 UTC (permalink / raw)
  To: mario.limonciello, Rafael J. Wysocki, Len Brown, Pavel Machek
  Cc: hdegoede, linux-acpi, linux-kernel, linux-pm

On some platforms it is found that Linux more aggressively enters s2idle
than Windows enters Modern Standby and this uncovers some synchronization
issues for the platform.  To aid in debugging this class of problems in
the future, add support for an extra optional callback intended for
drivers to emit extra debugging.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v2->v3:
 * Rename to *check
v1->v2:
 * Add a prototype for `acpi_s2idle_enter`

 drivers/acpi/sleep.h      |  1 +
 drivers/acpi/x86/s2idle.c | 14 ++++++++++++++
 include/linux/acpi.h      |  1 +
 include/linux/suspend.h   |  1 +
 kernel/power/suspend.c    |  3 +++
 5 files changed, 20 insertions(+)

diff --git a/drivers/acpi/sleep.h b/drivers/acpi/sleep.h
index 7fe41ee489d6..d960a238be4e 100644
--- a/drivers/acpi/sleep.h
+++ b/drivers/acpi/sleep.h
@@ -18,6 +18,7 @@ static inline acpi_status acpi_set_waking_vector(u32 wakeup_address)
 extern int acpi_s2idle_begin(void);
 extern int acpi_s2idle_prepare(void);
 extern int acpi_s2idle_prepare_late(void);
+extern void acpi_s2idle_check(void);
 extern bool acpi_s2idle_wake(void);
 extern void acpi_s2idle_restore_early(void);
 extern void acpi_s2idle_restore(void);
diff --git a/drivers/acpi/x86/s2idle.c b/drivers/acpi/x86/s2idle.c
index f9ac12b778e6..474aa46f82f6 100644
--- a/drivers/acpi/x86/s2idle.c
+++ b/drivers/acpi/x86/s2idle.c
@@ -486,6 +486,19 @@ int acpi_s2idle_prepare_late(void)
 	return 0;
 }
 
+void acpi_s2idle_check(void)
+{
+	struct acpi_s2idle_dev_ops *handler;
+
+	if (!lps0_device_handle || sleep_no_lps0)
+		return;
+
+	list_for_each_entry(handler, &lps0_s2idle_devops_head, list_node) {
+		if (handler->check)
+			handler->check();
+	}
+}
+
 void acpi_s2idle_restore_early(void)
 {
 	struct acpi_s2idle_dev_ops *handler;
@@ -527,6 +540,7 @@ static const struct platform_s2idle_ops acpi_s2idle_ops_lps0 = {
 	.begin = acpi_s2idle_begin,
 	.prepare = acpi_s2idle_prepare,
 	.prepare_late = acpi_s2idle_prepare_late,
+	.check = acpi_s2idle_check,
 	.wake = acpi_s2idle_wake,
 	.restore_early = acpi_s2idle_restore_early,
 	.restore = acpi_s2idle_restore,
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 6f64b2f3dc54..acaa2ddc067d 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -1075,6 +1075,7 @@ acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state,
 struct acpi_s2idle_dev_ops {
 	struct list_head list_node;
 	void (*prepare)(void);
+	void (*check)(void);
 	void (*restore)(void);
 };
 int acpi_register_lps0_dev(struct acpi_s2idle_dev_ops *arg);
diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index 70f2921e2e70..03ed42ed2c7f 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -191,6 +191,7 @@ struct platform_s2idle_ops {
 	int (*begin)(void);
 	int (*prepare)(void);
 	int (*prepare_late)(void);
+	void (*check)(void);
 	bool (*wake)(void);
 	void (*restore_early)(void);
 	void (*restore)(void);
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 827075944d28..c6272d466e58 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -136,6 +136,9 @@ static void s2idle_loop(void)
 			break;
 		}
 
+		if (s2idle_ops && s2idle_ops->check)
+			s2idle_ops->check();
+
 		s2idle_enter();
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 2/4] platform/x86/amd: pmc: Add defines for STB events
  2022-08-29 16:29 [PATCH v3 0/4] Add some extra debugging mechanisms for s0i3 Mario Limonciello
  2022-08-29 16:29 ` [PATCH v3 1/4] ACPI: s2idle: Add a new ->check() callback for platform_s2idle_ops Mario Limonciello
@ 2022-08-29 16:29 ` Mario Limonciello
  2022-08-29 16:29 ` [PATCH v3 3/4] platform/x86/amd: pmc: Always write to the STB Mario Limonciello
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Mario Limonciello @ 2022-08-29 16:29 UTC (permalink / raw)
  To: mario.limonciello, Shyam Sundar S K
  Cc: rafael, hdegoede, Mark Gross, platform-driver-x86, linux-kernel

Currently `amd-pmc` has two events, but just adds one to the first to
distinguish the second.  Add a clear definition what these events mean.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/platform/x86/amd/pmc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/amd/pmc.c b/drivers/platform/x86/amd/pmc.c
index 700eb19e8450..39e6ab88861d 100644
--- a/drivers/platform/x86/amd/pmc.c
+++ b/drivers/platform/x86/amd/pmc.c
@@ -39,7 +39,8 @@
 #define AMD_PMC_STB_INDEX_ADDRESS	0xF8
 #define AMD_PMC_STB_INDEX_DATA		0xFC
 #define AMD_PMC_STB_PMI_0		0x03E30600
-#define AMD_PMC_STB_PREDEF		0xC6000001
+#define AMD_PMC_STB_S2IDLE_PREPARE	0xC6000001
+#define AMD_PMC_STB_S2IDLE_RESTORE	0xC6000002
 
 /* STB S2D(Spill to DRAM) has different message port offset */
 #define STB_SPILL_TO_DRAM		0xBE
@@ -701,7 +702,7 @@ static void amd_pmc_s2idle_prepare(void)
 	}
 
 	if (enable_stb) {
-		rc = amd_pmc_write_stb(pdev, AMD_PMC_STB_PREDEF);
+		rc = amd_pmc_write_stb(pdev, AMD_PMC_STB_S2IDLE_PREPARE);
 		if (rc)
 			dev_err(pdev->dev, "error writing to STB: %d\n", rc);
 	}
@@ -724,9 +725,8 @@ static void amd_pmc_s2idle_restore(void)
 	/* Dump the IdleMask to see the blockers */
 	amd_pmc_idlemask_read(pdev, pdev->dev, NULL);
 
-	/* Write data incremented by 1 to distinguish in stb_read */
 	if (enable_stb) {
-		rc = amd_pmc_write_stb(pdev, AMD_PMC_STB_PREDEF + 1);
+		rc = amd_pmc_write_stb(pdev, AMD_PMC_STB_S2IDLE_RESTORE);
 		if (rc)
 			dev_err(pdev->dev, "error writing to STB: %d\n", rc);
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 3/4] platform/x86/amd: pmc: Always write to the STB
  2022-08-29 16:29 [PATCH v3 0/4] Add some extra debugging mechanisms for s0i3 Mario Limonciello
  2022-08-29 16:29 ` [PATCH v3 1/4] ACPI: s2idle: Add a new ->check() callback for platform_s2idle_ops Mario Limonciello
  2022-08-29 16:29 ` [PATCH v3 2/4] platform/x86/amd: pmc: Add defines for STB events Mario Limonciello
@ 2022-08-29 16:29 ` Mario Limonciello
  2022-08-29 16:29 ` [PATCH v3 4/4] platform/x86/amd: pmc: Add an extra STB message for checking s2idle entry Mario Limonciello
  2022-09-09 16:01 ` [PATCH v3 0/4] Add some extra debugging mechanisms for s0i3 Hans de Goede
  4 siblings, 0 replies; 9+ messages in thread
From: Mario Limonciello @ 2022-08-29 16:29 UTC (permalink / raw)
  To: mario.limonciello, Shyam Sundar S K
  Cc: rafael, hdegoede, Mark Gross, platform-driver-x86, linux-kernel

The kernel parameter `enable_stb` currently gates the access to the STB
from debugfs and also controls whether the kernel writes events to the
STB.

Even if not accessing STB data from the kernel it's useful to have this
data stored to review the STB. So in suspend/resume always write it.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/platform/x86/amd/pmc.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/platform/x86/amd/pmc.c b/drivers/platform/x86/amd/pmc.c
index 39e6ab88861d..fba42036682d 100644
--- a/drivers/platform/x86/amd/pmc.c
+++ b/drivers/platform/x86/amd/pmc.c
@@ -701,11 +701,9 @@ static void amd_pmc_s2idle_prepare(void)
 		return;
 	}
 
-	if (enable_stb) {
-		rc = amd_pmc_write_stb(pdev, AMD_PMC_STB_S2IDLE_PREPARE);
-		if (rc)
-			dev_err(pdev->dev, "error writing to STB: %d\n", rc);
-	}
+	rc = amd_pmc_write_stb(pdev, AMD_PMC_STB_S2IDLE_PREPARE);
+	if (rc)
+		dev_err(pdev->dev, "error writing to STB: %d\n", rc);
 }
 
 static void amd_pmc_s2idle_restore(void)
@@ -725,11 +723,9 @@ static void amd_pmc_s2idle_restore(void)
 	/* Dump the IdleMask to see the blockers */
 	amd_pmc_idlemask_read(pdev, pdev->dev, NULL);
 
-	if (enable_stb) {
-		rc = amd_pmc_write_stb(pdev, AMD_PMC_STB_S2IDLE_RESTORE);
-		if (rc)
-			dev_err(pdev->dev, "error writing to STB: %d\n", rc);
-	}
+	rc = amd_pmc_write_stb(pdev, AMD_PMC_STB_S2IDLE_RESTORE);
+	if (rc)
+		dev_err(pdev->dev, "error writing to STB: %d\n", rc);
 
 	/* Notify on failed entry */
 	amd_pmc_validate_deepest(pdev);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 4/4] platform/x86/amd: pmc: Add an extra STB message for checking s2idle entry
  2022-08-29 16:29 [PATCH v3 0/4] Add some extra debugging mechanisms for s0i3 Mario Limonciello
                   ` (2 preceding siblings ...)
  2022-08-29 16:29 ` [PATCH v3 3/4] platform/x86/amd: pmc: Always write to the STB Mario Limonciello
@ 2022-08-29 16:29 ` Mario Limonciello
  2022-09-09 16:01 ` [PATCH v3 0/4] Add some extra debugging mechanisms for s0i3 Hans de Goede
  4 siblings, 0 replies; 9+ messages in thread
From: Mario Limonciello @ 2022-08-29 16:29 UTC (permalink / raw)
  To: mario.limonciello, Shyam Sundar S K
  Cc: rafael, hdegoede, Mark Gross, platform-driver-x86, linux-kernel

The `check` callback is run right before the cores are put into HLT.
This will allow checking synchronization problems with other software
that writes into the STB.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v2->v3:
 * Update for changes in patch 1/4.

 drivers/platform/x86/amd/pmc.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/platform/x86/amd/pmc.c b/drivers/platform/x86/amd/pmc.c
index fba42036682d..32887687f888 100644
--- a/drivers/platform/x86/amd/pmc.c
+++ b/drivers/platform/x86/amd/pmc.c
@@ -41,6 +41,7 @@
 #define AMD_PMC_STB_PMI_0		0x03E30600
 #define AMD_PMC_STB_S2IDLE_PREPARE	0xC6000001
 #define AMD_PMC_STB_S2IDLE_RESTORE	0xC6000002
+#define AMD_PMC_STB_S2IDLE_CHECK	0xC6000003
 
 /* STB S2D(Spill to DRAM) has different message port offset */
 #define STB_SPILL_TO_DRAM		0xBE
@@ -706,6 +707,16 @@ static void amd_pmc_s2idle_prepare(void)
 		dev_err(pdev->dev, "error writing to STB: %d\n", rc);
 }
 
+static void amd_pmc_s2idle_check(void)
+{
+	struct amd_pmc_dev *pdev = &pmc;
+	int rc;
+
+	rc = amd_pmc_write_stb(pdev, AMD_PMC_STB_S2IDLE_CHECK);
+	if (rc)
+		dev_err(pdev->dev, "error writing to STB: %d\n", rc);
+}
+
 static void amd_pmc_s2idle_restore(void)
 {
 	struct amd_pmc_dev *pdev = &pmc;
@@ -733,6 +744,7 @@ static void amd_pmc_s2idle_restore(void)
 
 static struct acpi_s2idle_dev_ops amd_pmc_s2idle_dev_ops = {
 	.prepare = amd_pmc_s2idle_prepare,
+	.check = amd_pmc_s2idle_check,
 	.restore = amd_pmc_s2idle_restore,
 };
 #endif
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 1/4] ACPI: s2idle: Add a new ->check() callback for platform_s2idle_ops
  2022-08-29 16:29 ` [PATCH v3 1/4] ACPI: s2idle: Add a new ->check() callback for platform_s2idle_ops Mario Limonciello
@ 2022-08-30 11:39   ` Rafael J. Wysocki
  2022-08-30 11:42     ` Limonciello, Mario
  0 siblings, 1 reply; 9+ messages in thread
From: Rafael J. Wysocki @ 2022-08-30 11:39 UTC (permalink / raw)
  To: Mario Limonciello
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Hans de Goede,
	ACPI Devel Maling List, Linux Kernel Mailing List, Linux PM

On Mon, Aug 29, 2022 at 6:29 PM Mario Limonciello
<mario.limonciello@amd.com> wrote:
>
> On some platforms it is found that Linux more aggressively enters s2idle
> than Windows enters Modern Standby and this uncovers some synchronization
> issues for the platform.  To aid in debugging this class of problems in
> the future, add support for an extra optional callback intended for
> drivers to emit extra debugging.
>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

and I'm assuming that this is for Hans.

> ---
> v2->v3:
>  * Rename to *check
> v1->v2:
>  * Add a prototype for `acpi_s2idle_enter`
>
>  drivers/acpi/sleep.h      |  1 +
>  drivers/acpi/x86/s2idle.c | 14 ++++++++++++++
>  include/linux/acpi.h      |  1 +
>  include/linux/suspend.h   |  1 +
>  kernel/power/suspend.c    |  3 +++
>  5 files changed, 20 insertions(+)
>
> diff --git a/drivers/acpi/sleep.h b/drivers/acpi/sleep.h
> index 7fe41ee489d6..d960a238be4e 100644
> --- a/drivers/acpi/sleep.h
> +++ b/drivers/acpi/sleep.h
> @@ -18,6 +18,7 @@ static inline acpi_status acpi_set_waking_vector(u32 wakeup_address)
>  extern int acpi_s2idle_begin(void);
>  extern int acpi_s2idle_prepare(void);
>  extern int acpi_s2idle_prepare_late(void);
> +extern void acpi_s2idle_check(void);
>  extern bool acpi_s2idle_wake(void);
>  extern void acpi_s2idle_restore_early(void);
>  extern void acpi_s2idle_restore(void);
> diff --git a/drivers/acpi/x86/s2idle.c b/drivers/acpi/x86/s2idle.c
> index f9ac12b778e6..474aa46f82f6 100644
> --- a/drivers/acpi/x86/s2idle.c
> +++ b/drivers/acpi/x86/s2idle.c
> @@ -486,6 +486,19 @@ int acpi_s2idle_prepare_late(void)
>         return 0;
>  }
>
> +void acpi_s2idle_check(void)
> +{
> +       struct acpi_s2idle_dev_ops *handler;
> +
> +       if (!lps0_device_handle || sleep_no_lps0)
> +               return;
> +
> +       list_for_each_entry(handler, &lps0_s2idle_devops_head, list_node) {
> +               if (handler->check)
> +                       handler->check();
> +       }
> +}
> +
>  void acpi_s2idle_restore_early(void)
>  {
>         struct acpi_s2idle_dev_ops *handler;
> @@ -527,6 +540,7 @@ static const struct platform_s2idle_ops acpi_s2idle_ops_lps0 = {
>         .begin = acpi_s2idle_begin,
>         .prepare = acpi_s2idle_prepare,
>         .prepare_late = acpi_s2idle_prepare_late,
> +       .check = acpi_s2idle_check,
>         .wake = acpi_s2idle_wake,
>         .restore_early = acpi_s2idle_restore_early,
>         .restore = acpi_s2idle_restore,
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 6f64b2f3dc54..acaa2ddc067d 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -1075,6 +1075,7 @@ acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state,
>  struct acpi_s2idle_dev_ops {
>         struct list_head list_node;
>         void (*prepare)(void);
> +       void (*check)(void);
>         void (*restore)(void);
>  };
>  int acpi_register_lps0_dev(struct acpi_s2idle_dev_ops *arg);
> diff --git a/include/linux/suspend.h b/include/linux/suspend.h
> index 70f2921e2e70..03ed42ed2c7f 100644
> --- a/include/linux/suspend.h
> +++ b/include/linux/suspend.h
> @@ -191,6 +191,7 @@ struct platform_s2idle_ops {
>         int (*begin)(void);
>         int (*prepare)(void);
>         int (*prepare_late)(void);
> +       void (*check)(void);
>         bool (*wake)(void);
>         void (*restore_early)(void);
>         void (*restore)(void);
> diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
> index 827075944d28..c6272d466e58 100644
> --- a/kernel/power/suspend.c
> +++ b/kernel/power/suspend.c
> @@ -136,6 +136,9 @@ static void s2idle_loop(void)
>                         break;
>                 }
>
> +               if (s2idle_ops && s2idle_ops->check)
> +                       s2idle_ops->check();
> +
>                 s2idle_enter();
>         }
>
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 1/4] ACPI: s2idle: Add a new ->check() callback for platform_s2idle_ops
  2022-08-30 11:39   ` Rafael J. Wysocki
@ 2022-08-30 11:42     ` Limonciello, Mario
  2022-08-30 14:50       ` Hans de Goede
  0 siblings, 1 reply; 9+ messages in thread
From: Limonciello, Mario @ 2022-08-30 11:42 UTC (permalink / raw)
  To: Rafael J. Wysocki, Hans de Goede
  Cc: Len Brown, Pavel Machek, ACPI Devel Maling List,
	Linux Kernel Mailing List, Linux PM, Shyam-sundar S-k

On 8/30/2022 06:39, Rafael J. Wysocki wrote:
> On Mon, Aug 29, 2022 at 6:29 PM Mario Limonciello
> <mario.limonciello@amd.com> wrote:
>>
>> On some platforms it is found that Linux more aggressively enters s2idle
>> than Windows enters Modern Standby and this uncovers some synchronization
>> issues for the platform.  To aid in debugging this class of problems in
>> the future, add support for an extra optional callback intended for
>> drivers to emit extra debugging.
>>
>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> 
> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> and I'm assuming that this is for Hans.

Thanks, and yeah I think it makes more sense for this to go through 
platform-x86.

> 
>> ---
>> v2->v3:
>>   * Rename to *check
>> v1->v2:
>>   * Add a prototype for `acpi_s2idle_enter`
>>
>>   drivers/acpi/sleep.h      |  1 +
>>   drivers/acpi/x86/s2idle.c | 14 ++++++++++++++
>>   include/linux/acpi.h      |  1 +
>>   include/linux/suspend.h   |  1 +
>>   kernel/power/suspend.c    |  3 +++
>>   5 files changed, 20 insertions(+)
>>
>> diff --git a/drivers/acpi/sleep.h b/drivers/acpi/sleep.h
>> index 7fe41ee489d6..d960a238be4e 100644
>> --- a/drivers/acpi/sleep.h
>> +++ b/drivers/acpi/sleep.h
>> @@ -18,6 +18,7 @@ static inline acpi_status acpi_set_waking_vector(u32 wakeup_address)
>>   extern int acpi_s2idle_begin(void);
>>   extern int acpi_s2idle_prepare(void);
>>   extern int acpi_s2idle_prepare_late(void);
>> +extern void acpi_s2idle_check(void);
>>   extern bool acpi_s2idle_wake(void);
>>   extern void acpi_s2idle_restore_early(void);
>>   extern void acpi_s2idle_restore(void);
>> diff --git a/drivers/acpi/x86/s2idle.c b/drivers/acpi/x86/s2idle.c
>> index f9ac12b778e6..474aa46f82f6 100644
>> --- a/drivers/acpi/x86/s2idle.c
>> +++ b/drivers/acpi/x86/s2idle.c
>> @@ -486,6 +486,19 @@ int acpi_s2idle_prepare_late(void)
>>          return 0;
>>   }
>>
>> +void acpi_s2idle_check(void)
>> +{
>> +       struct acpi_s2idle_dev_ops *handler;
>> +
>> +       if (!lps0_device_handle || sleep_no_lps0)
>> +               return;
>> +
>> +       list_for_each_entry(handler, &lps0_s2idle_devops_head, list_node) {
>> +               if (handler->check)
>> +                       handler->check();
>> +       }
>> +}
>> +
>>   void acpi_s2idle_restore_early(void)
>>   {
>>          struct acpi_s2idle_dev_ops *handler;
>> @@ -527,6 +540,7 @@ static const struct platform_s2idle_ops acpi_s2idle_ops_lps0 = {
>>          .begin = acpi_s2idle_begin,
>>          .prepare = acpi_s2idle_prepare,
>>          .prepare_late = acpi_s2idle_prepare_late,
>> +       .check = acpi_s2idle_check,
>>          .wake = acpi_s2idle_wake,
>>          .restore_early = acpi_s2idle_restore_early,
>>          .restore = acpi_s2idle_restore,
>> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
>> index 6f64b2f3dc54..acaa2ddc067d 100644
>> --- a/include/linux/acpi.h
>> +++ b/include/linux/acpi.h
>> @@ -1075,6 +1075,7 @@ acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state,
>>   struct acpi_s2idle_dev_ops {
>>          struct list_head list_node;
>>          void (*prepare)(void);
>> +       void (*check)(void);
>>          void (*restore)(void);
>>   };
>>   int acpi_register_lps0_dev(struct acpi_s2idle_dev_ops *arg);
>> diff --git a/include/linux/suspend.h b/include/linux/suspend.h
>> index 70f2921e2e70..03ed42ed2c7f 100644
>> --- a/include/linux/suspend.h
>> +++ b/include/linux/suspend.h
>> @@ -191,6 +191,7 @@ struct platform_s2idle_ops {
>>          int (*begin)(void);
>>          int (*prepare)(void);
>>          int (*prepare_late)(void);
>> +       void (*check)(void);
>>          bool (*wake)(void);
>>          void (*restore_early)(void);
>>          void (*restore)(void);
>> diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
>> index 827075944d28..c6272d466e58 100644
>> --- a/kernel/power/suspend.c
>> +++ b/kernel/power/suspend.c
>> @@ -136,6 +136,9 @@ static void s2idle_loop(void)
>>                          break;
>>                  }
>>
>> +               if (s2idle_ops && s2idle_ops->check)
>> +                       s2idle_ops->check();
>> +
>>                  s2idle_enter();
>>          }
>>
>> --
>> 2.34.1
>>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 1/4] ACPI: s2idle: Add a new ->check() callback for platform_s2idle_ops
  2022-08-30 11:42     ` Limonciello, Mario
@ 2022-08-30 14:50       ` Hans de Goede
  0 siblings, 0 replies; 9+ messages in thread
From: Hans de Goede @ 2022-08-30 14:50 UTC (permalink / raw)
  To: Limonciello, Mario, Rafael J. Wysocki
  Cc: Len Brown, Pavel Machek, ACPI Devel Maling List,
	Linux Kernel Mailing List, Linux PM, Shyam-sundar S-k

Hi,

On 8/30/22 13:42, Limonciello, Mario wrote:
> On 8/30/2022 06:39, Rafael J. Wysocki wrote:
>> On Mon, Aug 29, 2022 at 6:29 PM Mario Limonciello
>> <mario.limonciello@amd.com> wrote:
>>>
>>> On some platforms it is found that Linux more aggressively enters s2idle
>>> than Windows enters Modern Standby and this uncovers some synchronization
>>> issues for the platform.  To aid in debugging this class of problems in
>>> the future, add support for an extra optional callback intended for
>>> drivers to emit extra debugging.
>>>
>>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
>>
>> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>
>> and I'm assuming that this is for Hans.
> 
> Thanks, and yeah I think it makes more sense for this to go through platform-x86.

Ok, I will review 2-4 and merge the entire series
through platform-x86.

Regards,

Hans


> 
>>
>>> ---
>>> v2->v3:
>>>   * Rename to *check
>>> v1->v2:
>>>   * Add a prototype for `acpi_s2idle_enter`
>>>
>>>   drivers/acpi/sleep.h      |  1 +
>>>   drivers/acpi/x86/s2idle.c | 14 ++++++++++++++
>>>   include/linux/acpi.h      |  1 +
>>>   include/linux/suspend.h   |  1 +
>>>   kernel/power/suspend.c    |  3 +++
>>>   5 files changed, 20 insertions(+)
>>>
>>> diff --git a/drivers/acpi/sleep.h b/drivers/acpi/sleep.h
>>> index 7fe41ee489d6..d960a238be4e 100644
>>> --- a/drivers/acpi/sleep.h
>>> +++ b/drivers/acpi/sleep.h
>>> @@ -18,6 +18,7 @@ static inline acpi_status acpi_set_waking_vector(u32 wakeup_address)
>>>   extern int acpi_s2idle_begin(void);
>>>   extern int acpi_s2idle_prepare(void);
>>>   extern int acpi_s2idle_prepare_late(void);
>>> +extern void acpi_s2idle_check(void);
>>>   extern bool acpi_s2idle_wake(void);
>>>   extern void acpi_s2idle_restore_early(void);
>>>   extern void acpi_s2idle_restore(void);
>>> diff --git a/drivers/acpi/x86/s2idle.c b/drivers/acpi/x86/s2idle.c
>>> index f9ac12b778e6..474aa46f82f6 100644
>>> --- a/drivers/acpi/x86/s2idle.c
>>> +++ b/drivers/acpi/x86/s2idle.c
>>> @@ -486,6 +486,19 @@ int acpi_s2idle_prepare_late(void)
>>>          return 0;
>>>   }
>>>
>>> +void acpi_s2idle_check(void)
>>> +{
>>> +       struct acpi_s2idle_dev_ops *handler;
>>> +
>>> +       if (!lps0_device_handle || sleep_no_lps0)
>>> +               return;
>>> +
>>> +       list_for_each_entry(handler, &lps0_s2idle_devops_head, list_node) {
>>> +               if (handler->check)
>>> +                       handler->check();
>>> +       }
>>> +}
>>> +
>>>   void acpi_s2idle_restore_early(void)
>>>   {
>>>          struct acpi_s2idle_dev_ops *handler;
>>> @@ -527,6 +540,7 @@ static const struct platform_s2idle_ops acpi_s2idle_ops_lps0 = {
>>>          .begin = acpi_s2idle_begin,
>>>          .prepare = acpi_s2idle_prepare,
>>>          .prepare_late = acpi_s2idle_prepare_late,
>>> +       .check = acpi_s2idle_check,
>>>          .wake = acpi_s2idle_wake,
>>>          .restore_early = acpi_s2idle_restore_early,
>>>          .restore = acpi_s2idle_restore,
>>> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
>>> index 6f64b2f3dc54..acaa2ddc067d 100644
>>> --- a/include/linux/acpi.h
>>> +++ b/include/linux/acpi.h
>>> @@ -1075,6 +1075,7 @@ acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state,
>>>   struct acpi_s2idle_dev_ops {
>>>          struct list_head list_node;
>>>          void (*prepare)(void);
>>> +       void (*check)(void);
>>>          void (*restore)(void);
>>>   };
>>>   int acpi_register_lps0_dev(struct acpi_s2idle_dev_ops *arg);
>>> diff --git a/include/linux/suspend.h b/include/linux/suspend.h
>>> index 70f2921e2e70..03ed42ed2c7f 100644
>>> --- a/include/linux/suspend.h
>>> +++ b/include/linux/suspend.h
>>> @@ -191,6 +191,7 @@ struct platform_s2idle_ops {
>>>          int (*begin)(void);
>>>          int (*prepare)(void);
>>>          int (*prepare_late)(void);
>>> +       void (*check)(void);
>>>          bool (*wake)(void);
>>>          void (*restore_early)(void);
>>>          void (*restore)(void);
>>> diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
>>> index 827075944d28..c6272d466e58 100644
>>> --- a/kernel/power/suspend.c
>>> +++ b/kernel/power/suspend.c
>>> @@ -136,6 +136,9 @@ static void s2idle_loop(void)
>>>                          break;
>>>                  }
>>>
>>> +               if (s2idle_ops && s2idle_ops->check)
>>> +                       s2idle_ops->check();
>>> +
>>>                  s2idle_enter();
>>>          }
>>>
>>> -- 
>>> 2.34.1
>>>
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 0/4] Add some extra debugging mechanisms for s0i3
  2022-08-29 16:29 [PATCH v3 0/4] Add some extra debugging mechanisms for s0i3 Mario Limonciello
                   ` (3 preceding siblings ...)
  2022-08-29 16:29 ` [PATCH v3 4/4] platform/x86/amd: pmc: Add an extra STB message for checking s2idle entry Mario Limonciello
@ 2022-09-09 16:01 ` Hans de Goede
  4 siblings, 0 replies; 9+ messages in thread
From: Hans de Goede @ 2022-09-09 16:01 UTC (permalink / raw)
  To: Mario Limonciello, Len Brown, linux-acpi, platform-driver-x86,
	linux-pm
  Cc: rafael, linux-kernel

Hi All,

On 8/29/22 18:29, Mario Limonciello wrote:
> Recently there have been reports of problems where the system consumes
> too much power after certain interrupts occur that would notify the
> kernel of some event but those events aren't marked for wakeup.
> 
> These problems have been root caused to the timing of the kernel moving
> the cores into ACPI C3 relative to other events from the previous wakeup
> not being settled.  Linux will more aggressively move the cores into C3
> for s2idle than Windows does for Modern Standby.
> 
> To aide with debugging this class of problems in the future add a new
> set of optional debugging infrastructure.
> 
> Mario Limonciello (4):
>   ACPI: s2idle: Add a new ->check() callback for platform_s2idle_ops
>   platform/x86/amd: pmc: Add defines for STB events
>   platform/x86/amd: pmc: Always write to the STB
>   platform/x86/amd: pmc: Add an extra STB message for checking s2idle
>     entry


Thank you for your patch-series, I've applied the series 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



> 
>  drivers/acpi/sleep.h           |  1 +
>  drivers/acpi/x86/s2idle.c      | 14 ++++++++++++++
>  drivers/platform/x86/amd/pmc.c | 32 ++++++++++++++++++++------------
>  include/linux/acpi.h           |  1 +
>  include/linux/suspend.h        |  1 +
>  kernel/power/suspend.c         |  3 +++
>  6 files changed, 40 insertions(+), 12 deletions(-)
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-09-09 16:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-29 16:29 [PATCH v3 0/4] Add some extra debugging mechanisms for s0i3 Mario Limonciello
2022-08-29 16:29 ` [PATCH v3 1/4] ACPI: s2idle: Add a new ->check() callback for platform_s2idle_ops Mario Limonciello
2022-08-30 11:39   ` Rafael J. Wysocki
2022-08-30 11:42     ` Limonciello, Mario
2022-08-30 14:50       ` Hans de Goede
2022-08-29 16:29 ` [PATCH v3 2/4] platform/x86/amd: pmc: Add defines for STB events Mario Limonciello
2022-08-29 16:29 ` [PATCH v3 3/4] platform/x86/amd: pmc: Always write to the STB Mario Limonciello
2022-08-29 16:29 ` [PATCH v3 4/4] platform/x86/amd: pmc: Add an extra STB message for checking s2idle entry Mario Limonciello
2022-09-09 16:01 ` [PATCH v3 0/4] Add some extra debugging mechanisms for s0i3 Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox