@@ -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.
*/
@@ -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;
}
}
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@huawei.com> --- include/linux/sbitmap.h | 5 +++++ lib/sbitmap.c | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-)