From patchwork Tue May 29 08:15:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 10434517 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EB3E8602CC for ; Tue, 29 May 2018 08:15:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE4A7285B6 for ; Tue, 29 May 2018 08:15:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D081F285D1; Tue, 29 May 2018 08:15:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D4CF285B6 for ; Tue, 29 May 2018 08:15:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755179AbeE2IPe (ORCPT ); Tue, 29 May 2018 04:15:34 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:51452 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754919AbeE2IPb (ORCPT ); Tue, 29 May 2018 04:15:31 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id B2E366038E; Tue, 29 May 2018 08:15:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527581730; bh=Y+SZv2Y5zz45rmAbkYO+Iiz2xArImVn41idg9JsDq7w=; h=From:To:Cc:Subject:Date:From; b=Q9vuMJZwhCYF/oLhY2C+vzqODDZFjoqr2RDICGSqcxBzKTgCRTK4Sq+hqjK7kFf95 M/l4XUP+GXpQAEfdqXQW0LnrReCvkvabOJBXa4N3rdofcuS9du5uhtMjDNF6YggbTQ C15nzEQ+ZRHA+3DjEx5PCByi685k6BDZzQjbHn7I= Received: from mojha-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mojha@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id B16B56028C; Tue, 29 May 2018 08:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527581730; bh=Y+SZv2Y5zz45rmAbkYO+Iiz2xArImVn41idg9JsDq7w=; h=From:To:Cc:Subject:Date:From; b=Q9vuMJZwhCYF/oLhY2C+vzqODDZFjoqr2RDICGSqcxBzKTgCRTK4Sq+hqjK7kFf95 M/l4XUP+GXpQAEfdqXQW0LnrReCvkvabOJBXa4N3rdofcuS9du5uhtMjDNF6YggbTQ C15nzEQ+ZRHA+3DjEx5PCByi685k6BDZzQjbHn7I= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org B16B56028C Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=mojha@codeaurora.org From: Mukesh Ojha To: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mukesh Ojha Subject: [PATCH] time: Fix sleeptime injection for non-stop clocksource & persistent clock Date: Tue, 29 May 2018 13:45:18 +0530 Message-Id: <1527581718-5624-1-git-send-email-mojha@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, for both non-stop clocksource and persistent clock there is a corner case, when a driver failed to go suspend mode rtc_resume injects the sleeptime as timekeeping_rtc_skipresume returned 'false' due to which we can see mismatch in time with system clock. Success case: {sleeptime_injected=true} rtc_suspend() => timekeeping_suspend() => timekeeping_resume() => rtc_resume() Failure case: {failure in sleep path} {sleeptime_injected=false} rtc_suspend() => rtc_resume() Change-Id: I98928761c98cec21a3033a55d3e10fb34138f38c Signed-off-by: Mukesh Ojha --- kernel/time/timekeeping.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 427e33d..c022d82 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1511,9 +1511,6 @@ void __weak read_boot_clock64(struct timespec64 *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; @@ -1611,7 +1608,14 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk, */ bool timekeeping_rtc_skipresume(void) { - return sleeptime_injected; + struct timekeeper *tk = &tk_core.timekeeper; + bool skip_rtc_resume = false; + + skip_rtc_resume = ((tk->tkr_mono.clock->flags & + CLOCK_SOURCE_SUSPEND_NONSTOP) || + (persistent_clock_exists)) ? true : false; + + return skip_rtc_resume; } /** @@ -1671,8 +1675,8 @@ void timekeeping_resume(void) unsigned long flags; struct timespec64 ts_new, ts_delta; cycle_t cycle_now, cycle_delta; + bool sleeptime_injected = false; - sleeptime_injected = false; read_persistent_clock64(&ts_new); clockevents_resume();