From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760000AbdKPQIV (ORCPT ); Thu, 16 Nov 2017 11:08:21 -0500 Received: from mail-qt0-f194.google.com ([209.85.216.194]:46724 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754765AbdKPQIO (ORCPT ); Thu, 16 Nov 2017 11:08:14 -0500 X-Google-Smtp-Source: AGs4zMYDr1RZ8ByxCFK0tcHjmezrOgGoMCRKFIXRBn7J+KN4ZXNkyHxtDO/VrOxdUtcSL4dPrla4+Q== Date: Thu, 16 Nov 2017 11:08:11 -0500 (EST) From: Nicolas Pitre To: Marc Gonzalez cc: Russell King - ARM Linux , Linus Torvalds , Alan Cox , LKML , Linux ARM , Steven Rostedt , Ingo Molnar , Thomas Gleixner , Peter Zijlstra , John Stultz , Douglas Anderson , Mark Rutland , Will Deacon , Jonathan Austin , Arnd Bergmann , Kevin Hilman , Michael Turquette , Stephen Boyd , Boris Brezillon , Thibaud Cornic , Mason Subject: Re: [RFC] Improving udelay/ndelay on platforms where that is possible In-Reply-To: <9a4cfa9d-3940-b7f2-5a4d-59e89af85bb7@sigmadesigns.com> Message-ID: References: <20171101175325.2557ce85@alans-desktop> <4b707ce0-6067-ab36-e167-1acf348d26bf@free.fr> <11393e07-b042-180c-3bcd-484bf51eada6@sigmadesigns.com> <20171115131351.GE31757@n2100.armlinux.org.uk> <1fa81694-7bd2-564b-e5b9-ae53b9ea6620@sigmadesigns.com> <20171116153625.GJ31757@n2100.armlinux.org.uk> <9a4cfa9d-3940-b7f2-5a4d-59e89af85bb7@sigmadesigns.com> User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 16 Nov 2017, Marc Gonzalez wrote: > On 16/11/2017 16:36, Russell King - ARM Linux wrote: > > On Thu, Nov 16, 2017 at 04:26:51PM +0100, Marc Gonzalez wrote: > >> On 15/11/2017 14:13, Russell King - ARM Linux wrote: > >> > >>> udelay() needs to offer a consistent interface so that drivers know > >>> what to expect no matter what the implementation is. Making one > >>> implementation conform to your ideas while leaving the other > >>> implementations with other expectations is a recipe for bugs. > >>> > >>> If you really want to do this, fix the loops_per_jiffy implementation > >>> as well so that the consistency is maintained. > >> > >> Hello Russell, > >> > >> It seems to me that, when using DFS, there's a serious issue with loop-based > >> delays. (IIRC, it was you who pointed this out a few years ago.) > >> > >> If I'm reading arch/arm/kernel/smp.c correctly, loops_per_jiffy is scaled > >> when the frequency changes. > >> > >> But arch/arm/lib/delay-loop.S starts by loading the current value of > >> loops_per_jiffy, computes the number of times to loop, and then loops. > >> If the frequency increases when the core is in __loop_delay, the > >> delay will be much shorter than requested. > >> > >> Is this a correct assessment of the situation? > > > > Absolutely correct, and it's something that people are aware of, and > > have already catered for while writing their drivers. > > In their cpufreq driver? > In "real" device drivers that happen to use delays? > > On my system, the CPU frequency may ramp up from 120 MHz to 1.2 GHz. > If the frequency increases at the beginning of __loop_delay, udelay(100) > would spin only 10 microseconds. This is likely to cause issues in > any driver using udelay. > > How does one cater for that? You make sure your delays are based on a stable hardware timer. Most platforms nowdays should have a suitable timer source. Nicolas