Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp727787imm; Fri, 1 Jun 2018 08:32:09 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLDu6HM7zOvzMWmN4E7y2+FaZ2iTJEQmrElsMZHv0occ+BffyHDG3NW8SNYwnRGcB9gknzw X-Received: by 2002:a65:6252:: with SMTP id q18-v6mr3952689pgv.106.1527867129767; Fri, 01 Jun 2018 08:32:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527867129; cv=none; d=google.com; s=arc-20160816; b=qNsKpDre3zlWbYjbPWWGOouDEGxya45tWyS+m99c7bNKwP35AXWACJzzGmENqK7yCj RY/0+pQMhZZmfK7ueubwwfCD1jAP8F62Wp78aXOmjjlee3QCyYjZzIyUnzbRKa88sELY F12B7nERLvrDymb7VWYoCBwVl3nBtBSknyUCZ5YnkZ2nB3+sKT2FT8PLylCyj97CUfob 3YrXEbzaCxMEK2UbBiepJ4g4sY6JOWBfYCdDNT/SPJ9Y7H2Bo3ozrdIEtP376HOpcGXf ScW4E10bavTpQ3v5QN3G2E4ye68eOgtgY3QhH5gN9nYlSXiVXHApdqcxwx3022WimOsX qU7w== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=r/WUJxunnycEj6rCsbA7+RpyokoO4OLbH+9EbCTBYEA=; b=t/RpzY2BJWhuxcsTOJyTamtNCJ8ZK11RB9pb/Kjky2XjQdInI+PWc1p9fJtLTBOupm H4d0/oldKjGVCWJYpDbukxr7vFdJv4XJUphx+VUfGrsf7Mh7W/fV1evTrUk0seFWTJF+ Rt03KiF+0adWBmqln/Rt8fawYDQrumUh4Vd20f+OmCI0zcEVKj9zSm3ZEAxNHQzNCWDz lnYml+AvfzxKSnSd8YOodfd+EyFsz5/ZX3FybqltCC4MK764mBINxUWEhx04la2uMTXf vGbNtl2yfJi/vwKGny1Td1/NJgdcrsaOQEn/+ajIfd+r5u81+eb2EWPKdkWJRYFS5KBa oK5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mteRUNnu; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t14-v6si17015059ply.102.2018.06.01.08.31.54; Fri, 01 Jun 2018 08:32:09 -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=@gmail.com header.s=20161025 header.b=mteRUNnu; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753166AbeFAPaH (ORCPT + 99 others); Fri, 1 Jun 2018 11:30:07 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:40987 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753307AbeFAP3i (ORCPT ); Fri, 1 Jun 2018 11:29:38 -0400 Received: by mail-oi0-f67.google.com with SMTP id 11-v6so22805774ois.8; Fri, 01 Jun 2018 08:29:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=r/WUJxunnycEj6rCsbA7+RpyokoO4OLbH+9EbCTBYEA=; b=mteRUNnuP5jk6iS9O2XxTYDmDnDMzxczXPMZhvywb8ogssqISEsJubyvUTtUBASQpZ MxsV8HYYN4hwMBQ54JHF9GO5kAm4g6CjuQBOWyYw9ABAlWSJYgvDPOwgbYvVQopUiQRu qBQmqvrSsLPWCjeLtlVvMP/Isl+x0KnZrf8HTn9eCSVknBs3zg2ibPI3XdKmSkBq8ktc 9P4DuzDio/c9AmifQuBds1lWEBPdIt3R3zj5PkUc0ZVtY/p5AIapm5TvJ1dA3PxiXwTu nYta3gxnXjraiRCD4KndJuPem8i6QgzUNXcNRtarCetGkHYN1+1OH6yr2hEt3vD/7KWM HJVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=r/WUJxunnycEj6rCsbA7+RpyokoO4OLbH+9EbCTBYEA=; b=LxlsRObjVoUxlqfUZdVxpFtNJYNaicb5yETir7a57JXdnkH6YopNNcPE6ArLU7rt0B 9LGshQq3afSKXLF0Kim8RC15KCrgHsLdaXf2H90UpouGMTVmreD4zE2gIFTbKNr3z1oZ zDeKSQE3EHnIEgsJPLWRBSjVwA7EzwZ6ROSd/RMZ4vjSqphwumOZyREZlQn9Lwo6iLf8 ftBUa4JYhCobK2GpkMz57b1bZqTEqMVKz4K76Inw3NTTQTDV6Ac5xo6Ry1KrsUF9GjpA wIcLTQSGD6sR0h5lI0SLigXBi6SZWZ9zv0RTcIMzpeUkRi9QkMOKTJ2ABXLbyK7fUMZx 8i2w== X-Gm-Message-State: APt69E2EBpQzcV+bDE+vHJaXW7VnMivpELNZP+DY9wKGQKTNb5ZrDqaJ 4n1iP1t+injb3xHLAexwSguGN3oBPdk= X-Received: by 2002:aca:c5d4:: with SMTP id v203-v6mr6838247oif.92.1527866977261; Fri, 01 Jun 2018 08:29:37 -0700 (PDT) Received: from nuclearis2_1.gtech (c-98-201-114-184.hsd1.tx.comcast.net. [98.201.114.184]) by smtp.gmail.com with ESMTPSA id a41-v6sm7159560otj.45.2018.06.01.08.29.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jun 2018 08:29:36 -0700 (PDT) Subject: Re: [PATCH v2] PCI: Check for PCIe downtraining conditions To: Andy Shevchenko Cc: Bjorn Helgaas , alex_gagniuc@dellteam.com, austin_bolen@dell.com, shyam_iyer@dell.com, Keith Busch , Sinan Kaya , linux-pci@vger.kernel.org, Linux Kernel Mailing List References: <20180601150129.10486-1-mr.nuke.me@gmail.com> From: "Alex G." Message-ID: <6fabb0e8-0de8-ab74-94f3-8990033f9658@gmail.com> Date: Fri, 1 Jun 2018 10:29:36 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/01/2018 10:12 AM, Andy Shevchenko wrote: > On Fri, Jun 1, 2018 at 6:01 PM, Alexandru Gagniuc wrote: >> PCIe downtraining happens when both the device and PCIe port are >> capable of a larger bus width or higher speed than negotiated. >> Downtraining might be indicative of other problems in the system, and >> identifying this from userspace is neither intuitive, nor straigh >> forward. >> >> The easiest way to detect this is with pcie_print_link_status(), >> since the bottleneck is usually the link that is downtrained. It's not >> a perfect solution, but it works extremely well in most cases. > >> +static void pcie_check_upstream_link(struct pci_dev *dev) >> +{ > >> + > > This is redundant, but... Hmm. I thought it's not safe to call pci_pcie_type() on non-pcie devices. I see the pci_is_pcie() check followed by pci_pcie_type() is not uncommon. I didn't think it would be an issue, as long as it's consistent with the rest of the code. >> + if (!pci_is_pcie(dev)) >> + return; >> + >> + /* Look from the device up to avoid downstream ports with no devices. */ >> + if ((pci_pcie_type(dev) != PCI_EXP_TYPE_ENDPOINT) && >> + (pci_pcie_type(dev) != PCI_EXP_TYPE_LEG_END) && >> + (pci_pcie_type(dev) != PCI_EXP_TYPE_UPSTREAM)) >> + return; > > ...wouldn't be better > > int type = pci_pcie_type(dev); > > ? An extra local variable when the compiler knows how to optimize it out? To me, it doesn't seem like it would improve readability, but it would make the code longer. > But also possible, looking at existing code, > > static inline bool pci_is_pcie_type(dev, type) > { > return pci_is_pcie(dev) ? pci_pcie_type(dev) == type : false; > } return pci_is_pcie(dev) && (pci_pcie_type(dev) == type); seems cleaner. Although this sort of cleanup is beyond the scope of this change. Thanks, Alex