From nobody Sat Apr 20 14:04:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69587+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69587+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609774974; cv=none; d=zohomail.com; s=zohoarc; b=eJg1RVvXXSQaVYIZDYkLESY68POPywZumlRw826WKlJYr4bSLWiQZCFY/Lxc496dETy7syYQKYbO9BS09v2eh05//0jVmLgscn5M5hsOOcedDIF+VXJcU2L6bemQGzsovwfuTQC+M+c773hdJegqy+BVc9bRVwKT4kgsNJoPJhw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609774974; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=DRH6yubsOnlioNU8qaZaF7Cwxzwr9NGfBRLn39GNQfQ=; b=VWFews7/ZB8BJKESmsGOH8GhgATyA08E0gcR4M2i7Lwl5miNhPVx5ekdRJysOqr0+bWOiIjmrhcPzVf7gagIwmaMxFzbW9Fvae06NKPhyZSYuiCv81+j6Ksn9aJ7+glY5uW5Kqdt4tP/Q/ByMpna+kdXbJq4CVyr3yCq/tjeWms= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69587+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609774974343446.42491729794483; Mon, 4 Jan 2021 07:42:54 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id EXUAYY1788612xPhj1G4mqSd; Mon, 04 Jan 2021 07:42:53 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web10.15222.1609774972409313347 for ; Mon, 04 Jan 2021 07:42:52 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-DDp83wNBMUywQrBvtH_pYg-1; Mon, 04 Jan 2021 10:42:42 -0500 X-MC-Unique: DDp83wNBMUywQrBvtH_pYg-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47C2714552B; Mon, 4 Jan 2021 15:42:41 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-80.ams2.redhat.com [10.36.113.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26B82100239A; Mon, 4 Jan 2021 15:42:39 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Ray Ni , Zhichao Gao Subject: [edk2-devel] [PATCH 1/8] ShellPkg/Comp: add file buffering Date: Mon, 4 Jan 2021 16:42:28 +0100 Message-Id: <20210104154235.31785-2-lersek@redhat.com> In-Reply-To: <20210104154235.31785-1-lersek@redhat.com> References: <20210104154235.31785-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: iXR2VM8ZbYDMqrSuqsYm68Kzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609774973; bh=DRH6yubsOnlioNU8qaZaF7Cwxzwr9NGfBRLn39GNQfQ=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=KFYRwcFXA3uuAniKWarx5PQYXWxJLvVGOjtWDwqyyPtdy6e50daWSCU1tdwWS4YlUiI rl4T9NVOVgiCdKOVtAOSWeu2dxhwPq3uijCkbH1eDszxAI4/s66VtszTMpJzHQjp2Ynr6 bA1Oy1R9nF37sQLgoV/YGT8kQ6mt21twYIw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The COMP shell command compares two files byte for byte. In order to retrieve the bytes to compare, it currently invokes gEfiShellProtocol->ReadFile() on both files, using a single-byte buffer every time. This is very inefficient; the underlying EFI_FILE_PROTOCOL.Read() function may be costly. Read both file operands in chunks of "PcdShellFileOperationSize" bytes. Draw bytes for comparison from the internal read-ahead buffers. Some ad-hoc measurements on my laptop, using OVMF, and the 4KB default of "PcdShellFileOperationSize": - When comparing two identical 1MB files that are served by EnhancedFatDxe on top of VirtioScsiDxe, this patch brings no noticeable improvement; the comparison completes in <1s both before and after. - When comparing two identical 1MB files served by VirtioFsDxe, the comparison time improves from 2 minutes 25 seconds to <1s. Cc: Philippe Mathieu-Daud=C3=A9 Cc: Ray Ni Cc: Zhichao Gao Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3123 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel Reviewed-by: Zhichao Gao --- ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf= | 1 + ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c = | 127 +++++++++++++++++++- 2 files changed, 125 insertions(+), 3 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Com= mandsLib.inf b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1C= ommandsLib.inf index ed94477a0642..74ad5facf6b1 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.inf +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.inf @@ -113,6 +113,7 @@ [LibraryClasses] BcfgCommandLib =20 [Pcd] + gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize ## CONSUMES gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask ## CONSUMES =20 [Protocols] diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c b/ShellPkg/= Library/UefiShellDebug1CommandsLib/Comp.c index 0a5d13f01c7b..0df0b3149369 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c @@ -21,6 +21,16 @@ typedef enum { InPrevDiffPoint } READ_STATUS; =20 +// +// Buffer type, for reading both file operands in chunks. +// +typedef struct { + UINT8 *Data; // dynamically allocated buffer + UINTN Allocated; // the allocated size of Data + UINTN Next; // next position in Data to fetch a byte at + UINTN Left; // number of bytes left in Data for fetching at Next +} FILE_BUFFER; + /** Function to print differnt point data. =20 @@ -76,6 +86,106 @@ PrintDifferentPoint( ShellPrintEx (-1, -1, L"*\r\n"); } =20 +/** + Initialize a FILE_BUFFER. + + @param[out] FileBuffer The FILE_BUFFER to initialize. On return, the ca= ller + is responsible for checking FileBuffer->Data: if + FileBuffer->Data is NULL on output, then memory + allocation failed. +**/ +STATIC +VOID +FileBufferInit ( + OUT FILE_BUFFER *FileBuffer + ) +{ + FileBuffer->Allocated =3D PcdGet32 (PcdShellFileOperationSize); + FileBuffer->Data =3D AllocatePool (FileBuffer->Allocated); + FileBuffer->Left =3D 0; +} + +/** + Uninitialize a FILE_BUFFER. + + @param[in,out] FileBuffer The FILE_BUFFER to uninitialize. The caller is + responsible for making sure FileBuffer was fi= rst + initialized with FileBufferInit(), successful= ly or + unsuccessfully. +**/ +STATIC +VOID +FileBufferUninit ( + IN OUT FILE_BUFFER *FileBuffer + ) +{ + SHELL_FREE_NON_NULL (FileBuffer->Data); +} + +/** + Read a byte from a SHELL_FILE_HANDLE, buffered with a FILE_BUFFER. + + @param[in] FileHandle The SHELL_FILE_HANDLE to replenish FileBuffer + from, if needed. + + @param[in,out] FileBuffer The FILE_BUFFER to read a byte from. If FileB= uffer + is empty on entry, then FileBuffer is refilled + from FileHandle, before outputting a byte from + FileBuffer to Byte. The caller is responsible= for + ensuring that FileBuffer was successfully + initialized with FileBufferInit(). + + @param[out] BytesRead On successful return, BytesRead is set to 1 i= f the + next byte from FileBuffer has been stored to = Byte. + On successful return, BytesRead is set to 0 if + FileBuffer is empty, and FileHandle is at EOF. + When an error is returned, BytesRead is not s= et. + + @param[out] Byte On output, the next byte from FileBuffer. Onl= y set + if (a) EFI_SUCCESS is returned and (b) BytesR= ead + is set to 1 on output. + + @retval EFI_SUCCESS BytesRead has been set to 0 or 1. In the latter cas= e, + Byte has been set as well. + + @return Error codes propagated from + gEfiShellProtocol->ReadFile(). +**/ +STATIC +EFI_STATUS +FileBufferReadByte ( + IN SHELL_FILE_HANDLE FileHandle, + IN OUT FILE_BUFFER *FileBuffer, + OUT UINTN *BytesRead, + OUT UINT8 *Byte + ) +{ + UINTN ReadSize; + EFI_STATUS Status; + + if (FileBuffer->Left =3D=3D 0) { + ReadSize =3D FileBuffer->Allocated; + Status =3D gEfiShellProtocol->ReadFile (FileHandle, &ReadSize, + FileBuffer->Data); + if (EFI_ERROR (Status)) { + return Status; + } + if (ReadSize =3D=3D 0) { + *BytesRead =3D 0; + return EFI_SUCCESS; + } + FileBuffer->Next =3D 0; + FileBuffer->Left =3D ReadSize; + } + + *BytesRead =3D 1; + *Byte =3D FileBuffer->Data[FileBuffer->Next]; + + FileBuffer->Next++; + FileBuffer->Left--; + return EFI_SUCCESS; +} + /** Function for 'comp' command. =20 @@ -107,6 +217,8 @@ ShellCommandRunComp ( UINT8 OneByteFromFile2; UINT8 *DataFromFile1; UINT8 *DataFromFile2; + FILE_BUFFER FileBuffer1; + FILE_BUFFER FileBuffer2; UINTN InsertPosition1; UINTN InsertPosition2; UINTN DataSizeFromFile1; @@ -234,10 +346,15 @@ ShellCommandRunComp ( if (ShellStatus =3D=3D SHELL_SUCCESS) { DataFromFile1 =3D AllocateZeroPool ((UINTN)DifferentBytes); DataFromFile2 =3D AllocateZeroPool ((UINTN)DifferentBytes); - if (DataFromFile1 =3D=3D NULL || DataFromFile2 =3D=3D NULL) { + FileBufferInit (&FileBuffer1); + FileBufferInit (&FileBuffer2); + if (DataFromFile1 =3D=3D NULL || DataFromFile2 =3D=3D NULL || + FileBuffer1.Data =3D=3D NULL || FileBuffer2.Data =3D=3D NULL) { ShellStatus =3D SHELL_OUT_OF_RESOURCES; SHELL_FREE_NON_NULL (DataFromFile1); SHELL_FREE_NON_NULL (DataFromFile2); + FileBufferUninit (&FileBuffer1); + FileBufferUninit (&FileBuffer2); } } =20 @@ -247,9 +364,11 @@ ShellCommandRunComp ( DataSizeFromFile2 =3D 1; OneByteFromFile1 =3D 0; OneByteFromFile2 =3D 0; - Status =3D gEfiShellProtocol->ReadFile (FileHandle1, &DataSizeFr= omFile1, &OneByteFromFile1); + Status =3D FileBufferReadByte (FileHandle1, &FileBuffer1, + &DataSizeFromFile1, &OneByteFromFile1); ASSERT_EFI_ERROR (Status); - Status =3D gEfiShellProtocol->ReadFile (FileHandle2, &DataSizeFr= omFile2, &OneByteFromFile2); + Status =3D FileBufferReadByte (FileHandle2, &FileBuffer2, + &DataSizeFromFile2, &OneByteFromFile2); ASSERT_EFI_ERROR (Status); =20 TempAddress++; @@ -346,6 +465,8 @@ ShellCommandRunComp ( =20 SHELL_FREE_NON_NULL (DataFromFile1); SHELL_FREE_NON_NULL (DataFromFile2); + FileBufferUninit (&FileBuffer1); + FileBufferUninit (&FileBuffer2); =20 if (DiffPointNumber =3D=3D 0) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_PASS= ), gShellDebug1HiiHandle); --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69587): https://edk2.groups.io/g/devel/message/69587 Mute This Topic: https://groups.io/mt/79426445/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat Apr 20 14:04:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69584+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69584+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609774975; cv=none; d=zohomail.com; s=zohoarc; b=jUY6PlrtQvmhYufXQ0UIPlyNoDGA67rpi7mhS+MEYW72BxjNCAs0TYTNKPRKyzNMpQAw0rtLKP06asa3n2Bs/oUf59Q1Fm4ZvLzJSJamW3+gVZwGvPlI9X2DSzaBp0qCqd6MrOgtSwq9SjSeVMod7ovynj+Slbgv79BjrBEE9Mk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609774975; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Me3wHJBsygav/Qa6cO1KMT+xa01hnOLLtqXcpQVSvhk=; b=DeycggK7b5McxeTM0OC00wF9hMoZNMn44gd/EfURzgO9mvEJ6Y/4jdME00Oddpg2zUq+hxqDvPpTYWdqehanOqw5FBQV3+GnfXhr41PZpgYiQ1jiUVGVlTYQzx/C9BDs4rKSu5uVDP/qjNVvG+xzmiFKxRmShNxO9KyH3IdBmnE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69584+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609774975852946.5443596704968; Mon, 4 Jan 2021 07:42:55 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ADLIYY1788612xhGo4sjV2yc; Mon, 04 Jan 2021 07:42:55 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web11.15134.1609774971807183225 for ; Mon, 04 Jan 2021 07:42:52 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-589-b8Zo4A77NhmA_nlK3yYanw-1; Mon, 04 Jan 2021 10:42:46 -0500 X-MC-Unique: b8Zo4A77NhmA_nlK3yYanw-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 15FC5800D53; Mon, 4 Jan 2021 15:42:45 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-80.ams2.redhat.com [10.36.113.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9B1D100239A; Mon, 4 Jan 2021 15:42:43 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [PATCH 2/8] OvmfPkg: raise PcdShellFileOperationSize to 128KB Date: Mon, 4 Jan 2021 16:42:29 +0100 Message-Id: <20210104154235.31785-3-lersek@redhat.com> In-Reply-To: <20210104154235.31785-1-lersek@redhat.com> References: <20210104154235.31785-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: OBK9rIPgGJml8QR8lv4TwAG2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609774975; bh=Me3wHJBsygav/Qa6cO1KMT+xa01hnOLLtqXcpQVSvhk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=NyANOg+E6BPZNBadevIlah182fQR0jZUA/XqkUyw2eKwjNx24DBu2i52N4abXdJ2xI+ vZ3AHw5vUwRRX51IsbX9HqO3uxY1rTLj9HZMpvf7tYEnUzgChsgQN+80GzSUXoktYLeqk oMPkT/HLUDigX47bxekp+SKufCdWEX6LvkY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Some UEFI shell commands read and write files in chunks. The chunk size is given by "PcdShellFileOperationSize", whose default in "ShellPkg/ShellPkg.dec" is 4KB (0x1000). The virtio-fs daemon of QEMU advertizes a 128KB maximum buffer size by default, for the FUSE_WRITE operation. By raising PcdShellFileOperationSize 32-fold, the number of FUSE write requests shrinks proportionately, when writing large files. And when a Virtio Filesystem is not used, a 128KB chunk size is still not particularly wasteful. Some ad-hoc measurements on my laptop, using OVMF: - The time it takes to copy a ~270MB file from a Virtio Filesystem to the same Virtio Filesystem improves from ~9 seconds to ~1 second. - The time it takes to compare two identical ~270MB files on the same Virtio Filesystem improves from ~11 seconds to ~3 seconds. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3125 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/OvmfPkgIa32.dsc | 2 ++ OvmfPkg/OvmfPkgIa32X64.dsc | 2 ++ OvmfPkg/OvmfPkgX64.dsc | 2 ++ 3 files changed, 6 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 26a013ec353e..cd0acf021459 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -560,6 +560,8 @@ [PcdsFixedAtBuild] # !include NetworkPkg/NetworkPcds.dsc.inc =20 + gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize|0x20000 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackSize|0x4000 !endif diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 10579fe46c5b..3bf493bdb08f 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -566,6 +566,8 @@ [PcdsFixedAtBuild.X64] # !include NetworkPkg/NetworkPcds.dsc.inc =20 + gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize|0x20000 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackSize|0x4000 !endif diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index c9235e48ad62..cebdbc9faabe 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -564,6 +564,8 @@ [PcdsFixedAtBuild] # !include NetworkPkg/NetworkPcds.dsc.inc =20 + gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize|0x20000 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackSize|0x4000 !endif --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69584): https://edk2.groups.io/g/devel/message/69584 Mute This Topic: https://groups.io/mt/79426442/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat Apr 20 14:04:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69585+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69585+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609774977; cv=none; d=zohomail.com; s=zohoarc; b=hYV51YwyGvICanj+kK7pAf1fHQT3xNKpibS0W27vKtvB8RwyM/0TU1HJEFpsvVAT0AvkykkC/JayoD97CqjLBOlCkxBqEjt59ocNTHqaxH579Qd5F5zrgJdAuxvwM/FoUtnB/JM5R5mDROevTw6lrffBqiVtM2dfzPmUHuHaQ+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609774977; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=D7mDNu7rqIydHOj1e+YuI97FBQJpOX9xaq+2gHMAphw=; b=YCMc6mfRO650Gs+lbo1LZ6F/lU8ydQi/MtCXNGYrfXEdBRguAfdnGqbFbQJM0c2MkYUHsFNieoeMxLdrcJyZ0ZSOamBFAGGbDYQ9FuqTTLhnxlFD7sHwOlfAr7sOJSwAhRXQCRQ3h0pGjeS5AijmTOwn+XFvMGOtGG9bw/c7PkE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69585+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609774977113164.3607065758789; Mon, 4 Jan 2021 07:42:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id puP2YY1788612xIr3h7nUHSR; Mon, 04 Jan 2021 07:42:56 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.15394.1609774972187317251 for ; Mon, 04 Jan 2021 07:42:52 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-61-gYRcqRfCO8mXHztwE9omHg-1; Mon, 04 Jan 2021 10:42:47 -0500 X-MC-Unique: gYRcqRfCO8mXHztwE9omHg-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F9681005504; Mon, 4 Jan 2021 15:42:46 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-80.ams2.redhat.com [10.36.113.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D17D10016FE; Mon, 4 Jan 2021 15:42:45 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Ard Biesheuvel , Leif Lindholm , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [PATCH 3/8] ArmVirtPkg: raise PcdShellFileOperationSize to 128KB Date: Mon, 4 Jan 2021 16:42:30 +0100 Message-Id: <20210104154235.31785-4-lersek@redhat.com> In-Reply-To: <20210104154235.31785-1-lersek@redhat.com> References: <20210104154235.31785-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: Ok0kb3yUXTuJAqxKkOjwak4ex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609774976; bh=D7mDNu7rqIydHOj1e+YuI97FBQJpOX9xaq+2gHMAphw=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=P/CNjm+wut/X3UNyTK5klNj0rwjsDFZ2gbdExp962hSA24Qp1lD0A2LkYDnKxjjZIf2 3Ekn/eU4O+ctUsyRSRgY+nPDCaxTBSKN2D2WDeZg7YtYdLiueoyree8z6rmg+PL8wvo3H 6K9oBrfVscqgPoOLGN/4lNFrcpjsCKL90Y0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Some UEFI shell commands read and write files in chunks. The chunk size is given by "PcdShellFileOperationSize", whose default in "ShellPkg/ShellPkg.dec" is 4KB (0x1000). The virtio-fs daemon of QEMU advertizes a 128KB maximum buffer size by default, for the FUSE_WRITE operation. By raising PcdShellFileOperationSize 32-fold, the number of FUSE write requests shrinks proportionately, when writing large files. And when a Virtio Filesystem is not used, a 128KB chunk size is still not particularly wasteful. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3125 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- ArmVirtPkg/ArmVirtQemu.dsc | 1 + ArmVirtPkg/ArmVirtQemuKernel.dsc | 1 + 2 files changed, 2 insertions(+) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index ef5d6dbeaddc..b8bc08d73921 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -204,6 +204,7 @@ [PcdsFixedAtBuild.common] !endif =20 gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|3 + gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize|0x20000 =20 [PcdsFixedAtBuild.AARCH64] # Clearing BIT0 in this PCD prevents installing a 32-bit SMBIOS entry po= int, diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index f8f5f7f4b94b..2ef86f96688f 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -174,6 +174,7 @@ [PcdsFixedAtBuild.common] !endif =20 gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|3 + gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize|0x20000 =20 [PcdsPatchableInModule.common] # we need to provide a resolution for this PCD that supports PcdSet64() --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69585): https://edk2.groups.io/g/devel/message/69585 Mute This Topic: https://groups.io/mt/79426443/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat Apr 20 14:04:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69586+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69586+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609774975; cv=none; d=zohomail.com; s=zohoarc; b=NU9Gg0LHlJwhQL18C2GgwUwN4mSNtTojcygESNm3a+4XrueSP3KyV0ISAofMXzbs6pF1v6FCRmjLhXB7crEmdbrTATMH3IZ9USIMe1N39ujJ7hrzqD8hIVDKT6b5v7iQ/4FJrEPbfK9kcU4zWxsVjfa7NtdgN0SBvnGlbr7eFxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609774975; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=A9z37cpCshvDMKpofkxcec4RLs5ljJ8/9pkTNK4ctUo=; b=Ll4EtlyNVPkcLO1OogEDuraEodd4G1i+cveZI8FT4Qf48GS6p1VJAp3yCdOha30hhdNr2CL6qYRMnDEEoqBVmvCm6dz2W7Q8PK3QgOKOqT+hqf1vNYYXm/oYqVURi2rB2eUUDQvgK6rOePr617mh0nG8OPGVDf9WqrOQjN9qNOQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69586+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609774975372915.0534576966953; Mon, 4 Jan 2021 07:42:55 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id gaN3YY1788612xiT39CurTSh; Mon, 04 Jan 2021 07:42:54 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web11.15135.1609774971991679839 for ; Mon, 04 Jan 2021 07:42:52 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-250-oUcqXsOCPzybhC8EZcl_Nw-1; Mon, 04 Jan 2021 10:42:49 -0500 X-MC-Unique: oUcqXsOCPzybhC8EZcl_Nw-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3F136145528; Mon, 4 Jan 2021 15:42:48 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-80.ams2.redhat.com [10.36.113.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4E13100239A; Mon, 4 Jan 2021 15:42:46 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Ray Ni , Zhichao Gao Subject: [edk2-devel] [PATCH 4/8] ShellPkg/ShellCommandLib: add ShellSortFileList() Date: Mon, 4 Jan 2021 16:42:31 +0100 Message-Id: <20210104154235.31785-5-lersek@redhat.com> In-Reply-To: <20210104154235.31785-1-lersek@redhat.com> References: <20210104154235.31785-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: R7UK5sVA3lTbQv5e5m3XxGDIx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609774974; bh=A9z37cpCshvDMKpofkxcec4RLs5ljJ8/9pkTNK4ctUo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=c7BkXZY83131uUd+oq+IbDQfR+YkkdPIVdFbc6C7q2iQDPr7oYQeyoN20lMSW4coq6f 9k5WfbRCeJeQJ2KKqTC6HKa5i9ec0NfM9zxoD2VrPAJGHgT9wjYY/3aW7m0y/KRRkK9nC yTYivvK4Zf7DtEeWb86q12aeF9udZ5TOHUU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Introduce the ShellSortFileList() function, for sorting an EFI_SHELL_FILE_INFO list, by FileName or by FullName. Duplicates can be kept in the same list, or separated out to a new list. In either case, the relative order between duplicates does not change (the sorting is stable). For the sorting, use OrderedCollectionLib rather than SortLib: - The PerformQuickSort() function from the latter has quadratic worst-case time complexity, plus it is implemented recursively (see "MdeModulePkg/Library/UefiSortLib/UefiSortLib.c"). It can also not return an error on memory allocation failure. - In comparison, the Red-Black Tree instance of OrderedCollectionLib sorts in O(n*log(n)) worst-case time, contains no recursion with the default PcdValidateOrderedCollection=3DFALSE setting, and the OrderedCollectionLib class APIs return errors appropriately. The OrderedCollectionLib APIs do not permit duplicates natively, but by using lists as collection entries, stable sorting of duplicates can be achieved. Cc: Philippe Mathieu-Daud=C3=A9 Cc: Ray Ni Cc: Zhichao Gao Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3151 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel Reviewed-by: Zhichao Gao --- ShellPkg/ShellPkg.dsc | 1 + ShellPkg/Include/Library/ShellCommandLib.h | 81 +++++ ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf | 1 + ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h | 19 ++ ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c | 312 +++++++= +++++++++++++ 5 files changed, 414 insertions(+) diff --git a/ShellPkg/ShellPkg.dsc b/ShellPkg/ShellPkg.dsc index c42bc9464a0f..a8b6de334284 100644 --- a/ShellPkg/ShellPkg.dsc +++ b/ShellPkg/ShellPkg.dsc @@ -47,6 +47,7 @@ [LibraryClasses.common] ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib= .inf ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsing= Lib.inf + OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib= /BaseOrderedCollectionRedBlackTreeLib.inf =20 PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeC= offGetEntryPointLib.inf BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCom= mandLib.inf diff --git a/ShellPkg/Include/Library/ShellCommandLib.h b/ShellPkg/Include/= Library/ShellCommandLib.h index 63fcac82a2de..bc1afed5e7f5 100644 --- a/ShellPkg/Include/Library/ShellCommandLib.h +++ b/ShellPkg/Include/Library/ShellCommandLib.h @@ -714,4 +714,85 @@ CatSDumpHex ( IN UINTN DataSize, IN VOID *UserData ); + +// +// Determines the ordering operation for ShellSortFileList(). +// +typedef enum { + // + // Sort the EFI_SHELL_FILE_INFO objects by the FileName field, in increa= sing + // order, using gUnicodeCollation->StriColl(). + // + ShellSortFileListByFileName, + // + // Sort the EFI_SHELL_FILE_INFO objects by the FullName field, in increa= sing + // order, using gUnicodeCollation->StriColl(). + // + ShellSortFileListByFullName, + ShellSortFileListMax +} SHELL_SORT_FILE_LIST; + +/** + Sort an EFI_SHELL_FILE_INFO list, optionally moving duplicates to a sepa= rate + list. + + @param[in,out] FileList The list of EFI_SHELL_FILE_INFO objects to sort. + + If FileList is NULL on input, then FileList is + considered an empty, hence already sorted, list. + + Otherwise, if (*FileList) is NULL on input, then + EFI_INVALID_PARAMETER is returned. + + Otherwise, the caller is responsible for having + initialized (*FileList)->Link with + InitializeListHead(). No other fields in the + (**FileList) head element are accessed by this + function. + + On output, (*FileList) is sorted according to O= rder. + If Duplicates is NULL on input, then duplicate + elements are preserved, sorted stably, on + (*FileList). If Duplicates is not NULL on input, + then duplicates are moved (stably sorted) to the + new, dynamically allocated (*Duplicates) list. + + @param[out] Duplicates If Duplicates is NULL on input, (*FileList) wil= l be + a monotonically ordered list on output, with + duplicates stably sorted. + + If Duplicates is not NULL on input, (*FileList)= will + be a strictly monotonically oredered list on ou= tput, + with duplicates separated (stably sorted) to + (*Duplicates). All fields except Link will be + zero-initialized in the (**Duplicates) head ele= ment. + If no duplicates exist, then (*Duplicates) is s= et to + NULL on output. + + @param[in] Order Determines the comparison operation between + EFI_SHELL_FILE_INFO objects. + + @retval EFI_INVALID_PARAMETER (UINTN)Order is greater than or equal to + (UINTN)ShellSortFileListMax. Neither the + (*FileList) nor the (*Duplicates) list has + been modified. + + @retval EFI_INVALID_PARAMETER (*FileList) was NULL on input. Neither the + (*FileList) nor the (*Duplicates) list has + been modified. + + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. Neither the + (*FileList) nor the (*Duplicates) list has + been modified. + + @retval EFI_SUCCESS Sorting successful, including the case wh= en + FileList is NULL on input. +**/ +EFI_STATUS +EFIAPI +ShellSortFileList ( + IN OUT EFI_SHELL_FILE_INFO **FileList, + OUT EFI_SHELL_FILE_INFO **Duplicates OPTIONAL, + IN SHELL_SORT_FILE_LIST Order + ); #endif //_SHELL_COMMAND_LIB_ diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf b= /ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf index a1b5601c96b6..08ca7cb78842 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf @@ -42,6 +42,7 @@ [LibraryClasses] ShellLib HiiLib HandleParsingLib + OrderedCollectionLib =20 [Protocols] gEfiUnicodeCollation2ProtocolGuid ## CONSUMES diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h b/S= hellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h index 8ecc2f6bf5a2..0ca291e4f9bf 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h @@ -39,6 +39,7 @@ #include #include #include +#include =20 typedef struct{ LIST_ENTRY Link; @@ -60,6 +61,24 @@ typedef struct { CHAR16 *Path; } SHELL_COMMAND_FILE_HANDLE; =20 +// +// Collects multiple EFI_SHELL_FILE_INFO objects that share the same name. +// +typedef struct { + // + // A string that compares equal to either the FileName or the FullName f= ields + // of all EFI_SHELL_FILE_INFO objects on SameNameList, according to + // gUnicodeCollation->StriColl(). The string is not dynamically allocate= d; + // instead, it *aliases* the FileName or FullName field of the + // EFI_SHELL_FILE_INFO object that was first encountered with this name. + // + CONST CHAR16 *Alias; + // + // A list of EFI_SHELL_FILE_INFO objects whose FileName or FullName fiel= ds + // compare equal to Alias, according to gUnicodeCollation->StriColl(). + // + LIST_ENTRY SameNameList; +} SHELL_SORT_UNIQUE_NAME; =20 #endif //_UEFI_COMMAND_LIB_INTERNAL_HEADER_ =20 diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/S= hellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c index 345808a1eac6..b06d22592d33 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c @@ -1909,3 +1909,315 @@ CatSDumpHex ( =20 return RetVal; } + +/** + ORDERED_COLLECTION_USER_COMPARE function for SHELL_SORT_UNIQUE_NAME obje= cts. + + @param[in] Unique1AsVoid The first SHELL_SORT_UNIQUE_NAME object (Uniqu= e1), + passed in as a pointer-to-VOID. + + @param[in] Unique2AsVoid The second SHELL_SORT_UNIQUE_NAME object (Uniq= ue2), + passed in as a pointer-to-VOID. + + @retval <0 If Unique1 compares less than Unique2. + + @retval 0 If Unique1 compares equal to Unique2. + + @retval >0 If Unique1 compares greater than Unique2. +**/ +STATIC +INTN +EFIAPI +UniqueNameCompare ( + IN CONST VOID *Unique1AsVoid, + IN CONST VOID *Unique2AsVoid + ) +{ + CONST SHELL_SORT_UNIQUE_NAME *Unique1; + CONST SHELL_SORT_UNIQUE_NAME *Unique2; + + Unique1 =3D Unique1AsVoid; + Unique2 =3D Unique2AsVoid; + + // + // We need to cast away CONST for EFI_UNICODE_COLLATION_STRICOLL. + // + return gUnicodeCollation->StriColl ( + gUnicodeCollation, + (CHAR16 *)Unique1->Alias, + (CHAR16 *)Unique2->Alias + ); +} + +/** + ORDERED_COLLECTION_KEY_COMPARE function for SHELL_SORT_UNIQUE_NAME objec= ts. + + @param[in] UniqueAliasAsVoid The CHAR16 string UniqueAlias, passed in a= s a + pointer-to-VOID. + + @param[in] UniqueAsVoid The SHELL_SORT_UNIQUE_NAME object (Unique), + passed in as a pointer-to-VOID. + + @retval <0 If UniqueAlias compares less than Unique->Alias. + + @retval 0 If UniqueAlias compares equal to Unique->Alias. + + @retval >0 If UniqueAlias compares greater than Unique->Alias. +**/ +STATIC +INTN +EFIAPI +UniqueNameAliasCompare ( + IN CONST VOID *UniqueAliasAsVoid, + IN CONST VOID *UniqueAsVoid + ) +{ + CONST CHAR16 *UniqueAlias; + CONST SHELL_SORT_UNIQUE_NAME *Unique; + + UniqueAlias =3D UniqueAliasAsVoid; + Unique =3D UniqueAsVoid; + + // + // We need to cast away CONST for EFI_UNICODE_COLLATION_STRICOLL. + // + return gUnicodeCollation->StriColl ( + gUnicodeCollation, + (CHAR16 *)UniqueAlias, + (CHAR16 *)Unique->Alias + ); +} + +/** + Sort an EFI_SHELL_FILE_INFO list, optionally moving duplicates to a sepa= rate + list. + + @param[in,out] FileList The list of EFI_SHELL_FILE_INFO objects to sort. + + If FileList is NULL on input, then FileList is + considered an empty, hence already sorted, list. + + Otherwise, if (*FileList) is NULL on input, then + EFI_INVALID_PARAMETER is returned. + + Otherwise, the caller is responsible for having + initialized (*FileList)->Link with + InitializeListHead(). No other fields in the + (**FileList) head element are accessed by this + function. + + On output, (*FileList) is sorted according to O= rder. + If Duplicates is NULL on input, then duplicate + elements are preserved, sorted stably, on + (*FileList). If Duplicates is not NULL on input, + then duplicates are moved (stably sorted) to the + new, dynamically allocated (*Duplicates) list. + + @param[out] Duplicates If Duplicates is NULL on input, (*FileList) wil= l be + a monotonically ordered list on output, with + duplicates stably sorted. + + If Duplicates is not NULL on input, (*FileList)= will + be a strictly monotonically oredered list on ou= tput, + with duplicates separated (stably sorted) to + (*Duplicates). All fields except Link will be + zero-initialized in the (**Duplicates) head ele= ment. + If no duplicates exist, then (*Duplicates) is s= et to + NULL on output. + + @param[in] Order Determines the comparison operation between + EFI_SHELL_FILE_INFO objects. + + @retval EFI_INVALID_PARAMETER (UINTN)Order is greater than or equal to + (UINTN)ShellSortFileListMax. Neither the + (*FileList) nor the (*Duplicates) list has + been modified. + + @retval EFI_INVALID_PARAMETER (*FileList) was NULL on input. Neither the + (*FileList) nor the (*Duplicates) list has + been modified. + + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. Neither the + (*FileList) nor the (*Duplicates) list has + been modified. + + @retval EFI_SUCCESS Sorting successful, including the case wh= en + FileList is NULL on input. +**/ +EFI_STATUS +EFIAPI +ShellSortFileList ( + IN OUT EFI_SHELL_FILE_INFO **FileList, + OUT EFI_SHELL_FILE_INFO **Duplicates OPTIONAL, + IN SHELL_SORT_FILE_LIST Order + ) +{ + LIST_ENTRY *FilesHead; + ORDERED_COLLECTION *Sort; + LIST_ENTRY *FileEntry; + EFI_SHELL_FILE_INFO *FileInfo; + SHELL_SORT_UNIQUE_NAME *Unique; + EFI_STATUS Status; + EFI_SHELL_FILE_INFO *Dupes; + LIST_ENTRY *NextFileEntry; + CONST CHAR16 *Alias; + ORDERED_COLLECTION_ENTRY *SortEntry; + LIST_ENTRY *TargetFileList; + ORDERED_COLLECTION_ENTRY *NextSortEntry; + VOID *UniqueAsVoid; + + if ((UINTN)Order >=3D (UINTN)ShellSortFileListMax) { + return EFI_INVALID_PARAMETER; + } + + if (FileList =3D=3D NULL) { + // + // FileList is considered empty, hence already sorted, with no duplica= tes. + // + if (Duplicates !=3D NULL) { + *Duplicates =3D NULL; + } + return EFI_SUCCESS; + } + + if (*FileList =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + FilesHead =3D &(*FileList)->Link; + + // + // Collect all the unique names. + // + Sort =3D OrderedCollectionInit (UniqueNameCompare, UniqueNameAliasCompar= e); + if (Sort =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + BASE_LIST_FOR_EACH (FileEntry, FilesHead) { + FileInfo =3D (EFI_SHELL_FILE_INFO *)FileEntry; + + // + // Try to record the name of this file as a unique name. + // + Unique =3D AllocatePool (sizeof (*Unique)); + if (Unique =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto UninitSort; + } + Unique->Alias =3D ((Order =3D=3D ShellSortFileListByFileName) ? + FileInfo->FileName : + FileInfo->FullName); + InitializeListHead (&Unique->SameNameList); + + Status =3D OrderedCollectionInsert (Sort, NULL, Unique); + if (EFI_ERROR (Status)) { + // + // Only two errors are possible: memory allocation failed, or this n= ame + // has been encountered before. In either case, the + // SHELL_SORT_UNIQUE_NAME object being constructed has to be release= d. + // + FreePool (Unique); + // + // Memory allocation failure is fatal, while having seen the same na= me + // before is normal. + // + if (Status =3D=3D EFI_OUT_OF_RESOURCES) { + goto UninitSort; + } + ASSERT (Status =3D=3D EFI_ALREADY_STARTED); + } + } + + // + // If separation of duplicates has been requested, allocate the list for + // them. + // + if (Duplicates !=3D NULL) { + Dupes =3D AllocateZeroPool (sizeof (*Dupes)); + if (Dupes =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto UninitSort; + } + InitializeListHead (&Dupes->Link); + } + + // + // No memory allocation beyond this point; thus, no chance to fail. We c= an + // now migrate the EFI_SHELL_FILE_INFO objects from (*FileList) to Sort. + // + BASE_LIST_FOR_EACH_SAFE (FileEntry, NextFileEntry, FilesHead) { + FileInfo =3D (EFI_SHELL_FILE_INFO *)FileEntry; + // + // Look up the SHELL_SORT_UNIQUE_NAME that matches FileInfo's name. + // + Alias =3D ((Order =3D=3D ShellSortFileListByFileName) ? + FileInfo->FileName : + FileInfo->FullName); + SortEntry =3D OrderedCollectionFind (Sort, Alias); + ASSERT (SortEntry !=3D NULL); + Unique =3D OrderedCollectionUserStruct (SortEntry); + // + // Move FileInfo from (*FileList) to the end of the list of files whose + // names all compare identical to FileInfo's name. + // + RemoveEntryList (&FileInfo->Link); + InsertTailList (&Unique->SameNameList, &FileInfo->Link); + } + + // + // All EFI_SHELL_FILE_INFO objects originally in (*FileList) have been + // distributed to Sort. Now migrate them back to (*FileList), advancing = in + // unique name order. + // + for (SortEntry =3D OrderedCollectionMin (Sort); + SortEntry !=3D NULL; + SortEntry =3D OrderedCollectionNext (SortEntry)) { + Unique =3D OrderedCollectionUserStruct (SortEntry); + // + // The first FileInfo encountered for each unique name goes back on + // (*FileList) unconditionally. Further FileInfo instances for the same + // unique name -- that is, duplicates -- are either returned to (*File= List) + // or separated, dependent on the caller's request. + // + TargetFileList =3D FilesHead; + BASE_LIST_FOR_EACH_SAFE (FileEntry, NextFileEntry, &Unique->SameNameLi= st) { + RemoveEntryList (FileEntry); + InsertTailList (TargetFileList, FileEntry); + if (Duplicates !=3D NULL) { + TargetFileList =3D &Dupes->Link; + } + } + } + + // + // We're done. If separation of duplicates has been requested, output the + // list of duplicates -- and free that list at once, if it's empty (i.e.= , if + // no duplicates have been found). + // + if (Duplicates !=3D NULL) { + if (IsListEmpty (&Dupes->Link)) { + FreePool (Dupes); + *Duplicates =3D NULL; + } else { + *Duplicates =3D Dupes; + } + } + Status =3D EFI_SUCCESS; + + // + // Fall through. + // +UninitSort: + for (SortEntry =3D OrderedCollectionMin (Sort); + SortEntry !=3D NULL; + SortEntry =3D NextSortEntry) { + NextSortEntry =3D OrderedCollectionNext (SortEntry); + OrderedCollectionDelete (Sort, SortEntry, &UniqueAsVoid); + Unique =3D UniqueAsVoid; + ASSERT (IsListEmpty (&Unique->SameNameList)); + FreePool (Unique); + } + OrderedCollectionUninit (Sort); + + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69586): https://edk2.groups.io/g/devel/message/69586 Mute This Topic: https://groups.io/mt/79426444/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat Apr 20 14:04:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69588+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69588+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609774976; cv=none; d=zohomail.com; s=zohoarc; b=aaQ/KOE5qU7ABzW8ZQuajGiiNZYzYUmc3d6k2OC3FB2gGeqUUL3SPdLZErVXhIAtfTK2vhwOdJIF40p1J/Yvcjq9m40SwzUFejMoHiab0nykh/H9XzoZ2AbJaqdCCFGG51XWzlWEk7I+VgXUxQNRxEurzdN2btclH+Jr5+rnXvs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609774976; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=+WfSJbxEilUEmpxD9YTL0zrU7kmG1i0TbVnPVRlXvuE=; b=DWr+w9jtjOXx6N5lAe1REs9+h+dU3pWIZ9kTC/C6ZTdPsMlo5tZnf9j0rXrjBTidZ5j74iruV9P+wklIUNrKheAUhtkf3B8DnjEMd2AnFrk1S82FBMlhYtmVPIpY0a+uXfGsT8e7gEBJoiIF49oT3s3RY1SiYzaePw+TD9Em4c8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69588+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 160977497669468.14897964710656; Mon, 4 Jan 2021 07:42:56 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id NwkXYY1788612xWE4C8u2HIY; Mon, 04 Jan 2021 07:42:56 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web10.15223.1609774973307175459 for ; Mon, 04 Jan 2021 07:42:53 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-583-oew1vPUeMW2Wu-ipbyX-0w-1; Mon, 04 Jan 2021 10:42:50 -0500 X-MC-Unique: oew1vPUeMW2Wu-ipbyX-0w-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6AB9190A7AA; Mon, 4 Jan 2021 15:42:49 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-80.ams2.redhat.com [10.36.113.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95F7C10016FE; Mon, 4 Jan 2021 15:42:48 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Ray Ni , Zhichao Gao Subject: [edk2-devel] [PATCH 5/8] ShellPkg/Ls: sort output by FileName in non-SFO mode Date: Mon, 4 Jan 2021 16:42:32 +0100 Message-Id: <20210104154235.31785-6-lersek@redhat.com> In-Reply-To: <20210104154235.31785-1-lersek@redhat.com> References: <20210104154235.31785-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: hSkATxboZLNEhepJCIGsRROLx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609774976; bh=+WfSJbxEilUEmpxD9YTL0zrU7kmG1i0TbVnPVRlXvuE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=drQ2IHfmQi9UsXJZGu6HR2O/iYYMhx6VwRrogWMe8QqP23SLuhKTfoGnas/nuRuSlAh xCqYHw+3knDIsaR6OkS0/ByK/2XxWeuxicBO+ZvQ/goR11nFuqZP95aCv3SLCNH6QFVbr dpk1ZguuWFjHKADxqp7S/YPHthsv/Bd7r7g= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Sorting the LS output in non-SFO mode by FileName is best demonstrated with two examples. (1a) Before: > FS2:\> dir -r apps > Directory of: FS2:\apps\ > 01/01/1970 01:00 r 0 . > 12/22/2020 17:53 4,096 X64 > 12/22/2020 17:53 4,096 AARCH64 > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 4,096 IA32 > 0 File(s) 0 bytes > 5 Dir(s) > Directory of: FS2:\apps\X64\ > 12/22/2020 17:52 18,752 DumpDynPcd.efi > 12/22/2020 17:52 34,240 SmiHandlerProfileInfo.efi > 01/01/1970 01:00 r 0 . > 12/22/2020 17:52 11,456 VariableInfo.efi > 12/22/2020 17:52 26,304 MemoryProfileInfo.efi > 12/22/2020 17:53 126,656 AcpiViewApp.efi > 12/22/2020 17:53 38,784 Cpuid.efi > 01/01/1970 01:00 r 0 .. > 6 File(s) 256,192 bytes > 2 Dir(s) > Directory of: FS2:\apps\AARCH64\ > 12/22/2020 17:52 32,768 DumpDynPcd.efi > 01/01/1970 01:00 r 0 . > 12/22/2020 17:52 20,480 VariableInfo.efi > 12/22/2020 17:52 40,960 MemoryProfileInfo.efi > 12/22/2020 17:53 139,264 AcpiViewApp.efi > 01/01/1970 01:00 r 0 .. > 4 File(s) 233,472 bytes > 2 Dir(s) > Directory of: FS2:\apps\IA32\ > 12/22/2020 17:52 17,344 DumpDynPcd.efi > 12/22/2020 17:52 30,720 SmiHandlerProfileInfo.efi > 01/01/1970 01:00 r 0 . > 12/22/2020 17:52 10,880 VariableInfo.efi > 12/22/2020 17:52 24,192 MemoryProfileInfo.efi > 12/22/2020 17:53 105,536 AcpiViewApp.efi > 12/22/2020 17:53 36,096 Cpuid.efi > 01/01/1970 01:00 r 0 .. > 6 File(s) 224,768 bytes > 2 Dir(s) (1b) After: > FS2:\> dir -r apps > Directory of: FS2:\apps\ > 01/01/1970 01:00 r 0 . > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 4,096 AARCH64 > 12/22/2020 17:53 4,096 IA32 > 12/22/2020 17:53 4,096 X64 > 0 File(s) 0 bytes > 5 Dir(s) > Directory of: FS2:\apps\X64\ > 01/01/1970 01:00 r 0 . > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 126,656 AcpiViewApp.efi > 12/22/2020 17:53 38,784 Cpuid.efi > 12/22/2020 17:52 18,752 DumpDynPcd.efi > 12/22/2020 17:52 26,304 MemoryProfileInfo.efi > 12/22/2020 17:52 34,240 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 11,456 VariableInfo.efi > 6 File(s) 256,192 bytes > 2 Dir(s) > Directory of: FS2:\apps\AARCH64\ > 01/01/1970 01:00 r 0 . > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 139,264 AcpiViewApp.efi > 12/22/2020 17:52 32,768 DumpDynPcd.efi > 12/22/2020 17:52 40,960 MemoryProfileInfo.efi > 12/22/2020 17:52 20,480 VariableInfo.efi > 4 File(s) 233,472 bytes > 2 Dir(s) > Directory of: FS2:\apps\IA32\ > 01/01/1970 01:00 r 0 . > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 105,536 AcpiViewApp.efi > 12/22/2020 17:53 36,096 Cpuid.efi > 12/22/2020 17:52 17,344 DumpDynPcd.efi > 12/22/2020 17:52 24,192 MemoryProfileInfo.efi > 12/22/2020 17:52 30,720 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 10,880 VariableInfo.efi > 6 File(s) 224,768 bytes > 2 Dir(s) (2a) Before: > FS2:\> dir apps\*\*.efi > Directory of: FS2:\apps\*\ > 12/22/2020 17:52 18,752 DumpDynPcd.efi > 12/22/2020 17:52 34,240 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 11,456 VariableInfo.efi > 12/22/2020 17:52 26,304 MemoryProfileInfo.efi > 12/22/2020 17:53 126,656 AcpiViewApp.efi > 12/22/2020 17:53 38,784 Cpuid.efi > 12/22/2020 17:52 32,768 DumpDynPcd.efi > 12/22/2020 17:52 20,480 VariableInfo.efi > 12/22/2020 17:52 40,960 MemoryProfileInfo.efi > 12/22/2020 17:53 139,264 AcpiViewApp.efi > 12/22/2020 17:52 17,344 DumpDynPcd.efi > 12/22/2020 17:52 30,720 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 10,880 VariableInfo.efi > 12/22/2020 17:52 24,192 MemoryProfileInfo.efi > 12/22/2020 17:53 105,536 AcpiViewApp.efi > 12/22/2020 17:53 36,096 Cpuid.efi > 16 File(s) 714,432 bytes > 0 Dir(s) (2b) After: > FS2:\> dir apps\*\*.efi > Directory of: FS2:\apps\*\ > 12/22/2020 17:53 126,656 AcpiViewApp.efi > 12/22/2020 17:53 139,264 AcpiViewApp.efi > 12/22/2020 17:53 105,536 AcpiViewApp.efi > 12/22/2020 17:53 38,784 Cpuid.efi > 12/22/2020 17:53 36,096 Cpuid.efi > 12/22/2020 17:52 18,752 DumpDynPcd.efi > 12/22/2020 17:52 32,768 DumpDynPcd.efi > 12/22/2020 17:52 17,344 DumpDynPcd.efi > 12/22/2020 17:52 26,304 MemoryProfileInfo.efi > 12/22/2020 17:52 40,960 MemoryProfileInfo.efi > 12/22/2020 17:52 24,192 MemoryProfileInfo.efi > 12/22/2020 17:52 34,240 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 30,720 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 11,456 VariableInfo.efi > 12/22/2020 17:52 20,480 VariableInfo.efi > 12/22/2020 17:52 10,880 VariableInfo.efi > 16 File(s) 714,432 bytes > 0 Dir(s) (In example (2), note that the sorting is stable; that is, whatever order is established between identical FileNames by ShellOpenFileMetaArg(), it is preserved by ShellSortFileList().) Cc: Philippe Mathieu-Daud=C3=A9 Cc: Ray Ni Cc: Zhichao Gao Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3151 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel Reviewed-by: Zhichao Gao --- ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Li= brary/UefiShellLevel2CommandsLib/Ls.c index da2b1acab47c..8b97926d7f47 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c @@ -489,6 +489,20 @@ PrintLsOutput( PrintSfoVolumeInfoTableEntry(ListHead); } =20 + if (!Sfo) { + // + // Sort the file list by FileName, stably. + // + // If the call below fails, then the EFI_SHELL_FILE_INFO list anchor= ed to + // ListHead will not be changed in any way. + // + ShellSortFileList ( + &ListHead, + NULL, // Duplicates + ShellSortFileListByFileName + ); + } + for ( Node =3D (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link), L= ongestPath =3D 0 ; !IsNull(&ListHead->Link, &Node->Link) ; Node =3D (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &No= de->Link) --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69588): https://edk2.groups.io/g/devel/message/69588 Mute This Topic: https://groups.io/mt/79426446/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat Apr 20 14:04:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69589+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69589+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609774976; cv=none; d=zohomail.com; s=zohoarc; b=iMooyJ/WUfAyOtG6p0/P7P1AFgFF6lfclr8D3QFU0hchrnoM2+HkVy9hoqWVwmAMBfJmkNbydoX6hieuBLFHaSZi/KGLmzTPSKAmwNdEDLdaHWC0ZCEUjC1kYMvzH0r2Fckcf0q8zADQFgFK2Isn0Ehje5cg319Xt4Pyd5V2UU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609774976; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=uDIyYuinfJxilAQKf+k1Q5pRUffKLOXkq+z08AbrYZM=; b=GQ+u3AStDoKXNDBBP72fbVZbq/AMSt0p4GuWsquf4Aa26L6XmKnwauxwJaIBYhostL+WIYv4JTTn8vAWce6hx/VgQU10AXPxzE0TslyHAaJksAYUGduHjSvAmivgn0e24ONhm24QulvCUFCvxKPlUVV4/lfvpM4yBDmfuidMxgo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69589+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609774976875767.0293488362702; Mon, 4 Jan 2021 07:42:56 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id m6C1YY1788612xZLAJlWcyhu; Mon, 04 Jan 2021 07:42:56 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web11.15137.1609774974851839168 for ; Mon, 04 Jan 2021 07:42:55 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-542-OKI6NAQaPuOHpOoW15Bgag-1; Mon, 04 Jan 2021 10:42:52 -0500 X-MC-Unique: OKI6NAQaPuOHpOoW15Bgag-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 38B68107ACE3; Mon, 4 Jan 2021 15:42:51 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-80.ams2.redhat.com [10.36.113.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 185F11001281; Mon, 4 Jan 2021 15:42:49 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Ray Ni , Zhichao Gao Subject: [edk2-devel] [PATCH 6/8] ShellPkg/ShellProtocol: sort files by FullName in RemoveDupInFileList() Date: Mon, 4 Jan 2021 16:42:33 +0100 Message-Id: <20210104154235.31785-7-lersek@redhat.com> In-Reply-To: <20210104154235.31785-1-lersek@redhat.com> References: <20210104154235.31785-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: Te424hG8jblkH0ogqveEz6fCx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609774976; bh=uDIyYuinfJxilAQKf+k1Q5pRUffKLOXkq+z08AbrYZM=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=rcVFM4EPBkJ/GnI62gvmLyLQEM7q/LPCKwEieULKm7Jgyvl4kEpyype+lNHWqNg8uIl ldhq+zE9ASiZg8s4OLjTP5NCav9XsYRevNyL+F/EabPHCSYSzINOLSv1Tr5zsQFbXp3S1 fHaU2V+zB977c8RZLEMz+vMhVZpnPETLUDk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The current implementation of EfiShellRemoveDupInFileList(): - has quadratic time complexity, as a disadvantage, and - needs no dynamic memory, as an advantage. Because the UEFI Shell Spec requires EFI_SHELL_PROTOCOL.RemoveDupInFileList() to succeed at all times, keep the current method as a fallback (it cannot fail due to needing no dynamic memory). However, as a higher priority option, call the new ShellSortFileList() function at first, separating out and releasing duplicates. (ShellSortFileList() can fail due to EFI_OUT_OF_RESOURCES.) Beyond improving the runtime of EfiShellRemoveDupInFileList(), this change has the extremely desirable effect that the ShellOpenFileMetaArg() function in the ShellPkg/Library/UefiShellLib instance will produce file lists that are sorted by FullName. Consequently, when used with wildcards, the ATTRIB, CP, FOR, LOAD, LOADPCIROM, LS, MV, RM, TOUCH, TYPE commands will process files in FullName order. (LS in recursive mode uses wildcards internally.) Before: > FS2:\> dir -r -sfo apps > [...] > FileInfo,"FS2:\apps\" > FileInfo,"FS2:\apps\X64" > FileInfo,"FS2:\apps\AARCH64" > FileInfo,"FS2:\" > FileInfo,"FS2:\apps\IA32" > FileInfo,"FS2:\apps\X64\DumpDynPcd.efi" > FileInfo,"FS2:\apps\X64\SmiHandlerProfileInfo.efi" > FileInfo,"FS2:\apps\X64\" > FileInfo,"FS2:\apps\X64\VariableInfo.efi" > FileInfo,"FS2:\apps\X64\MemoryProfileInfo.efi" > FileInfo,"FS2:\apps\X64\AcpiViewApp.efi" > FileInfo,"FS2:\apps\X64\Cpuid.efi" > FileInfo,"FS2:\apps\" > FileInfo,"FS2:\apps\AARCH64\DumpDynPcd.efi" > FileInfo,"FS2:\apps\AARCH64\" > FileInfo,"FS2:\apps\AARCH64\VariableInfo.efi" > FileInfo,"FS2:\apps\AARCH64\MemoryProfileInfo.efi" > FileInfo,"FS2:\apps\AARCH64\AcpiViewApp.efi" > FileInfo,"FS2:\apps\" > FileInfo,"FS2:\apps\IA32\DumpDynPcd.efi" > FileInfo,"FS2:\apps\IA32\SmiHandlerProfileInfo.efi" > FileInfo,"FS2:\apps\IA32\" > FileInfo,"FS2:\apps\IA32\VariableInfo.efi" > FileInfo,"FS2:\apps\IA32\MemoryProfileInfo.efi" > FileInfo,"FS2:\apps\IA32\AcpiViewApp.efi" > FileInfo,"FS2:\apps\IA32\Cpuid.efi" > FileInfo,"FS2:\apps\" After: > FS2:\> dir -r -sfo apps > [...] > FileInfo,"FS2:\" > FileInfo,"FS2:\apps\" > FileInfo,"FS2:\apps\AARCH64" > FileInfo,"FS2:\apps\IA32" > FileInfo,"FS2:\apps\X64" > FileInfo,"FS2:\apps\" > FileInfo,"FS2:\apps\AARCH64\" > FileInfo,"FS2:\apps\AARCH64\AcpiViewApp.efi" > FileInfo,"FS2:\apps\AARCH64\DumpDynPcd.efi" > FileInfo,"FS2:\apps\AARCH64\MemoryProfileInfo.efi" > FileInfo,"FS2:\apps\AARCH64\VariableInfo.efi" > FileInfo,"FS2:\apps\" > FileInfo,"FS2:\apps\IA32\" > FileInfo,"FS2:\apps\IA32\AcpiViewApp.efi" > FileInfo,"FS2:\apps\IA32\Cpuid.efi" > FileInfo,"FS2:\apps\IA32\DumpDynPcd.efi" > FileInfo,"FS2:\apps\IA32\MemoryProfileInfo.efi" > FileInfo,"FS2:\apps\IA32\SmiHandlerProfileInfo.efi" > FileInfo,"FS2:\apps\IA32\VariableInfo.efi" > FileInfo,"FS2:\apps\" > FileInfo,"FS2:\apps\X64\" > FileInfo,"FS2:\apps\X64\AcpiViewApp.efi" > FileInfo,"FS2:\apps\X64\Cpuid.efi" > FileInfo,"FS2:\apps\X64\DumpDynPcd.efi" > FileInfo,"FS2:\apps\X64\MemoryProfileInfo.efi" > FileInfo,"FS2:\apps\X64\SmiHandlerProfileInfo.efi" > FileInfo,"FS2:\apps\X64\VariableInfo.efi" Regarding LS in non-SFO mode, the stability of ShellSortFileList() shows. The ShellSortFileList() call added to LS in the previous patch re-sorts the output of ShellOpenFileMetaArg(); and so this patch improves the ordering between identical FileNames: Before: > FS2:\> dir -r apps > Directory of: FS2:\apps\ > 01/01/1970 01:00 r 0 . > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 4,096 AARCH64 > 12/22/2020 17:53 4,096 IA32 > 12/22/2020 17:53 4,096 X64 > 0 File(s) 0 bytes > 5 Dir(s) > Directory of: FS2:\apps\X64\ > 01/01/1970 01:00 r 0 . > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 126,656 AcpiViewApp.efi > 12/22/2020 17:53 38,784 Cpuid.efi > 12/22/2020 17:52 18,752 DumpDynPcd.efi > 12/22/2020 17:52 26,304 MemoryProfileInfo.efi > 12/22/2020 17:52 34,240 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 11,456 VariableInfo.efi > 6 File(s) 256,192 bytes > 2 Dir(s) > Directory of: FS2:\apps\AARCH64\ > 01/01/1970 01:00 r 0 . > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 139,264 AcpiViewApp.efi > 12/22/2020 17:52 32,768 DumpDynPcd.efi > 12/22/2020 17:52 40,960 MemoryProfileInfo.efi > 12/22/2020 17:52 20,480 VariableInfo.efi > 4 File(s) 233,472 bytes > 2 Dir(s) > Directory of: FS2:\apps\IA32\ > 01/01/1970 01:00 r 0 . > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 105,536 AcpiViewApp.efi > 12/22/2020 17:53 36,096 Cpuid.efi > 12/22/2020 17:52 17,344 DumpDynPcd.efi > 12/22/2020 17:52 24,192 MemoryProfileInfo.efi > 12/22/2020 17:52 30,720 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 10,880 VariableInfo.efi > 6 File(s) 224,768 bytes > 2 Dir(s) > > FS2:\> dir apps\*\*.efi > Directory of: FS2:\apps\*\ > 12/22/2020 17:53 126,656 AcpiViewApp.efi > 12/22/2020 17:53 139,264 AcpiViewApp.efi > 12/22/2020 17:53 105,536 AcpiViewApp.efi > 12/22/2020 17:53 38,784 Cpuid.efi > 12/22/2020 17:53 36,096 Cpuid.efi > 12/22/2020 17:52 18,752 DumpDynPcd.efi > 12/22/2020 17:52 32,768 DumpDynPcd.efi > 12/22/2020 17:52 17,344 DumpDynPcd.efi > 12/22/2020 17:52 26,304 MemoryProfileInfo.efi > 12/22/2020 17:52 40,960 MemoryProfileInfo.efi > 12/22/2020 17:52 24,192 MemoryProfileInfo.efi > 12/22/2020 17:52 34,240 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 30,720 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 11,456 VariableInfo.efi > 12/22/2020 17:52 20,480 VariableInfo.efi > 12/22/2020 17:52 10,880 VariableInfo.efi > 16 File(s) 714,432 bytes > 0 Dir(s) After: > FS2:\> dir -r apps > Directory of: FS2:\apps\ > 01/01/1970 01:00 r 0 . > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 4,096 AARCH64 > 12/22/2020 17:53 4,096 IA32 > 12/22/2020 17:53 4,096 X64 > 0 File(s) 0 bytes > 5 Dir(s) > Directory of: FS2:\apps\AARCH64\ > 01/01/1970 01:00 r 0 . > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 139,264 AcpiViewApp.efi > 12/22/2020 17:52 32,768 DumpDynPcd.efi > 12/22/2020 17:52 40,960 MemoryProfileInfo.efi > 12/22/2020 17:52 20,480 VariableInfo.efi > 4 File(s) 233,472 bytes > 2 Dir(s) > Directory of: FS2:\apps\IA32\ > 01/01/1970 01:00 r 0 . > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 105,536 AcpiViewApp.efi > 12/22/2020 17:53 36,096 Cpuid.efi > 12/22/2020 17:52 17,344 DumpDynPcd.efi > 12/22/2020 17:52 24,192 MemoryProfileInfo.efi > 12/22/2020 17:52 30,720 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 10,880 VariableInfo.efi > 6 File(s) 224,768 bytes > 2 Dir(s) > Directory of: FS2:\apps\X64\ > 01/01/1970 01:00 r 0 . > 01/01/1970 01:00 r 0 .. > 12/22/2020 17:53 126,656 AcpiViewApp.efi > 12/22/2020 17:53 38,784 Cpuid.efi > 12/22/2020 17:52 18,752 DumpDynPcd.efi > 12/22/2020 17:52 26,304 MemoryProfileInfo.efi > 12/22/2020 17:52 34,240 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 11,456 VariableInfo.efi > 6 File(s) 256,192 bytes > 2 Dir(s) > > FS2:\> dir apps\*\*.efi > Directory of: FS2:\apps\*\ > 12/22/2020 17:53 139,264 AcpiViewApp.efi > 12/22/2020 17:53 105,536 AcpiViewApp.efi > 12/22/2020 17:53 126,656 AcpiViewApp.efi > 12/22/2020 17:53 36,096 Cpuid.efi > 12/22/2020 17:53 38,784 Cpuid.efi > 12/22/2020 17:52 32,768 DumpDynPcd.efi > 12/22/2020 17:52 17,344 DumpDynPcd.efi > 12/22/2020 17:52 18,752 DumpDynPcd.efi > 12/22/2020 17:52 40,960 MemoryProfileInfo.efi > 12/22/2020 17:52 24,192 MemoryProfileInfo.efi > 12/22/2020 17:52 26,304 MemoryProfileInfo.efi > 12/22/2020 17:52 30,720 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 34,240 SmiHandlerProfileInfo.efi > 12/22/2020 17:52 20,480 VariableInfo.efi > 12/22/2020 17:52 10,880 VariableInfo.efi > 12/22/2020 17:52 11,456 VariableInfo.efi > 16 File(s) 714,432 bytes > 0 Dir(s) Cc: Philippe Mathieu-Daud=C3=A9 Cc: Ray Ni Cc: Zhichao Gao Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3151 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel Reviewed-by: Zhichao Gao --- ShellPkg/Application/Shell/ShellProtocol.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Applicat= ion/Shell/ShellProtocol.c index 4e639fe35e4f..e79c39058b3e 100644 --- a/ShellPkg/Application/Shell/ShellProtocol.c +++ b/ShellPkg/Application/Shell/ShellProtocol.c @@ -1855,6 +1855,8 @@ EfiShellRemoveDupInFileList( IN EFI_SHELL_FILE_INFO **FileList ) { + EFI_STATUS Status; + EFI_SHELL_FILE_INFO *Duplicates; EFI_SHELL_FILE_INFO *ShellFileListItem; EFI_SHELL_FILE_INFO *ShellFileListItem2; EFI_SHELL_FILE_INFO *TempNode; @@ -1862,6 +1864,20 @@ EfiShellRemoveDupInFileList( if (FileList =3D=3D NULL || *FileList =3D=3D NULL) { return (EFI_INVALID_PARAMETER); } + + Status =3D ShellSortFileList ( + FileList, + &Duplicates, + ShellSortFileListByFullName + ); + if (!EFI_ERROR (Status)) { + EfiShellFreeFileList (&Duplicates); + return EFI_SUCCESS; + } + // + // Fall back to the slow method that needs no extra memory, and so cannot + // fail. + // for ( ShellFileListItem =3D (EFI_SHELL_FILE_INFO*)GetFirstNode(&(*FileLi= st)->Link) ; !IsNull(&(*FileList)->Link, &ShellFileListItem->Link) ; ShellFileListItem =3D (EFI_SHELL_FILE_INFO*)GetNextNode(&(*FileLis= t)->Link, &ShellFileListItem->Link) --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69589): https://edk2.groups.io/g/devel/message/69589 Mute This Topic: https://groups.io/mt/79426448/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat Apr 20 14:04:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69591+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69591+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609774983; cv=none; d=zohomail.com; s=zohoarc; b=m2uahW1CYouagx+lnL4DTe98DCWoVXCBEa9spr6iwiN9GaNHVTk1/JQKhrGMv0h4SPmm3aftLyaqlqKs5clz4nbRrbsUD1p0KDgy1ZXZ5MC7LzPGwAU03Av7wJ0cs3neUid6EAGaNrCKxO+00/qBVaiQX+vMDEuAFpgT9GSDffw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609774983; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=fs27H6Wb2PjU97orgd/lvuUKzA4GiIX/QxMVfpXpNdo=; b=mx8kpWRT/9b9nHB/6zFKYEcTQ1mdczf8xsjqRe2/xQqjkX1CTj3dd20OsFbOb1mI0vakHNicv4N1+RGOJMoY4lXMKe4+/a3B9OMett+GEKg4qPt2WjvQ/PSwQWFQ7xxGpPMNa5bxbi03BZBfQZFKBAd0xg0whCmOcDLemz4OU4g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69591+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609774983803234.32105739299516; Mon, 4 Jan 2021 07:43:03 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id aNF5YY1788612xrAf5AoEagR; Mon, 04 Jan 2021 07:43:03 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web11.15139.1609774977826856510 for ; Mon, 04 Jan 2021 07:42:58 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-470-Gw_WbxQlOeWgPSF39YVq8Q-1; Mon, 04 Jan 2021 10:42:55 -0500 X-MC-Unique: Gw_WbxQlOeWgPSF39YVq8Q-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D72D410054FF; Mon, 4 Jan 2021 15:42:53 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-80.ams2.redhat.com [10.36.113.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FBDE10016FE; Mon, 4 Jan 2021 15:42:51 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Anthony Perard , Ard Biesheuvel , Jordan Justen , Julien Grall , Leif Lindholm , Peter Grehan , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Rebecca Cran , Sami Mujawar Subject: [edk2-devel] [PATCH 7/8] OvmfPkg: disable list length checks in NOOPT and DEBUG builds Date: Mon, 4 Jan 2021 16:42:34 +0100 Message-Id: <20210104154235.31785-8-lersek@redhat.com> In-Reply-To: <20210104154235.31785-1-lersek@redhat.com> References: <20210104154235.31785-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: BXAttEcdcCoPDQBWBUacWhK2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609774983; bh=fs27H6Wb2PjU97orgd/lvuUKzA4GiIX/QxMVfpXpNdo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=htOY7OAVuQTeBXvz9vUbTMSuEGl6lZGrM0mL7X5DN+w/TcByS8gyhvqwVRlkO2wBqyc tEurIQx2w9ESptZD974AcRSzkZ/Jywjov0HCYbEAFwhin96UxcJ7FuDDDtsLtrLtRNXlQ CMmsqJlr0YDFLvCsMEP1Cv2ceLUmOKFEVe4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" In NOOPT and DEBUG builds, if "PcdMaximumLinkedListLength" is nonzero, then several LIST_ENTRY *node* APIs in BaseLib compare the *full* list length against the PCD. This turns the time complexity of node-level APIs from constant to linear, and that of full-list manipulations from linear to quadratic. As an example, consider the EFI_SHELL_FILE_INFO list, which is a data structure that's widely used in the UEFI shell. I randomly extracted 5000 files from "/usr/include" on my laptop, spanning 1095 subdirectories out of 1538, and then ran "DIR -R" in the UEFI shell on this tree. These are the wall-clock times: PcdMaximumLinkedListLength PcdMaximumLinkedListLength =3D1,000,000 =3D0 -------------------------- --------------------------- FAT 4 min 31 s 18 s virtio-fs 5 min 13 s 1 min 33 s Checking list lengths against an arbitrary maximum (default: 1,000,000) seems useless even in NOOPT and DEBUG builds, while the cost is significant; so set the PCD to 0. Cc: Anthony Perard Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Julien Grall Cc: Leif Lindholm Cc: Peter Grehan Cc: Philippe Mathieu-Daud=C3=A9 Cc: Rebecca Cran Cc: Sami Mujawar Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3152 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/Bhyve/BhyveX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 1 + 6 files changed, 6 insertions(+) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index bb7697eb324b..c1b3d27885b0 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -437,6 +437,7 @@ [PcdsFixedAtBuild] gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize|1 gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FAL= SE gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler|0x10 + gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|0 !if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index b93fe30ae4e0..acf8f17ade12 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -429,6 +429,7 @@ [PcdsFixedAtBuild] gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize|1 gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FAL= SE gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler|0x10 + gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|0 !if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index cd0acf021459..7cce8944e496 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -476,6 +476,7 @@ [PcdsFixedAtBuild] gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FAL= SE !endif gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler|0x10 + gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|0 !if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 3bf493bdb08f..8d21dc0ed7b6 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -480,6 +480,7 @@ [PcdsFixedAtBuild] gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FAL= SE !endif gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler|0x10 + gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|0 !if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index cebdbc9faabe..103af2fea7a5 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -480,6 +480,7 @@ [PcdsFixedAtBuild] gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FAL= SE !endif gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler|0x10 + gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|0 !if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 12b7a87ee877..c15835d9d23c 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -356,6 +356,7 @@ [PcdsFixedAtBuild] gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize|1 gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FAL= SE gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler|0x10 + gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|0 !if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69591): https://edk2.groups.io/g/devel/message/69591 Mute This Topic: https://groups.io/mt/79426451/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat Apr 20 14:04:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69592+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69592+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609774981; cv=none; d=zohomail.com; s=zohoarc; b=fOYvS+fFnOhRD7e1tIX8/ym3D7NVQl2qSwmmfoHjfLB1Aln82SeqCacRK+NGxh3/GinaNdqrYaCJbjRGB7n6ZI+w/xRSvirIRl9KU5WdufGspJoMV0jLK6FeMFCWx2GpnQY4PQaqKhvFEHGGrhuXU9x8kKP+jNln3Q1fAzhuobg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609774981; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=uPRl5IyEBgzK5dPKvFxD8GB4AkxbGlUOIHdMStg++Cw=; b=R8kNhSaOSLSac3+874xdmsfTCX+THcqX4mk6TVcb+JYvrsg6TwXmDjJtfQnsW8ppNQIIQPvgSQGvFgl0poBYStbecPJYzeP6rq0I6GzEhxsMiYluL0E6hVqrWNh7jEvakwVwKKiylNm33PEl5y+XjGGkJWb6cGaWpdpNr1NuHP4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69592+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609774981332294.77690847482165; Mon, 4 Jan 2021 07:43:01 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id fvWTYY1788612xMtDRRl0Agd; Mon, 04 Jan 2021 07:43:00 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web11.15140.1609774979552571475 for ; Mon, 04 Jan 2021 07:42:59 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-257-_sScCzMONEyLA91C1LoCqA-1; Mon, 04 Jan 2021 10:42:57 -0500 X-MC-Unique: _sScCzMONEyLA91C1LoCqA-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C38F2190A7A0; Mon, 4 Jan 2021 15:42:55 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-80.ams2.redhat.com [10.36.113.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38C271001281; Mon, 4 Jan 2021 15:42:54 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Ard Biesheuvel , Julien Grall , Leif Lindholm , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sami Mujawar Subject: [edk2-devel] [PATCH 8/8] ArmVirtPkg: disable list length checks in NOOPT and DEBUG builds Date: Mon, 4 Jan 2021 16:42:35 +0100 Message-Id: <20210104154235.31785-9-lersek@redhat.com> In-Reply-To: <20210104154235.31785-1-lersek@redhat.com> References: <20210104154235.31785-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: RBC396fS2xvFeMGJAPP3B5Cex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609774980; bh=uPRl5IyEBgzK5dPKvFxD8GB4AkxbGlUOIHdMStg++Cw=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=InYauMt05xzLhBqxsfiMu1U4Q85MZVHb6gKbc/yVNIPOXLK7MaEk1KEsZEIlYACGnOg YiI/Ykas8fKZ2qGb5XcWtS6kVo81rjI0dIJXUKyytKbUP3TwTv1EGlnjp3IJTS1ouUyY0 4V+uu8RHbmZ6nphH959EmmSoyvj5XMJ49tE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" In NOOPT and DEBUG builds, if "PcdMaximumLinkedListLength" is nonzero, then several LIST_ENTRY *node* APIs in BaseLib compare the *full* list length against the PCD. This turns the time complexity of node-level APIs from constant to linear, and that of full-list manipulations from linear to quadratic. (See some example OVMF numbers in the previous patch.) Checking list lengths against an arbitrary maximum -- default value, and current ArmVirtPkg setting: 1,000,000 -- seems useless even in NOOPT and DEBUG builds, while the cost is significant; so set the PCD to 0. Cc: Ard Biesheuvel Cc: Julien Grall Cc: Leif Lindholm Cc: Philippe Mathieu-Daud=C3=A9 Cc: Sami Mujawar Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3152 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- ArmVirtPkg/ArmVirt.dsc.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 9ec92930472d..d9abadbe708c 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -290,7 +290,7 @@ [PcdsFeatureFlag.AARCH64] [PcdsFixedAtBuild.common] gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000 gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000 - gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000 + gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|0 gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000 gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320 =20 --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69592): https://edk2.groups.io/g/devel/message/69592 Mute This Topic: https://groups.io/mt/79426452/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-