From patchwork Thu Apr 2 03:34:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 46691 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 72254216D1 for ; Thu, 2 Apr 2015 03:35:40 +0000 (UTC) Received: by lbdc10 with SMTP id c10sf14469638lbd.0 for ; Wed, 01 Apr 2015 20:35:39 -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=3wrws99rTHK3e1l0BHStsTRBsZh5KOxAD2BULnERQ40=; b=TwGoLE8PmXEwekED99aHUT8WEnFy8/Hdw6uh47LXOG5Yn2QNJZA9AxcrrET1eOH+qf BIU3n0V1myUFCQooKuGHXP9FQJUCWx7eDVwADJ97mqR3ZlCpAnuY13/2tmNOgSivvdgR 9U2fwaX8/F/H5azsUf+o4gulBMJtJIRiktHe5AM+1Gbdz/PBg9NMfv9+47j5OciZOVuO CpnLXEdoJHcO/DqZ23AY0Z+Ks54MCq/MD3vIcBzOp7kiFBnstykZVXpF5GgNppKZS93V eJ1cda4+VuW5atCUJd0YbwAkqmsh7fo2FZCqdrtJoeSB953mUtBYBcWx9fVdfnATAFpB jXhA== X-Gm-Message-State: ALoCoQnIvVEu92QeKPivx/JCw35rBOeX3QBDx8+aMifag3TuXytCLrMhQzNpbubcKzlOrSGlP7oo X-Received: by 10.152.206.36 with SMTP id ll4mr1327537lac.6.1427945739425; Wed, 01 Apr 2015 20:35:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.6.10 with SMTP id cq10ls153120lad.72.gmail; Wed, 01 Apr 2015 20:35:39 -0700 (PDT) X-Received: by 10.112.140.38 with SMTP id rd6mr38301020lbb.116.1427945738990; Wed, 01 Apr 2015 20:35:38 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id w7si3120700lbk.135.2015.04.01.20.35.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Apr 2015 20:35:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbdc10 with SMTP id c10so50290957lbd.2 for ; Wed, 01 Apr 2015 20:35:38 -0700 (PDT) X-Received: by 10.152.8.161 with SMTP id s1mr29636797laa.41.1427945738880; Wed, 01 Apr 2015 20:35:38 -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.57.201 with SMTP id k9csp1063411lbq; Wed, 1 Apr 2015 20:35:38 -0700 (PDT) X-Received: by 10.68.93.194 with SMTP id cw2mr82413027pbb.129.1427945708882; Wed, 01 Apr 2015 20:35:08 -0700 (PDT) Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com. [209.85.220.46]) by mx.google.com with ESMTPS id f12si5544623pdm.155.2015.04.01.20.35.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Apr 2015 20:35:08 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.46 as permitted sender) client-ip=209.85.220.46; Received: by pacgg7 with SMTP id gg7so71306348pac.0 for ; Wed, 01 Apr 2015 20:35:07 -0700 (PDT) X-Received: by 10.70.119.37 with SMTP id kr5mr82531587pdb.107.1427945707406; Wed, 01 Apr 2015 20:35:07 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id da10sm3572603pac.42.2015.04.01.20.35.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Apr 2015 20:35:06 -0700 (PDT) From: John Stultz To: lkml Cc: Xunlei Pang , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , John Stultz Subject: [PATCH 17/21] time: Fix a bug in timekeeping_suspend() with no persistent clock Date: Wed, 1 Apr 2015 20:34:37 -0700 Message-Id: <1427945681-29972-18-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427945681-29972-1-git-send-email-john.stultz@linaro.org> References: <1427945681-29972-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.180 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: , From: Xunlei Pang When there's no persistent clock, normally timekeeping_suspend_time should always be zero, but this can break in timekeeping_suspend(). At T1, there was a system suspend, so old_delta was assigned T1. After some time, one time adjustment happened, and xtime got the value of T1-dt(0s Cc: Thomas Gleixner Cc: Ingo Molnar Signed-off-by: Xunlei Pang Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 7d799d3..6dafcea 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1255,7 +1255,7 @@ void __init timekeeping_init(void) raw_spin_unlock_irqrestore(&timekeeper_lock, flags); } -/* time in seconds when suspend began */ +/* time in seconds when suspend began for persistent clock */ static struct timespec64 timekeeping_suspend_time; /** @@ -1430,24 +1430,26 @@ int timekeeping_suspend(void) timekeeping_forward_now(tk); timekeeping_suspended = 1; - /* - * To avoid drift caused by repeated suspend/resumes, - * which each can add ~1 second drift error, - * try to compensate so the difference in system time - * and persistent_clock time stays close to constant. - */ - delta = timespec64_sub(tk_xtime(tk), timekeeping_suspend_time); - delta_delta = timespec64_sub(delta, old_delta); - if (abs(delta_delta.tv_sec) >= 2) { + if (has_persistent_clock()) { /* - * if delta_delta is too large, assume time correction - * has occured and set old_delta to the current delta. + * To avoid drift caused by repeated suspend/resumes, + * which each can add ~1 second drift error, + * try to compensate so the difference in system time + * and persistent_clock time stays close to constant. */ - old_delta = delta; - } else { - /* Otherwise try to adjust old_system to compensate */ - timekeeping_suspend_time = - timespec64_add(timekeeping_suspend_time, delta_delta); + delta = timespec64_sub(tk_xtime(tk), timekeeping_suspend_time); + delta_delta = timespec64_sub(delta, old_delta); + if (abs(delta_delta.tv_sec) >= 2) { + /* + * if delta_delta is too large, assume time correction + * has occurred and set old_delta to the current delta. + */ + old_delta = delta; + } else { + /* Otherwise try to adjust old_system to compensate */ + timekeeping_suspend_time = + timespec64_add(timekeeping_suspend_time, delta_delta); + } } timekeeping_update(tk, TK_MIRROR);