From patchwork Tue Jul 17 23:27:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Cross X-Patchwork-Id: 1207561 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 DB9F53FD9C for ; Tue, 17 Jul 2012 23:31:57 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SrHBc-0004ML-5H; Tue, 17 Jul 2012 23:28:12 +0000 Received: from mail-vb0-f73.google.com ([209.85.212.73]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SrHBV-0004M7-H2 for linux-arm-kernel@lists.infradead.org; Tue, 17 Jul 2012 23:28:06 +0000 Received: by vbkv13 with SMTP id v13so104329vbk.0 for ; Tue, 17 Jul 2012 16:28:02 -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=u6fS8Me+rhVbfjSCLWn9XpJdA1kQo8qRXTDWxkElLLM=; b=Ia5OuUi/lT++bkULgtiMRwh9pLcpTe+CvaAanKDprzS1pF5K41zP5+/ekv5/b+JmJx 4kk98LEE++xLefVWmDD71nb570M0WVxRGDJpsOgk6VZoTqXve0IP2sTzo2htKLwQ/OzI jgwTlCD5kCxyutEEDv7WPwL79/6QgMvZwvwC50bxXaOYwk9LsWjzOrSBeZibX+QfAFmh 2A/4e2xbatobLB4nHsXNHA9s7dl+zD0idT6d+GOD2tbVeySG0f91xchinwpNkT/LIB5K wCSmsh9PqoSD+k0c/z8yVAFlNIJrMz/sOSdZ4YEghJPa6kVcIXGKrqX94kRRVCLMaL9f zIVA== Received: by 10.236.181.34 with SMTP id k22mr280173yhm.46.1342567682322; Tue, 17 Jul 2012 16:28:02 -0700 (PDT) Received: by 10.236.181.34 with SMTP id k22mr280155yhm.46.1342567682244; Tue, 17 Jul 2012 16:28:02 -0700 (PDT) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id f27si2099111anj.1.2012.07.17.16.28.02 (version=TLSv1/SSLv3 cipher=AES128-SHA); Tue, 17 Jul 2012 16:28:02 -0700 (PDT) Received: from walnut.mtv.corp.google.com (walnut.mtv.corp.google.com [172.18.104.116]) by wpzn4.hot.corp.google.com (Postfix) with ESMTP id 25F541E006A; Tue, 17 Jul 2012 16:28:02 -0700 (PDT) Received: by walnut.mtv.corp.google.com (Postfix, from userid 99897) id BA40F257A28; Tue, 17 Jul 2012 16:28:01 -0700 (PDT) From: Colin Cross To: linux-arm-kernel@lists.infradead.org Subject: [RFC] ARM: sched_clock: update epoch_cyc on resume Date: Tue, 17 Jul 2012 16:27:51 -0700 Message-Id: <1342567672-29071-1-git-send-email-ccross@android.com> X-Mailer: git-send-email 1.7.7.3 X-Gm-Message-State: ALoCoQnDvSUkG/Iyq5b6G/OqHLbKw0xszW8dGhhFHc11jMxP5M0NfUmoWGJBeuCLLyhC1SpwdGmAepMPMYvGq7yVIh3DcarPj2KZS6Q/YTUjfTAHB6hLnjsmIj1TbK9ijMXQUiNaKbul7aW5PIfqqWYXcUKyqJC/BqjKgCdknygHR5tm/u5DN5Y/frf3O5dj/YRhbMEysMpq4H3UmUeHlwlSho+TsaUzkg== 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.212.73 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 , linux-kernel@vger.kernel.org, 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. This will have a side effect of causing SoCs that have clocks that continue to count in suspend to appear to stop counting, reporting the same sched_clock() value before and after suspend. Signed-off-by: Colin Cross Acked-by: Barry Song <21cnbao@gmail.com> --- arch/arm/kernel/sched_clock.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/arch/arm/kernel/sched_clock.c b/arch/arm/kernel/sched_clock.c index 27d186a..46c7d32 100644 --- a/arch/arm/kernel/sched_clock.c +++ b/arch/arm/kernel/sched_clock.c @@ -21,6 +21,7 @@ struct clock_data { u32 epoch_cyc_copy; u32 mult; u32 shift; + bool suspended; }; static void sched_clock_poll(unsigned long wrap_ticks); @@ -49,6 +50,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 @@ -169,11 +173,20 @@ void __init sched_clock_postinit(void) static int sched_clock_suspend(void) { sched_clock_poll(sched_clock_timer.data); + cd.suspended = true; return 0; } +static void sched_clock_resume(void) +{ + 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)