Skip to contentSkip to conversation

AHCI: Optimize interrupt processing in multi-MSI mode

PATCH Superseded Alexander Gordeev 2 participants 12 messages Sep 25, 2014 – Sep 29, 2014

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover AHCI: Optimize interrupt processing in multi-MSI mode

Changes since v3:
- series rebased on libata/for-3.18;
- single IRQ interrupt update removed, along with patches 4,5 "AHCI: Get rid of redundant arg to ahci_handle_port_interrupt()" "AHCI: Optimize single IRQ interrupt processing" removed;
- multi-MSI updated to skip zero value port status;

Changes since v2:
- single patch split in a series;
- benchmarking statistics reworded;
- HOST_IRQ_STAT reg optimization added (patch 6);

Alexander Gordeev (4):
AHCI: Cleanup checking of multiple MSIs/SLM modes
AHCI: Move host activation code into ahci_host_activate()
AHCI: Make few function names more descriptive
AHCI: Do not read HOST_IRQ_STAT reg in multi-MSI mode

 drivers/ata/acard-ahci.c       |   3 +-
 drivers/ata/ahci.c             |  80 ++---------------------
 drivers/ata/ahci.h             |   7 +-
 drivers/ata/libahci.c          | 145 ++++++++++++++++++++++++++---------------
 drivers/ata/libahci_platform.c |   3 +-
 5 files changed, 102 insertions(+), 136 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v4 1/4 AHCI: Cleanup checking of multiple MSIs/SLM modes

Sharing Last Message (SLM) mode is currently checked in two
functions: ahci_host_activate() and ahci_init_interrupts(). This update consolidates SLM mode check with activation of multiple MSIs mode.

---
 drivers/ata/ahci.c | 18 +++++++-----------
 drivers/ata/ahci.h |  2 +-
 2 files changed, 8 insertions(+), 12 deletions(-)
drivers/ata/ahci.c +7 -11
index c880699..f68a995 100644
@@ -1211,6 +1211,9 @@ static int ahci_init_interrupts(struct pci_dev *pdev, unsigned int n_ports,
 		goto single_msi;
 	}
 
+	if (nvec > 1)
+		hpriv->flags |= AHCI_HFLAG_MULTI_MSI;
+
 	return nvec;
 
 single_msi:
@@ -1227,7 +1230,6 @@ intx:
  *	ahci_host_activate - start AHCI host, request IRQs and register it
  *	@host: target ATA host
  *	@irq: base IRQ number to request
- *	@n_msis: number of MSIs allocated for this host
  *	@irq_handler: irq_handler used when requesting IRQs
  *	@irq_flags: irq_flags used when requesting IRQs
  *
@@ -1241,14 +1243,10 @@ intx:
  *	RETURNS:
  *	0 on success, -errno otherwise.
  */
-int ahci_host_activate(struct ata_host *host, int irq, unsigned int n_msis)
+int ahci_host_activate(struct ata_host *host, int irq)
 {
 	int i, rc;
 
-	/* Sharing Last Message among several ports is not supported */
-	if (n_msis < host->n_ports)
-		return -EINVAL;
-
 	rc = ata_host_start(host);
 	if (rc)
 		return rc;
@@ -1296,7 +1294,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	struct device *dev = &pdev->dev;
 	struct ahci_host_priv *hpriv;
 	struct ata_host *host;
-	int n_ports, n_msis, i, rc;
+	int n_ports, i, rc;
 	int ahci_pci_bar = AHCI_PCI_BAR_STANDARD;
 
 	VPRINTK("ENTER\n");
@@ -1437,9 +1435,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	 */
 	n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
 
-	n_msis = ahci_init_interrupts(pdev, n_ports, hpriv);
-	if (n_msis > 1)
-		hpriv->flags |= AHCI_HFLAG_MULTI_MSI;
+	ahci_init_interrupts(pdev, n_ports, hpriv);
 
 	host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
 	if (!host)
@@ -1492,7 +1488,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	pci_set_master(pdev);
 
 	if (hpriv->flags & AHCI_HFLAG_MULTI_MSI)
-		return ahci_host_activate(host, pdev->irq, n_msis);
+		return ahci_host_activate(host, pdev->irq);
 
 	return ata_host_activate(host, pdev->irq, ahci_interrupt, IRQF_SHARED,
 				 &ahci_sht);
drivers/ata/ahci.h +1 -1
index 90156ff..a074c73 100644
@@ -392,7 +392,7 @@ irqreturn_t ahci_interrupt(int irq, void *dev_instance);
 irqreturn_t ahci_hw_interrupt(int irq, void *dev_instance);
 irqreturn_t ahci_thread_fn(int irq, void *dev_instance);
 void ahci_print_info(struct ata_host *host, const char *scc_s);
-int ahci_host_activate(struct ata_host *host, int irq, unsigned int n_msis);
+int ahci_host_activate(struct ata_host *host, int irq);
 void ahci_error_handler(struct ata_port *ap);
 
 static inline void __iomem *__ahci_port_base(struct ata_host *host,
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v4 2/4 AHCI: Move host activation code into ahci_host_activate()

In reply to Alexander Gordeev

Currently host activation done by calling either function ahci_host_activate() or ata_host_activate(). Consolidate the code by only calling ahci_host_activate() for all AHCI devices.

---
 drivers/ata/acard-ahci.c       |  3 +-
 drivers/ata/ahci.c             | 66 +--------------------------------
 drivers/ata/ahci.h             |  6 +--
 drivers/ata/libahci.c          | 84 +++++++++++++++++++++++++++++++++++++++---
 drivers/ata/libahci_platform.c |  3 +-
 5 files changed, 83 insertions(+), 79 deletions(-)
drivers/ata/acard-ahci.c +1 -2
index 25d0ac3..c962886 100644
@@ -498,8 +498,7 @@ static int acard_ahci_init_one(struct pci_dev *pdev, const struct pci_device_id
 	acard_ahci_pci_print_info(host);
 
 	pci_set_master(pdev);
-	return ata_host_activate(host, pdev->irq, ahci_interrupt, IRQF_SHARED,
-				 &acard_ahci_sht);
+	return ahci_host_activate(host, pdev->irq, &acard_ahci_sht);
 }
 
 module_pci_driver(acard_ahci_pci_driver);
drivers/ata/ahci.c +1 -65

78 lines not on this page · raw message

drivers/ata/ahci.h +2 -4
index a074c73..6a22055 100644
@@ -388,11 +388,9 @@ int ahci_port_resume(struct ata_port *ap);
 void ahci_set_em_messages(struct ahci_host_priv *hpriv,
 			  struct ata_port_info *pi);
 int ahci_reset_em(struct ata_host *host);
-irqreturn_t ahci_interrupt(int irq, void *dev_instance);
-irqreturn_t ahci_hw_interrupt(int irq, void *dev_instance);
-irqreturn_t ahci_thread_fn(int irq, void *dev_instance);
 void ahci_print_info(struct ata_host *host, const char *scc_s);
-int ahci_host_activate(struct ata_host *host, int irq);
+int ahci_host_activate(struct ata_host *host, int irq,
+		       struct scsi_host_template *sht);
 void ahci_error_handler(struct ata_port *ap);
 
 static inline void __iomem *__ahci_port_base(struct ata_host *host,
drivers/ata/libahci.c +78 -6

121 lines not on this page · raw message

drivers/ata/libahci_platform.c +1 -2
index c7f787e..0b03f90 100644
@@ -493,8 +493,7 @@ int ahci_platform_init_host(struct platform_device *pdev,
 	ahci_init_controller(host);
 	ahci_print_info(host, "platform");
 
-	return ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED,
-				 &ahci_platform_sht);
+	return ahci_host_activate(host, irq, &ahci_platform_sht);
 }
 EXPORT_SYMBOL_GPL(ahci_platform_init_host);
 
Signature · 1 line
1.8.3.1
#3 lore raw

Re: [PATCH v4 2/4] AHCI: Move host activation code into ahci_host_activate()

Quoted 49 lines · Alexander Gordeev
drivers/ata/ahci.c +0 -49
-/**
- *	ahci_host_activate - start AHCI host, request IRQs and register it
- *	@host: target ATA host
- *	@irq: base IRQ number to request
- *	@irq_handler: irq_handler used when requesting IRQs
- *	@irq_flags: irq_flags used when requesting IRQs
- *
- *	Similar to ata_host_activate, but requests IRQs according to AHCI-1.1
- *	when multiple MSIs were allocated. That is one MSI per port, starting
- *	from @irq.
- *
- *	LOCKING:
- *	Inherited from calling layer (may sleep).
- *
- *	RETURNS:
- *	0 on success, -errno otherwise.
- */
-int ahci_host_activate(struct ata_host *host, int irq)
-{
-	int i, rc;
-
-	rc = ata_host_start(host);
-	if (rc)
-		return rc;
-
-	for (i = 0; i < host->n_ports; i++) {
-		struct ahci_port_priv *pp = host->ports[i]->private_data;
-
-		/* Do not receive interrupts sent by dummy ports */
-		if (!pp) {
-			disable_irq(irq + i);
-			continue;
-		}
-
-		rc = devm_request_threaded_irq(host->dev, irq + i,
-					       ahci_hw_interrupt,
-					       ahci_thread_fn, IRQF_SHARED,
-					       pp->irq_desc, host->ports[i]);
-		if (rc)
-			goto out_free_irqs;
-	}
-
-	for (i = 0; i < host->n_ports; i++)
-		ata_port_desc(host->ports[i], "irq %d", irq + i);
-
-	rc = ata_host_register(host, &ahci_sht);
-	if (rc)
-		goto out_free_all_irqs;
-

drivers/ata/ahci.c intx: · line 1287

Quoted 10 lines
drivers/ata/ahci.c +0 -10
-	return 0;
-
-out_free_all_irqs:
-	i = host->n_ports;
-out_free_irqs:
-	for (i--; i >= 0; i--)
-		devm_free_irq(host->dev, irq + i, host->ports[i]);
-
-	return rc;
-}

It's generally a bad idea to mix code movement w/ other changes. I'm applying this one but please separate code movements to separate patches from now on.

Thanks.

Signature · 1 line
tejun
#4 lore raw

Re: [PATCH v4 2/4] AHCI: Move host activation code into ahci_host_activate()

Quoted 3 lines · Tejun Heo

It's generally a bad idea to mix code movement w/ other changes. I'm applying this one but please separate code movements to separate patches from now on.

This patch lacks the hunk below, which causes build error.

drivers/ata/sata_highbank.c +1 -2
@@ -568,8 +568,7 @@ static int ahci_highbank_probe(struct platform_device *pdev)
 	ahci_init_controller(host);
 	ahci_print_info(host, "platform");
 
-	rc = ata_host_activate(host, irq, ahci_interrupt, 0,
-					&ahci_highbank_platform_sht);
+	rc = ahci_host_activate(host, irq, &ahci_highbank_platform_sht);
 	if (rc)
 		goto err0;
 
Quoted 4 lines

Thanks.

Signature · 1 line
tejun
Signature · 3 lines
Regards,
Alexander Gordeev
[email protected]
#5 lore raw

PATCH 1/1 AHCI: Move host activation code into ahci_host_activate()

Currently host activation done by calling either function ahci_host_activate() or ata_host_activate(). Consolidate the code by only calling ahci_host_activate() for all AHCI devices.

---
 drivers/ata/acard-ahci.c       |  3 +-
 drivers/ata/ahci.c             | 66 +--------------------------------
 drivers/ata/ahci.h             |  6 +--
 drivers/ata/libahci.c          | 84 +++++++++++++++++++++++++++++++++++++++---
 drivers/ata/libahci_platform.c |  3 +-
 drivers/ata/sata_highbank.c    |  3 +-
 6 files changed, 84 insertions(+), 81 deletions(-)
drivers/ata/acard-ahci.c +1 -2
index 25d0ac3..c962886 100644
@@ -498,8 +498,7 @@ static int acard_ahci_init_one(struct pci_dev *pdev, const struct pci_device_id
 	acard_ahci_pci_print_info(host);
 
 	pci_set_master(pdev);
-	return ata_host_activate(host, pdev->irq, ahci_interrupt, IRQF_SHARED,
-				 &acard_ahci_sht);
+	return ahci_host_activate(host, pdev->irq, &acard_ahci_sht);
 }
 
 module_pci_driver(acard_ahci_pci_driver);
drivers/ata/ahci.c +1 -65

78 lines not on this page · raw message

drivers/ata/ahci.h +2 -4
index a074c73..6a22055 100644
@@ -388,11 +388,9 @@ int ahci_port_resume(struct ata_port *ap);
 void ahci_set_em_messages(struct ahci_host_priv *hpriv,
 			  struct ata_port_info *pi);
 int ahci_reset_em(struct ata_host *host);
-irqreturn_t ahci_interrupt(int irq, void *dev_instance);
-irqreturn_t ahci_hw_interrupt(int irq, void *dev_instance);
-irqreturn_t ahci_thread_fn(int irq, void *dev_instance);
 void ahci_print_info(struct ata_host *host, const char *scc_s);
-int ahci_host_activate(struct ata_host *host, int irq);
+int ahci_host_activate(struct ata_host *host, int irq,
+		       struct scsi_host_template *sht);
 void ahci_error_handler(struct ata_port *ap);
 
 static inline void __iomem *__ahci_port_base(struct ata_host *host,
drivers/ata/libahci.c +78 -6

121 lines not on this page · raw message

drivers/ata/libahci_platform.c +1 -2
index c7f787e..0b03f90 100644
@@ -493,8 +493,7 @@ int ahci_platform_init_host(struct platform_device *pdev,
 	ahci_init_controller(host);
 	ahci_print_info(host, "platform");
 
-	return ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED,
-				 &ahci_platform_sht);
+	return ahci_host_activate(host, irq, &ahci_platform_sht);
 }
 EXPORT_SYMBOL_GPL(ahci_platform_init_host);
 
drivers/ata/sata_highbank.c +1 -2
index da3bc27..ce2b99a 100644
@@ -568,8 +568,7 @@ static int ahci_highbank_probe(struct platform_device *pdev)
 	ahci_init_controller(host);
 	ahci_print_info(host, "platform");
 
-	rc = ata_host_activate(host, irq, ahci_interrupt, 0,
-					&ahci_highbank_platform_sht);
+	rc = ahci_host_activate(host, irq, &ahci_highbank_platform_sht);
 	if (rc)
 		goto err0;
 
Signature · 6 lines
1.8.3.1

-- 
Regards,
Alexander Gordeev
[email protected]
#6 lore raw

Re: [PATCH] AHCI: Move host activation code into ahci_host_activate()

Quoted 7 lines · Alexander Gordeev

Currently host activation done by calling either function ahci_host_activate() or ata_host_activate(). Consolidate the code by only calling ahci_host_activate() for all AHCI devices.

I reverted 2-3. Can you please respin the patches so that code movement is separate from other changes?

Thanks.

Signature · 1 line
tejun
#7 lore raw

PATCH v4 3/4 AHCI: Make few function names more descriptive

In reply to Alexander Gordeev
---
 drivers/ata/libahci.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/ata/libahci.c +8 -8
index 0080551..48175e5 100644
@@ -1789,7 +1789,7 @@ static void ahci_port_intr(struct ata_port *ap)
 	ahci_handle_port_interrupt(ap, port_mmio, status);
 }
 
-static irqreturn_t ahci_thread_fn(int irq, void *dev_instance)
+static irqreturn_t ahci_port_thread_fn(int irq, void *dev_instance)
 {
 	struct ata_port *ap = dev_instance;
 	struct ahci_port_priv *pp = ap->private_data;
@@ -1810,7 +1810,7 @@ static irqreturn_t ahci_thread_fn(int irq, void *dev_instance)
 	return IRQ_HANDLED;
 }
 
-static void ahci_hw_port_interrupt(struct ata_port *ap)
+static void ahci_update_intr_status(struct ata_port *ap)
 {
 	void __iomem *port_mmio = ahci_port_base(ap);
 	struct ahci_port_priv *pp = ap->private_data;
@@ -1822,7 +1822,7 @@ static void ahci_hw_port_interrupt(struct ata_port *ap)
 	pp->intr_status |= status;
 }
 
-static irqreturn_t ahci_hw_interrupt(int irq, void *dev_instance)
+static irqreturn_t ahci_multi_irqs_intr(int irq, void *dev_instance)
 {
 	struct ata_port *ap_this = dev_instance;
 	struct ahci_port_priv *pp = ap_this->private_data;
@@ -1858,7 +1858,7 @@ static irqreturn_t ahci_hw_interrupt(int irq, void *dev_instance)
 
 		ap = host->ports[i];
 		if (ap) {
-			ahci_hw_port_interrupt(ap);
+			ahci_update_intr_status(ap);
 			VPRINTK("port %u\n", i);
 		} else {
 			VPRINTK("port %u (no irq)\n", i);
@@ -1877,7 +1877,7 @@ static irqreturn_t ahci_hw_interrupt(int irq, void *dev_instance)
 	return IRQ_WAKE_THREAD;
 }
 
-static irqreturn_t ahci_interrupt(int irq, void *dev_instance)
+static irqreturn_t ahci_single_irq_intr(int irq, void *dev_instance)
 {
 	struct ata_host *host = dev_instance;
 	struct ahci_host_priv *hpriv;
@@ -2488,8 +2488,8 @@ static int ahci_host_activate_multi_irqs(struct ata_host *host, int irq,
 		}
 
 		rc = devm_request_threaded_irq(host->dev, irq + i,
-					       ahci_hw_interrupt,
-					       ahci_thread_fn, IRQF_SHARED,
+					       ahci_multi_irqs_intr,
+					       ahci_port_thread_fn, IRQF_SHARED,
 					       pp->irq_desc, host->ports[i]);
 		if (rc)
 			goto out_free_irqs;
@@ -2538,7 +2538,7 @@ int ahci_host_activate(struct ata_host *host, int irq,
 	if (hpriv->flags & AHCI_HFLAG_MULTI_MSI)
 		rc = ahci_host_activate_multi_irqs(host, irq, sht);
 	else
-		rc = ata_host_activate(host, irq, ahci_interrupt,
+		rc = ata_host_activate(host, irq, ahci_single_irq_intr,
 				       IRQF_SHARED, sht);
 	return rc;
 }
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH v4 4/4 AHCI: Do not read HOST_IRQ_STAT reg in multi-MSI mode

In reply to Alexander Gordeev

As described in AHCI v1.0 specification chapter 10.6.2.2 "Multiple MSI Based Messages" generation of interrupts is not controlled through the HOST_IRQ_STAT register.

Considering MMIO access is expensive remove unnecessary reading and writing of HOST_IRQ_STAT register.

Further, serializing access to the host data is no longer needed and the interrupt service routine can avoid competing on the host lock.

---
 drivers/ata/ahci.h    |  1 +
 drivers/ata/libahci.c | 59 +++++++++++----------------------------------------
 2 files changed, 13 insertions(+), 47 deletions(-)
drivers/ata/ahci.h +1 -0
index 6a22055..e5c6048 100644
@@ -305,6 +305,7 @@ struct ahci_port_priv {
 	unsigned int		ncq_saw_dmas:1;
 	unsigned int		ncq_saw_sdb:1;
 	u32			intr_status;	/* interrupts to handle */
+	spinlock_t		intr_lock;	/* protects intr_status */
 	spinlock_t		lock;		/* protects parent ata_port */
 	u32 			intr_mask;	/* interrupts to enable */
 	bool			fbs_supported;	/* set iff FBS is supported */
drivers/ata/libahci.c +12 -47

83 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#10 lore raw

Re: [PATCH v4 4/4] AHCI: Do not read HOST_IRQ_STAT reg in multi-MSI mode

Hello, Alexander.

drivers/ata/libahci.c static irqreturn_t ahci_port_thread_fn(int irq, void *dev_instance) · line 1804

Quoted 11 lines · Alexander Gordeev
drivers/ata/libahci.c +2 -2
@@ -1797,11 +1797,14 @@ static irqreturn_t ahci_port_thread_fn(int irq, void *dev_instance)
 	unsigned long flags;
 	u32 status;
 
-	spin_lock_irqsave(&ap->host->lock, flags);
+	spin_lock_irqsave(&pp->intr_lock, flags);
 	status = pp->intr_status;
 	if (status)
 		pp->intr_status = 0;
-	spin_unlock_irqrestore(&ap->host->lock, flags);
+	spin_unlock_irqrestore(&pp->intr_lock, flags);

atomic_xchg() prolly is a better option here.

Quoted 10 lines
drivers/ata/libahci.c +3 -0
+
+	if (!status)
+		return IRQ_NONE;
 
 	spin_lock_bh(ap->lock);
 	ahci_handle_port_interrupt(ap, port_mmio, status);
@@ -1824,53 +1827,14 @@ static void ahci_update_intr_status(struct ata_port *ap)
 
 static irqreturn_t ahci_multi_irqs_intr(int irq, void *dev_instance)
 {

...

drivers/ata/libahci.c static void ahci_update_intr_status(struct ata_port *ap) · line 1837

Quoted 3 lines
drivers/ata/libahci.c +3 -0
+	spin_lock(&pp->intr_lock);
+	ahci_update_intr_status(ap);
+	spin_unlock(&pp->intr_lock);

and atomic_or() in update_intr_status.

Thanks.

Signature · 1 line
tejun
#11 lore raw

PATCH 1/1 AHCI: Do not read HOST_IRQ_STAT reg in multi-MSI mode

As described in AHCI v1.0 specification chapter 10.6.2.2 "Multiple MSI Based Messages" generation of interrupts is not controlled through the HOST_IRQ_STAT register.

Considering MMIO access is expensive remove unnecessary reading and writing of HOST_IRQ_STAT register.

Further, serializing access to the host data is no longer needed and the interrupt service routine can avoid competing on the host lock.

---
 drivers/ata/ahci.h    |  2 +-
 drivers/ata/libahci.c | 67 ++++++---------------------------------------------
 2 files changed, 9 insertions(+), 60 deletions(-)
drivers/ata/ahci.h +1 -1
index 6a22055..40f0e34 100644
@@ -304,7 +304,7 @@ struct ahci_port_priv {
 	unsigned int		ncq_saw_d2h:1;
 	unsigned int		ncq_saw_dmas:1;
 	unsigned int		ncq_saw_sdb:1;
-	u32			intr_status;	/* interrupts to handle */
+	atomic_t		intr_status;	/* interrupts to handle */
 	spinlock_t		lock;		/* protects parent ata_port */
 	u32 			intr_mask;	/* interrupts to enable */
 	bool			fbs_supported;	/* set iff FBS is supported */
drivers/ata/libahci.c +8 -59

89 lines not on this page · raw message

Signature · 6 lines
1.8.3.1

-- 
Regards,
Alexander Gordeev
[email protected]