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

@@ -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;
}

View File

@@ -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);

View File

@@ -12,6 +12,7 @@
#include <atomic>
#include <sysclk.h>
#include <switch.h>
#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 {

View File

@@ -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;