AutoCPUBoost for governor

This commit is contained in:
KazushiM
2022-10-31 12:55:27 +08:00
parent f1225c9ed1
commit 6a1ac29733
4 changed files with 30 additions and 20 deletions

View File

@@ -189,7 +189,6 @@ void ClockManager::WaitForNextTick()
if (boostOK) { if (boostOK) {
uint32_t core3Util = CpuCoreUtil(3, tickWaitTimeMs * 1000'000ULL).Get(); uint32_t core3Util = CpuCoreUtil(3, tickWaitTimeMs * 1000'000ULL).Get();
bool lastBoost = this->oc->systemCoreBoostCPU; bool lastBoost = this->oc->systemCoreBoostCPU;
constexpr uint32_t BOOST_THRESHOLD = 95'0;
this->oc->systemCoreBoostCPU = (core3Util >= BOOST_THRESHOLD); this->oc->systemCoreBoostCPU = (core3Util >= BOOST_THRESHOLD);
if (lastBoost && !this->oc->systemCoreBoostCPU) if (lastBoost && !this->oc->systemCoreBoostCPU)
@@ -217,8 +216,11 @@ bool ClockManager::RefreshContext()
bool hasChanged = this->config->Refresh(); bool hasChanged = this->config->Refresh();
if (hasChanged) { if (hasChanged) {
this->rnxSync->ToggleSync(this->GetConfig()->GetConfigValue(SysClkConfigValue_SyncReverseNXMode)); this->rnxSync->ToggleSync(this->GetConfig()->GetConfigValue(SysClkConfigValue_SyncReverseNXMode));
bool allowUnsafe = this->GetConfig()->GetConfigValue(SysClkConfigValue_AllowUnsafeFrequencies); if (Clocks::GetIsMariko()) {
Clocks::SetAllowUnsafe(allowUnsafe); bool allowUnsafe = this->GetConfig()->GetConfigValue(SysClkConfigValue_AllowUnsafeFrequencies);
Clocks::SetAllowUnsafe(allowUnsafe);
this->governor->SetAutoCPUBoost(this->GetConfig()->GetConfigValue(SysClkConfigValue_AutoCPUBoost));
}
} }
bool enabled = this->GetConfig()->Enabled(); bool enabled = this->GetConfig()->Enabled();

View File

@@ -14,6 +14,7 @@
#include <sysclk.h> #include <sysclk.h>
#define MAX_MEM_CLOCK 1862'400'000 #define MAX_MEM_CLOCK 1862'400'000
#define BOOST_THRESHOLD 95'0
class Clocks class Clocks
{ {

View File

@@ -272,32 +272,33 @@ void Governor::s_FreqContext::SetBoostHz() {
void Governor::CpuUtilWorker(void* args) { void Governor::CpuUtilWorker(void* args) {
s_CoreContext* s = static_cast<s_CoreContext*>(args); s_CoreContext* s = static_cast<s_CoreContext*>(args);
int coreid = s->id; int coreid = s->id;
constexpr int SYS_CORE_ID = (CORE_NUMS - 1);
Governor* self = s->self; Governor* self = s->self;
while (self->m_running) { while (self->m_running) {
uint64_t timestamp = armTicksToNs(armGetSystemTick());
s->timestamp = timestamp;
s->util = self->m_cpu_freq.GetNormalizedUtil(CpuCoreUtil(coreid, TICK_TIME_NS).Get());
bool CPUBoosted = apmExtIsCPUBoosted(self->m_perf_conf_id); bool CPUBoosted = apmExtIsCPUBoosted(self->m_perf_conf_id);
if (CPUBoosted) { if (CPUBoosted) {
svcSleepThread(TICK_TIME_NS); svcSleepThread(TICK_TIME_NS);
continue; continue;
} }
uint64_t timestamp = armTicksToNs(armGetSystemTick());
s->timestamp = timestamp;
for (int id = 0; id < CORE_NUMS; id++) { for (int id = 0; id < CORE_NUMS; id++) {
if (abs(self->m_cpu_core_ctx[id].timestamp - timestamp) < TICK_TIME_NS * 10) if (abs(self->m_cpu_core_ctx[id].timestamp - timestamp) < TICK_TIME_NS * 10)
continue; continue;
if (id == SYS_CORE_ID) { if (id == SYS_CORE_ID && self->m_syscore_autoboost) {
self->m_cpu_freq.SetBoostHz(); self->m_cpu_freq.SetBoostHz();
} else { break;
self->m_cpu_freq.target_hz = self->m_cpu_freq.max_hz;
self->m_cpu_freq.SetHz();
} }
self->m_cpu_freq.target_hz = self->m_cpu_freq.max_hz;
self->m_cpu_freq.SetHz();
break; break;
} }
s->util = self->m_cpu_freq.GetNormalizedUtil(CpuCoreUtil(coreid, TICK_TIME_NS).Get());
} }
} }
@@ -308,20 +309,24 @@ void Governor::Main(void* args) {
uint32_t nvgpu_field = self->m_nvgpu_field; uint32_t nvgpu_field = self->m_nvgpu_field;
s_Util cpu_util, gpu_util; s_Util cpu_util, gpu_util;
auto GetAdjCpuUtil = [self, cpu_util]() mutable { auto SetCpuFreq = [self, cpu_ctx, cpu_util]() mutable {
uint64_t util = self->m_cpu_core_ctx[0].util; uint32_t util = self->m_cpu_core_ctx[0].util;
for (size_t i = 1; i < CORE_NUMS; i++) { for (size_t i = 1; i < CORE_NUMS; i++) {
if (util < self->m_cpu_core_ctx[i].util) if (util < self->m_cpu_core_ctx[i].util)
util = self->m_cpu_core_ctx[i].util; util = self->m_cpu_core_ctx[i].util;
} }
cpu_util.Update(util); cpu_util.Update(util);
return cpu_util.Get(); if (self->m_cpu_core_ctx[SYS_CORE_ID].util > 95'0 && self->m_syscore_autoboost)
cpu_ctx->SetBoostHz();
else
cpu_ctx->SetNextFreq(cpu_util.Get());
}; };
auto GetAdjGpuUtil = [gpu_ctx, nvgpu_field, gpu_util]() mutable { auto SetGpuFreq = [gpu_ctx, nvgpu_field, gpu_util]() mutable {
uint32_t util = gpu_ctx->GetNormalizedUtil(GpuCoreUtil(nvgpu_field).Get()); uint32_t util = gpu_ctx->GetNormalizedUtil(GpuCoreUtil(nvgpu_field).Get());
gpu_util.Update(util); gpu_util.Update(util);
return gpu_util.Get(); util = gpu_util.Get();
gpu_ctx->SetNextFreq(util);
}; };
constexpr uint64_t UPDATE_CONTEXT_RATE = SAMPLE_RATE / 2; constexpr uint64_t UPDATE_CONTEXT_RATE = SAMPLE_RATE / 2;
@@ -360,9 +365,9 @@ void Governor::Main(void* args) {
} }
if (!GPUThrottled) if (!GPUThrottled)
gpu_ctx->SetNextFreq(GetAdjGpuUtil()); SetGpuFreq();
if (!CPUBoosted) if (!CPUBoosted)
cpu_ctx->SetNextFreq(GetAdjCpuUtil()); SetCpuFreq();
svcSleepThread(TICK_TIME_NS); svcSleepThread(TICK_TIME_NS);
} }

View File

@@ -70,7 +70,7 @@ public:
void Start(); void Start();
void Stop(); void Stop();
void SetMaxHz(uint32_t max_hz, SysClkModule module); void SetMaxHz(uint32_t max_hz, SysClkModule module);
void SetCPUBoostHz(uint32_t hz) { m_cpu_freq.boost_hz = hz; }; void SetAutoCPUBoost(bool enabled) { m_syscore_autoboost = enabled; };
void SetPerfConf(uint32_t id); void SetPerfConf(uint32_t id);
protected: protected:
@@ -79,8 +79,10 @@ protected:
static constexpr uint64_t TICK_TIME_NS = 1000'000'000 / SAMPLE_RATE; static constexpr uint64_t TICK_TIME_NS = 1000'000'000 / SAMPLE_RATE;
static constexpr int CORE_NUMS = 4; static constexpr int CORE_NUMS = 4;
static constexpr int SYS_CORE_ID = (CORE_NUMS - 1);
bool m_running = false; bool m_running = false;
bool m_syscore_autoboost = false;
Thread m_t_cpuworker[CORE_NUMS], m_t_main; Thread m_t_cpuworker[CORE_NUMS], m_t_main;
uint32_t m_nvgpu_field; uint32_t m_nvgpu_field;