Skip to contentSkip to conversation

libata: optimize the ncq tag search

PATCH New Shaohua Li 1 participant 1 message Sep 2, 2009 libata

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/1 libata: optimize the ncq tag search

the bitop API should be a little faster than the loop.

---
 drivers/ata/libata-core.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/ata/libata-core.c +5 -1
Index: linux/drivers/ata/libata-core.c
===================================================================
@@ -4842,11 +4842,15 @@ static struct ata_queued_cmd *ata_qc_new
 		return NULL;
 
 	/* the last tag is reserved for internal command. */
-	for (i = 0; i < ATA_MAX_QUEUE - 1; i++)
+	while (1) {
+		i = find_first_zero_bit(&ap->qc_allocated, ATA_MAX_QUEUE - 1);
+		if (i >= ATA_MAX_QUEUE - 1)
+			break;
 		if (!test_and_set_bit(i, &ap->qc_allocated)) {
 			qc = __ata_qc_from_tag(ap, i);
 			break;
 		}
+	}
 
 	if (qc)
 		qc->tag = i;