From patchwork Tue Apr 8 09:13:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 879036 Delivered-To: patch@linaro.org Received: by 2002:a5d:6dae:0:b0:38f:210b:807b with SMTP id u14csp5375481wrs; Tue, 8 Apr 2025 02:14:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV/4pv9jpFUA73/6sQpXjGBfe3REcJmtzLP43th8EhG/bbCq/ArYxKykwhtvol8r2OJv3KH1A==@linaro.org X-Google-Smtp-Source: AGHT+IECBQFSKIYty8P+vat2O4ibAHki7SX7MH2vCV6JHfoS3wKPPxAjUGDpAr0abKCtnXRD5BOC X-Received: by 2002:a05:6122:1d52:b0:523:c4df:4de3 with SMTP id 71dfb90a1353d-527644ac432mr12555624e0c.5.1744103647249; Tue, 08 Apr 2025 02:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744103647; cv=none; d=google.com; s=arc-20240605; b=jTcEGesj+Pu74hiMGX5KPYGOC64oJfdsmO9B3Id0vVQlMmpHmcEnmIN9QebR0d4jPS 1s9Bvtn30JR5lekOt2dwFpAo06hbkzp44gEry8v8z9KM5qQM35MPTSTvURPpN56lsUEu NbW6E4X2DTofKKqZq1nBU6KnEtbJWGw4j/yI9p+oQQdJOjH/MXczjdcoV0Qm8KX3BYdn fLFaItL4k9aRAN/2IcC3gCdoJvz9xZjSZF2E9W/ah1F8RbESoquQqvcJuUVl2MWeTUXl IfiV4m8LeNk63d5Bwk0+YbuSOXO9ADOZxqIjgOChC4jJUTlw/HRepmcla92nffaZne+K E+Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=mAe4tHQP5khDrN77TZDHRTl0ByXEeF2B4kSGsel0u4Y=; fh=OHIQE0JN7Ka5Id2Euof7RvskcJ0jBFK2CBflRprHaaE=; b=j92H1QPYOevYqZDVTugRnfaXn9Wqy2cbNm3KzHK5jWi74icrRWNY1rBBSjDM5grnYr MiAl8BEnqNAeam+VDe8OQT6gMmXUEuiHeAvpk3BNxXormvbj43B/30Rfd68m6xSNKwj6 eumvhmGw1yyT0SjmDKIkaGiX38Goe/gLwRtv2F9hsE6F/d4JsVp4K/mNnBJEDvKD29lg tlD9faEM8Osje23f6F0NpC+jXDBZzbDvHw4M8JSd7PIQxCCGii6KDzXubiQQawqgkqcm 643ouji02dWuLECSmmwH04KS7ThI55eg5BjomA6l4V6YCYZAVrnLWRHTD/BSSnb3WxiM ZkvA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C1F388t1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 71dfb90a1353d-5279b64f110si396260e0c.111.2025.04.08.02.14.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 02:14:07 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C1F388t1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AF6FB833C6; Tue, 8 Apr 2025 11:13:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="C1F388t1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DBE8C830F4; Tue, 8 Apr 2025 11:13:47 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B10F4833AD for ; Tue, 8 Apr 2025 11:13:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=neil.armstrong@linaro.org Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-43d0c18e84eso27168575e9.3 for ; Tue, 08 Apr 2025 02:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744103625; x=1744708425; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=mAe4tHQP5khDrN77TZDHRTl0ByXEeF2B4kSGsel0u4Y=; b=C1F388t13Ryb+/Sg+RjzAnD1zcHgGg+eB9Y71jkW38Rvb7yBPsF9PAFjySzrsgo721 YOVrLGqVxykocSQSjMXclM7RDlNhMS4mZGG1gxrKZMWa7dWM6ZUHYZHr7FStr4uk/1Pl yREPXkzZTeRuM1kljvbSdIRTyi779maY7WKv5Nt+eGQiWQW3qtXvNFINFlSsJEhxmoP5 0A4vSLwhLpvI9H2qY4i/oulYiQ7j3fLtvjDh41d2tvZyS4MRaokKxiq8K8nKHlGaHcJT ECF04WdnmV6lf+9B8evaV6ZkAbrMc+zRP3lxLSLS5o+0tREUQgU0jxuE2fcw2NS0I8uB 1DsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744103625; x=1744708425; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mAe4tHQP5khDrN77TZDHRTl0ByXEeF2B4kSGsel0u4Y=; b=m85OMq2MdtrDH+nMKvk8HQs7+rBc460/OfYnlp96dF2JhbT+/dDxwNp/P1jMSKaJqh 8LNpIY6Eckfx0Fhc2ds9MmTkGE0AHtNdAQgQ4/NgbnsBT5zD8YRaRslS1eB71r6yCJ6S qX+Gr8xwPPggNNliJOrMTwAdpmyRpIgV+TLFAvo4rXg0vRDL/e5xH6gSSSuup4TQjSDJ TV13bh7GSdUP6iRFXi+/uEo+pvcQ1aRaNENbR1QqvBv/jAQxRy/QvMmBLn+sJ66bhE06 vKAp8rqGlhnaliL47IMHuOwwM9KHZGaJU8XSpIsdmDB3M4Npu3apvY3ZQ6CxvLRwSrS5 yLsQ== X-Forwarded-Encrypted: i=1; AJvYcCXMlNo7zFlma/JqN3GqxjgXYhxJdCa5C50p4JwuT/LexBM0DgLTXOJ6plZG3C7BCmzXZgGZiTw=@lists.denx.de X-Gm-Message-State: AOJu0YxkCSdmIln9Uz3vqbffHUjzJ3E9ZT6oorJDUsIzoAN+fNWPvrWk btEBvBIcb12k2Zg/gz5mQm29u7u1KHtnZJ43QDRXqu6rw1+pkkGw+0gROs/cRbQ= X-Gm-Gg: ASbGncsZMejmzI4k8NbqOHCHXuDmpcfCDYkBPw3OCh/I4L1TroB7kYD10tZiPcRUNdx vMerKPn7Zhe4Z/GRnukHfIC5+FUqye3IumB+hBdhHkWc6N2gfGqgPSqxas7yzCvd8aeUgffiVPO XebpPZ3T5jqb+zRiOD3TAGuDcMAWAHVo7uOdZI+NpZBObJmwWFQvBhIVWXHFsN758ADgnJgOw8G 1OyqYZGzlYNQ01KkTGgqHczD/vn8HYqwHoW7JAw4JR4tZEuqjCePBLY4FhixDqMCFNKU1f3hsH5 It+O1V346EUC04B804zl8V0thAX0J1hNKxQcOUcTbC5acS/qVlnm4Z3VjuqvVrysTA== X-Received: by 2002:a05:600c:3d06:b0:43d:1c3:cb2e with SMTP id 5b1f17b1804b1-43f18908631mr1210565e9.17.1744103625101; Tue, 08 Apr 2025 02:13:45 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:3d9:2080:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm155056555e9.39.2025.04.08.02.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 02:13:44 -0700 (PDT) From: Neil Armstrong Date: Tue, 08 Apr 2025 11:13:40 +0200 Subject: [PATCH v2 1/3] part: add part_get_info_cached() API MIME-Version: 1.0 Message-Id: <20250408-topic-gpt-cache-v2-1-de76e47debb7@linaro.org> References: <20250408-topic-gpt-cache-v2-0-de76e47debb7@linaro.org> In-Reply-To: <20250408-topic-gpt-cache-v2-0-de76e47debb7@linaro.org> To: Tom Rini , Ilias Apalodimas , Heinrich Schuchardt Cc: u-boot-qcom@groups.io, u-boot@lists.denx.de, Neil Armstrong X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5729; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=UiBwH4PW7AbDnj3cPMfGLbVVQiR1T4VFUD/X9WbUuXk=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBn9OjGCcRuVr2Zkr+4bJ/sw32gaQH5v243yXUj326V NBAqZp2JAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZ/ToxgAKCRB33NvayMhJ0RZnEA Ckt9C3Cooz1E/89vf3GvCQG0UzFAxz0QTCjltUJtWM8utBUeR3n4+DSNmWWjWciw4gB8xFWPYFACRz qVtFatCBDZFg6L9aAPGgmE7vVnYVbu9Q1Yr/tKJhfsbvFZkylhYXQtPH5qlENJqHXxEKcUN88mGL69 /iIQj0z8g5iAx/lulO9HG3D5bHwKMZ00RoMsCZg+J5pGjeKrzSv2shh4LUsAgAa7xbghtChTckrhUt 4TQwqYKcpHhRx3E0znPacqXdkeVmY3rtM/xbmSkb/Cts9O4P+PSpVXd/4ltr5iq8bQf2FbzCqiv7qq Lux8a+sSKqrb4Gx0/nbVH1bgJ1wQbHKQp0vRpIAFiHYyhSGEvywHLzv1yff+5rRLYSzo/b2WemTkhJ IAhCHepH/ckUFpl1i94rKFBSWvPW2rljLcvsj/1H6UI0Ttb4MlFuXGE9zODoPCWPRfww0d7kOw89K5 8Jl0Iuxy41KcidZUfFH2Lj/tnaTOh0vyQ2q+BatDb1vMKmF3lTC495ekWT7VwBBpm/LBvcceVyxVC1 LMobq8ZSeZ04TYwUh1l5AUJNSK55n25IXE3lvMnp4xXfy2fql3FMKqFOfqtalUiso+TQaqr8OIzFI5 KsDlsNdNgNjMNCtO2ahGTvrQ5dBeMUCz9Lc2iOuRV0yp/ZWGHLrAO2ytSwKw== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Introduce a new part_get_info_cached() API that's used to get the part_info of a blk_desc allowing to use an eventual partition scanning cache to avoid rescanning the entire disk partition scheme for each partition number. The part_get_info_cached_free() is also added to hint the partition code to flush any cached data from this disk. The equivalent ops are added that directly maps to those added functions. This API is designed to be used as a direct replacement of part_get_info() in codes scanning all partitions for a same disk, like in blk-uclass. 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. Signed-off-by: Neil Armstrong --- disk/part.c | 55 ++++++++++++++++++++++++++++++++++++++++++++----------- include/part.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/disk/part.c b/disk/part.c index 303178161c083ec6e1b767b4f06ac5773576ca60..1d09c0511c75d457c81cab040c3f5caa924ee945 100644 --- a/disk/part.c +++ b/disk/part.c @@ -335,8 +335,8 @@ void part_print(struct blk_desc *desc) drv->print(desc); } -int part_get_info_by_type(struct blk_desc *desc, int part, int part_type, - struct disk_partition *info) +static int _part_get_info_by_type(struct blk_desc *desc, int part, int part_type, + struct disk_partition *info, bool cached) { struct part_driver *drv; @@ -356,24 +356,57 @@ int part_get_info_by_type(struct blk_desc *desc, int part, int part_type, desc->part_type); return -EPROTONOSUPPORT; } - if (!drv->get_info) { - PRINTF("## Driver %s does not have the get_info() method\n", - drv->name); - return -ENOSYS; - } - if (drv->get_info(desc, part, info) == 0) { - PRINTF("## Valid %s partition found ##\n", drv->name); - return 0; + if (cached && drv->get_info_cached) { + if (drv->get_info_cached(desc, part, info) == 0) { + PRINTF("## Valid %s partition found ##\n", drv->name); + return 0; + } + } else { + if (!drv->get_info) { + PRINTF("## Driver %s does not have the get_info() method\n", + drv->name); + return -ENOSYS; + } + if (drv->get_info(desc, part, info) == 0) { + PRINTF("## Valid %s partition found ##\n", drv->name); + return 0; + } } } return -ENOENT; } +int part_get_info_by_type(struct blk_desc *desc, int part, int part_type, + struct disk_partition *info) +{ + return _part_get_info_by_type(desc, part, part_type, info, false); +} + +int part_get_info_cached(struct blk_desc *desc, int part, + struct disk_partition *info) +{ + return _part_get_info_by_type(desc, part, PART_TYPE_UNKNOWN, info, true); +} + int part_get_info(struct blk_desc *desc, int part, struct disk_partition *info) { - return part_get_info_by_type(desc, part, PART_TYPE_UNKNOWN, info); + return _part_get_info_by_type(desc, part, PART_TYPE_UNKNOWN, info, false); +} + +void part_get_info_cached_free(struct blk_desc *desc) +{ + struct part_driver *drv; + + if (blk_enabled()) { + drv = part_driver_lookup_type(desc); + if (!drv) + return; + if (!drv->get_info_cache_free) + return; + drv->get_info_cache_free(desc); + } } int part_get_info_whole_disk(struct blk_desc *desc, diff --git a/include/part.h b/include/part.h index fcb3c13dea4de6346ad98d6ce320ef36747dda85..8c98865146306fb66509576068c45de01b9cedb6 100644 --- a/include/part.h +++ b/include/part.h @@ -216,6 +216,34 @@ struct blk_desc *mg_disk_get_dev(int dev); */ int part_get_info_by_type(struct blk_desc *desc, int part, int part_type, struct disk_partition *info); + +/** + * part_get_info_cached() - Get partitions from a block device but save the + * disk partition map between different partitions. + * + * Call to part_get_info_cached_free() is required when scanning of the + * block device is finished. + * + * If the partition driver doesn't support cached part_info, the + * normal part_info will be called instead. + * + * @desc: Block device descriptor + * @part: Partition number to read + * @info: Returned partition information + * + * Return: 0 on success, negative errno on failure + */ +int part_get_info_cached(struct blk_desc *desc, int part, + struct disk_partition *info); + +/** + * part_get_info_cached_free() - Free the saved disk partition map + * from a previous call of part_get_info_cached(). + * + * @desc: Block device descriptor + */ +void part_get_info_cached_free(struct blk_desc *desc); + int part_get_info(struct blk_desc *desc, int part, struct disk_partition *info); /** @@ -463,6 +491,22 @@ struct part_driver { int part_type; /** @max_entries: maximum number of partition table entries */ const int max_entries; + /** + * @cache_free_cache_free: Free any parsing data stored from get_info_cached() + * + * @get_info_cache_free.desc: Block device descriptor + */ + void (*get_info_cache_free)(struct blk_desc *desc); + /** + * @get_inf_cachedo: Get information about a partition, and save + * the resulting parsing data for the next partition. + * + * @get_info_cached.desc: Block device descriptor + * @get_info_cached.part: Partition number (1 = first) + * @get_info_cached.info: Returns partition information + */ + int (*get_info_cached)(struct blk_desc *desc, int part, + struct disk_partition *info); /** * @get_info: Get information about a partition * From patchwork Tue Apr 8 09:13:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 879038 Delivered-To: patch@linaro.org Received: by 2002:a5d:6dae:0:b0:38f:210b:807b with SMTP id u14csp5375624wrs; Tue, 8 Apr 2025 02:14:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUMn5gO6R4O601X8FUNyLaQwfQ7AAqg1V74UPRZ2EU7blS2Pya8tfieupGj6hZcoC7V+7w3RA==@linaro.org X-Google-Smtp-Source: AGHT+IEnQkymyhIdhHe8zDuHXln5u0tXIICblGHsba6kE1nA/nAAcbCskkMBYEWrUrA98xfhF3io X-Received: by 2002:a05:6102:151d:b0:4c4:e018:326f with SMTP id ada2fe7eead31-4c8553af12fmr12376147137.10.1744103670531; Tue, 08 Apr 2025 02:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744103670; cv=none; d=google.com; s=arc-20240605; b=ho8SlDg/2ONwU9OSv8jPkCjND049Lx5E4c8znNn6z+KCc3aHeRiZymDxOi89jUh/bN UEBvh1pCoiUSNMZml9IVBYQiN34zs51ssyL/Sg+sVZoG8sdXOeO71Y3EYO1ykX+0PknL tZTxyE5pHA9Zrr4y67/wqNuIDdBKYquSrQIGm8J1Sd7Qi28W80bXQ2z7ejhLSdb3RQqT bPonwcOAb8Z+sPeA6mx1LgaFLnDs49g05XXhHv4pdTItuU4z9m5d4IduxaYY4Geuxirp 9hRZZK+3VVVBgmav+mHkCPYrARrOOoPKveDO5MY5ysFr6/eFQfIKZXrQi7zhIqCIChnz KJxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=zcNtQq/p3lrJ5+YREThRsDvkDYGSU2+7JCaahH9LgMs=; fh=yrSxuWxAPYXUTF7m4sM0I+XzNWNM4r/pmClHDNkKGH8=; b=dzicYSecxpUzx4zLiD0KHZWqgXvBHNj+OhSEWdQpen5dBuBqV/9njt1HOTcYPXIhV4 UJuxGRo9Jgm4xw0QR/b/4/+QmDO6+JZiexxzNB1aoSJB+tKMjIHbCOIizMWgU/o1igVC zEXrOYrErt/ZkXAVEtTMrduGn3bPiyhDpatjs+bvToCxe6z4OO0IfRQWFNAHDqkEwsy8 IxcHXBX8LkA1TvzxdfldFbht5hHGn/KuaQrvnkIgx1eBSRZVtKUa6OFMXGrodE5d47lP Z8WaJh24iPcWCirA+tDgjkC1Lf44GuVvo30c4x6jGkznWWEFN/kBt5KyO8L/WZfGLvIy fIGA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A13XgPrA; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id ada2fe7eead31-4c9b453f40esi382480137.269.2025.04.08.02.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 02:14:30 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A13XgPrA; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E3330833FC; Tue, 8 Apr 2025 11:13:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="A13XgPrA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 80B63833C6; Tue, 8 Apr 2025 11:13:51 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4D5FD833BE for ; Tue, 8 Apr 2025 11:13:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=neil.armstrong@linaro.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-43cec5cd73bso29277025e9.3 for ; Tue, 08 Apr 2025 02:13:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744103626; x=1744708426; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=zcNtQq/p3lrJ5+YREThRsDvkDYGSU2+7JCaahH9LgMs=; b=A13XgPrAgR7wizIk79/zxxpTE1bbQh95vdDY0M3zEjrfR/WdZjCaryXLtJx0APOGod eM2L1nIdj4PcYr8VZxs4dJYLsq2a2mwTBelh2P059e6e5kghQ0oIloSbjAM5A3PRe/wi wUr+H6xp2ayGyd0kzhkqypRNwK2zVkFjyhpGsfICkrI6x9yhZh6CdH1AtIGpW+GJKbNw HZqsW0v2w9r7VaAS3+epG/Y2pn8K7t3MhMTlWsrdcHH0zemAdxpErjgQSUB86bDOOiNB N/nEdbHJY64yUyIRVu/uh+vmc+3Q/FdegBAdG8ol411UJSevHXmTPSsV9aXC+opcyMFe StBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744103626; x=1744708426; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zcNtQq/p3lrJ5+YREThRsDvkDYGSU2+7JCaahH9LgMs=; b=t4Q+sjGXR2wYO0WujPTgUibZe2k8G55n9TMi5avTg8A/Wn/KfbxZE6XQs3VNVVUYDT L5A9UFRiE4MYm4We9BwcehudtGN1seXnMZrjKNLrYE1CiKz9TkAuNIa2yZi+UbSRuR7E KA7QJmWiVgw6TXFODfcurRO6ukaeQ/L5tZ2KGlXheVYPyF++XhB5e1mScrgxGRg4v5Ci KI7gnTl/L2x+PURrXmg3ijUY77m2ltrPNyV8faYTjpFwpobU3DJGYTzhS8t/gUMDo6cj KXG15+GMRaHvwZNL4GYWKcLjn1+EDqX405YV2nszrAy9T0gFGLgwPSRfOs/3nmGAtNn0 W0CQ== X-Forwarded-Encrypted: i=1; AJvYcCUysJOEgTTkAx8OGz7FLRQTz/sAsLlqNDdz/Q7LlzXfaQgFCYA2KNaB3PoriKNgTZmDAHxGmrA=@lists.denx.de X-Gm-Message-State: AOJu0Ywz2y10adok0D/oweC+Q3iF6R0ckqJdMmK8e8oAET4+BtV1KsPw 2vATspWQqLZBPib32oTp7B88i63EVI8ZjLrJMBZZ7dUEczGANGiWbM8k488r0vaB2gS4plLiKcV b X-Gm-Gg: ASbGncs1EU6nWs8z8wtqmMIxtwm+qWB7U53kSgDImEzzKku9oW3YqZCpy9VixrhTTn4 JflHK7hpoFYclVBRNBqm36yhV/x4ZBy4tPCJ8+5x2OTYxAVnEEaMeWgK7+jM17cq6FL0zBly1Ng CsmTetTMKeSs7ukXupkE7adMWlLbKhztn3aTmz8m2h0baaZcS6sB+RhnLHG71sJPFaRtJjZCllD RirfphtffEeF1XnoBMLtbKbFM/+x6FxMX2kgtHtTbtR3Cj3qfQLwQVKwuFVjkrVyiIZPUGhtn3/ QS3b7MDOeFVuel3/W7pZ7pChv45TIQAaTUdn6IOoV43lDXtYuZnjD0a2l+aW9d8d6g== X-Received: by 2002:a05:600c:1d8f:b0:43d:526:e0ce with SMTP id 5b1f17b1804b1-43ee076d517mr82670985e9.21.1744103625785; Tue, 08 Apr 2025 02:13:45 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:3d9:2080:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm155056555e9.39.2025.04.08.02.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 02:13:45 -0700 (PDT) From: Neil Armstrong Date: Tue, 08 Apr 2025 11:13:41 +0200 Subject: [PATCH v2 2/3] part: efi: add GPT PTE cache used with part_get_info_cached() API MIME-Version: 1.0 Message-Id: <20250408-topic-gpt-cache-v2-2-de76e47debb7@linaro.org> References: <20250408-topic-gpt-cache-v2-0-de76e47debb7@linaro.org> In-Reply-To: <20250408-topic-gpt-cache-v2-0-de76e47debb7@linaro.org> To: Tom Rini , Ilias Apalodimas , Heinrich Schuchardt Cc: u-boot-qcom@groups.io, u-boot@lists.denx.de, Neil Armstrong X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8871; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=zDk+kDSWWudphQFpbKALF1vSKMox4zCeWi+smggKCUY=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBn9OjHHdGSwQrneeToAlVXksPedGZeng5sw2FzyxbN womORsGJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZ/ToxwAKCRB33NvayMhJ0RX3EA Cg5YEbryuF3/zTH47FQnek0NhRhQLGFVuSG/Ry5Nfiel8jX9is1/eZdmO2AhzC79oiOUq7n2haqFxc FfT61mzxS6SAf0tiYLI3XuiXHux7fKMwG6jxs3qi4IyaXwpzguG2wsznKgXfXo7Xrun+2NyM+tv3XP L3zS1u5DRcNWlWO4uXF9R60XnFRKZ7bVql342tnXkE4lK30hvUrvGOr6UGa5T1qbeLg7XfS7c+5/vJ AAdJKNT5ARWGPu3LROvY9blUv7ZJNmS8M4874iOhbrfhzqWdpec3z4lnKSr/uNYDVEO2kA+rb/J4Ju cPp5SOzbNS7AnMdEQhf4HdJPkt1qGtpuqnOBXB5tQMq/UuumchUdA/HmGHqJtlxGPa37UekUflKZ2v n3Yi5LpxYy6vAO6QaUvNLbtrPyFAmY6kHNElImg2x0ufAFW7ixW6fVJqGQlxAz1jTngTGMm88LyAtk 4LMw+1a36j8kpaOkI3ZatMF1N+Szo3d3fkbZgUVol/zOzk2mihmfLpmma3Srs8s7Ldqs5q4CvV9Dxy xJPENVW2tc0mAHvCNH0Bp62/zuN5jRbMoj1P8as4jBwPiWuJX5W//HW8qkxnTX68Y8AtIvZCNtJtv7 OkVFB2QPKYf77RBqV8AmNpYhMGMcSYBvOiwv+EQCWOKojKj0c6JeAD5eE6Ow== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Implement a simple cache for part_efi to be used by the newly introduced part_get_info_cached() API. The cache simply stores a successfully scanned GPT PTE if called from the part_get_info_cached() ops, and will return the cached data if the blk_desc and lba offset matches, invalidating the cache if not. The cache will only operate if called from the part_get_info_cached() API, all the over calls will operate uncached, making sure we can still update & re-scan the GPT partitions like before. Signed-off-by: Neil Armstrong --- disk/part_efi.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 96 insertions(+), 18 deletions(-) diff --git a/disk/part_efi.c b/disk/part_efi.c index 932d058c184ce6946b7142e7c2d9637b28e4661e..949968fcd30fc18766a023e73f43ca1381dcef89 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -55,12 +55,58 @@ static inline u32 efi_crc32(const void *buf, u32 len) static int pmbr_part_valid(struct partition *part); static int is_pmbr_valid(legacy_mbr * mbr); static int is_gpt_valid(struct blk_desc *desc, u64 lba, gpt_header *pgpt_head, - gpt_entry **pgpt_pte); + gpt_entry **pgpt_pte, bool cache); static gpt_entry *alloc_read_gpt_entries(struct blk_desc *desc, gpt_header *pgpt_head); static int is_pte_valid(gpt_entry * pte); static int find_valid_gpt(struct blk_desc *desc, gpt_header *gpt_head, - gpt_entry **pgpt_pte); + gpt_entry **pgpt_pte, bool cache); + +static struct gpt_pte_cache_data { + struct blk_desc *desc; + u64 lba; + gpt_entry *gpt_pte; + gpt_header gpt_head; +} gpt_pte_cache; + +static void clear_gpt_pte_cache(void) +{ + if (gpt_pte_cache.desc) { + if (gpt_pte_cache.gpt_pte) + free(gpt_pte_cache.gpt_pte); + + memset(&gpt_pte_cache, 0, sizeof(gpt_pte_cache)); + } +} + +static void cache_gpt_pte(struct blk_desc *desc, u64 lba, + gpt_entry *gpt_pte, gpt_header *pgpt_head) +{ + if (gpt_pte_cache.gpt_pte) + free(gpt_pte_cache.gpt_pte); + + gpt_pte_cache.desc = desc; + gpt_pte_cache.lba = lba; + gpt_pte_cache.gpt_pte = gpt_pte; + if (pgpt_head) + memcpy(&gpt_pte_cache.gpt_head, pgpt_head, sizeof(gpt_header)); +} + +static gpt_entry *get_cached_gpt_pte(struct blk_desc *desc, u64 lba, + gpt_header *pgpt_head) +{ + if (gpt_pte_cache.desc && gpt_pte_cache.gpt_pte) { + if (gpt_pte_cache.desc == desc && + gpt_pte_cache.lba == lba) { + memcpy(pgpt_head, &gpt_pte_cache.gpt_head, sizeof(gpt_header)); + return gpt_pte_cache.gpt_pte; + } + + clear_gpt_pte_cache(); + } + + return NULL; +} static char *print_efiname(gpt_entry *pte) { @@ -205,7 +251,7 @@ int get_disk_guid(struct blk_desc *desc, char *guid) unsigned char *guid_bin; /* This function validates AND fills in the GPT header and PTE */ - if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1) + if (find_valid_gpt(desc, gpt_head, &gpt_pte, false) != 1) return -EINVAL; guid_bin = gpt_head->disk_guid.b; @@ -224,7 +270,7 @@ static void __maybe_unused part_print_efi(struct blk_desc *desc) unsigned char *uuid; /* This function validates AND fills in the GPT header and PTE */ - if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1) + if (find_valid_gpt(desc, gpt_head, &gpt_pte, false) != 1) return; debug("%s: gpt-entry at %p\n", __func__, gpt_pte); @@ -258,8 +304,13 @@ static void __maybe_unused part_print_efi(struct blk_desc *desc) return; } -static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part, - struct disk_partition *info) +static void __maybe_unused part_get_info_cache_free_efi(struct blk_desc *desc) +{ + clear_gpt_pte_cache(); +} + +static int _part_get_info_efi(struct blk_desc *desc, int part, + struct disk_partition *info, bool cache) { ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz); gpt_entry *gpt_pte = NULL; @@ -271,13 +322,14 @@ static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part, } /* This function validates AND fills in the GPT header and PTE */ - if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1) + if (find_valid_gpt(desc, gpt_head, &gpt_pte, cache) != 1) return -EINVAL; if (part > le32_to_cpu(gpt_head->num_partition_entries) || !is_pte_valid(&gpt_pte[part - 1])) { log_debug("Invalid partition number %d\n", part); - free(gpt_pte); + if (!cache) + free(gpt_pte); return -EPERM; } @@ -307,11 +359,23 @@ static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part, log_debug("start 0x" LBAF ", size 0x" LBAF ", name %s\n", info->start, info->size, info->name); - /* Remember to free pte */ - free(gpt_pte); + if (!cache) + free(gpt_pte); return 0; } +static int __maybe_unused part_get_info_cached_efi(struct blk_desc *desc, int part, + struct disk_partition *info) +{ + return _part_get_info_efi(desc, part, info, true); +} + +static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part, + struct disk_partition *info) +{ + return _part_get_info_efi(desc, part, info, false); +} + static int part_test_efi(struct blk_desc *desc) { ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, desc->blksz); @@ -689,7 +753,7 @@ int gpt_verify_headers(struct blk_desc *desc, gpt_header *gpt_head, */ if (is_gpt_valid(desc, GPT_PRIMARY_PARTITION_TABLE_LBA, - gpt_head, gpt_pte) != 1) { + gpt_head, gpt_pte, false) != 1) { log_debug("Invalid GPT\n"); return -1; } @@ -706,7 +770,7 @@ int gpt_verify_headers(struct blk_desc *desc, gpt_header *gpt_head, } if (is_gpt_valid(desc, (desc->lba - 1), - gpt_head, gpt_pte) != 1) { + gpt_head, gpt_pte, false) != 1) { log_debug("Invalid Backup GPT\n"); return -1; } @@ -765,9 +829,9 @@ int gpt_repair_headers(struct blk_desc *desc) int ret = -1; is_gpt1_valid = is_gpt_valid(desc, GPT_PRIMARY_PARTITION_TABLE_LBA, - gpt_h1, &gpt_e1); + gpt_h1, &gpt_e1, false); is_gpt2_valid = is_gpt_valid(desc, desc->lba - 1, - gpt_h2, &gpt_e2); + gpt_h2, &gpt_e2, false); if (is_gpt1_valid && is_gpt2_valid) { ret = 0; @@ -1023,12 +1087,13 @@ static int is_pmbr_valid(legacy_mbr *mbr) * lba is the logical block address of the GPT header to test * gpt is a GPT header ptr, filled on return. * ptes is a PTEs ptr, filled on return. + * cache is a bool, true to use the cached gpt_pte from previous call * * Description: returns 1 if valid, 0 on error, 2 if ignored header * If valid, returns pointers to PTEs. */ static int is_gpt_valid(struct blk_desc *desc, u64 lba, gpt_header *pgpt_head, - gpt_entry **pgpt_pte) + gpt_entry **pgpt_pte, bool cache) { /* Confirm valid arguments prior to allocation. */ if (!desc || !pgpt_head) { @@ -1036,6 +1101,12 @@ static int is_gpt_valid(struct blk_desc *desc, u64 lba, gpt_header *pgpt_head, return 0; } + if (cache) { + *pgpt_pte = get_cached_gpt_pte(desc, lba, pgpt_head); + if (*pgpt_pte) + return 1; + } + ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, mbr, 1, desc->blksz); /* Read MBR Header from device */ @@ -1081,6 +1152,9 @@ static int is_gpt_valid(struct blk_desc *desc, u64 lba, gpt_header *pgpt_head, return 0; } + if (cache) + cache_gpt_pte(desc, lba, *pgpt_pte, pgpt_head); + /* We're done, all's well */ return 1; } @@ -1090,23 +1164,25 @@ static int is_gpt_valid(struct blk_desc *desc, u64 lba, gpt_header *pgpt_head, * * gpt is a GPT header ptr, filled on return. * ptes is a PTEs ptr, filled on return. + * cache if a bool, use cached GPT if available * * Description: returns 1 if found a valid gpt, 0 on error. * If valid, returns pointers to PTEs. */ static int find_valid_gpt(struct blk_desc *desc, gpt_header *gpt_head, - gpt_entry **pgpt_pte) + gpt_entry **pgpt_pte, bool cache) { int r; r = is_gpt_valid(desc, GPT_PRIMARY_PARTITION_TABLE_LBA, gpt_head, - pgpt_pte); + pgpt_pte, cache); if (r != 1) { if (r != 2) log_debug("Invalid GPT\n"); - if (is_gpt_valid(desc, desc->lba - 1, gpt_head, pgpt_pte) + if (is_gpt_valid(desc, desc->lba - 1, gpt_head, pgpt_pte, + true) != 1) { log_debug("Invalid Backup GPT\n"); return 0; @@ -1210,6 +1286,8 @@ U_BOOT_PART_TYPE(a_efi) = { .name = "EFI", .part_type = PART_TYPE_EFI, .max_entries = GPT_ENTRY_NUMBERS, + .get_info_cache_free = part_get_info_ptr(part_get_info_cache_free_efi), + .get_info_cached = part_get_info_ptr(part_get_info_cached_efi), .get_info = part_get_info_ptr(part_get_info_efi), .print = part_print_ptr(part_print_efi), .test = part_test_efi, From patchwork Tue Apr 8 09:13:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 879037 Delivered-To: patch@linaro.org Received: by 2002:a5d:6dae:0:b0:38f:210b:807b with SMTP id u14csp5375549wrs; Tue, 8 Apr 2025 02:14:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXLsfDen8MTZdU7ZNppSqs0NpTmnUJIuKKt9dn3iyTxpu6hT2tBdmN+YOlVnl/WLvg/MFv18Q==@linaro.org X-Google-Smtp-Source: AGHT+IErTRsKreUkAR3ktSUbJoLANfXcZdAxH27Q4ziZWx/YPGIkhaWNoI8UDgiTDhGeRK2CYMs8 X-Received: by 2002:a05:6102:c0b:b0:4ba:971a:41fd with SMTP id ada2fe7eead31-4c8554810b2mr12672742137.19.1744103659801; Tue, 08 Apr 2025 02:14:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744103659; cv=none; d=google.com; s=arc-20240605; b=UaoES7oS7mYJ686cljdsNdFMSQ2gQUbm+E1/rliNdP5OzIEwv/Uxd9wbBVmdOgHUL7 6m7sW0MuFtrIpKgh91SNd4Cb+14JpTr8iFF4vMfbFokQsWI9dJXQuE2/qPXu/aUjsfz7 wWNvZFcM60F5lUqHf9y5Y0hzlisL0Gs5AyvgjTHpKoKYWXZbm4eFQTgr87vo/KyQQicg s3ZV78ghfd8klTQuL92ePyxC8yBF9EOBKfbgu3pjABdhbKFDj/LkQRR4oHTN+CWmWiBR S3h72ZSyjGGWlyudB0RpmXaFOQhGv2yNZyGhhI3k8xyucIHLSuSOR/jE9KBqutQsdAxQ JtxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=TUt/PdLS+D/EZ0oATS8bLOXTFUuI6RbIUSJ16QFezuw=; fh=EvluKrb5JraKsuwRwt8aVjfmYCMX/yGyNdU7jR+AM5o=; b=DwsKtSCEI5ZbFlRtCsPoE0U/S5U5MhuPAd0pwKxDn9IbVrItlB3FIALQ0p2jH5/L8I iaDUpA9Ft7itMjWkmKS7hA24FCwdWyll2z/94kN7CqttrKh6fHx7LzFC26JrbrU4DppM dPD/07TchystUCDqFXNjrVgeayasx0sPYETldaPJAZvzegk5NmXgnRG6jbOlCu9/GQOy FMUfxTTp2ahXAmAsEx2FnofU+y0zMWadYC3w3YSfPKsXTdHJ3ZFJIHBwMK81/WSMBEdS jN+uMHKlxc84Fel/wE0qwwK+2/Vt6tDVJDbVBnWxH5a2ZkJDOUssww40HBYaH9vDiv9C m6yQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N818rgAR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ada2fe7eead31-4c9b4593e56si348987137.601.2025.04.08.02.14.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 02:14:19 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N818rgAR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9D12D833F6; Tue, 8 Apr 2025 11:13:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="N818rgAR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6DFFF833AD; Tue, 8 Apr 2025 11:13:51 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 210CE833D0 for ; Tue, 8 Apr 2025 11:13:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=neil.armstrong@linaro.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-43d0618746bso38200025e9.2 for ; Tue, 08 Apr 2025 02:13:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744103626; x=1744708426; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=TUt/PdLS+D/EZ0oATS8bLOXTFUuI6RbIUSJ16QFezuw=; b=N818rgAR/qF9hRWnHH+v8Uo1nOTvavzAbkKDvoADskTIocEMfHZHOIOVYDwrMgrjpP inP3+t2JCxEOQBFXuEW1DFIUL+MD5aU0aAjvxOJdmukeJaE9Z7p2DS16vutKj22JPsGl 068mx/xH2lS6m77gfGfXAX+IprO8uhl5w2RNo5ecRgrx/5sXv7jazP71DpuZ0hiTZQHl m3px+ecGhfkjoSGr+9FtJSpeWudAgZ2U8wCAwoutu0bJy9cWiJ/vQGQ6nLzmTPZiMXO+ uE8IGZN4tFOMVLjBiH3Q94O+hIsIsuqQVpNhopxh4bOfZoGr/tLE5/x98YM+yD8+fBH3 lPqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744103626; x=1744708426; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TUt/PdLS+D/EZ0oATS8bLOXTFUuI6RbIUSJ16QFezuw=; b=RgYNTBEJKw3p2eOqrWC7Rr+YP5Jo5V132aAj+N8OsoQ0Z/OpGSJBhaBYib21kyKACu WoRiKkRg6sG2bGKDGZQauFvx4x1JNpzszoY+zdSlhgiQ/Od1FpcaoKdWFa4olbUxPVeP n/1FJ+SWkfM/+ekxCZqwz3WBtEdnFJeArYaQz0hBSkN+ZBza+BntdXHg9CywWdJ7WtRN DXxtc6F84JhCK1scP28RZ5l6cziL3+xbLwn9I/ypXnKdCnrQXiXLuR6Mv1sFiUEnoF+Y LZJDt8gZU49bPd6dnP85UjRNwLmlkpvuuxkiH2ZqhKgKbBYtxatupQH1tUuXn/tkb8KA FBuA== X-Forwarded-Encrypted: i=1; AJvYcCVxUHUV2UD/q7oO9IcJb2GwUwrg0ExnxRtHZx0CO1DMI1uX309r4vYrKqtmUgILyY9mgk/l2m0=@lists.denx.de X-Gm-Message-State: AOJu0YyjatslrHxZpK/aXVP0+OJ40S6GuCWSyv0oHhVsM5xWc2ogaWCP KtkcMZuWrQ7G8sAtMhswsBheKIqJJDqOXP+rtVmQoYpTv4NCQBZtTX062tpPpEnjnfvvlqPrq7G 2 X-Gm-Gg: ASbGncv3KjgIfs7JMqvymMWow+wtBwVGn9UhacX08VbVYufe9M7iAtDU5JbOKwf4ZwZ zpc221IuLVsigZbaZsloA2ZBZVonX26+mQ4ZsTJL4mROBj2P+YASI9Y9/o8kuJmj2S9aFWlawBk WKZe2eNCEhoPvRr5BFgp5Qw2x3dpcJ36UN0Wj2VaOvy+wOtn3hXXOzdQbNX8ve5NPDGKJgvWj4P tB3VNMqSMQaEScKBpd/Ic/+7yZmypvRG1be/scXax/SEkk0BwRd+hbiMmz7yVm4EfyNblSZ9l2Y b21rA0TitkCKYgj7DMelcAKowh6B/yEW7cIGN62GKEKGBZ7LZkkU+SSco34Y31ENRA== X-Received: by 2002:a05:600c:1f0c:b0:43d:4e9:27f3 with SMTP id 5b1f17b1804b1-43ecf85f4bamr137064695e9.9.1744103626628; Tue, 08 Apr 2025 02:13:46 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:3d9:2080:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm155056555e9.39.2025.04.08.02.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 02:13:46 -0700 (PDT) From: Neil Armstrong Date: Tue, 08 Apr 2025 11:13:42 +0200 Subject: [PATCH v2 3/3] block: use part_get_info_cached() API when scanning partitions MIME-Version: 1.0 Message-Id: <20250408-topic-gpt-cache-v2-3-de76e47debb7@linaro.org> References: <20250408-topic-gpt-cache-v2-0-de76e47debb7@linaro.org> In-Reply-To: <20250408-topic-gpt-cache-v2-0-de76e47debb7@linaro.org> To: Tom Rini , Ilias Apalodimas , Heinrich Schuchardt Cc: u-boot-qcom@groups.io, u-boot@lists.denx.de, Neil Armstrong X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2648; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=3VUUXUHHK36WmdgHTTZknhh/dGAKueo+uN8b6XY61Es=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBn9OjHHDceFOj6O2wKRIV6K8UNThk+LkTnkFjdlWTV aNhYlZaJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZ/ToxwAKCRB33NvayMhJ0W64EA CWJbzZNNmCm5/166/40et5aGKK8So68OmFM1oshzu2fplgogH5UFsgCWYBnj7ehCUm+34mbMnIYWzk PTXc2xx8rware8FpDh6HWoYCzh6E1+ABdLXCdws8olduLpVx7qHPZDRIlQlys0ZGBc/+VKKlzh4S7Z ydzrsTjngeRg2TnaJNJn983F5RDSlPxFyLMEQot+LKZGRjVQTzxyze0iGk37bSldJOctb0GfO42enw 9cdxLJhol5vy/s98PoVrMHq6WuP4XYf4VusKE9TeAirFTbV5DSpzKWUeyTHfjfSPeuK9bOje9KfgKY fnhVcSKsxs726VNQvejFZomgNQYsircGWcsS37pVecQdMGzMRPLrwh4YxOy/xDymZrZm8TAe9984Xf Ngw7HcEJs7s4Y5BUexCkQ7wLImydpLXCKh5/lL/CUGr53hmKVcfShUGKQtOaZP4i1MOJK93wag9SjZ meIwzaK+Zgms0cwFhdILZ/ryd1k02GzL2ZOpED3tQxsCgqrO3Ecq7WC5mPng+VVh/0cRsbQh1rNLGv w4H6CLjVC1MgcUkZCO8OKb+WtbkNZ1nGuHXgRQb9/atWNxbWpRzOf8GuOrTW5O1NVoYMgsbevsnXr4 ciydtukKn8HXFHwsuwRiGcSjVicNog5KZVE4DJeTURuyGUoSaQzUeqjUwMHg== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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 --- 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; }