From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A2E3C10F0E for ; Mon, 15 Apr 2019 05:45:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E0F1C2073F for ; Mon, 15 Apr 2019 05:45:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JIfodPj4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0F1C2073F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HPwNT6vDohmfyH5VwQKfEdHMUTPE2Bol+I/hxrytTQQ=; b=JIfodPj4BQcJ89 lF/NCPtMxO9rZbLQZ368u3/mJJpUdEOOPkECmdxTQ9E/t5fe5ALtRi8RjJLg3Q9nARf269uT8Ohz1 Vgz6qTC/xq0ScGqHaOZ/7JoYXwhmRElnDW9ESkaQ3mFS7ptQpYDveqCFnNx8lZcW6FriKkcwaNrjG FTSURc7Pv/AAmV9GyMrfgqTVJEkBZHU+jr5yeV7E6pp/bZiipc9jjrGAXxhDDIH1DmDkdakfAhI0x 2y1Eu0Dy0FT21vVlzS9wVOwLSVEK5TktbQglhHZVqwSwRV6haBMdXRD/2Ql+X6cfAYC2WiZGJtXGo ltP6yK/jfSOMCO+QOKLQ==; 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 1hFuQN-0007vb-Ig; Mon, 15 Apr 2019 05:44:59 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hFuQK-0007uW-EU; Mon, 15 Apr 2019 05:44:58 +0000 X-UUID: ab573586491148e594754b7ae2e8a6ac-20190414 X-UUID: ab573586491148e594754b7ae2e8a6ac-20190414 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1668146921; Sun, 14 Apr 2019 21:44:44 -0800 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Sun, 14 Apr 2019 22:44:42 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 15 Apr 2019 13:44:41 +0800 Received: from [172.21.77.33] (172.21.77.33) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 15 Apr 2019 13:44:41 +0800 Message-ID: <1555307081.12121.2.camel@mtkswgap22> Subject: Re: [PATCH v2] sched/clock: Prevent generic sched_clock wrap caused by tick_freeze() From: Chang-An Chen To: Frederic Weisbecker , Matthias Brugger , Ingo Molnar , Thomas Gleixner Date: Mon, 15 Apr 2019 13:44:41 +0800 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> X-Mailer: Evolution 3.2.3-0ubuntu6 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190414_224456_497691_7AD365A1 X-CRM114-Status: GOOD ( 20.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , Freddy Hsin =?UTF-8?Q?=28=E8=BE=9B=E6=81=92=E8=B1=90=29?= , Kees Cook , Kuohong Wang =?UTF-8?Q?=28=E7=8E=8B=E5=9C=8B=E9=B4=BB=29?= , "linux-kernel@vger.kernel.org" , "linux-mediatek@lists.infradead.org" , John Stultz , Stanley Chu =?UTF-8?Q?=28=E6=9C=B1=E5=8E=9F=E9=99=9E=29?= , "linux-arm-kernel@lists.infradead.org" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, This is just a gentle ping for this patch. On Fri, 2019-03-29 at 10:59 +0800, Chang-An Chen wrote: > tick_freeze() introduced by suspend-to-idle in commit 124cf9117c5f > ("PM / sleep: Make it possible to quiesce timers during suspend-to-idle") > will use timekeeping_suspend() instead of syscore_suspend() during > suspend-to-idle. It means that generic sched_clock will keep going because > sched_clock_suspend() and sched_clock_resume() are not taken during > suspend-to-idle. This will lead to generic sched_clock wrap. > > For example: > In my 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() is taken during > suspend-to-idle. It makes sched_clock wrap at kernel time 8796s. > > To fix this issue, we add sched_clock_suspend() and sched_clock_resume() in > tick_freeze() together with timekeeping_suspend() and timekeeping_resume() > to make sure generic sched_clock wrapping will not happen. > > Signed-off-by: Chang-An Chen > Fixes: 124cf9117c5f (PM / sleep: Make it possible to quiesce timers during suspend-to-idle) > --- > 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 094b82c..930113b 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 529143b..df40146 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 7a9b4eb..141ab3a 100644 > --- a/kernel/time/timekeeping.h > +++ b/kernel/time/timekeeping.h > @@ -14,6 +14,13 @@ extern ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, > 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); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel