提交 f45df2f1 编写于 作者: V vit9696

OpenCoreKernelPatch: Added `SetApfsTrimTimeout` to tune APFS trim

上级 d14477cb
......@@ -12,6 +12,7 @@ OpenCore Changelog
- Fixed compatibility with page protection for all binaries
- Fixed crashes in OpenUsbKbDxe when handling unsupported devices
- Removed `HdaCodecDump` application in favor of `SysReport`
- Added `SetApfsTrimTimeout` to tune APFS trim command
#### v0.6.5
- Fixed installing OpenDuet on protected volumes
......
......@@ -756,7 +756,9 @@ and clarifications.
is available, and inline for \texttt{static} variables and functions.
\item Use line length of 120 characters or less, preferably 100 characters.
\item Use spaces after casts, e.g. \texttt{(VOID *)(UINTN) Variable}.
\item Use two spaces as indentations as always.
\item Use two spaces to indent function arguments when splitting lines.
\item Prefix public functions with either \texttt{Oc} or another distinct name.
\item Do not prefix private \texttt{static} functions, but use \texttt{Internal} for \texttt{non-static}.
\item Use SPDX license headers as shown in
\href{https://github.com/acidanthera/bugtracker/issues/483}{acidanthera/bugtracker\#483}.
\end{itemize}
......@@ -1430,7 +1432,7 @@ To view their current state use \texttt{pmset -g} command in Terminal.
\emph{Note}: While this quirk is required to run older macOS versions
on platforms with used lower memory it is not compatible with some
hardware and macOS 11. In this case you may try to use
hardware and macOS 11. In this case one may try to use
\texttt{EnableSafeModeSlide} instead.
\item
......@@ -2554,6 +2556,26 @@ blocking.
to wake up. For debug kernels \texttt{setpowerstate\_panic=0} boot argument
should be used, which is otherwise equivalent to this quirk.
\item
\texttt{SetApfsTrimTimeout}\\
\textbf{Type}: \texttt{plist\ integer}\\
\textbf{Failsafe}: \texttt{-1}\\
\textbf{Requirement}: 10.14 (not required for older)\\
\textbf{Description}: Set trim timeout in microseconds for APFS filesystems on SSDs.
Depending on the SSD controller trim procedure may take considerable
amount of time, causing noticeable boot slowdown as this is when the
APFS driver executes the trim operation. If the SSD supports
over-provisioning or there exists a dedicated unused partition that
can be used to reserve blocks, trim operation may not be necessary.
On the other side if the SSD is slow, the default timeout (equals to
\texttt{9.999999} seconds) may not be enough. See more details
in this \href{https://interface31.ru/tech_it/2015/04/mozhno-li-effektivno-ispolzovat-ssd-bez-podderzhki-trim.html}{article}.
Set this value to \texttt{4294967295} for the maximum timeout to
guarantee trim success or to \texttt{999} to essentially disable
trim.
\item
\texttt{ThirdPartyDrives}\\
\textbf{Type}: \texttt{plist\ boolean}\\
......
\documentclass[]{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL PreviousConfiguration.tex Tue Jan 5 10:48:23 2021
%DIF ADD ../Configuration.tex Sun Jan 24 10:54:55 2021
%DIF DEL PreviousConfiguration.tex Fri Jan 22 17:04:29 2021
%DIF ADD ../Configuration.tex Sun Jan 24 21:10:33 2021
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
......@@ -816,7 +816,9 @@ and clarifications.
is available, and inline for \texttt{static} variables and functions.
\item Use line length of 120 characters or less, preferably 100 characters.
\item Use spaces after casts, e.g. \texttt{(VOID *)(UINTN) Variable}.
\item Use \DIFaddbegin \DIFadd{two spaces as indentations as always.
\item Use \DIFaddbegin \DIFadd{two spaces to indent function arguments when splitting lines.
}\item \DIFadd{Prefix public functions with either }\texttt{\DIFadd{Oc}} \DIFadd{or another distinct name.
}\item \DIFadd{Do not prefix private }\texttt{\DIFadd{static}} \DIFadd{functions, but use }\texttt{\DIFadd{Internal}} \DIFadd{for }\texttt{\DIFadd{non-static}}\DIFadd{.
}\item \DIFadd{Use }\DIFaddend SPDX license headers as shown in
\href{https://github.com/acidanthera/bugtracker/issues/483}{acidanthera/bugtracker\#483}.
\end{itemize}
......@@ -1490,7 +1492,7 @@ To view their current state use \texttt{pmset -g} command in Terminal.
\emph{Note}: While this quirk is required to run older macOS versions
on platforms with used lower memory it is not compatible with some
hardware and macOS 11. In this case you may try to use
hardware and macOS 11. In this case \DIFdelbegin \DIFdel{you }\DIFdelend \DIFaddbegin \DIFadd{one }\DIFaddend may try to use
\texttt{EnableSafeModeSlide} instead.
\item
......@@ -2615,7 +2617,30 @@ blocking.
should be used, which is otherwise equivalent to this quirk.
\item
\texttt{ThirdPartyDrives}\\
\DIFaddbegin \texttt{\DIFadd{SetApfsTrimTimeout}}\\
\textbf{\DIFadd{Type}}\DIFadd{: }\texttt{\DIFadd{plist\ integer}}\\
\textbf{\DIFadd{Failsafe}}\DIFadd{: }\texttt{\DIFadd{-1}}\\
\textbf{\DIFadd{Requirement}}\DIFadd{: 10.14 (not required for older)}\\
\textbf{\DIFadd{Description}}\DIFadd{: Set trim timeout in microseconds for APFS filesystems on SSDs.
}
\DIFadd{Depending on the SSD controller trim procedure may take considerable
amount of time, causing noticeable boot slowdown as this is when the
APFS driver executes the trim operation. If the SSD supports
over-provisioning or there exists a dedicated unused partition that
can be used to reserve blocks, trim operation may not be necessary.
On the other side if the SSD is slow, the default timeout (equals to
}\texttt{\DIFadd{9.999999}} \DIFadd{seconds) may not be enough. See more details
in this }\href{https://interface31.ru/tech_it/2015/04/mozhno-li-effektivno-ispolzovat-ssd-bez-podderzhki-trim.html}{\DIFadd{article}}\DIFadd{.
}
\DIFadd{Set this value to }\texttt{\DIFadd{4294967295}} \DIFadd{for the maximum timeout to
guarantee trim success or to }\texttt{\DIFadd{999}} \DIFadd{to essentially disable
trim.
}
\item
\DIFaddend \texttt{ThirdPartyDrives}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\
\textbf{Requirement}: 10.6 (not required for older)\\
......@@ -5538,20 +5563,24 @@ even cause permanent firmware damage. Some of the known drivers are listed below
& PS/2 mouse driver from \texttt{MdeModulePkg}. Some very old laptop firmware
may not include this driver but it is necessary for the touchpad to work
in UEFI graphical interfaces such as \texttt{OpenCanopy}. \\
\DIFdelbegin %DIFDELCMD < \href{https://github.com/acidanthera/audk}{\texttt{UsbMouseDxe}}%%%
\DIFdelend \DIFaddbegin \href{https://github.com/acidanthera/OpenCorePkg}{\texttt{OpenHfsPlus}}\DIFaddend \textbf{*}
\DIFdelbegin %DIFDELCMD < \href{https://github.com/acidanthera/audk}{%%%
\texttt{\DIFdel{UsbMouseDxe}}%DIFAUXCMD
\DIFdelend \DIFaddbegin \href{https://github.com/acidanthera/OpenCorePkg}{\texttt{\DIFadd{OpenHfsPlus}}\DIFaddend }\textbf{*}
& \DIFdelbegin \DIFdel{USB mouse driver from }\texttt{\DIFdel{MdeModulePkg}}%DIFAUXCMD
\DIFdel{. Some virtual machine firmware
such as OVMF may not include this driver but it is necessary for the mouse to work
in UEFI graphical interfaces such as }\texttt{\DIFdel{OpenCanopy}}%DIFAUXCMD
\DIFdel{. }%DIFDELCMD < \\
%DIFDELCMD < \href{https://github.com/acidanthera/OpenCorePkg}{\texttt{VBoxHfs}}
%DIFDELCMD < %%%
\href{https://github.com/acidanthera/OpenCorePkg}{\texttt{\DIFdel{VBoxHfs}}%DIFAUXCMD
}
%DIFAUXCMD
%DIFDELCMD < & %%%
\DIFdelend HFS file system driver with bless support. This driver is an alternative to
a closed source \texttt{HfsPlus} driver commonly found in Apple firmware. While
it is feature complete, it is approximately 3~times slower and is yet to undergo
a security audit. \\
\DIFaddbegin \href{https://github.com/acidanthera/audk}{\texttt{UsbMouseDxe}}\textbf{\DIFadd{*}}
\DIFaddbegin \href{https://github.com/acidanthera/audk}{\texttt{\DIFadd{UsbMouseDxe}}}\textbf{\DIFadd{*}}
& \DIFadd{USB mouse driver from }\texttt{\DIFadd{MdeModulePkg}}\DIFadd{. Some virtual machine firmware
such as OVMF may not include this driver but it is necessary for the mouse to work
in UEFI graphical interfaces such as }\texttt{\DIFadd{OpenCanopy}}\DIFadd{. }\\
......@@ -5613,7 +5642,8 @@ Some of the known tools are listed below (builtin tools are marked with \textbf{
\href{https://github.com/acidanthera/OpenCorePkg}{\texttt{GopStop}}\textbf{*}
& Test GraphicsOutput protocol with a
\href{https://github.com/acidanthera/OpenCorePkg/tree/master/Application/GopStop}{simple scenario}. \\
\DIFdelbegin %DIFDELCMD < \href{https://github.com/acidanthera/OpenCorePkg}{\texttt{HdaCodecDump}}%%%
\DIFdelbegin \href{https://github.com/acidanthera/OpenCorePkg}{\texttt{\DIFdel{HdaCodecDump}}%DIFAUXCMD
}%DIFAUXCMD
\textbf{\DIFdel{*}}
%DIFAUXCMD
%DIFDELCMD < & %%%
......@@ -6821,9 +6851,9 @@ Since it is not always accurate, the latest versions are listed below.
images are limited to their target model identifiers and have no
\texttt{-no\_compat\_check} boot argument support. Modified images
(with \texttt{ACDT} suffix) without model restrictions can be found
\DIFdelbegin %DIFDELCMD < \href{https://mega.nz/folder/z5YUhYTb#gA\_IRY5KMuYpnNCg7kR3ug}{here}%%%
\DIFdelend \DIFaddbegin \href{https://archive.org/details/10.6.7-10j3250-disk-images}{here}
\DIFadd{(}\href{https://mega.nz/folder/z5YUhYTb#gA\_IRY5KMuYpnNCg7kR3ug}{MEGA Mirror}\DIFadd{)}\DIFaddend ,
\DIFdelbegin %DIFDELCMD < \href{https://mega.nz/folder/z5YUhYTb#gA\_IRY5KMuYpnNCg7kR3ug}{%%%
\DIFdelend \DIFaddbegin \href{https://archive.org/details/10.6.7-10j3250-disk-images}{\DIFaddend here}
\DIFaddbegin \DIFadd{(}\href{https://mega.nz/folder/z5YUhYTb#gA\_IRY5KMuYpnNCg7kR3ug}{\DIFadd{MEGA Mirror}}\DIFadd{)}\DIFaddend ,
assuming macOS~10.6 is legally owned. Read \texttt{DIGEST.txt}
for more details. Note that these are the earliest tested
versions of macOS~10.6 with OpenCore.
......@@ -6873,9 +6903,9 @@ hdiutil convert ReadWrite.dmg -format UDZO -o ReadOnly.dmg
build \texttt{9J3050} (for \texttt{MacBookPro5,3}). Unlike the others,
this image is not limited to the target model identifiers and can be used
as is. The original \texttt{9J3050} image can be found
\DIFdelbegin %DIFDELCMD < \href{https://mega.nz/folder/inRBTarD#zanf7fUbviwz3WHBU5xpCg}{here}%%%
\DIFdelend \DIFaddbegin \href{https://archive.org/details/10.5.7-9-j-3050}{here}
\DIFadd{(}\href{https://mega.nz/folder/inRBTarD#zanf7fUbviwz3WHBU5xpCg}{MEGA Mirror}\DIFadd{)}\DIFaddend ,
\DIFdelbegin %DIFDELCMD < \href{https://mega.nz/folder/inRBTarD#zanf7fUbviwz3WHBU5xpCg}{%%%
\DIFdelend \DIFaddbegin \href{https://archive.org/details/10.5.7-9-j-3050}{\DIFaddend here}
\DIFaddbegin \DIFadd{(}\href{https://mega.nz/folder/inRBTarD#zanf7fUbviwz3WHBU5xpCg}{\DIFadd{MEGA Mirror}}\DIFadd{)}\DIFaddend ,
assuming macOS~10.5 is legally owned. Read \texttt{DIGEST.txt}
for more details. Note that this is the earliest tested
version of macOS~10.5 with OpenCore.
......@@ -6894,9 +6924,9 @@ hdiutil convert ReadWrite.dmg -format UDZO -o ReadOnly.dmg
to their target model identifiers as on newer macOS versions.
Modified \texttt{8R4088} images (with \texttt{ACDT} suffix) without
model restrictions can be found
\DIFdelbegin %DIFDELCMD < \href{https://mega.nz/folder/D3ASzLzA\#7sjYXE2X09f6aGjol\_C7dg}{here}%%%
\DIFdelend \DIFaddbegin \href{https://archive.org/details/10.4.10-8-r-4088-acdt}{here}
\DIFadd{(}\href{https://mega.nz/folder/D3ASzLzA\#7sjYXE2X09f6aGjol\_C7dg}{MEGA Mirror}\DIFadd{)}\DIFaddend ,
\DIFdelbegin %DIFDELCMD < \href{https://mega.nz/folder/D3ASzLzA\#7sjYXE2X09f6aGjol\_C7dg}{%%%
\DIFdelend \DIFaddbegin \href{https://archive.org/details/10.4.10-8-r-4088-acdt}{\DIFaddend here}
\DIFaddbegin \DIFadd{(}\href{https://mega.nz/folder/D3ASzLzA\#7sjYXE2X09f6aGjol\_C7dg}{\DIFadd{MEGA Mirror}}\DIFadd{)}\DIFaddend ,
assuming macOS~10.4 is legally owned. Read \texttt{DIGEST.txt}
for more details. Note that these are the earliest tested
versions of macOS~10.4 with OpenCore.
......
......@@ -727,6 +727,8 @@
<false/>
<key>PowerTimeoutKernelPanic</key>
<false/>
<key>SetApfsTrimTimeout</key>
<integer>-1</integer>
<key>ThirdPartyDrives</key>
<false/>
<key>XhciPortLimit</key>
......
......@@ -727,6 +727,8 @@
<false/>
<key>PowerTimeoutKernelPanic</key>
<false/>
<key>SetApfsTrimTimeout</key>
<integer>-1</integer>
<key>ThirdPartyDrives</key>
<false/>
<key>XhciPortLimit</key>
......
......@@ -577,6 +577,10 @@ typedef enum {
// Force SecureBoot support for all CPUs.
//
KernelQuirkForceSecureBootScheme,
//
// Set custom APFS trim timeout.
//
KernelQuirkSetApfsTrimTimeout,
KernelQuirkMax
} KERNEL_QUIRK_NAME;
......@@ -1099,6 +1103,16 @@ KextFindKmodAddress (
OUT UINT64 *Kmod
);
/**
Set timeout value in microseconds for KernelQuirkSetApfsTrimTimeout quirk.
@param[in] Timeout Timeout in microseconds.
**/
VOID
PatchSetApfsTimeout (
IN UINT32 Timeout
);
/**
Apply modification to CPUID 1.
......
......@@ -273,6 +273,7 @@
/// KernelSpace quirks.
///
#define OC_KERNEL_QUIRKS_FIELDS(_, __) \
_(INT64 , SetApfsTrimTimeout , , FALSE , ()) \
_(BOOLEAN , AppleCpuPmCfgLock , , FALSE , ()) \
_(BOOLEAN , AppleXcpmCfgLock , , FALSE , ()) \
_(BOOLEAN , AppleXcpmExtraMsrs , , FALSE , ()) \
......
......@@ -1890,6 +1890,71 @@ PatchForceSecureBootScheme (
return EFI_SUCCESS;
}
STATIC
UINT8
mApfsTimeoutFind[] = {
0x48, 0x3D, 0x7F, 0x96, 0x98, 0x00
};
STATIC
UINT8
mApfsTimeoutReplace[] = {
0x48, 0x3D, 0x00, 0x00, 0x00, 0x00
};
STATIC
PATCHER_GENERIC_PATCH
mApfsTimeoutPatch = {
.Comment = DEBUG_POINTER ("ApfsTimeout"),
.Base = NULL,
.Find = mApfsTimeoutFind,
.Mask = NULL,
.Replace = mApfsTimeoutReplace,
.ReplaceMask = NULL,
.Size = sizeof (mApfsTimeoutFind),
.Count = 1,
.Skip = 0,
.Limit = 0
};
VOID
PatchSetApfsTimeout (
IN UINT32 Timeout
)
{
// FIXME: This is really ugly, make quirks take a context param.
DEBUG ((DEBUG_INFO, "OCAK: Registering %u APFS timeout\n", Timeout));
CopyMem (&mApfsTimeoutReplace[2], &Timeout, sizeof (Timeout));
}
STATIC
EFI_STATUS
PatchSetApfsTrimTimeout (
IN OUT PATCHER_CONTEXT *Patcher,
IN UINT32 KernelVersion
)
{
EFI_STATUS Status;
if (!OcMatchDarwinVersion (KernelVersion, KERNEL_VERSION_MOJAVE_MIN, 0)) {
DEBUG ((DEBUG_INFO, "OCAK: Skipping apfs timeout on %u\n", KernelVersion));
return EFI_SUCCESS;
}
if (Patcher == NULL) {
return EFI_NOT_FOUND;
}
Status = PatcherApplyGenericPatch (Patcher, &mApfsTimeoutPatch);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCAK: Failed to apply patch SetApfsTrimTimeout - %r\n", Status));
} else {
DEBUG ((DEBUG_INFO, "OCAK: Patch success SetApfsTrimTimeout\n"));
}
return Status;
}
//
// Quirks table.
//
......@@ -1916,6 +1981,7 @@ KERNEL_QUIRK gKernelQuirks[] = {
[KernelQuirkExtendBTFeatureFlags] = { "com.apple.iokit.IOBluetoothFamily", PatchBTFeatureFlags },
[KernelQuirkLegacyCommpage] = { NULL, PatchLegacyCommpage },
[KernelQuirkForceSecureBootScheme] = { "com.apple.security.AppleImage4", PatchForceSecureBootScheme },
[KernelQuirkSetApfsTrimTimeout] = { "com.apple.filesystems.apfs", PatchSetApfsTrimTimeout },
};
EFI_STATUS
......
......@@ -357,6 +357,7 @@ mKernelQuirksSchema[] = {
OC_SCHEMA_BOOLEAN_IN ("LegacyCommpage", OC_GLOBAL_CONFIG, Kernel.Quirks.LegacyCommpage),
OC_SCHEMA_BOOLEAN_IN ("PanicNoKextDump", OC_GLOBAL_CONFIG, Kernel.Quirks.PanicNoKextDump),
OC_SCHEMA_BOOLEAN_IN ("PowerTimeoutKernelPanic", OC_GLOBAL_CONFIG, Kernel.Quirks.PowerTimeoutKernelPanic),
OC_SCHEMA_INTEGER_IN ("SetApfsTrimTimeout", OC_GLOBAL_CONFIG, Kernel.Quirks.SetApfsTrimTimeout),
OC_SCHEMA_BOOLEAN_IN ("ThirdPartyDrives", OC_GLOBAL_CONFIG, Kernel.Quirks.ThirdPartyDrives),
OC_SCHEMA_BOOLEAN_IN ("XhciPortLimit", OC_GLOBAL_CONFIG, Kernel.Quirks.XhciPortLimit),
};
......
......@@ -274,6 +274,11 @@ OcKernelApplyPatches (
));
}
}
if (Config->Kernel.Quirks.SetApfsTrimTimeout >= 0) {
PatchSetApfsTimeout ((UINT32) Config->Kernel.Quirks.SetApfsTrimTimeout);
OcKernelApplyQuirk (KernelQuirkSetApfsTrimTimeout, CacheType, DarwinVersion, NULL, &KernelPatcher);
}
} else {
if (Config->Kernel.Quirks.AppleXcpmCfgLock) {
OcKernelApplyQuirk (KernelQuirkAppleXcpmCfgLock, CacheType, DarwinVersion, NULL, &KernelPatcher);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册