hoc-sys: add multiple new options

This commit is contained in:
souldbminersmwc
2025-10-26 16:17:06 -04:00
parent ff26bb9e76
commit a14f4932af
9 changed files with 193 additions and 108 deletions

View File

@@ -16,6 +16,8 @@
#include "errors.h"
#include "ipc_service.h"
#define HOSPPC_HAS_BOOST (hosversionAtLeast(7,0,0))
ClockManager *ClockManager::instance = NULL;
ClockManager *ClockManager::GetInstance()
@@ -207,11 +209,20 @@ void ClockManager::Tick()
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");
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;
}
if (!targetHz)
{
targetHz = this->config->GetAutoClockHz(this->context->applicationId, (SysClkModule)module, this->context->profile);
@@ -221,9 +232,7 @@ void ClockManager::Tick()
{
maxHz = this->GetMaxAllowedHz((SysClkModule)module, this->context->profile);
nearestHz = this->GetNearestHz((SysClkModule)module, targetHz, maxHz);
if (nearestHz != this->context->freqs[module] && this->context->enabled/* && !apmExtIsBoostMode(this->context->perfConfId) && !this->config->GetConfigValue(HocClkConfigValue_OverwriteBoostMode)*/)
{
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),
@@ -232,12 +241,10 @@ void ClockManager::Tick()
Board::SetHz((SysClkModule)module, nearestHz);
this->context->freqs[module] = nearestHz;
}
// else
// {
// Board::ResetToStockCpu();
// Board::ResetToStockGpu();
// }
} else {
Board::ResetToStockCpu();
Board::ResetToStockGpu();
}
// }
// } else {
// #define GOVERNOR_LOAD_THRESHOLD 80

View File

@@ -180,24 +180,17 @@ bool Config::SetProfiles(std::uint64_t tid, SysClkTitleProfileList* profiles, bo
std::scoped_lock lock{this->configMutex};
uint8_t numProfiles = 0;
// String pointer array passed to ini
char* iniKeys[SysClkProfile_EnumMax * SysClkModule_EnumMax + 1];
char* iniValues[SysClkProfile_EnumMax * SysClkModule_EnumMax + 1];
// Char arrays to build strings
char keysStr[SysClkProfile_EnumMax * SysClkModule_EnumMax * 0x40];
char valuesStr[SysClkProfile_EnumMax * SysClkModule_EnumMax * 0x10];
char section[17] = {0};
// Iteration pointers
char** ik = &iniKeys[0];
char** iv = &iniValues[0];
char* sk = &keysStr[0];
char* sv = &valuesStr[0];
std::uint32_t* mhz = &profiles->mhz[0];
snprintf(section, sizeof(section), "%016lX", tid);
// Use dynamic allocation
std::vector<std::string> keys;
std::vector<std::string> values;
keys.reserve(SysClkProfile_EnumMax * SysClkModule_EnumMax);
values.reserve(SysClkProfile_EnumMax * SysClkModule_EnumMax);
std::uint32_t* mhz = &profiles->mhz[0];
for(unsigned int profile = 0; profile < SysClkProfile_EnumMax; profile++)
{
for(unsigned int module = 0; module < SysClkModule_EnumMax; module++)
@@ -206,34 +199,38 @@ bool Config::SetProfiles(std::uint64_t tid, SysClkTitleProfileList* profiles, bo
{
numProfiles++;
// Put key and value as string
snprintf(sk, 0x40, "%s_%s", Board::GetProfileName((SysClkProfile)profile, false), Board::GetModuleName((SysClkModule)module, false));
snprintf(sv, 0x10, "%d", *mhz);
// Build key and value strings
std::string key = std::string(Board::GetProfileName((SysClkProfile)profile, false)) +
"_" +
Board::GetModuleName((SysClkModule)module, false);
std::string value = std::to_string(*mhz);
// Add them to the ini key/value str arrays
*ik = sk;
*iv = sv;
ik++;
iv++;
// We used those chars, get to the next ones
sk += 0x40;
sv += 0x10;
keys.push_back(key);
values.push_back(value);
}
mhz++;
}
}
*ik = NULL;
*iv = NULL;
// Build pointer arrays
std::vector<const char*> keyPointers;
std::vector<const char*> valuePointers;
keyPointers.reserve(keys.size() + 1);
valuePointers.reserve(values.size() + 1);
if(!ini_putsection(section, (const char**)iniKeys, (const char**)iniValues, this->path.c_str()))
for(size_t i = 0; i < keys.size(); i++) {
keyPointers.push_back(keys[i].c_str());
valuePointers.push_back(values[i].c_str());
}
keyPointers.push_back(NULL);
valuePointers.push_back(NULL);
if(!ini_putsection(section, keyPointers.data(), valuePointers.data(), this->path.c_str()))
{
return false;
}
// Only actually apply changes in memory after a succesful save
// Only actually apply changes in memory after a successful save
if(immediate)
{
mhz = &profiles->mhz[0];
@@ -414,46 +411,43 @@ bool Config::SetConfigValues(SysClkConfigValueList* configValues, bool immediate
{
std::scoped_lock lock{this->configMutex};
// String pointer array passed to ini
const char* iniKeys[SysClkConfigValue_EnumMax + 1];
char* iniValues[SysClkConfigValue_EnumMax + 1];
// char arrays to build strings
char valuesStr[SysClkConfigValue_EnumMax * 0x80];
// Iteration pointers
char* sv = &valuesStr[0];
const char** ik = &iniKeys[0];
char** iv = &iniValues[0];
// Use dynamic allocation instead of fixed stack buffers
std::vector<const char*> iniKeys;
std::vector<std::string> iniValues;
iniKeys.reserve(SysClkConfigValue_EnumMax + 1);
iniValues.reserve(SysClkConfigValue_EnumMax);
for(unsigned int kval = 0; kval < SysClkConfigValue_EnumMax; kval++)
{
if(!sysclkValidConfigValue((SysClkConfigValue)kval, configValues->values[kval]) || configValues->values[kval] == sysclkDefaultConfigValue((SysClkConfigValue)kval))
if(!sysclkValidConfigValue((SysClkConfigValue)kval, configValues->values[kval]) ||
configValues->values[kval] == sysclkDefaultConfigValue((SysClkConfigValue)kval))
{
continue;
}
// Put key and value as string
// And add them to the ini key/value str arrays
snprintf(sv, 0x20, "%ld", configValues->values[kval]);
*ik = sysclkFormatConfigValue((SysClkConfigValue)kval, false);
*iv = sv;
// We used those chars, get to the next ones
sv += 0x20;
ik++;
iv++;
// Store as string in vector (automatically managed memory)
iniValues.push_back(std::to_string(configValues->values[kval]));
iniKeys.push_back(sysclkFormatConfigValue((SysClkConfigValue)kval, false));
}
*ik = NULL;
*iv = NULL;
// Null terminate
iniKeys.push_back(NULL);
if(!ini_putsection(CONFIG_VAL_SECTION, (const char**)iniKeys, (const char**)iniValues, this->path.c_str()))
// Build pointer array for ini function
std::vector<const char*> valuePointers;
valuePointers.reserve(iniValues.size() + 1);
for(const auto& val : iniValues) {
valuePointers.push_back(val.c_str());
}
valuePointers.push_back(NULL);
if(!ini_putsection(CONFIG_VAL_SECTION, iniKeys.data(), valuePointers.data(), this->path.c_str()))
{
return false;
}
// Only actually apply changes in memory after a succesful save
// Only actually apply changes in memory after a successful save
if(immediate)
{
for(unsigned int kval = 0; kval < SysClkConfigValue_EnumMax; kval++)
@@ -470,4 +464,4 @@ bool Config::SetConfigValues(SysClkConfigValueList* configValues, bool immediate
}
return true;
}
}

View File

@@ -4,15 +4,15 @@
//Fan curve table
const TemperaturePoint defaultTable[] =
{
{ .temperature_c = 25.0, .fanLevel_f = 0.10 },
{ .temperature_c = 30.0, .fanLevel_f = 0.20 },
{ .temperature_c = 35.0, .fanLevel_f = 0.30 },
{ .temperature_c = 40.0, .fanLevel_f = 0.40 },
{ .temperature_c = 45.0, .fanLevel_f = 0.50 },
{ .temperature_c = 50.0, .fanLevel_f = 0.60 },
{ .temperature_c = 55.0, .fanLevel_f = 0.70 },
{ .temperature_c = 60.0, .fanLevel_f = 0.80 },
{ .temperature_c = 65.0, .fanLevel_f = 0.90 },
{ .temperature_c = 25.0, .fanLevel_f = 0.00 },
{ .temperature_c = 30.0, .fanLevel_f = 0.00 },
{ .temperature_c = 35.0, .fanLevel_f = 0.00 },
{ .temperature_c = 40.0, .fanLevel_f = 0.00 },
{ .temperature_c = 45.0, .fanLevel_f = 0.30 },
{ .temperature_c = 50.0, .fanLevel_f = 0.50 },
{ .temperature_c = 55.0, .fanLevel_f = 0.60 },
{ .temperature_c = 60.0, .fanLevel_f = 0.85 },
{ .temperature_c = 65.0, .fanLevel_f = 0.95 },
{ .temperature_c = 70.0, .fanLevel_f = 1.00 }
};
@@ -136,7 +136,7 @@ void FanControllerThreadFunction(void*)
float fanLevelSet_f = 0;
float temperatureC_f = 0;
u64 awakeSleepTime = 250000000ULL; // 0.25 second when awake (250ms - responsive)
u64 sleepSleepTime = 5000000000ULL; // 5 seconds when in sleep
u64 sleepSleepTime = 10000000000ULL; // 10 seconds when in sleep
int sleepCheckCounter = 0;
Result rs = fanOpenController(&fc, 0x3D000001);
@@ -148,9 +148,9 @@ void FanControllerThreadFunction(void*)
while(!fanControllerThreadExit)
{
// Check if system is awake every 20 iterations (~5 seconds) to reduce overhead
// Check if system is awake every 40 iterations (~10 seconds) to reduce overhead
sleepCheckCounter++;
if(sleepCheckCounter >= 20)
if(sleepCheckCounter >= 40)
{
bool isAwake = IsSystemAwake();
sleepCheckCounter = 0;

View File

@@ -145,7 +145,7 @@ Result IpcService::ServiceHandlerFunc(void* arg, const IpcServerRequest* r, u8*
break;
case SysClkIpcCmd_GetConfigValues:
*out_dataSize = sizeof(SysClkTitleProfileList);
*out_dataSize = sizeof(SysClkConfigValueList); // bug in stock sys-clk. really stupid bug :skull:
return ipcSrv->GetConfigValues((SysClkConfigValueList*)out_data);
case SysClkIpcCmd_SetConfigValues: