[*] Rejuvenate AuMemory::SwapLock

This commit is contained in:
Reece Wilson 2024-04-09 22:29:11 +01:00
parent a300076c6d
commit 7f0dc81ec3
4 changed files with 126 additions and 96 deletions

View File

@ -501,6 +501,42 @@ namespace Aurora
&& ::IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE)
#endif
;
if (gShouldResPathDoNothing)
{
return;
}
#if defined(PROCESS_POWER_THROTTLING_CURRENT_VERSION)
if (pSetProcessInformation &&
AuSwInfo::IsWindows10OrGreater())
{
static AuInitOnceSmall gInitOnce;
if (AuThreading::InitOnceLocker::TryLock(&gInitOnce))
{
PROCESS_POWER_THROTTLING_STATE powerThrottling {};
powerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;
powerThrottling.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;
powerThrottling.StateMask = 0;
gShouldResPathDoNothing = bool(pSetProcessInformation(GetCurrentProcess(),
ProcessPowerThrottling,
&powerThrottling,
sizeof(powerThrottling)));
powerThrottling.ControlMask = PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION;
powerThrottling.StateMask = 0;
gShouldResPathDoNothing &= bool(pSetProcessInformation(GetCurrentProcess(),
ProcessPowerThrottling,
&powerThrottling,
sizeof(powerThrottling)));
AuThreading::InitOnceLocker::Finish(&gInitOnce);
} /* else no-wait. intentionally nop*/
}
#endif
}
void Win32DropSchedulerResolution()
@ -525,66 +561,6 @@ namespace Aurora
}
}
#if defined(PROCESS_POWER_THROTTLING_CURRENT_VERSION)
if (pSetProcessInformation &&
AuSwInfo::IsWindows10OrGreater())
{
static AuInitOnceSmall gInitOnce;
// Imagine paying any amount of money for a computer above Ivan's ewaste shitbox standards, just for Microsoft to tell you your non-portable platform isn't EcOnOmIcaLLY scheduling tasks EffiCiENT enough.
// Unless otherwise stated, piss off.
// Why would any platform make us opt into being able to use our own hardware to its' full potential? This is stupid.
// Microshit cant even write a memory management subsystem that provides free pages during phases of low resource consumption; and now, we have to trust them to give us high priority scheduling?
// (low resource consumption -> read: RAM [ (UNUSED HUGE FILE) (UNUSED HUGE FILE) (UNUSED HUGE FILE) (UNUSED HUGE FILE) (UNUSED HUGE FILE) (HUGE FILE) (FREE SPACE) (FREE SPACE) (YOU) ],
// SWAP: [ (UNUSED HUGE FILE) (UNUSED HUGE FILE) (UNUSED HUGE FILE) (UNUSED HUGE FILE) (UNUSED HUGE FILE) (HUGE FILE) (HEAP BACKUP LOL) (SOME EXTRA SWAP SPACE YOU WONT BE ABLE TO USE) ] )
// I'll let you know when we devolve into writing worthless chrome_helper.exe (42) processes allegedly doing some sandboxing of perceived value. Until then, let's assume our processes aren't *literal* retards staring into the abyss all day.
//
// Disable via: gRuntimeConfig.threadingConfig.bEnableAggressiveScheduling (def: false - unless defacto high perf application under xp-win7; use envvar AURORA_IS_NETBOOK to opt out)
//
// Update (2024/03): Fuck off; I'm doubling down on this messaging.
// Read into the absolute state of this, bio: "Using my 80,000 hours to evolve how anyone with an idea can apply technology to solve real problems."
// https://github.com/microsoft/WindowsAppSDK/discussions/2525
// https://github.com/dotnet/runtime/issues/66417
// Microsoft is planning on using data from https://app.electricitymaps.com/map, such that if you live in an area with "high climate impact of electricity," they're going to start shifting workloads to e-cores by default.
// To reiterate, fuck off CurryBlows 11 and fuck you SoySoft.
//
// Reece, [16/03/2024 18:11]
// `Imagine paying any amount of money for a computer above Ivan's ewaste shitbox standards, just for Microsoft to tell you [...]`
// [...] that MuH EnerGy GrId is ChArGinG toO mAnY TeSlAs of KarEns
// [...] TeXas CanT GeT ThEir ShiT ToGetTheR
// [...] CaLIiFoRnyanya is turning into a third world shithole with rolling blackouts worse than north korea (best korea - now with 100% less kpop slavery)
//
// Wake me when those soy infested over privileged retards commit to going one year without air conditioning and the mexicans' ball gargling service to go
//
// Update (2024/03) again:
// https://stackoverflow.com/questions/77182958/windows-11-application-timing-becomes-uneven-when-backgrounded
// It's already causing the general development community grief. bEnableAggressiveScheduling should always be enabled for high perf applications.
// "Under Windows 7, 8 or 10, it performed well. Under Windows 11, we have a new problem" - I stand by my other comments in the codebase that users should upgrade to Windows 7 - LTSC 10
if (AuThreading::InitOnceLocker::TryLock(&gInitOnce))
{
PROCESS_POWER_THROTTLING_STATE powerThrottling {};
powerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;
powerThrottling.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;
powerThrottling.StateMask = 0;
pSetProcessInformation(GetCurrentProcess(),
ProcessPowerThrottling,
&powerThrottling,
sizeof(powerThrottling));
powerThrottling.ControlMask = PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION;
powerThrottling.StateMask = 0;
pSetProcessInformation(GetCurrentProcess(),
ProcessPowerThrottling,
&powerThrottling,
sizeof(powerThrottling));
AuThreading::InitOnceLocker::Finish(&gInitOnce);
} /* else no-wait. intentionally nop*/
}
#endif
if (pZwSetTimerResolution)
{
auto uRet = pZwSetTimerResolution(1, true, &ullActualResolution);
@ -821,4 +797,14 @@ namespace Aurora
{
VirtualFree(pBuffer, 0, MEM_RELEASE);
}
bool SysMemoryLockPages(const void *pVoid, AuUInt uLength)
{
return VirtualLock((void *)pVoid, uLength);
}
bool SysMemoryUnlockPages(const void *pVoid, AuUInt uLength)
{
return VirtualUnlock((void *)pVoid, uLength);
}
}

View File

@ -44,9 +44,6 @@ namespace Aurora
void PosixTerminate()
{
#if 0
PosixShutup();
#endif
::killpg(0, SIGKILL);
}
@ -211,4 +208,14 @@ namespace Aurora
uLength = AuMemory::RoundPageUp(uLength);
::munmap(pBuffer, uLength);
}
bool SysMemoryLockPages(const void *pVoid, AuUInt uLength)
{
return ::mlock(pVoid, uLength) == 0;
}
bool SysMemoryUnlockPages(const void *pVoid, AuUInt uLength)
{
return ::munlock(pVoid, uLength) == 0;
}
}

View File

@ -59,6 +59,10 @@ namespace Aurora
void *SysAllocateLarge(AuUInt uLength);
void SysAllocateFree(void *pBuffer, AuUInt uLength);
bool SysMemoryLockPages(const void *pVoid, AuUInt uLength);
bool SysMemoryUnlockPages(const void *pVoid, AuUInt uLength);
}
#if defined(AURORA_IS_MODERNNT_DERIVED) || defined(AURORA_IS_POSIX_DERIVED)

View File

@ -10,34 +10,50 @@
#include "AuMemorySwapLock.hpp"
#include <Source/HWInfo/AuHWInfo.hpp>
#if defined(AURORA_IS_LINUX_DERIVED)
#include <sys/mman.h>
#endif
namespace Aurora::Memory::SwapLock
{
static AuPair<AuUInt, AuUInt> ToPagePair(AuPair<AuUInt, AuUInt> addressRange)
{
auto uBase = AuPageRound(addressRange.first, AuUInt(AuHwInfo::gPageSize));
auto uLength = AuPageRoundUp(addressRange.second + (addressRange.first - uBase), AuUInt(AuHwInfo::gPageSize));
return AuMakePair(uBase, uLength);
}
AUKN_SYM bool Lock(const AuList<AuPair<AuUInt, AuUInt>> &addressRanges)
{
for (const auto &addressRange : addressRanges)
for (AU_ITERATE_N(i, addressRanges.size()))
{
auto base = AuPageRound(addressRange.first, AuUInt(AuHwInfo::gPageSize));
auto length = AuPageRoundUp(addressRange.second + (addressRange.first - base), AuUInt(AuHwInfo::gPageSize));
bool bBypass {};
AuUInt uBase, uLength;
#if defined(AURORA_IS_MODERNNT_DERIVED)
if (!VirtualLock(AuReinterpretCast<LPVOID>(base), length))
AuTupleTie(uBase, uLength) = ToPagePair(addressRanges[i]);
for (AU_ITERATE_N(z, i))
{
SysPushErrorHAL("Couldn't lock memory 0x{:x} {}", base, length);
AuUInt uBase2, uLength2;
AuTupleTie(uBase2, uLength2) = ToPagePair(addressRanges[z]);
if (uBase < uBase2)
{
continue;
}
if ((uBase + uLength) > (uBase2 + uLength2))
{
continue;
}
bBypass = true;
break;
}
if (!bBypass &&
!SysMemoryLockPages(AuReinterpretCast<const void *>(uBase), uLength))
{
SysPushErrorHAL("Couldn't lock memory 0x{:x} {}", uBase, uLength);
return false;
}
#endif
#if defined(AURORA_IS_POSIX_DERIVED)
if (mlock(AuReinterpretCast<const void *>(base), length) != 0)
{
SysPushErrorHAL("Couldn't lock memory 0x{:x} {}", base, length);
return false;
}
#endif
}
return true;
@ -45,26 +61,43 @@ namespace Aurora::Memory::SwapLock
AUKN_SYM bool Unlock(const AuList<AuPair<AuUInt, AuUInt>> &addressRanges)
{
for (const auto &addressRange : addressRanges)
bool bRet { true };
for (AU_ITERATE_N(i, addressRanges.size()))
{
auto base = AuPageRound(addressRange.first, AuUInt(AuHwInfo::gPageSize));
auto length = AuPageRoundUp(addressRange.second + (addressRange.first - base), AuUInt(AuHwInfo::gPageSize));
bool bBypass {};
AuUInt uBase, uLength;
#if defined(AURORA_IS_MODERNNT_DERIVED)
if (!VirtualUnlock(AuReinterpretCast<LPVOID>(base), length))
{
SysPushErrorHAL("Couldn't unlock memory 0x{:x} {}", base, length);
}
#endif
AuTupleTie(uBase, uLength) = ToPagePair(addressRanges[i]);
#if defined(AURORA_IS_POSIX_DERIVED)
if (munlock(AuReinterpretCast<const void *>(base), length) != 0)
for (AU_ITERATE_N(z, i))
{
SysPushErrorHAL("Couldn't unlock memory 0x{:x} {}", base, length);
AuUInt uBase2, uLength2;
AuTupleTie(uBase2, uLength2) = ToPagePair(addressRanges[z]);
if (uBase < uBase2)
{
continue;
}
if ((uBase + uLength) > (uBase2 + uLength2))
{
continue;
}
bBypass = true;
break;
}
if (!bBypass &&
!SysMemoryUnlockPages(AuReinterpretCast<const void *>(uBase), uLength))
{
SysPushErrorHAL("Couldn't unlock memory 0x{:x} {}", uBase, uLength);
bRet = false;
}
#endif
}
return true;
return bRet;
}
}