From 3fa281f8a57363729e25ed84c1640765019da266 Mon Sep 17 00:00:00 2001 From: souldbminersmwc Date: Tue, 28 Oct 2025 16:34:11 -0400 Subject: [PATCH] hoc-sys: fix tdp --- Source/sys-clk/common/include/sysclk/board.h | 1 + Source/sys-clk/common/include/sysclk/config.h | 39 +++++++++- .../overlay/src/ui/gui/freq_choice_gui.cpp | 2 +- .../sys-clk/overlay/src/ui/gui/misc_gui.cpp | 6 +- Source/sys-clk/sysmodule/src/board.cpp | 8 +- .../sys-clk/sysmodule/src/clock_manager.cpp | 78 ++++++++++++------- Source/sys-clk/sysmodule/src/clock_manager.h | 2 + Source/sys-clk/sysmodule/src/fancontrol.c | 4 +- 8 files changed, 105 insertions(+), 35 deletions(-) diff --git a/Source/sys-clk/common/include/sysclk/board.h b/Source/sys-clk/common/include/sysclk/board.h index da4fd792..6def5a8d 100644 --- a/Source/sys-clk/common/include/sysclk/board.h +++ b/Source/sys-clk/common/include/sysclk/board.h @@ -18,6 +18,7 @@ typedef enum { SysClkSocType_Erista = 0, SysClkSocType_Mariko, + SysClkSocType_MarikoLite, SysClkSocType_EnumMax } SysClkSocType; diff --git a/Source/sys-clk/common/include/sysclk/config.h b/Source/sys-clk/common/include/sysclk/config.h index 051b871f..bd44ee15 100644 --- a/Source/sys-clk/common/include/sysclk/config.h +++ b/Source/sys-clk/common/include/sysclk/config.h @@ -19,18 +19,30 @@ typedef enum { SysClkConfigValue_FreqLogIntervalMs, SysClkConfigValue_PowerLogIntervalMs, SysClkConfigValue_CsvWriteIntervalMs, + HocClkConfigValue_UncappedClocks, HocClkConfigValue_OverwriteBoostMode, + HocClkConfigValue_EristaMaxCpuClock, HocClkConfigValue_EristaMaxGpuClock, HocClkConfigValue_EristaMaxMemClock, HocClkConfigValue_MarikoMaxCpuClock, HocClkConfigValue_MarikoMaxGpuClock, HocClkConfigValue_MarikoMaxMemClock, + HocClkConfigValue_ThermalThrottle, HocClkConfigValue_ThermalThrottleThreshold, + HocClkConfigValue_HandheldGovernor, HocClkConfigValue_DockedGovernor, + + HocClkConfigValue_HandheldTDP, + HocClkConfigValue_HandheldTDPLimit, + HocClkConfigValue_LiteTDPLimit, + HocClkConfigValue_TDPCycleLimit, + + HocClkConfigValue_EnforceBoardLimit, + SysClkConfigValue_EnumMax, } SysClkConfigValue; @@ -82,6 +94,18 @@ static inline const char* sysclkFormatConfigValue(SysClkConfigValue val, bool pr case HocClkConfigValue_HandheldGovernor: return pretty ? "Handheld Governor" : "governor_handheld"; + case HocClkConfigValue_HandheldTDP: + return pretty ? "Handheld TDP" : "handheld_tdp"; + + case HocClkConfigValue_HandheldTDPLimit: + return pretty ? "TDP Limit" : "tdp_limit"; + + case HocClkConfigValue_LiteTDPLimit: + return pretty ? "Lite TDP Limit" : "tdp_limit_l"; + + case HocClkConfigValue_TDPCycleLimit: + return pretty ? "TDP Cycle Limit" : "tdp_limit_c"; + default: return pretty ? "Null" : "null"; } @@ -115,11 +139,18 @@ static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val) return 1862ULL; case HocClkConfigValue_ThermalThrottle: - case HocClkConfigValue_ThermalThrottleThreshold: case HocClkConfigValue_DockedGovernor: case HocClkConfigValue_HandheldGovernor: - case HocClkConfigValue_ThermalThrottleThreshold: + case HocClkConfigValue_HandheldTDP: return 1ULL; + case HocClkConfigValue_ThermalThrottleThreshold: + return 70ULL; + case HocClkConfigValue_HandheldTDPLimit: + return 8600ULL; + case HocClkConfigValue_LiteTDPLimit: + return 6400ULL; + case HocClkConfigValue_TDPCycleLimit: + return 10ULL; default: return 0ULL; } @@ -136,18 +167,22 @@ static inline uint64_t sysclkValidConfigValue(SysClkConfigValue val, uint64_t in case HocClkConfigValue_MarikoMaxGpuClock: case HocClkConfigValue_MarikoMaxMemClock: case HocClkConfigValue_ThermalThrottleThreshold: + case HocClkConfigValue_HandheldTDPLimit: + case HocClkConfigValue_LiteTDPLimit: case SysClkConfigValue_PollingIntervalMs: return input > 0; case SysClkConfigValue_TempLogIntervalMs: case SysClkConfigValue_FreqLogIntervalMs: case SysClkConfigValue_PowerLogIntervalMs: case SysClkConfigValue_CsvWriteIntervalMs: + case HocClkConfigValue_TDPCycleLimit: return input >= 0; case HocClkConfigValue_UncappedClocks: case HocClkConfigValue_OverwriteBoostMode: case HocClkConfigValue_ThermalThrottle: case HocClkConfigValue_DockedGovernor: case HocClkConfigValue_HandheldGovernor: + case HocClkConfigValue_HandheldTDP: return (input & 0x1) == input; default: return false; diff --git a/Source/sys-clk/overlay/src/ui/gui/freq_choice_gui.cpp b/Source/sys-clk/overlay/src/ui/gui/freq_choice_gui.cpp index 68be07ab..242ac0f5 100644 --- a/Source/sys-clk/overlay/src/ui/gui/freq_choice_gui.cpp +++ b/Source/sys-clk/overlay/src/ui/gui/freq_choice_gui.cpp @@ -113,7 +113,7 @@ FreqChoiceGui::~FreqChoiceGui() if (IsMariko()) { unsafe_cpu = 1964; - unsafe_gpu = 1153; + unsafe_gpu = 1076; danger_cpu = 2398; danger_gpu = 1306; } 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 7142e756..d3732048 100644 --- a/Source/sys-clk/overlay/src/ui/gui/misc_gui.cpp +++ b/Source/sys-clk/overlay/src/ui/gui/misc_gui.cpp @@ -108,8 +108,10 @@ void MiscGui::listUI() this->listElement->addItem(new tsl::elm::CategoryHeader("Experimental")); addConfigToggle(HocClkConfigValue_ThermalThrottle, nullptr); - addConfigToggle(HocClkConfigValue_DockedGovernor, nullptr); - addConfigToggle(HocClkConfigValue_HandheldGovernor, nullptr); + addConfigToggle(HocClkConfigValue_HandheldTDP, nullptr); + +// addConfigToggle(HocClkConfigValue_DockedGovernor, nullptr); +// addConfigToggle(HocClkConfigValue_HandheldGovernor, nullptr); this->listElement->addItem(new tsl::elm::CategoryHeader("Max Clocks")); diff --git a/Source/sys-clk/sysmodule/src/board.cpp b/Source/sys-clk/sysmodule/src/board.cpp index 5be2a4f0..f72921bf 100644 --- a/Source/sys-clk/sysmodule/src/board.cpp +++ b/Source/sys-clk/sysmodule/src/board.cpp @@ -465,6 +465,7 @@ SysClkSocType Board::GetSocType() { return g_socType; } + void Board::FetchHardwareInfos() { u64 sku = 0; @@ -478,9 +479,14 @@ void Board::FetchHardwareInfos() switch(sku) { - case 2 ... 5: + case 2: + case 3: + case 5: g_socType = SysClkSocType_Mariko; break; + case 4: + g_socType = SysClkSocType_MarikoLite; + break; default: g_socType = SysClkSocType_Erista; } diff --git a/Source/sys-clk/sysmodule/src/clock_manager.cpp b/Source/sys-clk/sysmodule/src/clock_manager.cpp index 97fc30df..44728f74 100644 --- a/Source/sys-clk/sysmodule/src/clock_manager.cpp +++ b/Source/sys-clk/sysmodule/src/clock_manager.cpp @@ -44,7 +44,6 @@ void ClockManager::Initialize() ClockManager::ClockManager() { this->config = Config::CreateDefault(); - this->context = new SysClkContext; this->context->applicationId = 0; this->context->profile = SysClkProfile_Handheld; @@ -124,7 +123,16 @@ std::uint32_t ClockManager::GetMaxAllowedHz(SysClkModule module, SysClkProfile p { if (profile < SysClkProfile_HandheldCharging) { - return Board::GetSocType() == SysClkSocType_Mariko ? 614400000 : 460800000; + switch(Board::GetSocType()) { + case SysClkSocType_Erista: + return 460800000; + case SysClkSocType_Mariko: + return 614400000; + case SysClkSocType_MarikoLite: + return 537600000; + default: + return 4294967294; + } } else if (profile <= SysClkProfile_HandheldChargingUSB) { @@ -210,19 +218,44 @@ void ClockManager::Tick() std::uint32_t maxHz = 0; std::uint32_t nearestHz = 0; 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::GetSocType() == SysClkSocType_MarikoLite) { + if(Board::GetPowerMw(SysClkPowerSensor_Now) < -(int)this->config->GetConfigValue(HocClkConfigValue_LiteTDPLimit)) { + ResetToStockClocks(); + return; + } + } else { + if(Board::GetPowerMw(SysClkPowerSensor_Now) < -(int)this->config->GetConfigValue(HocClkConfigValue_HandheldTDPLimit)) { + ResetToStockClocks(); + return; + } + } + } + + if(apmExtIsBoostMode(mode) && !this->config->GetConfigValue(HocClkConfigValue_OverwriteBoostMode)) { + ResetToStockClocks(); + return; + } + + if(((tmp451TempSoc() / 1000) > (int)this->config->GetConfigValue(HocClkConfigValue_ThermalThrottleThreshold)) && this->config->GetConfigValue(HocClkConfigValue_ThermalThrottle)) { + ResetToStockClocks(); + return; + } + 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 (!this->config->GetConfigValue(HocClkConfigValue_DockedGovernor) || !this->config->GetConfigValue(HocClkConfigValue_HandheldGovernor)) -// { - if((apmExtIsBoostMode(mode) && !this->config->GetConfigValue(HocClkConfigValue_OverwriteBoostMode)) || ((tmp451TempSoc() / 1000) > (int)this->config->GetConfigValue(HocClkConfigValue_ThermalThrottleThreshold) && this->config->GetConfigValue(HocClkConfigValue_ThermalThrottle)) ) { // WHY?!?!??!?!? - Board::ResetToStockCpu(); - Board::ResetToStockGpu(); - return; - } + targetHz = this->context->overrideFreqs[module]; + if (!targetHz) { targetHz = this->config->GetAutoClockHz(this->context->applicationId, (SysClkModule)module, this->context->profile); @@ -241,27 +274,18 @@ void ClockManager::Tick() Board::SetHz((SysClkModule)module, nearestHz); this->context->freqs[module] = nearestHz; - } else { - Board::ResetToStockCpu(); - Board::ResetToStockGpu(); - } - // } - // } else { - // #define GOVERNOR_LOAD_THRESHOLD 80 - // if(apmExtIsBoostMode(this->context->perfConfId)) { - // Board::ResetToStockCpu(); // GOVERNOR: Reset to stock clocks if boost mode (dont use governor when boosted) - // Board::ResetToStockGpu(); - // } else { - // // Actually run the CPU governor - // if(t210EmcLoadCpu() > GOVERNOR_LOAD_THRESHOLD) { - // realHz = targetHz / 1000000 - // } - // } - } + } + } + } } } +void ClockManager::ResetToStockClocks() { + Board::ResetToStockCpu(); + Board::ResetToStockGpu(); +} + void ClockManager::WaitForNextTick() { svcSleepThread(this->GetConfig()->GetConfigValue(SysClkConfigValue_PollingIntervalMs) * 1000000ULL); diff --git a/Source/sys-clk/sysmodule/src/clock_manager.h b/Source/sys-clk/sysmodule/src/clock_manager.h index 125c3a1e..8b6fe18a 100644 --- a/Source/sys-clk/sysmodule/src/clock_manager.h +++ b/Source/sys-clk/sysmodule/src/clock_manager.h @@ -12,6 +12,7 @@ #include #include +#include #include "config.h" #include "board.h" @@ -37,6 +38,7 @@ class ClockManager bool Running(); void GetFreqList(SysClkModule module, std::uint32_t* list, std::uint32_t maxCount, std::uint32_t* outCount); void Tick(); + void ResetToStockClocks(); void WaitForNextTick(); void SetRNXRTMode(ReverseNXMode mode); struct { diff --git a/Source/sys-clk/sysmodule/src/fancontrol.c b/Source/sys-clk/sysmodule/src/fancontrol.c index ac253e90..11e1be1d 100644 --- a/Source/sys-clk/sysmodule/src/fancontrol.c +++ b/Source/sys-clk/sysmodule/src/fancontrol.c @@ -2,7 +2,7 @@ #include "tmp451.h" //Fan curve table -const TemperaturePoint defaultTable[] = +TemperaturePoint defaultTable[] = { { .temperature_c = 25.0, .fanLevel_f = 0.00 }, { .temperature_c = 30.0, .fanLevel_f = 0.00 }, @@ -135,7 +135,7 @@ void FanControllerThreadFunction(void*) FanController fc; float fanLevelSet_f = 0; float temperatureC_f = 0; - u64 awakeSleepTime = 250000000ULL; // 0.25 second when awake (250ms - responsive) + u64 awakeSleepTime = 1000000000ULL; // 1 second when awake u64 sleepSleepTime = 10000000000ULL; // 10 seconds when in sleep int sleepCheckCounter = 0;