From patchwork Thu Sep 6 20:02:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 10591009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 260C85A4 for ; Thu, 6 Sep 2018 20:02:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 057DB2AD58 for ; Thu, 6 Sep 2018 20:02:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED31A2AD61; Thu, 6 Sep 2018 20:02:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E3ED12AD58 for ; Thu, 6 Sep 2018 20:02:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From :Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=iToR91aNX2h4I6Add4d5lA8qJmQy9IPc//9VRLFtXLQ=; b=NQV5dk0CN8n9P0 S1cP+DA/M6JTlVOXiJTT7Fu9ukd2NL7NPOtxQ0NIzprVawxuw/D4xBWPEFp/oDJGmuVjbn69wkm3h CwFSi8wzBDXxAqGQ0hehkS9XUm1enntd2ZLIb/5IElY0ZKf+AVLaDaYLtsd+UwtstihsOwf0CuOvu eo/AJ0zCw1q2CtANgEKvTdpKGVhFfD4nnagqtI6WrCv0rzk9ol8jXLjjjhiHT+cD0DM5djOTSOuBc EmgDWqYU8RSlyJvKzdUoGW/Wg2CdrIEePheKcmhOwe31xQDSszF1PZ3zqGxIiOytLYY2oCSbq+N2q VpyTURUjNHNNOyU3VE5g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fy0Tw-00009C-VN; Thu, 06 Sep 2018 20:02:24 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fy0Ts-00008S-W4 for linux-arm-kernel@lists.infradead.org; Thu, 06 Sep 2018 20:02:22 +0000 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fy0Tc-0004Dm-0E; Thu, 06 Sep 2018 22:02:04 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1fy0Ta-00084Y-AC; Thu, 06 Sep 2018 22:02:02 +0200 Date: Thu, 6 Sep 2018 22:02:02 +0200 From: Uwe =?iso-8859-1?q?Kleine-K=F6nig?= To: Fabio Estevam , Shawn Guo Subject: Timer on i.MX28 moving backwards Message-ID: <20180906200202.et4whmzq22n4uajt@pengutronix.de> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180906_130221_188061_4E678F26 X-CRM114-Status: GOOD ( 13.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Wahren , linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hello, on an i.MX28 based machine running Linux 4.9.y-rt I added the following patch: And with this I got the following trace: $ grep mxs_clocksource_mmio_readl_down trace ... -0 [000] d...1.. 1647.391949: mxs_clocksource_mmio_readl_down: time = 349cfe51 -0 [000] d...1.. 1647.397639: mxs_clocksource_mmio_readl_down: time = 349f1436 -0 [000] d..h2.. 1647.397672: mxs_clocksource_mmio_readl_down: time = 349f1731 -0 [000] dn.h1.. 1647.397705: mxs_clocksource_mmio_readl_down: time = 349f1a2b profinet-250 [000] ....... 1647.397821: mxs_clocksource_mmio_readl_down: time = 349f24e8 -0 [000] d...1.. 1647.398181: mxs_clocksource_mmio_readl_down: time = 349f466f -0 [000] d...1.. 1647.399452: mxs_clocksource_mmio_readl_down: time = 349fbe0e -0 [000] d..h2.. 1647.399488: mxs_clocksource_mmio_readl_down: time = 349fc16e -0 [000] dn.h1.. 1647.399524: mxs_clocksource_mmio_readl_down: time = 349fc4b8 mrp62439d-221 [000] ....... 1647.400062: mxs_clocksource_mmio_readl_down: time = 349ff658 mrp62439d-221 [000] ....... 1647.400858: mxs_clocksource_mmio_readl_down: time = 34a04125 mrp62439d-221 [000] d..h1.. 1647.401013: mxs_clocksource_mmio_readl_down: time = 34a04f0f mrp62439d-221 [000] d..h... 1647.401059: mxs_clocksource_mmio_readl_down: time = 34a05484 mrp62439d-221 [000] d..h3.. 1647.401263: mxs_clocksource_mmio_readl_down: time = 34a06981 mrp62439d-221 [000] d..h3.. 1647.401263: mxs_clocksource_mmio_readl_down: time = 34a06ac3 mrp62439d-221 [000] d..h3.. 1647.401263: mxs_clocksource_mmio_readl_down: time = 34a06c39 mrp62439d-221 [000] ....... 1647.401263: mxs_clocksource_mmio_readl_down: time = 34a064ca The interesting fact here is, that the values returned by mxs_clocksource_mmio_readl_down are not completely monotonic: The last value is smaller than the previous value. Given that the jump backwards is that small, I think we can rule out an overflow. (The input clk for the mx28 timer runs with 24 MHz, so one complete turnaround takes 0x100000000 / 24000000 Hz = 178.95697 s.) And this happens often: $ awk '/mxs_clocksource_mmio_readl_down/ { gsub(".*time = ", "0x"); time = strtonum($0); if (time - prev < 0) { printf "%x: %d\n", time, time - prev; } prev = time }' trace | wc -l 106 (There is one false positive where the counter overflows, the trace covers a time span of ~48 s. The 5 biggest backwards jumps are: -183784, -79486, -38294, -6552, -5471; minimum: -1332) Checking the Errata for i.MX28 there isn't anything documented affecting TIMROT. Reading the Reference Manual I didn't find anything that would explain a jump in the counter register. I didn't try yet to reproduce this on another machine or with a newer non-rt kernel, but I'd expect the same to happen there. Does this ring a bell for someone? Does someone see an explanation that doesn't include a hardware fault? Best regards Uwe diff --git a/drivers/clocksource/mmio.c b/drivers/clocksource/mmio.c index c4f7d7a9b689..557e555e95b7 100644 --- a/drivers/clocksource/mmio.c +++ b/drivers/clocksource/mmio.c @@ -25,6 +25,13 @@ cycle_t clocksource_mmio_readl_up(struct clocksource *c) return (cycle_t)readl_relaxed(to_mmio_clksrc(c)->reg); } +cycle_t mxs_clocksource_mmio_readl_down(struct clocksource *c) +{ + cycle_t ret = ~(cycle_t)readl_relaxed(to_mmio_clksrc(c)->reg) & c->mask; + trace_printk("time = %llx\n", ret); + return ret; +} + cycle_t clocksource_mmio_readl_down(struct clocksource *c) { return ~(cycle_t)readl_relaxed(to_mmio_clksrc(c)->reg) & c->mask; diff --git a/drivers/clocksource/mxs_timer.c b/drivers/clocksource/mxs_timer.c index 0ba0a913b41d..d78edf9345b2 100644 --- a/drivers/clocksource/mxs_timer.c +++ b/drivers/clocksource/mxs_timer.c @@ -217,7 +217,7 @@ static int __init mxs_clocksource_init(struct clk *timer_clk) clocksource_register_hz(&clocksource_mxs, c); else { clocksource_mmio_init(mxs_timrot_base + HW_TIMROT_RUNNING_COUNTn(1), - "mxs_timer", c, 200, 32, clocksource_mmio_readl_down); + "mxs_timer", c, 200, 32, mxs_clocksource_mmio_readl_down); sched_clock_register(mxs_read_sched_clock_v2, 32, c); } diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index 08398182f56e..dead82c9b19c 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h @@ -234,6 +234,7 @@ static inline void __clocksource_update_freq_khz(struct clocksource *cs, u32 khz extern int timekeeping_notify(struct clocksource *clock); extern cycle_t clocksource_mmio_readl_up(struct clocksource *); +extern cycle_t mxs_clocksource_mmio_readl_down(struct clocksource *); extern cycle_t clocksource_mmio_readl_down(struct clocksource *); extern cycle_t clocksource_mmio_readw_up(struct clocksource *); extern cycle_t clocksource_mmio_readw_down(struct clocksource *);