linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Peter Zijlstra <peterz@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Clemens Ladisch <clemens@ladisch.de>,
	Sultan Alsawaf <sultan@kerneltoast.com>,
	Waiman Long <longman@redhat.com>, X86 ML <x86@kernel.org>
Subject: Re: infinite loop in read_hpet from ktime_get_boot_fast_ns
Date: Fri, 14 Jun 2019 11:14:12 +0200	[thread overview]
Message-ID: <CAHmME9qa-8J0-x8zmcBrSg_iyPNS02h5CFvhFfXpNth60OQsBg@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1906132136280.1791@nanos.tec.linutronix.de>

Hey Thomas,

> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
>         } while (read_seqcount_retry(&tk_core.seq, seq));
>
> -       return base;
> -
> +       return base + nsecs;

The rest of the file seems to use `ktime_add_ns(base, nsecs)`. I
realize, of course, that these days that macro is the same thing as
what you wrote, though.

I can confirm that this fixes it (see below), so you can add my
Tested-by if you want or care.

One thing I'm curious about is the performance comparison with various
ways of using jiffies directly:

ktime_mono_to_any(ns_to_ktime(jiffies64_to_nsecs(get_jiffies_64())),
TK_OFFS_BOOT)

Or really giving up on the locking:

ktime_to_ns(tk_core.timekeeper.offs_boot) + jiffies64_to_nsecs(get_jiffies_64())

Or keeping things in units of jiffies, though that incurs a div_u64:

nsecs_to_jiffies64(ktime_to_ns(tk_core.timekeeper.offs_boot)) + get_jiffies_64()

But since offs_boot is updated somewhat rarely, that div_u64 could be
precomputed each time offs_boot is updated, allowing hypothetically:

tk_core.timekeeper.offs_boot_jiffies + get_jiffies_64()

Which then could be remade into a wrapper such as:

get_jiffies_boot_64()

The speed is indeed an important factor to me in accessing this time
value. Are any of these remotely interesting to you in that light?
Maybe I'll send a patch for the latter.

Jason

8<-----------------

int __init mod_init(void)
{
  u64 j1 = 0, j2, k1 = 0, k2, c1 = 0, c2, l1 = 0, l2;
  for (;;) {
    j2 = jiffies64_to_nsecs(get_jiffies_64());
    k2 = ktime_to_ns(ktime_mono_to_any(ns_to_ktime(jiffies64_to_nsecs(get_jiffies_64())),
TK_OFFS_BOOT));
    c2 = ktime_get_coarse_boottime();
    l2 = local_clock();
    pr_err("%llu %llu %llu %llu\n", j2 - j1, k2 - k1, c2 - c1, l2 - l1);
    j1 = j2;
    k1 = k2;
    c1 = c2;
    l1 = l2;
    msleep(200);
  }
  return 0;
}

[    0.420861] wireguard: 17179569472000000 17179569472000000
312696682 420860781
[    0.628656] wireguard: 208000000 208000000 208000000 207791083
[    0.836591] wireguard: 208000000 208000000 208000000 207934734
[    1.044728] wireguard: 208000000 208000000 208000000 208137167
[    1.252593] wireguard: 208000000 208000000 208000000 207862974
[    1.460815] wireguard: 208000000 208000000 208000000 208223514
[    1.668667] wireguard: 208000000 208000000 208000000 207852437
[    1.876438] wireguard: 208000000 208000000 208000000 207773658
[    2.084627] wireguard: 208000000 208000000 208000000 208185643
[    2.292690] wireguard: 208000000 208000000 208000000 208063377
[    2.500672] wireguard: 208000000 208000000 208000000 207982209
[    2.708658] wireguard: 208000000 208000000 208000000 207986527
[    2.916686] wireguard: 208000000 208000000 208000000 208026945
[    3.124732] wireguard: 208000000 208000000 208000000 208046153
[    3.332684] wireguard: 208000000 208000000 208000000 207952302
[    3.540668] wireguard: 208000000 208000000 208000000 207978195
[    3.748633] wireguard: 208000000 208000000 208000000 207970981
[    3.956686] wireguard: 208000000 208000000 208000000 208053094
[    4.164690] wireguard: 208000000 208000000 208000000 207995376
[    4.372660] wireguard: 208000000 208000000 208000000 207978324
[    4.580787] wireguard: 208000000 208000000 208000000 208126491
[    4.788716] wireguard: 208000000 208000000 208000000 207930106
[    4.996685] wireguard: 208000000 208000000 208000000 207968555
[    5.204673] wireguard: 208000000 208000000 208000000 207988295
[    5.412676] wireguard: 208000000 208000000 208000000 207991396
[    5.620648] wireguard: 208000000 208000000 208000000 207983671
[    5.828822] wireguard: 208000000 208000000 208000000 208174230
[    6.036596] wireguard: 208000000 208000000 208000000 207773401
[    6.244615] wireguard: 208000000 208000000 208000000 208017986
[    6.452625] wireguard: 208000000 208000000 208000000 208011215
[    6.660678] wireguard: 208000000 208000000 208000000 208053134
[    6.868609] wireguard: 208000000 208000000 208000000 207929536

  reply	other threads:[~2019-06-14  9:14 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-07 14:14 infinite loop in read_hpet from ktime_get_boot_fast_ns Jason A. Donenfeld
2019-06-11 21:09 ` Thomas Gleixner
2019-06-11 21:40   ` Waiman Long
2019-06-12  9:02   ` Peter Zijlstra
2019-06-12  9:44     ` Jason A. Donenfeld
2019-06-12 12:28       ` Peter Zijlstra
2019-06-12 12:31         ` Peter Zijlstra
2019-06-12 12:58         ` Jason A. Donenfeld
2019-06-12 15:27           ` Peter Zijlstra
2019-06-12 19:46         ` Arnd Bergmann
2019-06-18 17:34         ` Jason A. Donenfeld
2019-06-12 14:01       ` Arnd Bergmann
2019-06-13 15:18         ` Jason A. Donenfeld
2019-06-13 15:40           ` Arnd Bergmann
2019-06-13 16:17             ` Jason A. Donenfeld
2019-06-13 16:26               ` Thomas Gleixner
2019-06-13 16:34                 ` Jason A. Donenfeld
2019-06-13 16:41                   ` Jason A. Donenfeld
2019-06-13 19:53                   ` Thomas Gleixner
2019-06-14  9:14                     ` Jason A. Donenfeld [this message]
2019-06-14  9:44                       ` Thomas Gleixner
2019-06-14  9:56                         ` Jason A. Donenfeld
2019-06-14  9:48                       ` [PATCH] timekeeping: add get_jiffies_boot_64() for jiffies including sleep Jason A. Donenfeld
2019-06-14  9:55                     ` [tip:timers/urgent] timekeeping: Repair ktime_get_coarse*() granularity tip-bot for Thomas Gleixner
2019-06-14 11:18                       ` Arnd Bergmann
2019-06-12  9:29   ` infinite loop in read_hpet from ktime_get_boot_fast_ns Peter Zijlstra

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=CAHmME9qa-8J0-x8zmcBrSg_iyPNS02h5CFvhFfXpNth60OQsBg@mail.gmail.com \
    --to=jason@zx2c4.com \
    --cc=arnd@arndb.de \
    --cc=clemens@ladisch.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sultan@kerneltoast.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).