From patchwork Fri Jul 13 03:16:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: katsuki.uwatoko@toshiba.co.jp X-Patchwork-Id: 1193631 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 6659FDF24C for ; Fri, 13 Jul 2012 03:22:13 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SpWNV-0006gj-PS; Fri, 13 Jul 2012 03:17:13 +0000 Received: from imx12.toshiba.co.jp ([61.202.160.132]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SpWN1-0006gV-AO for linux-arm-kernel@lists.infradead.org; Fri, 13 Jul 2012 03:16:46 +0000 Received: from arc11.toshiba.co.jp ([133.199.90.127]) by imx12.toshiba.co.jp with ESMTP id q6D3G9u7022352; Fri, 13 Jul 2012 12:16:09 +0900 (JST) Received: (from root@localhost) by arc11.toshiba.co.jp id q6D3G9J1003455; Fri, 13 Jul 2012 12:16:09 +0900 (JST) Received: from ovp11.toshiba.co.jp [133.199.90.148] by arc11.toshiba.co.jp with ESMTP id NAA03454; Fri, 13 Jul 2012 12:16:09 +0900 Received: from mx.toshiba.co.jp (localhost [127.0.0.1]) by ovp11.toshiba.co.jp with ESMTP id q6D3G86Z003119; Fri, 13 Jul 2012 12:16:08 +0900 (JST) Received: from tgxml308.toshiba.local by toshiba.co.jp id q6D3G72F007646; Fri, 13 Jul 2012 12:16:08 +0900 (JST) Received: from TGXML316.toshiba.local ([169.254.4.106]) by tgxml308.toshiba.local ([133.199.66.203]) with mapi id 14.01.0339.002; Fri, 13 Jul 2012 12:16:07 +0900 From: To: Subject: [PATCH] ARM: sched_clock: fix the timing of reading current clock cycles in cyc_to_sched_clock. Thread-Topic: [PATCH] ARM: sched_clock: fix the timing of reading current clock cycles in cyc_to_sched_clock. Thread-Index: AQHNYKXX1v+PtYiC/ECLOxgyGm6ECg== Date: Fri, 13 Jul 2012 03:16:06 +0000 Message-ID: Accept-Language: ja-JP, en-US Content-Language: en-US x-originating-ip: [133.114.87.187] msscp.transfermailtomossagent: 103 Content-ID: <31B8C4DAA147EE4393DFCD85688A4AEB@toshiba.local> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -6.9 (------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-6.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [61.202.160.132 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -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] 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines Cc: linux@arm.linux.org.uk 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 The current clock cycle (cyc) must be read after epoc_cyc and epoch_ns are fixed. The calculation result gets invalid when epoch_cyc is updated after cyc is determined, because the result of (cyc - epoch_cyc) is unsigned int. Signed-off-by: UWATOKO Katsuki --- arch/arm/kernel/sched_clock.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/kernel/sched_clock.c b/arch/arm/kernel/sched_clock.c index 27d186a..ab08671 100644 --- a/arch/arm/kernel/sched_clock.c +++ b/arch/arm/kernel/sched_clock.c @@ -44,7 +44,7 @@ static inline u64 cyc_to_ns(u64 cyc, u32 mult, u32 shift) return (cyc * mult) >> shift; } -static unsigned long long cyc_to_sched_clock(u32 cyc, u32 mask) +static unsigned long long cyc_to_sched_clock(u32 (*read)(void), u32 mask) { u64 epoch_ns; u32 epoch_cyc; @@ -63,7 +63,8 @@ static unsigned long long cyc_to_sched_clock(u32 cyc, u32 mask) smp_rmb(); } while (epoch_cyc != cd.epoch_cyc_copy); - return epoch_ns + cyc_to_ns((cyc - epoch_cyc) & mask, cd.mult, cd.shift); + return epoch_ns + cyc_to_ns((read() - epoch_cyc) & mask, cd.mult, + cd.shift); } /* @@ -150,8 +151,7 @@ void __init setup_sched_clock(u32 (*read)(void), int bits, unsigned long rate) unsigned long long notrace sched_clock(void) { - u32 cyc = read_sched_clock(); - return cyc_to_sched_clock(cyc, sched_clock_mask); + return cyc_to_sched_clock(read_sched_clock, sched_clock_mask); } void __init sched_clock_postinit(void)