From patchwork Tue Aug 6 12:06:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 817322 Received: from mail.nearlyone.de (mail.nearlyone.de [49.12.199.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78DEA1C9DD3; Tue, 6 Aug 2024 12:07:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=49.12.199.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722946057; cv=none; b=qA0fZGCnqTvhCzczrwd5XR2Ah0S7jf5EJUIxr+zL48r4bYCySjJ6T/0dZhLuyYghCuzgzMQuiuYgeumDAQRTs04hPEdkLNL1rNrGGde1+sFAfVl+cvTnvNcnSg3gwz6IUkDkm7tAGqwlV7uOXHVf2MEllFvidzXtuVHXAw5JzAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722946057; c=relaxed/simple; bh=fnqQngpB9VAAoP06dVKi6yALSCcKS28hR+nq7eyRTZA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hXUDPqhEcUXzeJlzeA9JT6xweaOE2qYCE9dhnAjw5PoiD+1JyaXiumHbVZC0xVffJ05xOqRpCHYntOGRbFvuSlWX6C7X56wCnEAC3ZYz0npg4UHkAAmHvX2n6WDG3vlgXzPv4g9Upw6gbB3PoNr+e8bICJ5OR8yuTFqW6wMctH8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=monom.org; dkim=pass (2048-bit key) header.d=monom.org header.i=@monom.org header.b=kLEV4Nca; arc=none smtp.client-ip=49.12.199.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=monom.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=monom.org header.i=@monom.org header.b="kLEV4Nca" Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DF951DAE1F; Tue, 6 Aug 2024 14:07:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monom.org; s=dkim; t=1722946053; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=36nC1tJdzP6+GYlju6N0sffMCcAgT9UKOFYY1rUGz2E=; b=kLEV4NcaLu+42mjnHzlW5bUaHbHANVJh4avtRkvlXG72tKiz5G214AwEiioNKGy/Hm1/6d hgx7dnhy/9RBMNNxhxgfG8oAs3eba2YvI+jcSiF5JSDu5uZwUhzYYydMs8reRdyuRc1I/p 2evUnio4SgDaCDZ5hIsMjCqRfkeegwJTZ7HlxR+Bco+7BzZ1qpXiItRzkivnnbq1N1613n 9ewedKY+cSM2esbnzWhRCRELnbP1wa9p3Ac+bWHdx2niQuMKVJDaZX4/wua+1fhu00dK2O gzi7eiSL1sr4OyPyxDs1a5V4QfGyBmd2VnXRGI8h8mTIFvQZplY3gq64dadotA== From: Daniel Wagner Date: Tue, 06 Aug 2024 14:06:42 +0200 Subject: [PATCH v3 10/15] blk-mq: add number of queue calc helper Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240806-isolcpus-io-queues-v3-10-da0eecfeaf8b@suse.de> References: <20240806-isolcpus-io-queues-v3-0-da0eecfeaf8b@suse.de> In-Reply-To: <20240806-isolcpus-io-queues-v3-0-da0eecfeaf8b@suse.de> To: Jens Axboe , Keith Busch , Sagi Grimberg , Thomas Gleixner , Christoph Hellwig , "Martin K. Petersen" , John Garry , "Michael S. Tsirkin" , Jason Wang , Kashyap Desai , Sumit Saxena , Shivasharan S , Chandrakanth patil , Sathya Prakash Veerichetty , Suganath Prabu Subramani , Nilesh Javali , GR-QLogic-Storage-Upstream@marvell.com, Jonathan Corbet Cc: Frederic Weisbecker , Mel Gorman , Hannes Reinecke , Sridhar Balaraman , "brookxu.cn" , Ming Lei , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, virtualization@lists.linux.dev, megaraidlinux.pdl@broadcom.com, mpi3mr-linuxdrv.pdl@broadcom.com, MPT-FusionLinux.pdl@broadcom.com, storagedev@microchip.com, linux-doc@vger.kernel.org, Daniel Wagner X-Mailer: b4 0.14.0 X-Last-TLS-Session-Version: TLSv1.3 Multiqueue devices should only allocate queues for the housekeeping CPUs when isolcpus=io_queue is set. This avoids that the isolated CPUs get disturbed with OS workload. Add two variants of helpers which calculates the correct number of queues which should be used. The need for two variants is necessary because some drivers calculate their max number of queues based on the possible CPU mask, others based on the online CPU mask. Signed-off-by: Daniel Wagner Reviewed-by: Christoph Hellwig --- block/blk-mq-cpumap.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/blk-mq.h | 2 ++ 2 files changed, 47 insertions(+) diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c index 7037a2dc485f..c1277763aeeb 100644 --- a/block/blk-mq-cpumap.c +++ b/block/blk-mq-cpumap.c @@ -11,10 +11,55 @@ #include #include #include +#include #include "blk.h" #include "blk-mq.h" +static unsigned int blk_mq_num_queues(const struct cpumask *mask, + unsigned int max_queues) +{ + unsigned int num; + + if (housekeeping_enabled(HK_TYPE_IO_QUEUE)) + mask = housekeeping_cpumask(HK_TYPE_IO_QUEUE); + + num = cpumask_weight(mask); + return min_not_zero(num, max_queues); +} + +/** + * blk_mq_num_possible_queues - Calc nr of queues for multiqueue devices + * @max_queues: The maximal number of queues the hardware/driver + * supports. If max_queues is 0, the argument is + * ignored. + * + * Calculate the number of queues which should be used for a multiqueue + * device based on the number of possible cpu. The helper is considering + * isolcpus settings. + */ +unsigned int blk_mq_num_possible_queues(unsigned int max_queues) +{ + return blk_mq_num_queues(cpu_possible_mask, max_queues); +} +EXPORT_SYMBOL_GPL(blk_mq_num_possible_queues); + +/** + * blk_mq_num_online_queues - Calc nr of queues for multiqueue devices + * @max_queues: The maximal number of queues the hardware/driver + * supports. If max_queues is 0, the argument is + * ignored. + * + * Calculate the number of queues which should be used for a multiqueue + * device based on the number of online cpus. The helper is considering + * isolcpus settings. + */ +unsigned int blk_mq_num_online_queues(unsigned int max_queues) +{ + return blk_mq_num_queues(cpu_online_mask, max_queues); +} +EXPORT_SYMBOL_GPL(blk_mq_num_online_queues); + void blk_mq_map_queues(struct blk_mq_queue_map *qmap) { const struct cpumask *masks; diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index cfc96d6a3136..bcd5ef712af7 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -931,6 +931,8 @@ int blk_mq_freeze_queue_wait_timeout(struct request_queue *q, typedef const struct cpumask *(get_queue_affinty_fn)(void *dev_data, int dev_off, int queue_idx); +unsigned int blk_mq_num_possible_queues(unsigned int max_queues); +unsigned int blk_mq_num_online_queues(unsigned int max_queues); void blk_mq_map_queues(struct blk_mq_queue_map *qmap); void blk_mq_dev_map_queues(struct blk_mq_queue_map *qmap, void *dev_data, int dev_off,