From c6dfdbad416d3ef34701e77dd04f028e421e0fcb Mon Sep 17 00:00:00 2001 From: chao an Date: Wed, 11 Dec 2024 08:57:54 +0800 Subject: [PATCH] binfmt/loadable: move binary_s to stack to avoid access allocator Improve performance by reducing allocator accesses Signed-off-by: chao an --- binfmt/binfmt_exec.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/binfmt/binfmt_exec.c b/binfmt/binfmt_exec.c index f607dc45b5..6ffc535a3f 100644 --- a/binfmt/binfmt_exec.c +++ b/binfmt/binfmt_exec.c @@ -84,16 +84,22 @@ static int exec_internal(FAR const char *filename, irqstate_t flags; int pid; int ret; +#ifndef CONFIG_BINFMT_LOADABLE + struct binary_s sbin; + + bin = &sbin; +#else /* Allocate the load information */ bin = kmm_zalloc(sizeof(struct binary_s)); - if (!bin) + if (bin == NULL) { berr("ERROR: Failed to allocate binary_s\n"); ret = -ENOMEM; goto errout; } +#endif /* Load the module into memory */ @@ -154,15 +160,9 @@ static int exec_internal(FAR const char *filename, if (ret < 0) { berr("ERROR: Failed to schedule unload '%s': %d\n", filename, ret); + goto errout_with_lock; } -#else - /* Free the binary_s structure here */ - - kmm_free(bin); - - /* TODO: How does the module get unloaded in this case? */ - #endif sched_unlock(); @@ -174,8 +174,10 @@ errout_with_lock: leave_critical_section(flags); unload_module(bin); errout_with_bin: +#ifdef CONFIG_BINFMT_LOADABLE kmm_free(bin); errout: +#endif return ret; }