From patchwork Thu Apr 18 12:40:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot for Kobe Wu X-Patchwork-Id: 10917383 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B2D16912 for ; Thu, 25 Apr 2019 15:40:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A07FD28BFE for ; Thu, 25 Apr 2019 15:40:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9333128D0A; Thu, 25 Apr 2019 15:40:47 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3F95A28C57 for ; Thu, 25 Apr 2019 15:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Subject:To: References:In-Reply-To:Message-ID:From:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tJLHBXSIR6T2dtTW+lTqI5CQoUEdaEeSXKzNFRKfTos=; b=L0D8rsIjMafeNQ Q/7ZN7tCxsWkdHuCkR4g93eDdAuKbXCkZKXl4TGX8rlfNX5ngw9ZLaq6Oa8acaasdVe7EcZi2b7dI TGaOYFWgELss0SvLbcFOlTLnf6eYe3mAFqkzc6rh/+0U6R/qkQzfiTAJhxfNjDO3PyrK5z9NDzNin ueI3+fBCug97eFJ/L8L0toL4IdRjg4ofqpp9PESRMrBiZxGXkHhHfripnpELa/PyHaOOJkKwxYb9w gioOid0w5OB1paztuhnzwlJPb2IistotaEwwOF7jg/lKBPFHZ/4M5qWpftqnFSRAGKZY3yqPjf/xg kuCud/PW+Ys1QiN+wt0g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJgUK-0001Uu-9U; Thu, 25 Apr 2019 15:40:40 +0000 Received: from terminus.zytor.com ([198.137.202.136]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hH6Ly-0007Zc-2b; Thu, 18 Apr 2019 12:41:24 +0000 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x3ICf5NI190534 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 18 Apr 2019 05:41:06 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x3ICf5NI190534 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019041745; t=1555591269; bh=6OJ0bNksX9Qhw6vmZ+FIym5DHCb2o24skW/r+X2GbsI=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=T6SH//riICm6cTpTkxEgOZdSsqn7vP67T+fOGJ+bX/AFcfuedVh2usG/U2a/NfvZN xfkVsxQWNGgSVQ5qjWuBn783w7m6xplbnvNHElV3JPRDWKGQTIP9sLiGVNM76k6OOF DbgF/nvVuhB/NB9Fb1KBAqjInYzzpeeVlXT7zLSQVpCG5gLsMIq9sPMA4ihv75E5WW UoLrJDa59kc+kfBUwnqcpVxvuvAGVlg87hD43iMdRpsKaiNBvLmMogOWHMMTTjD6OU LljtlWUFm8siVuYX9H/2af+xvuv4zpDUmhpbPnaknmFT1JoC0RftAbv3j3e0YfkxDs UJrzgRI7xl8Ag== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x3ICewfE190527; Thu, 18 Apr 2019 05:40:58 -0700 Date: Thu, 18 Apr 2019 05:40:58 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Chang-An Chen Message-ID: In-Reply-To: <1553828349-8914-1-git-send-email-chang-an.chen@mediatek.com> References: <1553828349-8914-1-git-send-email-chang-an.chen@mediatek.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/urgent] timers/sched_clock: Prevent generic sched_clock wrap caused by tick_freeze() Git-Commit-ID: 3f2552f7e9c5abef2775c53f7af66532f8bf65bc X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk X-Bad-Reply: References and In-Reply-To but no 'Re:' in Subject. X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190418_054122_117672_02EDD880 X-CRM114-Status: GOOD ( 10.03 ) X-Mailman-Approved-At: Thu, 25 Apr 2019 08:40:38 -0700 X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: john.stultz@linaro.org, matthias.bgg@gmail.com, freddy.hsin@mediatek.com, hpa@zytor.com, keescook@chromium.org, chang-an.chen@mediatek.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, kuohong.wang@mediatek.com, mingo@kernel.org, cminyard@mvista.com, fweisbec@gmail.com, linux-mediatek@lists.infradead.org, stanley.chu@mediatek.com Cc: cminyard@mvista.com, freddy.hsin@mediatek.com, john.stultz@linaro.org, keescook@chromium.org, fweisbec@gmail.com, kuohong.wang@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, hpa@zytor.com, matthias.bgg@gmail.com, chang-an.chen@mediatek.com, tglx@linutronix.de, stanley.chu@mediatek.com, mingo@kernel.org, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Commit-ID: 3f2552f7e9c5abef2775c53f7af66532f8bf65bc Gitweb: https://git.kernel.org/tip/3f2552f7e9c5abef2775c53f7af66532f8bf65bc Author: Chang-An Chen AuthorDate: Fri, 29 Mar 2019 10:59:09 +0800 Committer: Thomas Gleixner CommitDate: Thu, 18 Apr 2019 14:34:53 +0200 timers/sched_clock: Prevent generic sched_clock wrap caused by tick_freeze() tick_freeze() introduced by suspend-to-idle in commit 124cf9117c5f ("PM / sleep: Make it possible to quiesce timers during suspend-to-idle") uses timekeeping_suspend() instead of syscore_suspend() during suspend-to-idle. As a consequence generic sched_clock will keep going because sched_clock_suspend() and sched_clock_resume() are not invoked during suspend-to-idle which can result in a generic sched_clock wrap. On a ARM system with suspend-to-idle enabled, sched_clock is registered as "56 bits at 13MHz, resolution 76ns, wraps every 4398046511101ns", which means the real wrapping duration is 8796093022202ns. [ 134.551779] suspend-to-idle suspend (timekeeping_suspend()) [ 1204.912239] suspend-to-idle resume (timekeeping_resume()) ...... [ 1206.912239] suspend-to-idle suspend (timekeeping_suspend()) [ 5880.502807] suspend-to-idle resume (timekeeping_resume()) ...... [ 6000.403724] suspend-to-idle suspend (timekeeping_suspend()) [ 8035.753167] suspend-to-idle resume (timekeeping_resume()) ...... [ 8795.786684] (2)[321:charger_thread]...... [ 8795.788387] (2)[321:charger_thread]...... [ 0.057226] (0)[0:swapper/0]...... [ 0.061447] (2)[0:swapper/2]...... sched_clock was not stopped during suspend-to-idle, and sched_clock_poll hrtimer was not expired because timekeeping_suspend() was invoked during suspend-to-idle. It makes sched_clock wrap at kernel time 8796s. To prevent this, invoke sched_clock_suspend() and sched_clock_resume() in tick_freeze() together with timekeeping_suspend() and timekeeping_resume(). Fixes: 124cf9117c5f (PM / sleep: Make it possible to quiesce timers during suspend-to-idle) Signed-off-by: Chang-An Chen Signed-off-by: Thomas Gleixner Cc: Frederic Weisbecker Cc: Matthias Brugger Cc: John Stultz Cc: Kees Cook Cc: Corey Minyard Cc: Cc: Cc: Stanley Chu Cc: Cc: Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/1553828349-8914-1-git-send-email-chang-an.chen@mediatek.com --- kernel/time/sched_clock.c | 4 ++-- kernel/time/tick-common.c | 2 ++ kernel/time/timekeeping.h | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index 094b82ca95e5..930113b9799a 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c @@ -272,7 +272,7 @@ static u64 notrace suspended_sched_clock_read(void) return cd.read_data[seq & 1].epoch_cyc; } -static int sched_clock_suspend(void) +int sched_clock_suspend(void) { struct clock_read_data *rd = &cd.read_data[0]; @@ -283,7 +283,7 @@ static int sched_clock_suspend(void) return 0; } -static void sched_clock_resume(void) +void sched_clock_resume(void) { struct clock_read_data *rd = &cd.read_data[0]; diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index 529143b4c8d2..df401463a191 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c @@ -487,6 +487,7 @@ void tick_freeze(void) trace_suspend_resume(TPS("timekeeping_freeze"), smp_processor_id(), true); system_state = SYSTEM_SUSPEND; + sched_clock_suspend(); timekeeping_suspend(); } else { tick_suspend_local(); @@ -510,6 +511,7 @@ void tick_unfreeze(void) if (tick_freeze_depth == num_online_cpus()) { timekeeping_resume(); + sched_clock_resume(); system_state = SYSTEM_RUNNING; trace_suspend_resume(TPS("timekeeping_freeze"), smp_processor_id(), false); diff --git a/kernel/time/timekeeping.h b/kernel/time/timekeeping.h index 7a9b4eb7a1d5..141ab3ab0354 100644 --- a/kernel/time/timekeeping.h +++ b/kernel/time/timekeeping.h @@ -14,6 +14,13 @@ extern u64 timekeeping_max_deferment(void); extern void timekeeping_warp_clock(void); extern int timekeeping_suspend(void); extern void timekeeping_resume(void); +#ifdef CONFIG_GENERIC_SCHED_CLOCK +extern int sched_clock_suspend(void); +extern void sched_clock_resume(void); +#else +static inline int sched_clock_suspend(void) { return 0; } +static inline void sched_clock_resume(void) { } +#endif extern void do_timer(unsigned long ticks); extern void update_wall_time(void);