Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4201994pxk; Tue, 29 Sep 2020 18:02:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn5Snwh5llXPHkXlPoBiMfutZfZts9SUMt8UpDHcj/SYWk2QPPSAe8VmXoY6WoWgMqCBTp X-Received: by 2002:aa7:d296:: with SMTP id w22mr136667edq.327.1601427759468; Tue, 29 Sep 2020 18:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601427759; cv=none; d=google.com; s=arc-20160816; b=GB85mDhfzxmAzOWfq3h2DfUvIxDmL4LaHllAAfOj4RZ0HnUBcZyMvKhMP9/dRPdkQP sujjgLIuKtzEYyMJH/9TllEY6rNe36Hjk6oCpowYiiD9x8+vARDlcECNcvzEa1sqJ0HK 8hqTZAF77DOEC4MtfvPcoeCmiI8uKp9tsJPzRV7mVvCFEn8LMH6FTmitBUaSzD+TZbWK smnEmdVXW6z3lA1Jr18CMGbehcQ5snDBtrMlJtm1/vV+Huu987EFDuGd1vz43hQzA1wI QrSAVO8VUJnU9iTzyeTz6yE6MataCYZKOUyjuBu8yBCDkUD3izFBMLCt3kfZGDqAmczb 0Kpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:dkim-signature; bh=uXZBl2SuPm2uEbCG/CnRR8c/y/1bFaqSLMqAnU5sW3o=; b=m+z+H1QrHU8jvSOinHZudNd5jts1aOxpzPBzSSP4eG54qnLhGw4dr8T2AmFi2rJ3f/ 62eM2PVl/AawD1AaUMlF9ernUT1ZmdBFMj1gjNyipn8zEXqbqXMQzZ2MxSZ/Y6giWJ7o NrRK0uuYMRcAtlNLTPi1kMb/QySdzbu7x6CdXlrhF6n83XddrZuv7Lz9woUvi0g2xMu3 Y/La+0b40C+IrOV8kG2AtchHsVD7fEmsoCZXSE1GpGARwNlzD+Zb1o96kEnBBD7h9Off 0sSXuWqmnLjnclNG0KvzhFk2ceL37fEYjBYDqZLN/jtW7rLnIl6fPppeNC6+lt4wg7af kL/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b=gnqmQET7; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=duoLuofu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f25si120606ejh.697.2020.09.29.18.02.17; Tue, 29 Sep 2020 18:02:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b=gnqmQET7; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=duoLuofu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729178AbgI3BA1 (ORCPT + 99 others); Tue, 29 Sep 2020 21:00:27 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:36543 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728943AbgI3BA1 (ORCPT ); Tue, 29 Sep 2020 21:00:27 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id C4E2C5C01B0; Tue, 29 Sep 2020 21:00:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Tue, 29 Sep 2020 21:00:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=u XZBl2SuPm2uEbCG/CnRR8c/y/1bFaqSLMqAnU5sW3o=; b=gnqmQET76LNyu8TCZ HhoTlpwM6XR7NcIAQ9nKxXhZV+keDQ+w9pIxDlfLiBoJy++86lITvmVWpYyds1RI O+71C2r7vK5uoSPzrsHuoVHR3G35VcoXoJE3vlC5DA9ZRQPQCrUWrKeH/mSctdeD muoxDbzz62sNk5Y6rlKCdt8irfKhnH9h34aRtTIFVdqtt9qhA8SlNhnSYn+jYSqm /VcOTuLItwQRCwpOmj2FxGGwAP0MY4tYiN0fBDlQY1FxzLgC4OTDZKX2gc03IJvg +rkPheJa7CYqBepY7vYpEVGUcwF9181hHcgWu8G21Xe8Mtx0hnMmtnt8rXeES9qn WWoIw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=uXZBl2SuPm2uEbCG/CnRR8c/y/1bFaqSLMqAnU5sW 3o=; b=duoLuofudl5wvpgnosV4kIxHtTIVN3HqeAHAWPIbF1Sv1ZXLdrT2a+KkI g0MAikaF7kkB9lH1fgLz7x5fhW4Y/8D8+vt/lJbRpS5wxnxKz2D11BZamKpfo5p2 tT4Yx3pPuwZMa3aBh3yRvj5F+dQDi2woDKob2VtdYKikGA/nD/xMb7d5p18CIXkN d+hKdafC/711m54Jj2+91l0qFvxk5PyYVM4rUAQLwpZ57Ir85oRcFgFs8BlUFhD8 vEaWiXjkpGi0hwHGw7NJpQwOa8jNeUDJ34TA2972WBYkN/iDdmexWWLkB05LjJVz 2aT9mcCucPyUF1AJiqmjp+3sNehmw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrfedtgdefkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtjeertddtfeejnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpefflefhtdeukedvffeigfeludeltdfhjeehkeekhfeuvdehfeehheeh keehhfdtvdenucffohhmrghinhepghhithhhuhgsrdgtohhmpdhinhhfrhgruggvrggurd horhhgnecukfhppeejtddrudefhedrudegkedrudehudenucevlhhushhtvghrufhiiigv pedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehsrghmuhgvlhesshhhohhllhgrnhgurd horhhg X-ME-Proxy: Received: from [192.168.50.169] (70-135-148-151.lightspeed.stlsmo.sbcglobal.net [70.135.148.151]) by mail.messagingengine.com (Postfix) with ESMTPA id 102F7328005D; Tue, 29 Sep 2020 21:00:24 -0400 (EDT) Subject: Re: [PATCH] RFC: arm64: arch_timer: Fix timer inconsistency test for A64 To: Mark Rutland , Roman Stratiienko Cc: linux-sunxi@googlegroups.com, megous@megous.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, maz@kernel.org References: <20200929111347.1967438-1-r.stratiienko@gmail.com> <20200929154012.GF53442@C02TD0UTHF1T.local> From: Samuel Holland Message-ID: <90f2e396-b679-fa25-c227-37489bc167e6@sholland.org> Date: Tue, 29 Sep 2020 20:00:21 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200929154012.GF53442@C02TD0UTHF1T.local> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/29/20 10:40 AM, Mark Rutland wrote: > Hi, > > Please Cc maintainers for drivers -- Marc and I maintain the arch timer > driver. > > On Tue, Sep 29, 2020 at 02:13:47PM +0300, Roman Stratiienko wrote: >> Fixes linux_kselftest:timers_inconsistency-check_arm_64 >> >> Test logs without the fix: >> ''' >> binary returned non-zero. Exit code: 1, stderr: , stdout: >> Consistent CLOCK_REALTIME >> 1601335525:467086804 >> 1601335525:467087554 >> 1601335525:467088345 >> 1601335525:467089095 >> 1601335525:467089887 >> 1601335525:467090637 >> 1601335525:467091429 >> 1601335525:467092179 >> 1601335525:467092929 >> 1601335525:467093720 >> 1601335525:467094470 >> 1601335525:467095262 >> 1601335525:467096012 >> 1601335525:467096804 >> -------------------- >> 1601335525:467097554 >> 1601335525:467077012 > > That's 0x1BD757D2 followed by 0x1BD70794. The rollback is somewhere in > bits 15:12 to go from 0x1BD75xxx to 0x1BD70xxx, which suggests the > analysis in the existing comment is incomplete. My analysis only looked at consecutive timer reads on a single core. Apparently, from the vendor comment that they needed CLOCKSOURCE_VALIDATE_LAST_CYCLE (linked below), there is another inconsistency with reads across cores. >> -------------------- >> 1601335525:467099095 >> 1601335525:467099845 >> 1601335525:467100637 >> 1601335525:467101387 >> 1601335525:467102179 >> 1601335525:467102929 >> ''' > > It would be very helpful if the commit message could explain the rough > idea behind the change, because the rationale is not clear to me. > >> Signed-off-by: Roman Stratiienko >> CC: linux-arm-kernel@lists.infradead.org >> CC: linux-kernel@vger.kernel.org >> CC: linux-sunxi@googlegroups.com >> CC: megous@megous.com >> --- >> drivers/clocksource/arm_arch_timer.c | 9 +++++---- >> 1 file changed, 5 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c >> index 6c3e841801461..d50aa43cb654b 100644 >> --- a/drivers/clocksource/arm_arch_timer.c >> +++ b/drivers/clocksource/arm_arch_timer.c >> @@ -346,16 +346,17 @@ static u64 notrace arm64_858921_read_cntvct_el0(void) >> * number of CPU cycles in 3 consecutive 24 MHz counter periods. >> */ >> #define __sun50i_a64_read_reg(reg) ({ \ >> - u64 _val; \ >> + u64 _val1, _val2; \ >> int _retries = 150; \ >> \ >> do { \ >> - _val = read_sysreg(reg); \ >> + _val1 = read_sysreg(reg); \ >> + _val2 = read_sysreg(reg); \ >> _retries--; \ >> - } while (((_val + 1) & GENMASK(9, 0)) <= 1 && _retries); \ >> + } while (((_val2 - _val1) > 0x10) && _retries); \ > > This is going to fail quite often at low CPU frequencies, and it's not > clear to me that this solves the problem any more generally. DO we know > what the underlying erratum is here? This is what we have from the vendor: https://github.com/Allwinner-Homlet/H6-BSP4.9-linux/blob/master/arch/arm64/include/asm/arch_timer.h#L155 https://github.com/Allwinner-Homlet/H6-BSP4.9-linux/blob/master/drivers/clocksource/arm_arch_timer.c#L272 and they select CLOCKSOURCE_VALIDATE_LAST_CYCLE. Everything else we know (e.g. the tables and explanation in my original commit log) is from testing by users. I had not seen the vendor changes to arch_timer.h when I wrote the existing workaround. Their retry loop is similar to this patch, but as you mention, it won't work if the CPU frequency is too low. That may not be a problem for the vendor kernel, but it breaks badly on mainline. As Ondrej referenced, the mainline DVFS implementation bypasses the PLL during frequency changes. At that point, both the CPU and the timer are running at 24 MHz, so the chance of hitting the retry limit is high... and there's a udelay() call in the PLL bypass code (ccu_mux_notifier_cb()) that will need to read the timer. > Thanks, > Mark. Cheers, Samuel >> \ >> WARN_ON_ONCE(!_retries); \ >> - _val; \ >> + _val2; \ >> }) >> >> static u64 notrace sun50i_a64_read_cntpct_el0(void) >> -- >> 2.25.1 >> >> >> _______________________________________________ >> linux-arm-kernel mailing list >> linux-arm-kernel@lists.infradead.org >> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel