Received: by 10.223.185.116 with SMTP id b49csp2698813wrg; Mon, 12 Feb 2018 14:24:03 -0800 (PST) X-Google-Smtp-Source: AH8x224eTFd8ST+D9Pq4JUG1onKTAEO7EBJT4Fv3IH1F41KDW+A2MGQjkW9Rk5KE1S3hR7tPOaL3 X-Received: by 10.98.16.9 with SMTP id y9mr13130487pfi.189.1518474243436; Mon, 12 Feb 2018 14:24:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518474243; cv=none; d=google.com; s=arc-20160816; b=uBSgpyLNhQRduT8VyUILDwW1XfrW2lN2XZPt4O/VHUzRPR5RGXDXRpnHsf7ka+9mzf m4XyX7zKhjg/ZAM2jGsko9QpXWjQ1fHNpGVWBrEd0+0MxoBoQabPXFD0Irk+REg/1jMt H0vdfOJVhG9VMgrnjwSIRv57D/5a/H78Hx23uQLo58sd2ivsoQOZDOoPTAn/10J660sN H67kgqrMr3yZI6r0KcLdeWrtzN1lsM2FrZMDC9dhN6KT6EywhaTP3ZTAcautIv0JapWB OXb6Ad68lykrELZQEn/f0iJcosGpSExodSX1OU3KESGmf9Vt3CrSJqfh3dzB1zURsCLH OnIg== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=6/c8ufa/C/AgH/VeDbMteu9572ZA0M6c5ctI5u8d5Qg=; b=OW9vVWWTdcojoQX021SDwj0iLadphJQCQFruOCDoeJppgj3gfN58dTRhQq3HLtqACy myDLDwX1cLvJxGhak5ffGW6KocSDSrfCs2bMjjPbv4hE86ndx3wpY0WV9rhqStLlHI0Z mfjAyBHvpY8+XkUg+eM5jj1IzfNE34A8+Lgjh2nIxtGJgCIQKlzJx+eBLd7a6tA6nZP4 hkmWg2daPBYHJ3scez0Ta5+pWV6SKk5G3a3z71bE3eHNemx+xhYMreQYzFj6gqn2OMp+ uP8ToUfsPK4dCSvx4oepmDdf5z91sUEaAIw6atXN/5/4pijR6t4hWP+b7hxZfVepOrMT 2btg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=GLP2FXE5; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1si2375718pfp.91.2018.02.12.14.23.49; Mon, 12 Feb 2018 14:24:03 -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=@gmail.com header.s=20161025 header.b=GLP2FXE5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932955AbeBLWWt (ORCPT + 99 others); Mon, 12 Feb 2018 17:22:49 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:41021 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932628AbeBLWWo (ORCPT ); Mon, 12 Feb 2018 17:22:44 -0500 Received: by mail-pg0-f65.google.com with SMTP id t4so7395750pgp.8; Mon, 12 Feb 2018 14:22:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=6/c8ufa/C/AgH/VeDbMteu9572ZA0M6c5ctI5u8d5Qg=; b=GLP2FXE5DTEW94TmvydxZVVSn31lDdH8VMbOVOx6pB/tnvi+BJtO3U5i7hsySSrmXE YPvNhj705e9CvOoVj4F5SN51rkaDpEFWbf2tYaw0ji+nr6IMfozIIVJPQZVvxcV78ZkW Vmq0nH/GV2dxwfk53uQV9UIEsDomvHIA/ncsD8qR3gVODxAaNq6D7saQVzKkYKQJIpgZ 0L2PybLAv6K6WFHGlSa61UkeefKHSBAo+e78kCzes+ek1s7bOXfIMEgJRSi+7/MLij8i v2eOv7ROUzgDsaeKYXGf3w6nUH9lBlbjrNHGcJDZ+z/yG18p8EkgFEt9pmglsTKt93m9 DH/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=6/c8ufa/C/AgH/VeDbMteu9572ZA0M6c5ctI5u8d5Qg=; b=S8FOzyBXzn2eCYXY2V8uc8DqV7hFT6zZhass12GFPCBySuaI4mWlireUwRDH1R5m8F pDWybGUc1wjxKDXmFH7FDahdJI81HNiTq+PJwp5wAbPOX9r7LEyWetLcKAXjLQHbs4qc qTVGPgvF4Q9to/dvAuNBfC6tki/oN7EaENCENI+ntmtB0pSswwnhJeXLTf19AjYSp+pM ntfX+pq00o0/A+3bQoIqQCM1hIfytnUSrPNKZFjSseMsN2sHWw2n0uLNW0e35h6dXJ71 1kRo4ibuBgwlxyUFjRKKPA2Z9+PZblg5uwpA+ynoxuvGz+FYA1fW59dLHIEAHNIDd9rc QBTQ== X-Gm-Message-State: APf1xPCtdwqgsEoPABLWy5LoLF81SooT/UVHRK2ltholX3/do1VgAOX0 FNqXj4sU0k++bUB4j2qH60V/iA== X-Received: by 10.101.96.47 with SMTP id p15mr10194051pgu.390.1518474164121; Mon, 12 Feb 2018 14:22:44 -0800 (PST) Received: from localhost (108-223-40-66.lightspeed.sntcca.sbcglobal.net. [108.223.40.66]) by smtp.gmail.com with ESMTPSA id p85sm39556783pfd.8.2018.02.12.14.22.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Feb 2018 14:22:43 -0800 (PST) Date: Mon, 12 Feb 2018 14:22:41 -0800 From: Guenter Roeck To: Jean Delvare Cc: Wolfram Sang , =?iso-8859-1?B?Wm9sdOFuIEL2c3r2cm3pbnlp?= , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] i2c: piix4: Use usleep_range() Message-ID: <20180212222241.GA32060@roeck-us.net> References: <1514652658-6228-1-git-send-email-linux@roeck-us.net> <1514652658-6228-2-git-send-email-linux@roeck-us.net> <20180212115336.4b828ab8@endymion> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180212115336.4b828ab8@endymion> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jean, On Mon, Feb 12, 2018 at 11:53:36AM +0100, Jean Delvare wrote: > Hi Guenter, > > On Sat, 30 Dec 2017 08:50:58 -0800, Guenter Roeck wrote: > > The piix4 i2c driver is extremely slow. Replacing msleep() > > with usleep_range() increases its speed substantially. > > > > Signed-off-by: Guenter Roeck > > --- > > drivers/i2c/busses/i2c-piix4.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c > > index 78dd5951d6e7..52a8b1c5c110 100644 > > --- a/drivers/i2c/busses/i2c-piix4.c > > +++ b/drivers/i2c/busses/i2c-piix4.c > > @@ -467,13 +467,13 @@ static int piix4_transaction(struct i2c_adapter *piix4_adapter) > > > > /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */ > > if (srvrworks_csb5_delay) /* Extra delay for SERVERWORKS_CSB5 */ > > - msleep(2); > > + usleep_range(2000, 2000); > > Isn't this exactly the same? I'm fine using the same function for > consistency, just curious. > > > else > > - msleep(1); > > + usleep_range(500, 1000); > > Were you able to test this on older hardware? Unfortunately, the > specification errata of the original Intel PIIX4 is quite vague on the > amount of time you must wait before checking the Host Busy bit: > > "Note that there may be moderate latency before the transaction begins > and the Host Busy bit gets set." > > I guess we made it 1 ms at the time because it was the minimum we could > sleep anyway. > > One option if you really care about the performance of the i2c-piix4 > driver on recent hardware would be to lower the initial delay even more > for ATI and AMD chipsets. The errata was for Intel chipsets originally, > and while we know that at least some of the ServerWorks implementations > suffered from the same problem (worse actually) I don't think that > anybody ever bothered checking if it applied to more recent > implementations by other vendors. > > For reference, at 93.75 kHz (the default SMBus frequency or the SB800), > an SMBus Quick transaction would be completed in 117 us, so I guess an > initial delay of 150 or 200 us would be optimum. And an SMBus Read Byte > transaction completes in 416 ms. I think this is the most popular SMBus > transaction, so ensuring that it is as fast as possible would make > sense. > > And it might even work on older Intel chipsets, who knows. Plus I doubt > anyone is still using them anyway, so you have my approval to lower the > delays to whatever works for you. > > As a comparison point, in the i2c-i801 driver we use: > > usleep_range(250, 500); > > for both the initial sleep and the waiting loop. > A further test on Ryzen shows that bit 0 of SMBHSTSTS is set immediately, ie with outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); busy = inb_p(SMBHSTSTS) & 0x01; busy is always true. None of the datasheets I was able to find (sb700, sb800, bolton) suggests that an initial delay is needed. Another quick test with my Ryzen system, using usleep_range(100, 100), shows the result of quick commands in the third loop iteration (ie after 200 uS), and the result of a "read byte" operation in the 6th loop iteration (ie after 500 uS). This is measured without initial delay. Not sure what that means, if anything, for the driver. The biggest concern is the "moderate latency" required by the Intel chips. Otherwise we could just use the values from i2c-i801 for both initial and loop delay. Guenter