All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Linux PCI <linux-pci@vger.kernel.org>,
	Linux PM <linux-pm@vger.kernel.org>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] PCI: PM: Avoid resuming devices in D3hot during system suspend
Date: Fri, 31 May 2019 16:16:48 -0500	[thread overview]
Message-ID: <20190531211648.GB58810@google.com> (raw)
In-Reply-To: <4561083.VtDMOnK5Me@kreacher>

On Fri, May 31, 2019 at 11:49:30AM +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> The current code resumes devices in D3hot during system suspend if
> the target power state for them is D3cold, but that is not necessary
> in general.  It only is necessary to do that if the platform firmware
> requires the device to be resumed, but that should be covered by
> the platform_pci_need_resume() check anyway, so rework
> pci_dev_keep_suspended() to avoid returning 'false' for devices
> in D3hot which need not be resumed due to platform firmware
> requirements.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/pci/pci.c |   15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> Index: linux-pm/drivers/pci/pci.c
> ===================================================================
> --- linux-pm.orig/drivers/pci/pci.c
> +++ linux-pm/drivers/pci/pci.c
> @@ -2474,10 +2474,19 @@ bool pci_dev_keep_suspended(struct pci_d
>  {
>  	struct device *dev = &pci_dev->dev;
>  	bool wakeup = device_may_wakeup(dev);
> +	pci_power_t target_state;
>  
> -	if (!pm_runtime_suspended(dev)
> -	    || pci_target_state(pci_dev, wakeup) != pci_dev->current_state
> -	    || platform_pci_need_resume(pci_dev))
> +	if (!pm_runtime_suspended(dev) || platform_pci_need_resume(pci_dev))
> +		return false;
> +
> +	target_state = pci_target_state(pci_dev, wakeup);

Nit, add a blank line here.

> +	/*
> +	 * If the earlier platform check has not triggered, D3cold is just power
> +	 * removal on top of D3hot, so no need to resume the device in that
> +	 * case.
> +	 */
> +	if (target_state != pci_dev->current_state &&
> +	    target_state != PCI_D3cold && pci_dev->current_state != PCI_D3hot)
>  		return false;

This is more a comment on the existing code than on this particular
patch, but I find this whole function hard to understand, and I think
one reason is that there are a lot of negative conditions, both in
this function and in its callers.  This "target_state != ... &&
target_state != ...  && current_state != ..." is one example.  Another
is the function name itself.  It might be easier to read as something
like this:

  bool pci_dev_need_resume(...)
  {
    if (!pm_runtime_suspended(...))
      return true;

    if (platform_pci_need_resume(...))
      return true;

    if (target_state != current_state)
      return true;

    ...

Another reason I think it's hard to read is that
"pci_dev_keep_suspended" suggests that this is a pure boolean function
without side-effects, but in fact it also fiddles with the PME state
in some cases.  I don't have any ideas for that part.

Bjorn

  reply	other threads:[~2019-05-31 21:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-31  9:49 [PATCH] PCI: PM: Avoid resuming devices in D3hot during system suspend Rafael J. Wysocki
2019-05-31 21:16 ` Bjorn Helgaas [this message]
2019-06-03 10:10   ` Rafael J. Wysocki
2019-06-05 11:36     ` Bjorn Helgaas
2019-06-05 12:01       ` Rafael J. Wysocki

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=20190531211648.GB58810@google.com \
    --to=helgaas@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=rjw@rjwysocki.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.