From c5f6eef9fed51173d341b6750f78103b86ac3c3e Mon Sep 17 00:00:00 2001 From: souldbminersmwc Date: Sat, 6 Dec 2025 11:06:32 -0500 Subject: [PATCH] sysmodule/overlay: re-add governor and fix global profile again --- .../common/include/sysclk/clock_manager.h | 4 +- Source/sys-clk/common/include/sysclk/config.h | 4 +- .../sys-clk/overlay/src/ui/gui/misc_gui.cpp | 2 + .../sys-clk/sysmodule/src/clock_manager.cpp | 147 +++++++++++++----- Source/sys-clk/sysmodule/src/ipc_service.cpp | 2 +- 5 files changed, 114 insertions(+), 45 deletions(-) diff --git a/Source/sys-clk/common/include/sysclk/clock_manager.h b/Source/sys-clk/common/include/sysclk/clock_manager.h index 798a5efb..8a8f8c0b 100644 --- a/Source/sys-clk/common/include/sysclk/clock_manager.h +++ b/Source/sys-clk/common/include/sysclk/clock_manager.h @@ -55,4 +55,6 @@ typedef struct #define SYSCLK_FREQ_LIST_MAX 32 #define SYSCLK_GPU_BOOST_HZ 76800000 -#define SYSCLK_CPU_BOOST_HZ 1785000000 \ No newline at end of file +#define SYSCLK_CPU_BOOST_HZ 1785000000 + +#define GLOBAL_PROFILE_ID 0xA111111111111111 \ No newline at end of file diff --git a/Source/sys-clk/common/include/sysclk/config.h b/Source/sys-clk/common/include/sysclk/config.h index 52329fdd..b4cfdb1d 100644 --- a/Source/sys-clk/common/include/sysclk/config.h +++ b/Source/sys-clk/common/include/sysclk/config.h @@ -199,7 +199,7 @@ static inline const char* sysclkFormatConfigValue(SysClkConfigValue val, bool pr case HocClkConfigValue_DockedGovernor: return pretty ? "Docked Governor" : "governor_docked"; case HocClkConfigValue_HandheldGovernor: - return pretty ? "Handheld Governor" : "governor_handheld"; + return pretty ? "Governor" : "governor"; case HocClkConfigValue_HandheldTDP: return pretty ? "Handheld TDP" : "handheld_tdp"; @@ -337,7 +337,7 @@ static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val) switch(val) { case SysClkConfigValue_PollingIntervalMs: - return 300ULL; + return 50ULL; case SysClkConfigValue_TempLogIntervalMs: case SysClkConfigValue_FreqLogIntervalMs: case SysClkConfigValue_PowerLogIntervalMs: diff --git a/Source/sys-clk/overlay/src/ui/gui/misc_gui.cpp b/Source/sys-clk/overlay/src/ui/gui/misc_gui.cpp index 89867f2d..0ccac0b8 100644 --- a/Source/sys-clk/overlay/src/ui/gui/misc_gui.cpp +++ b/Source/sys-clk/overlay/src/ui/gui/misc_gui.cpp @@ -204,6 +204,8 @@ void MiscGui::listUI() addConfigToggle(HocClkConfigValue_UncappedClocks, nullptr); addConfigToggle(HocClkConfigValue_OverwriteBoostMode, nullptr); + addConfigToggle(HocClkConfigValue_HandheldGovernor, nullptr); + this->listElement->addItem(new tsl::elm::CategoryHeader("Experimental")); addConfigToggle(HocClkConfigValue_ThermalThrottle, nullptr); addConfigToggle(HocClkConfigValue_HandheldTDP, nullptr); diff --git a/Source/sys-clk/sysmodule/src/clock_manager.cpp b/Source/sys-clk/sysmodule/src/clock_manager.cpp index ea664f59..86a07015 100644 --- a/Source/sys-clk/sysmodule/src/clock_manager.cpp +++ b/Source/sys-clk/sysmodule/src/clock_manager.cpp @@ -225,10 +225,31 @@ void ClockManager::RefreshFreqTableRow(SysClkModule module) FileUtils::LogLine("[mgr] count = %u", this->freqTable[module].count); } +u32 findIndex(u32 arr[], u32 size, u32 value) { + for (u32 i = 0; i < size; i++) { + if (arr[i] == value) { + return i; + } + } + return 0; +} + +u32 findIndexMHz(u32 arr[], u32 size, u32 value) { + for (u32 i = 0; i < size; i++) { + if (arr[i] / 1000000 == value) { + return i; + } + } + return 0; +} + void ClockManager::Tick() { std::scoped_lock lock{this->contextMutex}; + std::uint32_t mode = 0; AppletOperationMode opMode = appletGetOperationMode(); + Result rc = apmExtGetCurrentPerformanceConfiguration(&mode); + ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration"); if(this->config->GetConfigValue(HocClkConfigValue_HandheldTDP) && opMode == AppletOperationMode_Handheld) { if(Board::GetConsoleType() == HorizonOCConsoleType_Lite) { @@ -250,55 +271,99 @@ void ClockManager::Tick() return; } + u64 currentFreqIndex = findIndex(freqTable[SysClkModule_GPU].list, SYSCLK_FREQ_LIST_MAX, Board::GetHz(SysClkModule_GPU)); + if(this->config->GetConfigValue(HocClkConfigValue_HandheldGovernor)) { + u64 targetHz = this->context->overrideFreqs[SysClkModule_GPU]; + if (!targetHz) + { + targetHz = this->config->GetAutoClockHz(this->context->applicationId, SysClkModule_GPU, this->context->profile); + if(!targetHz) + targetHz = this->config->GetAutoClockHz(GLOBAL_PROFILE_ID, SysClkModule_GPU, this->context->profile); + } + if(Board::GetPartLoad(HocClkPartLoad_GPU) < 600) { + currentFreqIndex--; + if(currentFreqIndex < 0) { + currentFreqIndex = 0; + } + Board::SetHz(SysClkModule_GPU, freqTable[SysClkModule_GPU].list[currentFreqIndex]); + } + if(Board::GetPartLoad(HocClkPartLoad_GPU) > 800) { + currentFreqIndex++; + + if(!targetHz) { + if(IsAssignableHz(SysClkModule_GPU, freqTable[SysClkModule_GPU].list[currentFreqIndex])) { + if(Board::GetSocType() == SysClkSocType_Mariko) { + if(freqTable[SysClkModule_GPU].list[currentFreqIndex] / 1000000 < this->config->GetConfigValue(HocClkConfigValue_MarikoMaxGpuClock)) + currentFreqIndex++; // TODO: make this properly go back to target freq if the old target freq is more than one index away + else // probably needs the max clocks to be stored in hz instead of mhz to compare easily + currentFreqIndex--; + } else { + if(freqTable[SysClkModule_GPU].list[currentFreqIndex] / 1000000 < this->config->GetConfigValue(HocClkConfigValue_EristaMaxGpuClock)) + currentFreqIndex++; + else + currentFreqIndex--; + } + } else { + currentFreqIndex--; + } + } else { + if(currentFreqIndex > findIndex(freqTable[SysClkModule_GPU].list, SYSCLK_FREQ_LIST_MAX, targetHz)) + currentFreqIndex--; + } + Board::SetHz(SysClkModule_GPU, freqTable[SysClkModule_GPU].list[currentFreqIndex]); + + } + } + + bool noGPU = false; + if (this->RefreshContext() || this->config->Refresh()) { std::uint32_t targetHz = 0; std::uint32_t maxHz = 0; std::uint32_t nearestHz = 0; - std::uint32_t mode = 0; - - Result rc = apmExtGetCurrentPerformanceConfiguration(&mode); - ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration"); + if(apmExtIsBoostMode(mode) && !this->config->GetConfigValue(HocClkConfigValue_OverwriteBoostMode)) { + ResetToStockClocks(); + return; + } + for (unsigned int module = 0; module < SysClkModule_EnumMax; module++) + { + if(this->config->GetConfigValue(HocClkConfigValue_HandheldGovernor)) { + noGPU = true; + } else { + noGPU = false; + } + if(noGPU && module == SysClkModule_GPU) + continue; + targetHz = this->context->overrideFreqs[module]; + if (!targetHz) + { + targetHz = this->config->GetAutoClockHz(this->context->applicationId, (SysClkModule)module, this->context->profile); + if(!targetHz) + targetHz = this->config->GetAutoClockHz(GLOBAL_PROFILE_ID, (SysClkModule)module, this->context->profile); + } - if(apmExtIsBoostMode(mode) && !this->config->GetConfigValue(HocClkConfigValue_OverwriteBoostMode)) { - ResetToStockClocks(); - return; + if (targetHz) + { + + maxHz = this->GetMaxAllowedHz((SysClkModule)module, this->context->profile); + nearestHz = this->GetNearestHz((SysClkModule)module, targetHz, maxHz); + if (nearestHz != this->context->freqs[module] && this->context->enabled) { + FileUtils::LogLine( + "[mgr] %s clock set : %u.%u MHz (target = %u.%u MHz)", + Board::GetModuleName((SysClkModule)module, true), + nearestHz / 1000000, nearestHz / 100000 - nearestHz / 1000000 * 10, + targetHz / 1000000, targetHz / 100000 - targetHz / 1000000 * 10); + + Board::SetHz((SysClkModule)module, nearestHz); + this->context->freqs[module] = nearestHz; + } + } + + } } - - if(this->config->GetConfigValue(HocClkConfigValue_HandheldGovernor) && opMode == AppletOperationMode_Handheld) { - - } - if(this->config->GetConfigValue(HocClkConfigValue_DockedGovernor) && opMode == AppletOperationMode_Console) { - - } - for (unsigned int module = 0; module < SysClkModule_EnumMax; module++) - { - targetHz = this->context->overrideFreqs[module]; - - if (!targetHz) - { - targetHz = this->config->GetAutoClockHz(this->context->applicationId, (SysClkModule)module, this->context->profile); - } - - if (targetHz) - { - maxHz = this->GetMaxAllowedHz((SysClkModule)module, this->context->profile); - nearestHz = this->GetNearestHz((SysClkModule)module, targetHz, maxHz); - if (nearestHz != this->context->freqs[module] && this->context->enabled) { - FileUtils::LogLine( - "[mgr] %s clock set : %u.%u MHz (target = %u.%u MHz)", - Board::GetModuleName((SysClkModule)module, true), - nearestHz / 1000000, nearestHz / 100000 - nearestHz / 1000000 * 10, - targetHz / 1000000, targetHz / 100000 - targetHz / 1000000 * 10); - - Board::SetHz((SysClkModule)module, nearestHz); - this->context->freqs[module] = nearestHz; - } - } - - } - } + } void ClockManager::ResetToStockClocks() { diff --git a/Source/sys-clk/sysmodule/src/ipc_service.cpp b/Source/sys-clk/sysmodule/src/ipc_service.cpp index a76f6c65..4ce492a4 100644 --- a/Source/sys-clk/sysmodule/src/ipc_service.cpp +++ b/Source/sys-clk/sysmodule/src/ipc_service.cpp @@ -370,7 +370,7 @@ Result IpcService::SetKipData() { } Result IpcService::GetKipData() { - ClockManager::GetInstance()->GetKipConfigValues(mode); + ClockManager::GetInstance()->GetKipConfigValues(); return 0; }