From: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
To: rdh@east.sun.com
Cc: Jesse Barnes <jbarnes@virtuousgeek.org>,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH] pci/pcie: Avoid unnecessary PCIe link retrains
Date: Thu, 05 Nov 2009 10:38:10 +0900 [thread overview]
Message-ID: <4AF22C82.2040105@jp.fujitsu.com> (raw)
In-Reply-To: <20091104110321.5e58e112@jbarnes-piketon>
Jesse Barnes wrote:
> [Cc'ing linux-pci@vger.kernel.org too]
>
> On Tue, 3 Nov 2009 16:38:20 -0500
> RDH <rdh@east.sun.com> wrote:
>
>> This patch avoids unnecessary PCIe link retraining sequences within
>> the PCIe ASPM common clock setup code by issuing a link retrain
>> command only if we are actually changing the PCIe clock configuration.
>>
>> Signed-off-by: Robert D. Houk <rdh@East.Sun.COM>
>> ---
>> aspm.c | 20 ++++++++++++++++++++
>> 1 file changed, 20 insertions(+)
>> --- a/drivers/pci/pcie/aspm.c 2009-10-15 20:41:50.000000000
>> -0400 +++ b/drivers/pci/pcie/aspm.c 2009-11-02
>> 14:29:35.000000000 -0500 @@ -183,6 +183,7 @@ static void
>> pcie_aspm_configure_common_c {
>> int ppos, cpos, same_clock = 1;
>> u16 reg16, parent_reg, child_reg[8];
>> + u16 lnkctl_ccc_or, lnkctl_ccc_and;
>> unsigned long start_jiffies;
>> struct pci_dev *child, *parent = link->pdev;
>> struct pci_bus *linkbus = parent->subordinate;
>> @@ -205,6 +206,25 @@ static void pcie_aspm_configure_common_c
>> if (!(reg16 & PCI_EXP_LNKSTA_SLC))
>> same_clock = 0;
>>
>> + /* Check upstream component for Common Clock Config */
>> + pci_read_config_word(parent, ppos + PCI_EXP_LNKCTL, ®16);
>> + lnkctl_ccc_and = lnkctl_ccc_or = (reg16 &
>> PCI_EXP_LNKCTL_CCC); +
>> + /* Scan downstream component for CCC, all functions */
>> + list_for_each_entry(child, &linkbus->devices, bus_list) {
>> + cpos = pci_find_capability(child, PCI_CAP_ID_EXP);
>> + pci_read_config_word(child, cpos + PCI_EXP_LNKCTL,
>> ®16);
>> + lnkctl_ccc_and &= (reg16 & PCI_EXP_LNKCTL_CCC);
>> + lnkctl_ccc_or |= (reg16 & PCI_EXP_LNKCTL_CCC);
>> + }
>> +
>> + /* If we want Common Clock OFF and no device/function has it
>> on */
>> + /* or we want Common Clock ON and every device/function has
>> it on */
>> + /* then there is no need to retrain PCIe links */
>> + if (((same_clock == 0) && (lnkctl_ccc_or == 0))
>> + || ((same_clock == 1) && (lnkctl_ccc_and ==
>> PCI_EXP_LNKCTL_CCC)))
>> + return; /* Don't retrain link(s) */
>> +
>> /* Configure downstream component, all functions */
>> list_for_each_entry(child, &linkbus->devices, bus_list) {
>> cpos = pci_find_capability(child, PCI_CAP_ID_EXP);
>>
>
> Seems ok to me, anyone have comments?
>
Hi Robert,
How about like below? IMHO, it is easier to understand.
(Please note that I don't test it yet)
Thanks,
Kenji Kaneshige
---
drivers/pci/pcie/aspm.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
Index: 20091026/drivers/pci/pcie/aspm.c
===================================================================
--- 20091026.orig/drivers/pci/pcie/aspm.c
+++ 20091026/drivers/pci/pcie/aspm.c
@@ -186,6 +186,7 @@ static void pcie_aspm_configure_common_c
unsigned long start_jiffies;
struct pci_dev *child, *parent = link->pdev;
struct pci_bus *linkbus = parent->subordinate;
+ bool ccc_updated = false;
/*
* All functions of a slot should have the same Slot Clock
* Configuration, so just check one function
@@ -214,7 +215,10 @@ static void pcie_aspm_configure_common_c
reg16 |= PCI_EXP_LNKCTL_CCC;
else
reg16 &= ~PCI_EXP_LNKCTL_CCC;
+ if (reg16 == child_reg[PCI_FUNC(child->devfn)])
+ continue;
pci_write_config_word(child, cpos + PCI_EXP_LNKCTL, reg16);
+ ccc_updated = true;
}
/* Configure upstream component */
@@ -224,7 +228,14 @@ static void pcie_aspm_configure_common_c
reg16 |= PCI_EXP_LNKCTL_CCC;
else
reg16 &= ~PCI_EXP_LNKCTL_CCC;
- pci_write_config_word(parent, ppos + PCI_EXP_LNKCTL, reg16);
+ if (reg16 != parent_reg) {
+ pci_write_config_word(parent, ppos + PCI_EXP_LNKCTL, reg16);
+ ccc_updated = true;
+ }
+
+ /* Don't need to retrain link if there is no change in CCC */
+ if (!ccc_updated)
+ return;
/* Retrain link */
reg16 |= PCI_EXP_LNKCTL_RL;
prev parent reply other threads:[~2009-11-05 1:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-03 21:38 [PATCH] pci/pcie: Avoid unnecessary PCIe link retrains RDH
2009-11-04 19:03 ` Jesse Barnes
2009-11-04 23:28 ` Bjorn Helgaas
2009-11-05 3:05 ` Kenji Kaneshige
2009-11-05 18:59 ` Bjorn Helgaas
2009-11-05 19:07 ` Matthew Wilcox
2009-11-05 20:29 ` Bjorn Helgaas
2009-11-06 1:15 ` Kenji Kaneshige
2009-11-05 19:11 ` Matthew Wilcox
2009-11-06 2:48 ` Kenji Kaneshige
2009-11-06 22:00 ` Jesse Barnes
2009-11-05 1:38 ` Kenji Kaneshige [this message]
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=4AF22C82.2040105@jp.fujitsu.com \
--to=kaneshige.kenji@jp.fujitsu.com \
--cc=jbarnes@virtuousgeek.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=rdh@east.sun.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 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.