- [Sys-clk-OC] Partial rewrite, general performance & stability improvement
- [ReverseNX-RT] Notify user if profile is synced with sys-clk
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define FORCE_ALL_HANDHELD_MODES_TO_USE_DOCK_CLOCK
|
||||
#include <nxExt.h>
|
||||
#include "errors.h"
|
||||
#include "clock_manager.h"
|
||||
@@ -46,6 +45,7 @@ ClockManager::ClockManager()
|
||||
this->context = new SysClkContext;
|
||||
this->context->applicationId = 0;
|
||||
this->context->profile = SysClkProfile_Handheld;
|
||||
this->context->realProfile = SysClkProfile_Handheld;
|
||||
this->context->enabled = false;
|
||||
for(unsigned int i = 0; i < SysClkModule_EnumMax; i++)
|
||||
{
|
||||
@@ -60,8 +60,10 @@ ClockManager::ClockManager()
|
||||
this->oc = new SysClkOcExtra;
|
||||
this->oc->systemCoreBoostCPU = false;
|
||||
this->oc->systemCoreCheckStuck = false;
|
||||
this->oc->tickWaitTimeMs = 500;
|
||||
this->oc->systemCoreBoostThreshold = 100;
|
||||
this->oc->reverseNXToolMode = ReverseNX_NotFound;
|
||||
this->oc->reverseNXRTMode = ReverseNX_NotFound;
|
||||
this->oc->tickWaitTimeMs = 0;
|
||||
this->oc->maxMEMFreq = 1600'000'000;
|
||||
// this->oc->systemCoreStuckCount = 0;
|
||||
}
|
||||
|
||||
@@ -75,98 +77,18 @@ ClockManager::~ClockManager()
|
||||
bool ClockManager::IsCpuBoostMode()
|
||||
{
|
||||
std::uint32_t confId = this->context->perfConfId;
|
||||
if(confId == 0x92220009 || confId == 0x9222000A)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return (confId == 0x92220009 || confId == 0x9222000A);
|
||||
}
|
||||
|
||||
SysClkProfile ClockManager::ReverseNXProfile(bool ForceDock)
|
||||
bool ClockManager::IsReverseNXEnabled()
|
||||
{
|
||||
RealProfile = Clocks::GetCurrentProfile();
|
||||
switch(RealProfile)
|
||||
{
|
||||
case SysClkProfile_HandheldChargingOfficial:
|
||||
#ifdef FORCE_ALL_HANDHELD_MODES_TO_USE_DOCK_CLOCK
|
||||
case SysClkProfile_HandheldChargingUSB:
|
||||
case SysClkProfile_HandheldCharging:
|
||||
case SysClkProfile_Handheld:
|
||||
#endif
|
||||
if (ForceDock)
|
||||
return SysClkProfile_Docked;
|
||||
else
|
||||
return RealProfile;
|
||||
case SysClkProfile_Docked:
|
||||
if (ForceDock)
|
||||
return SysClkProfile_Docked;
|
||||
else
|
||||
return FileUtils::IsDownclockDockEnabled() ? SysClkProfile_HandheldChargingOfficial : SysClkProfile_Docked;
|
||||
default:
|
||||
return RealProfile;
|
||||
}
|
||||
return (this->oc->reverseNXRTMode || this->oc->reverseNXToolMode);
|
||||
}
|
||||
|
||||
void ClockManager::checkReverseNXTool()
|
||||
bool ClockManager::IsReverseNXDocked()
|
||||
{
|
||||
char ReverseNXToolAsm[] = "_ZN2nn2oe18GetPerformanceModeEv.asm64"; // Checking one asm64 file is enough
|
||||
char ReverseNXToolAsmPath[128];
|
||||
uint8_t flag = 0;
|
||||
snprintf(ReverseNXToolAsmPath, sizeof ReverseNXToolAsmPath, "/SaltySD/patches/%s", ReverseNXToolAsm);
|
||||
|
||||
FILE *readReverseNXToolAsm;
|
||||
readReverseNXToolAsm = fopen(ReverseNXToolAsmPath, "rb");
|
||||
|
||||
// Enforce mode globally: Enabled
|
||||
if(readReverseNXToolAsm != NULL)
|
||||
{
|
||||
checkReverseNXToolAsm(readReverseNXToolAsm, &flag);
|
||||
switch(flag)
|
||||
{
|
||||
case 1:
|
||||
FileUtils::LogLine("[mgr] ReverseNX-Tool patches detected: Enforce Handheld globally");
|
||||
this->context->profile = ReverseNXProfile(false);
|
||||
isDockedReverseNX = false;
|
||||
isEnabledReverseNX = true;
|
||||
isEnabledReverseNXTool = true;
|
||||
break;
|
||||
case 2:
|
||||
FileUtils::LogLine("[mgr] ReverseNX-Tool patches detected: Enforce Docked globally");
|
||||
this->context->profile = ReverseNXProfile(true);
|
||||
isDockedReverseNX = true;
|
||||
isEnabledReverseNX = true;
|
||||
isEnabledReverseNXTool = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(ReverseNXToolAsmPath, sizeof ReverseNXToolAsmPath, "/SaltySD/patches/%016lX/%s", this->context->applicationId, ReverseNXToolAsm);
|
||||
readReverseNXToolAsm = fopen(ReverseNXToolAsmPath, "rb");
|
||||
// Found game-specific setting
|
||||
if(readReverseNXToolAsm != NULL)
|
||||
{
|
||||
checkReverseNXToolAsm(readReverseNXToolAsm, &flag);
|
||||
switch(flag)
|
||||
{
|
||||
case 1:
|
||||
FileUtils::LogLine("[mgr] ReverseNX-Tool patches detected: Force Handheld in %016lX", this->context->applicationId);
|
||||
this->context->profile = ReverseNXProfile(false);
|
||||
isDockedReverseNX = false;
|
||||
isEnabledReverseNX = true;
|
||||
isEnabledReverseNXTool = true;
|
||||
break;
|
||||
case 2:
|
||||
FileUtils::LogLine("[mgr] ReverseNX-Tool patches detected: Force Docked in %016lX", this->context->applicationId);
|
||||
this->context->profile = ReverseNXProfile(true);
|
||||
isDockedReverseNX = true;
|
||||
isEnabledReverseNX = true;
|
||||
isEnabledReverseNXTool = true;
|
||||
break;
|
||||
default:
|
||||
isEnabledReverseNXTool = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (this->oc->reverseNXRTMode == ReverseNX_Docked
|
||||
|| this->oc->reverseNXToolMode == ReverseNX_Docked);
|
||||
}
|
||||
|
||||
void ClockManager::SetRunning(bool running)
|
||||
@@ -186,16 +108,16 @@ uint32_t ClockManager::GetHz(SysClkModule module)
|
||||
/* Temp override setting */
|
||||
hz = this->context->overrideFreqs[module];
|
||||
|
||||
/* Per-Game setting */
|
||||
if (!hz)
|
||||
hz = this->config->GetAutoClockHz(this->context->applicationId, module, this->context->profile);
|
||||
|
||||
/* Global setting */
|
||||
if (!hz)
|
||||
hz = this->config->GetAutoClockHz(0xA111111111111111, module, this->context->profile);
|
||||
|
||||
/* Adjust hz if ReverseNX is enabled */
|
||||
if (!hz && isEnabledReverseNX)
|
||||
/* Per-Game setting */
|
||||
if (!hz)
|
||||
hz = this->config->GetAutoClockHz(this->context->applicationId, module, this->context->profile);
|
||||
|
||||
/* Return pre-set hz if ReverseNX is enabled, downclock is disabled when realProfile == Docked */
|
||||
if (!hz && IsReverseNXEnabled())
|
||||
{
|
||||
switch(module)
|
||||
{
|
||||
@@ -203,15 +125,13 @@ uint32_t ClockManager::GetHz(SysClkModule module)
|
||||
hz = 1020'000'000;
|
||||
break;
|
||||
case SysClkModule_GPU:
|
||||
if (!isDockedReverseNX && ((FileUtils::IsDownclockDockEnabled() && RealProfile == SysClkProfile_Docked)
|
||||
|| RealProfile != SysClkProfile_Docked))
|
||||
if (!IsReverseNXDocked() && this->context->realProfile != SysClkProfile_Docked)
|
||||
hz = 460'800'000;
|
||||
else
|
||||
hz = 768'000'000;
|
||||
break;
|
||||
case SysClkModule_MEM:
|
||||
if (!isDockedReverseNX && ((FileUtils::IsDownclockDockEnabled() && RealProfile == SysClkProfile_Docked)
|
||||
|| RealProfile != SysClkProfile_Docked))
|
||||
if (!IsReverseNXDocked() && this->context->realProfile != SysClkProfile_Docked)
|
||||
hz = 1331'200'000;
|
||||
else
|
||||
hz = 1600'000'000;
|
||||
@@ -223,20 +143,25 @@ uint32_t ClockManager::GetHz(SysClkModule module)
|
||||
|
||||
if (hz)
|
||||
{
|
||||
hz = Clocks::GetNearestHz(module, isEnabledReverseNX ? RealProfile : this->context->profile, hz);
|
||||
/* Considering realProfile frequency limit */
|
||||
hz = Clocks::GetNearestHz(module, this->context->realProfile, hz);
|
||||
|
||||
/* Ignore if MEM Max Hz > 1600 MHz */
|
||||
if (module == SysClkModule_MEM && hz == 1600'000'000 && this->context->freqs[module] >= hz)
|
||||
if (module == SysClkModule_MEM && hz == 1600'000'000)
|
||||
{
|
||||
return 0;
|
||||
/* Return maxMemFreq */
|
||||
if (this->context->freqs[module] > this->oc->maxMEMFreq)
|
||||
this->oc->maxMEMFreq = this->context->freqs[module];
|
||||
|
||||
return this->oc->maxMEMFreq;
|
||||
}
|
||||
}
|
||||
|
||||
if (module == SysClkModule_CPU)
|
||||
{
|
||||
if (this->oc->systemCoreBoostCPU && hz < MAX_CPU)
|
||||
return MAX_CPU;
|
||||
if (this->oc->systemCoreBoostCPU && hz < CPU_BOOST_FREQ)
|
||||
return CPU_BOOST_FREQ;
|
||||
else if (!hz)
|
||||
/* Prevent crash when hz = 0 in SetHz(0), trigger RefreshContext() and Tick() */
|
||||
return 1020'000'000;
|
||||
}
|
||||
|
||||
@@ -255,14 +180,12 @@ void ClockManager::Tick()
|
||||
|
||||
if (hz && hz != this->context->freqs[module])
|
||||
{
|
||||
if (IsCpuBoostMode())
|
||||
// Skip setting CPU or GPU clocks in CpuBoostMode if CPU <= 1963.5MHz or GPU >= 76.8MHz
|
||||
if (IsCpuBoostMode() && ((module == SysClkModule_CPU && hz <= CPU_BOOST_FREQ) || module == SysClkModule_GPU))
|
||||
{
|
||||
// Skip setting CPU or GPU clocks in CpuBoostMode if CPU <= 1963.5MHz or GPU >= 76.8MHz
|
||||
if ((module == SysClkModule_CPU && hz <= MAX_CPU) || module == SysClkModule_GPU)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
FileUtils::LogLine("[mgr] %s clock set : %u.%u Mhz", Clocks::GetModuleName((SysClkModule)module, true), hz/1000000, hz/100000 - hz/1000000*10);
|
||||
Clocks::SetHz((SysClkModule)module, hz);
|
||||
this->context->freqs[module] = hz;
|
||||
@@ -275,36 +198,37 @@ void ClockManager::WaitForNextTick()
|
||||
{
|
||||
/* Self-check system core (#3) usage via idleticks at intervals (Not enabled at higher CPU freq or without charger) */
|
||||
this->oc->tickWaitTimeMs = this->GetConfig()->GetConfigValue(SysClkConfigValue_PollingIntervalMs);
|
||||
uint64_t tickWaitTimeNs = this->oc->tickWaitTimeMs * 1000000ULL;
|
||||
|
||||
if ( this->context->enabled
|
||||
&& this->context->profile != SysClkProfile_Handheld
|
||||
&& this->context->freqs[SysClkModule_CPU] <= MAX_CPU)
|
||||
if ( FileUtils::IsBoostEnabled()
|
||||
&& this->context->realProfile != SysClkProfile_Handheld
|
||||
&& this->context->enabled
|
||||
&& this->context->freqs[SysClkModule_CPU] <= CPU_BOOST_FREQ)
|
||||
{
|
||||
uint64_t systemCoreIdleTickPrev = 0, systemCoreIdleTickNext = 0;
|
||||
svcGetInfo(&systemCoreIdleTickPrev, InfoType_IdleTickCount, INVALID_HANDLE, 3);
|
||||
svcSleepThread(this->oc->tickWaitTimeMs * 1000000ULL);
|
||||
svcSleepThread(tickWaitTimeNs);
|
||||
svcGetInfo(&systemCoreIdleTickNext, InfoType_IdleTickCount, INVALID_HANDLE, 3);
|
||||
|
||||
/* Convert idletick to load% */
|
||||
/* Convert idletick to free% */
|
||||
/* If CPU core usage is 0%, then idletick = 19'200'000 per sec */
|
||||
uint64_t systemCoreIdleTick = systemCoreIdleTickNext - systemCoreIdleTickPrev;
|
||||
uint64_t freeIdleTick = 19'200 * this->oc->tickWaitTimeMs;
|
||||
uint8_t freePerc = systemCoreIdleTick / (freeIdleTick / 100);
|
||||
|
||||
bool systemCoreBoostCPU_PrevState = this->oc->systemCoreBoostCPU;
|
||||
|
||||
switch (this->context->profile)
|
||||
uint8_t systemCoreBoostFreeThreshold = 5;
|
||||
switch (this->context->realProfile)
|
||||
{
|
||||
case SysClkProfile_HandheldChargingOfficial:
|
||||
case SysClkProfile_Docked:
|
||||
this->oc->systemCoreBoostThreshold = systemCoreBoostCPU_PrevState ? 6 : 10;
|
||||
systemCoreBoostFreeThreshold = 10;
|
||||
break;
|
||||
default: // Unofficial charger
|
||||
this->oc->systemCoreBoostThreshold = systemCoreBoostCPU_PrevState ? 3 : 5;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
this->oc->systemCoreBoostCPU = (freePerc <= this->oc->systemCoreBoostThreshold);
|
||||
bool systemCoreBoostCPU_PrevState = this->oc->systemCoreBoostCPU;
|
||||
this->oc->systemCoreBoostCPU = (freePerc <= systemCoreBoostFreeThreshold);
|
||||
|
||||
if (systemCoreBoostCPU_PrevState && !this->oc->systemCoreBoostCPU)
|
||||
{
|
||||
@@ -312,12 +236,12 @@ void ClockManager::WaitForNextTick()
|
||||
}
|
||||
else if (!systemCoreBoostCPU_PrevState && this->oc->systemCoreBoostCPU)
|
||||
{
|
||||
Clocks::SetHz(SysClkModule_CPU, MAX_CPU);
|
||||
Clocks::SetHz(SysClkModule_CPU, CPU_BOOST_FREQ);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
svcSleepThread(this->oc->tickWaitTimeMs * 1000000ULL);
|
||||
svcSleepThread(tickWaitTimeNs);
|
||||
}
|
||||
|
||||
/* Signal that systemCore is not busy */
|
||||
@@ -334,7 +258,7 @@ void ClockManager::WaitForNextTick()
|
||||
{
|
||||
svcSleepThread(clkMgr->oc->tickWaitTimeMs * 1000000ULL);
|
||||
|
||||
if (clkMgr->context->freqs[SysClkModule_CPU] >= clkMgr->MAX_CPU)
|
||||
if (clkMgr->context->freqs[SysClkModule_CPU] >= clkMgr->CPU_BOOST_FREQ)
|
||||
continue;
|
||||
|
||||
// Core #0,1,2 will check if Core#3 is stuck (threshold count = 2*3 = 6)
|
||||
@@ -343,7 +267,7 @@ void ClockManager::WaitForNextTick()
|
||||
{
|
||||
// Signal that current core will take over to boost CPU and wait some time to recheck
|
||||
clkMgr->oc->systemCoreStuckCount = -6;
|
||||
Clocks::SetHz(SysClkModule_CPU, clkMgr->MAX_CPU);
|
||||
Clocks::SetHz(SysClkModule_CPU, clkMgr->CPU_BOOST_FREQ);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
@@ -370,61 +294,107 @@ void ClockManager::WaitForNextTick()
|
||||
threadClose(&this->t_CheckSystemCoreStuck_2);
|
||||
}*/
|
||||
|
||||
void ClockManager::checkReverseNXToolAsm(FILE* readFile, uint8_t* flag)
|
||||
SysClkProfile ClockManager::ReverseNXProfileHandler()
|
||||
{
|
||||
// Magic Value
|
||||
uint8_t Docked[0x10] = {0xE0, 0x03, 0x00, 0x32, 0xC0, 0x03, 0x5F, 0xD6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
uint8_t Handheld[0x10] = {0x00, 0x00, 0xA0, 0x52, 0xC0, 0x03, 0x5F, 0xD6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
uint8_t filebuffer[0x10] = {0};
|
||||
fread(&filebuffer, 1, 16, readFile);
|
||||
|
||||
uint8_t cmpresult = 0;
|
||||
cmpresult = memcmp(filebuffer, Docked, sizeof(Docked));
|
||||
if (cmpresult != 0)
|
||||
if (!IsReverseNXEnabled())
|
||||
{
|
||||
cmpresult = memcmp(filebuffer, Handheld, sizeof(Handheld));
|
||||
if (cmpresult != 0)
|
||||
*flag = 0; // Set to default
|
||||
else
|
||||
*flag = 1; // Handheld
|
||||
return this->context->realProfile;
|
||||
}
|
||||
else
|
||||
*flag = 2; // Docked
|
||||
|
||||
fclose(readFile);
|
||||
if (IsReverseNXDocked())
|
||||
{
|
||||
return SysClkProfile_Docked;
|
||||
}
|
||||
|
||||
if (// !IsReversedNXDocked() &&
|
||||
this->context->realProfile == SysClkProfile_Docked)
|
||||
{
|
||||
return SysClkProfile_HandheldChargingOfficial;
|
||||
}
|
||||
|
||||
return this->context->realProfile;
|
||||
}
|
||||
|
||||
void ClockManager::checkReverseNXRT(bool recheckReverseNX, uint8_t* flag)
|
||||
ReverseNXMode ClockManager::ReverseNXFileHandler(bool checkTool, const char* filePath)
|
||||
{
|
||||
FILE* readReverseNXRTConf = fopen(FILE_REVERSENX_RT_CONF_PATH, "rb");
|
||||
if (readReverseNXRTConf != NULL)
|
||||
FILE *readFile;
|
||||
readFile = fopen(filePath, "rb");
|
||||
|
||||
if (!readFile)
|
||||
{
|
||||
uint8_t ReverseNXRTConfArr[9];
|
||||
fread(ReverseNXRTConfArr, 9, 1, readReverseNXRTConf);
|
||||
fclose(readReverseNXRTConf);
|
||||
remove(FILE_REVERSENX_RT_CONF_PATH);
|
||||
|
||||
uint8_t currentTid[8];
|
||||
for(int i = 0; i < 8; i++)
|
||||
currentTid[i] = this->context->applicationId >> 8*(7-i);
|
||||
|
||||
uint8_t cmpresult = memcmp(currentTid, ReverseNXRTConfArr, sizeof(currentTid));
|
||||
|
||||
if (cmpresult == 0)
|
||||
*flag = ReverseNXRTConfArr[8]; // 1: Handheld, 2: Docked, 3: Reset
|
||||
else
|
||||
*flag = 0; // 0: Not applicable
|
||||
return ReverseNX_NotFound;
|
||||
}
|
||||
else if (recheckReverseNX)
|
||||
*flag = prevReverseNXRT; // Use previous state when profile changes
|
||||
else
|
||||
*flag = 0;
|
||||
|
||||
if (checkTool)
|
||||
{
|
||||
uint64_t magicDocked = 0xD65F03C0320003E0;
|
||||
uint64_t magicHandheld = 0xD65F03C052A00000;
|
||||
|
||||
uint64_t readBuffer = 0;
|
||||
fread(&readBuffer, 1, sizeof(readBuffer), readFile);
|
||||
fclose(readFile);
|
||||
|
||||
if (!memcmp(&readBuffer, &magicDocked, sizeof(readBuffer)))
|
||||
return ReverseNX_Docked;
|
||||
|
||||
if (!memcmp(&readBuffer, &magicHandheld, sizeof(readBuffer)))
|
||||
return ReverseNX_Handheld;
|
||||
}
|
||||
else // checkRT
|
||||
{
|
||||
uint64_t tidBuffer = 0;
|
||||
uint8_t ctrlBuffer = 0;
|
||||
fread(&tidBuffer, 1, sizeof(tidBuffer), readFile);
|
||||
fread(&ctrlBuffer, 1, sizeof(ctrlBuffer), readFile);
|
||||
fclose(readFile);
|
||||
remove(filePath);
|
||||
|
||||
if (!memcmp(&this->context->applicationId, &tidBuffer, sizeof(tidBuffer)))
|
||||
{
|
||||
/* If user toggles -RT overlay, mode set by -Tool remains invalid until the game restarts */
|
||||
this->oc->reverseNXToolMode = ReverseNX_NotValid;
|
||||
|
||||
ReverseNXMode getMode = static_cast<ReverseNXMode>(ctrlBuffer);
|
||||
this->oc->reverseNXRTMode = getMode;
|
||||
|
||||
return getMode;
|
||||
}
|
||||
}
|
||||
|
||||
return ReverseNX_NotValid;
|
||||
}
|
||||
|
||||
void ClockManager::CheckReverseNXTool()
|
||||
{
|
||||
bool shouldCheckReverseNXTool = FileUtils::IsReverseNXSyncEnabled() && FileUtils::ExistReverseNXTool();
|
||||
if (!shouldCheckReverseNXTool)
|
||||
return;
|
||||
|
||||
ReverseNXMode getMode = ReverseNX_NotValid;
|
||||
if (this->context->applicationId != PROCESS_MANAGEMENT_QLAUNCH_TID)
|
||||
{
|
||||
const char asmFileName[] = "_ZN2nn2oe18GetPerformanceModeEv.asm64"; // Checking one asm64 file is enough
|
||||
char asmFilePath[128];
|
||||
|
||||
/* Check global override */
|
||||
snprintf(asmFilePath, sizeof(asmFilePath), "/SaltySD/patches/%s", asmFileName);
|
||||
getMode = ReverseNXFileHandler(true, asmFilePath);
|
||||
|
||||
if (!getMode)
|
||||
{
|
||||
/* Check per-game override */
|
||||
snprintf(asmFilePath, sizeof(asmFilePath), "/SaltySD/patches/%016lX/%s", this->context->applicationId, asmFileName);
|
||||
getMode = ReverseNXFileHandler(true, asmFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
this->oc->reverseNXToolMode = getMode;
|
||||
}
|
||||
|
||||
bool ClockManager::RefreshContext()
|
||||
{
|
||||
bool hasChanged = false;
|
||||
bool shouldAdjustProfile = false;
|
||||
|
||||
bool enabled = this->GetConfig()->Enabled();
|
||||
if(enabled != this->context->enabled)
|
||||
@@ -438,81 +408,42 @@ bool ClockManager::RefreshContext()
|
||||
if (applicationId != this->context->applicationId)
|
||||
{
|
||||
FileUtils::LogLine("[mgr] TitleID change: %016lX", applicationId);
|
||||
prevReverseNXRT = 0; // Reset ReverseNX-RT previous state when Title ID changes
|
||||
this->context->applicationId = applicationId;
|
||||
hasChanged = true;
|
||||
shouldAdjustProfile = true;
|
||||
|
||||
if (FileUtils::IsReverseNXSyncEnabled() && (FileUtils::IsReverseNXToolExist() || recheckReverseNX))
|
||||
{
|
||||
// A new game starts or the real profile changes, then we need to check if ReverseNXTool patches are applied
|
||||
isEnabledReverseNX = false;
|
||||
|
||||
// Check if ReverseNXTool patches are applied
|
||||
if (applicationId != PROCESS_MANAGEMENT_QLAUNCH_TID)
|
||||
this->checkReverseNXTool();
|
||||
}
|
||||
/* Clear ReverseNX-RT state and recheck -Tool patches*/
|
||||
this->oc->reverseNXRTMode = ReverseNX_SystemDefault;
|
||||
CheckReverseNXTool();
|
||||
}
|
||||
|
||||
if (FileUtils::IsReverseNXSyncEnabled() && (!tickCheckReverseNXRT || recheckReverseNX))
|
||||
{
|
||||
uint8_t flag = 0;
|
||||
checkReverseNXRT(recheckReverseNX, &flag);
|
||||
|
||||
switch(flag)
|
||||
{
|
||||
case 1:
|
||||
FileUtils::LogLine("[mgr] ReverseNX-RT detected: Enforce Handheld Mode");
|
||||
this->context->profile = ReverseNXProfile(false);
|
||||
prevReverseNXRT = flag;
|
||||
isEnabledReverseNX = true;
|
||||
isDockedReverseNX = false;
|
||||
hasChanged = true;
|
||||
break;
|
||||
case 2:
|
||||
FileUtils::LogLine("[mgr] ReverseNX-RT detected: Enforce Docked Mode");
|
||||
this->context->profile = ReverseNXProfile(true);
|
||||
prevReverseNXRT = flag;
|
||||
isEnabledReverseNX = true;
|
||||
isDockedReverseNX = true;
|
||||
hasChanged = true;
|
||||
break;
|
||||
case 3:
|
||||
FileUtils::LogLine("[mgr] ReverseNX-RT disabled: Reset to System-controlled Mode and recheck ReverseNX-Tool");
|
||||
RealProfile = Clocks::GetCurrentProfile();
|
||||
this->context->profile = RealProfile;
|
||||
prevReverseNXRT = 0;
|
||||
isEnabledReverseNX = false;
|
||||
isDockedReverseNX = false;
|
||||
hasChanged = true;
|
||||
if (this->context->applicationId != PROCESS_MANAGEMENT_QLAUNCH_TID)
|
||||
this->checkReverseNXTool();
|
||||
break;
|
||||
case 0:
|
||||
if (recheckReverseNX && isEnabledReverseNXTool && this->context->applicationId != PROCESS_MANAGEMENT_QLAUNCH_TID)
|
||||
this->checkReverseNXTool();
|
||||
break;
|
||||
}
|
||||
tickCheckReverseNXRT = (std::uint32_t)( 1'000 / this->oc->tickWaitTimeMs ) + 1;
|
||||
}
|
||||
tickCheckReverseNXRT--;
|
||||
|
||||
if (recheckReverseNX)
|
||||
recheckReverseNX = false;
|
||||
|
||||
SysClkProfile profile = Clocks::GetCurrentProfile();
|
||||
if (profile != this->context->profile && !isEnabledReverseNX)
|
||||
if (profile != this->context->realProfile)
|
||||
{
|
||||
FileUtils::LogLine("[mgr] Profile change: %s", Clocks::GetProfileName(profile, true));
|
||||
this->context->profile = profile;
|
||||
this->context->realProfile = profile;
|
||||
hasChanged = true;
|
||||
shouldAdjustProfile = true;
|
||||
}
|
||||
if (profile != RealProfile && isEnabledReverseNX)
|
||||
|
||||
/* Check ReverseNX-RT once per tick */
|
||||
{
|
||||
FileUtils::LogLine("[mgr] Profile change: %s, recheck ReverseNX", Clocks::GetProfileName(profile, true));
|
||||
this->context->profile = profile;
|
||||
RealProfile = profile;
|
||||
hasChanged = true;
|
||||
recheckReverseNX = true;
|
||||
ReverseNXMode getMode = ReverseNXFileHandler(false, FILE_REVERSENX_RT_CONF_PATH);
|
||||
if (getMode)
|
||||
{
|
||||
this->oc->reverseNXRTMode = getMode;
|
||||
shouldAdjustProfile = true;
|
||||
}
|
||||
|
||||
if (getMode == ReverseNX_RTResetToDefault)
|
||||
{
|
||||
this->oc->reverseNXRTMode = ReverseNX_SystemDefault;
|
||||
}
|
||||
|
||||
if (shouldAdjustProfile)
|
||||
{
|
||||
this->context->profile = ReverseNXProfileHandler();
|
||||
}
|
||||
}
|
||||
|
||||
/* Update PerformanceConfigurationId */
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
class ClockManager
|
||||
{
|
||||
public:
|
||||
const std::uint32_t MAX_CPU = 1963500000;
|
||||
|
||||
static ClockManager* GetInstance();
|
||||
static void Initialize();
|
||||
@@ -47,23 +46,18 @@ class ClockManager
|
||||
std::uint64_t lastTempLogNs;
|
||||
std::uint64_t lastCsvWriteNs;
|
||||
|
||||
bool recheckReverseNX = false;
|
||||
bool isEnabledReverseNX = false;
|
||||
bool isEnabledReverseNXTool = false;
|
||||
bool isDockedReverseNX = false;
|
||||
uint16_t tickCheckReverseNXRT = 0;
|
||||
uint8_t prevReverseNXRT = 0;
|
||||
SysClkProfile RealProfile;
|
||||
SysClkOcExtra *oc;
|
||||
const uint32_t CPU_BOOST_FREQ = 1963'500'000;
|
||||
|
||||
bool IsCpuBoostMode();
|
||||
SysClkProfile ReverseNXProfile(bool);
|
||||
void checkReverseNXTool();
|
||||
bool IsReverseNXEnabled();
|
||||
bool IsReverseNXDocked();
|
||||
|
||||
void checkReverseNXToolAsm(FILE*, uint8_t*);
|
||||
void checkReverseNXRT(bool, uint8_t*);
|
||||
|
||||
SysClkOcExtra *oc;
|
||||
uint32_t GetHz(SysClkModule);
|
||||
SysClkProfile ReverseNXProfileHandler();
|
||||
ReverseNXMode ReverseNXFileHandler(bool, const char*);
|
||||
|
||||
void CheckReverseNXTool();
|
||||
|
||||
// Thread t_CheckSystemCoreStuck_0, t_CheckSystemCoreStuck_1, t_CheckSystemCoreStuck_2;
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#include "clocks.h"
|
||||
#include "errors.h"
|
||||
|
||||
bool Clocks::isMariko = false;
|
||||
|
||||
void Clocks::GetList(SysClkModule module, std::uint32_t **outClocks)
|
||||
{
|
||||
switch(module)
|
||||
@@ -37,6 +35,19 @@ void Clocks::Initialize()
|
||||
{
|
||||
Result rc = 0;
|
||||
|
||||
// Check if it's Mariko
|
||||
u64 hardware_type = 0;
|
||||
splInitialize();
|
||||
splGetConfig(SplConfigItem_HardwareType, &hardware_type);
|
||||
splExit();
|
||||
|
||||
switch (hardware_type) {
|
||||
case 0: //Icosa
|
||||
case 1: //Copper
|
||||
ERROR_THROW("[!] Erista is not supported!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(hosversionAtLeast(8,0,0))
|
||||
{
|
||||
rc = clkrstInitialize();
|
||||
@@ -290,11 +301,7 @@ std::uint32_t Clocks::GetMaxAllowedHz(SysClkModule module, SysClkProfile profile
|
||||
{
|
||||
if(profile < SysClkProfile_HandheldCharging)
|
||||
{
|
||||
return isMariko ? 1344000000 : SYSCLK_GPU_HANDHELD_MAX_HZ;
|
||||
}
|
||||
else if(profile <= SysClkProfile_HandheldChargingUSB)
|
||||
{
|
||||
return isMariko ? 1344000000 : SYSCLK_GPU_UNOFFICIAL_CHARGER_MAX_HZ;
|
||||
return SYSCLK_GPU_HANDHELD_MAX_HZ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,92 +310,6 @@ std::uint32_t Clocks::GetMaxAllowedHz(SysClkModule module, SysClkProfile profile
|
||||
|
||||
std::uint32_t Clocks::GetNearestHz(SysClkModule module, std::uint32_t inHz)
|
||||
{
|
||||
// Hardcoded values to return, or the frequency will ramp up to max as dvfs table is not correct
|
||||
if(module == SysClkModule_MEM)
|
||||
{
|
||||
switch(inHz)
|
||||
{
|
||||
// From Hekate Minerva module
|
||||
case 1331000000:
|
||||
return 1331200000;
|
||||
case 1795000000:
|
||||
return 1795200000;
|
||||
case 1862000000:
|
||||
return 1862400000;
|
||||
case 1894000000:
|
||||
return 1894400000;
|
||||
case 1932000000:
|
||||
return 1932800000;
|
||||
case 1996000000:
|
||||
return 1996800000;
|
||||
case 2099000000:
|
||||
return 2099200000;
|
||||
case 2131000000:
|
||||
return 2131200000;
|
||||
default:
|
||||
return inHz;
|
||||
}
|
||||
}
|
||||
|
||||
if(module == SysClkModule_CPU)
|
||||
{
|
||||
switch(inHz)
|
||||
{
|
||||
case 1963000000:
|
||||
return 1963500000;
|
||||
default:
|
||||
return inHz;
|
||||
}
|
||||
}
|
||||
|
||||
if(module == SysClkModule_GPU)
|
||||
{
|
||||
switch(inHz)
|
||||
{
|
||||
case 76000000:
|
||||
return 76800000;
|
||||
case 153000000:
|
||||
return 153600000;
|
||||
case 230000000:
|
||||
return 230400000;
|
||||
case 307000000:
|
||||
return 307200000;
|
||||
case 460000000:
|
||||
return 460800000;
|
||||
case 537000000:
|
||||
return 537600000;
|
||||
case 614000000:
|
||||
return 614400000;
|
||||
case 691000000:
|
||||
return 691200000;
|
||||
case 844000000:
|
||||
return 844800000;
|
||||
case 921000000:
|
||||
return 921600000;
|
||||
case 998000000:
|
||||
return 998400000;
|
||||
case 1075000000:
|
||||
return 1075200000;
|
||||
case 1228000000:
|
||||
return 1228800000;
|
||||
case 1267000000:
|
||||
return 1267200000;
|
||||
case 1305000000:
|
||||
return 1305600000;
|
||||
case 1382000000:
|
||||
return 1382400000;
|
||||
case 1420000000:
|
||||
return 1420800000;
|
||||
case 1459000000:
|
||||
return 1459200000;
|
||||
case 1497000000:
|
||||
return 1497600000;
|
||||
default:
|
||||
return inHz;
|
||||
}
|
||||
}
|
||||
|
||||
return inHz;
|
||||
std::uint32_t *clockTable = NULL;
|
||||
GetList(module, &clockTable);
|
||||
|
||||
@@ -398,16 +319,19 @@ std::uint32_t Clocks::GetNearestHz(SysClkModule module, std::uint32_t inHz)
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while(clockTable[i + 1])
|
||||
while(clockTable[i])
|
||||
{
|
||||
if (inHz <= (clockTable[i] + clockTable[i + 1]) / 2)
|
||||
// if (inHz <= (clockTable[i] + clockTable[i + 1]) / 2)
|
||||
if ((inHz / 1000'000) == (clockTable[i] / 1000'000))
|
||||
{
|
||||
break;
|
||||
return clockTable[i];
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return clockTable[i];
|
||||
/* Freq not found in the table, return inHz regardlessly */
|
||||
return inHz;
|
||||
}
|
||||
|
||||
std::uint32_t Clocks::GetTemperatureMilli(SysClkThermalSensor sensor)
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
class Clocks
|
||||
{
|
||||
public:
|
||||
static bool isMariko;
|
||||
static void Exit();
|
||||
static void Initialize();
|
||||
static void ResetToStock(unsigned int module = SysClkModule_EnumMax);
|
||||
|
||||
@@ -19,7 +19,6 @@ static LockableMutex g_csv_mutex;
|
||||
static std::atomic_bool g_has_initialized = false;
|
||||
static bool g_log_enabled = false;
|
||||
static bool g_boost_enabled = false;
|
||||
static bool g_downclock_dock_enabled = false;
|
||||
static bool g_reversenx_tool_exist = false;
|
||||
static bool g_reversenx_sync_enabled = false;
|
||||
static std::uint64_t g_last_flag_check = 0;
|
||||
@@ -136,42 +135,11 @@ void FileUtils::RefreshFlags(bool force)
|
||||
|
||||
void FileUtils::InitCheckFlags()
|
||||
{
|
||||
// Check if it's Mariko
|
||||
u64 hardware_type = 0;
|
||||
splInitialize();
|
||||
splGetConfig(SplConfigItem_HardwareType, &hardware_type);
|
||||
splExit();
|
||||
|
||||
switch(hardware_type) {
|
||||
case 0: //Icosa
|
||||
case 1: //Copper
|
||||
break;
|
||||
case 2: //Hoag
|
||||
case 3: //Iowa
|
||||
case 4: //Calcio
|
||||
case 5: //Aula
|
||||
Clocks::isMariko = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
FILE *file;
|
||||
// Only Enable Boost for Mariko
|
||||
if (Clocks::isMariko)
|
||||
{
|
||||
file = fopen(FILE_BOOST_FLAG_PATH, "r");
|
||||
if (file)
|
||||
{
|
||||
g_boost_enabled = true;
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
|
||||
file = fopen(FILE_DOWNCLOCK_DOCK_FLAG_PATH, "r");
|
||||
file = fopen(FILE_BOOST_FLAG_PATH, "r");
|
||||
if (file)
|
||||
{
|
||||
g_downclock_dock_enabled = true;
|
||||
g_boost_enabled = true;
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
@@ -195,12 +163,7 @@ bool FileUtils::IsBoostEnabled()
|
||||
return g_boost_enabled;
|
||||
}
|
||||
|
||||
bool FileUtils::IsDownclockDockEnabled()
|
||||
{
|
||||
return g_downclock_dock_enabled;
|
||||
}
|
||||
|
||||
bool FileUtils::IsReverseNXToolExist()
|
||||
bool FileUtils::ExistReverseNXTool()
|
||||
{
|
||||
return g_reversenx_tool_exist;
|
||||
}
|
||||
@@ -242,12 +205,11 @@ Result FileUtils::Initialize()
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
FileUtils::RefreshFlags(true);
|
||||
FileUtils::InitCheckFlags();
|
||||
g_has_initialized = true;
|
||||
FileUtils::LogLine("=== " TARGET " " TARGET_VERSION " ===");
|
||||
}
|
||||
|
||||
FileUtils::InitCheckFlags();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
#define FILE_LOG_FLAG_PATH FILE_CONFIG_DIR "/log.flag"
|
||||
#define FILE_LOG_FILE_PATH FILE_CONFIG_DIR "/log.txt"
|
||||
#define FILE_BOOST_FLAG_PATH FILE_CONFIG_DIR "/boost.flag"
|
||||
#define FILE_BOOST_START_FLAG_PATH FILE_CONFIG_DIR "/boost_start.flag"
|
||||
#define FILE_DOWNCLOCK_DOCK_FLAG_PATH FILE_CONFIG_DIR "/downclock_dock.flag"
|
||||
#define FILE_SALTYNX_PATH "/atmosphere/contents/0000000000534C56/flags/boot2.flag" // Just check for SaltyNX boot flag
|
||||
#define FILE_REVERSENX_SYNC_FLAG_PATH FILE_CONFIG_DIR "/ReverseNX_sync.flag"
|
||||
#define FILE_REVERSENX_RT_CONF_PATH FILE_CONFIG_DIR "/ReverseNX-RT.conf"
|
||||
@@ -37,9 +35,8 @@ class FileUtils
|
||||
static bool IsInitialized();
|
||||
static bool IsLogEnabled();
|
||||
static bool IsBoostEnabled();
|
||||
static bool IsDownclockDockEnabled();
|
||||
static bool IsReverseNXSyncEnabled();
|
||||
static bool IsReverseNXToolExist();
|
||||
static bool ExistReverseNXTool();
|
||||
static void InitializeAsync();
|
||||
static void LogLine(const char *format, ...);
|
||||
static void WriteContextToCsv(const SysClkContext* context);
|
||||
|
||||
Reference in New Issue
Block a user