mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chunguang Xu <brookxu.cn@gmail.com>
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] block: introduce for_each_rq_qos macro
Date: Wed,  6 Jan 2021 19:20:56 +0800	[thread overview]
Message-ID: <1609932056-26990-1-git-send-email-brookxu@tencent.com> (raw)

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


                 reply	other threads:[~2021-01-06 11:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1609932056-26990-1-git-send-email-brookxu@tencent.com \
    --to=brookxu.cn@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®