diff mbox series

initramfs-framework: avoid processes when parsing cmdline

Message ID 20260911151416.1946900-1-wenwfu@qti.qualcomm.com
State New
Headers show
Series initramfs-framework: avoid processes when parsing cmdline | expand

Commit Message

Wenwen Fu Sept. 11, 2026, 3:14 p.m. UTC
Use shell parameter expansion rather than external cut and sed commands
while parsing kernel command-line parameters in the initramfs.

On the target initramfs, 100 command-line parser runs took 13.48 s
before this change and 0.51 s afterwards. This reduces the per-run
cost from 134.8 ms to 5.1 ms.

Signed-off-by: Wenwen Fu <wenwfu@qti.qualcomm.com>
---
 meta/recipes-core/initrdscripts/initramfs-framework/init | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Yoann Congal Sept. 11, 2026, 6:56 p.m. UTC | #1
On Fri Sep 11, 2026 at 5:14 PM CEST, Wenwen Fu via lists.openembedded.org wrote:
> Use shell parameter expansion rather than external cut and sed commands
> while parsing kernel command-line parameters in the initramfs.
>
> On the target initramfs, 100 command-line parser runs took 13.48 s
> before this change and 0.51 s afterwards. This reduces the per-run
> cost from 134.8 ms to 5.1 ms.
>
> Signed-off-by: Wenwen Fu <wenwfu@qti.qualcomm.com>
> ---
>  meta/recipes-core/initrdscripts/initramfs-framework/init | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/init b/meta/recipes-core/initrdscripts/initramfs-framework/init
> index 67590ad765..62d8ccfd0c 100755
> --- a/meta/recipes-core/initrdscripts/initramfs-framework/init
> +++ b/meta/recipes-core/initrdscripts/initramfs-framework/init
> @@ -104,13 +104,14 @@ for p in `cat /proc/cmdline`; do
>  		continue
>  	fi
>  
> -	opt=`echo $p | cut -d'=' -f1`
> -	opt=`echo $opt | sed -e 'y/.-/__/'`
> -	if [ "`echo $p | cut -d'=' -f1`" = "$p" ]; then
> +	key=${p%%=*}
> +	opt=${key//./_}

Hello,

Isn't this only available in busybox if and only if it was compiled
with CONFIG_ASH_BASH_COMPAT? Can you check if that works with more
minimal busybox?

> +	opt=${opt//-/_}
> +	if [ "$key" = "$p" ]; then
>  		# opt parameter
>  		eval "bootparam_${opt}=true"
>  	else
> -		value="`echo $p | cut -d'=' -f2-`"	# Option value
> +		value=${p#*=}	# Option value
>  		value_lstripped=${value#\"}
>  		value_rstripped=${value%\"}
>  

Regards,
diff mbox series

Patch

diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/init b/meta/recipes-core/initrdscripts/initramfs-framework/init
index 67590ad765..62d8ccfd0c 100755
--- a/meta/recipes-core/initrdscripts/initramfs-framework/init
+++ b/meta/recipes-core/initrdscripts/initramfs-framework/init
@@ -104,13 +104,14 @@  for p in `cat /proc/cmdline`; do
 		continue
 	fi
 
-	opt=`echo $p | cut -d'=' -f1`
-	opt=`echo $opt | sed -e 'y/.-/__/'`
-	if [ "`echo $p | cut -d'=' -f1`" = "$p" ]; then
+	key=${p%%=*}
+	opt=${key//./_}
+	opt=${opt//-/_}
+	if [ "$key" = "$p" ]; then
 		# opt parameter
 		eval "bootparam_${opt}=true"
 	else
-		value="`echo $p | cut -d'=' -f2-`"	# Option value
+		value=${p#*=}	# Option value
 		value_lstripped=${value#\"}
 		value_rstripped=${value%\"}