linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Victor Ding <victording@google.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Ben Chuang <ben.chuang@genesyslogic.com.tw>,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	linux-mmc@vger.kernel.org, Alex Levin <levinale@google.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Kai-Heng Feng <kai.heng.feng@canonical.com>,
	"Saheed O. Bolarinwa" <refactormyself@gmail.com>,
	Sean Paul <seanpaul@chromium.org>,
	Sukumar Ghorai <sukumar.ghorai@intel.com>,
	Yicong Yang <yangyicong@hisilicon.com>
Subject: Re: [PATCH 1/2] PCI/ASPM: Disable ASPM until its LTR and L1ss state is restored
Date: Tue, 12 Jan 2021 16:32:28 -0600	[thread overview]
Message-ID: <20210112223228.GA1857596@bjorn-Precision-5520> (raw)
In-Reply-To: <20210112040146.1.I9aa2b9dd39a6ac9235ec55a8c56020538aa212fb@changeid>

Hi Victor,

Thanks for the patch.  Improving suspend/resume performance is always
a good thing!

On Tue, Jan 12, 2021 at 04:02:04AM +0000, Victor Ding wrote:
> Right after powering up, the device may have ASPM enabled; however,
> its LTR and/or L1ss controls may not be in the desired states; hence,
> the device may enter L1.2 undesirably and cause resume performance
> penalty. This is especially problematic if ASPM related control
> registers are modified before a suspension.

s/L1ss/L1SS/ (several occurrences) to match existing usage.

> Therefore, ASPM should disabled until its LTR and L1ss states are
> fully restored.
> 
> Signed-off-by: Victor Ding <victording@google.com>
> ---
> 
>  drivers/pci/pci.c       | 11 +++++++++++
>  drivers/pci/pci.h       |  2 ++
>  drivers/pci/pcie/aspm.c |  2 +-
>  3 files changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index eb323af34f1e..428de433f2e6 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -1660,6 +1660,17 @@ void pci_restore_state(struct pci_dev *dev)
>  	if (!dev->state_saved)
>  		return;
>  
> +	/*
> +	 * Right after powering up, the device may have ASPM enabled;

I think this could be stated more precisely.  "Right after powering
up," ASPM should be *disabled* because ASPM Control in the Link
Control register powers up as zero (disabled).

> +	 * however, its LTR and/or L1ss controls may not be in the desired
> +	 * states; as a result, the device may enter L1.2 undesirably and
> +	 * cause resume performance penalty.
> +	 * Therefore, ASPM is disabled until its LTR and L1ss states are
> +	 * fully restored.
> +	 * (enabling ASPM is part of pci_restore_pcie_state)

If we're enabling L1.2 before LTR has been configured, that's
definitely a bug.  But I don't see how that happens.  The current code
looks like:

  pci_restore_state
    pci_restore_ltr_state
      pci_write_config_word(dev, ltr + PCI_LTR_MAX_SNOOP_LAT, *cap++)
      pci_write_config_word(dev, ltr + PCI_LTR_MAX_NOSNOOP_LAT, *cap++)
    pci_restore_aspm_l1ss_state
      pci_write_config_dword(dev, aspm_l1ss + PCI_L1SS_CTL1, *cap++)
    pci_restore_pcie_state
      pcie_capability_write_word(dev, PCI_EXP_LNKCTL, cap[i++])

We *do* restore PCI_L1SS_CTL1, which contains "ASPM L1.2 Enable",
before we restore PCI_EXP_LNKCTL, which contains "ASPM Control", but I
don't think "ASPM L1.2 Enable" by itself should be enough to allow
hardware to enter L1.2.

Reading PCIe r5.0, sec 5.5.1, it seems like hardware should ignore the
PCI_L1SS_CTL1 bits unless ASPM L1 entry is enabled in PCI_EXP_LNKCTL.

What am I missing?

> +	 */
> +	pcie_config_aspm_dev(dev, 0);
> +
>  	/*
>  	 * Restore max latencies (in the LTR capability) before enabling
>  	 * LTR itself (in the PCIe capability).
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index e9ea5dfaa3e0..f774bd6d2555 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -564,6 +564,7 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev);
>  void pcie_aspm_exit_link_state(struct pci_dev *pdev);
>  void pcie_aspm_pm_state_change(struct pci_dev *pdev);
>  void pcie_aspm_powersave_config_link(struct pci_dev *pdev);
> +void pcie_config_aspm_dev(struct pci_dev *pdev, u32 val);
>  void pci_save_aspm_l1ss_state(struct pci_dev *dev);
>  void pci_restore_aspm_l1ss_state(struct pci_dev *dev);
>  #else
> @@ -571,6 +572,7 @@ static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { }
>  static inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { }
>  static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev) { }
>  static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { }
> +static inline void pcie_config_aspm_dev(struct pci_dev *pdev, u32 val) { }
>  static inline void pci_save_aspm_l1ss_state(struct pci_dev *dev) { }
>  static inline void pci_restore_aspm_l1ss_state(struct pci_dev *dev) { }
>  #endif
> diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
> index a08e7d6dc248..45535b4e1595 100644
> --- a/drivers/pci/pcie/aspm.c
> +++ b/drivers/pci/pcie/aspm.c
> @@ -778,7 +778,7 @@ void pci_restore_aspm_l1ss_state(struct pci_dev *dev)
>  	pci_write_config_dword(dev, aspm_l1ss + PCI_L1SS_CTL2, *cap++);
>  }
>  
> -static void pcie_config_aspm_dev(struct pci_dev *pdev, u32 val)
> +void pcie_config_aspm_dev(struct pci_dev *pdev, u32 val)
>  {
>  	pcie_capability_clear_and_set_word(pdev, PCI_EXP_LNKCTL,
>  					   PCI_EXP_LNKCTL_ASPMC, val);
> -- 
> 2.30.0.284.gd98b1dd5eaa7-goog
> 

  reply	other threads:[~2021-01-12 22:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-12  4:02 [PATCH 0/2] Disable ASPM on GL9750 during a suspension Victor Ding
2021-01-12  4:02 ` [PATCH 1/2] PCI/ASPM: Disable ASPM until its LTR and L1ss state is restored Victor Ding
2021-01-12 22:32   ` Bjorn Helgaas [this message]
2021-01-13  2:16     ` Victor Ding
2021-01-13 20:54       ` Bjorn Helgaas
2021-01-14  9:13         ` Victor Ding
2021-01-12  4:02 ` [PATCH 2/2] mmc: sdhci-pci-gli: Disable ASPM during a suspension Victor Ding
2021-01-12 22:38   ` Bjorn Helgaas
2021-01-13  2:16     ` Victor Ding
2021-01-13 21:48       ` Bjorn Helgaas
2021-01-14  9:13         ` Victor Ding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210112223228.GA1857596@bjorn-Precision-5520 \
    --to=helgaas@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ben.chuang@genesyslogic.com.tw \
    --cc=bhelgaas@google.com \
    --cc=kai.heng.feng@canonical.com \
    --cc=levinale@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=refactormyself@gmail.com \
    --cc=seanpaul@chromium.org \
    --cc=sukumar.ghorai@intel.com \
    --cc=ulf.hansson@linaro.org \
    --cc=victording@google.com \
    --cc=yangyicong@hisilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).