From patchwork Wed Jul 25 02:49:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Cross X-Patchwork-Id: 1234151 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id DAB253FF1C for ; Wed, 25 Jul 2012 02:56:19 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Strfn-00026h-Ek; Wed, 25 Jul 2012 02:50:03 +0000 Received: from mail-vc0-f201.google.com ([209.85.220.201]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Strff-00026T-QP for linux-arm-kernel@lists.infradead.org; Wed, 25 Jul 2012 02:49:57 +0000 Received: by vcbfo13 with SMTP id fo13so30446vcb.0 for ; Tue, 24 Jul 2012 19:49:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=Ba/VuTwJPUYnOe5im93YQrJKa6ihCTNNhajcENbPZxk=; b=bPJW029K9h0I2p7vX6MHBGGQ7hpz4hdN+OoNTra6mMAU/yzhpLI79zD6ygQmw9nHo8 EVR8TtrCAWNRWHnPJiC27FEp128E86jbVxBNrUtwr94jrTIuC1A1iyGtDAIRCeCz/7u+ KwP6S2bvFZ4WkPYYE/vdWZZIb1Jm/+mitAyuIByxDp93e+2KZ3NjjNd1sdCRgCmiPH9g r6ZoiolPgQRsT8/drXYiJXSK1KQJdnIoBo/iSfPVMWMi3EgBY4rbkyJ9w9P+sxYrZ7qX qLm2AUOO9pRmJxTSM//MH7uMmOb6bttW2u22vrnxFg5UwHq0hTJgOig5CtOGmWbHYpio KYjw== Received: by 10.236.133.146 with SMTP id q18mr11978243yhi.12.1343184590409; Tue, 24 Jul 2012 19:49:50 -0700 (PDT) Received: by 10.236.133.146 with SMTP id q18mr11978226yhi.12.1343184590342; Tue, 24 Jul 2012 19:49:50 -0700 (PDT) Received: from wpzn3.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id i24si1768819anh.2.2012.07.24.19.49.50 (version=TLSv1/SSLv3 cipher=AES128-SHA); Tue, 24 Jul 2012 19:49:50 -0700 (PDT) Received: from walnut.mtv.corp.google.com (walnut.mtv.corp.google.com [172.18.104.116]) by wpzn3.hot.corp.google.com (Postfix) with ESMTP id 3C906100047; Tue, 24 Jul 2012 19:49:50 -0700 (PDT) Received: by walnut.mtv.corp.google.com (Postfix, from userid 99897) id DC28E257A40; Tue, 24 Jul 2012 19:49:49 -0700 (PDT) From: Colin Cross To: linux-arm-kernel@lists.infradead.org Subject: [RFC v2] ARM: sched_clock: update epoch_cyc on resume Date: Tue, 24 Jul 2012 19:49:44 -0700 Message-Id: <1343184588-20239-1-git-send-email-ccross@android.com> X-Mailer: git-send-email 1.7.7.3 X-Gm-Message-State: ALoCoQkm9mSLd8JevsG+UQf11iv1TtxwCYFug4iaVR0I9ZmJhyA6sjlzShedcCSpR/gZjjxHwEBI1+yScJ9io4p3ZXoFjD+wfK6PrZkZcRmltFiDFjM/SJyAXy3/SsXgMUq0kEME1ECtJ/eGcfM3BLy823Thw4pBbdL8ZwSsYLaGZYwjka5AyKm96DKFxaQJAJomWJIfX8EESfRApQWZQANA5yqN5ynL9A== X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.201 listed in list.dnswl.org] -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Russell King , Nicolas Pitre , Marc Zyngier , Linus Walleij , Barry Song <21cnbao@gmail.com>, linux-kernel@vger.kernel.org, Vaibhav Bedia , Colin Cross , Krzysztof Halasa X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Many clocks that are used to provide sched_clock will reset during suspend. If read_sched_clock returns 0 after suspend, sched_clock will appear to jump forward. This patch resets cd.epoch_cyc to the current value of read_sched_clock during resume, which causes sched_clock() just after suspend to return the same value as sched_clock() just before suspend. In addition, during the window where epoch_ns has been updated before suspend, but epoch_cyc has not been updated after suspend, it is unknown whether the clock has reset or not, and sched_clock() could return a bogus value. Add a suspended flag, and return the pre-suspend epoch_ns value during this period. The new behavior is triggered by calling setup_sched_clock_needs_suspend instead of setup_sched_clock. Signed-off-by: Colin Cross Reviewed-by: Linus Walleij --- arch/arm/include/asm/sched_clock.h | 2 ++ arch/arm/kernel/sched_clock.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/arch/arm/include/asm/sched_clock.h b/arch/arm/include/asm/sched_clock.h index e3f7572..05b8e82 100644 --- a/arch/arm/include/asm/sched_clock.h +++ b/arch/arm/include/asm/sched_clock.h @@ -10,5 +10,7 @@ extern void sched_clock_postinit(void); extern void setup_sched_clock(u32 (*read)(void), int bits, unsigned long rate); +extern void setup_sched_clock_needs_suspend(u32 (*read)(void), int bits, + unsigned long rate); #endif diff --git a/arch/arm/kernel/sched_clock.c b/arch/arm/kernel/sched_clock.c index 27d186a..f451539 100644 --- a/arch/arm/kernel/sched_clock.c +++ b/arch/arm/kernel/sched_clock.c @@ -21,6 +21,8 @@ struct clock_data { u32 epoch_cyc_copy; u32 mult; u32 shift; + bool suspended; + bool needs_suspend; }; static void sched_clock_poll(unsigned long wrap_ticks); @@ -49,6 +51,9 @@ static unsigned long long cyc_to_sched_clock(u32 cyc, u32 mask) u64 epoch_ns; u32 epoch_cyc; + if (cd.suspended) + return cd.epoch_ns; + /* * Load the epoch_cyc and epoch_ns atomically. We do this by * ensuring that we always write epoch_cyc, epoch_ns and @@ -98,6 +103,13 @@ static void sched_clock_poll(unsigned long wrap_ticks) update_sched_clock(); } +void __init setup_sched_clock_needs_suspend(u32 (*read)(void), int bits, + unsigned long rate) +{ + setup_sched_clock(read, bits, rate); + cd.needs_suspend = true; +} + void __init setup_sched_clock(u32 (*read)(void), int bits, unsigned long rate) { unsigned long r, w; @@ -169,11 +181,23 @@ void __init sched_clock_postinit(void) static int sched_clock_suspend(void) { sched_clock_poll(sched_clock_timer.data); + if (cd.needs_suspend) + cd.suspended = true; return 0; } +static void sched_clock_resume(void) +{ + if (cd.needs_suspend) { + cd.epoch_cyc = read_sched_clock(); + cd.epoch_cyc_copy = cd.epoch_cyc; + cd.suspended = false; + } +} + static struct syscore_ops sched_clock_ops = { .suspend = sched_clock_suspend, + .resume = sched_clock_resume, }; static int __init sched_clock_syscore_init(void)