Support using MSI interrupts in ntb_transport
Subsystems (5)
Logan Gunthorpe
maintainerv3 cover Support using MSI interrupts in ntb_transport
This is version 3 of the MSI interrupts for ntb_transport patchset.
I've addressed the feedback so far and rebased on the latest kernel and would like this to be considered for merging this cycle.
The only outstanding issue I know of is that it still will not work with IDT hardware, but ntb_transport doesn't work with IDT hardware and there is still no sensible common infrastructure to support ntb_peer_mw_set_trans(). Thus, I decline to consider that complication in this patchset. However, I'll be happy to review work that adds this feature in the future.
Also as the port number and resource index stuff is a bit complicated, I made a quick out of tree test fixture to ensure it's correct[1]. As an excerise I also wrote some test code[2] using the upcomming KUnit feature.
Logan
[1] https://repl.it/repls/ExcitingPresentFile
[2] https://github.com/sbates130272/linux-p2pmem/commits/ntb_kunit
--
Changes in v3:
* Rebased onto v5.1-rc1 (Dropped the first two patches as they have been merged, and cleaned up some minor conflicts in the PCI tree)
* Added a new patch (#3) to calculate logical port numbers that are port numbers from 0 to (number of ports - 1). This is then used in ntb_peer_resource_idx() to fix the issues brought up by Serge.
* Fixed missing __iomem and iowrite calls (as noticed by Serge)
* Added patch 10 which describes ntb_msi_test in the documentation file (as requested by Serge)
* A couple other minor nits and documentation fixes
--
Changes in v2:
* Cleaned up the changes in intel_irq_remapping.c to make them less confusing and add a comment. (Per discussion with Jacob and Joerg)
* Fixed a nit from Bjorn and collected his Ack
* Added a Kconfig dependancy on CONFIG_PCI_MSI for CONFIG_NTB_MSI as the Kbuild robot hit a random config that didn't build without it.
* Worked in a callback for when the MSI descriptor changes so that the clients can resend the new address and data values to the peer. On my test system this was never necessary, but there may be other platforms where this can occur. I tested this by hacking in a path to rewrite the MSI descriptor when I change the cpu affinity of an IRQ. There's a bit of uncertainty over the latency of the change, but without hardware this can acctually occur on we can't test this. This was the result of a discussion with Dave.
--
This patch series adds optional support for using MSI interrupts instead of NTB doorbells in ntb_transport. This is desirable seeing doorbells on current hardware are quite slow and therefore switching to MSI interrupts provides a significant performance gain. On switchtec hardware, a simple apples-to-apples comparison shows ntb_netdev/iperf numbers going from 3.88Gb/s to 14.1Gb/s when switching to MSI interrupts.
To do this, a couple changes are required outside of the NTB tree:
1) The IOMMU must know to accept MSI requests from aliased bused numbers seeing NTB hardware typically sends proxied request IDs through additional requester IDs. The first patch in this series adds support for the Intel IOMMU. A quirk to add these aliases for switchtec hardware was already accepted. See commit ad281ecf1c7d ("PCI: Add DMA alias quirk for Microsemi Switchtec NTB") for a description of NTB proxy IDs and why this is necessary.
2) NTB transport (and other clients) may often need more MSI interrupts than the NTB hardware actually advertises support for. However, seeing these interrupts will not be triggered by the hardware but through an NTB memory window, the hardware does not actually need support or need to know about them. Therefore we add the concept of Virtual MSI interrupts which are allocated just like any other MSI interrupt but are not programmed into the hardware's MSI table. This is done in Patch 2 and then made use of in Patch 3.
The remaining patches in this series add a library for dealing with MSI interrupts, a test client and finally support in ntb_transport.
The series is based off of v5.1-rc1 plus the patches in ntb-next. A git repo is available here:
https://github.com/sbates130272/linux-p2pmem/ ntb_transport_msi_v3
Thanks,
Logan
--
Logan Gunthorpe (10):
PCI/MSI: Support allocating virtual MSI interrupts PCI/switchtec: Add module parameter to request more interrupts
NTB: Introduce helper functions to calculate logical port number
NTB: Introduce functions to calculate multi-port resource index
NTB: Rename ntb.c to support multiple source files in the module
NTB: Introduce MSI library
NTB: Introduce NTB MSI Test Client
NTB: Add ntb_msi_test support to ntb_test
NTB: Add MSI interrupt support to ntb_transport
NTB: Describe the ntb_msi_test client in the documentation.
Documentation/ntb.txt | 27 ++
drivers/ntb/Kconfig | 11 +
drivers/ntb/Makefile | 3 +
drivers/ntb/{ntb.c => core.c} | 0
drivers/ntb/msi.c | 415 +++++++++++++++++++++++
drivers/ntb/ntb_transport.c | 169 ++++++++-
drivers/ntb/test/Kconfig | 9 +
drivers/ntb/test/Makefile | 1 +
drivers/ntb/test/ntb_msi_test.c | 433 ++++++++++++++++++++++++
drivers/pci/msi.c | 54 ++-
drivers/pci/switch/switchtec.c | 12 +-
include/linux/msi.h | 8 +
include/linux/ntb.h | 196 ++++++++++-
include/linux/pci.h | 9 +
tools/testing/selftests/ntb/ntb_test.sh | 54 ++-
15 files changed, 1386 insertions(+), 15 deletions(-)
rename drivers/ntb/{ntb.c => core.c} (100%)
create mode 100644 drivers/ntb/msi.c
create mode 100644 drivers/ntb/test/ntb_msi_test.c--
2.20.1
Logan Gunthorpe
maintainerPATCH v3 1/10 PCI/MSI: Support allocating virtual MSI interrupts
For NTB devices, we want to be able to trigger MSI interrupts through a memory window. In these cases we may want to use more interrupts than the NTB PCI device has available in its MSI-X table.
We allow for this by creating a new 'virtual' interrupt. These interrupts are allocated as usual but are not programmed into the MSI-X table (as there may not be space for them).
The MSI address and data will then handled through an NTB MSI library introduced later in this series.
--- drivers/pci/msi.c | 54 +++++++++++++++++++++++++++++++++++++-------- include/linux/msi.h | 8 +++++++ include/linux/pci.h | 9 ++++++++ 3 files changed, 62 insertions(+), 9 deletions(-)
drivers/pci/msi.c +45 -9
@@ -192,6 +192,9 @@ static void msi_mask_irq(struct msi_desc *desc, u32 mask, u32 flag)static void __iomem *pci_msix_desc_addr (struct msi_desc *desc) { +if (desc->msi_attrib.is_virtual) +return NULL ; +return desc->mask_base + desc->msi_attrib.entry_nr *PCI_MSIX_ENTRY_SIZE ; }
@@ -206,14 +209,19 @@ static void __iomem *pci_msix_desc_addr(struct msi_desc *desc)u32 __pci_msix_desc_mask_irq (struct msi_desc *desc,u32 flag) {u32 mask_bits = desc->masked; +void __iomem *desc_addr;if (pci_msi_ignore_mask)return 0 ; + desc_addr =pci_msix_desc_addr (desc); +if (!desc_addr) +return 0 ; mask_bits &= ~PCI_MSIX_ENTRY_CTRL_MASKBIT ;if (flag) mask_bits |=PCI_MSIX_ENTRY_CTRL_MASKBIT ; -writel (mask_bits,pci_msix_desc_addr (desc) +PCI_MSIX_ENTRY_VECTOR_CTRL ); + +writel (mask_bits, desc_addr +PCI_MSIX_ENTRY_VECTOR_CTRL );return mask_bits; }
@@ -273,6 +281,11 @@ void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg)if (entry->msi_attrib.is_msix) {void __iomem *base =pci_msix_desc_addr (entry); +if (!base) { +WARN_ON (1 ); +return ; + } + msg->address_lo =readl (base +PCI_MSIX_ENTRY_LOWER_ADDR ); msg->address_hi =readl (base +PCI_MSIX_ENTRY_UPPER_ADDR ); msg->data =readl (base +PCI_MSIX_ENTRY_DATA );
@@ -303,6 +316,9 @@ void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg) }else if (entry->msi_attrib.is_msix) {void __iomem *base =pci_msix_desc_addr (entry); +if (!base) + goto skip; +writel (msg->address_lo, base +PCI_MSIX_ENTRY_LOWER_ADDR );writel (msg->address_hi, base +PCI_MSIX_ENTRY_UPPER_ADDR );writel (msg->data, base +PCI_MSIX_ENTRY_DATA );
@@ -327,7 +343,13 @@ void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg) msg->data); } } + +skip: entry->msg = *msg; + +if (entry->write_msi_msg) + entry->write_msi_msg (entry, entry->write_msi_msg_data); + }void pci_write_msi_msg (unsigned int irq,struct msi_msg *msg)
@@ -550,6 +572,7 @@ msi_setup_entry(struct pci_dev *dev, int nvec, struct irq_affinity *affd) entry->msi_attrib.is_msix =0 ; entry->msi_attrib.is_64 = !!(control &PCI_MSI_FLAGS_64BIT ); + entry->msi_attrib.is_virtual =0 ; entry->msi_attrib.entry_nr =0 ; entry->msi_attrib.maskbit = !!(control &PCI_MSI_FLAGS_MASKBIT ); entry->msi_attrib.default_irq = dev->irq;/* Save IOAPIC IRQ */
@@ -674,6 +697,7 @@ static int msix_setup_entries(struct pci_dev *dev, void __iomem *base,struct irq_affinity_desc *curmsk, *masks =NULL ;struct msi_desc *entry;int ret, i; +int vec_count =pci_msix_vec_count (dev);if (affd) masks =irq_create_affinity_masks (nvec, affd);
@@ -696,6 +720,10 @@ static int msix_setup_entries(struct pci_dev *dev, void __iomem *base, entry->msi_attrib.entry_nr = entries[i].entry; else entry->msi_attrib.entry_nr = i; + + entry->msi_attrib.is_virtual = + entry->msi_attrib.entry_nr >= vec_count; + entry->msi_attrib.default_irq = dev->irq; entry->mask_base = base;
@@ -714,12 +742,19 @@ static void msix_program_entries(struct pci_dev *dev, {struct msi_desc *entry;int i =0 ; +void __iomem *desc_addr;for_each_pci_msi_entry (entry, dev) {if (entries) entries[i++].vector = entry->irq; - entry->masked =readl (pci_msix_desc_addr (entry) + -PCI_MSIX_ENTRY_VECTOR_CTRL ); + + desc_addr =pci_msix_desc_addr (entry); +if (desc_addr) + entry->masked =readl (desc_addr + +PCI_MSIX_ENTRY_VECTOR_CTRL ); +else + entry->masked =0 ; +msix_mask_irq (entry,1 ); } }
@@ -932,7 +967,7 @@ int pci_msix_vec_count(struct pci_dev *dev)EXPORT_SYMBOL (pci_msix_vec_count);static int __pci_enable_msix (struct pci_dev *dev,struct msix_entry *entries, -int nvec,struct irq_affinity *affd) +int nvec,struct irq_affinity *affd,int flags) {int nr_entries;int i, j;
@@ -943,7 +978,7 @@ static int __pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, nr_entries =pci_msix_vec_count (dev);if (nr_entries <0 )return nr_entries; -if (nvec > nr_entries) +if (nvec > nr_entries && !(flags &PCI_IRQ_VIRTUAL ))return nr_entries;if (entries) {
@@ -1079,7 +1114,8 @@ EXPORT_SYMBOL(pci_enable_msi);static int __pci_enable_msix_range (struct pci_dev *dev,struct msix_entry *entries,int minvec, -int maxvec,struct irq_affinity *affd) +int maxvec,struct irq_affinity *affd, +int flags) {int rc, nvec = maxvec;
@@ -1096,7 +1132,7 @@ static int __pci_enable_msix_range(struct pci_dev *dev,return -ENOSPC ; } - rc =__pci_enable_msix (dev, entries, nvec, affd); + rc =__pci_enable_msix (dev, entries, nvec, affd, flags);if (rc ==0 )return nvec;
@@ -1127,7 +1163,7 @@ static int __pci_enable_msix_range(struct pci_dev *dev,int pci_enable_msix_range (struct pci_dev *dev,struct msix_entry *entries,int minvec,int maxvec) { -return __pci_enable_msix_range (dev, entries, minvec, maxvec,NULL ); +return __pci_enable_msix_range (dev, entries, minvec, maxvec,NULL ,0 ); }EXPORT_SYMBOL (pci_enable_msix_range);
@@ -1167,7 +1203,7 @@ int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,if (flags &PCI_IRQ_MSIX ) { msix_vecs =__pci_enable_msix_range (dev,NULL , min_vecs, - max_vecs, affd); + max_vecs, affd, flags);if (msix_vecs >0 )return msix_vecs; }
include/linux/msi.h +8 -0
@@ -56,6 +56,10 @@ struct fsl_mc_msi_desc {* @msg: The last set MSI message cached for reuse * @affinity: Optional pointer to a cpu affinity mask for this descriptor * +* @write_msi_msg: Callback that may be called when the MSI message +* address or data changes +* @write_msi_msg_data: Data parameter for the callback. +* * @masked: [PCI MSI/X] Mask bits * @is_msix: [PCI MSI/X] True if MSI-X * @multiple: [PCI MSI/X] log2 num of messages allocated
@@ -78,6 +82,9 @@ struct msi_desc {struct msi_msg msg;struct irq_affinity_desc *affinity; +void (*write_msi_msg)(struct msi_desc *entry,void *data); +void *write_msi_msg_data; + union { /* PCI MSI/X specific data */ struct {
@@ -88,6 +95,7 @@ struct msi_desc { u8 multi_cap : 3; u8 maskbit : 1; u8 is_64 : 1; + u8 is_virtual : 1;u16 entry_nr;unsigned default_irq; } msi_attrib;
include/linux/pci.h +9 -0
@@ -1355,6 +1355,15 @@ int pci_set_vga_state(struct pci_dev *pdev, bool decode,#define PCI_IRQ_MSI (1 << 1)/* Allow MSI interrupts */ #define PCI_IRQ_MSIX (1 << 2)/* Allow MSI-X interrupts */ #define PCI_IRQ_AFFINITY (1 << 3)/* Auto-assign affinity */ + +/* +* Virtual interrupts allow for more interrupts to be allocated +* than the device has interrupts for. These are not programmed +* into the device's MSI-X table and must be handled by some +* other driver means. +*/ +#define PCI_IRQ_VIRTUAL (1 << 4) +#define PCI_IRQ_ALL_TYPES \ (PCI_IRQ_LEGACY | PCI_IRQ_MSI | PCI_IRQ_MSIX)
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v3 2/10 PCI/switchtec: Add module parameter to request more interrupts
In reply to Logan GunthorpeSeeing the we want to use more interrupts in the NTB MSI code we need to be able allocate more (sometimes virtual) interrupts in the switchtec driver. Therefore add a module parameter to request to allocate additional interrupts.
This puts virtually no limit on the number of MSI interrupts available to NTB clients.
--- drivers/pci/switch/switchtec.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/pci/switch/switchtec.c +10 -2
@@ -30,6 +30,10 @@ module_param(use_dma_mrpc, bool, 0644);MODULE_PARM_DESC (use_dma_mrpc,"Enable the use of the DMA MRPC feature" ); +static int nirqs =32 ; +module_param (nirqs, int,0644 ); +MODULE_PARM_DESC (nirqs,"number of interrupts to allocate (more may be useful for NTB applications)" ); +static dev_t switchtec_devt;static DEFINE_IDA (switchtec_minor_ida);
@@ -1247,8 +1251,12 @@ static int switchtec_init_isr(struct switchtec_dev *stdev)int dma_mrpc_irq;int rc; - nvecs =pci_alloc_irq_vectors (stdev->pdev,1 ,4 , -PCI_IRQ_MSIX |PCI_IRQ_MSI ); +if (nirqs <4 ) + nirqs =4 ; + + nvecs =pci_alloc_irq_vectors (stdev->pdev,1 , nirqs, +PCI_IRQ_MSIX |PCI_IRQ_MSI | +PCI_IRQ_VIRTUAL );if (nvecs <0 )return nvecs;
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v3 3/10 NTB: Introduce helper functions to calculate logical port number
In reply to Logan GunthorpeThis patch introduces the "Logical Port Number" which is similar to the "Port Number" in that it enumerates the ports in the system.
The original (or Physical) "Port Number" can be any number used by the hardware to uniquley identify a port in the system. The "Logical Port Number" enumerates all ports in the system from 0 to the number of ports minus one.
For example a system with 5 ports might have the following port numbers which would be enumareted thusly:
Port Number: 1 2 5 7 116 Logical Port Number: 0 1 2 3 4
The logical port number is useful when calculating which resources to use for which peers. So we thus define two helper functions:ntb_logical_port_number() and ntb_peer_logical_port_number() which provide the "Logical Port Number" for the local port and any peer respectively.
--- include/linux/ntb.h | 53 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-)
include/linux/ntb.h +52 -1
@@ -616,7 +616,6 @@ static inline int ntb_port_number(struct ntb_dev *ntb)return ntb->ops->port_number (ntb); } -/** * ntb_peer_port_count() - get the number of peer device ports * @ntb: NTB device context.
@@ -653,6 +652,58 @@ static inline int ntb_peer_port_number(struct ntb_dev *ntb, int pidx)return ntb->ops->peer_port_number (ntb, pidx); } +/** +* ntb_logical_port_number() - get the logical port number of the local port +* @ntb: NTB device context. +* +* The Logical Port Number is defined to be a unique number for each +* port starting from zero through to the number of ports minus one. +* This is in contrast to the Port Number where each port can be assigned +* any unqique physical number by the hardware. +* +* The logical port number is useful for calculating the resource indexes +* used by peers. +* +* Return: the logical port number or negative value indicating an error +*/ +static inline int ntb_logical_port_number (struct ntb_dev *ntb) +{ +int lport =ntb_port_number (ntb); +int pidx; + +if (lport <0 ) +return lport; + +for (pidx =0 ; pidx <ntb_peer_port_count (ntb); pidx++) +if (lport <=ntb_peer_port_number (ntb, pidx)) +return pidx; + +return pidx; +} + +/** +* ntb_peer_logical_port_number() - get the logical peer port by given index +* @ntb: NTB device context. +* @pidx: Peer port index. +* +* The Logical Port Number is defined to be a unique number for each +* port starting from zero through to the number of ports minus one. +* This is in contrast to the Port Number where each port can be assigned +* any unqique physical number by the hardware. +* +* The logical port number is useful for calculating the resource indexes +* used by peers. +* +* Return: the peer's logical port number or negative value indicating an error +*/ +static inline int ntb_peer_logical_port_number (struct ntb_dev *ntb,int pidx) +{ +if (ntb_peer_port_number (ntb, pidx) <ntb_port_number (ntb)) +return pidx; +else +return pidx +1 ; +} +/** * ntb_peer_port_idx() - get the peer device port index by given port number * @ntb: NTB device context.
Signature · 1 line
2.20.1
Re: [PATCH v3 03/10] NTB: Introduce helper functions to calculate logical port number
Quoted 5 lines · Logan Gunthorpe
This patch introduces the "Logical Port Number" which is similar to the "Port Number" in that it enumerates the ports in the system.
The original (or Physical) "Port Number" can be any number used by the hardware to uniquley identify a port in the system. The "Logical Port
s/uniquley/uniquely/
Quoted 5 lines
Number" enumerates all ports in the system from 0 to the number of ports minus one.
For example a system with 5 ports might have the following port numbers which would be enumareted thusly:
s/enumareted/enumerated/
Quoted 7 lines
+ *
ntb_logical_port_number()- get the logical port number of the local port
+ * @ntb: NTB device context.
+ *
+ * The Logical Port Number is defined to be a unique number for each
+ * port starting from zero through to the number of ports minus one.
+ * This is in contrast to the Port Number where each port can be assigned
+ * any unqique physical number by the hardware.
s/unqique/unique/
Quoted 8 lines
+ *
ntb_peer_logical_port_number()- get the logical peer port by given index
+ * @ntb: NTB device context.
+ * @pidx: Peer port index.
+ *
+ * The Logical Port Number is defined to be a unique number for each
+ * port starting from zero through to the number of ports minus one.
+ * This is in contrast to the Port Number where each port can be assigned
+ * any unqique physical number by the hardware.
s/unqique/unique/
Bjorn
Logan Gunthorpe
maintainerPATCH v3 4/10 NTB: Introduce functions to calculate multi-port resource index
In reply to Logan GunthorpeWhen using multi-ports each port uses resources (dbs, msgs, mws, etc) on every other port. Creating a mapping for these resources such that each port has a corresponding resource on every other port is a bit tricky.
Introduce the ntb_peer_resource_idx() function for this purpose. It returns the peer resource number that will correspond with the local peer index on the remote peer.
Also, introduce ntb_peer_highest_mw_idx() which will use ntb_peer_resource_idx() but return the MW index starting with the highest index and working down.
--- include/linux/ntb.h | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+)
include/linux/ntb.h +70 -0
@@ -1557,4 +1557,74 @@ static inline int ntb_peer_msg_write(struct ntb_dev *ntb, int pidx, int midx, return ntb->ops->peer_msg_write(ntb, pidx, midx, msg); } +/** +* ntb_peer_resource_idx() - get a resource index for a given peer idx +* @ntb: NTB device context. +* @pidx: Peer port index. +* +* When constructing a graph of peers, each remote peer must use a different +* resource index (mw, doorbell, etc) to communicate with each other +* peer. +* +* In a two peer system, this function should always return 0 such that +* resource 0 points to the remote peer on both ports. +* +* In a 5 peer system, this function will return the following matrix +* +* pidx \ port 0 1 2 3 4 +* 0 0 0 1 2 3 +* 1 0 1 1 2 3 +* 2 0 1 2 2 3 +* 3 0 1 2 3 3 +* +* For example, if this function is used to program peer's memory +* windows, port 0 will program MW 0 on all it's peers to point to itself. +* port 1 will program MW 0 in port 0 to point to itself and MW 1 on all +* other ports. etc. +* +* For the legacy two host case, ntb_port_number() and ntb_peer_port_number() +* both return zero and therefore this function will always return zero. +* So MW 0 on each host would be programmed to point to the other host. +* +* Return: the resource index to use for that peer. +*/ +static inline int ntb_peer_resource_idx (struct ntb_dev *ntb,int pidx) +{ +int local_port, peer_port; + +if (pidx >=ntb_peer_port_count (ntb)) +return -EINVAL ; + + local_port =ntb_logical_port_number (ntb); + peer_port =ntb_peer_logical_port_number (ntb, pidx); + +if (peer_port < local_port) +return local_port -1 ; +else +return local_port; +} + +/** +* ntb_peer_highest_mw_idx() - get a memory window index for a given peer idx +* using the highest index memory windows first +* +* @ntb: NTB device context. +* @pidx: Peer port index. +* +* Like ntb_peer_resource_idx(), except it returns indexes starting with +* last memory window index. +* +* Return: the resource index to use for that peer. +*/ +static inline int ntb_peer_highest_mw_idx (struct ntb_dev *ntb,int pidx) +{ +int ret; + + ret =ntb_peer_resource_idx (ntb, pidx); +if (ret <0 ) +return ret; + +return ntb_mw_count (ntb, pidx) - ret -1 ; +} +#endif
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v3 5/10 NTB: Rename ntb.c to support multiple source files in the module
In reply to Logan GunthorpeThe kbuild system does not support having multiple source files in a module if one of those source files has the same name as the module.
Therefore, we must rename ntb.c to core.c, while the module remains ntb.ko.
This is similar to the way the nvme modules are structured.
---
drivers/ntb/Makefile | 2 ++
drivers/ntb/{ntb.c => core.c} | 0
2 files changed, 2 insertions(+)
rename drivers/ntb/{ntb.c => core.c} (100%)drivers/ntb/Makefile +2 -0
@@ -1,2 +1,4 @@ obj-$(CONFIG_NTB) += ntb.o hw/ test/ obj-$(CONFIG_NTB_TRANSPORT) += ntb_transport.o + +ntb-y := core.o
drivers/ntb/core.c renamed from drivers/ntb/ntb.c +0 -0
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v3 6/10 NTB: Introduce MSI library
In reply to Logan GunthorpeThe NTB MSI library allows passing MSI interrupts across a memory window. This offers similar functionality to doorbells or messages except will often have much better latency and the client can potentially use significantly more remote interrupts than typical hardware provides for doorbells. (Which can be important in high-multiport setups.)
The library utilizes one memory window per peer and uses the highest index memory windows. Before any ntb_msi function may be used, the user must call ntb_msi_init(). It may then setup and tear down the memory windows when the link state changes using ntb_msi_setup_mws() and ntb_msi_clear_mws().
The peer which receives the interrupt must call ntb_msim_request_irq() to assign the interrupt handler (this function is functionally similar to devm_request_irq()) and the returned descriptor must be transferred to the peer which can use it to trigger the interrupt. The triggering peer, once having received the descriptor, can trigger the interrupt by calling ntb_msi_peer_trigger().
--- drivers/ntb/Kconfig | 11 ++ drivers/ntb/Makefile | 3 +- drivers/ntb/msi.c | 415 +++++++++++++++++++++++++++++++++++++++++++ include/linux/ntb.h | 73 ++++++++ 4 files changed, 501 insertions(+), 1 deletion(-) create mode 100644 drivers/ntb/msi.c
drivers/ntb/Kconfig +11 -0
@@ -12,6 +12,17 @@ menuconfig NTB if NTB +config NTB_MSI + bool "MSI Interrupt Support" + depends on PCI_MSI + help + Support using MSI interrupt forwarding instead of (or in addition to) + hardware doorbells. MSI interrupts typically offer lower latency + than doorbells and more MSI interrupts can be made available to + clients. However this requires an extra memory window and support + in the hardware driver for creating the MSI interrupts. + + If unsure, say N. source "drivers/ntb/hw/Kconfig" source "drivers/ntb/test/Kconfig"
drivers/ntb/Makefile +2 -1
@@ -1,4 +1,5 @@ obj-$(CONFIG_NTB) += ntb.o hw/ test/ obj-$(CONFIG_NTB_TRANSPORT) += ntb_transport.o -ntb-y := core.o +ntb-y := core.o +ntb-$(CONFIG_NTB_MSI) += msi.o
drivers/ntb/msi.c new file +415 -0
415 lines not on this page · raw message
include/linux/ntb.h +73 -0
92 lines not on this page · raw message
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v3 7/10 NTB: Introduce NTB MSI Test Client
In reply to Logan GunthorpeIntroduce a tool to test NTB MSI interrupts similar to the other NTB test tools. This tool creates a debugfs directory for each NTB device with the following files:
portirqX_occurrences
peerX/port
peerX/count
peerX/trigger
The 'port' file tells the user the local port number and the 'occurrences' files tell the number of local interrupts that have been received for each interrupt.
For each peer, the 'port' file and the 'count' file tell you the peer's port number and number of interrupts respectively. Writing the interrupt number to the 'trigger' file triggers the interrupt handler for the peer which should increment their corresponding 'occurrences' file. The 'ready' file indicates if a peer is ready, writing to this file blocks until it is ready.
The module parameter num_irqs can be used to set the number of local interrupts. By default this is 4. This is only limited by the number of unused MSI interrupts registered by the hardware (this will require support of the hardware driver) and there must be at least 2*num_irqs + 1 spads registers available.
--- drivers/ntb/test/Kconfig | 9 + drivers/ntb/test/Makefile | 1 + drivers/ntb/test/ntb_msi_test.c | 433 ++++++++++++++++++++++++++++++++ 3 files changed, 443 insertions(+) create mode 100644 drivers/ntb/test/ntb_msi_test.c
drivers/ntb/test/Kconfig +9 -0
@@ -25,3 +25,12 @@ config NTB_PERF to and from the window without additional software interaction. If unsure, say N. + +config NTB_MSI_TEST + tristate "NTB MSI Test Client" + depends on NTB_MSI + help + This tool demonstrates the use of the NTB MSI library to + send MSI interrupts between peers. + + If unsure, say N.
drivers/ntb/test/Makefile +1 -0
@@ -1,3 +1,4 @@ obj-$(CONFIG_NTB_PINGPONG) += ntb_pingpong.o obj-$(CONFIG_NTB_TOOL) += ntb_tool.o obj-$(CONFIG_NTB_PERF) += ntb_perf.o +obj-$(CONFIG_NTB_MSI_TEST) += ntb_msi_test.o
drivers/ntb/test/ntb_msi_test.c new file +433 -0
433 lines not on this page · raw message
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v3 8/10 NTB: Add ntb_msi_test support to ntb_test
In reply to Logan GunthorpeWhen the ntb_msi_test module is available, the test code will trigger each of the interrupts and ensure the corresponding occurrences files gets incremented.
--- tools/testing/selftests/ntb/ntb_test.sh | 54 ++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-)
tools/testing/selftests/ntb/ntb_test.sh +52 -2
@@ -87,10 +87,10 @@ set -e function _modprobe() { - modprobe "$@" + modprobe "$@" || return 1 if [[ "$REMOTE_HOST" != "" ]]; then - ssh "$REMOTE_HOST" modprobe "$@" + ssh "$REMOTE_HOST" modprobe "$@" || return 1 fi }
@@ -451,6 +451,30 @@ function pingpong_test() echo " Passed" } +function msi_test() +{ + LOC=$1 + REM=$2 + + write_file 1 $LOC/ready + + echo "Running MSI interrupt tests on: $(subdirname $LOC) / $(subdirname $REM)" + + CNT=$(read_file "$LOC/count") + for ((i = 0; i < $CNT; i++)); do + START=$(read_file $REM/../irq${i}_occurrences) + write_file $i $LOC/trigger + END=$(read_file $REM/../irq${i}_occurrences) + + if [[ $(($END - $START)) != 1 ]]; then + echo "MSI did not trigger the interrupt on the remote side!" >&2 + exit 1 + fi + done + + echo " Passed" +} + function perf_test() { USE_DMA=$1
@@ -529,6 +553,29 @@ function ntb_pingpong_tests() _modprobe -r ntb_pingpong } +function ntb_msi_tests() +{ + LOCAL_MSI="$DEBUGFS/ntb_msi_test/$LOCAL_DEV" + REMOTE_MSI="$REMOTE_HOST:$DEBUGFS/ntb_msi_test/$REMOTE_DEV" + + echo "Starting ntb_msi_test tests..." + + if ! _modprobe ntb_msi_test 2> /dev/null; then + echo " Not doing MSI tests seeing the module is not available." + return + fi + + port_test $LOCAL_MSI $REMOTE_MSI + + LOCAL_PEER="$LOCAL_MSI/peer$LOCAL_PIDX" + REMOTE_PEER="$REMOTE_MSI/peer$REMOTE_PIDX" + + msi_test $LOCAL_PEER $REMOTE_PEER + msi_test $REMOTE_PEER $LOCAL_PEER + + _modprobe -r ntb_msi_test +} + function ntb_perf_tests() { LOCAL_PERF="$DEBUGFS/ntb_perf/$LOCAL_DEV"
@@ -550,6 +597,7 @@ function cleanup() _modprobe -r ntb_perf 2> /dev/null _modprobe -r ntb_pingpong 2> /dev/null _modprobe -r ntb_transport 2> /dev/null + _modprobe -r ntb_msi_test 2> /dev/null set -e }
@@ -586,5 +634,7 @@ ntb_tool_tests echo ntb_pingpong_tests echo +ntb_msi_tests +echo ntb_perf_tests echo
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v3 9/10 NTB: Add MSI interrupt support to ntb_transport
In reply to Logan GunthorpeIntroduce the module parameter 'use_msi' which, when set uses MSI interrupts instead of doorbells for each queue pair (QP). T he parameter is only available if NTB MSI support is configured into the kernel. We also require there to be more than one memory window (MW) so that an extra one is available to forward the APIC region.
To use MSIs, we request one interrupt per QP and forward the MSI address and data to the peer using scratch pad registers (SPADS) above the MW spads. (If there are not enough SPADS the MSI interrupt will not be used.)
Once registered, we simply use ntb_msi_peer_trigger and the recieving ISR simply queues up the rxc_db_work for the queue.
This addition can significantly improve performance of ntb_transport. In a simple, untuned, apples-to-apples comparision using ntb_netdev and iperf with switchtec hardware, I see 3.88Gb/s without MSI interrupts and 14.1Gb/s which is a more than 3x improvement.
--- drivers/ntb/ntb_transport.c | 169 +++++++++++++++++++++++++++++++++++- 1 file changed, 168 insertions(+), 1 deletion(-)
drivers/ntb/ntb_transport.c +168 -1
@@ -93,6 +93,12 @@ static bool use_dma;module_param (use_dma, bool,0644 );MODULE_PARM_DESC (use_dma,"Use DMA engine to perform large data copy" ); +static bool use_msi; +#ifdef CONFIG_NTB_MSI +module_param (use_msi, bool,0644 ); +MODULE_PARM_DESC (use_msi,"Use MSI interrupts instead of doorbells" ); +#endif +static struct dentry *nt_debugfs_dir;/* Only two-ports NTB devices are supported */
@@ -188,6 +194,11 @@ struct ntb_transport_qp {u64 tx_err_no_buf;u64 tx_memcpy;u64 tx_async; + +bool use_msi; +int msi_irq; +struct ntb_msi_desc msi_desc; +struct ntb_msi_desc peer_msi_desc; };struct ntb_transport_mw {
@@ -221,6 +232,10 @@ struct ntb_transport_ctx {u64 qp_bitmap;u64 qp_bitmap_free; +bool use_msi; +unsigned int msi_spad_offset; +u64 msi_db_mask; +bool link_is_up;struct delayed_work link_work;struct work_struct link_cleanup;
@@ -667,6 +682,114 @@ static int ntb_transport_setup_qp_mw(struct ntb_transport_ctx *nt,return 0 ; } +static irqreturn_t ntb_transport_isr (int irq,void *dev) +{ +struct ntb_transport_qp *qp = dev; + +tasklet_schedule (&qp->rxc_db_work); + +return IRQ_HANDLED ; +} + +static void ntb_transport_setup_qp_peer_msi (struct ntb_transport_ctx *nt, +unsigned int qp_num) +{ +struct ntb_transport_qp *qp = &nt->qp_vec[qp_num]; +int spad = qp_num *2 + nt->msi_spad_offset; + +if (!nt->use_msi) +return ; + +if (spad >=ntb_spad_count (nt->ndev)) +return ; + + qp->peer_msi_desc.addr_offset = +ntb_peer_spad_read (qp->ndev,PIDX , spad); + qp->peer_msi_desc.data = +ntb_peer_spad_read (qp->ndev,PIDX , spad +1 ); + +dev_dbg (&qp->ndev->pdev->dev,"QP%d Peer MSI addr=%x data=%x\n" , + qp_num, qp->peer_msi_desc.addr_offset, qp->peer_msi_desc.data); + +if (qp->peer_msi_desc.addr_offset) { + qp->use_msi = true; +dev_info (&qp->ndev->pdev->dev, +"Using MSI interrupts for QP%d\n" , qp_num); + } +} + +static void ntb_transport_setup_qp_msi (struct ntb_transport_ctx *nt, +unsigned int qp_num) +{ +struct ntb_transport_qp *qp = &nt->qp_vec[qp_num]; +int spad = qp_num *2 + nt->msi_spad_offset; +int rc; + +if (!nt->use_msi) +return ; + +if (spad >=ntb_spad_count (nt->ndev)) { +dev_warn_once (&qp->ndev->pdev->dev, +"Not enough SPADS to use MSI interrupts\n" ); +return ; + } + +ntb_spad_write (qp->ndev, spad,0 ); +ntb_spad_write (qp->ndev, spad +1 ,0 ); + +if (!qp->msi_irq) { + qp->msi_irq =ntbm_msi_request_irq (qp->ndev, ntb_transport_isr, +KBUILD_MODNAME , qp, + &qp->msi_desc); +if (qp->msi_irq <0 ) { +dev_warn (&qp->ndev->pdev->dev, +"Unable to allocate MSI interrupt for qp%d\n" , + qp_num); +return ; + } + } + + rc =ntb_spad_write (qp->ndev, spad, qp->msi_desc.addr_offset); +if (rc) + goto err_free_interrupt; + + rc =ntb_spad_write (qp->ndev, spad +1 , qp->msi_desc.data); +if (rc) + goto err_free_interrupt; + +dev_dbg (&qp->ndev->pdev->dev,"QP%d MSI %d addr=%x data=%x\n" , + qp_num, qp->msi_irq, qp->msi_desc.addr_offset, + qp->msi_desc.data); + +return ; + +err_free_interrupt: +devm_free_irq (&nt->ndev->dev, qp->msi_irq, qp); +} + +static void ntb_transport_msi_peer_desc_changed (struct ntb_transport_ctx *nt) +{ +int i; + +dev_dbg (&nt->ndev->pdev->dev,"Peer MSI descriptors changed" ); + +for (i =0 ; i < nt->qp_count; i++) +ntb_transport_setup_qp_peer_msi (nt, i); +} + +static void ntb_transport_msi_desc_changed (void *data) +{ +struct ntb_transport_ctx *nt = data; +int i; + +dev_dbg (&nt->ndev->pdev->dev,"MSI descriptors changed" ); + +for (i =0 ; i < nt->qp_count; i++) +ntb_transport_setup_qp_msi (nt, i); + +ntb_peer_db_set (nt->ndev, nt->msi_db_mask); +} +static void ntb_free_mw (struct ntb_transport_ctx *nt,int num_mw) {struct ntb_transport_mw *mw = &nt->mw_vec[num_mw];
@@ -905,6 +1028,20 @@ static void ntb_transport_link_work(struct work_struct *work)int rc =0 , i, spad;/* send the local info, in the opposite order of the way we read it */ + +if (nt->use_msi) { + rc =ntb_msi_setup_mws (ndev); +if (rc) { +dev_warn (&pdev->dev, +"Failed to register MSI memory window: %d\n" , + rc); + nt->use_msi = false; + } + } + +for (i =0 ; i < nt->qp_count; i++) +ntb_transport_setup_qp_msi (nt, i); +for (i =0 ; i < nt->mw_count; i++) { size = nt->mw_vec[i].phys_size;
@@ -962,6 +1099,7 @@ static void ntb_transport_link_work(struct work_struct *work)struct ntb_transport_qp *qp = &nt->qp_vec[i];ntb_transport_setup_qp_mw (nt, i); +ntb_transport_setup_qp_peer_msi (nt, i);if (qp->client_ready)schedule_delayed_work (&qp->link_work,0 );
@@ -1135,6 +1273,19 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)return -ENOMEM ; nt->ndev = ndev; + +/* +* If we are using MSI, and have at least one extra memory window, +* we will reserve the last MW for the MSI window. +*/ +if (use_msi && mw_count >1 ) { + rc =ntb_msi_init (ndev, ntb_transport_msi_desc_changed); +if (!rc) { + mw_count -=1 ; + nt->use_msi = true; + } + } + spad_count =ntb_spad_count (ndev);/* Limit the MW's based on the availability of scratchpads */
@@ -1148,6 +1299,8 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev) max_mw_count_for_spads = (spad_count -MW0_SZ_HIGH ) /2 ; nt->mw_count =min (mw_count, max_mw_count_for_spads); + nt->msi_spad_offset = nt->mw_count *2 +MW0_SZ_HIGH ; + nt->mw_vec =kcalloc_node (mw_count,sizeof (*nt->mw_vec),GFP_KERNEL , node);if (!nt->mw_vec) {
@@ -1178,6 +1331,12 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev) qp_bitmap =ntb_db_valid_mask (ndev); qp_count =ilog2 (qp_bitmap); +if (nt->use_msi) { + qp_count -=1 ; + nt->msi_db_mask =1 << qp_count; +ntb_db_clear_mask (ndev, nt->msi_db_mask); + } +if (max_num_clients && max_num_clients < qp_count) qp_count = max_num_clients;else if (nt->mw_count < qp_count)
@@ -1601,7 +1760,10 @@ static void ntb_tx_copy_callback(void *data,iowrite32 (entry->flags |DESC_DONE_FLAG , &hdr->flags); -ntb_peer_db_set (qp->ndev,BIT_ULL (qp->qp_num)); +if (qp->use_msi) +ntb_msi_peer_trigger (qp->ndev,PIDX , &qp->peer_msi_desc); +else +ntb_peer_db_set (qp->ndev,BIT_ULL (qp->qp_num));/* The entry length can only be zero if the packet is intended to be a * "link down" or similar. Since no payload is being sent in these
@@ -2268,6 +2430,11 @@ static void ntb_transport_doorbell_callback(void *data, int vector)u64 db_bits;unsigned int qp_num; +if (ntb_db_read (nt->ndev) & nt->msi_db_mask) { +ntb_transport_msi_peer_desc_changed (nt); +ntb_db_clear (nt->ndev, nt->msi_db_mask); + } + db_bits = (nt->qp_bitmap & ~nt->qp_bitmap_free &ntb_db_vector_mask (nt->ndev, vector));
Signature · 1 line
2.20.1
Re: [PATCH v3 09/10] NTB: Add MSI interrupt support to ntb_transport
Hi Logan,
Drive-by nits:
Quoted 1 line · Logan Gunthorpe
Introduce the module parameter '
use_msi' which, when set uses
s/set/set,/
Quoted 2 lines
MSI interrupts instead of doorbells for each queue pair (QP). T he parameter is only available if NTB MSI support is configured into
Spurious newline in the middle of "The".
Quoted 6 lines
the kernel. We also require there to be more than one memory window (MW) so that an extra one is available to forward the APIC region.
To use MSIs, we request one interrupt per QP and forward the MSI address and data to the peer using scratch pad registers (SPADS) above the MW spads. (If there are not enough SPADS the MSI interrupt will not be used.)
/spads/SPADS/ for consistency
Quoted 1 line
Once registered, we simply use
ntb_msi_peer_triggerand the recieving
s/recieving/receiving/
Quoted 6 lines
ISR simply queues up the
rxc_db_workfor the queue.This addition can significantly improve performance of
ntb_transport. In a simple, untuned, apples-to-apples comparision usingntb_netdevand iperf with switchtec hardware, I see 3.88Gb/s without MSI interrupts and 14.1Gb/s which is a more than 3x improvement.
s/which is/with MSI, which is/
Bjorn
Logan Gunthorpe
maintainerRe: [PATCH v3 09/10] NTB: Add MSI interrupt support to ntb_transport
Quoted 3 lines · Bjorn Helgaas
Hi Logan,
Drive-by nits:
Thanks Bjorn! I've updated my patches for v4 which I'll send out in a week or two.
Logan
Logan Gunthorpe
maintainerPATCH v3 10/10 NTB: Describe the ntb_msi_test client in the documentation.
In reply to Logan GunthorpeAdd a blurb in Documentation/ntb.txt to describe the ntb_msi_test tool's debugfs interface. Similar to the (out of date) ntb_tool description.
--- Documentation/ntb.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
Documentation/ntb.txt +27 -0
@@ -194,6 +194,33 @@ Debugfs Files: This file is used to read and write peer scratchpads. See *spad* for details. +NTB MSI Test Client (ntb\_msi\_test) +------------------------------------ + +The MSI test client serves to test and debug the MSI library which +allows for passing MSI interrupts across NTB memory windows. The +test client is interacted with through the debugfs filesystem: + +* *debugfs*/ntb\_tool/*hw*/ + A directory in debugfs will be created for each + NTB device probed by the tool. This directory is shortened to *hw* + below. +* *hw*/port + This file describes the local port number +* *hw*/irq*_occurrences + One occurrences file exists for each interrupt and, when read, + returns the number of times the interrupt has been triggered. +* *hw*/peer*/port + This file describes the port number for each peer +* *hw*/peer*/count + This file describes the number of interrupts that can be + triggered on each peer +* *hw*/peer*/trigger + Writing an interrupt number (any number less than the value + specified in count) will trigger the interrupt on the + specified peer. That peer's interrupt's occurrence file + should be incremented. + NTB Hardware Drivers ====================
Signature · 1 line
2.20.1