hoc-sys: fix tdp

This commit is contained in:
souldbminersmwc
2025-10-28 16:34:11 -04:00
parent a14f4932af
commit 3fa281f8a5
8 changed files with 105 additions and 35 deletions

View File

@@ -18,6 +18,7 @@ typedef enum
{ {
SysClkSocType_Erista = 0, SysClkSocType_Erista = 0,
SysClkSocType_Mariko, SysClkSocType_Mariko,
SysClkSocType_MarikoLite,
SysClkSocType_EnumMax SysClkSocType_EnumMax
} SysClkSocType; } SysClkSocType;

View File

@@ -19,18 +19,30 @@ typedef enum {
SysClkConfigValue_FreqLogIntervalMs, SysClkConfigValue_FreqLogIntervalMs,
SysClkConfigValue_PowerLogIntervalMs, SysClkConfigValue_PowerLogIntervalMs,
SysClkConfigValue_CsvWriteIntervalMs, SysClkConfigValue_CsvWriteIntervalMs,
HocClkConfigValue_UncappedClocks, HocClkConfigValue_UncappedClocks,
HocClkConfigValue_OverwriteBoostMode, HocClkConfigValue_OverwriteBoostMode,
HocClkConfigValue_EristaMaxCpuClock, HocClkConfigValue_EristaMaxCpuClock,
HocClkConfigValue_EristaMaxGpuClock, HocClkConfigValue_EristaMaxGpuClock,
HocClkConfigValue_EristaMaxMemClock, HocClkConfigValue_EristaMaxMemClock,
HocClkConfigValue_MarikoMaxCpuClock, HocClkConfigValue_MarikoMaxCpuClock,
HocClkConfigValue_MarikoMaxGpuClock, HocClkConfigValue_MarikoMaxGpuClock,
HocClkConfigValue_MarikoMaxMemClock, HocClkConfigValue_MarikoMaxMemClock,
HocClkConfigValue_ThermalThrottle, HocClkConfigValue_ThermalThrottle,
HocClkConfigValue_ThermalThrottleThreshold, HocClkConfigValue_ThermalThrottleThreshold,
HocClkConfigValue_HandheldGovernor, HocClkConfigValue_HandheldGovernor,
HocClkConfigValue_DockedGovernor, HocClkConfigValue_DockedGovernor,
HocClkConfigValue_HandheldTDP,
HocClkConfigValue_HandheldTDPLimit,
HocClkConfigValue_LiteTDPLimit,
HocClkConfigValue_TDPCycleLimit,
HocClkConfigValue_EnforceBoardLimit,
SysClkConfigValue_EnumMax, SysClkConfigValue_EnumMax,
} SysClkConfigValue; } SysClkConfigValue;
@@ -82,6 +94,18 @@ static inline const char* sysclkFormatConfigValue(SysClkConfigValue val, bool pr
case HocClkConfigValue_HandheldGovernor: case HocClkConfigValue_HandheldGovernor:
return pretty ? "Handheld Governor" : "governor_handheld"; 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: default:
return pretty ? "Null" : "null"; return pretty ? "Null" : "null";
} }
@@ -115,11 +139,18 @@ static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val)
return 1862ULL; return 1862ULL;
case HocClkConfigValue_ThermalThrottle: case HocClkConfigValue_ThermalThrottle:
case HocClkConfigValue_ThermalThrottleThreshold:
case HocClkConfigValue_DockedGovernor: case HocClkConfigValue_DockedGovernor:
case HocClkConfigValue_HandheldGovernor: case HocClkConfigValue_HandheldGovernor:
case HocClkConfigValue_ThermalThrottleThreshold: case HocClkConfigValue_HandheldTDP:
return 1ULL; return 1ULL;
case HocClkConfigValue_ThermalThrottleThreshold:
return 70ULL;
case HocClkConfigValue_HandheldTDPLimit:
return 8600ULL;
case HocClkConfigValue_LiteTDPLimit:
return 6400ULL;
case HocClkConfigValue_TDPCycleLimit:
return 10ULL;
default: default:
return 0ULL; return 0ULL;
} }
@@ -136,18 +167,22 @@ static inline uint64_t sysclkValidConfigValue(SysClkConfigValue val, uint64_t in
case HocClkConfigValue_MarikoMaxGpuClock: case HocClkConfigValue_MarikoMaxGpuClock:
case HocClkConfigValue_MarikoMaxMemClock: case HocClkConfigValue_MarikoMaxMemClock:
case HocClkConfigValue_ThermalThrottleThreshold: case HocClkConfigValue_ThermalThrottleThreshold:
case HocClkConfigValue_HandheldTDPLimit:
case HocClkConfigValue_LiteTDPLimit:
case SysClkConfigValue_PollingIntervalMs: case SysClkConfigValue_PollingIntervalMs:
return input > 0; return input > 0;
case SysClkConfigValue_TempLogIntervalMs: case SysClkConfigValue_TempLogIntervalMs:
case SysClkConfigValue_FreqLogIntervalMs: case SysClkConfigValue_FreqLogIntervalMs:
case SysClkConfigValue_PowerLogIntervalMs: case SysClkConfigValue_PowerLogIntervalMs:
case SysClkConfigValue_CsvWriteIntervalMs: case SysClkConfigValue_CsvWriteIntervalMs:
case HocClkConfigValue_TDPCycleLimit:
return input >= 0; return input >= 0;
case HocClkConfigValue_UncappedClocks: case HocClkConfigValue_UncappedClocks:
case HocClkConfigValue_OverwriteBoostMode: case HocClkConfigValue_OverwriteBoostMode:
case HocClkConfigValue_ThermalThrottle: case HocClkConfigValue_ThermalThrottle:
case HocClkConfigValue_DockedGovernor: case HocClkConfigValue_DockedGovernor:
case HocClkConfigValue_HandheldGovernor: case HocClkConfigValue_HandheldGovernor:
case HocClkConfigValue_HandheldTDP:
return (input & 0x1) == input; return (input & 0x1) == input;
default: default:
return false; return false;

View File

@@ -113,7 +113,7 @@ FreqChoiceGui::~FreqChoiceGui()
if (IsMariko()) if (IsMariko())
{ {
unsafe_cpu = 1964; unsafe_cpu = 1964;
unsafe_gpu = 1153; unsafe_gpu = 1076;
danger_cpu = 2398; danger_cpu = 2398;
danger_gpu = 1306; danger_gpu = 1306;
} }

View File

@@ -108,8 +108,10 @@ void MiscGui::listUI()
this->listElement->addItem(new tsl::elm::CategoryHeader("Experimental")); this->listElement->addItem(new tsl::elm::CategoryHeader("Experimental"));
addConfigToggle(HocClkConfigValue_ThermalThrottle, nullptr); addConfigToggle(HocClkConfigValue_ThermalThrottle, nullptr);
addConfigToggle(HocClkConfigValue_DockedGovernor, nullptr); addConfigToggle(HocClkConfigValue_HandheldTDP, nullptr);
addConfigToggle(HocClkConfigValue_HandheldGovernor, nullptr);
// addConfigToggle(HocClkConfigValue_DockedGovernor, nullptr);
// addConfigToggle(HocClkConfigValue_HandheldGovernor, nullptr);
this->listElement->addItem(new tsl::elm::CategoryHeader("Max Clocks")); this->listElement->addItem(new tsl::elm::CategoryHeader("Max Clocks"));

View File

@@ -465,6 +465,7 @@ SysClkSocType Board::GetSocType() {
return g_socType; return g_socType;
} }
void Board::FetchHardwareInfos() void Board::FetchHardwareInfos()
{ {
u64 sku = 0; u64 sku = 0;
@@ -478,9 +479,14 @@ void Board::FetchHardwareInfos()
switch(sku) switch(sku)
{ {
case 2 ... 5: case 2:
case 3:
case 5:
g_socType = SysClkSocType_Mariko; g_socType = SysClkSocType_Mariko;
break; break;
case 4:
g_socType = SysClkSocType_MarikoLite;
break;
default: default:
g_socType = SysClkSocType_Erista; g_socType = SysClkSocType_Erista;
} }

View File

@@ -44,7 +44,6 @@ void ClockManager::Initialize()
ClockManager::ClockManager() ClockManager::ClockManager()
{ {
this->config = Config::CreateDefault(); this->config = Config::CreateDefault();
this->context = new SysClkContext; this->context = new SysClkContext;
this->context->applicationId = 0; this->context->applicationId = 0;
this->context->profile = SysClkProfile_Handheld; this->context->profile = SysClkProfile_Handheld;
@@ -124,7 +123,16 @@ std::uint32_t ClockManager::GetMaxAllowedHz(SysClkModule module, SysClkProfile p
{ {
if (profile < SysClkProfile_HandheldCharging) 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) else if (profile <= SysClkProfile_HandheldChargingUSB)
{ {
@@ -210,19 +218,44 @@ void ClockManager::Tick()
std::uint32_t maxHz = 0; std::uint32_t maxHz = 0;
std::uint32_t nearestHz = 0; std::uint32_t nearestHz = 0;
std::uint32_t mode = 0; std::uint32_t mode = 0;
AppletOperationMode opMode = appletGetOperationMode();
Result rc = apmExtGetCurrentPerformanceConfiguration(&mode); Result rc = apmExtGetCurrentPerformanceConfiguration(&mode);
ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration"); 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++) for (unsigned int module = 0; module < SysClkModule_EnumMax; module++)
{ {
targetHz = this->context->overrideFreqs[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;
}
if (!targetHz) if (!targetHz)
{ {
targetHz = this->config->GetAutoClockHz(this->context->applicationId, (SysClkModule)module, this->context->profile); targetHz = this->config->GetAutoClockHz(this->context->applicationId, (SysClkModule)module, this->context->profile);
@@ -241,27 +274,18 @@ void ClockManager::Tick()
Board::SetHz((SysClkModule)module, nearestHz); Board::SetHz((SysClkModule)module, nearestHz);
this->context->freqs[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() void ClockManager::WaitForNextTick()
{ {
svcSleepThread(this->GetConfig()->GetConfigValue(SysClkConfigValue_PollingIntervalMs) * 1000000ULL); svcSleepThread(this->GetConfig()->GetConfigValue(SysClkConfigValue_PollingIntervalMs) * 1000000ULL);

View File

@@ -12,6 +12,7 @@
#include <atomic> #include <atomic>
#include <sysclk.h> #include <sysclk.h>
#include <switch.h>
#include "config.h" #include "config.h"
#include "board.h" #include "board.h"
@@ -37,6 +38,7 @@ class ClockManager
bool Running(); bool Running();
void GetFreqList(SysClkModule module, std::uint32_t* list, std::uint32_t maxCount, std::uint32_t* outCount); void GetFreqList(SysClkModule module, std::uint32_t* list, std::uint32_t maxCount, std::uint32_t* outCount);
void Tick(); void Tick();
void ResetToStockClocks();
void WaitForNextTick(); void WaitForNextTick();
void SetRNXRTMode(ReverseNXMode mode); void SetRNXRTMode(ReverseNXMode mode);
struct { struct {

View File

@@ -2,7 +2,7 @@
#include "tmp451.h" #include "tmp451.h"
//Fan curve table //Fan curve table
const TemperaturePoint defaultTable[] = TemperaturePoint defaultTable[] =
{ {
{ .temperature_c = 25.0, .fanLevel_f = 0.00 }, { .temperature_c = 25.0, .fanLevel_f = 0.00 },
{ .temperature_c = 30.0, .fanLevel_f = 0.00 }, { .temperature_c = 30.0, .fanLevel_f = 0.00 },
@@ -135,7 +135,7 @@ void FanControllerThreadFunction(void*)
FanController fc; FanController fc;
float fanLevelSet_f = 0; float fanLevelSet_f = 0;
float temperatureC_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 u64 sleepSleepTime = 10000000000ULL; // 10 seconds when in sleep
int sleepCheckCounter = 0; int sleepCheckCounter = 0;