From patchwork Thu Apr 18 19:30:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 2462251 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork2.kernel.org (Postfix) with ESMTP id 23A31DF2E5 for ; Thu, 18 Apr 2013 19:30:43 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1USuXN-0001pl-6Q; Thu, 18 Apr 2013 19:30:29 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1USuXK-0006iT-JE; Thu, 18 Apr 2013 19:30:26 +0000 Received: from mail-vc0-f172.google.com ([209.85.220.172]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1USuXH-0006hr-Q6 for linux-arm-kernel@lists.infradead.org; Thu, 18 Apr 2013 19:30:24 +0000 Received: by mail-vc0-f172.google.com with SMTP id gd11so3051713vcb.3 for ; Thu, 18 Apr 2013 12:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=M3rEzVLo23XJJ9fdiQuwIrx3OnLsvxBOuSrbhBhnteo=; b=fIPQw/M44TQrG+B9Ho4lfhdSRcZRoYygD2Wv7b2Kxd3nukvpISLx7t6u9YESlxUkIy 7mlyPj+sK6wWJPZyTCM7idxUdSsmnoIFBDkVOrBuzqIWwXO9FwGOLfKdydtr170QX+xv 2lC/FNk87a5bVpXLcvlw8AluecBernKvmZ1IBOO3xQcT12gMJrFE6AvcK1F5h80/RJuq SKTez5h+dp0tSIRmeYTaPRZlq5RMCYq3iZreg45b7KHowlH/2Ey6bXIO+mXVtVvaS6Mn 9PGoNjIE2UTOlchBKsUAEJ0V+9ngD4XWuJsC9tmdoSuKHWzdpU64nLpFPTRY400zWAvv S1Ig== X-Received: by 10.52.155.210 with SMTP id vy18mr7901214vdb.121.1366313420307; Thu, 18 Apr 2013 12:30:20 -0700 (PDT) Received: from rob-laptop.calxeda.com ([173.226.190.126]) by mx.google.com with ESMTPS id u20sm10937613vdt.10.2013.04.18.12.30.18 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 18 Apr 2013 12:30:19 -0700 (PDT) From: Rob Herring To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] clocksource: arm_arch_timer: add boot and suspend sched_clock offset Date: Thu, 18 Apr 2013 14:30:10 -0500 Message-Id: <1366313410-16692-2-git-send-email-robherring2@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1366313410-16692-1-git-send-email-robherring2@gmail.com> References: <1366313410-16692-1-git-send-email-robherring2@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130418_153023_991442_A3A42D04 X-CRM114-Status: GOOD ( 16.27 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.172 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (robherring2[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (robherring2[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Russell King , Catalin Marinas , Will Deacon , Rob Herring , arm@kernel.org, John Stultz , Thomas Gleixner X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Rob Herring Commit 023796b (ARM: arch_timer: use full 64-bit counter for sched_clock) fails to ensure sched_clock always starts at time 0 and counting is suspended during suspend. arm64 sched_clock support also has the same issues. This fixes all architected timer users by maintaining an initial offset which is updated on resume. Signed-off-by: Rob Herring Cc: Russell King Cc: John Stultz Cc: Thomas Gleixner Cc: Catalin Marinas Cc: Will Deacon Cc: Stephen Boyd Acked-by: Catalin Marinas --- arch/arm/kernel/arch_timer.c | 1 + drivers/clocksource/arm_arch_timer.c | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/arm/kernel/arch_timer.c b/arch/arm/kernel/arch_timer.c index df6825e..9a517fe 100644 --- a/arch/arm/kernel/arch_timer.c +++ b/arch/arm/kernel/arch_timer.c @@ -42,5 +42,6 @@ int __init arch_timer_arch_init(void) arch_timer_delay_timer_register(); sched_clock_func = arch_timer_sched_clock; + return 0; } diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index 17ed8e4..cc0bd67 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -267,14 +268,34 @@ static struct notifier_block arch_timer_cpu_nb __cpuinitdata = { }; static u64 sched_clock_mult __read_mostly; +static u64 arch_timer_suspend_cyc; +static u64 arch_timer_sched_clock_offset; unsigned long long notrace arch_timer_sched_clock(void) { - return arch_timer_read_counter() * sched_clock_mult; + u64 cyc = arch_timer_read_counter() - arch_timer_sched_clock_offset; + return cyc * sched_clock_mult; } unsigned long long sched_clock(void) \ __attribute__((weak, alias("arch_timer_sched_clock"))); +static int arch_timer_suspend(void) +{ + arch_timer_suspend_cyc = arch_timer_read_counter(); + return 0; +} + +static void arch_timer_resume(void) +{ + arch_timer_sched_clock_offset += + arch_timer_read_counter() - arch_timer_suspend_cyc; +} + +static struct syscore_ops arch_timer_ops = { + .suspend = arch_timer_suspend, + .resume = arch_timer_resume, +}; + static int __init arch_timer_register(void) { int err; @@ -332,6 +353,9 @@ static int __init arch_timer_register(void) pr_info("sched_clock: ARM arch timer >56 bits at %ukHz, resolution %lluns\n", arch_timer_rate / 1000, sched_clock_mult); + arch_timer_sched_clock_offset = arch_timer_read_counter(); + register_syscore_ops(&arch_timer_ops); + return 0; out_free_irq: