Received: by 10.223.185.116 with SMTP id b49csp768819wrg; Wed, 14 Feb 2018 06:45:47 -0800 (PST) X-Google-Smtp-Source: AH8x227LIq0ssZE7KA0RTk9eDzX7msRbF/mTgE9ulA9fC5iHu7zDFUgzT6mhDiBzC6sPJNlQSXb1 X-Received: by 10.98.129.5 with SMTP id t5mr5006818pfd.6.1518619547221; Wed, 14 Feb 2018 06:45:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518619547; cv=none; d=google.com; s=arc-20160816; b=KrleE6Vqsxb241kLrol4ONFb9DXpDBz3Ig1xVMMKrnEPcw8VHmHpK9umedJH+PnkQb 2m+aMl4nTelVrzwkpBF6fH2Bd8FCD6F3NkDYz46CrRcZb2UTzXfmkCqX7D07bwABzUs5 jsWHKIBlr46gO1cdTtJ8ksyaiHsIjp5oW/3hUM1oMxOXiDSsf1WA+/FlZNjQgHANClXE o5AIYj1pknqlc+weJnfXaKWg+6AqqYfgEZEkczmQFTcV4WIXX/sPWqDDmmao7q81TgVJ tO6Hq2D7oLrXFaEojIWxP2ppXvaTfsccG9LxEYwsuLBFI1niyplkfWo8UkN7pDlxekXD 7PHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=og7RNubgRbuviq6HL0WLOMidb7Ya2a/kuC6JMdOrS+c=; b=QTF9Yd5asJcTSuu1Gm0Eq21rhpqDktJY/I5WdXs1oTzP+yE6iZT5eeFaPg5WaczNdW OMQKuBEg5YrbsnJeuoNsRshoiCJw44lIyqbnnwcGT+xx5h8udlhWUtBAMk9urOaZF8R/ eRuWhoreY+XAcWsgkL7GhyD0HlET9v/mhSt4aHQQcXHPkSSQRJ9m77LoOtrRCKDqubd0 g1a0DyH40eg4mVZH1Omx2j2DprdsWtQnR49kMuWmZP6Nlk2NYjhUAJ7bwdpvy5KFL/UN bkclZNMSJJ6GKSfkK807Nw9JM79NNe/yGpZzp3gW2zIBEVSexHUk/+qeJkpKzbcvhx+v bh5Q== ARC-Authentication-Results: i=1; mx.google.com; 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 w17-v6si1587349plp.44.2018.02.14.06.45.32; Wed, 14 Feb 2018 06:45:47 -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; 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 S1030964AbeBNOoX convert rfc822-to-8bit (ORCPT + 99 others); Wed, 14 Feb 2018 09:44:23 -0500 Received: from mx2.suse.de ([195.135.220.15]:35040 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030839AbeBNOoT (ORCPT ); Wed, 14 Feb 2018 09:44:19 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8C579ACCD; Wed, 14 Feb 2018 14:44:17 +0000 (UTC) Date: Wed, 14 Feb 2018 15:44:16 +0100 From: Jean Delvare To: Guenter Roeck Cc: Wolfram Sang , =?UTF-8?B?Wm9sdMOhbiBCw7ZzesO2cm0=?= =?UTF-8?B?w6lueWk=?= , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] i2c: piix4: Use usleep_range() Message-ID: <20180214154416.5113038d@endymion> In-Reply-To: <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> <20180212222241.GA32060@roeck-us.net> Organization: SUSE Linux X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.31; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 12 Feb 2018 14:22:41 -0800, Guenter Roeck wrote: > On Mon, Feb 12, 2018 at 11:53:36AM +0100, Jean Delvare wrote: > > 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. It it good that today's hardware is better than Intel's original hardware, but on the other hand, it makes little sense to start polling before the command has a chance of being completed. So I don't think that skipping the initial delay would help with performance. > 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. Your numbers are in line with my theoretical estimates above. > 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. I think I would not bother too much about that older hardware which probably nobody uses anymore (we are talking about late 90s motherboards here, I'm rather conservative and sentimental with my hardware and even me no longer have these.) It makes more sense to make the driver as efficient as possible for current hardware. From your numbers above, an initial sleep of 200 us followed by 200 us in-loop delays would seem reasonable to me. With some upper margin to let the scheduler reduce the CPU awakening, as suggested by Joe somewhere else in this thread. If you want to push it one step further, you could estimate how long the transaction is expected to take (based on the SMBus clock frequency and the number of bytes in the transaction) and set the initial delay to match that. That would allow to shorten the cycle time in the polling loop (as you know you won't cycle at all in most cases) and limit the useless calls to usleep_range() and the polls which can't succeed. Whether you want to spend time on this is up to you, of course. -- Jean Delvare SUSE L3 Support