All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: introduce for_each_rq_qos macro
@ 2021-01-06 11:20 Chunguang Xu
  0 siblings, 0 replies; only message in thread
From: Chunguang Xu @ 2021-01-06 11:20 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, linux-kernel

From: Chunguang Xu <brookxu@tencent.com>

Compared to direct pointer traversal, introducing a macro
will make the code more concise. But the introduction of
macros will make rq_qos_xxx() produce a redundant judgment,
usually this may not be a big problem.

Signed-off-by: Chunguang Xu <brookxu@tencent.com>
---
 block/blk-rq-qos.c | 45 ++++++++++++++++++---------------------------
 block/blk-rq-qos.h | 11 +++++++++--
 2 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c
index 6564606..2c21a49 100644
--- a/block/blk-rq-qos.c
+++ b/block/blk-rq-qos.c
@@ -31,83 +31,74 @@ bool rq_wait_inc_below(struct rq_wait *rq_wait, unsigned int limit)
 
 void __rq_qos_cleanup(struct rq_qos *rqos, struct bio *bio)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->cleanup)
 			rqos->ops->cleanup(rqos, bio);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_done(struct rq_qos *rqos, struct request *rq)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->done)
 			rqos->ops->done(rqos, rq);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_issue(struct rq_qos *rqos, struct request *rq)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->issue)
 			rqos->ops->issue(rqos, rq);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_requeue(struct rq_qos *rqos, struct request *rq)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->requeue)
 			rqos->ops->requeue(rqos, rq);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_throttle(struct rq_qos *rqos, struct bio *bio)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->throttle)
 			rqos->ops->throttle(rqos, bio);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_track(struct rq_qos *rqos, struct request *rq, struct bio *bio)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->track)
 			rqos->ops->track(rqos, rq, bio);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_merge(struct rq_qos *rqos, struct request *rq, struct bio *bio)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->merge)
 			rqos->ops->merge(rqos, rq, bio);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_done_bio(struct rq_qos *rqos, struct bio *bio)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->done_bio)
 			rqos->ops->done_bio(rqos, bio);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_queue_depth_changed(struct rq_qos *rqos)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->queue_depth_changed)
 			rqos->ops->queue_depth_changed(rqos);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 /*
diff --git a/block/blk-rq-qos.h b/block/blk-rq-qos.h
index 2bc43e9..bfa72a5 100644
--- a/block/blk-rq-qos.h
+++ b/block/blk-rq-qos.h
@@ -57,11 +57,18 @@ struct rq_depth {
 	unsigned int default_depth;
 };
 
+/*
+ * for_each_rq_qos() allows you to iterate on each rqos
+ */
+#define for_each_rq_qos(rqos) \
+	for (; rqos; rqos = rqos->next)
+
 static inline struct rq_qos *rq_qos_id(struct request_queue *q,
 				       enum rq_qos_id id)
 {
-	struct rq_qos *rqos;
-	for (rqos = q->rq_qos; rqos; rqos = rqos->next) {
+	struct rq_qos *rqos = q->rq_qos;
+
+	for_each_rq_qos(rqos) {
 		if (rqos->id == id)
 			break;
 	}
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-06 11:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06 11:20 [PATCH] block: introduce for_each_rq_qos macro Chunguang Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.