From patchwork Mon Mar 9 06:27:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 45525 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 A5941214AE for ; Mon, 9 Mar 2015 06:30:08 +0000 (UTC) Received: by wesq59 with SMTP id q59sf3812441wes.1 for ; Sun, 08 Mar 2015 23:30:07 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=Q9xo/JKdwQfZSR3ABgODtQuPEY+26nvgJZ0foFP3Tl8=; b=asW7ci07/fjReKJkfOPY+DpMlrAOXKNYCN/NLRMVu/gCk203ETk/mbZFM3sK4ggpxc fpQlwxPH/DcQJK31K4rBDSGzzhWvly6DvVf60pMINCiVhLJ8AUE1uONJWWF15UKSybe4 A86tVh7Dgyh5FRuuppogp2CS3JlP4N7jdn7twhEy96/JCcCP03+0aheSfyVR1VxPsgjE uGDf5TF+D6i+Vj9cLDpuaXNhFf8MksBsOMLEgDqTUOx3xm42QXuRwJhGs8jJwmT9b8L4 OMCTHLao9I5rlGnrYVBTXllhTYwj3XfuUr4NjBKg0SEYd9suZ6P03H0P/12nY+XlrEas rZCQ== X-Gm-Message-State: ALoCoQlnuSGjWAm9FcytAzh3vjD0Sj5BDZ9Wn+lROP5GqzJIDv0Vx9yWFsAUgPkHu1wJCxb1hpxD X-Received: by 10.112.162.135 with SMTP id ya7mr3616056lbb.14.1425882607894; Sun, 08 Mar 2015 23:30:07 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.5.2 with SMTP id ci2ls66408lad.38.gmail; Sun, 08 Mar 2015 23:30:06 -0700 (PDT) X-Received: by 10.112.92.66 with SMTP id ck2mr23838036lbb.105.1425882606412; Sun, 08 Mar 2015 23:30:06 -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 t9si13449504lal.77.2015.03.08.23.30.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Mar 2015 23:30:06 -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 labgq15 with SMTP id gq15so14800968lab.11 for ; Sun, 08 Mar 2015 23:30:06 -0700 (PDT) X-Received: by 10.152.28.5 with SMTP id x5mr23663087lag.112.1425882606268; Sun, 08 Mar 2015 23:30:06 -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 h5csp1282113lbj; Sun, 8 Mar 2015 23:30:04 -0700 (PDT) X-Received: by 10.70.132.71 with SMTP id os7mr42009514pdb.94.1425882602516; Sun, 08 Mar 2015 23:30:02 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y2si10279709pas.63.2015.03.08.23.30.00; Sun, 08 Mar 2015 23:30:02 -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 S1751670AbbCIG3x (ORCPT + 28 others); Mon, 9 Mar 2015 02:29:53 -0400 Received: from m50-111.126.com ([123.125.50.111]:56623 "EHLO m50-111.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750930AbbCIG3t (ORCPT ); Mon, 9 Mar 2015 02:29:49 -0400 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp5 (Coremail) with SMTP id jtKowAD3dKpwPf1UBXZyAA--.189S4; Mon, 09 Mar 2015 14:28:16 +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 v5 3/4] time: rtc: Don't bother into rtc_resume() for the nonstop clocksource Date: Mon, 9 Mar 2015 14:27:50 +0800 Message-Id: <1425882471-5591-3-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1425882471-5591-1-git-send-email-xlpang@126.com> References: <1425882471-5591-1-git-send-email-xlpang@126.com> X-CM-TRANSID: jtKowAD3dKpwPf1UBXZyAA--.189S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxtF15JF4DCw1Dtr4DGF4DJwb_yoW3Xw18p3 y2kwnxK39rWr15uwnrt3ZruryYgws5KF47J34fK34FkryjqFn7GF1Fk3y5tryDur1fAw1D ZF48t3y5ur4UZFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jGfO7UUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbijA+3v1GfUQ0j8wABsI 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 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(). This patch also improves the name of persistent_clock_exist to make it more grammatical. Signed-off-by: Xunlei Pang --- v5 changes: Rename persistent_clock_exist to persistent_clock_exists. Rename sleeptime_inject to sleeptime_injected. Place these two variables together. drivers/rtc/class.c | 4 +-- include/linux/timekeeping.h | 9 ++---- kernel/time/timekeeping.c | 68 +++++++++++++++++++++++++++++++++------------ 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index 472a5ad..74a943e 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c @@ -55,7 +55,7 @@ static int rtc_suspend(struct device *dev) struct timespec64 delta, delta_delta; int err; - if (has_persistent_clock()) + if (timekeeping_rtc_skipsuspend()) return 0; if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) @@ -102,7 +102,7 @@ static int rtc_resume(struct device *dev) struct timespec64 sleep_time; int err; - if (has_persistent_clock()) + if (timekeeping_rtc_skipresume()) return 0; rtc_hctosys_ret = -ENODEV; diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 3eaae47..7cbd518 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -242,6 +242,9 @@ static inline void timekeeping_clocktai(struct timespec *ts) /* * RTC specific */ +extern bool timekeeping_rtc_skipsuspend(void); +extern bool timekeeping_rtc_skipresume(void); + extern void timekeeping_inject_sleeptime64(struct timespec64 *delta); /* @@ -253,14 +256,8 @@ extern void getnstime_raw_and_real(struct timespec *ts_raw, /* * Persistent clock related interfaces */ -extern bool persistent_clock_exist; extern int persistent_clock_is_local; -static inline bool has_persistent_clock(void) -{ - return persistent_clock_exist; -} - extern void read_persistent_clock(struct timespec *ts); extern void read_boot_clock(struct timespec *ts); extern int update_persistent_clock(struct timespec now); diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 2aae419..eab6b09 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -63,9 +63,6 @@ static struct tk_fast tk_fast_mono ____cacheline_aligned; /* flag for if timekeeping is suspended */ int __read_mostly timekeeping_suspended; -/* Flag for if there is a persistent clock on this platform */ -bool __read_mostly persistent_clock_exist = false; - static inline void tk_normalize_xtime(struct timekeeper *tk) { while (tk->tkr.xtime_nsec >= ((u64)NSEC_PER_SEC << tk->tkr.shift)) { @@ -1045,6 +1042,12 @@ void __weak read_boot_clock(struct timespec *ts) ts->tv_nsec = 0; } +/* Flag for if timekeeping_resume() has injected sleeptime */ +static bool sleeptime_injected; + +/* Flag for if there is a persistent clock on this platform */ +static bool persistent_clock_exists; + /* * timekeeping_init - Initializes the clocksource and common timekeeping values */ @@ -1064,7 +1067,7 @@ void __init timekeeping_init(void) now.tv_sec = 0; now.tv_nsec = 0; } else if (now.tv_sec || now.tv_nsec) - persistent_clock_exist = true; + persistent_clock_exists = true; read_boot_clock(&ts); boot = timespec_to_timespec64(ts); @@ -1127,11 +1130,47 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk, #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_RTC_HCTOSYS_DEVICE) /** + * We have three kinds of time sources to use for sleep time + * injection, the preference order is: + * 1) non-stop clocksource + * 2) persistent clock (ie: RTC accessible when irqs are off) + * 3) RTC + * + * 1) and 2) are used by timekeeping, 3) by RTC subsystem. + * If system has neither 1) nor 2), 3) will be used finally. + * + * + * If timekeeping has injected sleeptime via either 1) or 2), + * 3) becomes needless, so in this case we don't need to call + * rtc_resume(), and this is what timekeeping_rtc_skipresume() + * means. + */ +bool timekeeping_rtc_skipresume(void) +{ + return sleeptime_injected; +} + +/** + * 1) can be determined whether to use or not only when doing + * timekeeping_resume() which is invoked after rtc_suspend(), + * so we can't skip rtc_suspend() surely if system has 1). + * + * But if system has 2), 2) will definitely be used, so in this + * case we don't need to call rtc_suspend(), and this is what + * timekeeping_rtc_skipsuspend() means. + */ +bool timekeeping_rtc_skipsuspend(void) +{ + return persistent_clock_exists; +} + +/** * 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. @@ -1141,13 +1180,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); @@ -1180,8 +1212,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_injected = false; read_persistent_clock(&tmp); ts_new = timespec_to_timespec64(tmp); @@ -1228,14 +1260,14 @@ static void timekeeping_resume(void) nsec += ((u64) cycle_delta * mult) >> shift; ts_delta = ns_to_timespec64(nsec); - suspendtime_found = true; + sleeptime_injected = true; } else if (timespec64_compare(&ts_new, &persistent_clock_suspendtime) > 0) { ts_delta = timespec64_sub(ts_new, persistent_clock_suspendtime); - suspendtime_found = true; + sleeptime_injected = true; } - if (suspendtime_found) + if (sleeptime_injected) __timekeeping_inject_sleeptime(tk, &ts_delta); /* Re-base the last cycle value */ @@ -1272,14 +1304,14 @@ static int timekeeping_suspend(void) */ if (persistent_clock_suspendtime.tv_sec || persistent_clock_suspendtime.tv_nsec) - persistent_clock_exist = true; + persistent_clock_exists = true; raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); timekeeping_forward_now(tk); timekeeping_suspended = 1; - if (has_persistent_clock()) { + if (persistent_clock_exists) { /* * To avoid drift caused by repeated suspend/resumes, * which each can add ~1 second drift error,