All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power: ab8500_chargalg: Use CLOCK_MONOTONIC
@ 2022-03-08 15:44 Linus Walleij
  2022-03-09  6:45 ` Vaittinen, Matti
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2022-03-08 15:44 UTC (permalink / raw)
  To: Sebastian Reichel, Marcus Cooper
  Cc: linux-pm, Matti Vaittinen, Linus Walleij, Lee Jones, Matti Vaittinen

The HRTimer in the AB8500 charging code is using CLOCK_REALTIME
to set an alarm some hours forward in time +/- 5 min for a safety
timer.

I have observed that this will sometimes fire sporadically
early when charging a battery with the result that
charging stops.

As CLOCK_REALTIME can be subject to adjustments of time from
sources such as NTP, this cannot be trusted and will likely
for example fire events if the clock is set forward some hours
by say NTP.

Use CLOCK_MONOTONIC as indicated in other instances and the
problem goes away. Also initialize the timer to REL mode
as this is what will be used later.

Fixes: 257107ae6b9b ("ab8500-chargalg: Use hrtimer")
Cc: Lee Jones <lee.jones@linaro.org>
Suggested-by: Matti Vaittinen <mazziesaccount@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/power/supply/ab8500_chargalg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c
index 20d6b29cc9e2..c345d5e99118 100644
--- a/drivers/power/supply/ab8500_chargalg.c
+++ b/drivers/power/supply/ab8500_chargalg.c
@@ -1780,11 +1780,11 @@ static int ab8500_chargalg_probe(struct platform_device *pdev)
 	psy_cfg.drv_data = di;
 
 	/* Initilialize safety timer */
-	hrtimer_init(&di->safety_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
+	hrtimer_init(&di->safety_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	di->safety_timer.function = ab8500_chargalg_safety_timer_expired;
 
 	/* Initilialize maintenance timer */
-	hrtimer_init(&di->maintenance_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
+	hrtimer_init(&di->maintenance_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	di->maintenance_timer.function =
 		ab8500_chargalg_maintenance_timer_expired;
 
-- 
2.35.1


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

* Re: [PATCH] power: ab8500_chargalg: Use CLOCK_MONOTONIC
  2022-03-08 15:44 [PATCH] power: ab8500_chargalg: Use CLOCK_MONOTONIC Linus Walleij
@ 2022-03-09  6:45 ` Vaittinen, Matti
  2022-03-14 16:32   ` Sebastian Reichel
  0 siblings, 1 reply; 3+ messages in thread
From: Vaittinen, Matti @ 2022-03-09  6:45 UTC (permalink / raw)
  To: Linus Walleij, Sebastian Reichel, Marcus Cooper
  Cc: linux-pm, Lee Jones, Matti Vaittinen

On 3/8/22 17:44, Linus Walleij wrote:
> The HRTimer in the AB8500 charging code is using CLOCK_REALTIME
> to set an alarm some hours forward in time +/- 5 min for a safety
> timer.
> 
> I have observed that this will sometimes fire sporadically
> early when charging a battery with the result that
> charging stops.
> 
> As CLOCK_REALTIME can be subject to adjustments of time from
> sources such as NTP, this cannot be trusted and will likely
> for example fire events if the clock is set forward some hours
> by say NTP.
> 
> Use CLOCK_MONOTONIC as indicated in other instances and the
> problem goes away. Also initialize the timer to REL mode
> as this is what will be used later.
> 
> Fixes: 257107ae6b9b ("ab8500-chargalg: Use hrtimer")
> Cc: Lee Jones <lee.jones@linaro.org>
> Suggested-by: Matti Vaittinen <mazziesaccount@gmail.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

FWIW:
Reviewed-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>


-- 
The Linux Kernel guy at ROHM Semiconductors

Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~ this year is the year of a signature writers block ~~

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

* Re: [PATCH] power: ab8500_chargalg: Use CLOCK_MONOTONIC
  2022-03-09  6:45 ` Vaittinen, Matti
@ 2022-03-14 16:32   ` Sebastian Reichel
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Reichel @ 2022-03-14 16:32 UTC (permalink / raw)
  To: Vaittinen, Matti
  Cc: Linus Walleij, Marcus Cooper, linux-pm, Lee Jones, Matti Vaittinen

[-- Attachment #1: Type: text/plain, Size: 1155 bytes --]

Hi,

On Wed, Mar 09, 2022 at 06:45:59AM +0000, Vaittinen, Matti wrote:
> On 3/8/22 17:44, Linus Walleij wrote:
> > The HRTimer in the AB8500 charging code is using CLOCK_REALTIME
> > to set an alarm some hours forward in time +/- 5 min for a safety
> > timer.
> > 
> > I have observed that this will sometimes fire sporadically
> > early when charging a battery with the result that
> > charging stops.
> > 
> > As CLOCK_REALTIME can be subject to adjustments of time from
> > sources such as NTP, this cannot be trusted and will likely
> > for example fire events if the clock is set forward some hours
> > by say NTP.
> > 
> > Use CLOCK_MONOTONIC as indicated in other instances and the
> > problem goes away. Also initialize the timer to REL mode
> > as this is what will be used later.
> > 
> > Fixes: 257107ae6b9b ("ab8500-chargalg: Use hrtimer")
> > Cc: Lee Jones <lee.jones@linaro.org>
> > Suggested-by: Matti Vaittinen <mazziesaccount@gmail.com>
> > Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> 
> FWIW:
> Reviewed-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>

Thanks, queued.

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2022-03-14 16:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 15:44 [PATCH] power: ab8500_chargalg: Use CLOCK_MONOTONIC Linus Walleij
2022-03-09  6:45 ` Vaittinen, Matti
2022-03-14 16:32   ` Sebastian Reichel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.