hocclk: reduce ram usage and add display undervolt

This commit is contained in:
souldbminersmwc
2026-04-06 15:57:10 -04:00
parent 8faaaa58d9
commit 521e3c22dd
11 changed files with 105 additions and 82 deletions

View File

@@ -217,8 +217,13 @@ namespace clockManager {
void HandleMiscFeatures()
{
if (config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent)) {
I2c_Bq24193_SetFastChargeCurrentLimit(config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent));
static u32 tick = 0;
if(++tick > 10) {
if (config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent)) {
I2c_Bq24193_SetFastChargeCurrentLimit(config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent));
}
tick = 0;
I2c_BuckConverter_SetMvOut(&I2c_Display, config::GetConfigValue(HocClkConfigValue_DisplayVoltage));
}
}
@@ -560,12 +565,12 @@ namespace clockManager {
board::FuseData *fuse = board::GetFuseData();
gContext.speedos[0] = fuse->cpuSpeedo;
gContext.speedos[1] = fuse->gpuSpeedo;
gContext.speedos[2] = fuse->socSpeedo;
gContext.iddq[0] = fuse->cpuIDDQ;
gContext.iddq[1] = fuse->gpuIDDQ;
gContext.iddq[2] = fuse->socIDDQ;
gContext.speedos[HocClkSpeedo_CPU] = fuse->cpuSpeedo;
gContext.speedos[HocClkSpeedo_GPU] = fuse->gpuSpeedo;
gContext.speedos[HocClkSpeedo_SOC] = fuse->socSpeedo;
gContext.iddq[HocClkSpeedo_CPU] = fuse->cpuIDDQ;
gContext.iddq[HocClkSpeedo_GPU] = fuse->gpuIDDQ;
gContext.iddq[HocClkSpeedo_SOC] = fuse->socIDDQ;
gContext.waferX = fuse->waferX;
gContext.waferY = fuse->waferY;
@@ -625,9 +630,9 @@ namespace clockManager {
bool isBoost = apmExtIsBoostMode(mode);
HandleSafetyFeatures();
HandleMiscFeatures();
if (RefreshContext() || config::Refresh()) {
HandleMiscFeatures();
SetClocks(isBoost);
}
}

View File

@@ -30,28 +30,12 @@
#include <cstring>
namespace errors {
namespace {
const char* FormatMessage(const char* format, va_list args) {
size_t len = vsnprintf(NULL, 0, format, args) * sizeof(char);
char* buf = (char*)malloc(len + 1);
if (buf == NULL) {
return format;
}
vsnprintf(buf, len + 1, format, args);
return buf;
}
}
void ThrowException(const char* format, ...) {
va_list args;
va_start(args, format);
const char* msg = FormatMessage(format, args);
va_end(args);
fileUtils::LogLine(format, args);
throw std::runtime_error(msg);
va_end(args);
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
// throw std::runtime_error(msg);
}
}

View File

@@ -84,9 +84,8 @@ namespace fileUtils {
if (file) {
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
struct tm* nowTm = localtime(&now.tv_sec);
fprintf(file, "[%04d-%02d-%02d %02d:%02d:%02d.%03ld] ", nowTm->tm_year+1900, nowTm->tm_mon+1, nowTm->tm_mday, nowTm->tm_hour, nowTm->tm_min, nowTm->tm_sec, now.tv_nsec / 1000000UL);
fprintf(file, "[%lu] ", armGetSystemTick());
vfprintf(file, format, args);
fprintf(file, "\n");
fclose(file);

View File

@@ -38,7 +38,5 @@ namespace governor {
void startThreads();
void exitThreads();
void HandleGovernor(uint32_t targetHz);
void CpuGovernorThread(void* arg);
void GovernorThread(void* arg);
void VRRThread(void* arg);
}

View File

@@ -37,8 +37,8 @@
#include "clock_manager.hpp"
#include "ipc_service.hpp"
#include "config.hpp"
#define INNER_HEAP_SIZE 0x45000
#define INNER_HEAP_SIZE 0x45000
extern "C"
{
@@ -54,6 +54,23 @@ extern "C"
char nx_inner_heap[INNER_HEAP_SIZE];
NvServiceType __nx_nv_service_type = NvServiceType_Factory;
// Ty to MasaGratoR for this!
//This is done to save some space as they have no practical use in our case
void* __real___cxa_throw(void *thrown_exception, void *pvar, void (*dest)(void *));
void* __real__Unwind_Resume();
void* __real___gxx_personality_v0();
void __wrap___cxa_throw(void *thrown_exception, void *pvar, void (*dest)(void *)) {
abort();
}
void __wrap__Unwind_Resume() {
return;
}
void __wrap___gxx_personality_v0() {
return;
}
void __libnx_initheap(void)
{
@@ -94,20 +111,19 @@ extern "C"
rc = i2cInitialize();
if (R_FAILED(rc))
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
rc = appletInitialize();
if (R_FAILED(rc))
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
}
}
void __appExit(void)
{
// CloseFanControllerThread();
// fanExit();
i2cExit();
fsExit();
setsysExit();
fsdevUnmountAll();
appletExit();
}
fsExit();
smExit();
}
}
int main(int argc, char** argv)
@@ -119,48 +135,36 @@ int main(int argc, char** argv)
return 1;
}
try
board::Initialize();
processManagement::Initialize();
processManagement::WaitForQLaunch();
clockManager::Initialize();
ipcService::Initialize();
fileUtils::LogLine("Ready");
clockManager::SetRunning(true);
config::SetEnabled(true);
ipcService::SetRunning(true);
// TemperaturePoint *table;
// ReadConfigFile(&table);
// InitFanController(table);
// StartFanControllerThread();
while (clockManager::Running())
{
board::Initialize();
processManagement::Initialize();
processManagement::WaitForQLaunch();
clockManager::Initialize();
ipcService::Initialize();
fileUtils::LogLine("Ready");
clockManager::SetRunning(true);
config::SetEnabled(true);
ipcService::SetRunning(true);
// TemperaturePoint *table;
// ReadConfigFile(&table);
// InitFanController(table);
// StartFanControllerThread();
while (clockManager::Running())
{
clockManager::Tick();
clockManager::WaitForNextTick();
}
ipcService::SetRunning(false);
ipcService::Exit();
clockManager::Exit();
processManagement::Exit();
board::Exit();
}
catch (const std::exception &ex)
{
fileUtils::LogLine("[!] %s", ex.what());
}
catch (...)
{
std::exception_ptr p = std::current_exception();
fileUtils::LogLine("[!?] %s", p ? p.__cxa_exception_type()->name() : "...");
clockManager::Tick();
clockManager::WaitForNextTick();
}
ipcService::SetRunning(false);
ipcService::Exit();
clockManager::Exit();
processManagement::Exit();
board::Exit();
fileUtils::LogLine("Exit");
svcSleepThread(1000000ULL);
fileUtils::Exit();