Skip to contentSkip to conversation

Enable LTR/OBFF before device is used by driver

PATCH In review Xudong Hao 4 participants 5 messages May 14, 2012 – May 31, 2012

Subsystems (2)
lore
Share & tools
lore

Xudong Hao

author
#0 lore raw

PATCH 1/1 Enable LTR/OBFF before device is used by driver

Enable LTR(Latency tolerance reporting) and OBFF(optimized buffer flush/fill) in
pci_enable_device(), so that they are enabled before the device is used by driver.

---
 drivers/pci/pci.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
drivers/pci/pci.c +29 -0
index 111569c..2369883 100644
@@ -1134,6 +1134,31 @@ int pci_load_and_free_saved_state(struct pci_dev *dev,
 }
 EXPORT_SYMBOL_GPL(pci_load_and_free_saved_state);
 
+static void pci_enable_dev_caps(struct pci_dev *dev)
+{
+       /* set default value */
+       unsigned long type = PCI_EXP_OBFF_SIGNAL_ALWAYS;
+
+       /* LTR(Latency tolerance reporting) allows devices to send
+        * messages to the root complex indicating their latency
+        * tolerance for snooped & unsnooped memory transactions.
+        */
+       pci_enable_ltr(dev);
+
+       /* OBFF (optimized buffer flush/fill), where supported,
+        * can help improve energy efficiency by giving devices
+        * information about when interrupts and other activity
+        * will have a reduced power impact.
+        */
+       pci_enable_obff(dev, type);
+}
+
+static void pci_disable_dev_caps(struct pci_dev *dev)
+{
+       pci_disable_obff(dev);
+       pci_disable_ltr(dev);
+}
+
 static int do_pci_enable_device(struct pci_dev *dev, int bars)
 {
        int err;
@@ -1146,6 +1171,9 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars)
                return err;
        pci_fixup_device(pci_fixup_enable, dev);
 
+       /* Enable some device capibility before it's used by driver. */
+       pci_enable_dev_caps(dev);
+
        return 0;
 }
 
@@ -1361,6 +1389,7 @@ static void do_pci_disable_device(struct pci_dev *dev)
        }
 
        pcibios_disable_device(dev);
+       pci_disable_dev_caps(dev);
 }
 
 /**

--
1.6.0.rc1

maintainer
#1 lore raw
Quoted 2 lines · Xudong Hao

Enable LTR(Latency tolerance reporting) and OBFF(optimized buffer flush/fill) in pci_enable_device(), so that they are enabled before the device is used by driver.

Please split this into two patches (one for LTR and another for OBFF) so they can be reverted individually if they cause trouble. It would be nice if you bundled these together with your other "save/restore max Latency Value" patch so they were all together on the mailing list.

I read the LTR sections of the PCIe spec, but I can't figure out how it's supposed to work. It says "power management policies ... can be implemented to consider Endpoint service requirements." Does that mean there's some OS software that might be involved, or is this just a matter of software flipping the LTR-enable bit and the hardware doing everything else? How confident can we be that enabling this is safe?

For OBFF, is there some OS piece not included here that tells a Root Complex that "now is a good time for Endpoints to do something," e.g., the spec mentions an "operating system timer tick." Is there some benefit to this patch without that piece? I don't understand the big picture yet.

Quoted 11 lines

---
 drivers/pci/pci.c |   29 +++++++++++++++++++++++++++++

 1 files changed, 29 insertions(+), 0 deletions(-)
drivers/pci/pci.c +0 -0
index 111569c..2369883 100644

drivers/pci/pci.c int pci_load_and_free_saved_state(struct pci_dev *dev, · line 1140

Quoted 7 lines
drivers/pci/pci.c +4 -0
@@ -1134,6 +1134,31 @@ int pci_load_and_free_saved_state(struct pci_dev *dev,
  }
  EXPORT_SYMBOL_GPL(pci_load_and_free_saved_state);
 
+static void pci_enable_dev_caps(struct pci_dev *dev)
+{
+       /* set default value */
+       unsigned long type = PCI_EXP_OBFF_SIGNAL_ALWAYS;

There's only one use of this value, so skip the variable and just use PCI_EXP_OBFF_SIGNAL_ALWAYS in the call.

The comment at pci_enable_obff() says PCI_OBFF_SIGNAL_L0 is the preferred type, so please explain why you're not using that.

drivers/pci/pci.c int pci_load_and_free_saved_state(struct pci_dev *dev, · line 1145

Quoted 5 lines
drivers/pci/pci.c +5 -0
+
+       /* LTR(Latency tolerance reporting) allows devices to send
+        * messages to the root complex indicating their latency
+        * tolerance for snooped & unsnooped memory transactions.
+        */

Follow Linux comment style, i.e.,

    /*
     * LTR ...
     */
Quoted 20 lines
drivers/pci/pci.c +16 -0
+       pci_enable_ltr(dev);
+
+       /* OBFF (optimized buffer flush/fill), where supported,
+        * can help improve energy efficiency by giving devices
+        * information about when interrupts and other activity
+        * will have a reduced power impact.
+        */
+       pci_enable_obff(dev, type);
+}
+
+static void pci_disable_dev_caps(struct pci_dev *dev)
+{
+       pci_disable_obff(dev);
+       pci_disable_ltr(dev);
+}
+
  static int do_pci_enable_device(struct pci_dev *dev, int bars)
  {
        int err;

drivers/pci/pci.c static int do_pci_enable_device(struct pci_dev *dev, int bars) · line 1175

Quoted 5 lines
drivers/pci/pci.c +2 -0
@@ -1146,6 +1171,9 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars)
                return err;
        pci_fixup_device(pci_fixup_enable, dev);
 
+       /* Enable some device capibility before it's used by driver. */
+       pci_enable_dev_caps(dev);

Why is this here? It seems similar to what's already in pci_init_capabilities(). Is there a reason to do this in the pci_enable_device() path rather than in the pci_device_add() path?

Quoted 15 lines
drivers/pci/pci.c +2 -1
+
        return 0;
  }
 
@@ -1361,6 +1389,7 @@ static void do_pci_disable_device(struct pci_dev *dev)
        }
 
        pcibios_disable_device(dev);
+       pci_disable_dev_caps(dev);
  }
 
  /**
--

1.6.0.rc1

#2 lore raw
Quoted 11 lines

-----Original Message-----
From: Bjorn Helgaas [mailto:[email protected]]
Sent: Saturday, May 19, 2012 9:20 AM
To: Xudong Hao
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zhang, Xiantao; Hao, Xudong
Subject: Re: [PATCH 1/1] Enable LTR/OBFF before device is used by driver

On Sun, May 13, 2012 at 8:48 PM, Xudong Hao <[email protected]> wrote:

Quoted 7 lines
Quoted 1 line

Enable LTR(Latency tolerance reporting) and OBFF(optimized buffer flush/fill)

in

Quoted 1 line

 pci_enable_device(), so that they are enabled before the device is used by

driver.

Please split this into two patches (one for LTR and another for OBFF) so they can be reverted individually if they cause trouble.

OK.

Quoted 5 lines

It would
be nice if you bundled these together with your other "save/restore max Latency Value" patch so they were all together on the mailing list.

Sure, I'll modify the save/restore patch and bundle them together.

Quoted 8 lines

I read the LTR sections of the PCIe spec, but I can't figure out how it's supposed to work. It says "power management policies ... can be implemented to consider Endpoint service requirements." Does that mean there's some OS software that might be involved, or is this just a matter of software flipping the LTR-enable bit and the hardware doing everything else? How confident can we be that enabling this is safe?

Software only set the LTR-enable bit, then hardware/chipset/device do everything else. There are one thing that software can be involved: software can configure maximum latency tolerance.

Quoted 6 lines

For OBFF, is there some OS piece not included here that tells a Root Complex that "now is a good time for Endpoints to do something," e.g., the spec mentions an "operating system timer tick." Is there some benefit to this patch without that piece? I don't understand the big picture yet.

As like LTR, OBFF do not need OS do additional changes, just set obff-enable bit.

Quoted 15 lines

drivers/pci/pci.c int pci_load_and_free_saved_state(struct

Quoted 11 lines

---
 drivers/pci/pci.c |   29 +++++++++++++++++++++++++++++

 1 files changed, 29 insertions(+), 0 deletions(-)
drivers/pci/pci.c +0 -0
index 111569c..2369883 100644
@@ -1134,6 +1134,31 @@ int pci_load_and_free_saved_state(struct

pci_dev *dev,

Quoted 3 lines
drivers/pci/pci.c +0 -0
  }
  EXPORT_SYMBOL_GPL(pci_load_and_free_saved_state);
 
Quoted 8 lines

drivers/pci/pci.c int pci_load_and_free_saved_state(struct pci_dev *dev, · line 1140

Quoted 4 lines
drivers/pci/pci.c +4 -0
+static void pci_enable_dev_caps(struct pci_dev *dev)
+{
+       /* set default value */
+       unsigned long type = PCI_EXP_OBFF_SIGNAL_ALWAYS;

There's only one use of this value, so skip the variable and just use PCI_EXP_OBFF_SIGNAL_ALWAYS in the call.

Ok.

Quoted 3 lines

The comment at pci_enable_obff() says PCI_OBFF_SIGNAL_L0 is the preferred type, so please explain why you're not using that.

Yes, here it's better to set PCI_OBFF_SIGNAL_L0 by default.

Quoted 6 lines

drivers/pci/pci.c int pci_load_and_free_saved_state(struct pci_dev *dev, · line 1145

Quoted 5 lines
drivers/pci/pci.c +5 -0
+
+       /* LTR(Latency tolerance reporting) allows devices to send
+        * messages to the root complex indicating their latency
+        * tolerance for snooped & unsnooped memory transactions.
+        */
Quoted 6 lines

Follow Linux comment style, i.e.,

    /*
     * LTR ...
     */

Will modify, Thanks.

Quoted 24 lines

drivers/pci/pci.c static int do_pci_enable_device(struct pci_dev

Quoted 20 lines
drivers/pci/pci.c +16 -0
+       pci_enable_ltr(dev);
+
+       /* OBFF (optimized buffer flush/fill), where supported,
+        * can help improve energy efficiency by giving devices
+        * information about when interrupts and other activity
+        * will have a reduced power impact.
+        */
+       pci_enable_obff(dev, type);
+}
+
+static void pci_disable_dev_caps(struct pci_dev *dev)
+{
+       pci_disable_obff(dev);
+       pci_disable_ltr(dev);
+}
+
  static int do_pci_enable_device(struct pci_dev *dev, int bars)
  {
        int err;
@@ -1146,6 +1171,9 @@ static int do_pci_enable_device(struct pci_dev

*dev, int bars)

Quoted 3 lines
drivers/pci/pci.c +0 -0
                return err;
        pci_fixup_device(pci_fixup_enable, dev);
 
Quoted 7 lines

drivers/pci/pci.c static int do_pci_enable_device(struct pci_dev *dev, int bars) · line 1175

Quoted 2 lines
drivers/pci/pci.c +2 -0
+       /* Enable some device capibility before it's used by driver. */
+       pci_enable_dev_caps(dev);

Why is this here? It seems similar to what's already in pci_init_capabilities(). Is there a reason to do this in the pci_enable_device() path rather than in the pci_device_add() path?

pci_enable_device is called by any pci driver including kvm driver, Considering such a case in kvm, when device is assigned to guest(the device will be reset), we want not host lose those advanced PM feature, so add it in pci_enable_device so that kvm driver call it.

Quoted 16 lines

drivers/pci/pci.c static void do_pci_disable_device(struct pci_dev

Quoted 5 lines
drivers/pci/pci.c +1 -0
+
        return 0;
  }
 
@@ -1361,6 +1389,7 @@ static void do_pci_disable_device(struct pci_dev

*dev)

Quoted 10 lines
drivers/pci/pci.c +1 -1
        }
 
        pcibios_disable_device(dev);
+       pci_disable_dev_caps(dev);
  }
 
  /**
--

1.6.0.rc1

#3 lore raw
In reply to Xudong Hao

While you are making the other recommended fixes, could
you add/create a pci_obff_supported() function, like the pci_ltr_supported() function, and more importantly, add it to the pci_disable_obff() function? The latter does not check that DEVCAP2 is supported, and thus, could be writing to non-existent (potentially private) cap space (i.e., a V1 CAP device, which do exist in the marketplace).

The [enable,disable]_ltr functions do a good job of doing pci_ltr_supported() checks, but the obff enable,disable functions should have similar calls.

Quoted 70 lines · Xudong Hao

Enable LTR(Latency tolerance reporting) and OBFF(optimized buffer flush/fill) in
pci_enable_device(), so that they are enabled before the device is used by driver.

---
  drivers/pci/pci.c |   29 +++++++++++++++++++++++++++++
  1 files changed, 29 insertions(+), 0 deletions(-)
drivers/pci/pci.c +29 -1
index 111569c..2369883 100644
@@ -1134,6 +1134,31 @@ int pci_load_and_free_saved_state(struct pci_dev *dev,
  }
  EXPORT_SYMBOL_GPL(pci_load_and_free_saved_state);
 
+static void pci_enable_dev_caps(struct pci_dev *dev)
+{
+       /* set default value */
+       unsigned long type = PCI_EXP_OBFF_SIGNAL_ALWAYS;
+
+       /* LTR(Latency tolerance reporting) allows devices to send
+        * messages to the root complex indicating their latency
+        * tolerance for snooped&  unsnooped memory transactions.
+        */
+       pci_enable_ltr(dev);
+
+       /* OBFF (optimized buffer flush/fill), where supported,
+        * can help improve energy efficiency by giving devices
+        * information about when interrupts and other activity
+        * will have a reduced power impact.
+        */
+       pci_enable_obff(dev, type);
+}
+
+static void pci_disable_dev_caps(struct pci_dev *dev)
+{
+       pci_disable_obff(dev);
+       pci_disable_ltr(dev);
+}
+
  static int do_pci_enable_device(struct pci_dev *dev, int bars)
  {
         int err;
@@ -1146,6 +1171,9 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars)
                 return err;
         pci_fixup_device(pci_fixup_enable, dev);
 
+       /* Enable some device capibility before it's used by driver. */
+       pci_enable_dev_caps(dev);
+
         return 0;
  }
 
@@ -1361,6 +1389,7 @@ static void do_pci_disable_device(struct pci_dev *dev)
         }
 
         pcibios_disable_device(dev);
+       pci_disable_dev_caps(dev);
  }
 
  /**
--

1.6.0.rc1

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 16 lines

-----Original Message-----
From: Don Dutile [mailto:[email protected]]
Sent: Thursday, May 31, 2012 12:13 AM
To: Xudong Hao
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zhang, Xiantao; Hao, Xudong
Subject: Re: [PATCH 1/1] Enable LTR/OBFF before device is used by driver

While you are making the other recommended fixes, could
you add/create a pci_obff_supported() function, like the pci_ltr_supported() function, and more importantly, add it to the pci_disable_obff() function? The latter does not check that DEVCAP2 is supported, and thus, could be writing to non-existent (potentially private) cap space (i.e., a V1 CAP device, which do exist in the marketplace).

Quoted 3 lines

The [enable,disable]_ltr functions do a good job of doing pci_ltr_supported() checks, but the obff enable,disable functions should have similar calls.

Yeah, it's a good suggestion, I'll add pci_obff_supported() function.

Quoted 77 lines · Xudong Hao
Quoted 1 line

Enable LTR(Latency tolerance reporting) and OBFF(optimized buffer flush/fill)

in

Quoted 1 line

pci_enable_device(), so that they are enabled before the device is used by

driver.

drivers/pci/pci.c int pci_load_and_free_saved_state(struct

Quoted 12 lines
---
  drivers/pci/pci.c |   29 +++++++++++++++++++++++++++++
  1 files changed, 29 insertions(+), 0 deletions(-)
drivers/pci/pci.c +0 -0
index 111569c..2369883 100644
@@ -1134,6 +1134,31 @@ int pci_load_and_free_saved_state(struct

pci_dev *dev,

drivers/pci/pci.c static int do_pci_enable_device(struct pci_dev

Quoted 32 lines
drivers/pci/pci.c +25 -0
  }
  EXPORT_SYMBOL_GPL(pci_load_and_free_saved_state);
 
+static void pci_enable_dev_caps(struct pci_dev *dev)
+{
+       /* set default value */
+       unsigned long type = PCI_EXP_OBFF_SIGNAL_ALWAYS;
+
+       /* LTR(Latency tolerance reporting) allows devices to send
+        * messages to the root complex indicating their latency
+        * tolerance for snooped&  unsnooped memory transactions.
+        */
+       pci_enable_ltr(dev);
+
+       /* OBFF (optimized buffer flush/fill), where supported,
+        * can help improve energy efficiency by giving devices
+        * information about when interrupts and other activity
+        * will have a reduced power impact.
+        */
+       pci_enable_obff(dev, type);
+}
+
+static void pci_disable_dev_caps(struct pci_dev *dev)
+{
+       pci_disable_obff(dev);
+       pci_disable_ltr(dev);
+}
+
  static int do_pci_enable_device(struct pci_dev *dev, int bars)
  {
         int err;
@@ -1146,6 +1171,9 @@ static int do_pci_enable_device(struct pci_dev

*dev, int bars)

drivers/pci/pci.c static void do_pci_disable_device(struct pci_dev

Quoted 10 lines
drivers/pci/pci.c +3 -0
                 return err;
         pci_fixup_device(pci_fixup_enable, dev);
 
+       /* Enable some device capibility before it's used by driver. */
+       pci_enable_dev_caps(dev);
+
         return 0;
  }
 
@@ -1361,6 +1389,7 @@ static void do_pci_disable_device(struct pci_dev

*dev)

Quoted 14 lines
drivers/pci/pci.c +1 -1
         }
 
         pcibios_disable_device(dev);
+       pci_disable_dev_caps(dev);
  }
 
  /**
--

1.6.0.rc1

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html