From patchwork Fri Dec 18 21:39:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 58763 Delivered-To: patches@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp1285563lbb; Fri, 18 Dec 2015 13:39:52 -0800 (PST) X-Received: by 10.66.158.193 with SMTP id ww1mr8569558pab.21.1450474772683; Fri, 18 Dec 2015 13:39:32 -0800 (PST) Return-Path: Received: from mail-pf0-x22c.google.com (mail-pf0-x22c.google.com. [2607:f8b0:400e:c00::22c]) by mx.google.com with ESMTPS id u27si22354952pfi.167.2015.12.18.13.39.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Dec 2015 13:39:32 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22c as permitted sender) client-ip=2607:f8b0:400e:c00::22c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22c as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dkim=pass header.i=@linaro.org Received: by mail-pf0-x22c.google.com with SMTP id o64so54878170pfb.3 for ; Fri, 18 Dec 2015 13:39:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=04iHeWlvd1iHJ8QZfIzM68cwbiqHBUsoC5PzaMVx478=; b=EeUMqCrb1Ht/lRSKqDkpx3snLRYAtthcEWg6ljNhJzIrs6nPTN5TliMJ+PPNcrzzEr T48pYcDYe+y8aP1WyLIA7B0H1ZGvRPQws2mpn2Wsghln2dlnKQ75vr03Ko8yh7zJ8eax FRM8+kjLkBOxCe3d99uSsPY+IgmTL4H1/6/5g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=04iHeWlvd1iHJ8QZfIzM68cwbiqHBUsoC5PzaMVx478=; b=Qw2+JyIBMgqWxx8FG4QV7kZ5ijTQoB7FAm9siTp1dLYltOlVi0ytG6VdPXDv+X1obg coGs5mTEqYFPe5JLk1sgKisi3DvY63HLTckv5kyAD/pgG1kqcUUn8uKbwEwtwtIn8Giv VpkyOyi1nAo2SLjIPAIoAoj9padyAR5ehp2TB0HfGp1odFzxB9qEPU+Ktdbh7yFYh73V 5NjWD9k34MLTr1mm1USRGxR1JfSPczbPIjMslqmmMD++8qRUtCpKe6Yccn8NGo5q6mmg B6KEwQ/2ZEC1ygSG71qe+pXe/+RjWnZMqrCYTD8qZg1iR/7F/lq7TaDPb3l+xrpBlCPT 1aVA== X-Gm-Message-State: ALoCoQkEFTzeDIPzu8NYEww3BRvI25hsOle3/I14pGrbD2RxUR1FMvjTVU+K0ei73VAVfX48DpYl1rlkzx1/fgU8henpZtmMlw== X-Received: by 10.98.16.70 with SMTP id y67mr8455989pfi.77.1450474772353; Fri, 18 Dec 2015 13:39:32 -0800 (PST) Return-Path: Received: from localhost.localdomain (c-76-115-103-22.hsd1.or.comcast.net. [76.115.103.22]) by smtp.gmail.com with ESMTPSA id w62sm19642284pfi.48.2015.12.18.13.39.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Dec 2015 13:39:31 -0800 (PST) From: John Stultz To: lkml Cc: DengChao , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Prarit Bhargava , Richard Cochran , John Stultz Subject: [PATCH 10/11] ntp: Fix second_overflow's input parameter type to be 64bits Date: Fri, 18 Dec 2015 13:39:15 -0800 Message-Id: <1450474756-10144-11-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450474756-10144-1-git-send-email-john.stultz@linaro.org> References: <1450474756-10144-1-git-send-email-john.stultz@linaro.org> From: DengChao The function "second_overflow" uses "unsign long" as its input parameter type which will overflow after year 2106 on 32bit systems. Thus this patch replaces it with time64_t type. While the 64-bit division is expensive, "next_ntp_leap_sec" has been calculated already, so we can just re-use it in the TIME_INS/DEL cases, allowing one expensive division per leapsecond instead of re-doing the divsion once a second after the leap flag has been set. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Prarit Bhargava Cc: Richard Cochran Signed-off-by: DengChao [jstultz: Tweaked commit message] Signed-off-by: John Stultz --- kernel/time/ntp.c | 16 +++++++++------- kernel/time/ntp_internal.h | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) -- 1.9.1 diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index e947bfd..36f2ca0 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "ntp_internal.h" #include "timekeeping_internal.h" @@ -394,10 +395,11 @@ ktime_t ntp_get_next_leap(void) * * Also handles leap second processing, and returns leap offset */ -int second_overflow(unsigned long secs) +int second_overflow(time64_t secs) { s64 delta; int leap = 0; + s32 rem; /* * Leap second processing. If in leap-insert state at the end of the @@ -408,19 +410,19 @@ int second_overflow(unsigned long secs) case TIME_OK: if (time_status & STA_INS) { time_state = TIME_INS; - ntp_next_leap_sec = secs + SECS_PER_DAY - - (secs % SECS_PER_DAY); + div_s64_rem(secs, SECS_PER_DAY, &rem); + ntp_next_leap_sec = secs + SECS_PER_DAY - rem; } else if (time_status & STA_DEL) { time_state = TIME_DEL; - ntp_next_leap_sec = secs + SECS_PER_DAY - - ((secs+1) % SECS_PER_DAY); + div_s64_rem(secs + 1, SECS_PER_DAY, &rem); + ntp_next_leap_sec = secs + SECS_PER_DAY - rem; } break; case TIME_INS: if (!(time_status & STA_INS)) { ntp_next_leap_sec = TIME64_MAX; time_state = TIME_OK; - } else if (secs % SECS_PER_DAY == 0) { + } else if (secs == ntp_next_leap_sec) { leap = -1; time_state = TIME_OOP; printk(KERN_NOTICE @@ -431,7 +433,7 @@ int second_overflow(unsigned long secs) if (!(time_status & STA_DEL)) { ntp_next_leap_sec = TIME64_MAX; time_state = TIME_OK; - } else if ((secs + 1) % SECS_PER_DAY == 0) { + } else if (secs == ntp_next_leap_sec) { leap = 1; ntp_next_leap_sec = TIME64_MAX; time_state = TIME_WAIT; diff --git a/kernel/time/ntp_internal.h b/kernel/time/ntp_internal.h index af92447..d8a7c11 100644 --- a/kernel/time/ntp_internal.h +++ b/kernel/time/ntp_internal.h @@ -6,7 +6,7 @@ extern void ntp_clear(void); /* Returns how long ticks are at present, in ns / 2^NTP_SCALE_SHIFT. */ extern u64 ntp_tick_length(void); extern ktime_t ntp_get_next_leap(void); -extern int second_overflow(unsigned long secs); +extern int second_overflow(time64_t secs); extern int ntp_validate_timex(struct timex *); extern int __do_adjtimex(struct timex *, struct timespec64 *, s32 *); extern void __hardpps(const struct timespec64 *, const struct timespec64 *);