All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hao Xu <haoxu@linux.alibaba.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: io-uring@vger.kernel.org, Pavel Begunkov <asml.silence@gmail.com>,
	Joseph Qi <joseph.qi@linux.alibaba.com>
Subject: [PATCH v2] io-wq: simplify code in __io_worker_busy
Date: Mon,  5 Apr 2021 15:36:22 +0800	[thread overview]
Message-ID: <1617608182-202901-1-git-send-email-haoxu@linux.alibaba.com> (raw)
In-Reply-To: <91175ea9-950a-868b-bddf-dfe4c0184225@gmail.com>

leverage xor to simplify code in __io_worker_busy

Signed-off-by: Hao Xu <haoxu@linux.alibaba.com>
---

I thought about [IO_WQ_ACCT_UNBOUND + IO_WQ_ACCT_BOUND - index], but it
is not antithetical, so I finally choose to calculate two indexes
respectively.

 fs/io-wq.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/fs/io-wq.c b/fs/io-wq.c
index 433c4d3c3c1c..7ec2948838ca 100644
--- a/fs/io-wq.c
+++ b/fs/io-wq.c
@@ -292,16 +292,12 @@ static void __io_worker_busy(struct io_wqe *wqe, struct io_worker *worker,
 	worker_bound = (worker->flags & IO_WORKER_F_BOUND) != 0;
 	work_bound = (work->flags & IO_WQ_WORK_UNBOUND) == 0;
 	if (worker_bound != work_bound) {
+		int index0 = work_bound ? IO_WQ_ACCT_UNBOUND : IO_WQ_ACCT_BOUND;
+		int index1 = work_bound ? IO_WQ_ACCT_BOUND : IO_WQ_ACCT_UNBOUND;
 		io_wqe_dec_running(worker);
-		if (work_bound) {
-			worker->flags |= IO_WORKER_F_BOUND;
-			wqe->acct[IO_WQ_ACCT_UNBOUND].nr_workers--;
-			wqe->acct[IO_WQ_ACCT_BOUND].nr_workers++;
-		} else {
-			worker->flags &= ~IO_WORKER_F_BOUND;
-			wqe->acct[IO_WQ_ACCT_UNBOUND].nr_workers++;
-			wqe->acct[IO_WQ_ACCT_BOUND].nr_workers--;
-		}
+		worker->flags ^= IO_WORKER_F_BOUND;
+		wqe->acct[index0].nr_workers--;
+		wqe->acct[index1].nr_workers++;
 		io_wqe_inc_running(worker);
 	 }
 }
-- 
1.8.3.1


      parent reply	other threads:[~2021-04-05  7:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-02 10:18 [PATCH] io-wq: simplify code in __io_worker_busy Hao Xu
2021-04-02 10:38 ` Pavel Begunkov
2021-04-04 19:17   ` Jens Axboe
2021-04-05  7:53     ` [PATCH v3] " Hao Xu
2021-04-05 21:46       ` Jens Axboe
2021-04-06  2:18         ` Hao Xu
2021-04-06  3:08         ` [PATCH v4] " Hao Xu
2021-04-06 15:36           ` Jens Axboe
2021-04-07 18:28           ` Pavel Begunkov
2021-04-05  7:36   ` Hao Xu [this message]

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=1617608182-202901-1-git-send-email-haoxu@linux.alibaba.com \
    --to=haoxu@linux.alibaba.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=joseph.qi@linux.alibaba.com \
    /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 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.