Skip to contentSkip to conversation

blk-mq: remove __blk_mq_delay_run_hw_queue

PATCH New Christoph Hellwig 1 participant 2 messages Dec 23, 2021 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 blk-mq: remove __blk_mq_delay_run_hw_queue

Open code the relevant parts of __blk_mq_delay_run_hw_queue in the two callers instead of the convoluted shared helper.

---
 block/blk-mq.c | 51 +++++++++++++++++++-------------------------------
 1 file changed, 19 insertions(+), 32 deletions(-)
block/blk-mq.c +19 -32
index 0d7c9d3e03293..565a0e6897b8f 100644
@@ -2025,46 +2025,19 @@ static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx)
 }
 
 /**
- * __blk_mq_delay_run_hw_queue - Run (or schedule to run) a hardware queue.
+ * blk_mq_delay_run_hw_queue - Run a hardware queue asynchronously.
  * @hctx: Pointer to the hardware queue to run.
- * @async: If we want to run the queue asynchronously.
  * @msecs: Milliseconds of delay to wait before running the queue.
  *
- * If !@async, try to run the queue now. Else, run the queue asynchronously and
- * with a delay of @msecs.
+ * Run a hardware queue asynchronously with a delay of @msecs.
  */
-static void __blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async,
-					unsigned long msecs)
+void blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs)
 {
 	if (unlikely(blk_mq_hctx_stopped(hctx)))
 		return;
-
-	if (!async && !(hctx->flags & BLK_MQ_F_BLOCKING)) {
-		int cpu = get_cpu();
-		if (cpumask_test_cpu(cpu, hctx->cpumask)) {
-			__blk_mq_run_hw_queue(hctx);
-			put_cpu();
-			return;
-		}
-
-		put_cpu();
-	}
-
 	kblockd_mod_delayed_work_on(blk_mq_hctx_next_cpu(hctx), &hctx->run_work,
 				    msecs_to_jiffies(msecs));
 }
-
-/**
- * blk_mq_delay_run_hw_queue - Run a hardware queue asynchronously.
- * @hctx: Pointer to the hardware queue to run.
- * @msecs: Milliseconds of delay to wait before running the queue.
- *
- * Run a hardware queue asynchronously with a delay of @msecs.
- */
-void blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs)
-{
-	__blk_mq_delay_run_hw_queue(hctx, true, msecs);
-}
 EXPORT_SYMBOL(blk_mq_delay_run_hw_queue);
 
 /**
@@ -2092,8 +2065,22 @@ void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async)
 		need_run = !blk_queue_quiesced(hctx->queue) &&
 		blk_mq_hctx_has_pending(hctx));
 
-	if (need_run)
-		__blk_mq_delay_run_hw_queue(hctx, async, 0);
+	if (!need_run || unlikely(blk_mq_hctx_stopped(hctx)))
+		return;
+
+	if (!async && !(hctx->flags & BLK_MQ_F_BLOCKING)) {
+		int cpu = get_cpu();
+		if (cpumask_test_cpu(cpu, hctx->cpumask)) {
+			__blk_mq_run_hw_queue(hctx);
+			put_cpu();
+			return;
+		}
+
+		put_cpu();
+	}
+
+	kblockd_mod_delayed_work_on(blk_mq_hctx_next_cpu(hctx), &hctx->run_work,
+				    0);
 }
 EXPORT_SYMBOL(blk_mq_run_hw_queue);
 
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/2 block: remove kblockd_mod_delayed_work_on

Just open code the mod_delayed_work{,_on} calls.

---
 block/blk-core.c       |  9 +--------
 block/blk-mq.c         | 15 ++++++++-------
 block/blk.h            |  1 +
 include/linux/blkdev.h |  1 -
 4 files changed, 10 insertions(+), 16 deletions(-)
block/blk-core.c +1 -8
index 10619fd83c1bc..0978ec0a7dcc4 100644
@@ -71,7 +71,7 @@ struct kmem_cache *blk_requestq_srcu_cachep;
 /*
  * Controlling structure to kblockd
  */
-static struct workqueue_struct *kblockd_workqueue;
+struct workqueue_struct *kblockd_workqueue;
 
 /**
  * blk_queue_flag_set - atomically set a queue flag
@@ -1153,13 +1153,6 @@ int kblockd_schedule_work(struct work_struct *work)
 }
 EXPORT_SYMBOL(kblockd_schedule_work);
 
-int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork,
-				unsigned long delay)
-{
-	return mod_delayed_work_on(cpu, kblockd_workqueue, dwork, delay);
-}
-EXPORT_SYMBOL(kblockd_mod_delayed_work_on);
-
 void blk_start_plug_nr_ios(struct blk_plug *plug, unsigned short nr_ios)
 {
 	struct task_struct *tsk = current;
block/blk-mq.c +8 -7
index 565a0e6897b8f..56d049a7fc67d 100644
@@ -1336,15 +1336,15 @@ void blk_mq_add_to_requeue_list(struct request *rq, bool at_head,
 
 void blk_mq_kick_requeue_list(struct request_queue *q)
 {
-	kblockd_mod_delayed_work_on(WORK_CPU_UNBOUND, &q->requeue_work, 0);
+	mod_delayed_work(kblockd_workqueue, &q->requeue_work, 0);
 }
 EXPORT_SYMBOL(blk_mq_kick_requeue_list);
 
 void blk_mq_delay_kick_requeue_list(struct request_queue *q,
 				    unsigned long msecs)
 {
-	kblockd_mod_delayed_work_on(WORK_CPU_UNBOUND, &q->requeue_work,
-				    msecs_to_jiffies(msecs));
+	mod_delayed_work(kblockd_workqueue, &q->requeue_work,
+			 msecs_to_jiffies(msecs));
 }
 EXPORT_SYMBOL(blk_mq_delay_kick_requeue_list);
 
@@ -2035,8 +2035,9 @@ void blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs)
 {
 	if (unlikely(blk_mq_hctx_stopped(hctx)))
 		return;
-	kblockd_mod_delayed_work_on(blk_mq_hctx_next_cpu(hctx), &hctx->run_work,
-				    msecs_to_jiffies(msecs));
+
+	mod_delayed_work_on(blk_mq_hctx_next_cpu(hctx), kblockd_workqueue,
+			    &hctx->run_work, msecs_to_jiffies(msecs));
 }
 EXPORT_SYMBOL(blk_mq_delay_run_hw_queue);
 
@@ -2079,8 +2080,8 @@ void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async)
 		put_cpu();
 	}
 
-	kblockd_mod_delayed_work_on(blk_mq_hctx_next_cpu(hctx), &hctx->run_work,
-				    0);
+	mod_delayed_work_on(blk_mq_hctx_next_cpu(hctx), kblockd_workqueue,
+			    &hctx->run_work, 0);
 }
 EXPORT_SYMBOL(blk_mq_run_hw_queue);
 
block/blk.h +1 -0
index 8bd43b3ad33d5..25a5c9fd48114 100644
@@ -12,6 +12,7 @@ struct elevator_type;
 /* Max future timer expiry for timeouts */
 #define BLK_MAX_TIMEOUT		(5 * HZ)
 
+extern struct workqueue_struct *kblockd_workqueue;
 extern struct dentry *blk_debugfs_root;
 
 struct blk_flush_queue {
include/linux/blkdev.h +0 -1
index bb5fb7282e6ee..43512c8ee0972 100644
@@ -1167,7 +1167,6 @@ static inline unsigned int block_size(struct block_device *bdev)
 }
 
 int kblockd_schedule_work(struct work_struct *work);
-int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay);
 
 #define MODULE_ALIAS_BLOCKDEV(major,minor) \
 	MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor))
Signature · 1 line
2.30.2