From patchwork Thu Jan 22 12:01:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 43514 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BD9DD218DB for ; Thu, 22 Jan 2015 12:02:35 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id n3sf1432928wiv.0 for ; Thu, 22 Jan 2015 04:02:35 -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=gxwo37ah1gdRWYp7o+f9QxL8MT8a/KqGmZ0nh5vGs3Q=; b=Q9FvMEc0SzITsJNM8ax/GbfQMvxatCs6CNaq0gm6mbKHV6VbxWCsL6/7uKcOaFPoyU FC5QA1nBVyBFLc79jjC2xHxFtJfXO4QSB+oo85nzEVMIro6WmjJ070+gDYwfE1G9wL9m FtTmgIqPEKmihgfIsi0w09mix+1yNUKLI7iVY+SeDhcrk6LU85sDp97t8oTau7usDdOx h8EjcO6kDglR5k9uTaPH4+7XxuU8Fmp17UEwi5tXu0nf5CUKPzS40sFPGVVdM+TXiL4y nLIu4yMCdTbEQDXY45XGXkkO1tCso3QGlPr0AQJGqUdguu4OKzcDZn71w4DN9aw1pUaM Cavg== X-Gm-Message-State: ALoCoQnAgxKYAiMH98qfkryPsVzW9wNohySfpKRiXLSaHWP8Ndk1eAfSwvFggPUFH5ZKEaHnkOpU X-Received: by 10.180.84.7 with SMTP id u7mr333546wiy.0.1421928155087; Thu, 22 Jan 2015 04:02:35 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.99 with SMTP id 3ls158216lat.107.gmail; Thu, 22 Jan 2015 04:02:34 -0800 (PST) X-Received: by 10.152.198.200 with SMTP id je8mr1016468lac.93.1421928154901; Thu, 22 Jan 2015 04:02:34 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id a3si3743935lah.98.2015.01.22.04.02.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jan 2015 04:02:34 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id l4so1085799lbv.13 for ; Thu, 22 Jan 2015 04:02:34 -0800 (PST) X-Received: by 10.152.6.132 with SMTP id b4mr1073354laa.59.1421928154760; Thu, 22 Jan 2015 04:02:34 -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.9.200 with SMTP id c8csp237712lbb; Thu, 22 Jan 2015 04:02:33 -0800 (PST) X-Received: by 10.70.128.45 with SMTP id nl13mr1600911pdb.126.1421928152905; Thu, 22 Jan 2015 04:02:32 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8si12443397pas.21.2015.01.22.04.02.32; Thu, 22 Jan 2015 04:02:32 -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 S1752062AbbAVMC2 (ORCPT + 28 others); Thu, 22 Jan 2015 07:02:28 -0500 Received: from mail-qg0-f47.google.com ([209.85.192.47]:61934 "EHLO mail-qg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751671AbbAVMCZ (ORCPT ); Thu, 22 Jan 2015 07:02:25 -0500 Received: by mail-qg0-f47.google.com with SMTP id z60so766335qgd.6 for ; Thu, 22 Jan 2015 04:02:24 -0800 (PST) X-Received: by 10.140.86.99 with SMTP id o90mr1563667qgd.21.1421928144775; Thu, 22 Jan 2015 04:02:24 -0800 (PST) Received: from ip-10-181-65-231.ec2.internal ([54.235.93.228]) by mx.google.com with ESMTPSA id j6sm3012956qga.9.2015.01.22.04.02.24 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Jan 2015 04:02:24 -0800 (PST) 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 v2 1/3] time: Don't bother to run rtc_resume() for the nonstop clocksource Date: Thu, 22 Jan 2015 12:01:15 +0000 Message-Id: <1421928077-4698-1-git-send-email-pang.xunlei@linaro.org> X-Mailer: git-send-email 2.2.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pang.xunlei@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.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org 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: , 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 --- v1->v2: Modify according to Thomas' feedback. drivers/rtc/class.c | 2 +- include/linux/timekeeping.h | 7 +++++++ kernel/time/timekeeping.c | 16 +++++----------- 3 files changed, 13 insertions(+), 12 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..2b87c64 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -238,6 +238,13 @@ extern void getnstime_raw_and_real(struct timespec *ts_raw, */ extern bool persistent_clock_exist; extern int persistent_clock_is_local; +extern bool timekeeping_sleeptime_inject; + +/* Used by rtc_resume() */ +static inline bool timekeeping_sleeptime_injected(void) +{ + return timekeeping_sleeptime_inject; +} static inline bool has_persistent_clock(void) { diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 6a93185..732ccd0 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -65,6 +65,7 @@ int __read_mostly timekeeping_suspended; /* Flag for if there is a persistent clock on this platform */ bool __read_mostly persistent_clock_exist = false; +bool timekeeping_sleeptime_inject; static inline void tk_normalize_xtime(struct timekeeper *tk) { @@ -1140,13 +1141,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); @@ -1178,8 +1172,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; + timekeeping_sleeptime_inject = false; read_persistent_clock(&tmp); ts_new = timespec_to_timespec64(tmp); @@ -1226,13 +1220,13 @@ static void timekeeping_resume(void) nsec += ((u64) cycle_delta * mult) >> shift; ts_delta = ns_to_timespec64(nsec); - suspendtime_found = true; + timekeeping_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; + timekeeping_sleeptime_inject = true; } - if (suspendtime_found) + if (timekeeping_sleeptime_inject) __timekeeping_inject_sleeptime(tk, &ts_delta); /* Re-base the last cycle value */