Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3664416pxb; Mon, 9 Nov 2020 18:08:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzqnnpaPlcVgXrNEIZz7tbKHKtJ020PRgkGd6kIr1aXdo0uuYQ9ogeqAWoN3RGisl8/NJ3N X-Received: by 2002:a17:906:b18:: with SMTP id u24mr18690996ejg.501.1604974134009; Mon, 09 Nov 2020 18:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604974134; cv=none; d=google.com; s=arc-20160816; b=Eas7pXWlM2ZE8ez7Bdzmb8fvF4WWAqPl4wLTCmat7qT0a+90PgS8dYPJuEupwnL+aD 8xASMz+7plCit1CBcyiV8k3cWUOdQ1hedcaSWDu3+ZKmT0YFNA25GiiZexBqR1/J5z7q 5lZiIIi+JITcTfeJA0auuQ6mgCsWndXeHLVtNSq2o6AxeIG4KZaGesLaaydtgNOjnktP O51+FqpKk7Ct3CHYsfabdGyETA885YPCvggKiTGs/v7ZE3K/jR26w71YhMFJtY9MtsZ1 zkCS8pNbZX8jp7xYBsZrB7kqwuYEEJSFM3WYkJ7Q0HyHIAusL6zNUFavMyYa4J/n9/3J 4EvQ== 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; bh=wUHE6ncYEApyoTUS8SHmnwhaXCXQFt3Ni5HWVeDrsCk=; b=e8V017niaZWRvbcKzVbV7DW12kyu45cbObj2gHfep2UB5qH5cOJE6wHNt3Nc6m3q9L C8tS2Hd2IYwF/GNSa39BUvYLSsFrXH31c89UnRuGSryyI/PiAQK9d3BJCpeAacecqBYz iHaMEyIkdmCNywZTO3eP5lMNG4HeYSUW7aJCKdBDGHx5HqgVSCbmhVs85BTa5NNd21KP xwXWCD7hgZSWVjyTc7GGn5ThkcSNGXflx/yTd8kZ39KcOv9Tw0DgaALmSVKEKAYYhe7n QcNeC6lGmZlNcQ6cPfGPDg0DPwBZb2/BOA4Ty/qxBrHLkN7/8dgnX0xK8sqVEzDjScp1 kyMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fnarfbargle.com header.s=mail header.b=y2qM8sEP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fnarfbargle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g13si8753944edn.525.2020.11.09.18.08.31; Mon, 09 Nov 2020 18:08:53 -0800 (PST) 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=@fnarfbargle.com header.s=mail header.b=y2qM8sEP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fnarfbargle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730066AbgKJCEu (ORCPT + 99 others); Mon, 9 Nov 2020 21:04:50 -0500 Received: from ns3.fnarfbargle.com ([103.4.19.87]:36088 "EHLO ns3.fnarfbargle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725889AbgKJCEu (ORCPT ); Mon, 9 Nov 2020 21:04:50 -0500 Received: from srv.home ([10.8.0.1] ident=heh10015) by ns3.fnarfbargle.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1kcJ0t-00033z-2n; Tue, 10 Nov 2020 10:04:03 +0800 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=fnarfbargle.com; s=mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject; bh=wUHE6ncYEApyoTUS8SHmnwhaXCXQFt3Ni5HWVeDrsCk=; b=y2qM8sEPo/UqaqSh80aNlR4XzOH/6zcjQ0ikMecHw43IHjuDKcaiIgc9De8gJdLB2suU72+bN1Shmgj70D7SX9ztQ7bWX5qdsx7MmFY9IdSIm7ae/9laUxZkq0jUn7HFwK03rLYvOS8BiCH7cTQPHeviYL0SkW7ZRduIZmUmx7k=; Subject: Re: [PATCH v3] applesmc: Re-work SMC comms To: Guenter Roeck , Henrik Rydberg Cc: Arnd Bergmann , linux-hwmon@vger.kernel.org, "linux-kernel@vger.kernel.org" , hns@goldelico.com, Andreas Kemnade , Jean Delvare References: <70331f82-35a1-50bd-685d-0b06061dd213@fnarfbargle.com> <3c72ccc3-4de1-b5d0-423d-7b8c80991254@fnarfbargle.com> <6d071547-10ee-ca92-ec8b-4b5069d04501@bitmath.org> <8e117844-d62a-bcb1-398d-c59cc0d4b878@fnarfbargle.com> <9109d059-d9cb-7464-edba-3f42aa78ce92@bitmath.org> <5310c0ab-0f80-1f9e-8807-066223edae13@bitmath.org> <57057d07-d3a0-8713-8365-7b12ca222bae@fnarfbargle.com> <41909045-9486-78d9-76c2-73b99a901b83@bitmath.org> <20201108101429.GA28460@mars.bitmath.org> From: Brad Campbell Message-ID: Date: Tue, 10 Nov 2020 13:04:04 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.2.2 MIME-Version: 1.0 In-Reply-To: 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/11/20 3:06 am, Guenter Roeck wrote: > On 11/8/20 2:14 AM, Henrik Rydberg wrote: >> On Sun, Nov 08, 2020 at 09:35:28AM +0100, Henrik Rydberg wrote: >>> Hi Brad, >>> >>> On 2020-11-08 02:00, Brad Campbell wrote: >>>> G'day Henrik, >>>> >>>> I noticed you'd also loosened up the requirement for SMC_STATUS_BUSY in read_smc(). I assume >>>> that causes problems on the early Macbook. This is revised on the one sent earlier. >>>> If you could test this on your Air1,1 it'd be appreciated. >>> >>> No, I managed to screw up the patch; you can see that I carefully added the >>> same treatment for the read argument, being unsure if the BUSY state would >>> remain during the AVAILABLE data phase. I can check that again, but >>> unfortunately the patch in this email shows the same problem. >>> >>> I think it may be worthwhile to rethink the behavior of wait_status() here. >>> If one machine shows no change after a certain status bit change, then >>> perhaps the others share that behavior, and we are waiting in vain. Just >>> imagine how many years of cpu that is, combined. ;-) >> >> Here is a modification along that line. >> > > Please resend this patch as stand-alone v4 patch. If sent like it was sent here, > it doesn't make it into patchwork, and is thus not only difficult to apply but > may get lost, and it is all but impossible to find and apply all tags. > Also, prior to Henrik's Signed=off-by: there should be a one-line explanation > of the changes made. > > Thanks, > Guenter > >> Compared to your latest version, this one has wait_status() return the >> actual status on success. Instead of waiting for BUSY, it waits for >> the other status bits, and checks BUSY afterwards. So as not to wait >> unneccesarily, the udelay() is placed together with the single >> outb(). The return value of send_byte_data() is augmented with >> -EAGAIN, which is then used in send_command() to create the resend >> loop. >> >> I reach 41 reads per second on the MBA1,1 with this version, which is >> getting close to the performance prior to the problems. >> Can I get an opinion on this wait statement please? The apple driver uses a loop with a million (1,000,000) retries spaced with a 10uS delay. In my testing on 2 machines, we don't busy wait more than about 2 loops. Replacing a small udelay with the usleep_range kills performance. With the following (do 10 fast checks before we start sleeping) I nearly triple the performance of the driver on my laptop, and double it on my iMac. This is on an otherwise unmodified version of Henriks v4 submission. Yes, given the timeouts I know it's a ridiculous loop condition. static int wait_status(u8 val, u8 mask) { unsigned long end = jiffies + (APPLESMC_MAX_WAIT * HZ) / USEC_PER_SEC; u8 status; int i; for (i=1; i < 1000000; i++) { status = inb(APPLESMC_CMD_PORT); if ((status & mask) == val) return status; /* timeout: give up */ if (time_after(jiffies, end)) break; if (i < 10) udelay(10); else usleep_range(APPLESMC_MIN_WAIT, APPLESMC_MIN_WAIT * 16); } return -EIO; } Regards, Brad