diff mbox series

[v6,04/25] spl: semihosting: Don't close fd before spl_load_simple_fit

Message ID 20231106022603.3405551-5-seanga2@gmail.com
State Superseded
Delegated to: Tom Rini
Headers show
Series spl: Use common function for loading/parsing images | expand

Commit Message

Sean Anderson Nov. 6, 2023, 2:25 a.m. UTC
On real hardware, semihosting calls tends to have a large constant
overhead (on the order of tens of milliseconds). Reduce the number of
calls by one by reusing the existing fd in smh_fit_read, and closing it
at the end of spl_smh_load_image.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 common/spl/spl_semihosting.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

Comments

Simon Glass Nov. 8, 2023, 4:23 a.m. UTC | #1
On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> On real hardware, semihosting calls tends to have a large constant
> overhead (on the order of tens of milliseconds). Reduce the number of
> calls by one by reusing the existing fd in smh_fit_read, and closing it
> at the end of spl_smh_load_image.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  common/spl/spl_semihosting.c | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c
index f7dd289286d..8f11c29913f 100644
--- a/common/spl/spl_semihosting.c
+++ b/common/spl/spl_semihosting.c
@@ -24,18 +24,14 @@  static int smh_read_full(long fd, void *memp, size_t len)
 static ulong smh_fit_read(struct spl_load_info *load, ulong file_offset,
 			  ulong size, void *buf)
 {
-	long fd;
+	long fd = *(long *)load->priv;
 	ulong ret;
 
-	fd = smh_open(load->filename, MODE_READ | MODE_BINARY);
-	if (fd < 0) {
-		log_debug("could not open %s: %ld\n", load->filename, fd);
+	if (smh_seek(fd, file_offset))
 		return 0;
-	}
+
 	ret = smh_read(fd, buf, size);
-	smh_close(fd);
-
-	return ret;
+	return ret < 0 ? 0 : ret;
 }
 
 static int spl_smh_load_image(struct spl_image_info *spl_image,
@@ -73,11 +69,11 @@  static int spl_smh_load_image(struct spl_image_info *spl_image,
 		debug("Found FIT\n");
 		load.read = smh_fit_read;
 		load.bl_len = 1;
-		load.filename = filename;
-		load.priv = NULL;
-		smh_close(fd);
+		load.filename = NULL;
+		load.priv = &fd;
 
-		return spl_load_simple_fit(spl_image, &load, 0, header);
+		ret = spl_load_simple_fit(spl_image, &load, 0, header);
+		goto out;
 	}
 
 	ret = spl_parse_image_header(spl_image, bootdev, header);