U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Neil Armstrong <neil.armstrong@linaro.org>
To: Tom Rini <trini@konsulko.com>,
	 Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	 Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: u-boot-qcom@groups.io, u-boot@lists.denx.de,
	 Neil Armstrong <neil.armstrong@linaro.org>
Subject: [PATCH v2 3/3] block: use part_get_info_cached() API when scanning partitions
Date: Tue, 08 Apr 2025 11:13:42 +0200	[thread overview]
Message-ID: <20250408-topic-gpt-cache-v2-3-de76e47debb7@linaro.org> (raw)
In-Reply-To: <20250408-topic-gpt-cache-v2-0-de76e47debb7@linaro.org>

Let's make use of the newly introduced part_get_info_cached() API
and the part_get_info_cached_free() when scanning all partitions
of a disk. With this, a lot of unnecessary computation is saved,
leading to a faster boot time when partitions are scanned, especially
with storage medias with potentially multiple large hardware
partitions like UFS, NVMe or eMMC.

Since the default part scan code will always scan up to
128 partitions for a block, and devices with an UFS chip
with up to 8 LUNs are very common in the field, this means
a complete GPT parsing and validation will be done
up to 1024 times instead of 8 on such devices.

On the SM8650 QRD platform with a KIOXIA THGJFJT1E45BATPC
configured with 8 LUNs, the scsi scan takes 0.2s with both
CPU caches enabled, but when disabling both CPU caches it
goes up to 4s to do the full scan of all 8 LUN partitions.

With this change the scan takes only 0.18s with both CPU
caches enabled running 1.1x times faster, and with both CPU
caches disabled the full scan takes only 1.27s running
3x faster.

While 20ms could look negligeable, it's still a 20ms gain
in the boot flow and a non negligeable reduction in
calculation and memory allocation since for each scan
it would allocate and free the gpt_pte table up to
1024 times, now it would only do 8 allocations, reducing
memory fragmentation.

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/block/blk-uclass.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index f3ac8db9464311acbc96f3358e0ef143471ca59d..313fbe6a480e5bced5230c6ea03a3815cf4087b9 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -820,15 +820,17 @@ static int part_create_block_devices(struct udevice *blk_dev)
 
 	/* Add devices for each partition */
 	for (count = 0, part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
-		if (part_get_info(desc, part, &info))
+		if (part_get_info_cached(desc, part, &info))
 			continue;
 		snprintf(devname, sizeof(devname), "%s:%d", blk_dev->name,
 			 part);
 
 		ret = device_bind_driver(blk_dev, "blk_partition",
 					 strdup(devname), &dev);
-		if (ret)
+		if (ret) {
+			part_get_info_cached_free(desc);
 			return ret;
+		}
 
 		part_data = dev_get_uclass_plat(dev);
 		part_data->partnum = part;
@@ -847,6 +849,7 @@ static int part_create_block_devices(struct udevice *blk_dev)
 	debug("%s: %d partitions found in %s\n", __func__, count,
 	      blk_dev->name);
 
+	part_get_info_cached_free(desc);
 	return 0;
 }
 

-- 
2.34.1


      parent reply	other threads:[~2025-04-08  9:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08  9:13 [PATCH v2 0/3] part_efi: cache last scanned GPT for next partition Neil Armstrong
2025-04-08  9:13 ` [PATCH v2 1/3] part: add part_get_info_cached() API Neil Armstrong
2025-04-08  9:55   ` Heinrich Schuchardt
2025-04-08 14:51     ` Neil Armstrong
2025-04-11 11:56   ` Ilias Apalodimas
2025-04-08  9:13 ` [PATCH v2 2/3] part: efi: add GPT PTE cache used with " Neil Armstrong
2025-04-08 10:57   ` Heinrich Schuchardt
2025-04-08 14:52     ` Neil Armstrong
2025-04-17  6:31   ` Ilias Apalodimas
2025-04-08  9:13 ` Neil Armstrong [this message]

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=20250408-topic-gpt-cache-v2-3-de76e47debb7@linaro.org \
    --to=neil.armstrong@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot-qcom@groups.io \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /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