From patchwork Fri Jul 13 05:21:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 9972 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id ED07723F4C for ; Fri, 13 Jul 2012 05:23:44 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id A621AA181A0 for ; Fri, 13 Jul 2012 05:23:44 +0000 (UTC) Received: by ggnf1 with SMTP id f1so3503771ggn.11 for ; Thu, 12 Jul 2012 22:23:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-content-scanned:x-cbid:x-gm-message-state; bh=cLa3lwRiA3drXlHVCuMcyVfMQDBDKxjfM27MVglyyis=; b=iKi/IwNo/a1lPa4Tm3/fC5PPwnQ+AI6/FbOB5U0pTnrQWm1l5grN7O2chvybK5/dtt h2+vqhci/ua+gr13nqQJoLDLK2gHH/f0C9rsM1Ogum3RWWOMbuYF5ywY/3NWfBhW1XHh 5LJQDW+s8m40uZCCYMTDbsx1WBPvFADqHTpJBZ01BPGc9osZUu0Epn3szUDJs/XQuaLo R53Mpszo6xBiaxwPwFj19OrvchXab98z6ZRW2YiJDNC1nERnEzvX5FxKqQjHbZISVyKv +Q1n+nIy2C/INM/klbkKPSnwHpZlv3KeWOvzLpbQjGmjkW4znvr4XfzfR75aahSSgMkK /e0g== Received: by 10.50.57.167 with SMTP id j7mr212158igq.53.1342157023874; Thu, 12 Jul 2012 22:23:43 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.241.2 with SMTP id lc2csp11726ibb; Thu, 12 Jul 2012 22:23:43 -0700 (PDT) Received: by 10.66.78.10 with SMTP id x10mr2027225paw.80.1342157023193; Thu, 12 Jul 2012 22:23:43 -0700 (PDT) Received: from e32.co.us.ibm.com (e32.co.us.ibm.com. [32.97.110.150]) by mx.google.com with ESMTPS id hw8si12640097pbc.206.2012.07.12.22.23.42 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 12 Jul 2012 22:23:43 -0700 (PDT) Received-SPF: neutral (google.com: 32.97.110.150 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=32.97.110.150; Authentication-Results: mx.google.com; spf=neutral (google.com: 32.97.110.150 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) smtp.mail=john.stultz@linaro.org Received: from /spool/local by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 12 Jul 2012 23:23:42 -0600 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 12 Jul 2012 23:23:40 -0600 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 07D441FF004C; Fri, 13 Jul 2012 05:23:01 +0000 (WET) Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6D5Mfa7179608; Thu, 12 Jul 2012 23:22:46 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6D5MPKJ018029; Thu, 12 Jul 2012 23:22:25 -0600 Received: from kernel.stglabs.ibm.com (kernel.stglabs.ibm.com [9.114.214.19]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q6D5MIiS017604; Thu, 12 Jul 2012 23:22:24 -0600 From: John Stultz To: Linux Kernel Cc: John Stultz , Ingo Molnar , Peter Zijlstra , Richard Cochran , Prarit Bhargava , Thomas Gleixner , John Stultz Subject: [PATCH 7/8] time: Move xtime_nsec adjustment underflow handling timekeeping_adjust Date: Fri, 13 Jul 2012 01:21:56 -0400 Message-Id: <1342156917-25092-8-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1342156917-25092-1-git-send-email-john.stultz@linaro.org> References: <1342156917-25092-1-git-send-email-john.stultz@linaro.org> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12071305-2356-0000-0000-00000050AE39 X-Gm-Message-State: ALoCoQmR8nw6MuwWuYq66juXkSEDMSu97knYpNt3hkYHT9cuUNzIZL5gdcHU2HTrX9CAeDFhgDlR When we make adjustments speeding up the clock, its possible for xtime_nsec to underflow. We already handle this properly, but we do so from update_wall_time() instead of the more logical timekeeping_adjust(), where the possible underflow actually occurs. Thus, move the correction logic to the timekeeping_adjust, which is the function that causes the issue. Making update_wall_time() more readable. CC: Ingo Molnar CC: Peter Zijlstra CC: Richard Cochran CC: Prarit Bhargava CC: Thomas Gleixner Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index dd119355..4b76432 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -987,6 +987,27 @@ static void timekeeping_adjust(s64 offset) timekeeper.xtime_nsec -= offset; timekeeper.ntp_error -= (interval - offset) << timekeeper.ntp_error_shift; + + /* + * It may be possible that when we entered this function, xtime_nsec + * was very small. Further, if we're slightly speeding the clocksource + * in the code above, its possible the required corrective factor to + * xtime_nsec could cause it to underflow. + * + * Now, since we already accumulated the second, cannot simply roll + * the accumulated second back, since the NTP subsystem has been + * notified via second_overflow. So instead we push xtime_nsec forward + * by the amount we underflowed, and add that amount into the error. + * + * We'll correct this error next time through this function, when + * xtime_nsec is not as small. + */ + if (unlikely((s64)timekeeper.xtime_nsec < 0)) { + s64 neg = -(s64)timekeeper.xtime_nsec; + timekeeper.xtime_nsec = 0; + timekeeper.ntp_error += neg << timekeeper.ntp_error_shift; + } + } @@ -1112,27 +1133,6 @@ static void update_wall_time(void) /* correct the clock when NTP error is too big */ timekeeping_adjust(offset); - /* - * Since in the loop above, we accumulate any amount of time - * in xtime_nsec over a second into xtime.tv_sec, its possible for - * xtime_nsec to be fairly small after the loop. Further, if we're - * slightly speeding the clocksource up in timekeeping_adjust(), - * its possible the required corrective factor to xtime_nsec could - * cause it to underflow. - * - * Now, we cannot simply roll the accumulated second back, since - * the NTP subsystem has been notified via second_overflow. So - * instead we push xtime_nsec forward by the amount we underflowed, - * and add that amount into the error. - * - * We'll correct this error next time through this function, when - * xtime_nsec is not as small. - */ - if (unlikely((s64)timekeeper.xtime_nsec < 0)) { - s64 neg = -(s64)timekeeper.xtime_nsec; - timekeeper.xtime_nsec = 0; - timekeeper.ntp_error += neg << timekeeper.ntp_error_shift; - } /* * Store only full nanoseconds into xtime_nsec after rounding