From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752603Ab2HCB2v (ORCPT ); Thu, 2 Aug 2012 21:28:51 -0400 Received: from mail-gg0-f174.google.com ([209.85.161.174]:34534 "EHLO mail-gg0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751312Ab2HCB2s (ORCPT ); Thu, 2 Aug 2012 21:28:48 -0400 MIME-Version: 1.0 In-Reply-To: References: <1343184588-20239-1-git-send-email-ccross@android.com> <20120727233829.GB14835@n2100.arm.linux.org.uk> Date: Thu, 2 Aug 2012 18:28:47 -0700 X-Google-Sender-Auth: BLzjf1cEVtuZ_qCNB5F0l7PC9aM Message-ID: Subject: Re: [RFC v2] ARM: sched_clock: update epoch_cyc on resume From: Colin Cross To: Russell King - ARM Linux Cc: Linus Walleij , linux-arm-kernel@lists.infradead.org, Barry Song <21cnbao@gmail.com>, Vaibhav Bedia , Krzysztof Halasa , Nicolas Pitre , Marc Zyngier , linux-kernel@vger.kernel.org Content-Type: text/plain; charset=ISO-8859-1 X-System-Of-Record: true Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 27, 2012 at 8:30 PM, Colin Cross wrote: > On Fri, Jul 27, 2012 at 6:15 PM, Colin Cross wrote: >> That patch was merged in 3.4, and my patch is on top of it. Your >> patch updates epoch_cyc and epoch_ns in suspend, but if the first call >> to cyc_to_sched_clock after resume gets cyc = 0, cyc - epoch_cyc can >> be negative, although it will be cast back to a large positive number. >> >> With my patch, epoch_cyc is updated in resume to whatever >> read_sched_clock() returns, and epoch_ns is still set to the suspend >> value, so it appears that sched_clock has not changed between >> sched_clock_suspend and sched_clock_resume. It will work with any >> timer behavior (reset to 0, reset to random value, or continuing >> counting). The old setup_sched_clock function maintains the old >> behavior to appease those who like their 32kHz sched clock to continue >> ticking in suspend, although I think it is more correct for all sched >> clocks to be faster than 32 kHz (when possible) and stop in suspend. > > I think the existing code can cause sched_clock to go backwards if the > register read by the read function resets to 0 in suspend: > > In sched_clock_suspend epoch_cyc is updated to 0x00002000. > > The first sched_clock call after resume gets cyc = 0, returning > epoch_ns + cyc_to_ns(0xffffe000) > > Later, sched_clock gets cyc = 0x5000, returning epoch_ns + > cyc_to_ns(0x3000), which will be much smaller than the previous > sched_clock value. Russell, any update on this? Should sched_clock.c handle read functions that go backwards in suspend, or should I modify the read function to track an offset in suspend and always return a monotonically increasing value across suspend?