Retrieve MSI/MSIX cap struct for once on setup
cover Retrieve MSI/MSIX cap struct for once on setup
While we setup MSI or MSI-X for specific PCI device, the address of MSI or MSI-X capability structure is figured out from the config space for multiple times. That's unnecessary and the patchset addresses that. With the patchset applied, the latency for MSI or MSI-X setup would be decreased hopefully.
drivers/pci/msi.c | 51 ++++++++++++++++++++------------------ drivers/pci/pcie/portdrv_core.c | 2 +- include/linux/pci.h | 4 +- 3 files changed, 30 insertions(+), 27 deletions(-)
Thanks,
Gavin
PATCH 1/4 PCI: Cache MSI/MSIX structure in pci_msi_check_device()
The patch introduces additional parameter to pci_msi_check_device() to trace the address of MSI or MSI-X capability structure so that we needn't retrieve that again while enabling MSI or MSI-X based interrupts for specific PCI device.
--- drivers/pci/msi.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
drivers/pci/msi.c +9 -6
@@ -758,12 +758,14 @@ error:* @dev: pointer to the pci_dev data structure of MSI device function * @nvec: how many MSIs have been requested ? * @type: are we checking for MSI or MSI-X ? +* @pos: address of MSI or MSI-X capability structure * * Look at global flags, the device itself, and its parent busses * to determine if MSI/-X are supported for the device. If MSI/-X is * supported return 0, else return an error code. **/ -static int pci_msi_check_device (struct pci_dev *dev,int nvec,int type) +static int pci_msi_check_device (struct pci_dev *dev, +int nvec,int type,int *pos) {struct pci_bus *bus;int ret;
@@ -795,7 +797,8 @@ static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type)if (ret)return ret; -if (!pci_find_capability (dev, type)) + *pos =pci_find_capability (dev, type); +if (!*pos)return -EINVAL ;return 0 ;
@@ -816,7 +819,7 @@ static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type)*/ int pci_enable_msi_block (struct pci_dev *dev,unsigned int nvec) { -int status, pos, maxvec; +int pos, status, maxvec;u16 msgctl; pos =pci_find_capability (dev,PCI_CAP_ID_MSI );
@@ -827,7 +830,7 @@ int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec)if (nvec > maxvec)return maxvec; - status =pci_msi_check_device (dev, nvec,PCI_CAP_ID_MSI ); + status =pci_msi_check_device (dev, nvec,PCI_CAP_ID_MSI , &pos);if (status)return status;
@@ -945,13 +948,13 @@ int pci_msix_table_size(struct pci_dev *dev)**/ int pci_enable_msix (struct pci_dev *dev,struct msix_entry *entries,int nvec) { -int status, nr_entries; +int pos, status, nr_entries;int i, j;if (!entries)return -EINVAL ; - status =pci_msi_check_device (dev, nvec,PCI_CAP_ID_MSIX ); + status =pci_msi_check_device (dev, nvec,PCI_CAP_ID_MSIX , &pos);if (status)return status;
Signature · 1 line
1.7.5.4
PATCH 2/4 PCI: Allow pci_msix_table_size() take MSIX cap struct
In reply to Gavin ShanThe patch introduces additional parameter to pci_msix_table_size() to allow it take the address of MSI-X capability structure. If that's zero, we need figure out the address from PCI config space.
--- drivers/pci/msi.c | 9 +++++---- drivers/pci/pcie/portdrv_core.c | 2 +- include/linux/pci.h | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-)
drivers/pci/msi.c +5 -4
@@ -917,13 +917,14 @@ EXPORT_SYMBOL(pci_disable_msi);/** * pci_msix_table_size - return the number of device's MSI-X table entries * @dev: pointer to the pci_dev data structure of MSI-X device function +* @pos: address of MSI-X capability structure */ -int pci_msix_table_size (struct pci_dev *dev) +int pci_msix_table_size (struct pci_dev *dev,int pos) { -int pos;u16 control; - pos =pci_find_capability (dev,PCI_CAP_ID_MSIX ); +if (!pos) + pos =pci_find_capability (dev,PCI_CAP_ID_MSIX );if (!pos)return 0 ;
@@ -958,7 +959,7 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)if (status)return status; - nr_entries =pci_msix_table_size (dev); + nr_entries =pci_msix_table_size (dev, pos);if (nvec > nr_entries)return nr_entries;
drivers/pci/pcie/portdrv_core.c +1 -1
@@ -79,7 +79,7 @@ static int pcie_port_enable_msix(struct pci_dev *dev, int *vectors, int mask)u16 reg16;u32 reg32; - nr_entries =pci_msix_table_size (dev); + nr_entries =pci_msix_table_size (dev,0 );if (!nr_entries)return -EINVAL ;if (nr_entries >PCIE_PORT_MAX_MSIX_ENTRIES )
include/linux/pci.h +2 -2
@@ -1116,7 +1116,7 @@ static inline void pci_msi_shutdown(struct pci_dev *dev)static inline void pci_disable_msi (struct pci_dev *dev) { } -static inline int pci_msix_table_size (struct pci_dev *dev) +static inline int pci_msix_table_size (struct pci_dev *dev,int pos) {return 0 ; }
@@ -1145,7 +1145,7 @@ extern int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec);extern int pci_enable_msi_block_auto (struct pci_dev *dev,unsigned int *maxvec);extern void pci_msi_shutdown (struct pci_dev *dev);extern void pci_disable_msi (struct pci_dev *dev); -extern int pci_msix_table_size (struct pci_dev *dev); +extern int pci_msix_table_size (struct pci_dev *dev,int pos);extern int pci_enable_msix (struct pci_dev *dev,struct msix_entry *entries,int nvec);extern void pci_msix_shutdown (struct pci_dev *dev);
Signature · 1 line
1.7.5.4
PATCH 3/4 PCI: Allow msix_capability_init() take MSIX cap struct
In reply to Gavin ShanThe patch introduces additional parameter to msix_capability_init() so that we can pass the address of MSI-X capability structure to the function.
--- drivers/pci/msi.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/pci/msi.c +6 -4
@@ -674,19 +674,20 @@ static void msix_program_entries(struct pci_dev *dev,* @dev: pointer to the pci_dev data structure of MSI-X device function * @entries: pointer to an array of struct msix_entry entries * @nvec: number of @entries +* @pos: address of MSI-X capability structure * * Setup the MSI-X capability structure of device function with a * single MSI-X irq. A return of zero indicates the successful setup of * requested MSI-X entries with allocated irqs or non-zero for otherwise. **/ static int msix_capability_init (struct pci_dev *dev, -struct msix_entry *entries,int nvec) +struct msix_entry *entries, +int nvec,int pos) { -int pos, ret; +int ret;u16 control;void __iomem *base; - pos =pci_find_capability (dev,PCI_CAP_ID_MSIX );pci_read_config_word (dev, pos +PCI_MSIX_FLAGS , &control);/* Ensure MSI-X is disabled while it is set up */
@@ -980,7 +981,8 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec) "(MSI IRQ already assigned)\n");return -EINVAL ; } - status =msix_capability_init (dev, entries, nvec); + + status =msix_capability_init (dev, entries, nvec, pos);return status; }EXPORT_SYMBOL (pci_enable_msix);
Signature · 1 line
1.7.5.4
PATCH 4/4 PCI: Retrieve MSI cap struct for once on setup
In reply to Gavin ShanThe patch adjusts function msi_capability_init() and pci_enable_msi_block() so that we needn't figure out the address of MSI capability structure for multiple time in one function call path while enabling MSI.
--- drivers/pci/msi.c | 19 ++++++++----------- 1 files changed, 8 insertions(+), 11 deletions(-)
drivers/pci/msi.c +8 -11
@@ -542,6 +542,7 @@ out_unroll:* msi_capability_init - configure device's MSI capability structure * @dev: pointer to the pci_dev data structure of MSI device function * @nvec: number of interrupts to allocate +* @pos: address of MSI capability structure * * Setup the MSI capability structure of the device with the requested * number of interrupts. A return value of zero indicates the successful
@@ -549,14 +550,13 @@ out_unroll:* an error, and a positive return value indicates the number of interrupts * which could have been allocated. */ -static int msi_capability_init (struct pci_dev *dev,int nvec) +static int msi_capability_init (struct pci_dev *dev,int nvec,int pos) {struct msi_desc *entry; -int pos, ret; +int ret;u16 control;unsigned mask; - pos =pci_find_capability (dev,PCI_CAP_ID_MSI );msi_set_enable (dev, pos,0 );/* Disable MSI during set up */ pci_read_config_word (dev,msi_control_reg (pos), &control);
@@ -823,18 +823,15 @@ int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec)int pos, status, maxvec;u16 msgctl; - pos =pci_find_capability (dev,PCI_CAP_ID_MSI ); -if (!pos) -return -EINVAL ; + status =pci_msi_check_device (dev, nvec,PCI_CAP_ID_MSI , &pos); +if (status) +return status; +pci_read_config_word (dev, pos +PCI_MSI_FLAGS , &msgctl); maxvec =1 << ((msgctl &PCI_MSI_FLAGS_QMASK ) >>1 );if (nvec > maxvec)return maxvec; - status =pci_msi_check_device (dev, nvec,PCI_CAP_ID_MSI , &pos); -if (status) -return status; -WARN_ON (!!dev->msi_enabled);/* Check whether driver already requested MSI-X irqs */
@@ -844,7 +841,7 @@ int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec)return -EINVAL ; } - status =msi_capability_init (dev, nvec); + status =msi_capability_init (dev, nvec, pos);return status; }EXPORT_SYMBOL (pci_enable_msi_block);
Signature · 1 line
1.7.5.4
Bjorn Helgaas
maintainerQuoted 10 lines · Gavin Shan
While we setup MSI or MSI-X for specific PCI device, the address of MSI or MSI-X capability structure is figured out from the config space for multiple times. That's unnecessary and the patchset addresses that. With the patchset applied, the latency for MSI or MSI-X setup would be decreased hopefully.
drivers/pci/msi.c | 51 ++++++++++++++++++++------------------ drivers/pci/pcie/portdrv_core.c | 2 +- include/linux/pci.h | 4 +- 3 files changed, 30 insertions(+), 27 deletions(-)
It seems a bit complicated to be passing around "pos" or "&pos" all the time. Wouldn't it be simpler to cache the MSI and MSI-X capability addresses directly in the pci_dev, like we do for the PCIe and PM capabilities?
Bjorn