Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1ns3lZ-0008Bb-0c for mharc-grub-devel@gnu.org; Fri, 20 May 2022 10:38:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ns3lR-00086Y-8E for grub-devel@gnu.org; Fri, 20 May 2022 10:38:02 -0400 Received: from mail.efficios.com ([167.114.26.124]:48416) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ns3lO-00066j-Ug for grub-devel@gnu.org; Fri, 20 May 2022 10:38:00 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 2CD1E3EF507; Fri, 20 May 2022 10:37:54 -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 K6z2fUU2BRbM; Fri, 20 May 2022 10:37:53 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id B3B213EF505; Fri, 20 May 2022 10:37:51 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com B3B213EF505 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1653057471; bh=eKAcUJ3Vwog/U5pko6aDj4DxDE5BHJKJTsP7eji0qRI=; h=From:To:Date:Message-Id:MIME-Version; b=Dalrt/O/csYw6k+1pFLjX1u/7y6LmT2e0VvGO6Z/iLTutpGc44TGfvsfdBK50yhAl dTxcV2n8uOpV7ZXEMI0l33iQ/+au029/3yhJBnpXD0PyRNGvWPK6Hgzd5FZN9rzuT5 6q5cFEHY+u8PcEmfJeZ46fV9pVIt323m+nX5n9ywSMtO8uK/Y31yvwYaIIX7/mtA3Y GOV2UpvEfu8AS3gMUcMY4jUDJUkvcZ2f9W6grMHe0zpnNtKTvS2cBVE53VmsECQrPd 01J1t2kODSEC9jWxzMArK4IIzDpXyjQktX47Ju6/nVjIumWJs8Da4ySIK9u4Qpnkrs 4MHPL49SroLHA== 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 eBm25T-A2ldC; Fri, 20 May 2022 10:37:51 -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 7161A3EF14F; Fri, 20 May 2022 10:37:50 -0400 (EDT) From: Mathieu Desnoyers To: grub-devel@gnu.org Cc: Mathieu Desnoyers , xen-devel@lists.xenproject.org Subject: [RFC PATCH v3 2/5] grub-mkconfig linux_xen: Fix quadratic algorithm for sorting menu items Date: Fri, 20 May 2022 10:37:38 -0400 Message-Id: <20220520143741.217690-3-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220520143741.217690-1-mathieu.desnoyers@efficios.com> References: <20220520143741.217690-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: Fri, 20 May 2022 14:38:03 -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. [ Note: this is untested. I would be grateful if anyone with a Xen environment could test it before it is merged. ] Signed-off-by: Mathieu Desnoyers Cc: xen-devel@lists.xenproject.org --- 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 f45559ff8..3178eb430 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/' -e '/ 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/' -= e 's/ 2$//') +reverse_sorted_linux_list=3D$(echo ${linux_list} | tr ' ' '\n' | sed -e = 's/\.old$/ 1/' -e '/ 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old= /' -e '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` @@ -349,13 +354,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