Re: Regression, thermal: core: battery reading wrong after wake from S3 [Was: Bug Report according to thermal_core.c]

From: Rafael J. Wysocki
Date: Thu Jun 13 2024 - 11:14:51 EST


On Wed, Jun 12, 2024 at 7:23 PM Rafael J. Wysocki <rafael@xxxxxxxxxx> wrote:
>
> Restored list CCs.
>
> On Wed, Jun 12, 2024 at 3:41 PM Rafael J. Wysocki <rafael@xxxxxxxxxx> wrote:
> >
> > On Wed, Jun 12, 2024 at 11:56 AM fhortner@xxxxxxxx <fhortner@xxxxxxxx> wrote:
> > >
> > > Am 11.06.24 um 16:42 schrieb Rafael J. Wysocki:
> > >
> > > This doesn't make them run in a different order, it just delays both
> > > of them, because the notifiers are called sequentially.
> > >
> > > However, if you added the msleep() at the beginning of
> > > thermal_zone_device_resume(), it would change the ordering of this
> > > function with respect to the PM notifiers, so please try doing this.
> > >
> > > I did so and added msleep(1000) to thermal_core.c line 1634
> > > I have also reverted the patch you sent me.
> > >
> > > The battery readings after resume from S3 sleep where fine.
> > > I have tried 2 reboots with 4 sleep/wake cycles, respectively
> >
> > Thanks!
> >
> > This means that the two code paths in question somehow interfere
> > destructively when they are running in parallel with each other.
>
> One more thing to try is the attached patch (independent of the
> previous one) to lower the priority of the thermal PM notifier to make
> it run always after the ACPI battery one.
>
> Please test this one too and let me know if it works for you.

Attached is a slightly modified version of the last patch I sent.
Please test it and let me know if it addresses the problem you are
seeing.

If it helps, I think we are done with this at least for now.
---
drivers/thermal/thermal_core.c | 6 ++++++
1 file changed, 6 insertions(+)

Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.c
+++ linux-pm/drivers/thermal/thermal_core.c
@@ -1712,6 +1712,12 @@ static int thermal_pm_notify(struct noti

static struct notifier_block thermal_pm_nb = {
.notifier_call = thermal_pm_notify,
+ /*
+ * Run at the lowest priority to avoid interference between the thermal
+ * zone resume work items spawned by thermal_pm_notify() and the other
+ * PM notifiers.
+ */
+ .priority = INT_MIN,
};

static int __init thermal_init(void)