From patchwork Fri Jul 27 23:38:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King - ARM Linux X-Patchwork-Id: 1250891 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 3B9DBE00A7 for ; Fri, 27 Jul 2012 23:48:35 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Suu7T-0003m8-CQ; Fri, 27 Jul 2012 23:38:55 +0000 Received: from caramon.arm.linux.org.uk ([78.32.30.218]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Suu7H-0003la-0G for linux-arm-kernel@lists.infradead.org; Fri, 27 Jul 2012 23:38:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=caramon; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=Qb5d9dQbwiFPNQ2O/MzmKf+al77o0G/hOFJ+RauRMZI=; b=gSXUNeU83a5xTHIRU2XkPe4OhHvevt6FXjxhNsHxfEcw4LOWE45FkorYwBvkkVKPPF8qEHiPdHdaIQfBV01RuqxFhGrfCCdjP/2mJzMvWPBmIUlmf+mdTHtx4eO/jGqdzysrixEyn+E/9HMXdy19v5z1jVBPNEnXz01iAe9Xd0s=; Received: from n2100.arm.linux.org.uk ([2002:4e20:1eda:1:214:fdff:fe10:4f86]:54485) by caramon.arm.linux.org.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1Suu74-0003QK-Ow; Sat, 28 Jul 2012 00:38:31 +0100 Received: from linux by n2100.arm.linux.org.uk with local (Exim 4.76) (envelope-from ) id 1Suu73-0005Dp-Mu; Sat, 28 Jul 2012 00:38:29 +0100 Date: Sat, 28 Jul 2012 00:38:29 +0100 From: Russell King - ARM Linux To: Linus Walleij Subject: Re: [RFC v2] ARM: sched_clock: update epoch_cyc on resume Message-ID: <20120727233829.GB14835@n2100.arm.linux.org.uk> References: <1343184588-20239-1-git-send-email-ccross@android.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-01-05) X-Spam-Note: CRM114 invocation failed X-Spam-Note: SpamAssassin invocation failed Cc: Nicolas Pitre , Marc Zyngier , Barry Song <21cnbao@gmail.com>, linux-kernel@vger.kernel.org, Vaibhav Bedia , Colin Cross , linux-arm-kernel@lists.infradead.org, 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: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org On Sat, Jul 28, 2012 at 01:32:50AM +0200, Linus Walleij wrote: > On Wed, Jul 25, 2012 at 4:49 AM, Colin Cross wrote: > > > 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 > > Sweet! > Reviewed-by: Linus Walleij Have any of you looked at the patch I originally posted for doing this? It needs updating but shows the overall principle - which is to ensure that the epoch is up to date before suspending. It doesn't deal with resume, because different timers behave differently, and there's no real way to deal with that properly. The important thing that this patch does is to ensure sched_clock() doesn't ever go backwards. arch/arm/kernel/sched_clock.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/arch/arm/kernel/sched_clock.c b/arch/arm/kernel/sched_clock.c index 9a46370..4be4019 100644 --- a/arch/arm/kernel/sched_clock.c +++ b/arch/arm/kernel/sched_clock.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -72,3 +73,20 @@ void __init sched_clock_postinit(void) { sched_clock_poll(sched_clock_timer.data); } + +static int sched_clock_suspend(void) +{ + sched_clock_poll(sched_clock_timer.data); + return 0; +} + +static struct syscore_ops sched_clock_ops = { + .suspend = sched_clock_suspend, +}; + +static int __init sched_clock_syscore_init(void) +{ + register_syscore_ops(&sched_clock_ops); + return 0; +} +device_initcall(sched_clock_syscore_init);