Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3244815imm; Tue, 29 May 2018 03:55:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq39vGkpXUO7p5QiC6Ekx1MiDTje4qIhIdkWyoEj+9fEMhHpm/NNkd6i0J9zU2np6/q3cCE X-Received: by 2002:a62:cf43:: with SMTP id b64-v6mr16777108pfg.248.1527591335007; Tue, 29 May 2018 03:55:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527591334; cv=none; d=google.com; s=arc-20160816; b=p4YXGTOGuUYAb0oqV5A8xuxA1JEWOq3LC57Jl9u5cNpRqTVDMHTg3Qr0VXGnwilUNF BqW+7ANuMunJIrADtf4m/nb4AAJC/EXLASQmTUYgsDzq7s6Xcs0Pe/Nj/5KtkVS2ziz7 5sqeg/JhOBi5kjer+gxVa344sSOz/Nc0gnNFjFE4PrWJKJwJV3C1HhNBL+XJAaYivg7I vLVzCZSSiHWa8ldHQ61eIpBE39URr/7mdTuJL6pJJ/7t3yD3o0tnYIra8iF1P+c23Ng8 wc2A2Se46BX4rGReltj9D8Vy9DCRse5N/QymnEJ1hE7DbxU6qgOBvUXfYL24T7lQJXQL LJjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=wxsEaRmgcdyQJ2VyPBKlj+kpVYUSdNrz8pw/tXHzen0=; b=cd+/9a8CGQOHWG9VtUhCD9z8Gfskhgk7/oY3AUYES6pod4SxnJve3pHhxCaCNzxS/o pBtVHyk+x6UKlYDEl2WzdMg2A8zu21fBWjiwtJjPYgz8q0ll0c55/EZZS1orzzWXTWLn Mm4kREW3TNlouL0SFG766z95e6OHx6c8wk3g5xNQBq3y/NwniNRtuxlRC+Xg0S12Lq+b 3qHrakKF8ZhW5RDzQdPL6TzEm13w/KVSIlvz7WBQWrIUBSYhGHHVFeL2m8SwNP+ecO6z 3EcSkDyOOXFCr6Pe6I9ZJR+M338uWwGFzLzaJdc+2jT5VMeFtHW2N9OjucbKn3mjq1/A zntg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1-v6si30789346plm.268.2018.05.29.03.55.20; Tue, 29 May 2018 03:55:34 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933299AbeE2Kxt (ORCPT + 99 others); Tue, 29 May 2018 06:53:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48868 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932847AbeE2Kxq (ORCPT ); Tue, 29 May 2018 06:53:46 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1450B401EF08; Tue, 29 May 2018 10:53:46 +0000 (UTC) Received: from holly.tpb.lab.eng.brq.redhat.com (unknown [10.43.134.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7AB52166BB2; Tue, 29 May 2018 10:53:44 +0000 (UTC) From: Miroslav Lichvar To: linux-kernel@vger.kernel.org Cc: Miroslav Lichvar , Thomas Gleixner , John Stultz , Richard Cochran , Prarit Bhargava Subject: [PATCHv1] timekeeping: Update multiplier when NTP frequency is set directly Date: Tue, 29 May 2018 12:53:43 +0200 Message-Id: <20180529105343.26870-1-mlichvar@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 29 May 2018 10:53:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 29 May 2018 10:53:46 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mlichvar@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 kernel/time/timekeeping.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 49cbceef5deb..5524c07d43e3 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -2021,11 +2021,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(bool force_update) { struct timekeeper *real_tk = &tk_core.timekeeper; struct timekeeper *tk = &shadow_timekeeper; @@ -2048,7 +2048,7 @@ void update_wall_time(void) #endif /* Check if there's really nothing to do */ - if (offset < real_tk->cycle_interval) + if (offset < real_tk->cycle_interval && !force_update) goto out; /* Do some additional sanity checking */ @@ -2105,6 +2105,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(false); +} + /** * getboottime64 - Return the real time of system boot. * @ts: pointer to the timespec64 to be set @@ -2332,6 +2341,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(true); + if (tai != orig_tai) clock_was_set(); -- 2.14.3