From patchwork Thu Jun 11 22:54:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 49776 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5E69F20C81 for ; Thu, 11 Jun 2015 22:55:18 +0000 (UTC) Received: by wizw5 with SMTP id w5sf197530wiz.2 for ; Thu, 11 Jun 2015 15:55:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=xoh5qTD8OqHqX81PoRKIv4eyI83177gCQ2rOEitULP8=; b=giTnIw3qxmOYckzQ6neR4JvmhJMY4PlHB3A7dwkeK8rvVS2rJXKnsv3TqeXMZDYOUG rF6vsLJJ/ymJ2QAt7Mtyw5ukgiLRcxoV7PzY55b0XxHTazy9tEaoTBpwUWh61/8aCJrF sZEHd//ASTao/Oe1w4qjysmbJnIed5C/6LPo5Yyc5PfNUMZrpPBjxntjwQmonroxlBpP 5q8NCATs3H/Cz1pLjZS+x7wI8qEzxnz0yeFEzTXcqPLh/79oSp5KSS2D0UVvtD+dHisV XRx34Irh9tRWwPsgCas/YzWDwyQNgKqRlPT11Ap4LijS/ad3rAkNIu8ZYEpENhyEKMcW JhiQ== X-Gm-Message-State: ALoCoQk9v037lUXGFv8xkP55q8ihHphhkhPv2930WpGu5VAicpdzNAKgFi+1kunbldgtS5dT8i8p X-Received: by 10.152.5.2 with SMTP id o2mr10895838lao.0.1434063317413; Thu, 11 Jun 2015 15:55:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.129 with SMTP id m1ls451394laf.76.gmail; Thu, 11 Jun 2015 15:55:17 -0700 (PDT) X-Received: by 10.152.21.97 with SMTP id u1mr12171344lae.71.1434063317051; Thu, 11 Jun 2015 15:55:17 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id qf12si1849028lbc.6.2015.06.11.15.55.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jun 2015 15:55:17 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbcmx3 with SMTP id mx3so10357736lbc.1 for ; Thu, 11 Jun 2015 15:55:17 -0700 (PDT) X-Received: by 10.112.93.37 with SMTP id cr5mr12432649lbb.106.1434063316941; Thu, 11 Jun 2015 15:55:16 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp135192lbb; Thu, 11 Jun 2015 15:55:15 -0700 (PDT) X-Received: by 10.70.93.106 with SMTP id ct10mr18362314pdb.92.1434063310665; Thu, 11 Jun 2015 15:55:10 -0700 (PDT) Received: from mail-pd0-f181.google.com (mail-pd0-f181.google.com. [209.85.192.181]) by mx.google.com with ESMTPS id v5si2732009pdb.7.2015.06.11.15.55.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jun 2015 15:55:10 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.181 as permitted sender) client-ip=209.85.192.181; Received: by pdbnf5 with SMTP id nf5so11473374pdb.2 for ; Thu, 11 Jun 2015 15:55:09 -0700 (PDT) X-Received: by 10.68.136.101 with SMTP id pz5mr17976677pbb.15.1434063309736; Thu, 11 Jun 2015 15:55:09 -0700 (PDT) Received: from localhost.localdomain (c-71-63-136-39.hsd1.or.comcast.net. [71.63.136.39]) by mx.google.com with ESMTPSA id ax2sm1676093pac.21.2015.06.11.15.55.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Jun 2015 15:55:08 -0700 (PDT) From: John Stultz To: linux-kernel@vger.kernel.org Cc: John Stultz , Prarit Bhargava , Daniel Bristot de Oliveira , Richard Cochran , Jan Kara , Jiri Bohac , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4/5] ntp: Do leapsecond adjustment in adjtimex read path Date: Thu, 11 Jun 2015 15:54:56 -0700 Message-Id: <1434063297-28657-5-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1434063297-28657-1-git-send-email-john.stultz@linaro.org> References: <1434063297-28657-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Since the leapsecond is applied at tick-time, this means there is a small window of time at the start of a leap-second where we cross into the next second before applying the leap. This patch modified adjtimex so that the leap-second is applied on the second edge. Providing more correct leapsecond behavior. This does make it so that adjtimex()'s returned time values can be inconsistent with time values read from gettimeofday() or clock_gettime(CLOCK_REALTIME,...) for a brief period of one tick at the leapsecond. However, those other interfaces do not provide the TIME_OOP time_state return that adjtimex() provides, which allows the leapsecond to be properly represented. They instead only see a time discontinuity, and cannot tell the first 23:59:59 from the repeated 23:59:59 leap second. This seems like a reasonable tradeoff given clock_gettime() / gettimeofday() cannot properly represent a leapsecond, and users likely care more about performance, while folks who are using adjtimex() more likely care about leap-second correctness. Cc: Prarit Bhargava Cc: Daniel Bristot de Oliveira Cc: Richard Cochran Cc: Jan Kara Cc: Jiri Bohac Cc: Thomas Gleixner Cc: Ingo Molnar Signed-off-by: John Stultz --- kernel/time/ntp.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 033743e..fb4d98c 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -740,6 +740,24 @@ int __do_adjtimex(struct timex *txc, struct timespec64 *ts, s32 *time_tai) if (!(time_status & STA_NANO)) txc->time.tv_usec /= NSEC_PER_USEC; + /* Handle leapsec adjustments */ + if (unlikely(ts->tv_sec >= ntp_next_leap_sec)) { + if ((time_state == TIME_INS) && (time_status & STA_INS)) { + result = TIME_OOP; + txc->tai++; + txc->time.tv_sec--; + } + if ((time_state == TIME_DEL) && (time_status & STA_DEL)) { + result = TIME_WAIT; + txc->tai--; + txc->time.tv_sec++; + } + if ((time_state == TIME_OOP) && + (ts->tv_sec == ntp_next_leap_sec)) { + result = TIME_WAIT; + } + } + return result; }