Skip to contentSkip to conversation

sata_mv: Prevent PIO commands to be defered too long if traffic in progress.

PATCH Applied Gwendal Grignou 4 participants 6 messages Oct 12, 2009 – Oct 16, 2009 libata

lore
Share & tools
lore
#0 lore raw

cover sata_mv: Prevent PIO commands to be defered too long if traffic in progress.

Hello,

I found a bug in the sata_mv driver, that defers PIO commands indefinitely while there is a traffic on other ports of a sata port multiplier [PMP]:

without traffic:
time smartctl --all /dev/sdc > /dev/null
real 0m0.243s

with fio running and blasting read IOs on 5 drives behind the same port multiplier for 5 minutes:
real 4m59.353s

Obviously the PIO commands are defer while traffic is in progress.

With the patch following, smart_ctl return before fio complete. It still takes 4s, time for all NCQ commands to be flushed out.
real 0m4.074s

Gwendal.

#1 lore raw

PATCH 1/1 sata_mv: Prevent PIO commands to be defered too long if traffic in progress.

Use excl_link when non NCQ commands are defered, to be sure they are processed as soon as outstanding commands are completed. It prevents some commands to be defered indifinitely when using a port multiplier.

---
 drivers/ata/sata_mv.c |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)
drivers/ata/sata_mv.c +27 -2
index 17f9ff9..6f5093b 100644
@@ -1382,6 +1382,25 @@ static int mv_qc_defer(struct ata_queued_cmd *qc)
 	 */
 	if (pp->pp_flags & MV_PP_FLAG_DELAYED_EH)
 		return ATA_DEFER_PORT;
+
+	/* PIO commands need exclusive link: no other commands [DMA or PIO]
+	 * can run concurrently.
+	 * set excl_link when we want to send a PIO command in DMA mode
+	 * or a non-NCQ command in NCQ mode.
+	 * When we receive a command from that link, and there are no
+	 * outstanding commands, mark a flag to clear excl_link and let
+	 * the command go through.
+	 */
+	if (unlikely(ap->excl_link)) {
+		if (link == ap->excl_link) {
+			if (ap->nr_active_links)
+				return ATA_DEFER_PORT;
+			qc->flags |= ATA_QCFLAG_CLEAR_EXCL;
+			return 0;
+		} else
+			return ATA_DEFER_PORT;
+	}
+
 	/*
 	 * If the port is completely idle, then allow the new qc.
 	 */
@@ -1395,8 +1414,14 @@ static int mv_qc_defer(struct ata_queued_cmd *qc)
 	 * doesn't allow it.
 	 */
 	if ((pp->pp_flags & MV_PP_FLAG_EDMA_EN) &&
-	    (pp->pp_flags & MV_PP_FLAG_NCQ_EN) && ata_is_ncq(qc->tf.protocol))
-		return 0;
+	    (pp->pp_flags & MV_PP_FLAG_NCQ_EN)) {
+		if (ata_is_ncq(qc->tf.protocol))
+			return 0;
+		else {
+			ap->excl_link = link;
+			return ATA_DEFER_PORT;
+		}
+	}
 
 	return ATA_DEFER_PORT;
 }
Signature · 1 line
1.5.4.3
Reviewed-by on v1 1/1
#2 lore raw
Quoted 5 lines · Gwendal Grignou

Use excl_link when non NCQ commands are defered, to be sure they are processed as soon as outstanding commands are completed. It prevents some commands to be defered indifinitely when using a port multiplier.

thanks,
grant

Quoted 59 lines

---
 drivers/ata/sata_mv.c |   29 +++++++++++++++++++++++++++--

 1 files changed, 27 insertions(+), 2 deletions(-)
drivers/ata/sata_mv.c +19 -0
index 17f9ff9..6f5093b 100644
@@ -1382,6 +1382,25 @@ static int mv_qc_defer(struct ata_queued_cmd *qc)
         */
        if (pp->pp_flags & MV_PP_FLAG_DELAYED_EH)
                return ATA_DEFER_PORT;
+
+       /* PIO commands need exclusive link: no other commands [DMA or PIO]
+        * can run concurrently.
+        * set excl_link when we want to send a PIO command in DMA mode
+        * or a non-NCQ command in NCQ mode.
+        * When we receive a command from that link, and there are no
+        * outstanding commands, mark a flag to clear excl_link and let
+        * the command go through.
+        */
+       if (unlikely(ap->excl_link)) {
+               if (link == ap->excl_link) {
+                       if (ap->nr_active_links)
+                               return ATA_DEFER_PORT;
+                       qc->flags |= ATA_QCFLAG_CLEAR_EXCL;
+                       return 0;
+               } else
+                       return ATA_DEFER_PORT;
+       }
+
        /*
         * If the port is completely idle, then allow the new qc.
         */
@@ -1395,8 +1414,14 @@ static int mv_qc_defer(struct ata_queued_cmd *qc)
         * doesn't allow it.
         */

       if ((pp->pp_flags & MV_PP_FLAG_EDMA_EN) &&
-           (pp->pp_flags & MV_PP_FLAG_NCQ_EN) && ata_is_ncq(qc->tf.protocol))
-               return 0;
+           (pp->pp_flags & MV_PP_FLAG_NCQ_EN)) {
+               if (ata_is_ncq(qc->tf.protocol))
+                       return 0;
+               else {
+                       ap->excl_link = link;
+                       return ATA_DEFER_PORT;
+               }
+       }

       return ATA_DEFER_PORT;
 }
--
1.5.4.3

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

Reviewed-by on v1 1/1
#3 lore raw
In reply to Gwendal Grignou
Quoted 5 lines · Gwendal Grignou

Use excl_link when non NCQ commands are defered, to be sure they are processed as soon as outstanding commands are completed. It prevents some commands to be defered indifinitely when using a port multiplier.

..

Quoted 1 line

..

Looks good to me. Jeff, please feel free to accept sata_mv patches directly from Gwendal and/or Grant -- they know the chips as well as I do.

Cheers

Mark

#4 lore raw
In reply to Gwendal Grignou
Quoted 8 lines · Gwendal Grignou

Use excl_link when non NCQ commands are defered, to be sure they are processed as soon as outstanding commands are completed. It prevents some commands to be defered indifinitely when using a port multiplier.

---
  drivers/ata/sata_mv.c |   29 +++++++++++++++++++++++++++--
  1 files changed, 27 insertions(+), 2 deletions(-)

An ACK from Mark, too, I hope?

I'll give this a try on a Gen-IIE chip...

Jeff

Applied
#5 lore raw
In reply to Gwendal Grignou
Quoted 8 lines · Gwendal Grignou

Use excl_link when non NCQ commands are defered, to be sure they are processed as soon as outstanding commands are completed. It prevents some commands to be defered indifinitely when using a port multiplier.

---
  drivers/ata/sata_mv.c |   29 +++++++++++++++++++++++++++--
  1 files changed, 27 insertions(+), 2 deletions(-)

applied