From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>,
linux-power <linux-power@fi.rohmeurope.com>,
Thomas Gleixner <tglx@linutronix.de>,
Anna-Maria Gleixner <anna-maria@linutronix.de>
Cc: Sebastian Reichel <sre@kernel.org>,
Code Kipper <codekipper@gmail.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
Lee Jones <lee.jones@linaro.org>
Subject: Re: Question on expiring HRtimer in-kernel
Date: Thu, 3 Mar 2022 14:43:22 +0200 [thread overview]
Message-ID: <abdc4d16-b2b4-6343-39d6-9bc48e8be43b@gmail.com> (raw)
In-Reply-To: <CACRpkdZmax=QpwnfgOJOR-5P3wTyKegaDn=VvhVOYz_AChc7bw@mail.gmail.com>
Hi Linus,
On 3/1/22 14:19, Linus Walleij wrote:
> I have a problem with a premature expiring HRtimer.
>
> The HRtimer hrtimer_set_expires_range() is used in two places in
> the upstream kernel:
> kernel/futex/core.c
> drivers/power/supply/ab8500_chargalg.c
>
> Now I am testing the code in the latter, and it has seen some
> bitrot since merged in 2012. Maybe it was correct at one point.
> The timer is started like this:
>
> hrtimer_init(&di->safety_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
> (...)
> hrtimer_set_expires_range(&di->safety_timer,
> ktime_set(timer_expiration * ONE_HOUR_IN_SECONDS, 0),
> ktime_set(FIVE_MINUTES_IN_SECONDS, 0));
> hrtimer_start_expires(&di->safety_timer, HRTIMER_MODE_REL);
>
> What the author wanted to achieve is a very definitive callback in one
> hour relative to now +/- 5 min, and that is one hour later in the
> physical world,
> as this deals with battery charging.
>
> However sometimes this fires almost immediately rather than in an hour.
>
> My first thought is to pass HRTIMER_MODE_REL also to init as
> hrtimer_set_expires_range() could make things happen immediately
> if we have ABS set, but this is all just intuitive.
>
> Any hints? Better ways to create a definitive event in one hour?
>
_a lot_ of water has been flowing in the Oulu river since I last touched
on any code like this. Unfortunately I can't go back to my old code as
it was left in proprietary world. So no promises I am at all helpful here ;)
In any case, I remember few cases where I hit nasty issues because I
used CLOCK_REALTIME - which (AFAIR) is subject to the time adjustments.
NTP, GPS-time and so on can make the time tick in a strange way :) I
guess you would have noticed if time was set when timer did expire.
Anyways, I guess the battery charging should rather be tied CLOCK_MONOTONIC.
No guarantees though - please ignore me if I make no sense. Oh,
actually, please don't - please correct me instead :)
-- Matti
next prev parent reply other threads:[~2022-03-03 12:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-01 12:19 Linus Walleij
2022-03-01 12:21 ` Linus Walleij
2022-03-03 12:43 ` Matti Vaittinen [this message]
2022-03-03 22:55 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=abdc4d16-b2b4-6343-39d6-9bc48e8be43b@gmail.com \
--to=mazziesaccount@gmail.com \
--cc=anna-maria@linutronix.de \
--cc=codekipper@gmail.com \
--cc=lee.jones@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-power@fi.rohmeurope.com \
--cc=sre@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®