Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1o0kk1-00083R-D3 for mharc-grub-devel@gnu.org; Mon, 13 Jun 2022 10:08:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0kjx-00081S-RQ for grub-devel@gnu.org; Mon, 13 Jun 2022 10:08:26 -0400 Received: from mail.efficios.com ([167.114.26.124]:34602) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0kjv-0003Us-PP for grub-devel@gnu.org; Mon, 13 Jun 2022 10:08:25 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 49B723B192F; Mon, 13 Jun 2022 10:08:22 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 1QIeFPky47dL; Mon, 13 Jun 2022 10:08:22 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id D79103B1917; Mon, 13 Jun 2022 10:08:21 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com D79103B1917 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1655129301; bh=6PhM3UYenJCPijS1HSQZt5FpUV3quhOUIlo9RAf1E/Q=; h=From:To:Date:Message-Id:MIME-Version; b=NEY1W6XLdvjCfizHEE972rv5aAiOd5T32YwP2j6DwPJK26tSZJEbtSjV0gGQkDMfL tBBkPexh+2ASFHWsU6u8wo8SN1msTlHMKIpThfV1gVuEaQJzqsNq4zmFRVWDhmoAa1 J6AawhReSY0topnwAMSFldeVhxRqRl/5ha3d2MGITCzH7FTl3p3x8z99f+QryzMx8o wE8VV2IghotAKwytN842o/wlrytOD4vYOEe1jt0ET9ZsAJ2aewBrg5Q/9MTT6IuTIy /jnMIYhlTZY9mXEJMms0k8yp+DVzpfixVQr7jBS8dis03t6y3vhFVSUr+h8znPCIdo nGTys1/7SAlBQ== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id TsoPpi0KGJXB; Mon, 13 Jun 2022 10:08:21 -0400 (EDT) Received: from thinkos.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by mail.efficios.com (Postfix) with ESMTPSA id 991733B157E; Mon, 13 Jun 2022 10:08:21 -0400 (EDT) From: Mathieu Desnoyers To: grub-devel@gnu.org, Daniel Kiper Cc: Mathieu Desnoyers , Jason Andryuk , xen-devel@lists.xenproject.org Subject: [PATCH v6 2/5] grub-mkconfig linux_xen: Fix quadratic algorithm for sorting menu items Date: Mon, 13 Jun 2022 10:08:23 -0400 Message-Id: <20220613140826.571036-3-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220613140826.571036-1-mathieu.desnoyers@efficios.com> References: <20220613140826.571036-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=167.114.26.124; envelope-from=mathieu.desnoyers@efficios.com; helo=mail.efficios.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jun 2022 14:08:26 -0000 The current implementation of the 20_linux_xen script implements its menu items sorting in bash with a quadratic algorithm, calling "sed", "sort", "head", and "grep" to compare versions between individual lines, which is annoyingly slow for kernel developers who can easily end up with 50-100 kernels in their boot partition. This fix is ported from the 10_linux script, which has a similar quadratic code pattern. Signed-off-by: Mathieu Desnoyers Tested-by: Jason Andryuk Cc: xen-devel@lists.xenproject.org --- Changes since v4: - Combine sed -e '...' -e '...' into sed -e '...; ...' --- util/grub.d/20_linux_xen.in | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index 51a983926..4382303c1 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -237,11 +237,17 @@ esac # yet, so it's empty. In a submenu it will be equal to '\t' (one tab). submenu_indentation=3D"" =20 +# Perform a reverse version sort on the entire xen_list and linux_list. +# Temporarily replace the '.old' suffix by ' 1' and append ' 2' for all +# other files to order the '.old' files after their non-old counterpart +# in reverse-sorted order. + +reverse_sorted_xen_list=3D$(echo ${xen_list} | tr ' ' '\n' | sed -e 's/\= .old$/ 1/; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 2$= //') +reverse_sorted_linux_list=3D$(echo ${linux_list} | tr ' ' '\n' | sed -e = 's/\.old$/ 1/; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s= / 2$//') + is_top_level=3Dtrue =20 -while [ "x${xen_list}" !=3D "x" ] ; do - list=3D"${linux_list}" - current_xen=3D`version_find_latest $xen_list` +for current_xen in ${reverse_sorted_xen_list}; do xen_basename=3D`basename ${current_xen}` xen_dirname=3D`dirname ${current_xen}` rel_xen_dirname=3D`make_system_path_relative_to_its_root $xen_dirnam= e` @@ -273,8 +279,7 @@ while [ "x${xen_list}" !=3D "x" ] ; do fi done =20 - while [ "x$list" !=3D "x" ] ; do - linux=3D`version_find_latest $list` + for linux in ${reverse_sorted_linux_list}; do gettext_printf "Found linux image: %s\n" "$linux" >&2 basename=3D`basename $linux` dirname=3D`dirname $linux` @@ -351,13 +356,10 @@ while [ "x${xen_list}" !=3D "x" ] ; do linux_entry "${OS}" "${version}" "${xen_version}" recovery \ "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE= _XEN}" fi - - list=3D`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '` done if [ x"$is_top_level" !=3D xtrue ]; then echo ' }' fi - xen_list=3D`echo $xen_list | tr ' ' '\n' | fgrep -vx "$current_xen" = | tr '\n' ' '` done =20 # If at least one kernel was found, then we need to --=20 2.30.2