Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3552175imm; Sun, 30 Sep 2018 23:57:57 -0700 (PDT) X-Google-Smtp-Source: ACcGV63TysQYiBwf1MIEkPInwes6XbRcQ1OuLOmIBpTU7OGV8ukdLi+JExfiaI584teugLzBOTQ7 X-Received: by 2002:a63:cb51:: with SMTP id m17-v6mr8875533pgi.105.1538377076926; Sun, 30 Sep 2018 23:57:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538377076; cv=none; d=google.com; s=arc-20160816; b=WhbyGKKxJnibxXXiCwU6Zu6lCaCRkkuq7fL6HXqbfneTuS3cmjM6QR1yEFTPbaTrcd OKd+8lNXyP85ACeF05dhcwKB2MV9p5kzVNRL8vQVAr0j15tGFlyVjZearBZqzfTyWVOj KylRzaMxONbRgd7b4EUwx3o3qy9HPoPS0v1z4hXwQpqnfDwnDdFO2QPGhXsiDJE/nOIu 5fmdQagEHnTi79pC66iF+fiaFJZY09yrhIAto8+uGbiN5xRO4LfKkioed4ZI99aNcpxr SeTknQC288p0m1HtWlxLy60yA4ZD6mRlgsO/9BR7adeGc0AhB2Y8M3elX1KyFHGGGvUE yDkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=6v+PEJgA6/RPmEXDPBzWHGWtq4n2ZgsG+QnnunA7HZc=; b=IP82Yw1dpvTtwLgTNBOdjQKctzcU31oAhlcyp4IJUFIW8sE4Tj+qFbV1tKjF+qWN7d oYuWSqyNn0NXWtczQHNURXMio72SIya7qRPy2TuWj52+tJ1U3wmrgSuuJHDumqz3ZL06 hWRNRoTQcY5VqNhxt9cTjHxsRB9/gwA6cc+EFobhYyWK+OpqMhW3FiNbjENjNIX0RqIf OGaml+PvFOXjVzdx3xMaaDP46vymYg620Gpse/WmOen11677zmt+aRf/j2BUz/D9sZYp 8bcxh09JDZ4Iz8O9yezTgAnYDRotWK66+oudINq34kLG2EaoCVRV8+EOvhI8CVnV8LlV diAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b="FM20/O8R"; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4-v6si11725532pla.299.2018.09.30.23.57.41; Sun, 30 Sep 2018 23:57:56 -0700 (PDT) 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=pass header.i=@broadcom.com header.s=google header.b="FM20/O8R"; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728832AbeJANdS (ORCPT + 99 others); Mon, 1 Oct 2018 09:33:18 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:46306 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728741AbeJANdS (ORCPT ); Mon, 1 Oct 2018 09:33:18 -0400 Received: by mail-qk1-f195.google.com with SMTP id q12-v6so7404900qkl.13 for ; Sun, 30 Sep 2018 23:57:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6v+PEJgA6/RPmEXDPBzWHGWtq4n2ZgsG+QnnunA7HZc=; b=FM20/O8RjtW776/nXGLHaoynFROyQv35ozEixBYfF9g+Np0SslzYaWGSJLYuNiMTai v7ZS3GeSFgEMazJPxEj36ih5iEGmCXksDg9VtOLRKz2H9ni5sfBvfwW46nLnh90RQNcS ypQKMMb+Y8sLcBuS01u1lQRz0r7JB61zNH8tQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6v+PEJgA6/RPmEXDPBzWHGWtq4n2ZgsG+QnnunA7HZc=; b=RUlR20ItTveCHjABpt6waw9JdN1yhVHNlwzQnGCnxHWqESacVd9fHma9U88q4VPEPG 04qkwhCF3imX2aVsxno9aq0ZEm4IJ2gHbeU+Iu14KWBlZrHZFNyMWHjNxj7odUWtO79U LZWhnP9+nNSVQxsIiKknNhcGQbwVl4InZBLreuLe4aC5jsA/pTFSYr/O5Ji+aq/UqOLT Py7mXf7gmMuQY8sXyBn233ppaeeAV5+OLrSCYNt6RfkdyFQsUfynmLBRCzkJS4yp3/2P VKEEhTQDoRLZNBVBHoSmhFgFjI81cBU9k03xs3ktSsQ1Jc/Ko62uP15zlkliBfdvspt1 hSVQ== X-Gm-Message-State: ABuFfogsubJu5EZcJaCzWdlOXbdpR4MxXRaH9edYqvAD9R4q01WJCOlG gIcc+rEm3kAgJtIqGcIVI2/JTYsjcTD/PxmImFC3qA== X-Received: by 2002:ae9:f106:: with SMTP id k6-v6mr2820678qkg.34.1538377022597; Sun, 30 Sep 2018 23:57:02 -0700 (PDT) MIME-Version: 1.0 References: <1537935759-14754-1-git-send-email-suganath-prabu.subramani@broadcom.com> <1537935759-14754-2-git-send-email-suganath-prabu.subramani@broadcom.com> <20180926213241.GI28024@bhelgaas-glaptop.roam.corp.google.com> <20180927070327.wvl5glb4c7gtjoa3@wunner.de> <20180927184746.GM28024@bhelgaas-glaptop.roam.corp.google.com> <20180927190959.dio4qwti3i4accjm@wunner.de> In-Reply-To: <20180927190959.dio4qwti3i4accjm@wunner.de> From: Suganath Prabu Subramani Date: Mon, 1 Oct 2018 12:27:28 +0530 Message-ID: Subject: Re: [PATCH v4 1/6] mpt3sas: Introduce mpt3sas_base_pci_device_is_available To: lukas@wunner.de Cc: helgaas@kernel.org, linux-scsi@vger.kernel.org, linux-pci@vger.kernel.org, Andy Shevchenko , Sathya Prakash , Sreekanth Reddy , linux-kernel@vger.kernel.org, benh@kernel.crashing.org, ruscur@russell.cc, sbobroff@linux.ibm.com, oohall@gmail.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lucas and Bjorn, Thanks for reviewing and providing useful comments. On Fri, Sep 28, 2018 at 12:40 AM Lukas Wunner wrote: > > On Thu, Sep 27, 2018 at 01:47:46PM -0500, Bjorn Helgaas wrote: > > mpt3sas_wait_for_commands_to_complete(...) > > { > > ... > > + if (!mpt3sas_base_pci_device_is_available(ioc)) > > + return; > > > > # In the definitive case, we returned above. If we get here, we > > # think the device *might* be present. The readl() inside > > # mpt3sas_base_get_iocstate() might fail (returning ~0 data). > > # It happens that (~0 & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL > > # so we will return below if the device was removed after the > > # check above. > > > > ioc_state = mpt3sas_base_get_iocstate(ioc, 0); > > if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) > > return; > > ... > > > > > > I think this code is unreasonably complicated. The multiple layers > > and negations make it very difficult to figure out what's definitive. > > I agree there's room for improvement. > > > > I'm not sure how mpt3sas benefits from adding > > mpt3sas_base_pci_device_is_available() here, other than the fact that > > it avoids an MMIO read to the device in most cases. I think it would > > be simpler and better to make mpt3sas_base_get_iocstate() smarter > > about handling ~0 values from the readl(). > > Avoiding an MMIO read when it's known to run into a Completion Timeout > buys about 17 ms. If the function is executed many times (I don't know > if that's the case here, I'm referring to the general case), or if bailing > out of it early avoids significant amounts of further I/O, then checking > for disconnectedness makes sense. > > The 17 ms number is from this talk: > https://www.youtube.com/watch?v=GJ6B0xzgvlM&t=832 > > It's the typical Completion Timeout on an Intel chip, but it can be up to > 50 ms in the default setting or up to 64 s if so configured in the Device > Control 2 register (PCIe r4.0 sec 7.8.16). > This function is called only during controller reset, system shutdown and driver unload operations. For this case we can remove mpt3sas_base_pci_device_is_available() check, since we can make the device removal from readl in mpt3sas_base_get_iocstate() as you suggested. But we need mpt3sas_base_pci_device_is_available() in other places like while submitting the IO/TMs to the HBA firmware etc where driver is not checking for the IOC state (through readl() operation) to gracefully handle the HBA hot-unplug operation. > Thanks, > > Lukas