From: Chao Gao <chao.gao@intel.com>
To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: Chao Gao <chao.gao@intel.com>,
Christoph Hellwig <hch@infradead.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>
Subject: [RESEND PATCH 2/3] swiotlb: consolidate rounding up default_nslabs
Date: Mon, 18 Jul 2022 09:16:06 +0800 [thread overview]
Message-ID: <20220718011608.106289-3-chao.gao@intel.com> (raw)
In-Reply-To: <20220718011608.106289-1-chao.gao@intel.com>
default_nslabs are rounded up in two cases with exactly same comments.
Add a simple wrapper to reduce duplicate code/comments. It is preparatory
to adding more logics into the round-up.
No functional change intended.
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
kernel/dma/swiotlb.c | 34 ++++++++++++++++++----------------
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 0d0f99146360..9ab87d6d47bc 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -88,6 +88,22 @@ struct io_tlb_area {
spinlock_t lock;
};
+/*
+ * Round up number of slabs to the next power of 2. The last area is going
+ * be smaller than the rest if default_nslabs is not power of two.
+ *
+ * Return true if default_nslabs is rounded up.
+ */
+static bool round_up_default_nslabs(void)
+{
+ if (!default_nareas || is_power_of_2(default_nslabs))
+ return false;
+
+ default_nslabs = roundup_pow_of_two(default_nslabs);
+
+ return true;
+}
+
static void swiotlb_adjust_nareas(unsigned int nareas)
{
if (!is_power_of_2(nareas))
@@ -96,16 +112,9 @@ static void swiotlb_adjust_nareas(unsigned int nareas)
default_nareas = nareas;
pr_info("area num %d.\n", nareas);
- /*
- * Round up number of slabs to the next power of 2.
- * The last area is going be smaller than the rest if
- * default_nslabs is not power of two.
- */
- if (nareas && !is_power_of_2(default_nslabs)) {
- default_nslabs = roundup_pow_of_two(default_nslabs);
+ if (round_up_default_nslabs())
pr_info("SWIOTLB bounce buffer size roundup to %luMB",
(default_nslabs << IO_TLB_SHIFT) >> 20);
- }
}
static int __init
@@ -154,17 +163,10 @@ void __init swiotlb_adjust_size(unsigned long size)
if (default_nslabs != IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT)
return;
- /*
- * Round up number of slabs to the next power of 2.
- * The last area is going be smaller than the rest if
- * default_nslabs is not power of two.
- */
size = ALIGN(size, IO_TLB_SIZE);
default_nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
- if (default_nareas) {
- default_nslabs = roundup_pow_of_two(default_nslabs);
+ if (round_up_default_nslabs())
size = default_nslabs << IO_TLB_SHIFT;
- }
pr_info("SWIOTLB bounce buffer size adjusted to %luMB", size >> 20);
}
--
2.25.1
next prev parent reply other threads:[~2022-07-18 1:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-18 1:16 [RESEND PATCH 0/3] Small fixes for swiotlb Chao Gao
2022-07-18 1:16 ` [RESEND PATCH 1/3] swiotlb: remove unused fields in io_tlb_mem Chao Gao
2022-07-18 1:16 ` Chao Gao [this message]
2022-07-18 1:16 ` [RESEND PATCH 3/3] swiotlb: ensure a segment doesn't cross the area boundary Chao Gao
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=20220718011608.106289-3-chao.gao@intel.com \
--to=chao.gao@intel.com \
--cc=hch@infradead.org \
--cc=iommu@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=robin.murphy@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox