Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1304870imm; Fri, 22 Jun 2018 14:10:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKNNN8s4umfr7iTivGxBLyHtsLoj7yitz8emluJoUVid51zvu8qE9Ls0xLSlSZfXJWXgFx9 X-Received: by 2002:a63:6107:: with SMTP id v7-v6mr2824725pgb.264.1529701817428; Fri, 22 Jun 2018 14:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529701817; cv=none; d=google.com; s=arc-20160816; b=OLY2pTaJgb5vZYaNEX06WWTicU2X/lJe38jBp0U4gTdeiF9mVUpOqB45exYzBIrRZs UToArPJlnZbAQT/ffydVx1f1mYSBZut9LYaqoTJrEP43Y45laby2DCcFLroAxJHoBIiw CaZ3psuOQec2wkCBPYErAWFxR7e8QGmxgmBDsGzDm9VR9y7PGKPRTkSqhSFnWbbcDYjC afTaqKBcqQSKjVMsvSGEVkrzwq4xE7bWQfUHVwTAVM9D6IyWPoUtzYPtz0H3TH+IkaHU FOnuUAbaF0WUKqHhyUM7o0D8uuLxPD67AgmdmW2CcNsXpfzuoEXuhHVtpifuWnQXQzl2 3wMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=yYD+UCz09VucF1nMPGcx0C2ctWO/KdfuPs0FOsFRl3E=; b=mIGeI6kBJFyL412/LfR8/euoc1LdWToZ/Qp6RH+W8OjR8wXNw3poSdXy9lUA0rHxtl Lkvc7/5/d0lxvYzjZWkpryZw/EaNjfdyywDf4TgYVEj+9uWo0kwjzgovJ3/D9SU5XbG+ edoMJ8mz+Yk95FI0qqjbdUYDVZsb90JVWf/RFedEGthwA971kQriZjR1+bbp/5T7C1f4 Ho9kjedipUf+gmnFLAtfRtz3YIU0ompICc5pjX6FKihDBUw6j5cwEbJbj0duC9IJu0HH 1ITpBIH9AVYxP1jViR4hJ+OgxVK8p9yRB9A0t9UrDgpaTj+6cXDDveI/uB3UZSgltWHW imEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i15-v6si7005362pgf.412.2018.06.22.14.10.03; Fri, 22 Jun 2018 14:10:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754501AbeFVVJY (ORCPT + 99 others); Fri, 22 Jun 2018 17:09:24 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:42797 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754283AbeFVVJX (ORCPT ); Fri, 22 Jun 2018 17:09:23 -0400 Received: from p4fea482e.dip0.t-ipconnect.de ([79.234.72.46] helo=nanos.glx-home) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fWTJ3-00042L-5u; Fri, 22 Jun 2018 23:09:21 +0200 Date: Fri, 22 Jun 2018 23:09:20 +0200 (CEST) From: Thomas Gleixner To: Miroslav Lichvar cc: linux-kernel@vger.kernel.org, John Stultz , Richard Cochran , Prarit Bhargava Subject: Re: [PATCHv2] timekeeping: Update multiplier when NTP frequency is set directly In-Reply-To: <20180604133421.19559-1-mlichvar@redhat.com> Message-ID: References: <20180604133421.19559-1-mlichvar@redhat.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 4 Jun 2018, Miroslav Lichvar wrote: > When the NTP frequency is set directly from userspace using the > ADJ_FREQUENCY or ADJ_TICK timex mode, immediately update the > timekeeper's multiplier instead of waiting for the next tick. > > This removes a hidden non-deterministic delay in setting of the > frequency and allows an extremely tight control of the system clock > with update rates close to or even exceeding the kernel HZ. > > The update is limited to archs using modern timekeeping > (!ARCH_USES_GETTIMEOFFSET). John ????? > > Cc: Thomas Gleixner > Cc: John Stultz > Cc: Richard Cochran > Cc: Prarit Bhargava > Signed-off-by: Miroslav Lichvar > --- > > Notes: > RFC->v1: > - added a new parameter to force the update of the timekeeper to the current > NTP tick length only from adjtimex() > - added timekeeping_advance() to keep the parameter local to timekeeping.c > v1->v2: > - replaced bool parameter with enum > - changed timekeeping_advance() to not make any updates for TK_ADV_FREQ with > !ARCH_USES_GETTIMEOFFSET (an alternative might be to update with zero offset) > > kernel/time/timekeeping.c | 36 ++++++++++++++++++++++++++++++------ > 1 file changed, 30 insertions(+), 6 deletions(-) > > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c > index 49cbceef5deb..a08ef3771ab5 100644 > --- a/kernel/time/timekeeping.c > +++ b/kernel/time/timekeeping.c > @@ -34,6 +34,14 @@ > #define TK_MIRROR (1 << 1) > #define TK_CLOCK_WAS_SET (1 << 2) > > +enum timekeeping_adv_mode { > + /* Update timekeeper when a tick has passed */ > + TK_ADV_TICK, > + > + /* Update timekeeper on a direct frequency change */ > + TK_ADV_FREQ > +}; > + > /* > * The most important data for readout fits into a single 64 byte > * cache line. > @@ -2021,11 +2029,11 @@ static u64 logarithmic_accumulation(struct timekeeper *tk, u64 offset, > return offset; > } > > -/** > - * update_wall_time - Uses the current clocksource to increment the wall time > - * > +/* > + * timekeeping_advance - Updates the timekeeper to the current time and > + * current NTP tick length > */ > -void update_wall_time(void) > +static void timekeeping_advance(enum timekeeping_adv_mode mode) > { > struct timekeeper *real_tk = &tk_core.timekeeper; > struct timekeeper *tk = &shadow_timekeeper; > @@ -2042,14 +2050,17 @@ void update_wall_time(void) > > #ifdef CONFIG_ARCH_USES_GETTIMEOFFSET > offset = real_tk->cycle_interval; > + > + if (mode != TK_ADV_TICK) > + goto out; > #else > offset = clocksource_delta(tk_clock_read(&tk->tkr_mono), > tk->tkr_mono.cycle_last, tk->tkr_mono.mask); > -#endif > > /* Check if there's really nothing to do */ > - if (offset < real_tk->cycle_interval) > + if (offset < real_tk->cycle_interval && mode == TK_ADV_TICK) > goto out; > +#endif > > /* Do some additional sanity checking */ > timekeeping_check_update(tk, offset); > @@ -2105,6 +2116,15 @@ void update_wall_time(void) > clock_was_set_delayed(); > } > > +/** > + * update_wall_time - Uses the current clocksource to increment the wall time > + * > + */ > +void update_wall_time(void) > +{ > + timekeeping_advance(TK_ADV_TICK); > +} > + > /** > * getboottime64 - Return the real time of system boot. > * @ts: pointer to the timespec64 to be set > @@ -2332,6 +2352,10 @@ int do_adjtimex(struct timex *txc) > write_seqcount_end(&tk_core.seq); > raw_spin_unlock_irqrestore(&timekeeper_lock, flags); > > + /* Update the multiplier immediately if frequency was set directly */ > + if (txc->modes & (ADJ_FREQUENCY | ADJ_TICK)) > + timekeeping_advance(TK_ADV_FREQ); > + > if (tai != orig_tai) > clock_was_set(); > > -- > 2.14.3 > >