From patchwork Fri Nov 22 19:44:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 21716 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f71.google.com (mail-vb0-f71.google.com [209.85.212.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0138123FDC for ; Fri, 22 Nov 2013 19:45:04 +0000 (UTC) Received: by mail-vb0-f71.google.com with SMTP id w8sf3102194vbj.6 for ; Fri, 22 Nov 2013 11:45:03 -0800 (PST) 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:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=SyJ0MSttgI1+BR0odlSTp8seGVgUCz7Tm8nmAAr+kYM=; b=DsVwmYUAQGe6YRrd25Vu6YA2W4Eh3C3+z0jf/0QeM8FlKoV/hXzINCVOh8J4AQLBUU C8SdOhiErNGAVVkkcMjj0oTev+qeO7Dkt7AEohkXpl0sAxAlZPYU6CTGrvkVwjB6+Oe2 NGRI3zryRVlkzPRMZQrGS3Ufa/Bhpx64m32eNY5J+8Mk0jCtdobxfCGzXARmE0648XuV RF2zsx2+vEOA/IXLbeRhgdb7z1MNeqptPzr7iA+Lud6R8HA+NdaVpUhO0DFle4KLyu8U 3YrJ4LOciqcdXmk/glnk+e13QFBP0XkLcV5W5neCOJ9wXPBT+ZSTijo+It59el3fDfeW SYFg== X-Gm-Message-State: ALoCoQkbdRAmhnoXEeq99e8y+sP6+49NauklrEI1yCMrGkMQ9qtztCVrWQTTP0bg/bEI5BdkYVwg X-Received: by 10.58.75.199 with SMTP id e7mr4331259vew.20.1385149503743; Fri, 22 Nov 2013 11:45:03 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.129.166 with SMTP id nx6ls1083088qeb.12.gmail; Fri, 22 Nov 2013 11:45:03 -0800 (PST) X-Received: by 10.58.216.74 with SMTP id oo10mr12854225vec.0.1385149503589; Fri, 22 Nov 2013 11:45:03 -0800 (PST) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id q6si1451502vdw.49.2013.11.22.11.45.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Nov 2013 11:45:03 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id c14so1235847vea.14 for ; Fri, 22 Nov 2013 11:45:03 -0800 (PST) X-Received: by 10.220.184.70 with SMTP id cj6mr9826764vcb.23.1385149503492; Fri, 22 Nov 2013 11:45:03 -0800 (PST) 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.220.174.196 with SMTP id u4csp63569vcz; Fri, 22 Nov 2013 11:45:02 -0800 (PST) X-Received: by 10.68.189.5 with SMTP id ge5mr13613713pbc.42.1385149502441; Fri, 22 Nov 2013 11:45:02 -0800 (PST) Received: from mail-pa0-f48.google.com (mail-pa0-f48.google.com [209.85.220.48]) by mx.google.com with ESMTPS id bc2si20517195pad.158.2013.11.22.11.45.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Nov 2013 11:45:02 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.48 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.220.48; Received: by mail-pa0-f48.google.com with SMTP id rd3so1746839pab.21 for ; Fri, 22 Nov 2013 11:45:02 -0800 (PST) X-Received: by 10.68.129.201 with SMTP id ny9mr4455094pbb.70.1385149501749; Fri, 22 Nov 2013 11:45:01 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id sg1sm55110983pbb.16.2013.11.22.11.45.00 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Nov 2013 11:45:01 -0800 (PST) From: John Stultz To: LKML Cc: Martin Schwidefsky , Tony Luck , Paul Mackerras , Benjamin Herrenschmidt , Andy Lutomirski , Paul Turner , Steven Rostedt , Richard Cochran , Prarit Bhargava , Fenghua Yu , Thomas Gleixner , stable , John Stultz Subject: [PATCH] time: Fix 1ns/tick drift w/ GENERIC_TIME_VSYSCALL_OLD Date: Fri, 22 Nov 2013 11:44:51 -0800 Message-Id: <1385149491-20307-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: , From: Martin Schwidefsky Since commit 1e75fa8be9f (time: Condense timekeeper.xtime into xtime_sec - merged in v3.6), there has been an problem with the error accounting in the timekeeping code, such that when truncating to nanoseconds, we round up to the next nsec, but the balancing adjustment to the ntp_error value was dropped. This causes 1ns per tick drift forward of the clock. In 3.7, this logic was isolated to only GENERIC_TIME_VSYSCALL_OLD architectures (s390, ia64, powerpc). The fix is simply to balance the accounting and to subtract the added nanosecond from ntp_error. This allows the internal long-term clock steering to keep the clock accuate. While this fix removes the regression added in 1e75fa8be9f, the ideal solution is to move away from GENERIC_TIME_VSYSCALL_OLD and use the new VSYSCALL method, which avoids entirely the nanosecond granular rounding, and the resulting short-term clock adjustment oscillation needed to keep long term accurate time. Many thanks to Martin for his efforts identifying this subtle bug, and providing the fix. Cc: Tony Luck Cc: Paul Mackerras Cc: Benjamin Herrenschmidt Cc: Andy Lutomirski Cc: Martin Schwidefsky Cc: Paul Turner Cc: Steven Rostedt Cc: Richard Cochran Cc: Prarit Bhargava Cc: Fenghua Yu Cc: Thomas Gleixner Cc: stable #v3.6+ Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 3abf534..87b4f00 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1347,7 +1347,7 @@ static inline void old_vsyscall_fixup(struct timekeeper *tk) tk->xtime_nsec -= remainder; tk->xtime_nsec += 1ULL << tk->shift; tk->ntp_error += remainder << tk->ntp_error_shift; - + tk->ntp_error -= (1ULL << tk->shift) << tk->ntp_error_shift; } #else #define old_vsyscall_fixup(tk)