public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Cc: kbusch@kernel.org, axboe@kernel.dk, hch@lst.de, sagi@grimberg.me,
	linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org, andersson@kernel.org,
	konradybcio@kernel.org, "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Ulf Hansson <ulf.hansson@linaro.org>
Subject: Re: [PATCH] nvme-pci: Shutdown the device if D3Cold is allowed by the user
Date: Thu, 5 Dec 2024 17:29:00 -0600	[thread overview]
Message-ID: <20241205232900.GA3072557@bhelgaas> (raw)
In-Reply-To: <20241123090113.semecglxaqjvlmzp@thinkpad>

On Sat, Nov 23, 2024 at 02:31:13PM +0530, Manivannan Sadhasivam wrote:
> On Fri, Nov 22, 2024 at 04:20:50PM -0600, Bjorn Helgaas wrote:
> > On Mon, Nov 18, 2024 at 01:53:44PM +0530, Manivannan Sadhasivam wrote:
> > > PCI core allows users to configure the D3Cold state for each PCI
> > > device through the sysfs attribute
> > > '/sys/bus/pci/devices/.../d3cold_allowed'. This attribute sets
> > > the 'pci_dev:d3cold_allowed' flag and could be used by users to
> > > allow/disallow the PCI devices to enter D3Cold during system
> > > suspend.
> > >
> > > So make use of this flag in the NVMe driver to shutdown the NVMe
> > > device during system suspend if the user has allowed D3Cold for
> > > the device.  Existing checks in the NVMe driver decide whether
> > > to shut down the device (based on platform/device limitations),
> > > so use this flag as the last resort to keep the existing
> > > behavior.
> > > 
> > > The default behavior of the 'pci_dev:d3cold_allowed' flag is to
> > > allow D3Cold and the users can disallow it through sysfs if they
> > > want.
> > 
> > What problem does this solve?  I guess there must be a case where
> > suspend leaves NVMe in a higher power state than you want?
> 
> Yeah, this is the case for all systems that doesn't fit into the
> existing checks in the NVMe suspend path:
> 
> 1. ACPI based platforms
> 2. Controller doesn't support NPSS (hardware issue/limitation)
> 3. ASPM not enabled
> 4. Devices/systems setting NVME_QUIRK_SIMPLE_SUSPEND flag
> 
> In my case, all the Qualcomm SoCs using Devicetree doesn't fall into
> the above checks. Hence, they were not fully powered down during
> system suspend and always in low power state. This means, I cannot
> achieve 'CX power collapse', a Qualcomm specific SoC powered down
> state that consumes just enough power to wake up the SoC. Since the
> controller driver keeps the PCI resource vote because of NVMe, the
> firmware in the Qualcomm SoCs cannot put the SoC into above
> mentioned low power state.

IIUC nvme_suspend() has two paths:

  - Do nvme_disable_prepare_reset() without calling pci_save_state(),
    so the PCI core chooses and sets the low-power state.

  - Put the device in an NVMe-specific low-power state and call
    pci_save_state(), which prevents the PCI core from putting the
    device in a low-power state.

    (The PCI core part is in pci_pm_suspend_noirq(),
    pci_pm_poweroff_noirq(), pci_pm_runtime_suspend())

And I guess you want the first path for basically all systems?  The
only systems that would use the NVMe-specific path are those where:

  - !pm_suspend_via_firmware() (not an ACPI system), AND

  - ctrl->npss (device supports NVMe power states), AND

  - pcie_aspm_enabled(), AND

  - !NVME_QUIRK_SIMPLE_SUSPEND (it's not something with a weird
    quirk), AND

  - !pdev->d3cold_allowed (user has cleared it via sysfs)

This frankly seems almost unintelligible to me, so I'm glad I'm not
responsible for nvme :)

> > I'm not sure the use of pdev->d3cold_allowed here really expresses
> > your underlying intent.  It suggests that you're really hoping for
> > D3cold, but that's only a possibility if firmware supports it, and
> > we have no visibility into that here.
> 
> I'm not relying on firmware to do anything here. If firmware has to
> decide the suspend state, it should already satisfy the
> pm_suspend_via_firmware() check in nvme_suspend(). ...

I'm confused about this because we want to use PCI core power
management, which chooses the new state with pci_target_state(),
which looks like it will choose D3hot unless we're on an ACPI system
and acpi_pci_choose_state() returns D3cold.

But your system is not an ACPI system, so we should get D3hot, but yet
you decide based on D3*cold* being allowed?

> Here, the controller driver takes care of putting the device into
> D3Cold.  Currently, the controller drivers cannot do it (on DT
> platforms) because of NVMe driver's behavior.

I'm missing the connection to the controller driver (I assume you mean
qcom-pcie?).  Maybe it's that having the NVMe device in a PCI
low-power state allows qcom_pcie_suspend_noirq() to reduce the ICC
bandwidth vote and do other power-saving things?  And it can't do
those things if we're using the NVMe low-power state because that
state is not visible to qcom-pcie?

> We did attempt to solve this problem in multiple ways, but the
> lesson learned was, kernel cannot decide the power mode without help
> from userspace. That's the reason I wanted to make use of this
> 'd3cold_allowed' sysfs attribute to allow userspace to override the
> D3Cold if it wants based on platform requirement.

It seems sub-optimal that this only works how you want if the user
intervenes.

Bjorn

  parent reply	other threads:[~2024-12-05 23:29 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-18  8:23 [PATCH] nvme-pci: Shutdown the device if D3Cold is allowed by the user Manivannan Sadhasivam
2024-11-18 12:58 ` Christoph Hellwig
2024-11-18 14:58   ` Manivannan Sadhasivam
2024-11-22 22:20 ` Bjorn Helgaas
2024-11-23  9:01   ` Manivannan Sadhasivam
2024-11-26 17:11     ` Bjorn Andersson
2024-11-27  5:49       ` Manivannan Sadhasivam
2024-12-05 23:29     ` Bjorn Helgaas [this message]
2024-12-06  1:49       ` Bjorn Helgaas
2024-12-09 13:36         ` Christoph Hellwig
2024-12-09 14:38           ` Manivannan Sadhasivam
2024-12-12  5:59             ` Christoph Hellwig
2024-12-12 12:21               ` Rafael J. Wysocki
2024-12-12 12:49                 ` Ulf Hansson
2024-12-12 15:13                   ` Christoph Hellwig
2024-12-13 14:35                     ` Rafael J. Wysocki
2024-12-14  6:30                       ` Manivannan Sadhasivam
2024-12-16 16:23                         ` Christoph Hellwig
2024-12-16 16:42                           ` Rafael J. Wysocki
2024-12-16 16:48                             ` Manivannan Sadhasivam
2024-12-16 17:28                               ` Rafael J. Wysocki
2024-12-16 17:39                                 ` Manivannan Sadhasivam
2024-12-16 19:10                                   ` Rafael J. Wysocki
2024-12-20 15:15                             ` Konrad Dybcio
2024-12-21  3:38                               ` Manivannan Sadhasivam
2024-12-21 11:17                                 ` Konrad Dybcio
2024-12-26 16:22                                   ` Manivannan Sadhasivam
2025-01-03  7:28                               ` Christoph Hellwig
2025-01-03 11:48                                 ` Konrad Dybcio
2024-12-16 16:24                         ` Rafael J. Wysocki
2024-12-16 17:11                           ` Manivannan Sadhasivam
2024-12-16 17:35                             ` Rafael J. Wysocki
2024-12-16 17:52                               ` Manivannan Sadhasivam
2024-12-16 19:34                                 ` Rafael J. Wysocki
2024-12-16 19:40                                   ` Keith Busch
2024-12-16 19:43                                     ` Rafael J. Wysocki
2024-12-17  5:26                                   ` manivannan.sadhasivam
2024-12-17 19:45                                     ` Rafael J. Wysocki
2024-12-19  8:02                                       ` Manivannan Sadhasivam
2024-12-19 12:45                                         ` Rafael J. Wysocki
2024-12-19 16:41                                           ` Ulf Hansson
2024-12-19 18:28                                             ` Rafael J. Wysocki
2025-01-03  7:26                                               ` Christoph Hellwig
2024-12-19  6:30                                 ` Christoph Hellwig
2024-12-19  8:03                                   ` Manivannan Sadhasivam
2024-12-09 14:43         ` Manivannan Sadhasivam
2024-12-09 14:57       ` Manivannan Sadhasivam

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=20241205232900.GA3072557@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=andersson@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=konradybcio@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=rjw@rjwysocki.net \
    --cc=sagi@grimberg.me \
    --cc=ulf.hansson@linaro.org \
    /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