From b74a62475c1e2c607b5a760124c016fb0c7ba049 Mon Sep 17 00:00:00 2001 From: Aluveitie Date: Tue, 26 May 2020 15:38:43 +0200 Subject: [PATCH] Fixes potential cause of freezes after sleep --- .../AMDRyzenCPUPowerManagement.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/AMDRyzenCPUPowerManagement/AMDRyzenCPUPowerManagement.cpp b/AMDRyzenCPUPowerManagement/AMDRyzenCPUPowerManagement.cpp index 4f28849..df3c877 100644 --- a/AMDRyzenCPUPowerManagement/AMDRyzenCPUPowerManagement.cpp +++ b/AMDRyzenCPUPowerManagement/AMDRyzenCPUPowerManagement.cpp @@ -383,7 +383,7 @@ IOReturn AMDRyzenCPUPowerManagement::setPowerState(unsigned long powerStateOrdin IOLog("AMDCPUSupport::setPowerState preparing for sleep\n"); sleepState.sleep = true; sleepState.cpb = getCPBState(); - dumpPstate(sleepState.pstate); + //dumpPstate(sleepState.pstate); stopWorkLoop(); } else if (1 == powerStateOrdinal && sleepState.sleep) { @@ -391,7 +391,7 @@ IOReturn AMDRyzenCPUPowerManagement::setPowerState(unsigned long powerStateOrdin IOLog("AMDCPUSupport::setPowerState preparing for wakeup\n"); sleepState.sleep = false; setCPBState(sleepState.cpb); - writePstate(sleepState.pstate); + //writePstate(sleepState.pstate); startWorkLoop(); } @@ -505,18 +505,22 @@ void AMDRyzenCPUPowerManagement::calculateEffectiveFrequency(uint8_t physical){ //read of last APERF, the effective frequency calculated in is invalid. //Yeah, so we will do nothing. if(APERF <= lastAPERF || MPERF <= lastMPERF) { - IOLog("AMDCPUSupport::calculateEffectiveFrequency: frequency is invalid!!!"); + IOLog("AMDCPUSupport::calculateEffectiveFrequency: frequency is invalid for %u", physical); + lastAPERF_PerCore[physical] = APERF; + lastMPERF_PerCore[physical] = MPERF; return; } float freqP0 = PStateDefClock_perCore[0]; uint64_t deltaAPERF = APERF - lastAPERF; + uint64_t deltaMPERF = MPERF - lastMPERF; deltaAPERF_PerCore[physical] = deltaAPERF; - deltaMPERF_PerCore[physical] = MPERF - lastMPERF; - float effFreq = ((float)deltaAPERF / (float)(MPERF - lastMPERF)) * freqP0; - - effFreq_perCore[physical] = effFreq; + deltaMPERF_PerCore[physical] = deltaMPERF; + if (deltaMPERF != 0) { + float effFreq = ((float)deltaAPERF / (float)(deltaMPERF)) * freqP0; + effFreq_perCore[physical] = effFreq; + } lastAPERF_PerCore[physical] = APERF; lastMPERF_PerCore[physical] = MPERF;