public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ASPM: Use msleep instead of cpu_relax during link retraining
@ 2009-01-05 23:07 Andrew Patterson
  2009-01-06  0:54 ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Patterson @ 2009-01-05 23:07 UTC (permalink / raw)
  To: linux-kernel, linux-pci; +Cc: andrew.patterson, matthew, akpm, shaohua.li

ASPM: Use msleep instead of cpu_relax during link retraining

The cpu_relax() function can be a noop on certain architectures
like IA-64 when CPU threads are disabled, so use msleep instead
during link retraining busy/wait loop.

Introduce define LINK_RETRAIN_TIMEOUT instead of hard-coding
timeout in pcie_aspm_configure_common_clock.

Use time_after() to avoid jiffy wraparound when checking for expired
timeout.

After timeout expires, recheck link status register link training bit
instead of checking for expired timeout to avoid possible false positive.

Note that Matthew Wilcox came up with the first rough version of
this patch.

Signed-off-by: Andrew Patterson <andrew.patterson@hp.com>
---

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index 4d8e2c7..e67eaa2 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -17,6 +17,7 @@
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/jiffies.h>
+#include <linux/delay.h>
 #include <linux/pci-aspm.h>
 #include "../pci.h"
 
@@ -75,6 +76,8 @@ static const char *policy_str[] = {
 	[POLICY_POWERSAVE] = "powersave"
 };
 
+#define LINK_RETRAIN_TIMEOUT HZ
+
 static int policy_to_aspm_state(struct pci_dev *pdev)
 {
 	struct pcie_link_state *link_state = pdev->link_state;
@@ -238,16 +241,19 @@ static void pcie_aspm_configure_common_clock(struct pci_dev *pdev)
 	pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
 
 	/* Wait for link training end */
-	/* break out after waiting for 1 second */
+	/* break out after waiting for timeout */
 	start_jiffies = jiffies;
-	while ((jiffies - start_jiffies) < HZ) {
+	for (;;) {
 		pci_read_config_word(pdev, pos + PCI_EXP_LNKSTA, &reg16);
 		if (!(reg16 & PCI_EXP_LNKSTA_LT))
 			break;
-		cpu_relax();
+		if (time_after(start_jiffies,
+			       start_jiffies + LINK_RETRAIN_TIMEOUT))
+			break;
+		msleep(1);
 	}
 	/* training failed -> recover */
-	if ((jiffies - start_jiffies) >= HZ) {
+	if (reg16 & PCI_EXP_LNKSTA_LT) {
 		dev_printk (KERN_ERR, &pdev->dev, "ASPM: Could not configure"
 			    " common clock\n");
 		i = 0;


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] ASPM: Use msleep instead of cpu_relax during link retraining
  2009-01-05 23:07 [PATCH v2] ASPM: Use msleep instead of cpu_relax during link retraining Andrew Patterson
@ 2009-01-06  0:54 ` Joe Perches
  2009-01-06  0:55   ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2009-01-06  0:54 UTC (permalink / raw)
  To: Andrew Patterson; +Cc: linux-kernel, linux-pci, matthew, akpm, shaohua.li

On Mon, 2009-01-05 at 16:07 -0700, Andrew Patterson wrote:
> ASPM: Use msleep instead of cpu_relax during link retraining
> Signed-off-by: Andrew Patterson <andrew.patterson@hp.com>
> diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
> index 4d8e2c7..e67eaa2 100644
> --- a/drivers/pci/pcie/aspm.c
> +++ b/drivers/pci/pcie/aspm.c
[]
> @@ -238,16 +241,19 @@ static void pcie_aspm_configure_common_clock(struct pci_dev *pdev)
>  	pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
>  
>  	/* Wait for link training end */
> -	/* break out after waiting for 1 second */
> +	/* break out after waiting for timeout */
>  	start_jiffies = jiffies;
> -	while ((jiffies - start_jiffies) < HZ) {
> +	for (;;) {
>  		pci_read_config_word(pdev, pos + PCI_EXP_LNKSTA, &reg16);
>  		if (!(reg16 & PCI_EXP_LNKSTA_LT))
>  			break;
> -		cpu_relax();
> +		if (time_after(start_jiffies,
> +			       start_jiffies + LINK_RETRAIN_TIMEOUT))
> +			break;
> +		msleep(1);
>  	}

if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT))



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] ASPM: Use msleep instead of cpu_relax during link retraining
  2009-01-06  0:54 ` Joe Perches
@ 2009-01-06  0:55   ` Joe Perches
  0 siblings, 0 replies; 3+ messages in thread
From: Joe Perches @ 2009-01-06  0:55 UTC (permalink / raw)
  To: Andrew Patterson; +Cc: linux-kernel, linux-pci, matthew, akpm, shaohua.li

I didn't notice you already sent v3.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-01-06  0:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-05 23:07 [PATCH v2] ASPM: Use msleep instead of cpu_relax during link retraining Andrew Patterson
2009-01-06  0:54 ` Joe Perches
2009-01-06  0:55   ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox