[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220408073916.1428590-2-yukuai3@huawei.com>
Date: Fri, 8 Apr 2022 15:39:09 +0800
From: Yu Kuai <yukuai3@...wei.com>
To: <axboe@...nel.dk>, <yukuai3@...wei.com>,
<andriy.shevchenko@...ux.intel.com>, <john.garry@...wei.com>,
<ming.lei@...hat.com>
CC: <linux-block@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<yi.zhang@...wei.com>
Subject: [PATCH -next RFC v2 1/8] sbitmap: record the number of waiters for each waitqueue
Add a counter in struct sbq_wait_stat to recored how many threads are
waiting on the waitqueue, this will be used in later patches to make
sure 8 waitqueues are balanced. Such counter will also be shown in
debugfs so that user can see if waitqueues are balanced.
Signed-off-by: Yu Kuai <yukuai3@...wei.com>
---
include/linux/sbitmap.h | 5 +++++
lib/sbitmap.c | 7 +++++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/include/linux/sbitmap.h b/include/linux/sbitmap.h
index 8f5a86e210b9..8a64271d0696 100644
--- a/include/linux/sbitmap.h
+++ b/include/linux/sbitmap.h
@@ -91,6 +91,11 @@ struct sbq_wait_state {
*/
atomic_t wait_cnt;
+ /**
+ * @waiters_cnt: Number of active waiters
+ */
+ atomic_t waiters_cnt;
+
/**
* @wait: Wait queue.
*/
diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index ae4fd4de9ebe..393f2b71647a 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -444,6 +444,7 @@ int sbitmap_queue_init_node(struct sbitmap_queue *sbq, unsigned int depth,
for (i = 0; i < SBQ_WAIT_QUEUES; i++) {
init_waitqueue_head(&sbq->ws[i].wait);
atomic_set(&sbq->ws[i].wait_cnt, sbq->wake_batch);
+ atomic_set(&sbq->ws[i].waiters_cnt, 0);
}
return 0;
@@ -759,9 +760,9 @@ void sbitmap_queue_show(struct sbitmap_queue *sbq, struct seq_file *m)
for (i = 0; i < SBQ_WAIT_QUEUES; i++) {
struct sbq_wait_state *ws = &sbq->ws[i];
- seq_printf(m, "\t{.wait_cnt=%d, .wait=%s},\n",
+ seq_printf(m, "\t{.wait_cnt=%d, .waiters_cnt=%d},\n",
atomic_read(&ws->wait_cnt),
- waitqueue_active(&ws->wait) ? "active" : "inactive");
+ atomic_read(&ws->waiters_cnt));
}
seq_puts(m, "}\n");
@@ -798,6 +799,7 @@ void sbitmap_prepare_to_wait(struct sbitmap_queue *sbq,
{
if (!sbq_wait->sbq) {
atomic_inc(&sbq->ws_active);
+ atomic_inc(&ws->waiters_cnt);
sbq_wait->sbq = sbq;
}
prepare_to_wait_exclusive(&ws->wait, &sbq_wait->wait, state);
@@ -810,6 +812,7 @@ void sbitmap_finish_wait(struct sbitmap_queue *sbq, struct sbq_wait_state *ws,
finish_wait(&ws->wait, &sbq_wait->wait);
if (sbq_wait->sbq) {
atomic_dec(&sbq->ws_active);
+ atomic_dec(&ws->waiters_cnt);
sbq_wait->sbq = NULL;
}
}
--
2.31.1
Powered by blists - more mailing lists