All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] PCI: hv: Do not set PCI_COMMAND_MEMORY to reduce VM boot time
@ 2022-05-02  7:42 Dexuan Cui
  2022-05-03 10:59 ` Wei Liu
  0 siblings, 1 reply; 2+ messages in thread
From: Dexuan Cui @ 2022-05-02  7:42 UTC (permalink / raw)
  To: wei.liu, kys, haiyangz, sthemmin, lorenzo.pieralisi, bhelgaas,
	linux-hyperv, linux-pci, linux-kernel, mikelley, robh, kw,
	helgaas, alex.williamson, boqun.feng, Boqun.Feng
  Cc: jakeo, Dexuan Cui

Currently when the pci-hyperv driver finishes probing and initializing the
PCI device, it sets the PCI_COMMAND_MEMORY bit; later when the PCI device
is registered to the core PCI subsystem, the core PCI driver's BAR detection
and initialization code toggles the bit multiple times, and each toggling of
the bit causes the hypervisor to unmap/map the virtual BARs from/to the
physical BARs, which can be slow if the BAR sizes are huge, e.g., a Linux VM
with 14 GPU devices has to spend more than 3 minutes on BAR detection and
initialization, causing a long boot time.

Reduce the boot time by not setting the PCI_COMMAND_MEMORY bit when we
register the PCI device (there is no need to have it set in the first place).
The bit stays off till the PCI device driver calls pci_enable_device().
With this change, the boot time of such a 14-GPU VM is reduced by almost
3 minutes.

Link: https://lore.kernel.org/lkml/20220419220007.26550-1-decui@microsoft.com/
Tested-by: Boqun Feng (Microsoft) <boqun.feng@gmail.com>
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Jake Oshins <jakeo@microsoft.com>

---

Changes in v2:
	Added Michael's Reviewed-by, Lorenzo's Acked-by, and a Link.
	Rewrote the commit message by following Lorenzo's suggestion.

	Thanks all for the informatie discussion!

@ Wei Liu: Lorenzo agrees that this patch can go via the Hyper-V tree's
hyperv-next branch (the patch should not go via the hyperv-fixes branch),
but in general we should keep the PCI folks in the review loop for PCI
hyper-V changes: https://lore.kernel.org/lkml/YmuzOJy%2F6F5wSjY7@lpieralisi/

 drivers/pci/controller/pci-hyperv.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
index d270a204324e..f9fbbd8d94db 100644
--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -2082,12 +2082,17 @@ static void prepopulate_bars(struct hv_pcibus_device *hbus)
 				}
 			}
 			if (high_size <= 1 && low_size <= 1) {
-				/* Set the memory enable bit. */
-				_hv_pcifront_read_config(hpdev, PCI_COMMAND, 2,
-							 &command);
-				command |= PCI_COMMAND_MEMORY;
-				_hv_pcifront_write_config(hpdev, PCI_COMMAND, 2,
-							  command);
+				/*
+				 * No need to set the PCI_COMMAND_MEMORY bit as
+				 * the core PCI driver doesn't require the bit
+				 * to be pre-set. Actually here we intentionally
+				 * keep the bit off so that the PCI BAR probing
+				 * in the core PCI driver doesn't cause Hyper-V
+				 * to unnecessarily unmap/map the virtual BARs
+				 * from/to the physical BARs multiple times.
+				 * This reduces the VM boot time significantly
+				 * if the BAR sizes are huge.
+				 */
 				break;
 			}
 		}
-- 
2.17.1


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

* Re: [PATCH v2] PCI: hv: Do not set PCI_COMMAND_MEMORY to reduce VM boot time
  2022-05-02  7:42 [PATCH v2] PCI: hv: Do not set PCI_COMMAND_MEMORY to reduce VM boot time Dexuan Cui
@ 2022-05-03 10:59 ` Wei Liu
  0 siblings, 0 replies; 2+ messages in thread
From: Wei Liu @ 2022-05-03 10:59 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: wei.liu, kys, haiyangz, sthemmin, lorenzo.pieralisi, bhelgaas,
	linux-hyperv, linux-pci, linux-kernel, mikelley, robh, kw,
	helgaas, alex.williamson, boqun.feng, Boqun.Feng, jakeo

On Mon, May 02, 2022 at 12:42:55AM -0700, Dexuan Cui wrote:
> Currently when the pci-hyperv driver finishes probing and initializing the
> PCI device, it sets the PCI_COMMAND_MEMORY bit; later when the PCI device
> is registered to the core PCI subsystem, the core PCI driver's BAR detection
> and initialization code toggles the bit multiple times, and each toggling of
> the bit causes the hypervisor to unmap/map the virtual BARs from/to the
> physical BARs, which can be slow if the BAR sizes are huge, e.g., a Linux VM
> with 14 GPU devices has to spend more than 3 minutes on BAR detection and
> initialization, causing a long boot time.
> 
> Reduce the boot time by not setting the PCI_COMMAND_MEMORY bit when we
> register the PCI device (there is no need to have it set in the first place).
> The bit stays off till the PCI device driver calls pci_enable_device().
> With this change, the boot time of such a 14-GPU VM is reduced by almost
> 3 minutes.
> 
> Link: https://lore.kernel.org/lkml/20220419220007.26550-1-decui@microsoft.com/
> Tested-by: Boqun Feng (Microsoft) <boqun.feng@gmail.com>
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> Reviewed-by: Michael Kelley <mikelley@microsoft.com>
> Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Jake Oshins <jakeo@microsoft.com>

Applied to hyperv-next. Thanks.

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

end of thread, other threads:[~2022-05-03 10:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-02  7:42 [PATCH v2] PCI: hv: Do not set PCI_COMMAND_MEMORY to reduce VM boot time Dexuan Cui
2022-05-03 10:59 ` Wei Liu

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.