From patchwork Fri Apr 15 10:10:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 12814699 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 997E8C433FE for ; Fri, 15 Apr 2022 09:56:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351944AbiDOJ7C (ORCPT ); Fri, 15 Apr 2022 05:59:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351936AbiDOJ64 (ORCPT ); Fri, 15 Apr 2022 05:58:56 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A096FB91B5; Fri, 15 Apr 2022 02:56:27 -0700 (PDT) Received: from kwepemi100009.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KfsB22gv0zgYtr; Fri, 15 Apr 2022 17:54:34 +0800 (CST) Received: from kwepemm600009.china.huawei.com (7.193.23.164) by kwepemi100009.china.huawei.com (7.221.188.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 15 Apr 2022 17:56:25 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 15 Apr 2022 17:56:24 +0800 From: Yu Kuai To: , , , , , CC: , , , Subject: [PATCH -next RFC v3 1/8] sbitmap: record the number of waiters for each waitqueue Date: Fri, 15 Apr 2022 18:10:46 +0800 Message-ID: <20220415101053.554495-2-yukuai3@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220415101053.554495-1-yukuai3@huawei.com> References: <20220415101053.554495-1-yukuai3@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org 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 --- 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..a5105ce6d424 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"); @@ -797,6 +798,7 @@ void sbitmap_prepare_to_wait(struct sbitmap_queue *sbq, struct sbq_wait *sbq_wait, int state) { if (!sbq_wait->sbq) { + atomic_inc(&ws->waiters_cnt); atomic_inc(&sbq->ws_active); sbq_wait->sbq = sbq; } @@ -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; } }