[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHmME9obwzZ5x=p3twDfNYux+kg0h4QAGe0ePAkZ2KqvguBK3g@mail.gmail.com>
Date: Wed, 12 Jun 2019 11:44:35 +0200
From: "Jason A. Donenfeld" <Jason@...c4.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Thomas Gleixner <tglx@...utronix.de>,
LKML <linux-kernel@...r.kernel.org>, clemens@...isch.de,
Sultan Alsawaf <sultan@...neltoast.com>,
Waiman Long <longman@...hat.com>, X86 ML <x86@...nel.org>
Subject: Re: infinite loop in read_hpet from ktime_get_boot_fast_ns
Hey Peter,
On Wed, Jun 12, 2019 at 11:03 AM Peter Zijlstra <peterz@...radead.org> wrote:
> How quasi? Do the comments in kernel/sched/clock.c look like something
> you could use?
>
> As already mentioned in the other tasks, anything ktime will be
> horrifically crap when it ends up using the HPET, the code in
> kernel/sched/clock.c is a best effort to keep using TSC even when it is
> deemed unusable for timekeeping.
Thanks for pointing that out. Indeed the HPET path is a bummer and I'd
like to just escape using ktime all together.
In fact, my accuracy requirements are very lax. I could probably even
deal with an inaccuracy as huge as ~200 milliseconds. But what I do
need is 64-bit, so that it doesn't wrap, allowing me to compare two
stamps taken a long time apart, and for it to take into account sleep
time, like CLOCK_BOOTTIME does, which means get_jiffies_64() doesn't
fit the bill. I was under the impression that I could only get this
with ktime_get_boot & co, because those add the sleep offset.
It looks like, though, kernel/sched/clock.c keeps track of some
offsets too -- __sched_clock_offset and __gtod_offset, and the comment
at the top mentions explicit sleep hooks. I wasn't sure which function
to use from here, though. sched_clock() seems based on jiffies, which
has the 32-bit wraparound issue, and the base implementation doesn't
seem to take into account sleeptime. The x86 implementation seems use
rdtsc and then adds cyc2ns_offset which looks to be based on
cyc2ns_suspend, which I assume is what I want. But there's still the
issue of the 32-bit wraparound on the base implementation.
I guess you know this code better than my quick perusal. Is there some
clock in here that doesn't have a wrap around issue and takes into
account sleeptime, without being super slow like ktime/hpet?
Jason
Powered by blists - more mailing lists