From: Lukas Wunner <lukas@wunner.de>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Bjorn Helgaas <helgaas@kernel.org>,
Linux PCI <linux-pci@vger.kernel.org>,
Linux PM <linux-pm@vger.kernel.org>,
Andreas Noever <andreas.noever@gmail.com>
Subject: Re: [PATCH v2 10/13] PCI: Avoid going from D3cold to D3hot for system sleep
Date: Sun, 14 Aug 2016 12:27:25 +0200 [thread overview]
Message-ID: <20160814102725.GA8634@wunner.de> (raw)
In-Reply-To: <2003407.8XLAPPsQTe@vostro.rjw.lan>
On Sat, Aug 13, 2016 at 12:18:26AM +0200, Rafael J. Wysocki wrote:
> Yes, so specifically I'm concerned about the pci_target_state() invocation
> in pci_dev_keep_suspended() which is done exactly for this purpose.
>
> If you apply the "keep it in D3cold if already there" logic to that case,
> it may lead to a wrong decision in theory. Say the device is in D3cold and
> platform_pci_choose_state() returns D1, but pci_no_d1d2() returns true,
> the device will end up in D3cold, but it may not be able to signal wakeup
> from that state after the system has been suspended.
Ugh, I had missed those break statements in the platform-case.
I must be blind. You're right of course, that wouldn't be correct.
> Of course, I guess you'll say that it may not be able to signal wakeup from
> D3hot as well in that case, which is correct. :-)
Hm, what would be the correct power state in that case then? PCI_D0?
> Why don't you simply rearrange the routine like
>
> pci_power_t target_state = PCI_D3hot;
>
> if (platform_pci_power_manageable(dev)) {
> ...
> return target_state;
> }
>
> if (!dev->pm_cap)
> return PCI_D0;
>
> if (dev->current_state == PCI_D3cold)
> target_state = PCI_D3cold;
>
> if (device_may_wakeup(&dev->dev)) {
> ...
> }
>
> return target_state;
>
> And that would be fine by me.
Looks good, I'll give that a try.
If the correct power state in the pci_no_d1d2() case is PCI_D0,
I could fix that up as well.
> That said I'm not sure why you want to use pci_target_state() so badly?
>
> If you are going to use a PM domain, why do you still need that function?
The dev_pm_domain is only assigned to the topmost device exposed by
the Thunderbolt controller (the upstream bridge). I would like to avoid
having to assign separate dev_pm_domains to the downstream bridges.
So I let the NHI and downstream bridges go to D3hot. And when the
upstream bridge cuts power, it iterates over all child devices
and changes their current_state to D3cold to reflect reality.
When the system is later put to sleep, this patch ensures that the
NHI and downstream bridges are not unnecessarily resumed to D3hot.
So why change the current_state of the children at all? I could just
leave the (incorrect) PCI_D3hot and everything would be peachy, right?
Well, there's another problem: The first few Thunderbolt chips had
broken MSI, they have to use INTx to signal hotplug. Unfortunately on
some Macs built 2011/2012, the IRQ is shared with multiple other devices,
most importantly the wireless card which can generate thousands of
interrupts on a crowded WLAN. If power is cut to the Thunderbolt
controller, reading from the hotplug ports' config space in pcie_isr()
fails and results in a "no response from device" message logged with
KERN_INFO. Getting thousands of such messages is annoying, not to
mention the giant waste of CPU cycles to read from the config space
of a device which we *know* is powered down.
The solution I came up with is to add a tiny two-liner to pcie_isr()
with commit ed91de7e14fb ("PCI: pciehp: Ignore interrupts during D3cold").
But that requires that I update the children's current_state to D3cold,
and necessitates that pci_target_state() doesn't resume them to D3hot
for system sleep. Hence the need for this patch.
The approach has the additional benefit that hybrid graphics devices
are implicitly also afforded direct-complete without having to add a
->prepare hook that returns a positive int. They only need to set their
current_state to D3cold, which they already do, see azx_vs_set_state(),
nouveau_pmops_runtime_suspend(), radeon_pmops_runtime_suspend(),
amdgpu_pmops_runtime_suspend().
However this also means that adding a can_power_off flag to struct
dev_pm_domain wouldn't be a viable solution because then I'd have to
assign a dev_pm_domain to the downstream bridges. Another thing I've
missed. Ugh. This is so complicated it's easy to get tangled up in
all these intricate little details.
Thanks for your patience in dealing with these issues,
Lukas
next prev parent reply other threads:[~2016-08-14 10:27 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-13 11:15 [PATCH v2 00/13] Runtime PM for Thunderbolt on Macs Lukas Wunner
2016-05-13 11:15 ` [PATCH v2 01/13] PCI: Recognize Thunderbolt devices Lukas Wunner
2016-05-13 11:15 ` [PATCH v2 06/13] PCI: pciehp: Support runtime pm Lukas Wunner
2016-05-13 11:15 ` [PATCH v2 08/13] PCI: Allow runtime PM for Thunderbolt hotplug ports on Macs Lukas Wunner
2016-06-14 9:08 ` [PATCH v2 08/13 REBASED] " Lukas Wunner
2016-06-17 21:53 ` [PATCH v2 08/13] " Bjorn Helgaas
2016-05-13 11:15 ` [PATCH v2 04/13] PCI: Generalize portdrv pm iterator Lukas Wunner
2016-05-13 11:15 ` [PATCH v2 02/13] PCI: Allow D3 for Thunderbolt ports Lukas Wunner
2016-05-13 11:15 ` [PATCH v2 09/13] PCI: Do not write to PM control register while in D3cold Lukas Wunner
2016-06-17 21:18 ` Bjorn Helgaas
2016-07-18 13:55 ` Rafael J. Wysocki
2016-05-13 11:15 ` [PATCH v2 13/13] thunderbolt: Support runtime pm on NHI Lukas Wunner
2016-05-13 11:15 ` [PATCH v2 05/13] PCI: Use portdrv pm iterator on further callbacks Lukas Wunner
2016-05-13 11:15 ` [PATCH v2 03/13] PCI: Add Thunderbolt portdrv service type Lukas Wunner
2016-06-17 22:51 ` Bjorn Helgaas
2016-07-20 0:30 ` Rafael J. Wysocki
2016-07-20 6:59 ` Lukas Wunner
2016-05-13 11:15 ` [PATCH v2 12/13] thunderbolt: Support runtime pm on upstream bridge Lukas Wunner
2016-05-13 11:15 ` [PATCH v2 10/13] PCI: Avoid going from D3cold to D3hot for system sleep Lukas Wunner
2016-06-17 21:09 ` Bjorn Helgaas
2016-06-17 22:14 ` Lukas Wunner
2016-07-18 13:39 ` Rafael J. Wysocki
2016-08-03 12:28 ` Lukas Wunner
2016-08-03 23:50 ` Rafael J. Wysocki
2016-08-04 0:45 ` Lukas Wunner
2016-08-04 1:07 ` Rafael J. Wysocki
2016-08-04 8:14 ` Lukas Wunner
2016-08-04 15:30 ` Rafael J. Wysocki
2016-08-07 9:03 ` Lukas Wunner
2016-08-07 23:32 ` Rafael J. Wysocki
2016-08-11 13:20 ` Lukas Wunner
2016-08-12 0:50 ` Rafael J. Wysocki
2016-08-12 16:16 ` Lukas Wunner
2016-08-12 22:18 ` Rafael J. Wysocki
2016-08-12 22:37 ` Rafael J. Wysocki
2016-08-14 10:27 ` Lukas Wunner [this message]
2016-08-15 23:05 ` Rafael J. Wysocki
2016-05-13 11:15 ` [PATCH v2 07/13] PCI: pciehp: Ignore interrupts during D3cold Lukas Wunner
2016-06-17 22:52 ` Bjorn Helgaas
2016-08-02 16:27 ` Lukas Wunner
2016-08-05 0:29 ` Rafael J. Wysocki
2016-05-13 11:15 ` [PATCH v2 11/13] PM / sleep: Allow opt-out from runtime resume after direct-complete Lukas Wunner
2016-07-18 13:18 ` Rafael J. Wysocki
2016-08-07 9:56 ` Lukas Wunner
2016-08-07 15:33 ` Alan Stern
2016-08-12 16:39 ` Lukas Wunner
2016-08-12 17:30 ` Alan Stern
2016-08-12 22:40 ` Rafael J. Wysocki
2016-05-21 9:48 ` [PATCH v2 00/13] Runtime PM for Thunderbolt on Macs Andreas Noever
2016-06-14 16:37 ` Bjorn Helgaas
2016-06-14 19:14 ` Andreas Noever
2016-06-14 20:22 ` Bjorn Helgaas
2016-06-15 18:40 ` Lukas Wunner
2016-06-16 1:55 ` Linus Torvalds
2016-07-07 17:39 ` Andreas Noever
2016-07-09 5:23 ` Greg KH
2016-07-12 21:46 ` Andreas Noever
2016-06-13 20:58 ` Bjorn Helgaas
2016-06-14 9:27 ` Lukas Wunner
2016-07-07 15:02 ` Lukas Wunner
2016-07-08 1:28 ` Rafael J. Wysocki
2016-07-20 7:23 ` Lukas Wunner
2016-07-20 12:48 ` 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=20160814102725.GA8634@wunner.de \
--to=lukas@wunner.de \
--cc=andreas.noever@gmail.com \
--cc=helgaas@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--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 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).