From patchwork Thu Mar 19 02:42:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 46007 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f197.google.com (mail-we0-f197.google.com [74.125.82.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 251A82153B for ; Thu, 19 Mar 2015 02:45:02 +0000 (UTC) Received: by wesu56 with SMTP id u56sf10218822wes.2 for ; Wed, 18 Mar 2015 19:45:01 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=NOskvk2NTVgQm8f+enfzdKRfxp6V1tDqJExrEJTxP7k=; b=aA/VXcuk5vF0YYXHdcWP1cPV88QhqVwy8xnpKz5pqcoOMdzECRltjSholFTlCSrafg ++duvNf3Kx/NBJyfSPpxTvHza9PumOattlCRUOBuqjga5yaUlw93k5A4hdO8zc/dhJYg MJIMJHEDeVCa8lRukPrqgUbr4thvN+olAu6kdhyfdnNG7oILtygtt/I0uAx5zWvCyOOu 8bz7Gg+zi9h86g6W8xMlLN1DVrNz4dY8+YdtLp86nAYkHxqaPCDItf0nv7tEi1McJwUA 0AIPmXwGV7ke9bFkPBCH02124QFAovu9Zl+q9vE/FJeQL25trRVesDWWWuFWkSgz7zmn LRHA== X-Gm-Message-State: ALoCoQkrgvvzJgrRi68zGdobOhSjuUgJLjUStUdOZ/8zvijp78qDLwFrWaCu721nkfNy3shXlbUO X-Received: by 10.112.162.135 with SMTP id ya7mr11479403lbb.14.1426733101409; Wed, 18 Mar 2015 19:45:01 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.169 with SMTP id s9ls251059laa.8.gmail; Wed, 18 Mar 2015 19:45:00 -0700 (PDT) X-Received: by 10.152.37.97 with SMTP id x1mr63192001laj.2.1426733100865; Wed, 18 Mar 2015 19:45:00 -0700 (PDT) Received: from mail-la0-x234.google.com (mail-la0-x234.google.com. [2a00:1450:4010:c03::234]) by mx.google.com with ESMTPS id g7si14194060lbd.52.2015.03.18.19.45.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Mar 2015 19:45:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::234 as permitted sender) client-ip=2a00:1450:4010:c03::234; Received: by lagg8 with SMTP id g8so51566155lag.1 for ; Wed, 18 Mar 2015 19:45:00 -0700 (PDT) X-Received: by 10.152.5.194 with SMTP id u2mr67074688lau.88.1426733100441; Wed, 18 Mar 2015 19:45:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp109220lbj; Wed, 18 Mar 2015 19:44:59 -0700 (PDT) X-Received: by 10.66.137.98 with SMTP id qh2mr167652462pab.76.1426733098500; Wed, 18 Mar 2015 19:44:58 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ok14si55472pdb.2.2015.03.18.19.44.57; Wed, 18 Mar 2015 19:44:58 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752044AbbCSCov (ORCPT + 27 others); Wed, 18 Mar 2015 22:44:51 -0400 Received: from m50-111.126.com ([123.125.50.111]:50415 "EHLO m50-111.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750756AbbCSCos (ORCPT ); Wed, 18 Mar 2015 22:44:48 -0400 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp5 (Coremail) with SMTP id jtKowAAndI2hNwpVuhRjAA--.398S2; Thu, 19 Mar 2015 10:42:47 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: rtc-linux@googlegroups.com, Thomas Gleixner , Alessandro Zummo , John Stultz , Arnd Bergmann , Peter Zijlstra , Xunlei Pang Subject: [PATCH 1/2] time: Fix a bug in timekeeping_suspend() with no persistent clock Date: Thu, 19 Mar 2015 10:42:31 +0800 Message-Id: <1426732952-26893-1-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: jtKowAAndI2hNwpVuhRjAA--.398S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxXr43Cry7Kw43Aw4DXrW7twb_yoW5CFyfpr W7Cr13Ka1DXFy3CrnFyFnru3s0gws5tw4UZr9Ik34xC347Xrs3Gr4Fk3WrtryqvryfAr98 ZF1Iq3y5u3y8GF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jqZXOUUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbiWwjBv1PM7hbVjgAAsR Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: xlpang@126.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::234 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@; dmarc=fail (p=NONE dis=NONE) header.from=126.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org 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 --- 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 1345e63..605da5c 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1127,7 +1127,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; /** @@ -1304,24 +1304,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);