Received: by 10.223.164.202 with SMTP id h10csp2125765wrb; Thu, 16 Nov 2017 09:45:25 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ20sK3ohbf1I8AXI05sJPGjNcyKG7WSGVAK49L9hH5RO+UFsmPsdci+ET2xVtqB9Zwkj+7 X-Received: by 10.84.232.8 with SMTP id h8mr2430343plk.274.1510854325273; Thu, 16 Nov 2017 09:45:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510854325; cv=none; d=google.com; s=arc-20160816; b=LwfvL+KOvBxwssikPMl0raD7OwyUpzyUFKkzCviWWGTrqzLnqFcQKL0ch5qs72I05n pNFc9+ENVoCe5mXk3ACGFhhVas3mWATbHe2YatrpZFzN39NPdEBbYbFLjbbIlMcsX76J x5RclhkRYIzIb/9dV194bbTfdJADHaIBjlrCa5nZ7iLXwIQFhusC+sA0NMq1lQ+/w9Cx TxdPHlIv75O7mLM43Q9CxoyhMc1daVwdoss9Q2c9+2tECwG79TSY44iSPeMdDxn9WgG2 t61rsx1T0BiXF2Rio2r0QOSLupoX4yllUr9iCxcXJMEoOqCzsvJOmad5/k/hKbL74m5I DqDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=tvC3HZeHe2QzZaoQ884Chi9SM5s4shTGkLSKaiXjFd8=; b=mRB7JnBP7tv4SIDCzqbW9XoaVBId8lxTDaTuH8sH+irlVTb+zAq0iqcZdNuzKi8evl aZZqlW9w0sxul2cE4bOWQfEDXJJj9QAT97I/yHo8Mad5f4Ln3fAeGT0P/AbF9abb4e1I j8LfFlaVLE1/Dqpt34bJameBNSFNXO/D2b9EhItVpeAxkz1FqvlgphL8/U/cYnvdKpvE 3QnDU/SQ+PArdjNMhYgBxPmAWYez8QkKr6O0EnKC1Con9t2pCxe1IyN3A7FyIE94kgVn +T2smJhNGLDj3jzKurt/kRDZ3LfGtJLB6J4EkBtcpc4De/0HoqsBWgXP13viSFQy1hlf qk9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=pOWPAW74; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t77si1358277pfa.185.2017.11.16.09.45.12; Thu, 16 Nov 2017 09:45:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=pOWPAW74; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936231AbdKPRFs (ORCPT + 92 others); Thu, 16 Nov 2017 12:05:48 -0500 Received: from pandora.armlinux.org.uk ([78.32.30.218]:48704 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936193AbdKPRFj (ORCPT ); Thu, 16 Nov 2017 12:05:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=tvC3HZeHe2QzZaoQ884Chi9SM5s4shTGkLSKaiXjFd8=; b=pOWPAW74dI9Gb2NaRo8eUS/pErTsNXnduyU3KUT2hKxk4d928/PHtljeUoK4a3qV2ZKk9aMNSX1bEeopCzUaoNYdTF9OGdA1ynafPfOzvjQQ5gw+Bv/jLZkzStDV0q+fCpk/tAeonA1WBamJvIBHL0zm5r5VS/wjruRT5nFBztY=; Received: from n2100.armlinux.org.uk ([2002:4e20:1eda:1:214:fdff:fe10:4f86]:37833) by pandora.armlinux.org.uk with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1eFNbY-0007n6-4n; Thu, 16 Nov 2017 17:05:32 +0000 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.76) (envelope-from ) id 1eFNbU-00034V-NP; Thu, 16 Nov 2017 17:05:28 +0000 Date: Thu, 16 Nov 2017 17:05:28 +0000 From: Russell King - ARM Linux To: Marc Gonzalez Cc: Nicolas Pitre , 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 Message-ID: <20171116170527.GL31757@n2100.armlinux.org.uk> References: <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> <48c38055-20f7-e565-aa56-74f360e6e3d9@sigmadesigns.com> <20171116163254.GK31757@n2100.armlinux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 16, 2017 at 05:42:36PM +0100, Marc Gonzalez wrote: > On 16/11/2017 17:32, Russell King - ARM Linux wrote: > > On Thu, Nov 16, 2017 at 05:26:32PM +0100, Marc Gonzalez wrote: > >> On 16/11/2017 17:08, Nicolas Pitre wrote: > >> > >>> 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 nowadays should have a suitable timer source. > >> > >> So you propose fixing loop-based delays by using clock-based delays, > >> is that correct? (That is indeed what I did on my platform.) > >> > >> Russell stated that there are platforms using loop-based delays with > >> cpufreq enabled. I'm asking how they manage the brokenness. > > > > Quite simply, they don't have such a wide range of frequencies that can > > be selected. They're on the order of 4x. For example, the original > > platform that cpufreq was developed on, a StrongARM-1110 board, can > > practically range from 221MHz down to 59MHz. > > Requesting 100 �s and spinning only 25 �s is still a problem, > don't you agree? Which is why, as I've said *many* times already, that drivers are written with leaway on the delays. I get the impression that we're just going around in circles, and what you're trying to do is to get me to agree with your point of view. That's not going to happen, because I know the history over about the last /24/ years of kernel development (which is how long I've been involved with the kernel.) That's almost a quarter of a century! I know how things were done years ago (which is relevant because we still have support in the kernel for these systems), and I also know the history of facilities like cpufreq - I was the one who took the work that Erik Mouw and others involved with the LART project, and turned it into something a little more generic. The idea of dynamically scaling the CPU frequency on ARM SoCs was something that the SoC manufacturer had not even considered - it was innovative. I know that udelay() can return short delays when used in a kernel with cpufreq enabled, and I also know that's almost an impossible problem to solve without going to a timer-based delay. So, when you think that sending an email about a udelay() that can be 10x shorter might be somehow new information, and might convince people that there's a problem, I'm afraid that it isn't really new information. The SA1110 cpufreq driver is dated 2001, and carries my copyright, and has the ability to make udelay()s 4x shorter or 4x longer depending on the direction of change. We've discussed solutions in the past (probably 10 years ago) about this, and what can be done, and the conclusion to that was, as Nicolas has said, to switch to using a timer-based delay mechanism where possible. Where this is not possible, the platform is stuck with the loops based delays, and their inherent variability and inaccuracy. These platforms have been tested with such a setup over many years. They work even with udelay() having this behaviour, because it's a known issue and drivers cater for it in ways that I've already covered in my many previous emails to you. These issues are known. They've been known for the last 15 odd years. > > BTW, your example above is incorrect. > > A 10x increase in frequency causes a request of 100 �s to spin > only 10 �s, as written above. Right, sorry, misread. -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up From 1584244951332474282@xxx Thu Nov 16 17:35:20 +0000 2017 X-GM-THRID: 1582790467810046578 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread