Skip to contentSkip to conversation

scsi_debug: Simplify request tag decoding

PATCH Applied Bart Van Assche 3 participants 3 messages Jan 26, 2018 – Feb 7, 2018 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi_debug: Simplify request tag decoding

Since commit 64d513ac31bd ("scsi: use host wide tags by default") all SCSI requests have a tag, whether or not scsi-mq is enabled. Additionally, it is safe to use blk_mq_unique_tag() and blk_mq_unique_tag_to_hwq() for legacy SCSI queues. Since this means that the sdebug_mq_active variable is superfluous, remove it.

Cc Douglas Gilbert <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
---
 drivers/scsi/scsi_debug.c | 37 +++++++++++--------------------------
 1 file changed, 11 insertions(+), 26 deletions(-)
drivers/scsi/scsi_debug.c +11 -26
index a5986dae9020..7d2ce0cc915a 100644
@@ -649,7 +649,6 @@ static bool sdebug_any_injecting_opt;
 static bool sdebug_verbose;
 static bool have_dif_prot;
 static bool sdebug_statistics = DEF_STATISTICS;
-static bool sdebug_mq_active;
 
 static unsigned int sdebug_store_sectors;
 static sector_t sdebug_capacity;	/* in sectors */
@@ -3727,20 +3726,13 @@ static int resp_xdwriteread_10(struct scsi_cmnd *scp,
 
 static struct sdebug_queue *get_queue(struct scsi_cmnd *cmnd)
 {
-	struct sdebug_queue *sqp = sdebug_q_arr;
+	u32 tag = blk_mq_unique_tag(cmnd->request);
+	u16 hwq = blk_mq_unique_tag_to_hwq(tag);
 
-	if (sdebug_mq_active) {
-		u32 tag = blk_mq_unique_tag(cmnd->request);
-		u16 hwq = blk_mq_unique_tag_to_hwq(tag);
-
-		if (unlikely(hwq >= submit_queues)) {
-			pr_warn("Unexpected hwq=%d, apply modulo\n", hwq);
-			hwq %= submit_queues;
-		}
-		pr_debug("tag=%u, hwq=%d\n", tag, hwq);
-		return sqp + hwq;
-	} else
-		return sqp;
+	pr_debug("tag=%#x, hwq=%d\n", tag, hwq);
+	if (WARN_ON_ONCE(hwq >= submit_queues))
+		hwq = 0;
+	return sdebug_q_arr + hwq;
 }
 
 /* Queued (deferred) command completions converge here. */
@@ -4587,9 +4579,8 @@ static int scsi_debug_show_info(struct seq_file *m, struct Scsi_Host *host)
 		   num_host_resets);
 	seq_printf(m, "dix_reads=%d, dix_writes=%d, dif_errors=%d\n",
 		   dix_reads, dix_writes, dif_errors);
-	seq_printf(m, "usec_in_jiffy=%lu, %s=%d, mq_active=%d\n",
-		   TICK_NSEC / 1000, "statistics", sdebug_statistics,
-		   sdebug_mq_active);
+	seq_printf(m, "usec_in_jiffy=%lu, statistics=%d\n", TICK_NSEC / 1000,
+		   sdebug_statistics);
 	seq_printf(m, "cmnd_count=%d, completions=%d, %s=%d, a_tsf=%d\n",
 		   atomic_read(&sdebug_cmnd_count),
 		   atomic_read(&sdebug_completions),
@@ -5612,13 +5603,8 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost,
 				n += scnprintf(b + n, sb - n, "%02x ",
 					       (u32)cmd[k]);
 		}
-		if (sdebug_mq_active)
-			sdev_printk(KERN_INFO, sdp, "%s: tag=%u, cmd %s\n",
-				    my_name, blk_mq_unique_tag(scp->request),
-				    b);
-		else
-			sdev_printk(KERN_INFO, sdp, "%s: cmd %s\n", my_name,
-				    b);
+		sdev_printk(KERN_INFO, sdp, "%s: tag=%#x, cmd %s\n", my_name,
+			    blk_mq_unique_tag(scp->request), b);
 	}
 	if (fake_host_busy(scp))
 		return SCSI_MLQUEUE_HOST_BUSY;
@@ -5782,8 +5768,7 @@ static int sdebug_driver_probe(struct device * dev)
 	}
 	/* Decide whether to tell scsi subsystem that we want mq */
 	/* Following should give the same answer for each host */
-	sdebug_mq_active = shost_use_blk_mq(hpnt) && (submit_queues > 1);
-	if (sdebug_mq_active)
+	if (shost_use_blk_mq(hpnt))
 		hpnt->nr_hw_queues = submit_queues;
 
 	sdbg_host->shost = hpnt;
Signature · 1 line
2.16.0
#1 lore raw
Quoted 8 lines · Bart Van Assche

Since commit 64d513ac31bd ("scsi: use host wide tags by default") all SCSI requests have a tag, whether or not scsi-mq is enabled. Additionally, it is safe to use blk_mq_unique_tag() and blk_mq_unique_tag_to_hwq() for legacy SCSI queues. Since this means that the sdebug_mq_active variable is superfluous, remove it.

Ack-ed by Douglas Gilbert <[email protected]>

Quoted 84 lines
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
---
  drivers/scsi/scsi_debug.c | 37 +++++++++++--------------------------
  1 file changed, 11 insertions(+), 26 deletions(-)
drivers/scsi/scsi_debug.c +11 -26
index a5986dae9020..7d2ce0cc915a 100644
@@ -649,7 +649,6 @@ static bool sdebug_any_injecting_opt;
  static bool sdebug_verbose;
  static bool have_dif_prot;
  static bool sdebug_statistics = DEF_STATISTICS;
-static bool sdebug_mq_active;
 
  static unsigned int sdebug_store_sectors;
  static sector_t sdebug_capacity;	/* in sectors */
@@ -3727,20 +3726,13 @@ static int resp_xdwriteread_10(struct scsi_cmnd *scp,
 
  static struct sdebug_queue *get_queue(struct scsi_cmnd *cmnd)
  {
-	struct sdebug_queue *sqp = sdebug_q_arr;
+	u32 tag = blk_mq_unique_tag(cmnd->request);
+	u16 hwq = blk_mq_unique_tag_to_hwq(tag);
 
-	if (sdebug_mq_active) {
-		u32 tag = blk_mq_unique_tag(cmnd->request);
-		u16 hwq = blk_mq_unique_tag_to_hwq(tag);
-
-		if (unlikely(hwq >= submit_queues)) {
-			pr_warn("Unexpected hwq=%d, apply modulo\n", hwq);
-			hwq %= submit_queues;
-		}
-		pr_debug("tag=%u, hwq=%d\n", tag, hwq);
-		return sqp + hwq;
-	} else
-		return sqp;
+	pr_debug("tag=%#x, hwq=%d\n", tag, hwq);
+	if (WARN_ON_ONCE(hwq >= submit_queues))
+		hwq = 0;
+	return sdebug_q_arr + hwq;
  }
 
  /* Queued (deferred) command completions converge here. */
@@ -4587,9 +4579,8 @@ static int scsi_debug_show_info(struct seq_file *m, struct Scsi_Host *host)
  		   num_host_resets);
  	seq_printf(m, "dix_reads=%d, dix_writes=%d, dif_errors=%d\n",
  		   dix_reads, dix_writes, dif_errors);
-	seq_printf(m, "usec_in_jiffy=%lu, %s=%d, mq_active=%d\n",
-		   TICK_NSEC / 1000, "statistics", sdebug_statistics,
-		   sdebug_mq_active);
+	seq_printf(m, "usec_in_jiffy=%lu, statistics=%d\n", TICK_NSEC / 1000,
+		   sdebug_statistics);
  	seq_printf(m, "cmnd_count=%d, completions=%d, %s=%d, a_tsf=%d\n",
  		   atomic_read(&sdebug_cmnd_count),
  		   atomic_read(&sdebug_completions),
@@ -5612,13 +5603,8 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost,
  				n += scnprintf(b + n, sb - n, "%02x ",
  					       (u32)cmd[k]);
  		}
-		if (sdebug_mq_active)
-			sdev_printk(KERN_INFO, sdp, "%s: tag=%u, cmd %s\n",
-				    my_name, blk_mq_unique_tag(scp->request),
-				    b);
-		else
-			sdev_printk(KERN_INFO, sdp, "%s: cmd %s\n", my_name,
-				    b);
+		sdev_printk(KERN_INFO, sdp, "%s: tag=%#x, cmd %s\n", my_name,
+			    blk_mq_unique_tag(scp->request), b);
  	}
  	if (fake_host_busy(scp))
  		return SCSI_MLQUEUE_HOST_BUSY;
@@ -5782,8 +5768,7 @@ static int sdebug_driver_probe(struct device * dev)
  	}
  	/* Decide whether to tell scsi subsystem that we want mq */
  	/* Following should give the same answer for each host */
-	sdebug_mq_active = shost_use_blk_mq(hpnt) && (submit_queues > 1);
-	if (sdebug_mq_active)
+	if (shost_use_blk_mq(hpnt))
  		hpnt->nr_hw_queues = submit_queues;
 
  	sdbg_host->shost = hpnt;
#2 lore raw
In reply to Bart Van Assche

Bart,

Quoted 5 lines

Since commit 64d513ac31bd ("scsi: use host wide tags by default") all SCSI requests have a tag, whether or not scsi-mq is enabled. Additionally, it is safe to use blk_mq_unique_tag() and blk_mq_unique_tag_to_hwq() for legacy SCSI queues. Since this means that the sdebug_mq_active variable is superfluous, remove it.

Applied to 4.17/scsi-queue. Thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering