From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D422EC31E44 for ; Fri, 14 Jun 2019 09:44:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B1C432168B for ; Fri, 14 Jun 2019 09:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727188AbfFNJoK (ORCPT ); Fri, 14 Jun 2019 05:44:10 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:37277 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727038AbfFNJoJ (ORCPT ); Fri, 14 Jun 2019 05:44:09 -0400 Received: from [5.158.153.52] (helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1hbikd-0006Lk-DM; Fri, 14 Jun 2019 11:44:03 +0200 Date: Fri, 14 Jun 2019 11:44:03 +0200 (CEST) From: Thomas Gleixner To: "Jason A. Donenfeld" cc: Arnd Bergmann , Peter Zijlstra , LKML , Clemens Ladisch , Sultan Alsawaf , Waiman Long , X86 ML Subject: Re: infinite loop in read_hpet from ktime_get_boot_fast_ns In-Reply-To: Message-ID: References: <20190612090257.GF3436@hirez.programming.kicks-ass.net> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jason, On Fri, 14 Jun 2019, Jason A. Donenfeld wrote: > 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. Yeah, historical raisins when ktime_t was special on 32bit. > 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() jiffies64 uses a seqcount on 32bit as well. > 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() Hrm, I'm not a great fan of these shortcuts which cut corners based on 'somewhat rarely, so it should not matter'. Should not matter always strikes back at some point. :) > 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. So what you are looking for is jiffies based on boot time? Thanks, tglx