From patchwork Thu Jan 29 15:59:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 43952 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B26252410D for ; Thu, 29 Jan 2015 16:04:15 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id b6sf21711614lbj.0 for ; Thu, 29 Jan 2015 08:04:13 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=NDs1YoY9pmPyxJKDtAd7T/VQwXW4tmra2hZOFYtGsjg=; b=FYUQZT1/iBGofQyJ4n0euJWVWsrHnaU2bv4H1Jwoj04+6x5tULvPo1ljr95gCFbSb/ vX+AbygGkZ+1u4Em+WzIf3aDsBLRpl2yR8Jrq60jtLkciWZOwRO5Wf0ra8e/OOngrKSs a8B0qoD8BntkJfGfdp2FDbPM6oWA+6+hfClHt7d5vwW5Vq2Ko2tIghZfIzm2uJ5NtsHT Be6xKcWKhp/KLCBnTYhDPZALEixsmnpyYvi4saCNYZJSrsB3EYSXzsk+8QfAl3gBcLcU 5eShAqjn8hJ6Hnt7fAxSoreIVP7yfR7BkLQm/mTbd23OFKfZOLbezf2hhui2PBlWMjFT avEw== X-Gm-Message-State: ALoCoQnl4aRAZHKETDj0BFNT+AE32OT1s2sgChg2bWbnSJeYDFWpAQOAiaD/XXFLLbPi8x+7MgQj X-Received: by 10.112.37.72 with SMTP id w8mr212770lbj.6.1422547453195; Thu, 29 Jan 2015 08:04:13 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.197 with SMTP id g5ls336863lam.99.gmail; Thu, 29 Jan 2015 08:04:12 -0800 (PST) X-Received: by 10.152.4.102 with SMTP id j6mr1586015laj.95.1422547452953; Thu, 29 Jan 2015 08:04:12 -0800 (PST) Received: from mail-lb0-x22a.google.com (mail-lb0-x22a.google.com. [2a00:1450:4010:c04::22a]) by mx.google.com with ESMTPS id s10si7835605lae.47.2015.01.29.08.04.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 Jan 2015 08:04:12 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::22a as permitted sender) client-ip=2a00:1450:4010:c04::22a; Received: by mail-lb0-f170.google.com with SMTP id w7so29695099lbi.1 for ; Thu, 29 Jan 2015 08:04:12 -0800 (PST) X-Received: by 10.112.41.234 with SMTP id i10mr1692205lbl.25.1422547452803; Thu, 29 Jan 2015 08:04:12 -0800 (PST) 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 h5csp1807623lbj; Thu, 29 Jan 2015 08:04:11 -0800 (PST) X-Received: by 10.66.156.229 with SMTP id wh5mr1593891pab.119.1422547450818; Thu, 29 Jan 2015 08:04:10 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ca5si10470084pdb.52.2015.01.29.08.04.09; Thu, 29 Jan 2015 08:04:10 -0800 (PST) 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 S1755571AbbA2QEF (ORCPT + 29 others); Thu, 29 Jan 2015 11:04:05 -0500 Received: from m50-111.126.com ([123.125.50.111]:44755 "EHLO m50-111.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750840AbbA2QEC (ORCPT ); Thu, 29 Jan 2015 11:04:02 -0500 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp5 (Coremail) with SMTP id jtKowAAnFg_qWMpUTaANDQ--.1799S2; Thu, 29 Jan 2015 23:59:53 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: rtc-linux@googlegroups.com, Thomas Gleixner , Alessandro Zummo , John Stultz , Arnd Bergmann , Xunlei Pang Subject: [PATCH v3 1/2] time: Don't bother to run rtc_resume() for the nonstop clocksource Date: Thu, 29 Jan 2015 23:59:06 +0800 Message-Id: <1422547147-3073-1-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: jtKowAAnFg_qWMpUTaANDQ--.1799S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGr4xGr4DAr48Aw4UJF4xZwb_yoWrCFWDpr Wak343KFZrXF15uwnFv3ZruryYqws5KFW7JFyfCryIkry8Xan7GF1F93y5JryUurZ7Aw1j vF18tw45ur4UXrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jPuc_UUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbigRKQv1E0bBuoLgAAso 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:c04::22a 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 If a system does not provide a persistent_clock(), the time will be updated on resume by rtc_resume(). With the addition of the non-stop clocksources for suspend timing, those systems set the time on resume in timekeeping_resume(), but may not provide a valid persistent_clock(). This results in the rtc_resume() logic thinking no one has set the time and it then will over-write the suspend time again, which is not necessary and only increases clock error. So, fix this for rtc_resume(). Signed-off-by: Xunlei Pang --- v2->v3: Refine according to John's comments using internal variable. drivers/rtc/class.c | 2 +- include/linux/timekeeping.h | 1 + kernel/time/timekeeping.c | 32 ++++++++++++++++++++------------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index 472a5ad..6100af5 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c @@ -102,7 +102,7 @@ static int rtc_resume(struct device *dev) struct timespec64 sleep_time; int err; - if (has_persistent_clock()) + if (timekeeping_sleeptime_injected()) return 0; rtc_hctosys_ret = -ENODEV; diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 9b63d13..17a460d 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -225,6 +225,7 @@ static inline void timekeeping_clocktai(struct timespec *ts) /* * RTC specific */ +extern bool timekeeping_sleeptime_injected(void); extern void timekeeping_inject_sleeptime64(struct timespec64 *delta); /* diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 6a93185..b02133e 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1125,12 +1125,26 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk, tk_debug_account_sleep_time(delta); } +static bool sleeptime_inject; + +#if defined(CONFIG_RTC_CLASS) && \ + defined(CONFIG_PM_SLEEP) && \ + defined(CONFIG_RTC_HCTOSYS_DEVICE) +/** + * Used by rtc_resume(). + */ +bool timekeeping_sleeptime_injected(void) +{ + return sleeptime_inject; +} + /** * timekeeping_inject_sleeptime64 - Adds suspend interval to timeekeeping values * @delta: pointer to a timespec64 delta value * * This hook is for architectures that cannot support read_persistent_clock - * because their RTC/persistent clock is only accessible when irqs are enabled. + * because their RTC/persistent clock is only accessible when irqs are enabled, + * and also don't have an effective nonstop clocksource. * * This function should only be called by rtc_resume(), and allows * a suspend offset to be injected into the timekeeping values. @@ -1140,13 +1154,6 @@ void timekeeping_inject_sleeptime64(struct timespec64 *delta) struct timekeeper *tk = &tk_core.timekeeper; unsigned long flags; - /* - * Make sure we don't set the clock twice, as timekeeping_resume() - * already did it - */ - if (has_persistent_clock()) - return; - raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); @@ -1162,6 +1169,7 @@ void timekeeping_inject_sleeptime64(struct timespec64 *delta) /* signal hrtimers about time change */ clock_was_set(); } +#endif /** * timekeeping_resume - Resumes the generic timekeeping subsystem. @@ -1178,8 +1186,8 @@ static void timekeeping_resume(void) struct timespec64 ts_new, ts_delta; struct timespec tmp; cycle_t cycle_now, cycle_delta; - bool suspendtime_found = false; + sleeptime_inject = false; read_persistent_clock(&tmp); ts_new = timespec_to_timespec64(tmp); @@ -1226,13 +1234,13 @@ static void timekeeping_resume(void) nsec += ((u64) cycle_delta * mult) >> shift; ts_delta = ns_to_timespec64(nsec); - suspendtime_found = true; + sleeptime_inject = true; } else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) { ts_delta = timespec64_sub(ts_new, timekeeping_suspend_time); - suspendtime_found = true; + sleeptime_inject = true; } - if (suspendtime_found) + if (sleeptime_inject) __timekeeping_inject_sleeptime(tk, &ts_delta); /* Re-base the last cycle value */